e3666a8d93bd9d5d7563f5fbe02ac56ca1e39d22
[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) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
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 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24
25 package org.forester.test;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.StringWriter;
32 import java.io.Writer;
33 import java.net.URL;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.HashSet;
37 import java.util.Iterator;
38 import java.util.List;
39 import java.util.Locale;
40 import java.util.Set;
41 import java.util.SortedSet;
42
43 import org.forester.application.support_transfer;
44 import org.forester.archaeopteryx.AptxUtil;
45 import org.forester.archaeopteryx.TreePanelUtil;
46 import org.forester.archaeopteryx.webservices.WebserviceUtil;
47 import org.forester.clade_analysis.CladeAnalysisTest;
48 import org.forester.development.DevelopmentTools;
49 import org.forester.evoinference.TestPhylogenyReconstruction;
50 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
51 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
52 import org.forester.go.TestGo;
53 import org.forester.io.parsers.FastaParser;
54 import org.forester.io.parsers.GeneralMsaParser;
55 import org.forester.io.parsers.HmmscanPerDomainTableParser;
56 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
57 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
58 import org.forester.io.parsers.nexus.NexusCharactersParser;
59 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
60 import org.forester.io.parsers.nhx.NHXParser;
61 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
62 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
63 import org.forester.io.parsers.tol.TolParser;
64 import org.forester.io.parsers.util.ParserUtils;
65 import org.forester.io.writers.PhylogenyWriter;
66 import org.forester.io.writers.SequenceWriter;
67 import org.forester.msa.BasicMsa;
68 import org.forester.msa.DeleteableMsa;
69 import org.forester.msa.Mafft;
70 import org.forester.msa.Msa;
71 import org.forester.msa.Msa.MSA_FORMAT;
72 import org.forester.msa.MsaInferrer;
73 import org.forester.msa.MsaMethods;
74 import org.forester.pccx.TestPccx;
75 import org.forester.phylogeny.Phylogeny;
76 import org.forester.phylogeny.PhylogenyBranch;
77 import org.forester.phylogeny.PhylogenyMethods;
78 import org.forester.phylogeny.PhylogenyNode;
79 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
80 import org.forester.phylogeny.data.Accession;
81 import org.forester.phylogeny.data.Accession.Source;
82 import org.forester.phylogeny.data.BinaryCharacters;
83 import org.forester.phylogeny.data.BranchWidth;
84 import org.forester.phylogeny.data.Confidence;
85 import org.forester.phylogeny.data.Distribution;
86 import org.forester.phylogeny.data.DomainArchitecture;
87 import org.forester.phylogeny.data.Event;
88 import org.forester.phylogeny.data.Identifier;
89 import org.forester.phylogeny.data.PhylogenyData;
90 import org.forester.phylogeny.data.PhylogenyDataUtil;
91 import org.forester.phylogeny.data.Polygon;
92 import org.forester.phylogeny.data.PropertiesList;
93 import org.forester.phylogeny.data.Property;
94 import org.forester.phylogeny.data.Property.AppliesTo;
95 import org.forester.phylogeny.data.ProteinDomain;
96 import org.forester.phylogeny.data.Taxonomy;
97 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
98 import org.forester.phylogeny.factories.PhylogenyFactory;
99 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
100 import org.forester.protein.BasicDomain;
101 import org.forester.protein.BasicProtein;
102 import org.forester.protein.Domain;
103 import org.forester.protein.Protein;
104 import org.forester.protein.ProteinId;
105 import org.forester.rio.TestRIO;
106 import org.forester.sdi.SDI;
107 import org.forester.sdi.SDIR;
108 import org.forester.sdi.TestGSDI;
109 import org.forester.sequence.BasicSequence;
110 import org.forester.sequence.MolecularSequence;
111 import org.forester.species.BasicSpecies;
112 import org.forester.species.Species;
113 import org.forester.surfacing.TestSurfacing;
114 import org.forester.tools.ConfidenceAssessor;
115 import org.forester.tools.SupportCount;
116 import org.forester.tools.TreeSplitMatrix;
117 import org.forester.util.AsciiHistogram;
118 import org.forester.util.BasicDescriptiveStatistics;
119 import org.forester.util.BasicTable;
120 import org.forester.util.BasicTableParser;
121 import org.forester.util.DescriptiveStatistics;
122 import org.forester.util.ForesterConstants;
123 import org.forester.util.ForesterUtil;
124 import org.forester.util.GeneralTable;
125 import org.forester.util.SequenceAccessionTools;
126 import org.forester.ws.seqdb.SequenceDatabaseEntry;
127 import org.forester.ws.seqdb.SequenceDbWsTools;
128 import org.forester.ws.seqdb.UniProtTaxonomy;
129
130 @SuppressWarnings( "unused")
131 public final class Test {
132
133     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
134             + ForesterUtil.getFileSeparator() + "resources" + ForesterUtil.getFileSeparator();
135     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
136             + ForesterUtil.getFileSeparator() + "test_data" + ForesterUtil.getFileSeparator();
137     private final static boolean PERFORM_DB_TESTS          = false;
138     private static final boolean PERFORM_WEB_TREE_ACCESS   = false;
139     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
140             + ForesterConstants.PHYLO_XML_VERSION + "/" + ForesterConstants.PHYLO_XML_XSD;
141     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
142             + ForesterConstants.PHYLO_XML_VERSION + "/" + ForesterConstants.PHYLO_XML_XSD;
143     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
144     private final static double  ZERO_DIFF                 = 1.0E-9;
145
146     private static boolean isEqual( final double a, final double b ) {
147         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
148     }
149
150     public static void main( final String[] args ) {
151         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
152         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
153                 + "]" );
154         Locale.setDefault( Locale.US );
155         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
156         int failed = 0;
157         int succeeded = 0;
158         System.out.print( "[Test if directory with files for testing exists/is readable: " );
159         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
160             System.out.println( "OK.]" );
161         }
162         else {
163             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
164             System.out.println( "Testing aborted." );
165             System.exit( -1 );
166         }
167         System.out.print( "[Test if resources directory exists/is readable: " );
168         if ( testDir( PATH_TO_RESOURCES ) ) {
169             System.out.println( "OK.]" );
170         }
171         else {
172             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
173             System.out.println( "Testing aborted." );
174             System.exit( -1 );
175         }
176         final long start_time = new Date().getTime();
177         System.out.print( "Basic node methods: " );
178         if ( Test.testBasicNodeMethods() ) {
179             System.out.println( "OK." );
180             succeeded++;
181         }
182         else {
183             System.out.println( "failed." );
184             failed++;
185         }
186         System.out.print( "Protein id: " );
187         if ( !testProteinId() ) {
188             System.out.println( "failed." );
189             failed++;
190         }
191         else {
192             succeeded++;
193         }
194         System.out.println( "OK." );
195         System.out.print( "Species: " );
196         if ( !testSpecies() ) {
197             System.out.println( "failed." );
198             failed++;
199         }
200         else {
201             succeeded++;
202         }
203         System.out.println( "OK." );
204         System.out.print( "Basic domain: " );
205         if ( !testBasicDomain() ) {
206             System.out.println( "failed." );
207             failed++;
208         }
209         else {
210             succeeded++;
211         }
212         System.out.println( "OK." );
213         System.out.print( "Basic protein: " );
214         if ( !testBasicProtein() ) {
215             System.out.println( "failed." );
216             failed++;
217         }
218         else {
219             succeeded++;
220         }
221         System.out.println( "OK." );
222         System.out.print( "Common prefix: " );
223         if ( !testCommonPrefix() ) {
224             System.out.println( "failed." );
225             failed++;
226         }
227         else {
228             succeeded++;
229         }
230         System.out.println( "OK." );
231         System.out.print( "Common prefix sep: " );
232         if ( !testCommonPrefixSep() ) {
233             System.out.println( "failed." );
234             failed++;
235         }
236         else {
237             succeeded++;
238         }
239         System.out.println( "OK." );
240         System.out.print( "Contains prefix: " );
241         if ( !testContainsPrefix() ) {
242             System.out.println( "failed." );
243             failed++;
244         }
245         else {
246             succeeded++;
247         }
248         System.out.println( "OK." );
249         System.out.print( "Sequence writer: " );
250         if ( testSequenceWriter() ) {
251             System.out.println( "OK." );
252             succeeded++;
253         }
254         else {
255             System.out.println( "failed." );
256             failed++;
257         }
258         System.out.print( "Sequence id parsing: " );
259         if ( testSequenceIdParsing() ) {
260             System.out.println( "OK." );
261             succeeded++;
262         }
263         else {
264             System.out.println( "failed." );
265             failed++;
266         }
267         System.out.print( "UniProtKB id extraction: " );
268         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
269             System.out.println( "OK." );
270             succeeded++;
271         }
272         else {
273             System.out.println( "failed." );
274             failed++;
275         }
276         System.out.print( "Sequence DB tools 1: " );
277         if ( testSequenceDbWsTools1() ) {
278             System.out.println( "OK." );
279             succeeded++;
280         }
281         else {
282             System.out.println( "failed." );
283             failed++;
284         }
285         System.out.print( "Hmmscan output parser: " );
286         if ( testHmmscanOutputParser() ) {
287             System.out.println( "OK." );
288             succeeded++;
289         }
290         else {
291             System.out.println( "failed." );
292             failed++;
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         System.out.print( "Taxonomy data extraction: " );
313         if ( Test.testExtractTaxonomyDataFromNodeName() ) {
314             System.out.println( "OK." );
315             succeeded++;
316         }
317         else {
318             System.out.println( "failed." );
319             failed++;
320         }
321         System.out.print( "Taxonomy code extraction: " );
322         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
323             System.out.println( "OK." );
324             succeeded++;
325         }
326         else {
327             System.out.println( "failed." );
328             failed++;
329         }
330         System.out.print( "SN extraction: " );
331         if ( Test.testExtractSNFromNodeName() ) {
332             System.out.println( "OK." );
333             succeeded++;
334         }
335         else {
336             System.out.println( "failed." );
337             failed++;
338         }
339         System.out.print( "Taxonomy extraction (general): " );
340         if ( Test.testTaxonomyExtraction() ) {
341             System.out.println( "OK." );
342             succeeded++;
343         }
344         else {
345             System.out.println( "failed." );
346             failed++;
347         }
348         System.out.print( "Uri for Aptx web sequence accession: " );
349         if ( Test.testCreateUriForSeqWeb() ) {
350             System.out.println( "OK." );
351             succeeded++;
352         }
353         else {
354             System.out.println( "failed." );
355             failed++;
356         }
357         System.out.print( "Basic node construction and parsing of NHX (node level): " );
358         if ( Test.testNHXNodeParsing() ) {
359             System.out.println( "OK." );
360             succeeded++;
361         }
362         else {
363             System.out.println( "failed." );
364             failed++;
365         }
366         System.out.print( "Node construction and parsing of NHX (node level): " );
367         if ( Test.testNHXNodeParsing2() ) {
368             System.out.println( "OK." );
369             succeeded++;
370         }
371         else {
372             System.out.println( "failed." );
373             failed++;
374         }
375         System.out.print( "NHX parsing iterating: " );
376         if ( Test.testNHParsingIter() ) {
377             System.out.println( "OK." );
378             succeeded++;
379         }
380         else {
381             System.out.println( "failed." );
382             failed++;
383         }
384         System.out.print( "NH parsing: " );
385         if ( Test.testNHParsing() ) {
386             System.out.println( "OK." );
387             succeeded++;
388         }
389         else {
390             System.out.println( "failed." );
391             failed++;
392         }
393         System.out.print( "NH parsing - special chars: " );
394         if ( Test.testNHParsingSpecialChars() ) {
395             System.out.println( "OK." );
396             succeeded++;
397         }
398         else {
399             System.out.println( "failed." );
400             failed++;
401         }
402         System.out.print( "Conversion to NHX (node level): " );
403         if ( Test.testNHXconversion() ) {
404             System.out.println( "OK." );
405             succeeded++;
406         }
407         else {
408             System.out.println( "failed." );
409             failed++;
410         }
411         System.out.print( "NHX parsing: " );
412         if ( Test.testNHXParsing() ) {
413             System.out.println( "OK." );
414             succeeded++;
415         }
416         else {
417             System.out.println( "failed." );
418             failed++;
419         }
420         System.out.print( "NHX parsing with quotes: " );
421         if ( Test.testNHXParsingQuotes() ) {
422             System.out.println( "OK." );
423             succeeded++;
424         }
425         else {
426             System.out.println( "failed." );
427             failed++;
428         }
429         System.out.print( "NHX parsing (MrBayes): " );
430         if ( Test.testNHXParsingMB() ) {
431             System.out.println( "OK." );
432             succeeded++;
433         }
434         else {
435             System.out.println( "failed." );
436             failed++;
437         }
438         System.out.print( "Nexus characters parsing: " );
439         if ( Test.testNexusCharactersParsing() ) {
440             System.out.println( "OK." );
441             succeeded++;
442         }
443         else {
444             System.out.println( "failed." );
445             failed++;
446         }
447         System.out.print( "Nexus tree parsing iterating: " );
448         if ( Test.testNexusTreeParsingIterating() ) {
449             System.out.println( "OK." );
450             succeeded++;
451         }
452         else {
453             System.out.println( "failed." );
454             failed++;
455         }
456         System.out.print( "Nexus tree parsing: " );
457         if ( Test.testNexusTreeParsing() ) {
458             System.out.println( "OK." );
459             succeeded++;
460         }
461         else {
462             System.out.println( "failed." );
463             failed++;
464         }
465         System.out.print( "Nexus tree parsing (translating): " );
466         if ( Test.testNexusTreeParsingTranslating() ) {
467             System.out.println( "OK." );
468             succeeded++;
469         }
470         else {
471             System.out.println( "failed." );
472             failed++;
473         }
474         System.out.print( "Nexus matrix parsing: " );
475         if ( Test.testNexusMatrixParsing() ) {
476             System.out.println( "OK." );
477             succeeded++;
478         }
479         else {
480             System.out.println( "failed." );
481             failed++;
482         }
483         System.out.print( "Basic phyloXML parsing: " );
484         if ( Test.testBasicPhyloXMLparsing() ) {
485             System.out.println( "OK." );
486             succeeded++;
487         }
488         else {
489             System.out.println( "failed." );
490             failed++;
491         }
492         System.out.print( "Basic phyloXML parsing (validating against schema): " );
493         if ( testBasicPhyloXMLparsingValidating() ) {
494             System.out.println( "OK." );
495             succeeded++;
496         }
497         else {
498             System.out.println( "failed." );
499             failed++;
500         }
501         System.out.print( "phyloXML parsing (validating against schema): " );
502         if ( testPhyloXMLparsingValidating() ) {
503             System.out.println( "OK." );
504             succeeded++;
505         }
506         else {
507             System.out.println( "failed." );
508             failed++;
509         }
510         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
511         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
512             System.out.println( "OK." );
513             succeeded++;
514         }
515         else {
516             System.out.println( "failed." );
517             failed++;
518         }
519         System.out.print( "phyloXML Distribution Element: " );
520         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
521             System.out.println( "OK." );
522             succeeded++;
523         }
524         else {
525             System.out.println( "failed." );
526             failed++;
527         }
528         System.out.print( "Tol XML parsing: " );
529         if ( Test.testBasicTolXMLparsing() ) {
530             System.out.println( "OK." );
531             succeeded++;
532         }
533         else {
534             System.out.println( "failed." );
535             failed++;
536         }
537         System.out.print( "UTF-8 parsing from file: " );
538         if ( Test.testUTF8ParsingFromFile() ) {
539             System.out.println( "OK." );
540             succeeded++;
541         }
542         else {
543             System.out.println( "failed." );
544             failed++;
545         }
546         System.out.print( "Copying of node data: " );
547         if ( Test.testCopyOfNodeData() ) {
548             System.out.println( "OK." );
549             succeeded++;
550         }
551         else {
552             System.out.println( "failed." );
553             failed++;
554         }
555         System.out.print( "Tree copy: " );
556         if ( Test.testTreeCopy() ) {
557             System.out.println( "OK." );
558             succeeded++;
559         }
560         else {
561             System.out.println( "failed." );
562             failed++;
563         }
564         System.out.print( "Basic tree methods: " );
565         if ( Test.testBasicTreeMethods() ) {
566             System.out.println( "OK." );
567             succeeded++;
568         }
569         else {
570             System.out.println( "failed." );
571             failed++;
572         }
573         System.out.print( "Tree methods: " );
574         if ( Test.testTreeMethods() ) {
575             System.out.println( "OK." );
576             succeeded++;
577         }
578         else {
579             System.out.println( "failed." );
580             failed++;
581         }
582         System.out.print( "Phylogeny methods:" );
583         if ( Test.testPhylogenyMethods() ) {
584             System.out.println( "OK." );
585             succeeded++;
586         }
587         else {
588             System.out.println( "failed." );
589             failed++;
590         }
591         System.out.print( "Postorder Iterator: " );
592         if ( Test.testPostOrderIterator() ) {
593             System.out.println( "OK." );
594             succeeded++;
595         }
596         else {
597             System.out.println( "failed." );
598             failed++;
599         }
600         System.out.print( "Preorder Iterator: " );
601         if ( Test.testPreOrderIterator() ) {
602             System.out.println( "OK." );
603             succeeded++;
604         }
605         else {
606             System.out.println( "failed." );
607             failed++;
608         }
609         System.out.print( "Levelorder Iterator: " );
610         if ( Test.testLevelOrderIterator() ) {
611             System.out.println( "OK." );
612             succeeded++;
613         }
614         else {
615             System.out.println( "failed." );
616             failed++;
617         }
618         System.out.print( "Re-id methods: " );
619         if ( Test.testReIdMethods() ) {
620             System.out.println( "OK." );
621             succeeded++;
622         }
623         else {
624             System.out.println( "failed." );
625             failed++;
626         }
627         System.out.print( "Methods on last external nodes: " );
628         if ( Test.testLastExternalNodeMethods() ) {
629             System.out.println( "OK." );
630             succeeded++;
631         }
632         else {
633             System.out.println( "failed." );
634             failed++;
635         }
636         System.out.print( "Methods on external nodes: " );
637         if ( Test.testExternalNodeRelatedMethods() ) {
638             System.out.println( "OK." );
639             succeeded++;
640         }
641         else {
642             System.out.println( "failed." );
643             failed++;
644         }
645         System.out.print( "Deletion of external nodes: " );
646         if ( Test.testDeletionOfExternalNodes() ) {
647             System.out.println( "OK." );
648             succeeded++;
649         }
650         else {
651             System.out.println( "failed." );
652             failed++;
653         }
654         System.out.print( "Subtree deletion: " );
655         if ( Test.testSubtreeDeletion() ) {
656             System.out.println( "OK." );
657             succeeded++;
658         }
659         else {
660             System.out.println( "failed." );
661             failed++;
662         }
663         System.out.print( "Phylogeny branch: " );
664         if ( Test.testPhylogenyBranch() ) {
665             System.out.println( "OK." );
666             succeeded++;
667         }
668         else {
669             System.out.println( "failed." );
670             failed++;
671         }
672         System.out.print( "Rerooting: " );
673         if ( Test.testRerooting() ) {
674             System.out.println( "OK." );
675             succeeded++;
676         }
677         else {
678             System.out.println( "failed." );
679             failed++;
680         }
681         System.out.print( "Mipoint rooting: " );
682         if ( Test.testMidpointrooting() ) {
683             System.out.println( "OK." );
684             succeeded++;
685         }
686         else {
687             System.out.println( "failed." );
688             failed++;
689         }
690         System.out.print( "Node removal: " );
691         if ( Test.testNodeRemoval() ) {
692             System.out.println( "OK." );
693             succeeded++;
694         }
695         else {
696             System.out.println( "failed." );
697             failed++;
698         }
699         System.out.print( "Support count: " );
700         if ( Test.testSupportCount() ) {
701             System.out.println( "OK." );
702             succeeded++;
703         }
704         else {
705             System.out.println( "failed." );
706             failed++;
707         }
708         System.out.print( "Support transfer: " );
709         if ( Test.testSupportTransfer() ) {
710             System.out.println( "OK." );
711             succeeded++;
712         }
713         else {
714             System.out.println( "failed." );
715             failed++;
716         }
717         System.out.print( "Finding of LCA: " );
718         if ( Test.testGetLCA() ) {
719             System.out.println( "OK." );
720             succeeded++;
721         }
722         else {
723             System.out.println( "failed." );
724             failed++;
725         }
726         System.out.print( "Finding of LCA 2: " );
727         if ( Test.testGetLCA2() ) {
728             System.out.println( "OK." );
729             succeeded++;
730         }
731         else {
732             System.out.println( "failed." );
733             failed++;
734         }
735         System.out.print( "Calculation of distance between nodes: " );
736         if ( Test.testGetDistance() ) {
737             System.out.println( "OK." );
738             succeeded++;
739         }
740         else {
741             System.out.println( "failed." );
742             failed++;
743         }
744         System.out.print( "Descriptive statistics: " );
745         if ( Test.testDescriptiveStatistics() ) {
746             System.out.println( "OK." );
747             succeeded++;
748         }
749         else {
750             System.out.println( "failed." );
751             failed++;
752         }
753         System.out.print( "Data objects and methods: " );
754         if ( Test.testDataObjects() ) {
755             System.out.println( "OK." );
756             succeeded++;
757         }
758         else {
759             System.out.println( "failed." );
760             failed++;
761         }
762         System.out.print( "Properties map: " );
763         if ( Test.testPropertiesMap() ) {
764             System.out.println( "OK." );
765             succeeded++;
766         }
767         else {
768             System.out.println( "failed." );
769             failed++;
770         }
771         System.out.print( "SDIse: " );
772         if ( Test.testSDIse() ) {
773             System.out.println( "OK." );
774             succeeded++;
775         }
776         else {
777             System.out.println( "failed." );
778             failed++;
779         }
780         System.out.print( "SDIunrooted: " );
781         if ( Test.testSDIunrooted() ) {
782             System.out.println( "OK." );
783             succeeded++;
784         }
785         else {
786             System.out.println( "failed." );
787             failed++;
788         }
789         System.out.print( "GSDI: " );
790         if ( TestGSDI.test() ) {
791             System.out.println( "OK." );
792             succeeded++;
793         }
794         else {
795             System.out.println( "failed." );
796             failed++;
797         }
798         System.out.print( "RIO: " );
799         if ( TestRIO.test() ) {
800             System.out.println( "OK." );
801             succeeded++;
802         }
803         else {
804             System.out.println( "failed." );
805             failed++;
806         }
807         System.out.print( "Clade analyis: " );
808         if ( CladeAnalysisTest.test() ) {
809             System.out.println( "OK." );
810             succeeded++;
811         }
812         else {
813             System.out.println( "failed." );
814             failed++;
815         }
816         System.out.print( "Phylogeny reconstruction:" );
817         System.out.println();
818         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
819             System.out.println( "OK." );
820             succeeded++;
821         }
822         else {
823             System.out.println( "failed." );
824             failed++;
825         }
826         System.out.print( "Analysis of domain architectures: " );
827         System.out.println();
828         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
829             System.out.println( "OK." );
830             succeeded++;
831         }
832         else {
833             System.out.println( "failed." );
834             failed++;
835         }
836         System.out.print( "GO: " );
837         System.out.println();
838         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
839             System.out.println( "OK." );
840             succeeded++;
841         }
842         else {
843             System.out.println( "failed." );
844             failed++;
845         }
846         System.out.print( "Modeling tools: " );
847         if ( TestPccx.test() ) {
848             System.out.println( "OK." );
849             succeeded++;
850         }
851         else {
852             System.out.println( "failed." );
853             failed++;
854         }
855         System.out.print( "Split Matrix strict: " );
856         if ( Test.testSplitStrict() ) {
857             System.out.println( "OK." );
858             succeeded++;
859         }
860         else {
861             System.out.println( "failed." );
862             failed++;
863         }
864         System.out.print( "Split Matrix: " );
865         if ( Test.testSplit() ) {
866             System.out.println( "OK." );
867             succeeded++;
868         }
869         else {
870             System.out.println( "failed." );
871             failed++;
872         }
873         System.out.print( "Confidence Assessor: " );
874         if ( Test.testConfidenceAssessor() ) {
875             System.out.println( "OK." );
876             succeeded++;
877         }
878         else {
879             System.out.println( "failed." );
880             failed++;
881         }
882         System.out.print( "Basic table: " );
883         if ( Test.testBasicTable() ) {
884             System.out.println( "OK." );
885             succeeded++;
886         }
887         else {
888             System.out.println( "failed." );
889             failed++;
890         }
891         System.out.print( "General table: " );
892         if ( Test.testGeneralTable() ) {
893             System.out.println( "OK." );
894             succeeded++;
895         }
896         else {
897             System.out.println( "failed." );
898             failed++;
899         }
900         System.out.print( "Amino acid sequence: " );
901         if ( Test.testAminoAcidSequence() ) {
902             System.out.println( "OK." );
903             succeeded++;
904         }
905         else {
906             System.out.println( "failed." );
907             failed++;
908         }
909         System.out.print( "General MSA parser: " );
910         if ( Test.testGeneralMsaParser() ) {
911             System.out.println( "OK." );
912             succeeded++;
913         }
914         else {
915             System.out.println( "failed." );
916             failed++;
917         }
918         System.out.print( "Fasta parser for msa: " );
919         if ( Test.testFastaParser() ) {
920             System.out.println( "OK." );
921             succeeded++;
922         }
923         else {
924             System.out.println( "failed." );
925             failed++;
926         }
927         System.out.print( "Creation of balanced phylogeny: " );
928         if ( Test.testCreateBalancedPhylogeny() ) {
929             System.out.println( "OK." );
930             succeeded++;
931         }
932         else {
933             System.out.println( "failed." );
934             failed++;
935         }
936         System.out.print( "Genbank accessor parsing: " );
937         if ( Test.testGenbankAccessorParsing() ) {
938             System.out.println( "OK." );
939             succeeded++;
940         }
941         else {
942             System.out.println( "failed." );
943             failed++;
944         }
945         String path = "";
946         final String os = ForesterUtil.OS_NAME.toLowerCase();
947         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
948             path = "/usr/local/bin/mafft";
949         }
950         else if ( os.indexOf( "win" ) >= 0 ) {
951             path = "C:\\Program Files\\mafft-win\\mafft.bat";
952         }
953         else {
954             path = "mafft";
955             if ( !MsaInferrer.isInstalled( path ) ) {
956                 path = "/usr/bin/mafft";
957             }
958             if ( !MsaInferrer.isInstalled( path ) ) {
959                 path = "/usr/local/bin/mafft";
960             }
961         }
962         if ( MsaInferrer.isInstalled( path ) ) {
963             System.out.print( "MAFFT (external program): " );
964             if ( Test.testMafft( path ) ) {
965                 System.out.println( "OK." );
966                 succeeded++;
967             }
968             else {
969                 System.out.println( "failed [will not count towards failed tests]" );
970             }
971         }
972         System.out.print( "Next nodes with collapsed: " );
973         if ( Test.testNextNodeWithCollapsing() ) {
974             System.out.println( "OK." );
975             succeeded++;
976         }
977         else {
978             System.out.println( "failed." );
979             failed++;
980         }
981         System.out.print( "Simple MSA quality: " );
982         if ( Test.testMsaQualityMethod() ) {
983             System.out.println( "OK." );
984             succeeded++;
985         }
986         else {
987             System.out.println( "failed." );
988             failed++;
989         }
990         System.out.print( "Deleteable MSA: " );
991         if ( Test.testDeleteableMsa() ) {
992             System.out.println( "OK." );
993             succeeded++;
994         }
995         else {
996             System.out.println( "failed." );
997             failed++;
998         }
999         System.out.print( "MSA entropy: " );
1000         if ( Test.testMsaEntropy() ) {
1001             System.out.println( "OK." );
1002             succeeded++;
1003         }
1004         else {
1005             System.out.println( "failed." );
1006             failed++;
1007         }
1008         if ( PERFORM_DB_TESTS ) {
1009             System.out.print( "Uniprot Entry Retrieval: " );
1010             if ( Test.testUniprotEntryRetrieval() ) {
1011                 System.out.println( "OK." );
1012                 succeeded++;
1013             }
1014             else {
1015                 System.out.println( "failed." );
1016                 failed++;
1017             }
1018             System.out.print( "Ebi Entry Retrieval: " );
1019             if ( Test.testEbiEntryRetrieval() ) {
1020                 System.out.println( "OK." );
1021                 succeeded++;
1022             }
1023             else {
1024                 System.out.println( "failed." );
1025                 failed++;
1026             }
1027             System.out.print( "Sequence DB tools 2: " );
1028             if ( testSequenceDbWsTools2() ) {
1029                 System.out.println( "OK." );
1030                 succeeded++;
1031             }
1032             else {
1033                 System.out.println( "failed." );
1034                 failed++;
1035                 System.exit( -1 );
1036             }
1037             System.out.print( "Uniprot Taxonomy Search: " );
1038             if ( Test.testUniprotTaxonomySearch() ) {
1039                 System.out.println( "OK." );
1040                 succeeded++;
1041             }
1042             else {
1043                 System.out.println( "failed." );
1044                 failed++;
1045             }
1046         }
1047         if ( PERFORM_WEB_TREE_ACCESS ) {
1048             System.out.print( "TreeBase acccess: " );
1049             if ( Test.testTreeBaseReading() ) {
1050                 System.out.println( "OK." );
1051                 succeeded++;
1052             }
1053             else {
1054                 System.out.println( "failed." );
1055                 failed++;
1056             }
1057             System.out.print( "ToL access: " );
1058             if ( Test.testToLReading() ) {
1059                 System.out.println( "OK." );
1060                 succeeded++;
1061             }
1062             else {
1063                 System.out.println( "failed." );
1064                 failed++;
1065             }
1066             System.out.print( "NHX parsing from URL: " );
1067             if ( Test.testNHXparsingFromURL() ) {
1068                 System.out.println( "OK." );
1069                 succeeded++;
1070             }
1071             else {
1072                 System.out.println( "failed." );
1073                 failed++;
1074             }
1075             System.out.print( "NHX parsing from URL 2: " );
1076             if ( Test.testNHXparsingFromURL2() ) {
1077                 System.out.println( "OK." );
1078                 succeeded++;
1079             }
1080             else {
1081                 System.out.println( "failed." );
1082                 failed++;
1083             }
1084             System.out.print( "phyloXML parsing from URL: " );
1085             if ( Test.testPhyloXMLparsingFromURL() ) {
1086                 System.out.println( "OK." );
1087                 succeeded++;
1088             }
1089             else {
1090                 System.out.println( "failed." );
1091                 failed++;
1092             }
1093             System.out.print( "TreeFam access: " );
1094             if ( Test.testTreeFamReading() ) {
1095                 System.out.println( "OK." );
1096                 succeeded++;
1097             }
1098             else {
1099                 System.out.println( "failed." );
1100                 failed++;
1101             }
1102             System.out.print( "Pfam tree access: " );
1103             if ( Test.testPfamTreeReading() ) {
1104                 System.out.println( "OK." );
1105                 succeeded++;
1106             }
1107             else {
1108                 System.out.println( "failed." );
1109                 failed++;
1110             }
1111         }
1112         System.out.println();
1113         final Runtime rt = java.lang.Runtime.getRuntime();
1114         final long free_memory = rt.freeMemory() / 1000000;
1115         final long total_memory = rt.totalMemory() / 1000000;
1116         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1117                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1118         System.out.println();
1119         System.out.println( "Successful tests: " + succeeded );
1120         System.out.println( "Failed     tests: " + failed );
1121         System.out.println();
1122         if ( failed < 1 ) {
1123             System.out.println( "OK." );
1124         }
1125         else {
1126             System.out.println( "Not OK." );
1127         }
1128     }
1129
1130     private static boolean testEngulfingOverlapRemoval() {
1131         try {
1132             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1133             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1134             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1135             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1136             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1137             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1138             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1139             final List<Boolean> covered = new ArrayList<>();
1140             covered.add( true ); // 0
1141             covered.add( false ); // 1
1142             covered.add( true ); // 2
1143             covered.add( false ); // 3
1144             covered.add( true ); // 4
1145             covered.add( true ); // 5
1146             covered.add( false ); // 6
1147             covered.add( true ); // 7
1148             covered.add( true ); // 8
1149             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1150                 return false;
1151             }
1152             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1153                 return false;
1154             }
1155             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1156                 return false;
1157             }
1158             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1159                 return false;
1160             }
1161             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1162                 return false;
1163             }
1164             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1165                 return false;
1166             }
1167             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1168                 return false;
1169             }
1170             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1171             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1172             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1173             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1174             abc.addProteinDomain( a );
1175             abc.addProteinDomain( b );
1176             abc.addProteinDomain( c );
1177             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1178             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1179             if ( abc.getNumberOfProteinDomains() != 3 ) {
1180                 return false;
1181             }
1182             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1183                 return false;
1184             }
1185             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1186                 return false;
1187             }
1188             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1189                 return false;
1190             }
1191             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1192                 return false;
1193             }
1194             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1195             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1196             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1197             final Protein def = new BasicProtein( "def", "nemve", 0 );
1198             def.addProteinDomain( d );
1199             def.addProteinDomain( e );
1200             def.addProteinDomain( f );
1201             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1202             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1203             if ( def.getNumberOfProteinDomains() != 3 ) {
1204                 return false;
1205             }
1206             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1207                 return false;
1208             }
1209             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1210                 return false;
1211             }
1212             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1213                 return false;
1214             }
1215             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1216                 return false;
1217             }
1218             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1219                 return false;
1220             }
1221         }
1222         catch ( final Exception e ) {
1223             e.printStackTrace( System.out );
1224             return false;
1225         }
1226         return true;
1227     }
1228
1229     private static final boolean testNHXparsingFromURL2() {
1230         try {
1231             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1232             final Phylogeny phys[] = AptxUtil
1233                     .readPhylogeniesFromUrl( new URL( s ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1234             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1235                 return false;
1236             }
1237             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1238                 System.out.println( phys[ 0 ].toNewHampshire() );
1239                 return false;
1240             }
1241             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1242                 System.out.println( phys[ 1 ].toNewHampshire() );
1243                 return false;
1244             }
1245             final Phylogeny phys2[] = AptxUtil
1246                     .readPhylogeniesFromUrl( new URL( s ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1247             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1248                 return false;
1249             }
1250             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1251                 System.out.println( phys2[ 0 ].toNewHampshire() );
1252                 return false;
1253             }
1254             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1255                 System.out.println( phys2[ 1 ].toNewHampshire() );
1256                 return false;
1257             }
1258             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1259                     + "SwissTree/ST001/consensus_tree.nhx" ),
1260                                                                        false,
1261                                                                        false,
1262                                                                        false,
1263                                                                        TAXONOMY_EXTRACTION.NO,
1264                                                                        false );
1265             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1266                 return false;
1267             }
1268             if ( !phys3[ 0 ].toNewHampshire()
1269                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1270                 System.out.println( phys3[ 0 ].toNewHampshire() );
1271                 return false;
1272             }
1273             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1274                     + "SwissTree/ST001/consensus_tree.nhx" ),
1275                                                                        false,
1276                                                                        false,
1277                                                                        false,
1278                                                                        TAXONOMY_EXTRACTION.NO,
1279                                                                        false );
1280             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1281                 return false;
1282             }
1283             if ( !phys4[ 0 ].toNewHampshire()
1284                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1285                 System.out.println( phys4[ 0 ].toNewHampshire() );
1286                 return false;
1287             }
1288         }
1289         catch ( final Exception e ) {
1290             e.printStackTrace();
1291             return false;
1292         }
1293         return true;
1294     }
1295
1296     private static final boolean testNHXparsingFromURL() {
1297         try {
1298             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1299             final URL u = new URL( s );
1300             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1301             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1302             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1303                 return false;
1304             }
1305             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1306                 System.out.println( phys[ 0 ].toNewHampshire() );
1307                 return false;
1308             }
1309             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1310                 System.out.println( phys[ 1 ].toNewHampshire() );
1311                 return false;
1312             }
1313             final URL u2 = new URL( s );
1314             final Phylogeny[] phys2 = factory.create( u2.openStream(), new NHXParser() );
1315             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1316                 return false;
1317             }
1318             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1319                 System.out.println( phys2[ 0 ].toNewHampshire() );
1320                 return false;
1321             }
1322             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1323             final NHXParser p = new NHXParser();
1324             final URL u3 = new URL( s );
1325             p.setSource( u3 );
1326             if ( !p.hasNext() ) {
1327                 return false;
1328             }
1329             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1330                 return false;
1331             }
1332             if ( !p.hasNext() ) {
1333                 return false;
1334             }
1335             p.reset();
1336             if ( !p.hasNext() ) {
1337                 return false;
1338             }
1339             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1340                 return false;
1341             }
1342             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1343                 return false;
1344             }
1345             p.reset();
1346             if ( !p.hasNext() ) {
1347                 return false;
1348             }
1349             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1350                 return false;
1351             }
1352             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1353                 return false;
1354             }
1355         }
1356         catch ( final Exception e ) {
1357             System.out.println( e.toString() );
1358             e.printStackTrace();
1359             return false;
1360         }
1361         return true;
1362     }
1363
1364     private static boolean testOverlapRemoval() {
1365         try {
1366             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1367             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1368             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1369             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1370             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1371             final List<Boolean> covered = new ArrayList<>();
1372             covered.add( true ); // 0
1373             covered.add( false ); // 1
1374             covered.add( true ); // 2
1375             covered.add( false ); // 3
1376             covered.add( true ); // 4
1377             covered.add( true ); // 5
1378             covered.add( false ); // 6
1379             covered.add( true ); // 7
1380             covered.add( true ); // 8
1381             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1382                 return false;
1383             }
1384             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1385                 return false;
1386             }
1387             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1388                 return false;
1389             }
1390             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1391                 return false;
1392             }
1393             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1394                 return false;
1395             }
1396             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1397             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1398             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1399             ab.addProteinDomain( a );
1400             ab.addProteinDomain( b );
1401             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1402             if ( ab.getNumberOfProteinDomains() != 2 ) {
1403                 return false;
1404             }
1405             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1406                 return false;
1407             }
1408             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1409                 return false;
1410             }
1411             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1412             if ( ab.getNumberOfProteinDomains() != 2 ) {
1413                 return false;
1414             }
1415             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1416                 return false;
1417             }
1418             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1419             final Domain d = new BasicDomain( "d",
1420                                               ( short ) 10000,
1421                                               ( short ) 10500,
1422                                               ( short ) 1,
1423                                               ( short ) 1,
1424                                               0.0000001,
1425                                               1 );
1426             final Domain e = new BasicDomain( "e",
1427                                               ( short ) 5000,
1428                                               ( short ) 5500,
1429                                               ( short ) 1,
1430                                               ( short ) 1,
1431                                               0.0001,
1432                                               1 );
1433             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1434             cde.addProteinDomain( c );
1435             cde.addProteinDomain( d );
1436             cde.addProteinDomain( e );
1437             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1438             if ( cde.getNumberOfProteinDomains() != 3 ) {
1439                 return false;
1440             }
1441             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1442                 return false;
1443             }
1444             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1445             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1446             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1447             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1448             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1449             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1450             fghi.addProteinDomain( f );
1451             fghi.addProteinDomain( g );
1452             fghi.addProteinDomain( h );
1453             fghi.addProteinDomain( i );
1454             fghi.addProteinDomain( i );
1455             fghi.addProteinDomain( i );
1456             fghi.addProteinDomain( i2 );
1457             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1458             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1459                 return false;
1460             }
1461             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1462                 return false;
1463             }
1464             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1465                 return false;
1466             }
1467             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1468             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1469                 return false;
1470             }
1471             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1472                 return false;
1473             }
1474             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1475             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1476             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1477             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1478             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1479             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1480             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1481             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1482             jklm.addProteinDomain( j );
1483             jklm.addProteinDomain( k );
1484             jklm.addProteinDomain( l );
1485             jklm.addProteinDomain( m );
1486             jklm.addProteinDomain( m0 );
1487             jklm.addProteinDomain( m1 );
1488             jklm.addProteinDomain( m2 );
1489             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1490             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1491                 return false;
1492             }
1493             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1494                 return false;
1495             }
1496             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1497                 return false;
1498             }
1499             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1500             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1501                 return false;
1502             }
1503             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1504                 return false;
1505             }
1506             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1507             final Protein od = new BasicProtein( "od", "varanus", 0 );
1508             od.addProteinDomain( only );
1509             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1510             if ( od.getNumberOfProteinDomains() != 1 ) {
1511                 return false;
1512             }
1513             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1514                 return false;
1515             }
1516         }
1517         catch ( final Exception e ) {
1518             e.printStackTrace( System.out );
1519             return false;
1520         }
1521         return true;
1522     }
1523
1524     private static final boolean testPfamTreeReading() {
1525         try {
1526             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1527             final NHXParser parser = new NHXParser();
1528             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1529             parser.setReplaceUnderscores( false );
1530             parser.setGuessRootedness( true );
1531             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1532             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1533                 return false;
1534             }
1535             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1536                 return false;
1537             }
1538         }
1539         catch ( final Exception e ) {
1540             e.printStackTrace();
1541             return false;
1542         }
1543         return true;
1544     }
1545
1546     private static final boolean testPhyloXMLparsingFromURL() {
1547         try {
1548             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1549             final URL u = new URL( s );
1550             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1551             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1552                 return false;
1553             }
1554             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1555             if ( ( phys2 == null ) || ( phys2.length != 2 ) ) {
1556                 return false;
1557             }
1558         }
1559         catch ( final Exception e ) {
1560             e.printStackTrace();
1561             return false;
1562         }
1563         return true;
1564     }
1565
1566     private static final boolean testToLReading() {
1567         try {
1568             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1569             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, new TolParser() );
1570             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1571                 return false;
1572             }
1573             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1574                 return false;
1575             }
1576             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName()
1577                     .equals( "Protacanthopterygii" ) ) {
1578                 return false;
1579             }
1580             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1581                 return false;
1582             }
1583             //
1584             final URL u2 = new URL( WebserviceUtil.TOL_URL_BASE + "17706" );
1585             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, new TolParser() );
1586             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
1587                 return false;
1588             }
1589             if ( !phys2[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "17706" ) ) {
1590                 return false;
1591             }
1592             if ( phys2[ 0 ].getNumberOfExternalNodes() < 5 ) {
1593                 return false;
1594             }
1595         }
1596         catch ( final Exception e ) {
1597             e.printStackTrace();
1598             return false;
1599         }
1600         return true;
1601     }
1602
1603     private static final boolean testTreeBaseReading() {
1604         try {
1605             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "72557?format=nexus" );
1606             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1607             parser.setReplaceUnderscores( true );
1608             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1609             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1610                 return false;
1611             }
1612             final URL u_1 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2406?format=nexus" );
1613             final NexusPhylogeniesParser parser_1 = new NexusPhylogeniesParser();
1614             final Phylogeny[] phys_1 = ForesterUtil.readPhylogeniesFromUrl( u_1, parser_1 );
1615             if ( ( phys_1 == null ) || ( phys_1.length != 1 ) ) {
1616                 return false;
1617             }
1618             final URL u_2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "422?format=nexus" );
1619             final NexusPhylogeniesParser parser_2 = new NexusPhylogeniesParser();
1620             final Phylogeny[] phys_2 = ForesterUtil.readPhylogeniesFromUrl( u_2, parser_2 );
1621             if ( ( phys_2 == null ) || ( phys_2.length != 1 ) ) {
1622                 return false;
1623             }
1624             final URL u_3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2654?format=nexus" );
1625             final NexusPhylogeniesParser parser_3 = new NexusPhylogeniesParser();
1626             final Phylogeny[] phys_3 = ForesterUtil.readPhylogeniesFromUrl( u_3, parser_3 );
1627             if ( ( phys_3 == null ) || ( phys_3.length != 1 ) ) {
1628                 return false;
1629             }
1630             final URL u_4 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1631             final NexusPhylogeniesParser parser_4 = new NexusPhylogeniesParser();
1632             final Phylogeny[] phys_4 = ForesterUtil.readPhylogeniesFromUrl( u_4, parser_4 );
1633             if ( ( phys_4 == null ) || ( phys_4.length != 1 ) ) {
1634                 return false;
1635             }
1636             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1637             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1638             parser2.setReplaceUnderscores( true );
1639             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, parser2 );
1640             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1641                 return false;
1642             }
1643             final URL u3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14909?format=nexus" );
1644             final NexusPhylogeniesParser parser3 = new NexusPhylogeniesParser();
1645             final Phylogeny[] phys3 = ForesterUtil.readPhylogeniesFromUrl( u3, parser3 );
1646             if ( ( phys3 == null ) || ( phys3.length != 2 ) ) {
1647                 return false;
1648             }
1649             final Phylogeny[] phys4 = ForesterUtil.readPhylogeniesFromUrl(
1650                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1651                                                                                    + "14525?format=nexus" ),
1652                                                                            new NexusPhylogeniesParser() );
1653             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1654                 return false;
1655             }
1656             final Phylogeny[] phys5 = ForesterUtil.readPhylogeniesFromUrl(
1657                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1658                                                                                    + "15632?format=nexus" ),
1659                                                                            new NexusPhylogeniesParser() );
1660             if ( ( phys5 == null ) || ( phys5.length != 1 ) ) {
1661                 return false;
1662             }
1663             final Phylogeny[] phys6 = ForesterUtil.readPhylogeniesFromUrl(
1664                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1665                                                                                    + "10190?format=nexus" ),
1666                                                                            new NexusPhylogeniesParser() );
1667             if ( ( phys6 == null ) || ( phys6.length != 1 ) ) {
1668                 return false;
1669             }
1670             final Phylogeny[] phys7 = ForesterUtil.readPhylogeniesFromUrl(
1671                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1672                                                                                    + "13246?format=nexus" ),
1673                                                                            new NexusPhylogeniesParser() );
1674             if ( ( phys7 == null ) || ( phys7.length != 2 ) ) {
1675                 return false;
1676             }
1677             final Phylogeny[] phys8 = ForesterUtil.readPhylogeniesFromUrl(
1678                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1679                                                                                    + "11662?format=nexus" ),
1680                                                                            new NexusPhylogeniesParser() );
1681             if ( ( phys8 == null ) || ( phys8.length != 2 ) ) {
1682                 return false;
1683             }
1684             final Phylogeny[] phys9 = ForesterUtil.readPhylogeniesFromUrl(
1685                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1686                                                                                    + "562?format=nexus" ),
1687                                                                            new NexusPhylogeniesParser() );
1688             if ( ( phys9 == null ) || ( phys9.length != 4 ) ) {
1689                 return false;
1690             }
1691             final Phylogeny[] phys16424 = ForesterUtil.readPhylogeniesFromUrl(
1692                                                                                new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1693                                                                                        + "16424?format=nexus" ),
1694                                                                                new NexusPhylogeniesParser() );
1695             if ( ( phys16424 == null ) || ( phys16424.length != 1 ) ) {
1696                 return false;
1697             }
1698             final Phylogeny[] phys17878 = ForesterUtil.readPhylogeniesFromUrl(
1699                                                                                new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1700                                                                                        + "17878?format=nexus" ),
1701                                                                                new NexusPhylogeniesParser() );
1702             if ( ( phys17878 == null ) || ( phys17878.length != 17 ) ) {
1703                 return false;
1704             }
1705             final Phylogeny[] phys18804 = ForesterUtil.readPhylogeniesFromUrl(
1706                                                                                new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1707                                                                                        + "18804?format=nexus" ),
1708                                                                                new NexusPhylogeniesParser() );
1709             if ( ( phys18804 == null ) || ( phys18804.length != 2 ) ) {
1710                 return false;
1711             }
1712             final Phylogeny[] phys346 = ForesterUtil.readPhylogeniesFromUrl(
1713                                                                              new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1714                                                                                      + "346?format=nexus" ),
1715                                                                              new NexusPhylogeniesParser() );
1716             if ( ( phys346 == null ) || ( phys346.length != 1 ) ) {
1717                 return false;
1718             }
1719         }
1720         catch ( final Exception e ) {
1721             e.printStackTrace();
1722             return false;
1723         }
1724         return true;
1725     }
1726
1727     private static final boolean testTreeFamReading() {
1728         try {
1729             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1730             final NHXParser parser = new NHXParser();
1731             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1732             parser.setReplaceUnderscores( false );
1733             parser.setGuessRootedness( true );
1734             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1735             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1736                 return false;
1737             }
1738             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1739                 return false;
1740             }
1741         }
1742         catch ( final Exception e ) {
1743             e.printStackTrace();
1744             return false;
1745         }
1746         return true;
1747     }
1748
1749     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1750         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1751         return p;
1752     }
1753
1754     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1755         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1756     }
1757
1758     private static boolean testAminoAcidSequence() {
1759         try {
1760             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1761             if ( aa1.getLength() != 13 ) {
1762                 return false;
1763             }
1764             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1765                 return false;
1766             }
1767             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1768                 return false;
1769             }
1770             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1771                 return false;
1772             }
1773             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1774             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1775                 return false;
1776             }
1777             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1778             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1779                 return false;
1780             }
1781             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1782             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1783                 return false;
1784             }
1785         }
1786         catch ( final Exception e ) {
1787             e.printStackTrace();
1788             return false;
1789         }
1790         return true;
1791     }
1792
1793     private static boolean testBasicDomain() {
1794         try {
1795             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1796             if ( !pd.getDomainId().equals( "id" ) ) {
1797                 return false;
1798             }
1799             if ( pd.getNumber() != 1 ) {
1800                 return false;
1801             }
1802             if ( pd.getTotalCount() != 4 ) {
1803                 return false;
1804             }
1805             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1806                 return false;
1807             }
1808             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1809             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1810             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1811             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1812             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1813             if ( !a1.equals( a1 ) ) {
1814                 return false;
1815             }
1816             if ( !a1.equals( a1_copy ) ) {
1817                 return false;
1818             }
1819             if ( !a1.equals( a1_equal ) ) {
1820                 return false;
1821             }
1822             if ( !a1.equals( a2 ) ) {
1823                 return false;
1824             }
1825             if ( a1.equals( a3 ) ) {
1826                 return false;
1827             }
1828             if ( a1.compareTo( a1 ) != 0 ) {
1829                 return false;
1830             }
1831             if ( a1.compareTo( a1_copy ) != 0 ) {
1832                 return false;
1833             }
1834             if ( a1.compareTo( a1_equal ) != 0 ) {
1835                 return false;
1836             }
1837             if ( a1.compareTo( a2 ) != 0 ) {
1838                 return false;
1839             }
1840             if ( a1.compareTo( a3 ) == 0 ) {
1841                 return false;
1842             }
1843         }
1844         catch ( final Exception e ) {
1845             e.printStackTrace( System.out );
1846             return false;
1847         }
1848         return true;
1849     }
1850
1851     private static boolean testBasicNodeMethods() {
1852         try {
1853             if ( PhylogenyNode.getNodeCount() != 0 ) {
1854                 return false;
1855             }
1856             final PhylogenyNode n1 = new PhylogenyNode();
1857             final PhylogenyNode n2 = PhylogenyNode
1858                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1859             final PhylogenyNode n3 = PhylogenyNode
1860                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1861             final PhylogenyNode n4 = PhylogenyNode
1862                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1863             if ( n1.isHasAssignedEvent() ) {
1864                 return false;
1865             }
1866             if ( PhylogenyNode.getNodeCount() != 4 ) {
1867                 return false;
1868             }
1869             if ( n3.getIndicator() != 0 ) {
1870                 return false;
1871             }
1872             if ( n3.getNumberOfExternalNodes() != 1 ) {
1873                 return false;
1874             }
1875             if ( !n3.isExternal() ) {
1876                 return false;
1877             }
1878             if ( !n3.isRoot() ) {
1879                 return false;
1880             }
1881             if ( !n4.getName().equals( "n4" ) ) {
1882                 return false;
1883             }
1884         }
1885         catch ( final Exception e ) {
1886             e.printStackTrace( System.out );
1887             return false;
1888         }
1889         return true;
1890     }
1891
1892     private static boolean testCommonPrefix() {
1893         final List<String> l0 = new ArrayList<>();
1894         l0.add( "abc" );
1895         if ( !ForesterUtil.greatestCommonPrefix( l0 ).equals( "abc" ) ) {
1896             return false;
1897         }
1898         final List<String> l1 = new ArrayList<>();
1899         l1.add( "abc" );
1900         l1.add( "abX" );
1901         if ( !ForesterUtil.greatestCommonPrefix( l1 ).equals( "ab" ) ) {
1902             return false;
1903         }
1904         final List<String> l2 = new ArrayList<>();
1905         l2.add( "abc" );
1906         l2.add( "abX" );
1907         l2.add( "axy" );
1908         if ( !ForesterUtil.greatestCommonPrefix( l2 ).equals( "a" ) ) {
1909             return false;
1910         }
1911         final List<String> l3 = new ArrayList<>();
1912         l3.add( "abXsdfsdfsdfsdfsdfsd" );
1913         l3.add( "abXsdfsdfsdfsdfsdfsd" );
1914         l3.add( "abc" );
1915         l3.add( "abXsdfsdfsdfsdfsdfsd" );
1916         l3.add( "ab" );
1917         l3.add( "abc" );
1918         l3.add( "ab" );
1919         if ( !ForesterUtil.greatestCommonPrefix( l3 ).equals( "ab" ) ) {
1920             return false;
1921         }
1922         final List<String> l4 = new ArrayList<>();
1923         l4.add( "abXsdfsdfsdfsdfsdfsd" );
1924         l4.add( "abXsdfsdfsdfsdfsdfsd" );
1925         l4.add( "abc" );
1926         l4.add( "Xsdfsdfsdfsdfsdfsd" );
1927         l4.add( "ab" );
1928         l4.add( "abc" );
1929         if ( !ForesterUtil.greatestCommonPrefix( l4 ).equals( "" ) ) {
1930             return false;
1931         }
1932         final List<String> l5 = new ArrayList<>();
1933         l5.add( "" );
1934         if ( !ForesterUtil.greatestCommonPrefix( l5 ).equals( "" ) ) {
1935             return false;
1936         }
1937         final List<String> l6 = new ArrayList<>();
1938         l6.add( "abc" );
1939         l6.add( "abX" );
1940         l6.add( "" );
1941         if ( !ForesterUtil.greatestCommonPrefix( l6 ).equals( "" ) ) {
1942             return false;
1943         }
1944         return true;
1945     }
1946
1947     private static boolean testCommonPrefixSep() {
1948         final List<String> l0 = new ArrayList<>();
1949         l0.add( "a.b.c" );
1950         if ( !ForesterUtil.greatestCommonPrefix( l0, "." ).equals( "a.b.c" ) ) {
1951             return false;
1952         }
1953         final List<String> l1 = new ArrayList<>();
1954         l1.add( "a.b.c" );
1955         l1.add( "a.b.X" );
1956         if ( !ForesterUtil.greatestCommonPrefix( l1, "." ).equals( "a.b" ) ) {
1957             return false;
1958         }
1959         final List<String> l2 = new ArrayList<>();
1960         l2.add( "a.b.c." );
1961         l2.add( "a.b.X." );
1962         l2.add( "a.x.y." );
1963         if ( !ForesterUtil.greatestCommonPrefix( l2, "." ).equals( "a" ) ) {
1964             return false;
1965         }
1966         final List<String> l3 = new ArrayList<>();
1967         l3.add( "a/b/X/s/d/f/s/d/f/s/d/f/s/d/f/s/d/f/s/d/" );
1968         l3.add( "a/b/X/s/d/f/s/d/f/s/d/f/s/d/f/s/d/f/s/d" );
1969         l3.add( "a/b/c" );
1970         l3.add( "a/b/X/s/d/f/s/d/f/s/d/f/s/d/f/s/d/f/s/d/" );
1971         l3.add( "a/b/" );
1972         l3.add( "a/b/c/" );
1973         l3.add( "a/b////////" );
1974         if ( !ForesterUtil.greatestCommonPrefix( l3, "/" ).equals( "a/b" ) ) {
1975             return false;
1976         }
1977         final List<String> l4 = new ArrayList<>();
1978         l4.add( "a.b.X.s.d.f.s.d.f.s.d.f.s.d.f.s.d.f.s.d" );
1979         l4.add( "a.b.X.s.d.f.s.d.f.s.d.f.s.d.f.s.d.f.s.d" );
1980         l4.add( "a.b.c" );
1981         l4.add( "X.s.d.f.s.d.f.s.d.f.s.d.f.s.d.f.s.d..." );
1982         l4.add( "a.b" );
1983         l4.add( "a.b.c" );
1984         if ( !ForesterUtil.greatestCommonPrefix( l4, "." ).equals( "" ) ) {
1985             return false;
1986         }
1987         final List<String> l5 = new ArrayList<>();
1988         l5.add( "" );
1989         if ( !ForesterUtil.greatestCommonPrefix( l5, "_" ).equals( "" ) ) {
1990             return false;
1991         }
1992         final List<String> l6 = new ArrayList<>();
1993         l6.add( "_" );
1994         l6.add( "__" );
1995         if ( !ForesterUtil.greatestCommonPrefix( l6, "_" ).equals( "" ) ) {
1996             return false;
1997         }
1998         final List<String> l7 = new ArrayList<>();
1999         l7.add( "a,b,c" );
2000         l7.add( "a,b,X" );
2001         l7.add( "" );
2002         l7.add( ",,,,,,,,,," );
2003         if ( !ForesterUtil.greatestCommonPrefix( l7, "," ).equals( "" ) ) {
2004             return false;
2005         }
2006         final List<String> l8 = new ArrayList<>();
2007         l8.add( "123.304.403.04" );
2008         l8.add( "123.304.403.04.02" );
2009         l8.add( "123.304.403.03.03" );
2010         if ( !ForesterUtil.greatestCommonPrefix( l8, "." ).equals( "123.304.403" ) ) {
2011             return false;
2012         }
2013         final List<String> l9 = new ArrayList<>();
2014         l9.add( "123.304.403.04" );
2015         l9.add( "123.304.403.04.02" );
2016         l9.add( "123.304.402.03.03" );
2017         if ( !ForesterUtil.greatestCommonPrefix( l9, "." ).equals( "123.304" ) ) {
2018             return false;
2019         }
2020         final List<String> l10 = new ArrayList<>();
2021         l10.add( "abcde" );
2022         l10.add( "adc" );
2023         if ( !ForesterUtil.greatestCommonPrefix( l10, "." ).equals( "" ) ) {
2024             return false;
2025         }
2026         return true;
2027     }
2028
2029     private static boolean testContainsPrefix() {
2030         if ( !ForesterUtil.isContainsPrefix( "a.b", "a", "." ) ) {
2031             return false;
2032         }
2033         if ( !ForesterUtil.isContainsPrefix( "a.b.c", "a", "." ) ) {
2034             return false;
2035         }
2036         if ( !ForesterUtil.isContainsPrefix( "a.b.c", "a.b", "." ) ) {
2037             return false;
2038         }
2039         if ( !ForesterUtil.isContainsPrefix( "a.b", "a.b", "." ) ) {
2040             return false;
2041         }
2042         if ( !ForesterUtil.isContainsPrefix( "a", "a", "." ) ) {
2043             return false;
2044         }
2045         if ( !ForesterUtil.isContainsPrefix( ".a.b", ".a", "." ) ) {
2046             return false;
2047         }
2048         if ( !ForesterUtil.isContainsPrefix( ".a.b.", ".a", "." ) ) {
2049             return false;
2050         }
2051         if ( !ForesterUtil.isContainsPrefix( ".a.b.", ".a.", "." ) ) {
2052             return false;
2053         }
2054         if ( !ForesterUtil.isContainsPrefix( "a..b.", "a", "." ) ) {
2055             return false;
2056         }
2057         if ( !ForesterUtil.isContainsPrefix( "a..b.", "a..", "." ) ) {
2058             return false;
2059         }
2060         if ( ForesterUtil.isContainsPrefix( "a", "a.b", "." ) ) {
2061             return false;
2062         }
2063         if ( ForesterUtil.isContainsPrefix( "a_b", "a", "." ) ) {
2064             return false;
2065         }
2066         if ( ForesterUtil.isContainsPrefix( ".a.", ".a.b.", "." ) ) {
2067             return false;
2068         }
2069         if ( ForesterUtil.isContainsPrefix( "a.b.c", "a.x", "." ) ) {
2070             return false;
2071         }
2072         return true;
2073     }
2074
2075     private static boolean testUTF8ParsingFromFile() {
2076         try {
2077             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2078             final Phylogeny[] phylogenies_xml = ParserBasedPhylogenyFactory.getInstance()
2079                     .create( new File( Test.PATH_TO_TEST_DATA + "chars.xml" ), xml_parser );
2080             if ( xml_parser.getErrorCount() > 0 ) {
2081                 System.out.println( xml_parser.getErrorMessages().toString() );
2082                 return false;
2083             }
2084             if ( phylogenies_xml.length != 1 ) {
2085                 return false;
2086             }
2087             final Phylogeny[] phylogenies_xml2 = ParserBasedPhylogenyFactory.getInstance()
2088                     .create( new StringBuffer( phylogenies_xml[ 0 ].toPhyloXML( 0 ) ), xml_parser );
2089             final Phylogeny[] phylogenies_nh = ParserBasedPhylogenyFactory.getInstance()
2090                     .create( new File( Test.PATH_TO_TEST_DATA + "chars.nh" ), new NHXParser() );
2091             if ( phylogenies_nh.length != 1 ) {
2092                 return false;
2093             }
2094             final Phylogeny[] phylogenies_nex = ParserBasedPhylogenyFactory.getInstance()
2095                     .create( new File( Test.PATH_TO_TEST_DATA + "chars.nex" ), new NexusPhylogeniesParser() );
2096             if ( phylogenies_nex.length != 1 ) {
2097                 return false;
2098             }
2099             final String[] xml_n = phylogenies_xml[ 0 ].getAllExternalNodeNames();
2100             final String[] xml_n2 = phylogenies_xml2[ 0 ].getAllExternalNodeNames();
2101             final String[] nh_n = phylogenies_nh[ 0 ].getAllExternalNodeNames();
2102             final String[] nex_n = phylogenies_nex[ 0 ].getAllExternalNodeNames();
2103             final String n0 = "AQ~!@#$%^&*()_+-=\\{}|;:\"<>?,./";
2104             final String n1 = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ";
2105             final String n2 = "漢字ひらがなカタカナ";
2106             final String n3 = "อักษรไทย";
2107             final String n4 = "繁體字";
2108             final String n5 = "한글";
2109             final String n6 = "देवनागरी";
2110             final String n7 = "chữ Quốc ngữ";
2111             final String n8 = "ру́сский язы́к";
2112             final String n9 = "អក្សរខ្មែរ";
2113             if ( !xml_n[ 0 ].equals( n0 ) ) {
2114                 System.out.println( xml_n[ 0 ] );
2115                 System.out.println( n0 );
2116                 return false;
2117             }
2118             if ( !xml_n2[ 0 ].equals( n0 ) ) {
2119                 System.out.println( xml_n2[ 0 ] );
2120                 System.out.println( n0 );
2121                 return false;
2122             }
2123             if ( !nh_n[ 0 ].equals( n0 ) ) {
2124                 System.out.println( nh_n[ 0 ] );
2125                 System.out.println( n0 );
2126                 return false;
2127             }
2128             if ( !nex_n[ 0 ].equals( n0 ) ) {
2129                 System.out.println( nex_n[ 0 ] );
2130                 System.out.println( n0 );
2131                 return false;
2132             }
2133             if ( !xml_n[ 1 ].equals( n1 ) ) {
2134                 System.out.println( xml_n[ 1 ] );
2135                 System.out.println( n1 );
2136                 return false;
2137             }
2138             if ( !xml_n2[ 1 ].equals( n1 ) ) {
2139                 System.out.println( xml_n2[ 1 ] );
2140                 System.out.println( n1 );
2141                 return false;
2142             }
2143             if ( !nh_n[ 1 ].equals( n1 ) ) {
2144                 System.out.println( nh_n[ 1 ] );
2145                 System.out.println( n1 );
2146                 return false;
2147             }
2148             if ( !nex_n[ 1 ].equals( n1 ) ) {
2149                 System.out.println( nex_n[ 1 ] );
2150                 System.out.println( n1 );
2151                 return false;
2152             }
2153             if ( !xml_n[ 2 ].equals( n2 ) ) {
2154                 System.out.println( xml_n[ 2 ] );
2155                 System.out.println( n2 );
2156                 return false;
2157             }
2158             if ( !xml_n2[ 2 ].equals( n2 ) ) {
2159                 System.out.println( xml_n2[ 2 ] );
2160                 System.out.println( n2 );
2161                 return false;
2162             }
2163             if ( !nh_n[ 2 ].equals( n2 ) ) {
2164                 System.out.println( nh_n[ 2 ] );
2165                 System.out.println( n2 );
2166                 return false;
2167             }
2168             if ( !nex_n[ 2 ].equals( n2 ) ) {
2169                 System.out.println( nex_n[ 2 ] );
2170                 System.out.println( n2 );
2171                 return false;
2172             }
2173             //
2174             if ( !xml_n[ 3 ].equals( n3 ) ) {
2175                 System.out.println( xml_n[ 3 ] );
2176                 System.out.println( n3 );
2177                 return false;
2178             }
2179             if ( !xml_n2[ 3 ].equals( n3 ) ) {
2180                 System.out.println( xml_n2[ 3 ] );
2181                 System.out.println( n3 );
2182                 return false;
2183             }
2184             if ( !nh_n[ 3 ].equals( n3 ) ) {
2185                 System.out.println( nh_n[ 3 ] );
2186                 System.out.println( n3 );
2187                 return false;
2188             }
2189             if ( !nex_n[ 3 ].equals( n3 ) ) {
2190                 System.out.println( nex_n[ 3 ] );
2191                 System.out.println( n3 );
2192                 return false;
2193             }
2194             //
2195             if ( !xml_n[ 4 ].equals( n4 ) ) {
2196                 System.out.println( xml_n[ 4 ] );
2197                 System.out.println( n4 );
2198                 return false;
2199             }
2200             if ( !nh_n[ 4 ].equals( n4 ) ) {
2201                 System.out.println( nh_n[ 4 ] );
2202                 System.out.println( n4 );
2203                 return false;
2204             }
2205             if ( !nex_n[ 4 ].equals( n4 ) ) {
2206                 System.out.println( nex_n[ 4 ] );
2207                 System.out.println( n4 );
2208                 return false;
2209             }
2210             //
2211             if ( !xml_n[ 5 ].equals( n5 ) ) {
2212                 System.out.println( xml_n[ 5 ] );
2213                 System.out.println( n5 );
2214                 return false;
2215             }
2216             if ( !nh_n[ 5 ].equals( n5 ) ) {
2217                 System.out.println( nh_n[ 5 ] );
2218                 System.out.println( n5 );
2219                 return false;
2220             }
2221             if ( !nex_n[ 5 ].equals( n5 ) ) {
2222                 System.out.println( nex_n[ 5 ] );
2223                 System.out.println( n5 );
2224                 return false;
2225             }
2226             //
2227             if ( !xml_n[ 6 ].equals( n6 ) ) {
2228                 System.out.println( xml_n[ 6 ] );
2229                 System.out.println( n6 );
2230                 return false;
2231             }
2232             if ( !nh_n[ 6 ].equals( n6 ) ) {
2233                 System.out.println( nh_n[ 6 ] );
2234                 System.out.println( n6 );
2235                 return false;
2236             }
2237             if ( !nex_n[ 6 ].equals( n6 ) ) {
2238                 System.out.println( nex_n[ 6 ] );
2239                 System.out.println( n6 );
2240                 return false;
2241             }
2242             //
2243             if ( !xml_n[ 7 ].equals( n7 ) ) {
2244                 System.out.println( xml_n[ 7 ] );
2245                 System.out.println( n7 );
2246                 return false;
2247             }
2248             if ( !nh_n[ 7 ].equals( n7 ) ) {
2249                 System.out.println( nh_n[ 7 ] );
2250                 System.out.println( n7 );
2251                 return false;
2252             }
2253             if ( !nex_n[ 7 ].equals( n7 ) ) {
2254                 System.out.println( nex_n[ 7 ] );
2255                 System.out.println( n7 );
2256                 return false;
2257             }
2258             if ( !xml_n[ 8 ].equals( n8 ) ) {
2259                 System.out.println( xml_n[ 8 ] );
2260                 System.out.println( n8 );
2261                 return false;
2262             }
2263             if ( !nh_n[ 8 ].equals( n8 ) ) {
2264                 System.out.println( nh_n[ 8 ] );
2265                 System.out.println( n8 );
2266                 return false;
2267             }
2268             if ( !nex_n[ 8 ].equals( n8 ) ) {
2269                 System.out.println( nex_n[ 8 ] );
2270                 System.out.println( n8 );
2271                 return false;
2272             }
2273             if ( !xml_n[ 9 ].equals( n9 ) ) {
2274                 System.out.println( xml_n[ 9 ] );
2275                 System.out.println( n9 );
2276                 return false;
2277             }
2278             if ( !xml_n2[ 9 ].equals( n9 ) ) {
2279                 System.out.println( xml_n2[ 9 ] );
2280                 System.out.println( n9 );
2281                 return false;
2282             }
2283             if ( !nh_n[ 9 ].equals( n9 ) ) {
2284                 System.out.println( nh_n[ 9 ] );
2285                 System.out.println( n9 );
2286                 return false;
2287             }
2288             if ( !nex_n[ 9 ].equals( n9 ) ) {
2289                 System.out.println( nex_n[ 9 ] );
2290                 System.out.println( n9 );
2291                 return false;
2292             }
2293             if ( !phylogenies_xml[ 0 ].toNewHampshire().equals( phylogenies_nh[ 0 ].toNewHampshire() ) ) {
2294                 System.out.println( phylogenies_xml[ 0 ].toNewHampshire() );
2295                 System.out.println( phylogenies_nh[ 0 ].toNewHampshire() );
2296                 return false;
2297             }
2298             if ( !phylogenies_xml[ 0 ].toNewHampshire().equals( phylogenies_nex[ 0 ].toNewHampshire() ) ) {
2299                 System.out.println( phylogenies_xml[ 0 ].toNewHampshire() );
2300                 System.out.println( phylogenies_nex[ 0 ].toNewHampshire() );
2301                 return false;
2302             }
2303         }
2304         catch ( final Exception e ) {
2305             e.printStackTrace( System.out );
2306             return false;
2307         }
2308         return true;
2309     }
2310
2311     private static boolean testBasicPhyloXMLparsing() {
2312         try {
2313             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2314             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2315             final Phylogeny[] phylogenies_0 = factory
2316                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ), xml_parser );
2317             if ( xml_parser.getErrorCount() > 0 ) {
2318                 System.out.println( xml_parser.getErrorMessages().toString() );
2319                 return false;
2320             }
2321             if ( phylogenies_0.length != 4 ) {
2322                 return false;
2323             }
2324             final Phylogeny t1 = phylogenies_0[ 0 ];
2325             final Phylogeny t2 = phylogenies_0[ 1 ];
2326             final Phylogeny t3 = phylogenies_0[ 2 ];
2327             final Phylogeny t4 = phylogenies_0[ 3 ];
2328             if ( t1.getNumberOfExternalNodes() != 1 ) {
2329                 return false;
2330             }
2331             if ( !t1.isRooted() ) {
2332                 return false;
2333             }
2334             if ( t1.isRerootable() ) {
2335                 return false;
2336             }
2337             if ( !t1.getType().equals( "gene_tree" ) ) {
2338                 return false;
2339             }
2340             if ( t2.getNumberOfExternalNodes() != 2 ) {
2341                 return false;
2342             }
2343             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
2344                 return false;
2345             }
2346             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
2347                 return false;
2348             }
2349             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2350                 return false;
2351             }
2352             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2353                 return false;
2354             }
2355             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2356                 return false;
2357             }
2358             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2359                 return false;
2360             }
2361             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2362                     .startsWith( "actgtgggggt" ) ) {
2363                 return false;
2364             }
2365             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2366                     .startsWith( "ctgtgatgcat" ) ) {
2367                 return false;
2368             }
2369             if ( t3.getNumberOfExternalNodes() != 4 ) {
2370                 return false;
2371             }
2372             if ( !t1.getName().equals( "t1" ) ) {
2373                 return false;
2374             }
2375             if ( !t2.getName().equals( "t2" ) ) {
2376                 return false;
2377             }
2378             if ( !t3.getName().equals( "t3" ) ) {
2379                 return false;
2380             }
2381             if ( !t4.getName().equals( "t4" ) ) {
2382                 return false;
2383             }
2384             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
2385                 return false;
2386             }
2387             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
2388                 return false;
2389             }
2390             if ( !t3.getNode( "root node" ).isDuplication() ) {
2391                 return false;
2392             }
2393             if ( !t3.getNode( "node a" ).isDuplication() ) {
2394                 return false;
2395             }
2396             if ( t3.getNode( "node a" ).isSpeciation() ) {
2397                 return false;
2398             }
2399             if ( t3.getNode( "node bc" ).isDuplication() ) {
2400                 return false;
2401             }
2402             if ( !t3.getNode( "node bc" ).isSpeciation() ) {
2403                 return false;
2404             }
2405             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2406                 return false;
2407             }
2408             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
2409                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2410                 return false;
2411             }
2412             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2413                 return false;
2414             }
2415             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2416                 return false;
2417             }
2418             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2419                     .equals( "UniProtKB" ) ) {
2420                 return false;
2421             }
2422             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2423                     .equals( "apoptosis" ) ) {
2424                 return false;
2425             }
2426             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2427                     .equals( "GO:0006915" ) ) {
2428                 return false;
2429             }
2430             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2431                     .equals( "UniProtKB" ) ) {
2432                 return false;
2433             }
2434             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2435                     .equals( "experimental" ) ) {
2436                 return false;
2437             }
2438             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2439                     .equals( "function" ) ) {
2440                 return false;
2441             }
2442             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2443                     .getValue() != 1 ) {
2444                 return false;
2445             }
2446             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence().getType()
2447                     .equals( "ml" ) ) {
2448                 return false;
2449             }
2450             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2451                     .equals( "apoptosis" ) ) {
2452                 return false;
2453             }
2454             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2455                     .getProperties( "AFFY:expression" ).get( 0 ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2456                 return false;
2457             }
2458             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2459                     .getProperties( "AFFY:expression" ).get( 0 ).getDataType().equals( "xsd:double" ) ) {
2460                 return false;
2461             }
2462             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2463                     .getProperties( "AFFY:expression" ).get( 0 ).getRef().equals( "AFFY:expression" ) ) {
2464                 return false;
2465             }
2466             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2467                     .getProperties( "AFFY:expression" ).get( 0 ).getUnit().equals( "AFFY:x" ) ) {
2468                 return false;
2469             }
2470             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2471                     .getProperties( "AFFY:expression" ).get( 0 ).getValue().equals( "0.2" ) ) {
2472                 return false;
2473             }
2474             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2475                     .getProperties( "MED:disease" ).get( 0 ).getValue().equals( "lymphoma" ) ) {
2476                 return false;
2477             }
2478             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2479                     .equals( "GO:0005829" ) ) {
2480                 return false;
2481             }
2482             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2483                     .equals( "intracellular organelle" ) ) {
2484                 return false;
2485             }
2486             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2487                 return false;
2488             }
2489             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2490                     .equals( "UniProt link" ) ) ) {
2491                 return false;
2492             }
2493             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2494                 return false;
2495             }
2496             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
2497             if ( x.size() != 4 ) {
2498                 return false;
2499             }
2500             int c = 0;
2501             for( final Accession acc : x ) {
2502                 if ( c == 0 ) {
2503                     if ( !acc.getSource().equals( "KEGG" ) ) {
2504                         return false;
2505                     }
2506                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2507                         return false;
2508                     }
2509                 }
2510                 c++;
2511             }
2512         }
2513         catch ( final Exception e ) {
2514             e.printStackTrace( System.out );
2515             return false;
2516         }
2517         return true;
2518     }
2519
2520     private static boolean testBasicPhyloXMLparsingRoundtrip() {
2521         try {
2522             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2523             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2524             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2525                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2526             }
2527             else {
2528                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2529             }
2530             final Phylogeny[] phylogenies_0 = factory
2531                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ), xml_parser );
2532             if ( xml_parser.getErrorCount() > 0 ) {
2533                 System.out.println( xml_parser.getErrorMessages().toString() );
2534                 return false;
2535             }
2536             if ( phylogenies_0.length != 4 ) {
2537                 return false;
2538             }
2539             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
2540             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
2541             if ( phylogenies_t1.length != 1 ) {
2542                 return false;
2543             }
2544             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
2545             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
2546                 return false;
2547             }
2548             if ( !t1_rt.isRooted() ) {
2549                 return false;
2550             }
2551             if ( t1_rt.isRerootable() ) {
2552                 return false;
2553             }
2554             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
2555                 return false;
2556             }
2557             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
2558             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
2559             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
2560             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2561                 return false;
2562             }
2563             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2564                 return false;
2565             }
2566             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2567                 return false;
2568             }
2569             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2570                 return false;
2571             }
2572             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2573                     .startsWith( "actgtgggggt" ) ) {
2574                 return false;
2575             }
2576             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2577                     .startsWith( "ctgtgatgcat" ) ) {
2578                 return false;
2579             }
2580             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
2581             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
2582             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
2583             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
2584             if ( phylogenies_1.length != 1 ) {
2585                 return false;
2586             }
2587             final Phylogeny t3_rt = phylogenies_1[ 0 ];
2588             if ( !t3_rt.getName().equals( "t3" ) ) {
2589                 return false;
2590             }
2591             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
2592                 return false;
2593             }
2594             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
2595                 return false;
2596             }
2597             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
2598                 return false;
2599             }
2600             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2601                 return false;
2602             }
2603             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
2604                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2605                 return false;
2606             }
2607             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2608                 return false;
2609             }
2610             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue()
2611                     .equals( "Q9BZR8" ) ) {
2612                 return false;
2613             }
2614             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2615                     .equals( "UniProtKB" ) ) {
2616                 return false;
2617             }
2618             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2619                     .equals( "apoptosis" ) ) {
2620                 return false;
2621             }
2622             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2623                     .equals( "GO:0006915" ) ) {
2624                 return false;
2625             }
2626             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2627                     .equals( "UniProtKB" ) ) {
2628                 return false;
2629             }
2630             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2631                     .equals( "experimental" ) ) {
2632                 return false;
2633             }
2634             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2635                     .equals( "function" ) ) {
2636                 return false;
2637             }
2638             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2639                     .getValue() != 1 ) {
2640                 return false;
2641             }
2642             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2643                     .getType().equals( "ml" ) ) {
2644                 return false;
2645             }
2646             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2647                     .equals( "apoptosis" ) ) {
2648                 return false;
2649             }
2650             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2651                     .getProperties( "AFFY:expression" ).get( 0 ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2652                 return false;
2653             }
2654             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2655                     .getProperties( "AFFY:expression" ).get( 0 ).getDataType().equals( "xsd:double" ) ) {
2656                 return false;
2657             }
2658             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2659                     .getProperties( "AFFY:expression" ).get( 0 ).getRef().equals( "AFFY:expression" ) ) {
2660                 return false;
2661             }
2662             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2663                     .getProperties( "AFFY:expression" ).get( 0 ).getUnit().equals( "AFFY:x" ) ) {
2664                 return false;
2665             }
2666             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2667                     .getProperties( "AFFY:expression" ).get( 0 ).getValue().equals( "0.2" ) ) {
2668                 return false;
2669             }
2670             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2671                     .getProperties( "MED:disease" ).get( 0 ).getValue().equals( "lymphoma" ) ) {
2672                 return false;
2673             }
2674             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2675                     .equals( "GO:0005829" ) ) {
2676                 return false;
2677             }
2678             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2679                     .equals( "intracellular organelle" ) ) {
2680                 return false;
2681             }
2682             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType()
2683                     .equals( "source" ) ) ) {
2684                 return false;
2685             }
2686             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2687                     .equals( "UniProt link" ) ) ) {
2688                 return false;
2689             }
2690             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2691                 return false;
2692             }
2693             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi()
2694                     .equals( "10.1038/387489a0" ) ) ) {
2695                 return false;
2696             }
2697             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2698                     .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." ) ) ) {
2699                 System.out.println( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription() );
2700                 return false;
2701             }
2702             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2703                 return false;
2704             }
2705             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2706                 return false;
2707             }
2708             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName()
2709                     .equals( "molting animals" ) ) {
2710                 return false;
2711             }
2712             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2713                 return false;
2714             }
2715             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2716                     .equals( "ncbi" ) ) {
2717                 return false;
2718             }
2719             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture()
2720                     .getTotalLength() != 124 ) {
2721                 return false;
2722             }
2723             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2724                     .getName().equals( "B" ) ) {
2725                 return false;
2726             }
2727             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2728                     .getFrom() != 21 ) {
2729                 return false;
2730             }
2731             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2732                     .getTo() != 44 ) {
2733                 return false;
2734             }
2735             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2736                     .getLength() != 24 ) {
2737                 return false;
2738             }
2739             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2740                     .getConfidence() != 0 ) {
2741                 return false;
2742             }
2743             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2744                     .equals( "pfam" ) ) {
2745                 return false;
2746             }
2747             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2748                 return false;
2749             }
2750             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2751                 return false;
2752             }
2753             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2754                 return false;
2755             }
2756             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2757                 return false;
2758             }
2759             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2760             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2761                 return false;
2762             }
2763             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2764                 return false;
2765             }
2766             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2767                 return false;
2768             }
2769             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2770                 return false;
2771             }
2772             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2773                 return false;
2774             }
2775             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2776                 return false;
2777             }
2778             if ( taxbb.getSynonyms().size() != 2 ) {
2779                 return false;
2780             }
2781             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2782                 return false;
2783             }
2784             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2785                 return false;
2786             }
2787             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2788                 return false;
2789             }
2790             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2791                 return false;
2792             }
2793             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2794                 return false;
2795             }
2796             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2797                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2798                 return false;
2799             }
2800             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2801                 return false;
2802             }
2803             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2804                 return false;
2805             }
2806             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2807                 return false;
2808             }
2809             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2810                 return false;
2811             }
2812             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2813                 return false;
2814             }
2815             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2816                 return false;
2817             }
2818             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2819                 return false;
2820             }
2821             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2822                 return false;
2823             }
2824             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2825                     .equalsIgnoreCase( "435" ) ) {
2826                 return false;
2827             }
2828             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString()
2829                     .equalsIgnoreCase( "416" ) ) {
2830                 return false;
2831             }
2832             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2833                     .equalsIgnoreCase( "443.7" ) ) {
2834                 return false;
2835             }
2836             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2837                 return false;
2838             }
2839             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2840                 return false;
2841             }
2842             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2843                     .equalsIgnoreCase( "433" ) ) {
2844                 return false;
2845             }
2846             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2847                     .getCrossReferences();
2848             if ( x.size() != 4 ) {
2849                 return false;
2850             }
2851             int c = 0;
2852             for( final Accession acc : x ) {
2853                 if ( c == 0 ) {
2854                     if ( !acc.getSource().equals( "KEGG" ) ) {
2855                         return false;
2856                     }
2857                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2858                         return false;
2859                     }
2860                 }
2861                 c++;
2862             }
2863         }
2864         catch ( final Exception e ) {
2865             e.printStackTrace( System.out );
2866             return false;
2867         }
2868         return true;
2869     }
2870
2871     private static boolean testBasicPhyloXMLparsingValidating() {
2872         try {
2873             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2874             PhyloXmlParser xml_parser = null;
2875             try {
2876                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2877             }
2878             catch ( final Exception e ) {
2879                 // Do nothing -- means were not running from jar.
2880             }
2881             if ( xml_parser == null ) {
2882                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2883                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2884                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2885                 }
2886                 else {
2887                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2888                 }
2889             }
2890             final Phylogeny[] phylogenies_0 = factory
2891                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ), xml_parser );
2892             if ( xml_parser.getErrorCount() > 0 ) {
2893                 System.out.println( xml_parser.getErrorMessages().toString() );
2894                 return false;
2895             }
2896             if ( phylogenies_0.length != 4 ) {
2897                 return false;
2898             }
2899             final Phylogeny t1 = phylogenies_0[ 0 ];
2900             final Phylogeny t2 = phylogenies_0[ 1 ];
2901             final Phylogeny t3 = phylogenies_0[ 2 ];
2902             final Phylogeny t4 = phylogenies_0[ 3 ];
2903             if ( !t1.getName().equals( "t1" ) ) {
2904                 return false;
2905             }
2906             if ( !t2.getName().equals( "t2" ) ) {
2907                 return false;
2908             }
2909             if ( !t3.getName().equals( "t3" ) ) {
2910                 return false;
2911             }
2912             if ( !t4.getName().equals( "t4" ) ) {
2913                 return false;
2914             }
2915             if ( t1.getNumberOfExternalNodes() != 1 ) {
2916                 return false;
2917             }
2918             if ( t2.getNumberOfExternalNodes() != 2 ) {
2919                 return false;
2920             }
2921             if ( t3.getNumberOfExternalNodes() != 4 ) {
2922                 return false;
2923             }
2924             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2925             final Phylogeny[] phylogenies_1 = factory.create( new File( x2 ), xml_parser );
2926             if ( xml_parser.getErrorCount() > 0 ) {
2927                 System.out.println( "errors:" );
2928                 System.out.println( xml_parser.getErrorMessages().toString() );
2929                 return false;
2930             }
2931             if ( phylogenies_1.length != 4 ) {
2932                 return false;
2933             }
2934             final Phylogeny[] phylogenies_2 = factory
2935                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml" ), xml_parser );
2936             if ( xml_parser.getErrorCount() > 0 ) {
2937                 System.out.println( "errors:" );
2938                 System.out.println( xml_parser.getErrorMessages().toString() );
2939                 return false;
2940             }
2941             if ( phylogenies_2.length != 1 ) {
2942                 return false;
2943             }
2944             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2945                 return false;
2946             }
2947             final Phylogeny[] phylogenies_3 = factory
2948                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml" ), xml_parser );
2949             if ( xml_parser.getErrorCount() > 0 ) {
2950                 System.out.println( xml_parser.getErrorMessages().toString() );
2951                 return false;
2952             }
2953             if ( phylogenies_3.length != 2 ) {
2954                 return false;
2955             }
2956             final Phylogeny a = phylogenies_3[ 0 ];
2957             if ( !a.getName().equals( "tree 4" ) ) {
2958                 return false;
2959             }
2960             if ( a.getNumberOfExternalNodes() != 3 ) {
2961                 return false;
2962             }
2963             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2964                 return false;
2965             }
2966             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2967                 return false;
2968             }
2969             final Phylogeny[] phylogenies_4 = factory
2970                     .create( new File( Test.PATH_TO_TEST_DATA + "special_characters.xml" ), xml_parser );
2971             if ( xml_parser.getErrorCount() > 0 ) {
2972                 System.out.println( xml_parser.getErrorMessages().toString() );
2973                 return false;
2974             }
2975             if ( phylogenies_4.length != 1 ) {
2976                 return false;
2977             }
2978             final Phylogeny s = phylogenies_4[ 0 ];
2979             if ( s.getNumberOfExternalNodes() != 6 ) {
2980                 return false;
2981             }
2982             s.getNode( "first" );
2983             s.getNode( "<>" );
2984             s.getNode( "\"<a'b&c'd\">\"" );
2985             s.getNode( "'''\"" );
2986             s.getNode( "\"\"\"" );
2987             s.getNode( "dick & doof" );
2988         }
2989         catch ( final Exception e ) {
2990             e.printStackTrace( System.out );
2991             return false;
2992         }
2993         return true;
2994     }
2995
2996     private static boolean testPhyloXMLparsingValidating() {
2997         try {
2998             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2999             PhyloXmlParser xml_parser = null;
3000             try {
3001                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
3002             }
3003             catch ( final Exception e ) {
3004                 // Do nothing -- means were not running from jar.
3005             }
3006             if ( xml_parser == null ) {
3007                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
3008                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
3009                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
3010                 }
3011                 else {
3012                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
3013                 }
3014             }
3015             final Phylogeny[] phylogenies_0 = factory
3016                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_1.xml" ), xml_parser );
3017             if ( xml_parser.getErrorCount() > 0 ) {
3018                 System.out.println( xml_parser.getErrorMessages().toString() );
3019                 return false;
3020             }
3021             if ( phylogenies_0.length != 3 ) {
3022                 return false;
3023             }
3024         }
3025         catch ( final Exception e ) {
3026             e.printStackTrace( System.out );
3027             return false;
3028         }
3029         return true;
3030     }
3031
3032     private static boolean testBasicProtein() {
3033         try {
3034             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
3035             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
3036             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
3037             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
3038             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
3039             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
3040             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
3041             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
3042             p0.addProteinDomain( y );
3043             p0.addProteinDomain( e );
3044             p0.addProteinDomain( b );
3045             p0.addProteinDomain( c );
3046             p0.addProteinDomain( d );
3047             p0.addProteinDomain( a );
3048             p0.addProteinDomain( x );
3049             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
3050                 return false;
3051             }
3052             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
3053                 return false;
3054             }
3055             //
3056             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
3057             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
3058             aa0.addProteinDomain( a1 );
3059             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
3060                 return false;
3061             }
3062             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
3063                 return false;
3064             }
3065             //
3066             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
3067             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
3068             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
3069             aa1.addProteinDomain( a11 );
3070             aa1.addProteinDomain( a12 );
3071             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
3072                 return false;
3073             }
3074             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
3075                 return false;
3076             }
3077             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
3078             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
3079                 return false;
3080             }
3081             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
3082                 return false;
3083             }
3084             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
3085                 return false;
3086             }
3087             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
3088             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
3089                 return false;
3090             }
3091             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
3092                 return false;
3093             }
3094             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
3095                 return false;
3096             }
3097             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
3098                 return false;
3099             }
3100             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
3101             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
3102                 return false;
3103             }
3104             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
3105                 return false;
3106             }
3107             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
3108                 return false;
3109             }
3110             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
3111                 return false;
3112             }
3113             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
3114             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
3115                 return false;
3116             }
3117             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
3118                 return false;
3119             }
3120             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
3121                 return false;
3122             }
3123             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
3124                 return false;
3125             }
3126             //
3127             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
3128             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
3129             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
3130             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
3131             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
3132             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
3133             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
3134             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
3135             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
3136             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
3137             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
3138             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
3139             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
3140             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
3141             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
3142             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
3143             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
3144             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
3145             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
3146             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
3147             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
3148             p00.addProteinDomain( y0 );
3149             p00.addProteinDomain( e0 );
3150             p00.addProteinDomain( b0 );
3151             p00.addProteinDomain( c0 );
3152             p00.addProteinDomain( d0 );
3153             p00.addProteinDomain( a0 );
3154             p00.addProteinDomain( x0 );
3155             p00.addProteinDomain( y1 );
3156             p00.addProteinDomain( y2 );
3157             p00.addProteinDomain( y3 );
3158             p00.addProteinDomain( e1 );
3159             p00.addProteinDomain( e2 );
3160             p00.addProteinDomain( e3 );
3161             p00.addProteinDomain( e4 );
3162             p00.addProteinDomain( e5 );
3163             p00.addProteinDomain( z0 );
3164             p00.addProteinDomain( z1 );
3165             p00.addProteinDomain( z2 );
3166             p00.addProteinDomain( zz0 );
3167             p00.addProteinDomain( zz1 );
3168             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
3169                 return false;
3170             }
3171             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
3172                 return false;
3173             }
3174             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
3175                 return false;
3176             }
3177             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
3178                 return false;
3179             }
3180             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" ) ) {
3181                 return false;
3182             }
3183             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
3184             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
3185             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
3186             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
3187             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
3188             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
3189             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
3190             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
3191             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
3192             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
3193             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
3194             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
3195             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
3196             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
3197             p.addProteinDomain( B15 );
3198             p.addProteinDomain( C50 );
3199             p.addProteinDomain( A60 );
3200             p.addProteinDomain( A30 );
3201             p.addProteinDomain( C70 );
3202             p.addProteinDomain( B35 );
3203             p.addProteinDomain( B40 );
3204             p.addProteinDomain( A0 );
3205             p.addProteinDomain( A10 );
3206             p.addProteinDomain( A20 );
3207             p.addProteinDomain( B25 );
3208             p.addProteinDomain( D80 );
3209             List<String> domains_ids = new ArrayList<>();
3210             domains_ids.add( "A" );
3211             domains_ids.add( "B" );
3212             domains_ids.add( "C" );
3213             if ( !p.contains( domains_ids, false ) ) {
3214                 return false;
3215             }
3216             if ( !p.contains( domains_ids, true ) ) {
3217                 return false;
3218             }
3219             domains_ids.add( "X" );
3220             if ( p.contains( domains_ids, false ) ) {
3221                 return false;
3222             }
3223             if ( p.contains( domains_ids, true ) ) {
3224                 return false;
3225             }
3226             domains_ids = new ArrayList<>();
3227             domains_ids.add( "A" );
3228             domains_ids.add( "C" );
3229             domains_ids.add( "D" );
3230             if ( !p.contains( domains_ids, false ) ) {
3231                 return false;
3232             }
3233             if ( !p.contains( domains_ids, true ) ) {
3234                 return false;
3235             }
3236             domains_ids = new ArrayList<>();
3237             domains_ids.add( "A" );
3238             domains_ids.add( "D" );
3239             domains_ids.add( "C" );
3240             if ( !p.contains( domains_ids, false ) ) {
3241                 return false;
3242             }
3243             if ( p.contains( domains_ids, true ) ) {
3244                 return false;
3245             }
3246             domains_ids = new ArrayList<>();
3247             domains_ids.add( "A" );
3248             domains_ids.add( "A" );
3249             domains_ids.add( "B" );
3250             if ( !p.contains( domains_ids, false ) ) {
3251                 return false;
3252             }
3253             if ( !p.contains( domains_ids, true ) ) {
3254                 return false;
3255             }
3256             domains_ids = new ArrayList<>();
3257             domains_ids.add( "A" );
3258             domains_ids.add( "A" );
3259             domains_ids.add( "A" );
3260             domains_ids.add( "B" );
3261             domains_ids.add( "B" );
3262             if ( !p.contains( domains_ids, false ) ) {
3263                 return false;
3264             }
3265             if ( !p.contains( domains_ids, true ) ) {
3266                 return false;
3267             }
3268             domains_ids = new ArrayList<>();
3269             domains_ids.add( "A" );
3270             domains_ids.add( "A" );
3271             domains_ids.add( "B" );
3272             domains_ids.add( "A" );
3273             domains_ids.add( "B" );
3274             domains_ids.add( "B" );
3275             domains_ids.add( "A" );
3276             domains_ids.add( "B" );
3277             domains_ids.add( "C" );
3278             domains_ids.add( "A" );
3279             domains_ids.add( "C" );
3280             domains_ids.add( "D" );
3281             if ( !p.contains( domains_ids, false ) ) {
3282                 return false;
3283             }
3284             if ( p.contains( domains_ids, true ) ) {
3285                 return false;
3286             }
3287         }
3288         catch ( final Exception e ) {
3289             e.printStackTrace( System.out );
3290             return false;
3291         }
3292         return true;
3293     }
3294
3295     private static boolean testBasicTable() {
3296         try {
3297             final BasicTable<String> t0 = new BasicTable<>();
3298             if ( t0.getNumberOfColumns() != 0 ) {
3299                 return false;
3300             }
3301             if ( t0.getNumberOfRows() != 0 ) {
3302                 return false;
3303             }
3304             t0.setValue( 3, 2, "23" );
3305             t0.setValue( 10, 1, "error" );
3306             t0.setValue( 10, 1, "110" );
3307             t0.setValue( 9, 1, "19" );
3308             t0.setValue( 1, 10, "101" );
3309             t0.setValue( 10, 10, "1010" );
3310             t0.setValue( 100, 10, "10100" );
3311             t0.setValue( 0, 0, "00" );
3312             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3313                 return false;
3314             }
3315             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3316                 return false;
3317             }
3318             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3319                 return false;
3320             }
3321             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3322                 return false;
3323             }
3324             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3325                 return false;
3326             }
3327             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3328                 return false;
3329             }
3330             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3331                 return false;
3332             }
3333             if ( t0.getNumberOfColumns() != 101 ) {
3334                 return false;
3335             }
3336             if ( t0.getNumberOfRows() != 11 ) {
3337                 return false;
3338             }
3339             if ( t0.getValueAsString( 49, 4 ) != null ) {
3340                 return false;
3341             }
3342             final String l = ForesterUtil.getLineSeparator();
3343             final StringBuffer source = new StringBuffer();
3344             source.append( "" + l );
3345             source.append( "# 1 1 1 1 1 1 1 1" + l );
3346             source.append( " 00 01 02 03" + l );
3347             source.append( "   10 11 12 13  " + l );
3348             source.append( "20 21 22 23 " + l );
3349             source.append( "    30  31    32 33" + l );
3350             source.append( "40 41 42 43" + l );
3351             source.append( "  # 1 1 1 1 1 " + l );
3352             source.append( "50 51 52 53 54" + l );
3353             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
3354             if ( t1.getNumberOfColumns() != 5 ) {
3355                 return false;
3356             }
3357             if ( t1.getNumberOfRows() != 6 ) {
3358                 return false;
3359             }
3360             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
3361                 return false;
3362             }
3363             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
3364                 return false;
3365             }
3366             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
3367                 return false;
3368             }
3369             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
3370                 return false;
3371             }
3372             final StringBuffer source1 = new StringBuffer();
3373             source1.append( "" + l );
3374             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3375             source1.append( " 00; 01 ;02;03" + l );
3376             source1.append( "   10; 11; 12; 13  " + l );
3377             source1.append( "20; 21; 22; 23 " + l );
3378             source1.append( "    30;  31;    32; 33" + l );
3379             source1.append( "40;41;42;43" + l );
3380             source1.append( "  # 1 1 1 1 1 " + l );
3381             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
3382             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
3383             if ( t2.getNumberOfColumns() != 5 ) {
3384                 return false;
3385             }
3386             if ( t2.getNumberOfRows() != 6 ) {
3387                 return false;
3388             }
3389             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
3390                 return false;
3391             }
3392             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
3393                 return false;
3394             }
3395             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
3396                 return false;
3397             }
3398             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
3399                 return false;
3400             }
3401             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
3402                 return false;
3403             }
3404             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
3405                 return false;
3406             }
3407             final StringBuffer source2 = new StringBuffer();
3408             source2.append( "" + l );
3409             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3410             source2.append( " 00; 01 ;02;03" + l );
3411             source2.append( "   10; 11; 12; 13  " + l );
3412             source2.append( "20; 21; 22; 23 " + l );
3413             source2.append( "                     " + l );
3414             source2.append( "    30;  31;    32; 33" + l );
3415             source2.append( "40;41;42;43" + l );
3416             source2.append( "  comment: 1 1 1 1 1 " + l );
3417             source2.append( ";;;50  ;   52; 53;;54   " + l );
3418             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
3419                                                                         ';',
3420                                                                         false,
3421                                                                         false,
3422                                                                         "comment:",
3423                                                                         false );
3424             if ( tl.size() != 2 ) {
3425                 return false;
3426             }
3427             final BasicTable<String> t3 = tl.get( 0 );
3428             final BasicTable<String> t4 = tl.get( 1 );
3429             if ( t3.getNumberOfColumns() != 4 ) {
3430                 return false;
3431             }
3432             if ( t3.getNumberOfRows() != 3 ) {
3433                 return false;
3434             }
3435             if ( t4.getNumberOfColumns() != 4 ) {
3436                 return false;
3437             }
3438             if ( t4.getNumberOfRows() != 3 ) {
3439                 return false;
3440             }
3441             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
3442                 return false;
3443             }
3444             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
3445                 return false;
3446             }
3447         }
3448         catch ( final Exception e ) {
3449             e.printStackTrace( System.out );
3450             return false;
3451         }
3452         return true;
3453     }
3454
3455     private static boolean testBasicTolXMLparsing() {
3456         try {
3457             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3458             final TolParser parser = new TolParser();
3459             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
3460             if ( parser.getErrorCount() > 0 ) {
3461                 System.out.println( parser.getErrorMessages().toString() );
3462                 return false;
3463             }
3464             if ( phylogenies_0.length != 1 ) {
3465                 return false;
3466             }
3467             final Phylogeny t1 = phylogenies_0[ 0 ];
3468             if ( t1.getNumberOfExternalNodes() != 5 ) {
3469                 return false;
3470             }
3471             if ( !t1.isRooted() ) {
3472                 return false;
3473             }
3474             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
3475                 return false;
3476             }
3477             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
3478                 return false;
3479             }
3480             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3481                     .equals( "Rhombozoa" ) ) {
3482                 return false;
3483             }
3484             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
3485                 return false;
3486             }
3487             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
3488             if ( parser.getErrorCount() > 0 ) {
3489                 System.out.println( parser.getErrorMessages().toString() );
3490                 return false;
3491             }
3492             if ( phylogenies_1.length != 1 ) {
3493                 return false;
3494             }
3495             final Phylogeny t2 = phylogenies_1[ 0 ];
3496             if ( t2.getNumberOfExternalNodes() != 664 ) {
3497                 return false;
3498             }
3499             if ( !t2.isRooted() ) {
3500                 return false;
3501             }
3502             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
3503                 return false;
3504             }
3505             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
3506                 return false;
3507             }
3508             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3509                 return false;
3510             }
3511             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3512                 return false;
3513             }
3514             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3515                     .equals( "Aquificae" ) ) {
3516                 return false;
3517             }
3518             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3519                     .equals( "Aquifex" ) ) {
3520                 return false;
3521             }
3522             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
3523             if ( parser.getErrorCount() > 0 ) {
3524                 System.out.println( parser.getErrorMessages().toString() );
3525                 return false;
3526             }
3527             if ( phylogenies_2.length != 1 ) {
3528                 return false;
3529             }
3530             final Phylogeny t3 = phylogenies_2[ 0 ];
3531             if ( t3.getNumberOfExternalNodes() != 184 ) {
3532                 return false;
3533             }
3534             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
3535                 return false;
3536             }
3537             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
3538                 return false;
3539             }
3540             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
3541                 return false;
3542             }
3543             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
3544             if ( parser.getErrorCount() > 0 ) {
3545                 System.out.println( parser.getErrorMessages().toString() );
3546                 return false;
3547             }
3548             if ( phylogenies_3.length != 1 ) {
3549                 return false;
3550             }
3551             final Phylogeny t4 = phylogenies_3[ 0 ];
3552             if ( t4.getNumberOfExternalNodes() != 1 ) {
3553                 return false;
3554             }
3555             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
3556                 return false;
3557             }
3558             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
3559                 return false;
3560             }
3561             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
3562                 return false;
3563             }
3564             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
3565             if ( parser.getErrorCount() > 0 ) {
3566                 System.out.println( parser.getErrorMessages().toString() );
3567                 return false;
3568             }
3569             if ( phylogenies_4.length != 1 ) {
3570                 return false;
3571             }
3572             final Phylogeny t5 = phylogenies_4[ 0 ];
3573             if ( t5.getNumberOfExternalNodes() != 13 ) {
3574                 return false;
3575             }
3576             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
3577                 return false;
3578             }
3579             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
3580                 return false;
3581             }
3582             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
3583                 return false;
3584             }
3585         }
3586         catch ( final Exception e ) {
3587             e.printStackTrace( System.out );
3588             return false;
3589         }
3590         return true;
3591     }
3592
3593     private static boolean testBasicTreeMethods() {
3594         try {
3595             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3596             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
3597             if ( t2.getNumberOfExternalNodes() != 4 ) {
3598                 return false;
3599             }
3600             if ( t2.calculateHeight( false ) != 8.5 ) {
3601                 return false;
3602             }
3603             if ( !t2.isCompletelyBinary() ) {
3604                 return false;
3605             }
3606             if ( t2.isEmpty() ) {
3607                 return false;
3608             }
3609             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
3610             if ( t3.getNumberOfExternalNodes() != 5 ) {
3611                 return false;
3612             }
3613             if ( t3.calculateHeight( true ) != 11 ) {
3614                 return false;
3615             }
3616             if ( t3.isCompletelyBinary() ) {
3617                 return false;
3618             }
3619             final PhylogenyNode n = t3.getNode( "ABC" );
3620             final Phylogeny t4 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3,(F,G,H,I))",
3621                                                  new NHXParser() )[ 0 ];
3622             if ( t4.getNumberOfExternalNodes() != 9 ) {
3623                 return false;
3624             }
3625             if ( t4.calculateHeight( false ) != 11 ) {
3626                 return false;
3627             }
3628             if ( t4.isCompletelyBinary() ) {
3629                 return false;
3630             }
3631             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)" );
3632             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
3633             if ( t5.getNumberOfExternalNodes() != 8 ) {
3634                 return false;
3635             }
3636             if ( t5.calculateHeight( false ) != 15 ) {
3637                 return false;
3638             }
3639             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)" );
3640             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
3641             if ( t6.calculateHeight( true ) != 15 ) {
3642                 return false;
3643             }
3644             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)" );
3645             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
3646             if ( t7.calculateHeight( true ) != 15 ) {
3647                 return false;
3648             }
3649             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)" );
3650             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
3651             if ( t8.getNumberOfExternalNodes() != 10 ) {
3652                 return false;
3653             }
3654             if ( t8.calculateHeight( true ) != 15 ) {
3655                 return false;
3656             }
3657             final char[] a9 = new char[] { 'a' };
3658             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
3659             if ( t9.calculateHeight( true ) != 0 ) {
3660                 return false;
3661             }
3662             final char[] a10 = new char[] { 'a', ':', '6' };
3663             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
3664             if ( t10.calculateHeight( true ) != 6 ) {
3665                 return false;
3666             }
3667         }
3668         catch ( final Exception e ) {
3669             e.printStackTrace( System.out );
3670             return false;
3671         }
3672         return true;
3673     }
3674
3675     private static boolean testConfidenceAssessor() {
3676         try {
3677             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3678             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3679             final Phylogeny[] ev0 = factory.create(
3680                                                     "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3681                                                     new NHXParser() );
3682             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3683             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3684                 return false;
3685             }
3686             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3687                 return false;
3688             }
3689             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3690             final Phylogeny[] ev1 = factory.create(
3691                                                     "((((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)));",
3692                                                     new NHXParser() );
3693             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3694             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3695                 return false;
3696             }
3697             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3698                 return false;
3699             }
3700             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3701             final Phylogeny[] ev_b = factory.create(
3702                                                      "((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",
3703                                                      new NHXParser() );
3704             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3705             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3706                 return false;
3707             }
3708             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3709                 return false;
3710             }
3711             //
3712             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3713             final Phylogeny[] ev1x = factory.create(
3714                                                      "((((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)));",
3715                                                      new NHXParser() );
3716             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3717             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3718                 return false;
3719             }
3720             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3721                 return false;
3722             }
3723             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3724             final Phylogeny[] ev_bx = factory.create(
3725                                                       "((((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",
3726                                                       new NHXParser() );
3727             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3728             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3729                 return false;
3730             }
3731             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3732                 return false;
3733             }
3734             final Phylogeny[] t2 = factory.create(
3735                                                    "((((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);",
3736                                                    new NHXParser() );
3737             final Phylogeny[] ev2 = factory.create(
3738                                                     "((((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);",
3739                                                     new NHXParser() );
3740             for( final Phylogeny target : t2 ) {
3741                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3742             }
3743             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3744                                                  new NHXParser() )[ 0 ];
3745             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3746             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3747             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3748                 return false;
3749             }
3750             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3751                 return false;
3752             }
3753             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3754                 return false;
3755             }
3756         }
3757         catch ( final Exception e ) {
3758             e.printStackTrace();
3759             return false;
3760         }
3761         return true;
3762     }
3763
3764     private static boolean testCopyOfNodeData() {
3765         try {
3766             final PhylogenyNode n1 = PhylogenyNode
3767                     .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]" );
3768             final PhylogenyNode n2 = n1.copyNodeData();
3769             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3770                 return false;
3771             }
3772         }
3773         catch ( final Exception e ) {
3774             e.printStackTrace();
3775             return false;
3776         }
3777         return true;
3778     }
3779
3780     private static boolean testCreateBalancedPhylogeny() {
3781         try {
3782             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3783             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3784                 return false;
3785             }
3786             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3787                 return false;
3788             }
3789             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3790             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3791                 return false;
3792             }
3793             if ( p1.getNumberOfExternalNodes() != 100 ) {
3794                 return false;
3795             }
3796         }
3797         catch ( final Exception e ) {
3798             e.printStackTrace();
3799             return false;
3800         }
3801         return true;
3802     }
3803
3804     private static boolean testCreateUriForSeqWeb() {
3805         try {
3806             final PhylogenyNode n = new PhylogenyNode();
3807             n.setName( "tr|B3RJ64" );
3808             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3809                 return false;
3810             }
3811             n.setName( "B0LM41_HUMAN" );
3812             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3813                     .equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3814                 return false;
3815             }
3816             n.setName( "NP_001025424" );
3817             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3818                     .equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3819                 return false;
3820             }
3821             n.setName( "_NM_001030253-" );
3822             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3823                     .equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3824                 return false;
3825             }
3826             n.setName( "XM_002122186" );
3827             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3828                     .equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3829                 return false;
3830             }
3831             n.setName( "dgh_AAA34956_gdg" );
3832             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3833                 return false;
3834             }
3835             n.setName( "AAA34956" );
3836             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3837                 return false;
3838             }
3839             n.setName( "GI:394892" );
3840             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3841                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3842                 return false;
3843             }
3844             n.setName( "gi_394892" );
3845             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3846                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3847                 return false;
3848             }
3849             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3850             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3851                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3852                 return false;
3853             }
3854             n.setName( "P12345" );
3855             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3856                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3857                 return false;
3858             }
3859             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3860             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3861                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3862                 return false;
3863             }
3864         }
3865         catch ( final Exception e ) {
3866             e.printStackTrace( System.out );
3867             return false;
3868         }
3869         return true;
3870     }
3871
3872     private static boolean testDataObjects() {
3873         try {
3874             final Confidence s0 = new Confidence();
3875             final Confidence s1 = new Confidence();
3876             if ( !s0.isEqual( s1 ) ) {
3877                 return false;
3878             }
3879             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3880             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3881             if ( s2.isEqual( s1 ) ) {
3882                 return false;
3883             }
3884             if ( !s2.isEqual( s3 ) ) {
3885                 return false;
3886             }
3887             final Confidence s4 = ( Confidence ) s3.copy();
3888             if ( !s4.isEqual( s3 ) ) {
3889                 return false;
3890             }
3891             s3.asSimpleText();
3892             s3.asText();
3893             // Taxonomy
3894             // ----------
3895             final Taxonomy t1 = new Taxonomy();
3896             final Taxonomy t2 = new Taxonomy();
3897             final Taxonomy t3 = new Taxonomy();
3898             final Taxonomy t4 = new Taxonomy();
3899             final Taxonomy t5 = new Taxonomy();
3900             t1.setIdentifier( new Identifier( "ecoli" ) );
3901             t1.setTaxonomyCode( "ECOLI" );
3902             t1.setScientificName( "E. coli" );
3903             t1.setCommonName( "coli" );
3904             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3905             if ( !t1.isEqual( t0 ) ) {
3906                 return false;
3907             }
3908             t2.setIdentifier( new Identifier( "ecoli" ) );
3909             t2.setTaxonomyCode( "OTHER" );
3910             t2.setScientificName( "what" );
3911             t2.setCommonName( "something" );
3912             if ( !t1.isEqual( t2 ) ) {
3913                 return false;
3914             }
3915             t2.setIdentifier( new Identifier( "nemve" ) );
3916             if ( t1.isEqual( t2 ) ) {
3917                 return false;
3918             }
3919             t1.setIdentifier( null );
3920             t3.setTaxonomyCode( "ECOLI" );
3921             t3.setScientificName( "what" );
3922             t3.setCommonName( "something" );
3923             if ( !t1.isEqual( t3 ) ) {
3924                 return false;
3925             }
3926             t1.setIdentifier( null );
3927             t1.setTaxonomyCode( "" );
3928             t4.setScientificName( "E. ColI" );
3929             t4.setCommonName( "something" );
3930             if ( !t1.isEqual( t4 ) ) {
3931                 return false;
3932             }
3933             t4.setScientificName( "B. subtilis" );
3934             t4.setCommonName( "something" );
3935             if ( t1.isEqual( t4 ) ) {
3936                 return false;
3937             }
3938             t1.setIdentifier( null );
3939             t1.setTaxonomyCode( "" );
3940             t1.setScientificName( "" );
3941             t5.setCommonName( "COLI" );
3942             if ( !t1.isEqual( t5 ) ) {
3943                 return false;
3944             }
3945             t5.setCommonName( "vibrio" );
3946             if ( t1.isEqual( t5 ) ) {
3947                 return false;
3948             }
3949             // Identifier
3950             // ----------
3951             final Identifier id0 = new Identifier( "123", "pfam" );
3952             final Identifier id1 = ( Identifier ) id0.copy();
3953             if ( !id1.isEqual( id1 ) ) {
3954                 return false;
3955             }
3956             if ( !id1.isEqual( id0 ) ) {
3957                 return false;
3958             }
3959             if ( !id0.isEqual( id1 ) ) {
3960                 return false;
3961             }
3962             id1.asSimpleText();
3963             id1.asText();
3964             // ProteinDomain
3965             // ---------------
3966             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3967             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3968             if ( !pd1.isEqual( pd1 ) ) {
3969                 return false;
3970             }
3971             if ( !pd1.isEqual( pd0 ) ) {
3972                 return false;
3973             }
3974             pd1.asSimpleText();
3975             pd1.asText();
3976             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3977             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3978             if ( !pd3.isEqual( pd3 ) ) {
3979                 return false;
3980             }
3981             if ( !pd2.isEqual( pd3 ) ) {
3982                 return false;
3983             }
3984             if ( !pd0.isEqual( pd3 ) ) {
3985                 return false;
3986             }
3987             pd3.asSimpleText();
3988             pd3.asText();
3989             // DomainArchitecture
3990             // ------------------
3991             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3992             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3993             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3994             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3995             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3996             final ArrayList<PhylogenyData> domains0 = new ArrayList<>();
3997             domains0.add( d2 );
3998             domains0.add( d0 );
3999             domains0.add( d3 );
4000             domains0.add( d1 );
4001             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
4002             if ( ds0.getNumberOfDomains() != 4 ) {
4003                 return false;
4004             }
4005             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
4006             if ( !ds0.isEqual( ds0 ) ) {
4007                 return false;
4008             }
4009             if ( !ds0.isEqual( ds1 ) ) {
4010                 return false;
4011             }
4012             if ( ds1.getNumberOfDomains() != 4 ) {
4013                 return false;
4014             }
4015             final ArrayList<PhylogenyData> domains1 = new ArrayList<>();
4016             domains1.add( d1 );
4017             domains1.add( d2 );
4018             domains1.add( d4 );
4019             domains1.add( d0 );
4020             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
4021             if ( ds0.isEqual( ds2 ) ) {
4022                 return false;
4023             }
4024             ds1.asSimpleText();
4025             ds1.asText();
4026             ds1.toNHX();
4027             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
4028             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
4029                 System.out.println( ds3.toNHX() );
4030                 return false;
4031             }
4032             if ( ds3.getNumberOfDomains() != 3 ) {
4033                 return false;
4034             }
4035             // Event
4036             // -----
4037             final Event e1 = new Event( Event.EventType.fusion );
4038             if ( e1.isDuplication() ) {
4039                 return false;
4040             }
4041             if ( !e1.isFusion() ) {
4042                 return false;
4043             }
4044             if ( !e1.asText().toString().equals( "fusion" ) ) {
4045                 return false;
4046             }
4047             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
4048                 return false;
4049             }
4050             final Event e11 = new Event( Event.EventType.fusion );
4051             if ( !e11.isEqual( e1 ) ) {
4052                 return false;
4053             }
4054             if ( !e11.toNHX().toString().equals( "" ) ) {
4055                 return false;
4056             }
4057             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
4058             if ( e2.isDuplication() ) {
4059                 return false;
4060             }
4061             if ( !e2.isSpeciationOrDuplication() ) {
4062                 return false;
4063             }
4064             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
4065                 return false;
4066             }
4067             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
4068                 return false;
4069             }
4070             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
4071                 return false;
4072             }
4073             if ( e11.isEqual( e2 ) ) {
4074                 return false;
4075             }
4076             final Event e2c = ( Event ) e2.copy();
4077             if ( !e2c.isEqual( e2 ) ) {
4078                 return false;
4079             }
4080             Event e3 = new Event( 1, 2, 3 );
4081             if ( e3.isDuplication() ) {
4082                 return false;
4083             }
4084             if ( e3.isSpeciation() ) {
4085                 return false;
4086             }
4087             if ( e3.isGeneLoss() ) {
4088                 return false;
4089             }
4090             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
4091                 return false;
4092             }
4093             final Event e3c = ( Event ) e3.copy();
4094             final Event e3cc = ( Event ) e3c.copy();
4095             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
4096                 return false;
4097             }
4098             e3 = null;
4099             if ( !e3c.isEqual( e3cc ) ) {
4100                 return false;
4101             }
4102             Event e4 = new Event( 1, 2, 3 );
4103             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
4104                 return false;
4105             }
4106             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
4107                 return false;
4108             }
4109             final Event e4c = ( Event ) e4.copy();
4110             e4 = null;
4111             final Event e4cc = ( Event ) e4c.copy();
4112             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
4113                 return false;
4114             }
4115             if ( !e4c.isEqual( e4cc ) ) {
4116                 return false;
4117             }
4118             final Event e5 = new Event();
4119             if ( !e5.isUnassigned() ) {
4120                 return false;
4121             }
4122             if ( !e5.asText().toString().equals( "unassigned" ) ) {
4123                 return false;
4124             }
4125             if ( !e5.asSimpleText().toString().equals( "" ) ) {
4126                 return false;
4127             }
4128             final Event e6 = new Event( 1, 0, 0 );
4129             if ( !e6.asText().toString().equals( "duplication" ) ) {
4130                 return false;
4131             }
4132             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
4133                 return false;
4134             }
4135             final Event e7 = new Event( 0, 1, 0 );
4136             if ( !e7.asText().toString().equals( "speciation" ) ) {
4137                 return false;
4138             }
4139             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
4140                 return false;
4141             }
4142             final Event e8 = new Event( 0, 0, 1 );
4143             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
4144                 return false;
4145             }
4146             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
4147                 return false;
4148             }
4149         }
4150         catch ( final Exception e ) {
4151             e.printStackTrace( System.out );
4152             return false;
4153         }
4154         return true;
4155     }
4156
4157     private static boolean testDeletionOfExternalNodes() {
4158         try {
4159             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4160             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
4161             final PhylogenyWriter w = new PhylogenyWriter();
4162             if ( t0.isEmpty() ) {
4163                 return false;
4164             }
4165             if ( t0.getNumberOfExternalNodes() != 1 ) {
4166                 return false;
4167             }
4168             t0.deleteSubtree( t0.getNode( "A" ), false );
4169             if ( t0.getNumberOfExternalNodes() != 0 ) {
4170                 return false;
4171             }
4172             if ( !t0.isEmpty() ) {
4173                 return false;
4174             }
4175             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
4176             if ( t1.getNumberOfExternalNodes() != 2 ) {
4177                 return false;
4178             }
4179             t1.deleteSubtree( t1.getNode( "A" ), false );
4180             if ( t1.getNumberOfExternalNodes() != 1 ) {
4181                 return false;
4182             }
4183             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
4184                 return false;
4185             }
4186             t1.deleteSubtree( t1.getNode( "B" ), false );
4187             if ( t1.getNumberOfExternalNodes() != 1 ) {
4188                 return false;
4189             }
4190             t1.deleteSubtree( t1.getNode( "r" ), false );
4191             if ( !t1.isEmpty() ) {
4192                 return false;
4193             }
4194             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
4195             if ( t2.getNumberOfExternalNodes() != 3 ) {
4196                 return false;
4197             }
4198             t2.deleteSubtree( t2.getNode( "B" ), false );
4199             if ( t2.getNumberOfExternalNodes() != 2 ) {
4200                 return false;
4201             }
4202             t2.toNewHampshireX();
4203             PhylogenyNode n = t2.getNode( "A" );
4204             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
4205                 return false;
4206             }
4207             t2.deleteSubtree( t2.getNode( "A" ), false );
4208             if ( t2.getNumberOfExternalNodes() != 2 ) {
4209                 return false;
4210             }
4211             t2.deleteSubtree( t2.getNode( "C" ), true );
4212             if ( t2.getNumberOfExternalNodes() != 1 ) {
4213                 return false;
4214             }
4215             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4216             if ( t3.getNumberOfExternalNodes() != 4 ) {
4217                 return false;
4218             }
4219             t3.deleteSubtree( t3.getNode( "B" ), true );
4220             if ( t3.getNumberOfExternalNodes() != 3 ) {
4221                 return false;
4222             }
4223             n = t3.getNode( "A" );
4224             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
4225                 return false;
4226             }
4227             n = n.getNextExternalNode();
4228             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
4229                 return false;
4230             }
4231             t3.deleteSubtree( t3.getNode( "A" ), true );
4232             if ( t3.getNumberOfExternalNodes() != 2 ) {
4233                 return false;
4234             }
4235             n = t3.getNode( "C" );
4236             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
4237                 return false;
4238             }
4239             t3.deleteSubtree( t3.getNode( "C" ), true );
4240             if ( t3.getNumberOfExternalNodes() != 1 ) {
4241                 return false;
4242             }
4243             t3.deleteSubtree( t3.getNode( "D" ), true );
4244             if ( t3.getNumberOfExternalNodes() != 0 ) {
4245                 return false;
4246             }
4247             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4248             if ( t4.getNumberOfExternalNodes() != 6 ) {
4249                 return false;
4250             }
4251             t4.deleteSubtree( t4.getNode( "B2" ), true );
4252             if ( t4.getNumberOfExternalNodes() != 5 ) {
4253                 return false;
4254             }
4255             String s = w.toNewHampshire( t4, true ).toString();
4256             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
4257                 return false;
4258             }
4259             t4.deleteSubtree( t4.getNode( "B11" ), true );
4260             if ( t4.getNumberOfExternalNodes() != 4 ) {
4261                 return false;
4262             }
4263             t4.deleteSubtree( t4.getNode( "C" ), true );
4264             if ( t4.getNumberOfExternalNodes() != 3 ) {
4265                 return false;
4266             }
4267             n = t4.getNode( "A" );
4268             n = n.getNextExternalNode();
4269             if ( !n.getName().equals( "B12" ) ) {
4270                 return false;
4271             }
4272             n = n.getNextExternalNode();
4273             if ( !n.getName().equals( "D" ) ) {
4274                 return false;
4275             }
4276             s = w.toNewHampshire( t4, true ).toString();
4277             if ( !s.equals( "((A,B12),D);" ) ) {
4278                 return false;
4279             }
4280             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4281             t5.deleteSubtree( t5.getNode( "A" ), true );
4282             if ( t5.getNumberOfExternalNodes() != 5 ) {
4283                 return false;
4284             }
4285             s = w.toNewHampshire( t5, true ).toString();
4286             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
4287                 return false;
4288             }
4289             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4290             t6.deleteSubtree( t6.getNode( "B11" ), true );
4291             if ( t6.getNumberOfExternalNodes() != 5 ) {
4292                 return false;
4293             }
4294             s = w.toNewHampshire( t6, false ).toString();
4295             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
4296                 return false;
4297             }
4298             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4299             t7.deleteSubtree( t7.getNode( "B12" ), true );
4300             if ( t7.getNumberOfExternalNodes() != 5 ) {
4301                 return false;
4302             }
4303             s = w.toNewHampshire( t7, true ).toString();
4304             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
4305                 return false;
4306             }
4307             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4308             t8.deleteSubtree( t8.getNode( "B2" ), true );
4309             if ( t8.getNumberOfExternalNodes() != 5 ) {
4310                 return false;
4311             }
4312             s = w.toNewHampshire( t8, false ).toString();
4313             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
4314                 return false;
4315             }
4316             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4317             t9.deleteSubtree( t9.getNode( "C" ), true );
4318             if ( t9.getNumberOfExternalNodes() != 5 ) {
4319                 return false;
4320             }
4321             s = w.toNewHampshire( t9, true ).toString();
4322             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
4323                 return false;
4324             }
4325             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4326             t10.deleteSubtree( t10.getNode( "D" ), true );
4327             if ( t10.getNumberOfExternalNodes() != 5 ) {
4328                 return false;
4329             }
4330             s = w.toNewHampshire( t10, true ).toString();
4331             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
4332                 return false;
4333             }
4334             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
4335             t11.deleteSubtree( t11.getNode( "A" ), true );
4336             if ( t11.getNumberOfExternalNodes() != 2 ) {
4337                 return false;
4338             }
4339             s = w.toNewHampshire( t11, true ).toString();
4340             if ( !s.equals( "(B,C);" ) ) {
4341                 return false;
4342             }
4343             t11.deleteSubtree( t11.getNode( "C" ), true );
4344             if ( t11.getNumberOfExternalNodes() != 1 ) {
4345                 return false;
4346             }
4347             s = w.toNewHampshire( t11, false ).toString();
4348             if ( !s.equals( "B;" ) ) {
4349                 return false;
4350             }
4351             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
4352             t12.deleteSubtree( t12.getNode( "B2" ), true );
4353             if ( t12.getNumberOfExternalNodes() != 8 ) {
4354                 return false;
4355             }
4356             s = w.toNewHampshire( t12, true ).toString();
4357             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
4358                 return false;
4359             }
4360             t12.deleteSubtree( t12.getNode( "B3" ), true );
4361             if ( t12.getNumberOfExternalNodes() != 7 ) {
4362                 return false;
4363             }
4364             s = w.toNewHampshire( t12, true ).toString();
4365             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
4366                 return false;
4367             }
4368             t12.deleteSubtree( t12.getNode( "C3" ), true );
4369             if ( t12.getNumberOfExternalNodes() != 6 ) {
4370                 return false;
4371             }
4372             s = w.toNewHampshire( t12, true ).toString();
4373             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
4374                 return false;
4375             }
4376             t12.deleteSubtree( t12.getNode( "A1" ), true );
4377             if ( t12.getNumberOfExternalNodes() != 5 ) {
4378                 return false;
4379             }
4380             s = w.toNewHampshire( t12, true ).toString();
4381             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
4382                 return false;
4383             }
4384             t12.deleteSubtree( t12.getNode( "B1" ), true );
4385             if ( t12.getNumberOfExternalNodes() != 4 ) {
4386                 return false;
4387             }
4388             s = w.toNewHampshire( t12, true ).toString();
4389             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
4390                 return false;
4391             }
4392             t12.deleteSubtree( t12.getNode( "A3" ), true );
4393             if ( t12.getNumberOfExternalNodes() != 3 ) {
4394                 return false;
4395             }
4396             s = w.toNewHampshire( t12, true ).toString();
4397             if ( !s.equals( "(A2,(C1,C2));" ) ) {
4398                 return false;
4399             }
4400             t12.deleteSubtree( t12.getNode( "A2" ), true );
4401             if ( t12.getNumberOfExternalNodes() != 2 ) {
4402                 return false;
4403             }
4404             s = w.toNewHampshire( t12, true ).toString();
4405             if ( !s.equals( "(C1,C2);" ) ) {
4406                 return false;
4407             }
4408             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
4409             t13.deleteSubtree( t13.getNode( "D" ), true );
4410             if ( t13.getNumberOfExternalNodes() != 4 ) {
4411                 return false;
4412             }
4413             s = w.toNewHampshire( t13, true ).toString();
4414             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
4415                 return false;
4416             }
4417             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
4418             t14.deleteSubtree( t14.getNode( "E" ), true );
4419             if ( t14.getNumberOfExternalNodes() != 5 ) {
4420                 return false;
4421             }
4422             s = w.toNewHampshire( t14, true ).toString();
4423             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
4424                 return false;
4425             }
4426             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
4427             t15.deleteSubtree( t15.getNode( "B2" ), true );
4428             if ( t15.getNumberOfExternalNodes() != 11 ) {
4429                 return false;
4430             }
4431             t15.deleteSubtree( t15.getNode( "B1" ), true );
4432             if ( t15.getNumberOfExternalNodes() != 10 ) {
4433                 return false;
4434             }
4435             t15.deleteSubtree( t15.getNode( "B3" ), true );
4436             if ( t15.getNumberOfExternalNodes() != 9 ) {
4437                 return false;
4438             }
4439             t15.deleteSubtree( t15.getNode( "B4" ), true );
4440             if ( t15.getNumberOfExternalNodes() != 8 ) {
4441                 return false;
4442             }
4443             t15.deleteSubtree( t15.getNode( "A1" ), true );
4444             if ( t15.getNumberOfExternalNodes() != 7 ) {
4445                 return false;
4446             }
4447             t15.deleteSubtree( t15.getNode( "C4" ), true );
4448             if ( t15.getNumberOfExternalNodes() != 6 ) {
4449                 return false;
4450             }
4451         }
4452         catch ( final Exception e ) {
4453             e.printStackTrace( System.out );
4454             return false;
4455         }
4456         return true;
4457     }
4458
4459     private static boolean testDescriptiveStatistics() {
4460         try {
4461             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
4462             dss1.addValue( 82 );
4463             dss1.addValue( 78 );
4464             dss1.addValue( 70 );
4465             dss1.addValue( 58 );
4466             dss1.addValue( 42 );
4467             if ( dss1.getN() != 5 ) {
4468                 return false;
4469             }
4470             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
4471                 return false;
4472             }
4473             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
4474                 return false;
4475             }
4476             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
4477                 return false;
4478             }
4479             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
4480                 return false;
4481             }
4482             if ( !Test.isEqual( dss1.median(), 70 ) ) {
4483                 return false;
4484             }
4485             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
4486                 return false;
4487             }
4488             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
4489                 return false;
4490             }
4491             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
4492                 return false;
4493             }
4494             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
4495                 return false;
4496             }
4497             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
4498                 return false;
4499             }
4500             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
4501                 return false;
4502             }
4503             dss1.addValue( 123 );
4504             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
4505                 return false;
4506             }
4507             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
4508                 return false;
4509             }
4510             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
4511                 return false;
4512             }
4513             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
4514             dss2.addValue( -1.85 );
4515             dss2.addValue( 57.5 );
4516             dss2.addValue( 92.78 );
4517             dss2.addValue( 57.78 );
4518             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
4519                 return false;
4520             }
4521             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
4522                 return false;
4523             }
4524             final double[] a = dss2.getDataAsDoubleArray();
4525             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
4526                 return false;
4527             }
4528             dss2.addValue( -100 );
4529             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
4530                 return false;
4531             }
4532             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
4533                 return false;
4534             }
4535             final double[] ds = new double[ 14 ];
4536             ds[ 0 ] = 34;
4537             ds[ 1 ] = 23;
4538             ds[ 2 ] = 1;
4539             ds[ 3 ] = 32;
4540             ds[ 4 ] = 11;
4541             ds[ 5 ] = 2;
4542             ds[ 6 ] = 12;
4543             ds[ 7 ] = 33;
4544             ds[ 8 ] = 13;
4545             ds[ 9 ] = 22;
4546             ds[ 10 ] = 21;
4547             ds[ 11 ] = 35;
4548             ds[ 12 ] = 24;
4549             ds[ 13 ] = 31;
4550             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
4551             if ( bins.length != 4 ) {
4552                 return false;
4553             }
4554             if ( bins[ 0 ] != 2 ) {
4555                 return false;
4556             }
4557             if ( bins[ 1 ] != 3 ) {
4558                 return false;
4559             }
4560             if ( bins[ 2 ] != 4 ) {
4561                 return false;
4562             }
4563             if ( bins[ 3 ] != 5 ) {
4564                 return false;
4565             }
4566             final double[] ds1 = new double[ 9 ];
4567             ds1[ 0 ] = 10.0;
4568             ds1[ 1 ] = 19.0;
4569             ds1[ 2 ] = 9.999;
4570             ds1[ 3 ] = 0.0;
4571             ds1[ 4 ] = 39.9;
4572             ds1[ 5 ] = 39.999;
4573             ds1[ 6 ] = 30.0;
4574             ds1[ 7 ] = 19.999;
4575             ds1[ 8 ] = 30.1;
4576             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
4577             if ( bins1.length != 4 ) {
4578                 return false;
4579             }
4580             if ( bins1[ 0 ] != 2 ) {
4581                 return false;
4582             }
4583             if ( bins1[ 1 ] != 3 ) {
4584                 return false;
4585             }
4586             if ( bins1[ 2 ] != 0 ) {
4587                 return false;
4588             }
4589             if ( bins1[ 3 ] != 4 ) {
4590                 return false;
4591             }
4592             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
4593             if ( bins1_1.length != 3 ) {
4594                 return false;
4595             }
4596             if ( bins1_1[ 0 ] != 3 ) {
4597                 return false;
4598             }
4599             if ( bins1_1[ 1 ] != 2 ) {
4600                 return false;
4601             }
4602             if ( bins1_1[ 2 ] != 4 ) {
4603                 return false;
4604             }
4605             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
4606             if ( bins1_2.length != 3 ) {
4607                 return false;
4608             }
4609             if ( bins1_2[ 0 ] != 2 ) {
4610                 return false;
4611             }
4612             if ( bins1_2[ 1 ] != 2 ) {
4613                 return false;
4614             }
4615             if ( bins1_2[ 2 ] != 2 ) {
4616                 return false;
4617             }
4618             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
4619             dss3.addValue( 1 );
4620             dss3.addValue( 1 );
4621             dss3.addValue( 1 );
4622             dss3.addValue( 2 );
4623             dss3.addValue( 3 );
4624             dss3.addValue( 4 );
4625             dss3.addValue( 5 );
4626             dss3.addValue( 5 );
4627             dss3.addValue( 5 );
4628             dss3.addValue( 6 );
4629             dss3.addValue( 7 );
4630             dss3.addValue( 8 );
4631             dss3.addValue( 9 );
4632             dss3.addValue( 10 );
4633             dss3.addValue( 10 );
4634             dss3.addValue( 10 );
4635             final AsciiHistogram histo = new AsciiHistogram( dss3 );
4636             histo.toStringBuffer( 10, '=', 40, 5 );
4637             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
4638         }
4639         catch ( final Exception e ) {
4640             e.printStackTrace( System.out );
4641             return false;
4642         }
4643         return true;
4644     }
4645
4646     private static boolean testDir( final String file ) {
4647         try {
4648             final File f = new File( file );
4649             if ( !f.exists() ) {
4650                 return false;
4651             }
4652             if ( !f.isDirectory() ) {
4653                 return false;
4654             }
4655             if ( !f.canRead() ) {
4656                 return false;
4657             }
4658         }
4659         catch ( final Exception e ) {
4660             return false;
4661         }
4662         return true;
4663     }
4664
4665     private static boolean testEbiEntryRetrieval() {
4666         try {
4667             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
4668             if ( !entry.getAccession().equals( "AAK41263" ) ) {
4669                 System.out.println( entry.getAccession() );
4670                 return false;
4671             }
4672             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
4673                 System.out.println( entry.getTaxonomyScientificName() );
4674                 return false;
4675             }
4676             if ( !entry.getSequenceName()
4677                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4678                 System.out.println( entry.getSequenceName() );
4679                 return false;
4680             }
4681             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4682                 System.out.println( entry.getGeneName() );
4683                 return false;
4684             }
4685             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4686                 System.out.println( entry.getTaxonomyIdentifier() );
4687                 return false;
4688             }
4689             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4690                 System.out.println( entry.getAnnotations().first().getRefValue() );
4691                 return false;
4692             }
4693             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4694                 System.out.println( entry.getAnnotations().first().getRefSource() );
4695                 return false;
4696             }
4697             if ( entry.getCrossReferences().size() < 1 ) {
4698                 return false;
4699             }
4700             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4701             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4702                 return false;
4703             }
4704             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4705                 System.out.println( entry1.getTaxonomyScientificName() );
4706                 return false;
4707             }
4708             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4709                 System.out.println( entry1.getSequenceName() );
4710                 return false;
4711             }
4712             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4713                 System.out.println( entry1.getTaxonomyIdentifier() );
4714                 return false;
4715             }
4716             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4717                 System.out.println( entry1.getGeneName() );
4718                 return false;
4719             }
4720             if ( entry1.getCrossReferences().size() < 1 ) {
4721                 return false;
4722             }
4723             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4724             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4725                 return false;
4726             }
4727             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4728                 System.out.println( entry2.getTaxonomyScientificName() );
4729                 return false;
4730             }
4731             if ( !entry2.getSequenceName()
4732                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4733                 System.out.println( entry2.getSequenceName() );
4734                 return false;
4735             }
4736             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4737                 System.out.println( entry2.getTaxonomyIdentifier() );
4738                 return false;
4739             }
4740             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4741                 System.out.println( entry2.getGeneName() );
4742                 return false;
4743             }
4744             if ( entry2.getCrossReferences().size() < 1 ) {
4745                 return false;
4746             }
4747             if ( !entry2.getChromosome().equals( "20" ) ) {
4748                 return false;
4749             }
4750             if ( !entry2.getMap().equals( "20q11.22" ) ) {
4751                 return false;
4752             }
4753             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4754             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4755                 return false;
4756             }
4757             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4758                 System.out.println( entry3.getTaxonomyScientificName() );
4759                 return false;
4760             }
4761             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4762                 System.out.println( entry3.getSequenceName() );
4763                 return false;
4764             }
4765             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4766                 System.out.println( entry3.getTaxonomyIdentifier() );
4767                 return false;
4768             }
4769             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4770                 System.out.println( entry3.getSequenceSymbol() );
4771                 return false;
4772             }
4773             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4774                 return false;
4775             }
4776             if ( entry3.getCrossReferences().size() < 1 ) {
4777                 return false;
4778             }
4779             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4780             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4781                 return false;
4782             }
4783             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4784                 System.out.println( entry4.getTaxonomyScientificName() );
4785                 return false;
4786             }
4787             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4788                 System.out.println( entry4.getSequenceName() );
4789                 return false;
4790             }
4791             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4792                 System.out.println( entry4.getTaxonomyIdentifier() );
4793                 return false;
4794             }
4795             if ( !entry4.getGeneName().equals( "ras" ) ) {
4796                 System.out.println( entry4.getGeneName() );
4797                 return false;
4798             }
4799             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4800             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4801                 return false;
4802             }
4803             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4804                 System.out.println( entry5.getTaxonomyScientificName() );
4805                 return false;
4806             }
4807             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4808                 System.out.println( entry5.getSequenceName() );
4809                 return false;
4810             }
4811             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4812                 System.out.println( entry5.getTaxonomyIdentifier() );
4813                 return false;
4814             }
4815             final SequenceDatabaseEntry entry6 = SequenceDbWsTools.obtainEntry( "M30539" );
4816             if ( !entry6.getAccession().equals( "M30539" ) ) {
4817                 return false;
4818             }
4819             if ( !entry6.getGeneName().equals( "ras" ) ) {
4820                 return false;
4821             }
4822             if ( !entry6.getSequenceName().equals( "Human SK2 c-Ha-ras-1 oncogene-encoded protein gene, exon 1" ) ) {
4823                 return false;
4824             }
4825             if ( !entry6.getTaxonomyIdentifier().equals( "9606" ) ) {
4826                 return false;
4827             }
4828             if ( !entry6.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4829                 return false;
4830             }
4831             if ( entry6.getCrossReferences().size() < 1 ) {
4832                 return false;
4833             }
4834         }
4835         catch ( final IOException e ) {
4836             System.out.println();
4837             System.out.println( "the following might be due to absence internet connection:" );
4838             e.printStackTrace( System.out );
4839             return true;
4840         }
4841         catch ( final Exception e ) {
4842             e.printStackTrace();
4843             return false;
4844         }
4845         return true;
4846     }
4847
4848     private static boolean testExternalNodeRelatedMethods() {
4849         try {
4850             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4851             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4852             PhylogenyNode n = t1.getNode( "A" );
4853             n = n.getNextExternalNode();
4854             if ( !n.getName().equals( "B" ) ) {
4855                 return false;
4856             }
4857             n = n.getNextExternalNode();
4858             if ( !n.getName().equals( "C" ) ) {
4859                 return false;
4860             }
4861             n = n.getNextExternalNode();
4862             if ( !n.getName().equals( "D" ) ) {
4863                 return false;
4864             }
4865             n = t1.getNode( "B" );
4866             while ( !n.isLastExternalNode() ) {
4867                 n = n.getNextExternalNode();
4868             }
4869             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4870             n = t2.getNode( "A" );
4871             n = n.getNextExternalNode();
4872             if ( !n.getName().equals( "B" ) ) {
4873                 return false;
4874             }
4875             n = n.getNextExternalNode();
4876             if ( !n.getName().equals( "C" ) ) {
4877                 return false;
4878             }
4879             n = n.getNextExternalNode();
4880             if ( !n.getName().equals( "D" ) ) {
4881                 return false;
4882             }
4883             n = t2.getNode( "B" );
4884             while ( !n.isLastExternalNode() ) {
4885                 n = n.getNextExternalNode();
4886             }
4887             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4888             n = t3.getNode( "A" );
4889             n = n.getNextExternalNode();
4890             if ( !n.getName().equals( "B" ) ) {
4891                 return false;
4892             }
4893             n = n.getNextExternalNode();
4894             if ( !n.getName().equals( "C" ) ) {
4895                 return false;
4896             }
4897             n = n.getNextExternalNode();
4898             if ( !n.getName().equals( "D" ) ) {
4899                 return false;
4900             }
4901             n = n.getNextExternalNode();
4902             if ( !n.getName().equals( "E" ) ) {
4903                 return false;
4904             }
4905             n = n.getNextExternalNode();
4906             if ( !n.getName().equals( "F" ) ) {
4907                 return false;
4908             }
4909             n = n.getNextExternalNode();
4910             if ( !n.getName().equals( "G" ) ) {
4911                 return false;
4912             }
4913             n = n.getNextExternalNode();
4914             if ( !n.getName().equals( "H" ) ) {
4915                 return false;
4916             }
4917             n = t3.getNode( "B" );
4918             while ( !n.isLastExternalNode() ) {
4919                 n = n.getNextExternalNode();
4920             }
4921             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4922             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4923                 final PhylogenyNode node = iter.next();
4924             }
4925             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4926             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4927                 final PhylogenyNode node = iter.next();
4928             }
4929             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))",
4930                                                  new NHXParser() )[ 0 ];
4931             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4932             if ( !iter.next().getName().equals( "A" ) ) {
4933                 return false;
4934             }
4935             if ( !iter.next().getName().equals( "B" ) ) {
4936                 return false;
4937             }
4938             if ( !iter.next().getName().equals( "C" ) ) {
4939                 return false;
4940             }
4941             if ( !iter.next().getName().equals( "D" ) ) {
4942                 return false;
4943             }
4944             if ( !iter.next().getName().equals( "E" ) ) {
4945                 return false;
4946             }
4947             if ( !iter.next().getName().equals( "F" ) ) {
4948                 return false;
4949             }
4950             if ( iter.hasNext() ) {
4951                 return false;
4952             }
4953         }
4954         catch ( final Exception e ) {
4955             e.printStackTrace( System.out );
4956             return false;
4957         }
4958         return true;
4959     }
4960
4961     private static boolean testExtractSNFromNodeName() {
4962         try {
4963             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4964                 return false;
4965             }
4966             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4967                 return false;
4968             }
4969             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4970                 return false;
4971             }
4972             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4973                     .equals( "Mus musculus musculus" ) ) {
4974                 return false;
4975             }
4976             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4977                     .equals( "Mus musculus musculus" ) ) {
4978                 return false;
4979             }
4980             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4981                     .equals( "Mus musculus musculus" ) ) {
4982                 return false;
4983             }
4984             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4985                     .equals( "Mus musculus musculus" ) ) {
4986                 return false;
4987             }
4988             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4989                 return false;
4990             }
4991             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4992                     .equals( "Mus musculus musculus" ) ) {
4993                 return false;
4994             }
4995             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4996                     .equals( "Mus musculus musculus" ) ) {
4997                 return false;
4998             }
4999             if ( ParserUtils
5000                     .extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
5001                 return false;
5002             }
5003             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
5004                 return false;
5005             }
5006             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
5007                 return false;
5008             }
5009             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
5010                 return false;
5011             }
5012             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
5013                     .equals( "Mus musculus musculus" ) ) {
5014                 return false;
5015             }
5016             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
5017                 return false;
5018             }
5019             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
5020                 return false;
5021             }
5022             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
5023                 return false;
5024             }
5025             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
5026                 return false;
5027             }
5028             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
5029                 return false;
5030             }
5031             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
5032                 return false;
5033             }
5034             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
5035                 return false;
5036             }
5037             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
5038                 return false;
5039             }
5040             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
5041                     .equals( "Mus musculus" ) ) {
5042                 return false;
5043             }
5044             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
5045                     .equals( "Mus musculus" ) ) {
5046                 return false;
5047             }
5048             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
5049                 return false;
5050             }
5051             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
5052                     .equals( "Mus musculus musculus" ) ) {
5053                 return false;
5054             }
5055             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
5056                     .equals( "Mus musculus musculus" ) ) {
5057                 return false;
5058             }
5059             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
5060                     .equals( "Mus musculus musculus" ) ) {
5061                 return false;
5062             }
5063             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
5064                 return false;
5065             }
5066             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
5067                     .equals( "Pilostyles mexicana" ) ) {
5068                 return false;
5069             }
5070             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
5071                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
5072                 return false;
5073             }
5074             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
5075                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
5076                 return false;
5077             }
5078             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
5079                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
5080                 return false;
5081             }
5082             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
5083                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
5084                 return false;
5085             }
5086             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
5087                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
5088                 return false;
5089             }
5090             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
5091                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
5092                 return false;
5093             }
5094             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
5095                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
5096                 return false;
5097             }
5098             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
5099                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
5100                 return false;
5101             }
5102             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
5103                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
5104                 return false;
5105             }
5106             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
5107                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
5108                 return false;
5109             }
5110             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
5111                     .equals( "Escherichia coli (strain K12)" ) ) {
5112                 return false;
5113             }
5114             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
5115                     .equals( "Escherichia coli (strain K12)" ) ) {
5116                 return false;
5117             }
5118             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
5119                     .equals( "Escherichia coli (str. K12)" ) ) {
5120                 return false;
5121             }
5122             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
5123                     .equals( "Escherichia coli (str. K12)" ) ) {
5124                 return false;
5125             }
5126             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
5127                     .equals( "Escherichia coli (str. K12)" ) ) {
5128                 return false;
5129             }
5130             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
5131                     .equals( "Escherichia coli (var. K12)" ) ) {
5132                 return false;
5133             }
5134             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
5135                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
5136                 return false;
5137             }
5138             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
5139                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
5140                 return false;
5141             }
5142             if ( !ParserUtils
5143                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
5144                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
5145                 return false;
5146             }
5147             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
5148                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
5149                 return false;
5150             }
5151             if ( !ParserUtils
5152                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
5153                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
5154                 return false;
5155             }
5156             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
5157                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
5158                 return false;
5159             }
5160             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
5161                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
5162                 return false;
5163             }
5164             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
5165                 return false;
5166             }
5167             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
5168                 return false;
5169             }
5170             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
5171                 return false;
5172             }
5173             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
5174                     .equals( "Macrocera sp." ) ) {
5175                 return false;
5176             }
5177             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
5178                 return false;
5179             }
5180             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
5181                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
5182                 return false;
5183             }
5184             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
5185                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
5186                 return false;
5187             }
5188             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
5189                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
5190                 return false;
5191             }
5192             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
5193                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
5194                 return false;
5195             }
5196         }
5197         catch ( final Exception e ) {
5198             e.printStackTrace( System.out );
5199             return false;
5200         }
5201         return true;
5202     }
5203
5204     private static boolean testExtractTaxonomyDataFromNodeName() {
5205         try {
5206             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
5207             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5208                 return false;
5209             }
5210             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
5211             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5212                 return false;
5213             }
5214             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
5215             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5216                 return false;
5217             }
5218             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
5219             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5220                 return false;
5221             }
5222             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
5223             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5224                 return false;
5225             }
5226             n = new PhylogenyNode( "HNRPR_HUMAN" );
5227             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5228                 return false;
5229             }
5230             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
5231             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5232                 return false;
5233             }
5234         }
5235         catch ( final Exception e ) {
5236             e.printStackTrace( System.out );
5237             return false;
5238         }
5239         return true;
5240     }
5241
5242     private static boolean testExtractTaxonomyCodeFromNodeName() {
5243         try {
5244             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE",
5245                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5246                 return false;
5247             }
5248             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5249                     .equals( "SOYBN" ) ) {
5250                 return false;
5251             }
5252             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
5253                     .equals( "ARATH" ) ) {
5254                 return false;
5255             }
5256             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
5257                     .equals( "ARATH" ) ) {
5258                 return false;
5259             }
5260             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE )
5261                     .equals( "RAT" ) ) {
5262                 return false;
5263             }
5264             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE )
5265                     .equals( "RAT" ) ) {
5266                 return false;
5267             }
5268             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1",
5269                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5270                 return false;
5271             }
5272             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5273                     .equals( "SOYBN" ) ) {
5274                 return false;
5275             }
5276             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5277                     .equals( "SOYBN" ) ) {
5278                 return false;
5279             }
5280             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5281                     .equals( "SOYBN" ) ) {
5282                 return false;
5283             }
5284             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5285                     .equals( "SOYBN" ) ) {
5286                 return false;
5287             }
5288             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5289                     .equals( "SOYBN" ) ) {
5290                 return false;
5291             }
5292             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5293                     .equals( "SOYBN" ) ) {
5294                 return false;
5295             }
5296             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
5297                     .equals( "SOYBN" ) ) {
5298                 return false;
5299             }
5300             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
5301                     .equals( "SOYBN" ) ) {
5302                 return false;
5303             }
5304             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx",
5305                                                               TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
5306                 return false;
5307             }
5308             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
5309                     .equals( "SOYBN" ) ) {
5310                 return false;
5311             }
5312             if ( !ParserUtils
5313                     .extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5314                     .equals( "ECOLI" ) ) {
5315                 return false;
5316             }
5317             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blagg_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
5318                     .equals( "9YX45" ) ) {
5319                 return false;
5320             }
5321             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
5322                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5323                     .equals( "MOUSE" ) ) {
5324                 return false;
5325             }
5326             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
5327                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5328                     .equals( "MOUSE" ) ) {
5329                 return false;
5330             }
5331             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
5332                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5333                     .equals( "MOUSE" ) ) {
5334                 return false;
5335             }
5336             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
5337                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5338                 return false;
5339             }
5340             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
5341                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5342                 return false;
5343             }
5344             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5345                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5346                     .equals( "RAT" ) ) {
5347                 return false;
5348             }
5349             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5350                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5351                     .equals( "RAT" ) ) {
5352                 return false;
5353             }
5354             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
5355                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5356                     .equals( "RAT" ) ) {
5357                 return false;
5358             }
5359             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
5360                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5361                 return false;
5362             }
5363             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
5364                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5365                 return false;
5366             }
5367             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5368                     .equals( "RAT" ) ) {
5369                 return false;
5370             }
5371             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5372                     .equals( "PIG" ) ) {
5373                 return false;
5374             }
5375             if ( !ParserUtils
5376                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5377                     .equals( "MOUSE" ) ) {
5378                 return false;
5379             }
5380             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5381                     .equals( "MOUSE" ) ) {
5382                 return false;
5383             }
5384             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ",
5385                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5386                 return false;
5387             }
5388         }
5389         catch ( final Exception e ) {
5390             e.printStackTrace( System.out );
5391             return false;
5392         }
5393         return true;
5394     }
5395
5396     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
5397         try {
5398             PhylogenyNode n = new PhylogenyNode();
5399             n.setName( "tr|B3RJ64" );
5400             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5401                 return false;
5402             }
5403             n.setName( "tr.B3RJ64" );
5404             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5405                 return false;
5406             }
5407             n.setName( "tr=B3RJ64" );
5408             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5409                 return false;
5410             }
5411             n.setName( "tr-B3RJ64" );
5412             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5413                 return false;
5414             }
5415             n.setName( "tr/B3RJ64" );
5416             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5417                 return false;
5418             }
5419             n.setName( "tr\\B3RJ64" );
5420             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5421                 return false;
5422             }
5423             n.setName( "tr_B3RJ64" );
5424             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5425                 return false;
5426             }
5427             n.setName( " tr|B3RJ64 " );
5428             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5429                 return false;
5430             }
5431             n.setName( "-tr|B3RJ64-" );
5432             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5433                 return false;
5434             }
5435             n.setName( "-tr=B3RJ64-" );
5436             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5437                 return false;
5438             }
5439             n.setName( "_tr=B3RJ64_" );
5440             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5441                 return false;
5442             }
5443             n.setName( " tr_tr|B3RJ64_sp|123 " );
5444             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5445                 return false;
5446             }
5447             n.setName( "B3RJ64" );
5448             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5449                 return false;
5450             }
5451             n.setName( "sp|B3RJ64" );
5452             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5453                 return false;
5454             }
5455             n.setName( "sp|B3RJ64C" );
5456             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5457                 return false;
5458             }
5459             n.setName( "sp B3RJ64" );
5460             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5461                 return false;
5462             }
5463             n.setName( "sp|B3RJ6X" );
5464             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5465                 return false;
5466             }
5467             n.setName( "sp|B3RJ6" );
5468             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5469                 return false;
5470             }
5471             n.setName( "K1PYK7_CRAGI" );
5472             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5473                 return false;
5474             }
5475             n.setName( "K1PYK7_PEA" );
5476             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
5477                 return false;
5478             }
5479             n.setName( "K1PYK7_RAT" );
5480             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
5481                 return false;
5482             }
5483             n.setName( "K1PYK7_PIG" );
5484             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5485                 return false;
5486             }
5487             n.setName( "~K1PYK7_PIG~" );
5488             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5489                 return false;
5490             }
5491             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
5492             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5493                 return false;
5494             }
5495             n.setName( "K1PYKX_CRAGI" );
5496             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5497                 return false;
5498             }
5499             n.setName( "XXXXX_CRAGI" );
5500             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
5501                 return false;
5502             }
5503             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
5504             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
5505                 return false;
5506             }
5507             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
5508             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5509                 return false;
5510             }
5511             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
5512             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
5513                 return false;
5514             }
5515             n = new PhylogenyNode();
5516             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
5517             seq.setSymbol( "K1PYK7_CRAGI" );
5518             n.getNodeData().addSequence( seq );
5519             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5520                 return false;
5521             }
5522             seq.setSymbol( "tr|B3RJ64" );
5523             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5524                 return false;
5525             }
5526             n = new PhylogenyNode();
5527             seq = new org.forester.phylogeny.data.Sequence();
5528             seq.setName( "K1PYK7_CRAGI" );
5529             n.getNodeData().addSequence( seq );
5530             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5531                 return false;
5532             }
5533             seq.setName( "tr|B3RJ64" );
5534             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5535                 return false;
5536             }
5537             n = new PhylogenyNode();
5538             seq = new org.forester.phylogeny.data.Sequence();
5539             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
5540             n.getNodeData().addSequence( seq );
5541             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
5542                 return false;
5543             }
5544             n = new PhylogenyNode();
5545             seq = new org.forester.phylogeny.data.Sequence();
5546             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
5547             n.getNodeData().addSequence( seq );
5548             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5549                 return false;
5550             }
5551             //
5552             n = new PhylogenyNode();
5553             n.setName( "ACP19736" );
5554             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5555                 return false;
5556             }
5557             n = new PhylogenyNode();
5558             n.setName( "|ACP19736|" );
5559             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5560                 return false;
5561             }
5562         }
5563         catch ( final Exception e ) {
5564             e.printStackTrace( System.out );
5565             return false;
5566         }
5567         return true;
5568     }
5569
5570     private static boolean testFastaParser() {
5571         try {
5572             final FileInputStream fis1 = new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" );
5573             if ( !FastaParser.isLikelyFasta( fis1 ) ) {
5574                 fis1.close();
5575                 return false;
5576             }
5577             else {
5578                 fis1.close();
5579             }
5580             final FileInputStream fis2 = new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" );
5581             if ( FastaParser.isLikelyFasta( fis2 ) ) {
5582                 fis2.close();
5583                 return false;
5584             }
5585             else {
5586                 fis2.close();
5587             }
5588             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
5589             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
5590                 return false;
5591             }
5592             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
5593                 return false;
5594             }
5595             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
5596                 return false;
5597             }
5598             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
5599                 return false;
5600             }
5601             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
5602                 return false;
5603             }
5604             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
5605                 return false;
5606             }
5607         }
5608         catch ( final Exception e ) {
5609             e.printStackTrace();
5610             return false;
5611         }
5612         return true;
5613     }
5614
5615     private static boolean testGenbankAccessorParsing() {
5616         //The format for GenBank Accession numbers are:
5617         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
5618         //Protein:    3 letters + 5 numerals
5619         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
5620         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
5621             return false;
5622         }
5623         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
5624             return false;
5625         }
5626         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" )
5627                 .equals( "AY423861.24" ) ) {
5628             return false;
5629         }
5630         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
5631             return false;
5632         }
5633         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
5634             return false;
5635         }
5636         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
5637             return false;
5638         }
5639         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
5640             return false;
5641         }
5642         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
5643             return false;
5644         }
5645         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
5646             return false;
5647         }
5648         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
5649             return false;
5650         }
5651         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
5652             return false;
5653         }
5654         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
5655             return false;
5656         }
5657         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
5658             return false;
5659         }
5660         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
5661             return false;
5662         }
5663         return true;
5664     }
5665
5666     private static boolean testGeneralMsaParser() {
5667         try {
5668             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
5669             final Msa msa_0 = GeneralMsaParser.parseMsa( new ByteArrayInputStream( msa_str_0.getBytes() ) );
5670             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
5671             final Msa msa_1 = GeneralMsaParser.parseMsa( new ByteArrayInputStream( msa_str_1.getBytes() ) );
5672             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
5673             final Msa msa_2 = GeneralMsaParser.parseMsa( new ByteArrayInputStream( msa_str_2.getBytes() ) );
5674             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
5675             final Msa msa_3 = GeneralMsaParser.parseMsa( new ByteArrayInputStream( msa_str_3.getBytes() ) );
5676             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5677                 return false;
5678             }
5679             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5680                 return false;
5681             }
5682             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5683                 return false;
5684             }
5685             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5686                 return false;
5687             }
5688             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5689                 return false;
5690             }
5691             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5692                 return false;
5693             }
5694             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5695                 return false;
5696             }
5697             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5698                 return false;
5699             }
5700             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5701                 return false;
5702             }
5703             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5704                 return false;
5705             }
5706             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5707                 return false;
5708             }
5709             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5710                 return false;
5711             }
5712             final Msa msa_4 = GeneralMsaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5713             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5714                 return false;
5715             }
5716             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5717                 return false;
5718             }
5719             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5720                 return false;
5721             }
5722             final Msa msa_5 = GeneralMsaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5723             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5724                 return false;
5725             }
5726             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5727                 return false;
5728             }
5729             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5730                 return false;
5731             }
5732             final Msa msa_6 = GeneralMsaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5733             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5734                 return false;
5735             }
5736             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5737                 return false;
5738             }
5739             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5740                 return false;
5741             }
5742         }
5743         catch ( final Exception e ) {
5744             e.printStackTrace();
5745             return false;
5746         }
5747         return true;
5748     }
5749
5750     private static boolean testGeneralTable() {
5751         try {
5752             final GeneralTable<Integer, String> t0 = new GeneralTable<>();
5753             t0.setValue( 3, 2, "23" );
5754             t0.setValue( 10, 1, "error" );
5755             t0.setValue( 10, 1, "110" );
5756             t0.setValue( 9, 1, "19" );
5757             t0.setValue( 1, 10, "101" );
5758             t0.setValue( 10, 10, "1010" );
5759             t0.setValue( 100, 10, "10100" );
5760             t0.setValue( 0, 0, "00" );
5761             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5762                 return false;
5763             }
5764             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5765                 return false;
5766             }
5767             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5768                 return false;
5769             }
5770             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5771                 return false;
5772             }
5773             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5774                 return false;
5775             }
5776             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5777                 return false;
5778             }
5779             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5780                 return false;
5781             }
5782             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5783                 return false;
5784             }
5785             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5786                 return false;
5787             }
5788             final GeneralTable<String, String> t1 = new GeneralTable<>();
5789             t1.setValue( "3", "2", "23" );
5790             t1.setValue( "10", "1", "error" );
5791             t1.setValue( "10", "1", "110" );
5792             t1.setValue( "9", "1", "19" );
5793             t1.setValue( "1", "10", "101" );
5794             t1.setValue( "10", "10", "1010" );
5795             t1.setValue( "100", "10", "10100" );
5796             t1.setValue( "0", "0", "00" );
5797             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5798             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5799                 return false;
5800             }
5801             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5802                 return false;
5803             }
5804             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5805                 return false;
5806             }
5807             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5808                 return false;
5809             }
5810             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5811                 return false;
5812             }
5813             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5814                 return false;
5815             }
5816             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5817                 return false;
5818             }
5819             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5820                 return false;
5821             }
5822             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5823                 return false;
5824             }
5825             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5826                 return false;
5827             }
5828         }
5829         catch ( final Exception e ) {
5830             e.printStackTrace( System.out );
5831             return false;
5832         }
5833         return true;
5834     }
5835
5836     private static boolean testGetDistance() {
5837         try {
5838             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5839             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",
5840                                                  new NHXParser() )[ 0 ];
5841             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5842                 return false;
5843             }
5844             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5845                 return false;
5846             }
5847             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5848                 return false;
5849             }
5850             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5851                 return false;
5852             }
5853             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5854                 return false;
5855             }
5856             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5857                 return false;
5858             }
5859             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5860                 return false;
5861             }
5862             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5863                 return false;
5864             }
5865             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5866                 return false;
5867             }
5868             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5869                 return false;
5870             }
5871             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5872                 return false;
5873             }
5874             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5875                 return false;
5876             }
5877             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5878                 return false;
5879             }
5880             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5881                 return false;
5882             }
5883             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5884                 return false;
5885             }
5886             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5887                 return false;
5888             }
5889             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5890                 return false;
5891             }
5892             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5893                 return false;
5894             }
5895             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5896                 return false;
5897             }
5898             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5899                 return false;
5900             }
5901             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5902                 return false;
5903             }
5904             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5905                 return false;
5906             }
5907             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5908                 return false;
5909             }
5910             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5911                 return false;
5912             }
5913             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5914                 return false;
5915             }
5916             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5917                 return false;
5918             }
5919             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5920                 return false;
5921             }
5922             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5923                 return false;
5924             }
5925             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5926                 return false;
5927             }
5928             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5929                 return false;
5930             }
5931             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5932                 return false;
5933             }
5934             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",
5935                                                  new NHXParser() )[ 0 ];
5936             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5937                 return false;
5938             }
5939             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5940                 return false;
5941             }
5942             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5943                 return false;
5944             }
5945             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5946                 return false;
5947             }
5948             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5949                 return false;
5950             }
5951             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5952                 return false;
5953             }
5954             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5955                 return false;
5956             }
5957             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5958                 return false;
5959             }
5960             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5961                 return false;
5962             }
5963             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5964                 return false;
5965             }
5966             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5967                 return false;
5968             }
5969         }
5970         catch ( final Exception e ) {
5971             e.printStackTrace( System.out );
5972             return false;
5973         }
5974         return true;
5975     }
5976
5977     private static boolean testGetLCA() {
5978         try {
5979             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5980             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5981                                                  new NHXParser() )[ 0 ];
5982             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5983             if ( !A.getName().equals( "A" ) ) {
5984                 return false;
5985             }
5986             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5987             if ( !gh.getName().equals( "gh" ) ) {
5988                 return false;
5989             }
5990             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5991             if ( !ab.getName().equals( "ab" ) ) {
5992                 return false;
5993             }
5994             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5995             if ( !ab2.getName().equals( "ab" ) ) {
5996                 return false;
5997             }
5998             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5999             if ( !gh2.getName().equals( "gh" ) ) {
6000                 return false;
6001             }
6002             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
6003             if ( !gh3.getName().equals( "gh" ) ) {
6004                 return false;
6005             }
6006             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
6007             if ( !abc.getName().equals( "abc" ) ) {
6008                 return false;
6009             }
6010             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
6011             if ( !abc2.getName().equals( "abc" ) ) {
6012                 return false;
6013             }
6014             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
6015             if ( !abcd.getName().equals( "abcd" ) ) {
6016                 return false;
6017             }
6018             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
6019             if ( !abcd2.getName().equals( "abcd" ) ) {
6020                 return false;
6021             }
6022             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
6023             if ( !abcdef.getName().equals( "abcdef" ) ) {
6024                 return false;
6025             }
6026             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
6027             if ( !abcdef2.getName().equals( "abcdef" ) ) {
6028                 return false;
6029             }
6030             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
6031             if ( !abcdef3.getName().equals( "abcdef" ) ) {
6032                 return false;
6033             }
6034             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
6035             if ( !abcdef4.getName().equals( "abcdef" ) ) {
6036                 return false;
6037             }
6038             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
6039             if ( !abcde.getName().equals( "abcde" ) ) {
6040                 return false;
6041             }
6042             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
6043             if ( !abcde2.getName().equals( "abcde" ) ) {
6044                 return false;
6045             }
6046             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
6047             if ( !r.getName().equals( "abcdefgh" ) ) {
6048                 return false;
6049             }
6050             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
6051             if ( !r2.getName().equals( "abcdefgh" ) ) {
6052                 return false;
6053             }
6054             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
6055             if ( !r3.getName().equals( "abcdefgh" ) ) {
6056                 return false;
6057             }
6058             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
6059             if ( !abcde3.getName().equals( "abcde" ) ) {
6060                 return false;
6061             }
6062             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
6063             if ( !abcde4.getName().equals( "abcde" ) ) {
6064                 return false;
6065             }
6066             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
6067             if ( !ab3.getName().equals( "ab" ) ) {
6068                 return false;
6069             }
6070             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
6071             if ( !ab4.getName().equals( "ab" ) ) {
6072                 return false;
6073             }
6074             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
6075             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
6076             if ( !cd.getName().equals( "cd" ) ) {
6077                 return false;
6078             }
6079             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
6080             if ( !cd2.getName().equals( "cd" ) ) {
6081                 return false;
6082             }
6083             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
6084             if ( !cde.getName().equals( "cde" ) ) {
6085                 return false;
6086             }
6087             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
6088             if ( !cde2.getName().equals( "cde" ) ) {
6089                 return false;
6090             }
6091             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
6092             if ( !cdef.getName().equals( "cdef" ) ) {
6093                 return false;
6094             }
6095             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
6096             if ( !cdef2.getName().equals( "cdef" ) ) {
6097                 return false;
6098             }
6099             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
6100             if ( !cdef3.getName().equals( "cdef" ) ) {
6101                 return false;
6102             }
6103             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
6104             if ( !rt.getName().equals( "r" ) ) {
6105                 return false;
6106             }
6107             final Phylogeny p3 = factory.create(
6108                                                  "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
6109                                                  new NHXParser() )[ 0 ];
6110             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
6111             if ( !bc_3.getName().equals( "bc" ) ) {
6112                 return false;
6113             }
6114             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
6115             if ( !ac_3.getName().equals( "abc" ) ) {
6116                 return false;
6117             }
6118             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
6119             if ( !ad_3.getName().equals( "abcde" ) ) {
6120                 return false;
6121             }
6122             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
6123             if ( !af_3.getName().equals( "abcdef" ) ) {
6124                 return false;
6125             }
6126             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
6127             if ( !ag_3.getName().equals( "" ) ) {
6128                 return false;
6129             }
6130             if ( !ag_3.isRoot() ) {
6131                 return false;
6132             }
6133             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
6134             if ( !al_3.getName().equals( "" ) ) {
6135                 return false;
6136             }
6137             if ( !al_3.isRoot() ) {
6138                 return false;
6139             }
6140             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
6141             if ( !kl_3.getName().equals( "" ) ) {
6142                 return false;
6143             }
6144             if ( !kl_3.isRoot() ) {
6145                 return false;
6146             }
6147             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
6148             if ( !fl_3.getName().equals( "" ) ) {
6149                 return false;
6150             }
6151             if ( !fl_3.isRoot() ) {
6152                 return false;
6153             }
6154             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
6155             if ( !gk_3.getName().equals( "ghijk" ) ) {
6156                 return false;
6157             }
6158             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
6159             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
6160             if ( !r_4.getName().equals( "r" ) ) {
6161                 return false;
6162             }
6163             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
6164             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
6165             if ( !r_5.getName().equals( "root" ) ) {
6166                 return false;
6167             }
6168             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
6169             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
6170             if ( !r_6.getName().equals( "rot" ) ) {
6171                 return false;
6172             }
6173             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
6174             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
6175             if ( !r_7.getName().equals( "rott" ) ) {
6176                 return false;
6177             }
6178         }
6179         catch ( final Exception e ) {
6180             e.printStackTrace( System.out );
6181             return false;
6182         }
6183         return true;
6184     }
6185
6186     private static boolean testGetLCA2() {
6187         try {
6188             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6189             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
6190             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
6191             PhylogenyMethods.preOrderReId( p_a );
6192             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
6193                                                                                               p_a.getNode( "a" ) );
6194             if ( !p_a_1.getName().equals( "a" ) ) {
6195                 return false;
6196             }
6197             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
6198             PhylogenyMethods.preOrderReId( p_b );
6199             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
6200                                                                                               p_b.getNode( "a" ) );
6201             if ( !p_b_1.getName().equals( "b" ) ) {
6202                 return false;
6203             }
6204             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
6205                                                                                               p_b.getNode( "b" ) );
6206             if ( !p_b_2.getName().equals( "b" ) ) {
6207                 return false;
6208             }
6209             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
6210             PhylogenyMethods.preOrderReId( p_c );
6211             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
6212                                                                                               p_c.getNode( "a" ) );
6213             if ( !p_c_1.getName().equals( "b" ) ) {
6214                 return false;
6215             }
6216             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
6217                                                                                               p_c.getNode( "c" ) );
6218             if ( !p_c_2.getName().equals( "c" ) ) {
6219                 System.out.println( p_c_2.getName() );
6220                 System.exit( -1 );
6221                 return false;
6222             }
6223             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
6224                                                                                               p_c.getNode( "b" ) );
6225             if ( !p_c_3.getName().equals( "b" ) ) {
6226                 return false;
6227             }
6228             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
6229                                                                                               p_c.getNode( "a" ) );
6230             if ( !p_c_4.getName().equals( "c" ) ) {
6231                 return false;
6232             }
6233             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
6234                                                  new NHXParser() )[ 0 ];
6235             PhylogenyMethods.preOrderReId( p1 );
6236             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6237                                                                                           p1.getNode( "A" ) );
6238             if ( !A.getName().equals( "A" ) ) {
6239                 return false;
6240             }
6241             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
6242                                                                                            p1.getNode( "gh" ) );
6243             if ( !gh.getName().equals( "gh" ) ) {
6244                 return false;
6245             }
6246             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6247                                                                                            p1.getNode( "B" ) );
6248             if ( !ab.getName().equals( "ab" ) ) {
6249                 return false;
6250             }
6251             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
6252                                                                                             p1.getNode( "A" ) );
6253             if ( !ab2.getName().equals( "ab" ) ) {
6254                 return false;
6255             }
6256             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
6257                                                                                             p1.getNode( "G" ) );
6258             if ( !gh2.getName().equals( "gh" ) ) {
6259                 return false;
6260             }
6261             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
6262                                                                                             p1.getNode( "H" ) );
6263             if ( !gh3.getName().equals( "gh" ) ) {
6264                 return false;
6265             }
6266             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
6267                                                                                             p1.getNode( "A" ) );
6268             if ( !abc.getName().equals( "abc" ) ) {
6269                 return false;
6270             }
6271             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6272                                                                                              p1.getNode( "C" ) );
6273             if ( !abc2.getName().equals( "abc" ) ) {
6274                 return false;
6275             }
6276             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6277                                                                                              p1.getNode( "D" ) );
6278             if ( !abcd.getName().equals( "abcd" ) ) {
6279                 return false;
6280             }
6281             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
6282                                                                                               p1.getNode( "A" ) );
6283             if ( !abcd2.getName().equals( "abcd" ) ) {
6284                 return false;
6285             }
6286             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6287                                                                                                p1.getNode( "F" ) );
6288             if ( !abcdef.getName().equals( "abcdef" ) ) {
6289                 return false;
6290             }
6291             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
6292                                                                                                 p1.getNode( "A" ) );
6293             if ( !abcdef2.getName().equals( "abcdef" ) ) {
6294                 return false;
6295             }
6296             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
6297                                                                                                 p1.getNode( "F" ) );
6298             if ( !abcdef3.getName().equals( "abcdef" ) ) {
6299                 return false;
6300             }
6301             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
6302                                                                                                 p1.getNode( "ab" ) );
6303             if ( !abcdef4.getName().equals( "abcdef" ) ) {
6304                 return false;
6305             }
6306             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6307                                                                                               p1.getNode( "E" ) );
6308             if ( !abcde.getName().equals( "abcde" ) ) {
6309                 return false;
6310             }
6311             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6312                                                                                                p1.getNode( "A" ) );
6313             if ( !abcde2.getName().equals( "abcde" ) ) {
6314                 return false;
6315             }
6316             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
6317                                                                                           p1.getNode( "abcdefgh" ) );
6318             if ( !r.getName().equals( "abcdefgh" ) ) {
6319                 return false;
6320             }
6321             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6322                                                                                            p1.getNode( "H" ) );
6323             if ( !r2.getName().equals( "abcdefgh" ) ) {
6324                 return false;
6325             }
6326             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
6327                                                                                            p1.getNode( "A" ) );
6328             if ( !r3.getName().equals( "abcdefgh" ) ) {
6329                 return false;
6330             }
6331             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6332                                                                                                p1.getNode( "abcde" ) );
6333             if ( !abcde3.getName().equals( "abcde" ) ) {
6334                 return false;
6335             }
6336             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
6337                                                                                                p1.getNode( "E" ) );
6338             if ( !abcde4.getName().equals( "abcde" ) ) {
6339                 return false;
6340             }
6341             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
6342                                                                                             p1.getNode( "B" ) );
6343             if ( !ab3.getName().equals( "ab" ) ) {
6344                 return false;
6345             }
6346             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
6347                                                                                             p1.getNode( "ab" ) );
6348             if ( !ab4.getName().equals( "ab" ) ) {
6349                 return false;
6350             }
6351             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
6352             PhylogenyMethods.preOrderReId( p2 );
6353             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6354                                                                                            p2.getNode( "d" ) );
6355             if ( !cd.getName().equals( "cd" ) ) {
6356                 return false;
6357             }
6358             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6359                                                                                             p2.getNode( "c" ) );
6360             if ( !cd2.getName().equals( "cd" ) ) {
6361                 return false;
6362             }
6363             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6364                                                                                             p2.getNode( "e" ) );
6365             if ( !cde.getName().equals( "cde" ) ) {
6366                 return false;
6367             }
6368             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
6369                                                                                              p2.getNode( "c" ) );
6370             if ( !cde2.getName().equals( "cde" ) ) {
6371                 return false;
6372             }
6373             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6374                                                                                              p2.getNode( "f" ) );
6375             if ( !cdef.getName().equals( "cdef" ) ) {
6376                 return false;
6377             }
6378             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6379                                                                                               p2.getNode( "f" ) );
6380             if ( !cdef2.getName().equals( "cdef" ) ) {
6381                 return false;
6382             }
6383             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
6384                                                                                               p2.getNode( "d" ) );
6385             if ( !cdef3.getName().equals( "cdef" ) ) {
6386                 return false;
6387             }
6388             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6389                                                                                            p2.getNode( "a" ) );
6390             if ( !rt.getName().equals( "r" ) ) {
6391                 return false;
6392             }
6393             final Phylogeny p3 = factory.create(
6394                                                  "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
6395                                                  new NHXParser() )[ 0 ];
6396             PhylogenyMethods.preOrderReId( p3 );
6397             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
6398                                                                                              p3.getNode( "c" ) );
6399             if ( !bc_3.getName().equals( "bc" ) ) {
6400                 return false;
6401             }
6402             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6403                                                                                              p3.getNode( "c" ) );
6404             if ( !ac_3.getName().equals( "abc" ) ) {
6405                 return false;
6406             }
6407             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6408                                                                                              p3.getNode( "d" ) );
6409             if ( !ad_3.getName().equals( "abcde" ) ) {
6410                 return false;
6411             }
6412             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6413                                                                                              p3.getNode( "f" ) );
6414             if ( !af_3.getName().equals( "abcdef" ) ) {
6415                 return false;
6416             }
6417             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6418                                                                                              p3.getNode( "g" ) );
6419             if ( !ag_3.getName().equals( "" ) ) {
6420                 return false;
6421             }
6422             if ( !ag_3.isRoot() ) {
6423                 return false;
6424             }
6425             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6426                                                                                              p3.getNode( "l" ) );
6427             if ( !al_3.getName().equals( "" ) ) {
6428                 return false;
6429             }
6430             if ( !al_3.isRoot() ) {
6431                 return false;
6432             }
6433             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
6434                                                                                              p3.getNode( "l" ) );
6435             if ( !kl_3.getName().equals( "" ) ) {
6436                 return false;
6437             }
6438             if ( !kl_3.isRoot() ) {
6439                 return false;
6440             }
6441             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
6442                                                                                              p3.getNode( "l" ) );
6443             if ( !fl_3.getName().equals( "" ) ) {
6444                 return false;
6445             }
6446             if ( !fl_3.isRoot() ) {
6447                 return false;
6448             }
6449             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
6450                                                                                              p3.getNode( "k" ) );
6451             if ( !gk_3.getName().equals( "ghijk" ) ) {
6452                 return false;
6453             }
6454             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
6455             PhylogenyMethods.preOrderReId( p4 );
6456             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
6457                                                                                             p4.getNode( "c" ) );
6458             if ( !r_4.getName().equals( "r" ) ) {
6459                 return false;
6460             }
6461             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
6462             PhylogenyMethods.preOrderReId( p5 );
6463             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
6464                                                                                             p5.getNode( "c" ) );
6465             if ( !r_5.getName().equals( "root" ) ) {
6466                 return false;
6467             }
6468             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
6469             PhylogenyMethods.preOrderReId( p6 );
6470             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
6471                                                                                             p6.getNode( "a" ) );
6472             if ( !r_6.getName().equals( "rot" ) ) {
6473                 return false;
6474             }
6475             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
6476             PhylogenyMethods.preOrderReId( p7 );
6477             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
6478                                                                                             p7.getNode( "e" ) );
6479             if ( !r_7.getName().equals( "rott" ) ) {
6480                 return false;
6481             }
6482             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6483                                                                                              p7.getNode( "a" ) );
6484             if ( !r_71.getName().equals( "rott" ) ) {
6485                 return false;
6486             }
6487             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6488                                                                                              p7.getNode( "rott" ) );
6489             if ( !r_72.getName().equals( "rott" ) ) {
6490                 return false;
6491             }
6492             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6493                                                                                              p7.getNode( "a" ) );
6494             if ( !r_73.getName().equals( "rott" ) ) {
6495                 return false;
6496             }
6497             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6498                                                                                              p7.getNode( "rott" ) );
6499             if ( !r_74.getName().equals( "rott" ) ) {
6500                 return false;
6501             }
6502             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6503                                                                                              p7.getNode( "e" ) );
6504             if ( !r_75.getName().equals( "e" ) ) {
6505                 return false;
6506             }
6507         }
6508         catch ( final Exception e ) {
6509             e.printStackTrace( System.out );
6510             return false;
6511         }
6512         return true;
6513     }
6514
6515     private static boolean testHmmscanOutputParser() {
6516         final String test_dir = Test.PATH_TO_TEST_DATA;
6517         try {
6518             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
6519                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ),
6520                                                                                          "MONBR",
6521                                                                                          INDIVIDUAL_SCORE_CUTOFF.NONE );
6522             parser1.parse();
6523             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
6524                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ),
6525                                                                                          "MONBR",
6526                                                                                          INDIVIDUAL_SCORE_CUTOFF.NONE );
6527             final List<Protein> proteins = parser2.parse();
6528             if ( parser2.getProteinsEncountered() != 4 ) {
6529                 return false;
6530             }
6531             if ( proteins.size() != 4 ) {
6532                 return false;
6533             }
6534             if ( parser2.getDomainsEncountered() != 69 ) {
6535                 return false;
6536             }
6537             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
6538                 return false;
6539             }
6540             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
6541                 return false;
6542             }
6543             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
6544                 return false;
6545             }
6546             final Protein p1 = proteins.get( 0 );
6547             if ( p1.getNumberOfProteinDomains() != 15 ) {
6548                 return false;
6549             }
6550             if ( p1.getLength() != 850 ) {
6551                 return false;
6552             }
6553             final Protein p2 = proteins.get( 1 );
6554             if ( p2.getNumberOfProteinDomains() != 51 ) {
6555                 return false;
6556             }
6557             if ( p2.getLength() != 1291 ) {
6558                 return false;
6559             }
6560             final Protein p3 = proteins.get( 2 );
6561             if ( p3.getNumberOfProteinDomains() != 2 ) {
6562                 return false;
6563             }
6564             final Protein p4 = proteins.get( 3 );
6565             if ( p4.getNumberOfProteinDomains() != 1 ) {
6566                 return false;
6567             }
6568             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
6569                 return false;
6570             }
6571             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
6572                 return false;
6573             }
6574             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
6575                 return false;
6576             }
6577             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
6578                 return false;
6579             }
6580             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
6581                 return false;
6582             }
6583             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
6584                 return false;
6585             }
6586             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
6587                 return false;
6588             }
6589         }
6590         catch ( final Exception e ) {
6591             e.printStackTrace( System.out );
6592             return false;
6593         }
6594         return true;
6595     }
6596
6597     private static boolean testLastExternalNodeMethods() {
6598         try {
6599             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6600             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
6601             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
6602             final PhylogenyNode n1 = t0.getNode( "A" );
6603             if ( n1.isLastExternalNode() ) {
6604                 return false;
6605             }
6606             final PhylogenyNode n2 = t0.getNode( "B" );
6607             if ( n2.isLastExternalNode() ) {
6608                 return false;
6609             }
6610             final PhylogenyNode n3 = t0.getNode( "C" );
6611             if ( n3.isLastExternalNode() ) {
6612                 return false;
6613             }
6614             final PhylogenyNode n4 = t0.getNode( "D" );
6615             if ( !n4.isLastExternalNode() ) {
6616                 return false;
6617             }
6618         }
6619         catch ( final Exception e ) {
6620             e.printStackTrace( System.out );
6621             return false;
6622         }
6623         return true;
6624     }
6625
6626     private static boolean testLevelOrderIterator() {
6627         try {
6628             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6629             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
6630             PhylogenyNodeIterator it0;
6631             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
6632                 it0.next();
6633             }
6634             for( it0.reset(); it0.hasNext(); ) {
6635                 it0.next();
6636             }
6637             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
6638             if ( !it.next().getName().equals( "r" ) ) {
6639                 return false;
6640             }
6641             if ( !it.next().getName().equals( "ab" ) ) {
6642                 return false;
6643             }
6644             if ( !it.next().getName().equals( "cd" ) ) {
6645                 return false;
6646             }
6647             if ( !it.next().getName().equals( "A" ) ) {
6648                 return false;
6649             }
6650             if ( !it.next().getName().equals( "B" ) ) {
6651                 return false;
6652             }
6653             if ( !it.next().getName().equals( "C" ) ) {
6654                 return false;
6655             }
6656             if ( !it.next().getName().equals( "D" ) ) {
6657                 return false;
6658             }
6659             if ( it.hasNext() ) {
6660                 return false;
6661             }
6662             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",
6663                                                  new NHXParser() )[ 0 ];
6664             PhylogenyNodeIterator it2;
6665             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
6666                 it2.next();
6667             }
6668             for( it2.reset(); it2.hasNext(); ) {
6669                 it2.next();
6670             }
6671             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
6672             if ( !it3.next().getName().equals( "r" ) ) {
6673                 return false;
6674             }
6675             if ( !it3.next().getName().equals( "abc" ) ) {
6676                 return false;
6677             }
6678             if ( !it3.next().getName().equals( "defg" ) ) {
6679                 return false;
6680             }
6681             if ( !it3.next().getName().equals( "A" ) ) {
6682                 return false;
6683             }
6684             if ( !it3.next().getName().equals( "B" ) ) {
6685                 return false;
6686             }
6687             if ( !it3.next().getName().equals( "C" ) ) {
6688                 return false;
6689             }
6690             if ( !it3.next().getName().equals( "D" ) ) {
6691                 return false;
6692             }
6693             if ( !it3.next().getName().equals( "E" ) ) {
6694                 return false;
6695             }
6696             if ( !it3.next().getName().equals( "F" ) ) {
6697                 return false;
6698             }
6699             if ( !it3.next().getName().equals( "G" ) ) {
6700                 return false;
6701             }
6702             if ( !it3.next().getName().equals( "1" ) ) {
6703                 return false;
6704             }
6705             if ( !it3.next().getName().equals( "2" ) ) {
6706                 return false;
6707             }
6708             if ( !it3.next().getName().equals( "3" ) ) {
6709                 return false;
6710             }
6711             if ( !it3.next().getName().equals( "4" ) ) {
6712                 return false;
6713             }
6714             if ( !it3.next().getName().equals( "5" ) ) {
6715                 return false;
6716             }
6717             if ( !it3.next().getName().equals( "6" ) ) {
6718                 return false;
6719             }
6720             if ( !it3.next().getName().equals( "f1" ) ) {
6721                 return false;
6722             }
6723             if ( !it3.next().getName().equals( "f2" ) ) {
6724                 return false;
6725             }
6726             if ( !it3.next().getName().equals( "f3" ) ) {
6727                 return false;
6728             }
6729             if ( !it3.next().getName().equals( "a" ) ) {
6730                 return false;
6731             }
6732             if ( !it3.next().getName().equals( "b" ) ) {
6733                 return false;
6734             }
6735             if ( !it3.next().getName().equals( "f21" ) ) {
6736                 return false;
6737             }
6738             if ( !it3.next().getName().equals( "X" ) ) {
6739                 return false;
6740             }
6741             if ( !it3.next().getName().equals( "Y" ) ) {
6742                 return false;
6743             }
6744             if ( !it3.next().getName().equals( "Z" ) ) {
6745                 return false;
6746             }
6747             if ( it3.hasNext() ) {
6748                 return false;
6749             }
6750             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6751             PhylogenyNodeIterator it4;
6752             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6753                 it4.next();
6754             }
6755             for( it4.reset(); it4.hasNext(); ) {
6756                 it4.next();
6757             }
6758             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6759             if ( !it5.next().getName().equals( "r" ) ) {
6760                 return false;
6761             }
6762             if ( !it5.next().getName().equals( "A" ) ) {
6763                 return false;
6764             }
6765             if ( !it5.next().getName().equals( "B" ) ) {
6766                 return false;
6767             }
6768             if ( !it5.next().getName().equals( "C" ) ) {
6769                 return false;
6770             }
6771             if ( !it5.next().getName().equals( "D" ) ) {
6772                 return false;
6773             }
6774             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6775             PhylogenyNodeIterator it6;
6776             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6777                 it6.next();
6778             }
6779             for( it6.reset(); it6.hasNext(); ) {
6780                 it6.next();
6781             }
6782             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6783             if ( !it7.next().getName().equals( "A" ) ) {
6784                 return false;
6785             }
6786             if ( it.hasNext() ) {
6787                 return false;
6788             }
6789         }
6790         catch ( final Exception e ) {
6791             e.printStackTrace( System.out );
6792             return false;
6793         }
6794         return true;
6795     }
6796
6797     private static boolean testMafft( final String path ) {
6798         try {
6799             final List<String> opts = new ArrayList<>();
6800             opts.add( "--maxiterate" );
6801             opts.add( "1000" );
6802             opts.add( "--localpair" );
6803             opts.add( "--quiet" );
6804             Msa msa = null;
6805             final MsaInferrer mafft = Mafft.createInstance( path );
6806             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6807             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6808                 return false;
6809             }
6810             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6811                 return false;
6812             }
6813         }
6814         catch ( final Exception e ) {
6815             e.printStackTrace( System.out );
6816             return false;
6817         }
6818         return true;
6819     }
6820
6821     private static boolean testMidpointrooting() {
6822         try {
6823             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6824             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6825             PhylogenyMethods.midpointRoot( t0 );
6826             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6827                 return false;
6828             }
6829             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6830                 return false;
6831             }
6832             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6833                            1 ) ) {
6834                 return false;
6835             }
6836             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",
6837                                                  new NHXParser() )[ 0 ];
6838             if ( !t1.isRooted() ) {
6839                 return false;
6840             }
6841             PhylogenyMethods.midpointRoot( t1 );
6842             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6843                 return false;
6844             }
6845             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6846                 return false;
6847             }
6848             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6849                 return false;
6850             }
6851             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6852                 return false;
6853             }
6854             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6855                 return false;
6856             }
6857             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6858                 return false;
6859             }
6860             t1.reRoot( t1.getNode( "A" ) );
6861             PhylogenyMethods.midpointRoot( t1 );
6862             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6863                 return false;
6864             }
6865             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6866                 return false;
6867             }
6868             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6869                 return false;
6870             }
6871             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6872                 return false;
6873             }
6874             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6875                 System.exit( -1 );
6876                 return false;
6877             }
6878             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6879                 return false;
6880             }
6881         }
6882         catch ( final Exception e ) {
6883             e.printStackTrace( System.out );
6884             return false;
6885         }
6886         return true;
6887     }
6888
6889     private static boolean testMsaQualityMethod() {
6890         try {
6891             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6892             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6893             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6894             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6895             final List<MolecularSequence> l = new ArrayList<>();
6896             l.add( s0 );
6897             l.add( s1 );
6898             l.add( s2 );
6899             l.add( s3 );
6900             final Msa msa = BasicMsa.createInstance( l );
6901             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6902                 return false;
6903             }
6904             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6905                 return false;
6906             }
6907             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6908                 return false;
6909             }
6910             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6911                 return false;
6912             }
6913             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6914                 return false;
6915             }
6916             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6917                 return false;
6918             }
6919             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6920                 return false;
6921             }
6922         }
6923         catch ( final Exception e ) {
6924             e.printStackTrace( System.out );
6925             return false;
6926         }
6927         return true;
6928     }
6929
6930     private static boolean testMsaEntropy() {
6931         try {
6932             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6933             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6934             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6935             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6936             final List<MolecularSequence> l = new ArrayList<>();
6937             l.add( s0 );
6938             l.add( s1 );
6939             l.add( s2 );
6940             l.add( s3 );
6941             final Msa msa = BasicMsa.createInstance( l );
6942             //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6943             //FIXME
6944             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6945             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6946             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6947             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6948             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6949             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6950             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6951             //            System.out.println();
6952             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6953             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6954             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6955             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6956             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6957             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6958             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6959             final List<MolecularSequence> l2 = new ArrayList<>();
6960             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6961             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6962             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6963             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6964             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6965             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6966             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6967             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6968             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6969             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6970             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6971             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6972             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6973             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6974             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6975             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6976             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6977             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6978             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6979             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6980             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6981             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6982             final Msa msa2 = BasicMsa.createInstance( l2 );
6983             //            System.out.println();
6984             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6985             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6986             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6987         }
6988         catch ( final Exception e ) {
6989             e.printStackTrace( System.out );
6990             return false;
6991         }
6992         return true;
6993     }
6994
6995     private static boolean testDeleteableMsa() {
6996         try {
6997             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6998             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6999             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
7000             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
7001             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
7002             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
7003             final List<MolecularSequence> l0 = new ArrayList<>();
7004             l0.add( s0 );
7005             l0.add( s1 );
7006             l0.add( s2 );
7007             l0.add( s3 );
7008             l0.add( s4 );
7009             l0.add( s5 );
7010             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
7011             dmsa0.deleteRow( "b", false );
7012             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
7013                 return false;
7014             }
7015             dmsa0.deleteRow( "e", false );
7016             dmsa0.deleteRow( "a", false );
7017             dmsa0.deleteRow( "f", false );
7018             if ( dmsa0.getLength() != 4 ) {
7019                 return false;
7020             }
7021             if ( dmsa0.getNumberOfSequences() != 2 ) {
7022                 return false;
7023             }
7024             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
7025                 return false;
7026             }
7027             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
7028                 return false;
7029             }
7030             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
7031                 return false;
7032             }
7033             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
7034                 return false;
7035             }
7036             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
7037                 return false;
7038             }
7039             dmsa0.deleteRow( "c", false );
7040             dmsa0.deleteRow( "d", false );
7041             if ( dmsa0.getNumberOfSequences() != 0 ) {
7042                 return false;
7043             }
7044             //
7045             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
7046             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
7047             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
7048             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
7049             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
7050             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
7051             final List<MolecularSequence> l1 = new ArrayList<>();
7052             l1.add( s_0 );
7053             l1.add( s_1 );
7054             l1.add( s_2 );
7055             l1.add( s_3 );
7056             l1.add( s_4 );
7057             l1.add( s_5 );
7058             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
7059             dmsa1.deleteGapOnlyColumns();
7060             dmsa1.deleteRow( "a", false );
7061             dmsa1.deleteRow( "f", false );
7062             dmsa1.deleteRow( "d", false );
7063             dmsa1.deleteGapOnlyColumns();
7064             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
7065                 return false;
7066             }
7067             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
7068                 return false;
7069             }
7070             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
7071                 return false;
7072             }
7073             dmsa1.deleteRow( "c", false );
7074             dmsa1.deleteGapOnlyColumns();
7075             final Writer w0 = new StringWriter();
7076             dmsa1.write( w0, MSA_FORMAT.FASTA );
7077             final Writer w1 = new StringWriter();
7078             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
7079             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
7080                 return false;
7081             }
7082             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
7083                 return false;
7084             }
7085             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
7086             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
7087             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
7088             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
7089             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
7090             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
7091             final List<MolecularSequence> l2 = new ArrayList<>();
7092             l2.add( s__0 );
7093             l2.add( s__1 );
7094             l2.add( s__2 );
7095             l2.add( s__3 );
7096             l2.add( s__4 );
7097             l2.add( s__5 );
7098             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
7099             dmsa2.deleteGapColumns( 0.5 );
7100             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
7101                 return false;
7102             }
7103             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
7104                 return false;
7105             }
7106             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
7107                 return false;
7108             }
7109             dmsa2.deleteGapColumns( 0.2 );
7110             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
7111                 return false;
7112             }
7113             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
7114                 return false;
7115             }
7116             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
7117                 return false;
7118             }
7119             dmsa2.deleteGapColumns( 0 );
7120             dmsa2.deleteRow( "a", false );
7121             dmsa2.deleteRow( "b", false );
7122             dmsa2.deleteRow( "f", false );
7123             dmsa2.deleteRow( "e", false );
7124             dmsa2.setIdentifier( 0, "new_c" );
7125             dmsa2.setIdentifier( 1, "new_d" );
7126             dmsa2.setResidueAt( 0, 0, 'x' );
7127             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
7128             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
7129                 return false;
7130             }
7131             final Writer w = new StringWriter();
7132             dmsa2.write( w, MSA_FORMAT.PHYLIP );
7133             final String phylip = w.toString();
7134             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
7135                 System.out.println( phylip );
7136                 return false;
7137             }
7138             final Writer w2 = new StringWriter();
7139             dmsa2.write( w2, MSA_FORMAT.FASTA );
7140             final String fasta = w2.toString();
7141             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
7142                 System.out.println( fasta );
7143                 return false;
7144             }
7145         }
7146         catch ( final Exception e ) {
7147             e.printStackTrace( System.out );
7148             return false;
7149         }
7150         return true;
7151     }
7152
7153     private static boolean testNextNodeWithCollapsing() {
7154         try {
7155             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7156             PhylogenyNode n;
7157             List<PhylogenyNode> ext = new ArrayList<>();
7158             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7159             final Phylogeny t0 = factory.create( sb0.toString(), new NHXParser() )[ 0 ];
7160             t0.getNode( "cd" ).setCollapse( true );
7161             t0.getNode( "cde" ).setCollapse( true );
7162             n = t0.getFirstExternalNode();
7163             while ( n != null ) {
7164                 ext.add( n );
7165                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7166             }
7167             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7168                 return false;
7169             }
7170             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7171                 return false;
7172             }
7173             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
7174                 return false;
7175             }
7176             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
7177                 return false;
7178             }
7179             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
7180                 return false;
7181             }
7182             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
7183                 return false;
7184             }
7185             ext.clear();
7186             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7187             final Phylogeny t1 = factory.create( sb1.toString(), new NHXParser() )[ 0 ];
7188             t1.getNode( "ab" ).setCollapse( true );
7189             t1.getNode( "cd" ).setCollapse( true );
7190             t1.getNode( "cde" ).setCollapse( true );
7191             n = t1.getNode( "ab" );
7192             ext = new ArrayList<>();
7193             while ( n != null ) {
7194                 ext.add( n );
7195                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7196             }
7197             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7198                 return false;
7199             }
7200             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7201                 return false;
7202             }
7203             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
7204                 return false;
7205             }
7206             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
7207                 return false;
7208             }
7209             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
7210                 return false;
7211             }
7212             ext.clear();
7213             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7214             final Phylogeny t2 = factory.create( sb2.toString(), new NHXParser() )[ 0 ];
7215             t2.getNode( "ab" ).setCollapse( true );
7216             t2.getNode( "cd" ).setCollapse( true );
7217             t2.getNode( "cde" ).setCollapse( true );
7218             t2.getNode( "c" ).setCollapse( true );
7219             t2.getNode( "d" ).setCollapse( true );
7220             t2.getNode( "e" ).setCollapse( true );
7221             t2.getNode( "gh" ).setCollapse( true );
7222             n = t2.getNode( "ab" );
7223             ext = new ArrayList<>();
7224             while ( n != null ) {
7225                 ext.add( n );
7226                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7227             }
7228             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7229                 return false;
7230             }
7231             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7232                 return false;
7233             }
7234             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
7235                 return false;
7236             }
7237             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
7238                 return false;
7239             }
7240             ext.clear();
7241             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7242             final Phylogeny t3 = factory.create( sb3.toString(), new NHXParser() )[ 0 ];
7243             t3.getNode( "ab" ).setCollapse( true );
7244             t3.getNode( "cd" ).setCollapse( true );
7245             t3.getNode( "cde" ).setCollapse( true );
7246             t3.getNode( "c" ).setCollapse( true );
7247             t3.getNode( "d" ).setCollapse( true );
7248             t3.getNode( "e" ).setCollapse( true );
7249             t3.getNode( "gh" ).setCollapse( true );
7250             t3.getNode( "fgh" ).setCollapse( true );
7251             n = t3.getNode( "ab" );
7252             ext = new ArrayList<>();
7253             while ( n != null ) {
7254                 ext.add( n );
7255                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7256             }
7257             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7258                 return false;
7259             }
7260             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7261                 return false;
7262             }
7263             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
7264                 return false;
7265             }
7266             ext.clear();
7267             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7268             final Phylogeny t4 = factory.create( sb4.toString(), new NHXParser() )[ 0 ];
7269             t4.getNode( "ab" ).setCollapse( true );
7270             t4.getNode( "cd" ).setCollapse( true );
7271             t4.getNode( "cde" ).setCollapse( true );
7272             t4.getNode( "c" ).setCollapse( true );
7273             t4.getNode( "d" ).setCollapse( true );
7274             t4.getNode( "e" ).setCollapse( true );
7275             t4.getNode( "gh" ).setCollapse( true );
7276             t4.getNode( "fgh" ).setCollapse( true );
7277             t4.getNode( "abcdefgh" ).setCollapse( true );
7278             n = t4.getNode( "abcdefgh" );
7279             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
7280                 return false;
7281             }
7282             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7283             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
7284             ext.clear();
7285             n = t5.getFirstExternalNode();
7286             while ( n != null ) {
7287                 ext.add( n );
7288                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7289             }
7290             if ( ext.size() != 8 ) {
7291                 return false;
7292             }
7293             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7294                 return false;
7295             }
7296             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7297                 return false;
7298             }
7299             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7300                 return false;
7301             }
7302             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7303                 return false;
7304             }
7305             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7306                 return false;
7307             }
7308             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7309                 return false;
7310             }
7311             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
7312                 return false;
7313             }
7314             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
7315                 return false;
7316             }
7317             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7318             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
7319             ext.clear();
7320             t6.getNode( "ab" ).setCollapse( true );
7321             n = t6.getNode( "ab" );
7322             while ( n != null ) {
7323                 ext.add( n );
7324                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7325             }
7326             if ( ext.size() != 7 ) {
7327                 return false;
7328             }
7329             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7330                 return false;
7331             }
7332             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7333                 return false;
7334             }
7335             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7336                 return false;
7337             }
7338             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7339                 return false;
7340             }
7341             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7342                 return false;
7343             }
7344             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7345                 return false;
7346             }
7347             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7348                 return false;
7349             }
7350             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7351             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
7352             ext.clear();
7353             t7.getNode( "cd" ).setCollapse( true );
7354             n = t7.getNode( "a" );
7355             while ( n != null ) {
7356                 ext.add( n );
7357                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7358             }
7359             if ( ext.size() != 7 ) {
7360                 return false;
7361             }
7362             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7363                 return false;
7364             }
7365             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7366                 return false;
7367             }
7368             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7369                 return false;
7370             }
7371             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7372                 return false;
7373             }
7374             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7375                 return false;
7376             }
7377             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7378                 return false;
7379             }
7380             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7381                 return false;
7382             }
7383             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7384             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
7385             ext.clear();
7386             t8.getNode( "cd" ).setCollapse( true );
7387             t8.getNode( "c" ).setCollapse( true );
7388             t8.getNode( "d" ).setCollapse( true );
7389             n = t8.getNode( "a" );
7390             while ( n != null ) {
7391                 ext.add( n );
7392                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7393             }
7394             if ( ext.size() != 7 ) {
7395                 return false;
7396             }
7397             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7398                 return false;
7399             }
7400             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7401                 return false;
7402             }
7403             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7404                 System.out.println( "2 fail" );
7405                 return false;
7406             }
7407             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7408                 return false;
7409             }
7410             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7411                 return false;
7412             }
7413             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7414                 return false;
7415             }
7416             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7417                 return false;
7418             }
7419             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7420             final Phylogeny t9 = factory.create( sb9.toString(), new NHXParser() )[ 0 ];
7421             ext.clear();
7422             t9.getNode( "gh" ).setCollapse( true );
7423             n = t9.getNode( "a" );
7424             while ( n != null ) {
7425                 ext.add( n );
7426                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7427             }
7428             if ( ext.size() != 7 ) {
7429                 return false;
7430             }
7431             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7432                 return false;
7433             }
7434             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7435                 return false;
7436             }
7437             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7438                 return false;
7439             }
7440             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7441                 return false;
7442             }
7443             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7444                 return false;
7445             }
7446             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7447                 return false;
7448             }
7449             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7450                 return false;
7451             }
7452             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7453             final Phylogeny t10 = factory.create( sb10.toString(), new NHXParser() )[ 0 ];
7454             ext.clear();
7455             t10.getNode( "gh" ).setCollapse( true );
7456             t10.getNode( "g" ).setCollapse( true );
7457             t10.getNode( "h" ).setCollapse( true );
7458             n = t10.getNode( "a" );
7459             while ( n != null ) {
7460                 ext.add( n );
7461                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7462             }
7463             if ( ext.size() != 7 ) {
7464                 return false;
7465             }
7466             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7467                 return false;
7468             }
7469             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7470                 return false;
7471             }
7472             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7473                 return false;
7474             }
7475             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7476                 return false;
7477             }
7478             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7479                 return false;
7480             }
7481             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7482                 return false;
7483             }
7484             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7485                 return false;
7486             }
7487             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7488             final Phylogeny t11 = factory.create( sb11.toString(), new NHXParser() )[ 0 ];
7489             ext.clear();
7490             t11.getNode( "gh" ).setCollapse( true );
7491             t11.getNode( "fgh" ).setCollapse( true );
7492             n = t11.getNode( "a" );
7493             while ( n != null ) {
7494                 ext.add( n );
7495                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7496             }
7497             if ( ext.size() != 6 ) {
7498                 return false;
7499             }
7500             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7501                 return false;
7502             }
7503             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7504                 return false;
7505             }
7506             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7507                 return false;
7508             }
7509             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7510                 return false;
7511             }
7512             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7513                 return false;
7514             }
7515             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7516                 return false;
7517             }
7518             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7519             final Phylogeny t12 = factory.create( sb12.toString(), new NHXParser() )[ 0 ];
7520             ext.clear();
7521             t12.getNode( "gh" ).setCollapse( true );
7522             t12.getNode( "fgh" ).setCollapse( true );
7523             t12.getNode( "g" ).setCollapse( true );
7524             t12.getNode( "h" ).setCollapse( true );
7525             t12.getNode( "f" ).setCollapse( true );
7526             n = t12.getNode( "a" );
7527             while ( n != null ) {
7528                 ext.add( n );
7529                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7530             }
7531             if ( ext.size() != 6 ) {
7532                 return false;
7533             }
7534             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7535                 return false;
7536             }
7537             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7538                 return false;
7539             }
7540             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7541                 return false;
7542             }
7543             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7544                 return false;
7545             }
7546             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7547                 return false;
7548             }
7549             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7550                 return false;
7551             }
7552             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7553             final Phylogeny t13 = factory.create( sb13.toString(), new NHXParser() )[ 0 ];
7554             ext.clear();
7555             t13.getNode( "ab" ).setCollapse( true );
7556             t13.getNode( "b" ).setCollapse( true );
7557             t13.getNode( "fgh" ).setCollapse( true );
7558             t13.getNode( "gh" ).setCollapse( true );
7559             n = t13.getNode( "ab" );
7560             while ( n != null ) {
7561                 ext.add( n );
7562                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7563             }
7564             if ( ext.size() != 5 ) {
7565                 return false;
7566             }
7567             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7568                 return false;
7569             }
7570             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7571                 return false;
7572             }
7573             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7574                 return false;
7575             }
7576             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7577                 return false;
7578             }
7579             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7580                 return false;
7581             }
7582             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
7583             final Phylogeny t14 = factory.create( sb14.toString(), new NHXParser() )[ 0 ];
7584             ext.clear();
7585             t14.getNode( "ab" ).setCollapse( true );
7586             t14.getNode( "a" ).setCollapse( true );
7587             t14.getNode( "fgh" ).setCollapse( true );
7588             t14.getNode( "gh" ).setCollapse( true );
7589             n = t14.getNode( "ab" );
7590             while ( n != null ) {
7591                 ext.add( n );
7592                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7593             }
7594             if ( ext.size() != 5 ) {
7595                 return false;
7596             }
7597             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7598                 return false;
7599             }
7600             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7601                 return false;
7602             }
7603             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7604                 return false;
7605             }
7606             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7607                 return false;
7608             }
7609             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7610                 return false;
7611             }
7612             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" );
7613             final Phylogeny t15 = factory.create( sb15.toString(), new NHXParser() )[ 0 ];
7614             ext.clear();
7615             t15.getNode( "ab" ).setCollapse( true );
7616             t15.getNode( "a" ).setCollapse( true );
7617             t15.getNode( "fgh" ).setCollapse( true );
7618             t15.getNode( "gh" ).setCollapse( true );
7619             n = t15.getNode( "ab" );
7620             while ( n != null ) {
7621                 ext.add( n );
7622                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7623             }
7624             if ( ext.size() != 6 ) {
7625                 return false;
7626             }
7627             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7628                 return false;
7629             }
7630             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7631                 return false;
7632             }
7633             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7634                 return false;
7635             }
7636             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7637                 return false;
7638             }
7639             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
7640                 return false;
7641             }
7642             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7643                 return false;
7644             }
7645             //
7646             //
7647             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" );
7648             final Phylogeny t16 = factory.create( sb16.toString(), new NHXParser() )[ 0 ];
7649             ext.clear();
7650             t16.getNode( "ab" ).setCollapse( true );
7651             t16.getNode( "a" ).setCollapse( true );
7652             t16.getNode( "fgh" ).setCollapse( true );
7653             t16.getNode( "gh" ).setCollapse( true );
7654             t16.getNode( "cd" ).setCollapse( true );
7655             t16.getNode( "cde" ).setCollapse( true );
7656             t16.getNode( "d" ).setCollapse( true );
7657             t16.getNode( "x" ).setCollapse( true );
7658             n = t16.getNode( "ab" );
7659             while ( n != null ) {
7660                 ext.add( n );
7661                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7662             }
7663             if ( ext.size() != 4 ) {
7664                 return false;
7665             }
7666             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7667                 return false;
7668             }
7669             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7670                 return false;
7671             }
7672             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
7673                 return false;
7674             }
7675             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
7676                 return false;
7677             }
7678         }
7679         catch ( final Exception e ) {
7680             e.printStackTrace( System.out );
7681             return false;
7682         }
7683         return true;
7684     }
7685
7686     private static boolean testNexusCharactersParsing() {
7687         try {
7688             final NexusCharactersParser parser = new NexusCharactersParser();
7689             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
7690             parser.parse();
7691             String[] labels = parser.getCharStateLabels();
7692             if ( labels.length != 7 ) {
7693                 return false;
7694             }
7695             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7696                 return false;
7697             }
7698             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7699                 return false;
7700             }
7701             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7702                 return false;
7703             }
7704             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7705                 return false;
7706             }
7707             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7708                 return false;
7709             }
7710             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7711                 return false;
7712             }
7713             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7714                 return false;
7715             }
7716             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7717             parser.parse();
7718             labels = parser.getCharStateLabels();
7719             if ( labels.length != 7 ) {
7720                 return false;
7721             }
7722             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7723                 return false;
7724             }
7725             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7726                 return false;
7727             }
7728             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7729                 return false;
7730             }
7731             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7732                 return false;
7733             }
7734             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7735                 return false;
7736             }
7737             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7738                 return false;
7739             }
7740             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7741                 return false;
7742             }
7743         }
7744         catch ( final Exception e ) {
7745             e.printStackTrace( System.out );
7746             return false;
7747         }
7748         return true;
7749     }
7750
7751     private static boolean testNexusMatrixParsing() {
7752         try {
7753             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7754             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7755             parser.parse();
7756             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7757             if ( m.getNumberOfCharacters() != 9 ) {
7758                 return false;
7759             }
7760             if ( m.getNumberOfIdentifiers() != 5 ) {
7761                 return false;
7762             }
7763             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7764                 return false;
7765             }
7766             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7767                 return false;
7768             }
7769             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7770                 return false;
7771             }
7772             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7773                 return false;
7774             }
7775             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7776                 return false;
7777             }
7778             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7779                 return false;
7780             }
7781             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7782                 return false;
7783             }
7784             //            if ( labels.length != 7 ) {
7785             //                return false;
7786             //            }
7787             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7788             //                return false;
7789             //            }
7790             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7791             //                return false;
7792             //            }
7793             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7794             //                return false;
7795             //            }
7796             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7797             //                return false;
7798             //            }
7799             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7800             //                return false;
7801             //            }
7802             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7803             //                return false;
7804             //            }
7805             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7806             //                return false;
7807             //            }
7808             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7809             //            parser.parse();
7810             //            labels = parser.getCharStateLabels();
7811             //            if ( labels.length != 7 ) {
7812             //                return false;
7813             //            }
7814             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7815             //                return false;
7816             //            }
7817             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7818             //                return false;
7819             //            }
7820             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7821             //                return false;
7822             //            }
7823             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7824             //                return false;
7825             //            }
7826             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7827             //                return false;
7828             //            }
7829             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7830             //                return false;
7831             //            }
7832             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7833             //                return false;
7834             //            }
7835         }
7836         catch ( final Exception e ) {
7837             e.printStackTrace( System.out );
7838             return false;
7839         }
7840         return true;
7841     }
7842
7843     private static boolean testNexusTreeParsing() {
7844         try {
7845             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7846             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7847             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7848             if ( phylogenies.length != 1 ) {
7849                 return false;
7850             }
7851             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7852                 return false;
7853             }
7854             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7855                 return false;
7856             }
7857             phylogenies = null;
7858             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7859             if ( phylogenies.length != 1 ) {
7860                 return false;
7861             }
7862             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7863                 return false;
7864             }
7865             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7866                 return false;
7867             }
7868             phylogenies = null;
7869             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7870             if ( phylogenies.length != 1 ) {
7871                 return false;
7872             }
7873             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7874                 return false;
7875             }
7876             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7877                 return false;
7878             }
7879             if ( phylogenies[ 0 ].isRooted() ) {
7880                 return false;
7881             }
7882             phylogenies = null;
7883             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7884             if ( phylogenies.length != 18 ) {
7885                 return false;
7886             }
7887             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7888                 return false;
7889             }
7890             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7891                 return false;
7892             }
7893             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7894                 return false;
7895             }
7896             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7897                 return false;
7898             }
7899             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7900                 return false;
7901             }
7902             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7903                 return false;
7904             }
7905             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7906                 return false;
7907             }
7908             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7909                 return false;
7910             }
7911             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7912                 return false;
7913             }
7914             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7915                 return false;
7916             }
7917             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7918                 return false;
7919             }
7920             if ( phylogenies[ 8 ].isRooted() ) {
7921                 return false;
7922             }
7923             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7924                 return false;
7925             }
7926             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7927                 return false;
7928             }
7929             if ( !phylogenies[ 9 ].isRooted() ) {
7930                 return false;
7931             }
7932             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7933                 return false;
7934             }
7935             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7936                 return false;
7937             }
7938             if ( !phylogenies[ 10 ].isRooted() ) {
7939                 return false;
7940             }
7941             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7942                 return false;
7943             }
7944             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7945                 return false;
7946             }
7947             if ( phylogenies[ 11 ].isRooted() ) {
7948                 return false;
7949             }
7950             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7951                 return false;
7952             }
7953             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7954                 return false;
7955             }
7956             if ( !phylogenies[ 12 ].isRooted() ) {
7957                 return false;
7958             }
7959             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7960                 return false;
7961             }
7962             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7963                 return false;
7964             }
7965             if ( !phylogenies[ 13 ].isRooted() ) {
7966                 return false;
7967             }
7968             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7969                 return false;
7970             }
7971             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7972                 return false;
7973             }
7974             if ( !phylogenies[ 14 ].isRooted() ) {
7975                 return false;
7976             }
7977             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7978                 return false;
7979             }
7980             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7981                 return false;
7982             }
7983             if ( phylogenies[ 15 ].isRooted() ) {
7984                 return false;
7985             }
7986             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7987                 return false;
7988             }
7989             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7990                 return false;
7991             }
7992             if ( !phylogenies[ 16 ].isRooted() ) {
7993                 return false;
7994             }
7995             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7996                 return false;
7997             }
7998             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7999                 return false;
8000             }
8001             if ( phylogenies[ 17 ].isRooted() ) {
8002                 return false;
8003             }
8004             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
8005                 return false;
8006             }
8007             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
8008             phylogenies = null;
8009             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
8010             if ( phylogenies.length != 9 ) {
8011                 return false;
8012             }
8013             if ( !isEqual( 0.48039661496919533,
8014                            phylogenies[ 0 ].getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8015                 return false;
8016             }
8017             if ( !isEqual( 0.3959796191512233,
8018                            phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8019                 return false;
8020             }
8021             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
8022                 return false;
8023             }
8024             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
8025                 return false;
8026             }
8027             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
8028                 return false;
8029             }
8030             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
8031                 return false;
8032             }
8033             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
8034                 return false;
8035             }
8036         }
8037         catch ( final Exception e ) {
8038             e.printStackTrace( System.out );
8039             return false;
8040         }
8041         return true;
8042     }
8043
8044     private static boolean testNexusTreeParsingIterating() {
8045         try {
8046             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
8047             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
8048             if ( !p.hasNext() ) {
8049                 return false;
8050             }
8051             Phylogeny phy = p.next();
8052             if ( phy == null ) {
8053                 return false;
8054             }
8055             if ( phy.getNumberOfExternalNodes() != 25 ) {
8056                 return false;
8057             }
8058             if ( !phy.getName().equals( "" ) ) {
8059                 return false;
8060             }
8061             if ( p.hasNext() ) {
8062                 return false;
8063             }
8064             phy = p.next();
8065             if ( phy != null ) {
8066                 return false;
8067             }
8068             p.reset();
8069             if ( !p.hasNext() ) {
8070                 return false;
8071             }
8072             phy = p.next();
8073             if ( phy == null ) {
8074                 return false;
8075             }
8076             if ( phy.getNumberOfExternalNodes() != 25 ) {
8077                 return false;
8078             }
8079             if ( !phy.getName().equals( "" ) ) {
8080                 return false;
8081             }
8082             if ( p.hasNext() ) {
8083                 return false;
8084             }
8085             phy = p.next();
8086             if ( phy != null ) {
8087                 return false;
8088             }
8089             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
8090             if ( !p.hasNext() ) {
8091                 return false;
8092             }
8093             phy = p.next();
8094             if ( phy == null ) {
8095                 return false;
8096             }
8097             if ( phy.getNumberOfExternalNodes() != 10 ) {
8098                 return false;
8099             }
8100             if ( !phy.getName().equals( "name" ) ) {
8101                 return false;
8102             }
8103             if ( p.hasNext() ) {
8104                 return false;
8105             }
8106             phy = p.next();
8107             if ( phy != null ) {
8108                 return false;
8109             }
8110             p.reset();
8111             if ( !p.hasNext() ) {
8112                 return false;
8113             }
8114             phy = p.next();
8115             if ( phy == null ) {
8116                 return false;
8117             }
8118             if ( phy.getNumberOfExternalNodes() != 10 ) {
8119                 return false;
8120             }
8121             if ( !phy.getName().equals( "name" ) ) {
8122                 return false;
8123             }
8124             if ( p.hasNext() ) {
8125                 return false;
8126             }
8127             phy = p.next();
8128             if ( phy != null ) {
8129                 return false;
8130             }
8131             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
8132             if ( !p.hasNext() ) {
8133                 return false;
8134             }
8135             phy = p.next();
8136             if ( phy == null ) {
8137                 return false;
8138             }
8139             if ( phy.getNumberOfExternalNodes() != 3 ) {
8140                 return false;
8141             }
8142             if ( !phy.getName().equals( "" ) ) {
8143                 return false;
8144             }
8145             if ( phy.isRooted() ) {
8146                 return false;
8147             }
8148             if ( p.hasNext() ) {
8149                 return false;
8150             }
8151             phy = p.next();
8152             if ( phy != null ) {
8153                 return false;
8154             }
8155             //
8156             p.reset();
8157             if ( !p.hasNext() ) {
8158                 return false;
8159             }
8160             phy = p.next();
8161             if ( phy == null ) {
8162                 return false;
8163             }
8164             if ( phy.getNumberOfExternalNodes() != 3 ) {
8165                 return false;
8166             }
8167             if ( !phy.getName().equals( "" ) ) {
8168                 return false;
8169             }
8170             if ( p.hasNext() ) {
8171                 return false;
8172             }
8173             phy = p.next();
8174             if ( phy != null ) {
8175                 return false;
8176             }
8177             //
8178             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
8179             if ( !p.hasNext() ) {
8180                 return false;
8181             }
8182             //0
8183             phy = p.next();
8184             if ( phy == null ) {
8185                 return false;
8186             }
8187             if ( phy.getNumberOfExternalNodes() != 10 ) {
8188                 return false;
8189             }
8190             if ( !phy.getName().equals( "tree 0" ) ) {
8191                 return false;
8192             }
8193             //1
8194             if ( !p.hasNext() ) {
8195                 return false;
8196             }
8197             phy = p.next();
8198             if ( phy == null ) {
8199                 return false;
8200             }
8201             if ( phy.getNumberOfExternalNodes() != 10 ) {
8202                 return false;
8203             }
8204             if ( !phy.getName().equals( "tree 1" ) ) {
8205                 return false;
8206             }
8207             //2
8208             if ( !p.hasNext() ) {
8209                 return false;
8210             }
8211             phy = p.next();
8212             if ( phy == null ) {
8213                 return false;
8214             }
8215             if ( phy.getNumberOfExternalNodes() != 3 ) {
8216                 System.out.println( phy.toString() );
8217                 return false;
8218             }
8219             if ( !phy.getName().equals( "" ) ) {
8220                 return false;
8221             }
8222             if ( phy.isRooted() ) {
8223                 return false;
8224             }
8225             //3
8226             if ( !p.hasNext() ) {
8227                 return false;
8228             }
8229             phy = p.next();
8230             if ( phy == null ) {
8231                 return false;
8232             }
8233             if ( phy.getNumberOfExternalNodes() != 4 ) {
8234                 return false;
8235             }
8236             if ( !phy.getName().equals( "" ) ) {
8237                 return false;
8238             }
8239             if ( !phy.isRooted() ) {
8240                 return false;
8241             }
8242             //4
8243             if ( !p.hasNext() ) {
8244                 return false;
8245             }
8246             phy = p.next();
8247             if ( phy == null ) {
8248                 return false;
8249             }
8250             if ( phy.getNumberOfExternalNodes() != 5 ) {
8251                 System.out.println( phy.getNumberOfExternalNodes() );
8252                 return false;
8253             }
8254             if ( !phy.getName().equals( "" ) ) {
8255                 return false;
8256             }
8257             if ( !phy.isRooted() ) {
8258                 return false;
8259             }
8260             //5
8261             if ( !p.hasNext() ) {
8262                 return false;
8263             }
8264             phy = p.next();
8265             if ( phy == null ) {
8266                 return false;
8267             }
8268             if ( phy.getNumberOfExternalNodes() != 3 ) {
8269                 return false;
8270             }
8271             if ( !phy.getName().equals( "" ) ) {
8272                 return false;
8273             }
8274             if ( phy.isRooted() ) {
8275                 return false;
8276             }
8277             //6
8278             if ( !p.hasNext() ) {
8279                 return false;
8280             }
8281             phy = p.next();
8282             if ( phy == null ) {
8283                 return false;
8284             }
8285             if ( phy.getNumberOfExternalNodes() != 2 ) {
8286                 return false;
8287             }
8288             if ( !phy.getName().equals( "" ) ) {
8289                 return false;
8290             }
8291             if ( !phy.isRooted() ) {
8292                 return false;
8293             }
8294             //7
8295             if ( !p.hasNext() ) {
8296                 return false;
8297             }
8298             phy = p.next();
8299             if ( phy.getNumberOfExternalNodes() != 3 ) {
8300                 return false;
8301             }
8302             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8303                 return false;
8304             }
8305             if ( !phy.isRooted() ) {
8306                 return false;
8307             }
8308             //8
8309             if ( !p.hasNext() ) {
8310                 return false;
8311             }
8312             phy = p.next();
8313             if ( phy.getNumberOfExternalNodes() != 3 ) {
8314                 return false;
8315             }
8316             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
8317                 return false;
8318             }
8319             if ( !phy.getName().equals( "tree 8" ) ) {
8320                 return false;
8321             }
8322             //9
8323             if ( !p.hasNext() ) {
8324                 return false;
8325             }
8326             phy = p.next();
8327             if ( phy.getNumberOfExternalNodes() != 3 ) {
8328                 return false;
8329             }
8330             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
8331                 return false;
8332             }
8333             if ( !phy.getName().equals( "tree 9" ) ) {
8334                 return false;
8335             }
8336             //10
8337             if ( !p.hasNext() ) {
8338                 return false;
8339             }
8340             phy = p.next();
8341             if ( phy.getNumberOfExternalNodes() != 3 ) {
8342                 return false;
8343             }
8344             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8345                 return false;
8346             }
8347             if ( !phy.getName().equals( "tree 10" ) ) {
8348                 return false;
8349             }
8350             if ( !phy.isRooted() ) {
8351                 return false;
8352             }
8353             //11
8354             if ( !p.hasNext() ) {
8355                 return false;
8356             }
8357             phy = p.next();
8358             if ( phy.getNumberOfExternalNodes() != 3 ) {
8359                 return false;
8360             }
8361             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
8362                 return false;
8363             }
8364             if ( !phy.getName().equals( "tree 11" ) ) {
8365                 return false;
8366             }
8367             if ( phy.isRooted() ) {
8368                 return false;
8369             }
8370             //12
8371             if ( !p.hasNext() ) {
8372                 return false;
8373             }
8374             phy = p.next();
8375             if ( phy.getNumberOfExternalNodes() != 3 ) {
8376                 return false;
8377             }
8378             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
8379                 return false;
8380             }
8381             if ( !phy.getName().equals( "tree 12" ) ) {
8382                 return false;
8383             }
8384             if ( !phy.isRooted() ) {
8385                 return false;
8386             }
8387             //13
8388             if ( !p.hasNext() ) {
8389                 return false;
8390             }
8391             phy = p.next();
8392             if ( phy.getNumberOfExternalNodes() != 3 ) {
8393                 return false;
8394             }
8395             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8396                 return false;
8397             }
8398             if ( !phy.getName().equals( "tree 13" ) ) {
8399                 return false;
8400             }
8401             if ( !phy.isRooted() ) {
8402                 return false;
8403             }
8404             //14
8405             if ( !p.hasNext() ) {
8406                 return false;
8407             }
8408             phy = p.next();
8409             if ( phy.getNumberOfExternalNodes() != 10 ) {
8410                 System.out.println( phy.getNumberOfExternalNodes() );
8411                 return false;
8412             }
8413             if ( !phy.toNewHampshire()
8414                     .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;" ) ) {
8415                 System.out.println( phy.toNewHampshire() );
8416                 return false;
8417             }
8418             if ( !phy.getName().equals( "tree 14" ) ) {
8419                 return false;
8420             }
8421             if ( !phy.isRooted() ) {
8422                 return false;
8423             }
8424             //15
8425             if ( !p.hasNext() ) {
8426                 return false;
8427             }
8428             phy = p.next();
8429             if ( phy.getNumberOfExternalNodes() != 10 ) {
8430                 System.out.println( phy.getNumberOfExternalNodes() );
8431                 return false;
8432             }
8433             if ( !phy.toNewHampshire()
8434                     .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;" ) ) {
8435                 System.out.println( phy.toNewHampshire() );
8436                 return false;
8437             }
8438             if ( !phy.getName().equals( "tree 15" ) ) {
8439                 return false;
8440             }
8441             if ( phy.isRooted() ) {
8442                 return false;
8443             }
8444             //16
8445             if ( !p.hasNext() ) {
8446                 return false;
8447             }
8448             phy = p.next();
8449             if ( phy.getNumberOfExternalNodes() != 10 ) {
8450                 System.out.println( phy.getNumberOfExternalNodes() );
8451                 return false;
8452             }
8453             if ( !phy.toNewHampshire()
8454                     .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;" ) ) {
8455                 System.out.println( phy.toNewHampshire() );
8456                 return false;
8457             }
8458             if ( !phy.getName().equals( "tree 16" ) ) {
8459                 return false;
8460             }
8461             if ( !phy.isRooted() ) {
8462                 return false;
8463             }
8464             //17
8465             if ( !p.hasNext() ) {
8466                 return false;
8467             }
8468             phy = p.next();
8469             if ( phy.getNumberOfExternalNodes() != 10 ) {
8470                 System.out.println( phy.getNumberOfExternalNodes() );
8471                 return false;
8472             }
8473             if ( !phy.toNewHampshire()
8474                     .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;" ) ) {
8475                 System.out.println( phy.toNewHampshire() );
8476                 return false;
8477             }
8478             if ( !phy.getName().equals( "tree 17" ) ) {
8479                 return false;
8480             }
8481             if ( phy.isRooted() ) {
8482                 return false;
8483             }
8484             //
8485             if ( p.hasNext() ) {
8486                 return false;
8487             }
8488             phy = p.next();
8489             if ( phy != null ) {
8490                 return false;
8491             }
8492             p.reset();
8493             //0
8494             if ( !p.hasNext() ) {
8495                 return false;
8496             }
8497             phy = p.next();
8498             if ( phy == null ) {
8499                 return false;
8500             }
8501             if ( phy.getNumberOfExternalNodes() != 10 ) {
8502                 return false;
8503             }
8504             if ( !phy.getName().equals( "tree 0" ) ) {
8505                 return false;
8506             }
8507             //1
8508             if ( !p.hasNext() ) {
8509                 return false;
8510             }
8511             phy = p.next();
8512             if ( phy == null ) {
8513                 return false;
8514             }
8515             if ( phy.getNumberOfExternalNodes() != 10 ) {
8516                 return false;
8517             }
8518             if ( !phy.getName().equals( "tree 1" ) ) {
8519                 return false;
8520             }
8521             //2
8522             if ( !p.hasNext() ) {
8523                 return false;
8524             }
8525             phy = p.next();
8526             if ( phy == null ) {
8527                 return false;
8528             }
8529             if ( phy.getNumberOfExternalNodes() != 3 ) {
8530                 return false;
8531             }
8532             if ( !phy.getName().equals( "" ) ) {
8533                 return false;
8534             }
8535             if ( phy.isRooted() ) {
8536                 return false;
8537             }
8538             //3
8539             if ( !p.hasNext() ) {
8540                 return false;
8541             }
8542             phy = p.next();
8543             if ( phy == null ) {
8544                 return false;
8545             }
8546             if ( phy.getNumberOfExternalNodes() != 4 ) {
8547                 return false;
8548             }
8549             if ( !phy.getName().equals( "" ) ) {
8550                 return false;
8551             }
8552             if ( !phy.isRooted() ) {
8553                 return false;
8554             }
8555             //4
8556             if ( !p.hasNext() ) {
8557                 return false;
8558             }
8559             phy = p.next();
8560             if ( phy == null ) {
8561                 return false;
8562             }
8563             if ( phy.getNumberOfExternalNodes() != 5 ) {
8564                 System.out.println( phy.getNumberOfExternalNodes() );
8565                 return false;
8566             }
8567             if ( !phy.getName().equals( "" ) ) {
8568                 return false;
8569             }
8570             if ( !phy.isRooted() ) {
8571                 return false;
8572             }
8573             //5
8574             if ( !p.hasNext() ) {
8575                 return false;
8576             }
8577             phy = p.next();
8578             if ( phy == null ) {
8579                 return false;
8580             }
8581             if ( phy.getNumberOfExternalNodes() != 3 ) {
8582                 return false;
8583             }
8584             if ( !phy.getName().equals( "" ) ) {
8585                 return false;
8586             }
8587             if ( phy.isRooted() ) {
8588                 return false;
8589             }
8590             //
8591             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
8592             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
8593             // 0
8594             if ( !p2.hasNext() ) {
8595                 return false;
8596             }
8597             phy = p2.next();
8598             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8599                 return false;
8600             }
8601             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8602                 return false;
8603             }
8604             // 1
8605             if ( !p2.hasNext() ) {
8606                 return false;
8607             }
8608             phy = p2.next();
8609             // 2
8610             if ( !p2.hasNext() ) {
8611                 return false;
8612             }
8613             phy = p2.next();
8614             // 3
8615             if ( !p2.hasNext() ) {
8616                 return false;
8617             }
8618             phy = p2.next();
8619             // 4
8620             if ( !p2.hasNext() ) {
8621                 return false;
8622             }
8623             phy = p2.next();
8624             // 5
8625             if ( !p2.hasNext() ) {
8626                 return false;
8627             }
8628             phy = p2.next();
8629             // 6
8630             if ( !p2.hasNext() ) {
8631                 return false;
8632             }
8633             phy = p2.next();
8634             // 7
8635             if ( !p2.hasNext() ) {
8636                 return false;
8637             }
8638             phy = p2.next();
8639             // 8
8640             if ( !p2.hasNext() ) {
8641                 return false;
8642             }
8643             phy = p2.next();
8644             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
8645                 return false;
8646             }
8647             if ( p2.hasNext() ) {
8648                 return false;
8649             }
8650             phy = p2.next();
8651             if ( phy != null ) {
8652                 return false;
8653             }
8654             // 0
8655             p2.reset();
8656             if ( !p2.hasNext() ) {
8657                 return false;
8658             }
8659             phy = p2.next();
8660             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8661                 return false;
8662             }
8663             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8664                 return false;
8665             }
8666         }
8667         catch ( final Exception e ) {
8668             e.printStackTrace( System.out );
8669             return false;
8670         }
8671         return true;
8672     }
8673
8674     private static boolean testNexusTreeParsingTranslating() {
8675         try {
8676             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8677             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
8678             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
8679             if ( phylogenies.length != 1 ) {
8680                 return false;
8681             }
8682             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8683                 return false;
8684             }
8685             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8686                 return false;
8687             }
8688             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8689                 return false;
8690             }
8691             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8692                 return false;
8693             }
8694             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8695                     .equals( "Aranaeus" ) ) {
8696                 return false;
8697             }
8698             phylogenies = null;
8699             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
8700             if ( phylogenies.length != 3 ) {
8701                 return false;
8702             }
8703             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8704                 return false;
8705             }
8706             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8707                 return false;
8708             }
8709             if ( phylogenies[ 0 ].isRooted() ) {
8710                 return false;
8711             }
8712             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8713                 return false;
8714             }
8715             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8716                 return false;
8717             }
8718             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8719                     .equals( "Aranaeus" ) ) {
8720                 return false;
8721             }
8722             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8723                 return false;
8724             }
8725             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8726                 return false;
8727             }
8728             if ( phylogenies[ 1 ].isRooted() ) {
8729                 return false;
8730             }
8731             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8732                 return false;
8733             }
8734             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8735                 return false;
8736             }
8737             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8738                     .equals( "Aranaeus" ) ) {
8739                 return false;
8740             }
8741             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8742                 return false;
8743             }
8744             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8745                 return false;
8746             }
8747             if ( !phylogenies[ 2 ].isRooted() ) {
8748                 return false;
8749             }
8750             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8751                 return false;
8752             }
8753             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8754                 return false;
8755             }
8756             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8757                     .equals( "Aranaeus" ) ) {
8758                 return false;
8759             }
8760             phylogenies = null;
8761             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8762             if ( phylogenies.length != 3 ) {
8763                 return false;
8764             }
8765             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8766                 return false;
8767             }
8768             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8769                 return false;
8770             }
8771             if ( phylogenies[ 0 ].isRooted() ) {
8772                 return false;
8773             }
8774             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8775                 return false;
8776             }
8777             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8778                 return false;
8779             }
8780             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8781                     .equals( "Aranaeus" ) ) {
8782                 return false;
8783             }
8784             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8785                 return false;
8786             }
8787             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8788                 return false;
8789             }
8790             if ( phylogenies[ 1 ].isRooted() ) {
8791                 return false;
8792             }
8793             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8794                 return false;
8795             }
8796             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8797                 return false;
8798             }
8799             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8800                     .equals( "Aranaeus" ) ) {
8801                 return false;
8802             }
8803             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8804                 return false;
8805             }
8806             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8807                 return false;
8808             }
8809             if ( !phylogenies[ 2 ].isRooted() ) {
8810                 return false;
8811             }
8812             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8813                 return false;
8814             }
8815             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8816                 return false;
8817             }
8818             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8819                     .equals( "Aranaeus" ) ) {
8820                 return false;
8821             }
8822             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8823             if ( phylogenies.length != 3 ) {
8824                 return false;
8825             }
8826             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8827                            0.00100049 ) ) {
8828                 return false;
8829             }
8830         }
8831         catch ( final Exception e ) {
8832             e.printStackTrace( System.out );
8833             return false;
8834         }
8835         return true;
8836     }
8837
8838     private static boolean testNHParsing() {
8839         try {
8840             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8841             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8842             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8843                 return false;
8844             }
8845             final NHXParser nhxp = new NHXParser();
8846             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8847             nhxp.setReplaceUnderscores( true );
8848             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8849             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8850                 return false;
8851             }
8852             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8853                 return false;
8854             }
8855             final Phylogeny p1b = factory.create(
8856                                                   "   \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 ",
8857                                                   new NHXParser() )[ 0 ];
8858             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8859                 return false;
8860             }
8861             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8862                 return false;
8863             }
8864             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ).toString(), new NHXParser() )[ 0 ];
8865             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8866             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8867             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ).toString(), new NHXParser() )[ 0 ];
8868             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8869             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8870             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8871             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8872             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8873             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8874             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8875                     + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; " + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8876                                                     new NHXParser() );
8877             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8878                 return false;
8879             }
8880             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8881                 return false;
8882             }
8883             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8884                 return false;
8885             }
8886             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8887                 return false;
8888             }
8889             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8890             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8891             final String p16_S = "((A,B),C)";
8892             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8893             if ( p16.length != 1 ) {
8894                 return false;
8895             }
8896             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8897                 return false;
8898             }
8899             final String p17_S = "(C,(A,B))";
8900             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8901             if ( p17.length != 1 ) {
8902                 return false;
8903             }
8904             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8905                 return false;
8906             }
8907             final String p18_S = "((A,B),(C,D))";
8908             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8909             if ( p18.length != 1 ) {
8910                 return false;
8911             }
8912             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8913                 return false;
8914             }
8915             final String p19_S = "(((A,B),C),D)";
8916             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8917             if ( p19.length != 1 ) {
8918                 return false;
8919             }
8920             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8921                 return false;
8922             }
8923             final String p20_S = "(A,(B,(C,D)))";
8924             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8925             if ( p20.length != 1 ) {
8926                 return false;
8927             }
8928             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8929                 return false;
8930             }
8931             final String p21_S = "(A,(B,(C,(D,E))))";
8932             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8933             if ( p21.length != 1 ) {
8934                 return false;
8935             }
8936             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8937                 return false;
8938             }
8939             final String p22_S = "((((A,B),C),D),E)";
8940             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8941             if ( p22.length != 1 ) {
8942                 return false;
8943             }
8944             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8945                 return false;
8946             }
8947             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8948             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8949             if ( p23.length != 1 ) {
8950                 System.out.println( "xl=" + p23.length );
8951                 System.exit( -1 );
8952                 return false;
8953             }
8954             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8955                 return false;
8956             }
8957             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8958             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8959             if ( p24.length != 1 ) {
8960                 return false;
8961             }
8962             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8963                 return false;
8964             }
8965             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8966             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8967             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8968             if ( p241.length != 2 ) {
8969                 return false;
8970             }
8971             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8972                 return false;
8973             }
8974             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8975                 return false;
8976             }
8977             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8978                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8979                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8980                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8981                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8982                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8983                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8984                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8985             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8986             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8987                 return false;
8988             }
8989             final String p26_S = "(A,B)ab";
8990             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8991             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8992                 return false;
8993             }
8994             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8995             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8996             if ( p27s.length != 1 ) {
8997                 System.out.println( "xxl=" + p27s.length );
8998                 System.exit( -1 );
8999                 return false;
9000             }
9001             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
9002                 System.out.println( p27s[ 0 ].toNewHampshireX() );
9003                 System.exit( -1 );
9004                 return false;
9005             }
9006             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
9007                                                     new NHXParser() );
9008             if ( p27.length != 1 ) {
9009                 System.out.println( "yl=" + p27.length );
9010                 System.exit( -1 );
9011                 return false;
9012             }
9013             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
9014                 System.out.println( p27[ 0 ].toNewHampshireX() );
9015                 System.exit( -1 );
9016                 return false;
9017             }
9018             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
9019             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
9020             final String p28_S3 = "(A,B)ab";
9021             final String p28_S4 = "((((A,B),C),D),;E;)";
9022             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
9023                                                     new NHXParser() );
9024             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
9025                 return false;
9026             }
9027             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
9028                 return false;
9029             }
9030             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
9031                 return false;
9032             }
9033             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
9034                 return false;
9035             }
9036             if ( p28.length != 4 ) {
9037                 return false;
9038             }
9039             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";
9040             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
9041             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
9042                 return false;
9043             }
9044             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";
9045             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
9046             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
9047                 return false;
9048             }
9049             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
9050             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
9051             if ( ( p32.length != 0 ) ) {
9052                 return false;
9053             }
9054             final String p33_S = "A";
9055             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
9056             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
9057                 return false;
9058             }
9059             final String p34_S = "B;";
9060             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
9061             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
9062                 return false;
9063             }
9064             final String p35_S = "B:0.2";
9065             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
9066             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
9067                 return false;
9068             }
9069             final String p36_S = "(A)";
9070             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
9071             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
9072                 return false;
9073             }
9074             final String p37_S = "((A))";
9075             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
9076             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
9077                 return false;
9078             }
9079             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
9080             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
9081             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
9082                 return false;
9083             }
9084             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
9085             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
9086             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
9087                 return false;
9088             }
9089             final String p40_S = "(A,B,C)";
9090             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
9091             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
9092                 return false;
9093             }
9094             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
9095             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
9096             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
9097                 return false;
9098             }
9099             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
9100             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
9101             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
9102                 return false;
9103             }
9104             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)";
9105             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
9106             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
9107                 return false;
9108             }
9109             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)))";
9110             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
9111             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
9112                 return false;
9113             }
9114             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
9115             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
9116             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
9117                 return false;
9118             }
9119             final String p46_S = "";
9120             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
9121             if ( p46.length != 0 ) {
9122                 return false;
9123             }
9124             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ).toString(),
9125                                                   new NHXParser() )[ 0 ];
9126             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
9127                 return false;
9128             }
9129             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ).toString(),
9130                                                   new NHXParser() )[ 0 ];
9131             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
9132                 return false;
9133             }
9134             final Phylogeny p49 = factory
9135                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ).toString(),
9136                              new NHXParser() )[ 0 ];
9137             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
9138                 return false;
9139             }
9140             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ).toString(),
9141                                                   new NHXParser() )[ 0 ];
9142             if ( p50.getNode( "A" ) == null ) {
9143                 return false;
9144             }
9145             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9146                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
9147                 return false;
9148             }
9149             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
9150                 return false;
9151             }
9152             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
9153                     .equals( "((A,B)88:2.0,C);" ) ) {
9154                 return false;
9155             }
9156             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ).toString(),
9157                                                   new NHXParser() )[ 0 ];
9158             if ( p51.getNode( "A(A" ) == null ) {
9159                 return false;
9160             }
9161             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ).toString(),
9162                                                   new NHXParser() )[ 0 ];
9163             if ( p52.getNode( "A(A" ) == null ) {
9164                 return false;
9165             }
9166             final Phylogeny p53 = factory
9167                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ).toString(),
9168                              new NHXParser() )[ 0 ];
9169             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
9170                 return false;
9171             }
9172             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ).toString(),
9173                                                   new NHXParser() )[ 0 ];
9174             if ( p54.getNode( "A" ) == null ) {
9175                 return false;
9176             }
9177             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9178                     .equals( "((A,B)[88],C);" ) ) {
9179                 return false;
9180             }
9181             final Phylogeny p55 = factory
9182                     .create( new StringBuffer( "((\"lcl|HPV32_L1.:1  s\":0.195593,\"lcl|HPV30_L1.1|;a\":0.114237):0.0359322,\"lcl|HPV56_L1.1|,d\":0.0727412,\"lcl|HPV66_L1.1x\":0.0798012);" )
9183                             .toString(), new NHXParser() )[ 0 ];
9184             if ( !p55.toNewHampshire()
9185                     .equals( "(('lcl|HPV32_L1.:1 s':0.195593,'lcl|HPV30_L1.1|;a':0.114237):0.0359322,'lcl|HPV56_L1.1|,d':0.0727412,lcl|HPV66_L1.1x:0.0798012);" ) ) {
9186                 System.out.println( p55.toNewHampshire() );
9187                 return false;
9188             }
9189             final Phylogeny p56 = factory
9190                     .create( new StringBuffer( "((\"lcl|HPV32_L1.:1      s\":0.195593,\"lcl|HPV30_L1.1|;a\":0.114\n237):0.0359322,\"lcl|HPV56_L1.1|,d\":0.0727412,\"lcl|HPV66_L1.1:x\":0.0798012);" )
9191                             .toString(), new NHXParser() )[ 0 ];
9192             if ( !p56.toNewHampshire()
9193                     .equals( "(('lcl|HPV32_L1.:1 s':0.195593,'lcl|HPV30_L1.1|;a':0.114237):0.0359322,'lcl|HPV56_L1.1|,d':0.0727412,'lcl|HPV66_L1.1:x':0.0798012);" ) ) {
9194                 System.out.println( p56.toNewHampshire() );
9195                 return false;
9196             }
9197             final Phylogeny p57 = factory
9198                     .create( new StringBuffer( "((\"lcl|HPV32_L1.:1      s\":0.195593,\"lcl|HPV30_L1.1|;a\":0.114\n237):0.0359322,\"lcl|HPV56_L1.1|,d\":0.0727412,\"lcl|HPV66_L1.1:x\":0.0798012);" )
9199                             .toString(), new NHXParser() )[ 0 ];
9200             if ( !p57.toNewHampshire()
9201                     .equals( "(('lcl|HPV32_L1.:1 s':0.195593,'lcl|HPV30_L1.1|;a':0.114237):0.0359322,'lcl|HPV56_L1.1|,d':0.0727412,'lcl|HPV66_L1.1:x':0.0798012);" ) ) {
9202                 System.out.println( p56.toNewHampshire() );
9203                 return false;
9204             }
9205             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
9206             final Phylogeny p58 = factory.create( s58, new NHXParser() )[ 0 ];
9207             if ( !p58.toNewHampshire().equals( s58 ) ) {
9208                 System.out.println( p58.toNewHampshire() );
9209                 return false;
9210             }
9211             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
9212             final Phylogeny p59 = factory.create( s59, new NHXParser() )[ 0 ];
9213             if ( !p59.toNewHampshire().equals( s59 ) ) {
9214                 System.out.println( p59.toNewHampshire() );
9215                 return false;
9216             }
9217             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
9218             final Phylogeny p60 = factory.create( s60, new NHXParser() )[ 0 ];
9219             if ( !p60.toNewHampshire().equals( s60 ) ) {
9220                 System.out.println( p60.toNewHampshire() );
9221                 return false;
9222             }
9223             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
9224             final Phylogeny p61 = factory.create( s61, new NHXParser() )[ 0 ];
9225             if ( !p61.toNewHampshire()
9226                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
9227                 System.out.println( p61.toNewHampshire() );
9228                 return false;
9229             }
9230             final String s62 = "(1[&type=\"X\",size=123,subtree=(1,2);]:0.003,2[&type=\"(X,Y:3)\"]:0.004)[&type=\"(X,Y)\"]:0.0;";
9231             final Phylogeny p62 = factory.create( s62, new NHXParser() )[ 0 ];
9232             if ( !p62.toNewHampshire().equals( "(1:0.003,2:0.004):0.0;" ) ) {
9233                 System.out.println( p62.toNewHampshire() );
9234                 return false;
9235             }
9236             final String s63 = "(1:0.003[&type=\"X\",size=123,subtree=(1,2);],2:0.004[&type=\"(X,Y:3)\"]):0.0[&type=\"(X,Y)\"];";
9237             final Phylogeny p63 = factory.create( s63, new NHXParser() )[ 0 ];
9238             if ( !p63.toNewHampshire().equals( "(1:0.003,2:0.004):0.0;" ) ) {
9239                 System.out.println( p63.toNewHampshire() );
9240                 return false;
9241             }
9242             final String s64 = "((1,2):[95.5],3);";
9243             final Phylogeny p64 = factory.create( s64, new NHXParser() )[ 0 ];
9244             if ( !p64.toNewHampshireX().equals( "((1,2)[&&NHX:B=95.5],3)" ) ) {
9245                 System.out.println( p64.toNewHampshireX() );
9246                 return false;
9247             }
9248             final String s65 = "((1:0.1,2:0.2):0.3[10.2],3);";
9249             final Phylogeny p65 = factory.create( s65, new NHXParser() )[ 0 ];
9250             if ( !p65.toNewHampshireX().equals( "((1:0.1,2:0.2):0.3[&&NHX:B=10.2],3)" ) ) {
9251                 System.out.println( p65.toNewHampshireX() );
9252                 return false;
9253             }
9254             final Phylogeny p66 = factory.create( "((A,B)ab:2[0.44],C)", new NHXParser() )[ 0 ];
9255             if ( !isEqual( 0.44, p66.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
9256                 return false;
9257             }
9258             final Phylogeny p67 = factory.create( "((A,B):2[0.67],C)", new NHXParser() )[ 0 ];
9259             if ( !isEqual( 0.67, p67.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9260                 return false;
9261             }
9262             final Phylogeny p68 = factory.create( "((A,B):[0.68],C)", new NHXParser() )[ 0 ];
9263             if ( !isEqual( 0.68, p68.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9264                 return false;
9265             }
9266             final Phylogeny p69 = factory.create( "((A,B)[0.69],C)", new NHXParser() )[ 0 ];
9267             if ( !isEqual( 0.69, p69.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9268                 return false;
9269             }
9270             final Phylogeny p70 = factory.create( "((A,B)[+0.7],C)", new NHXParser() )[ 0 ];
9271             if ( !isEqual( 0.7, p70.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9272                 return false;
9273             }
9274             final Phylogeny p71 = factory.create( "((A,B)[-0.71],C)", new NHXParser() )[ 0 ];
9275             if ( !isEqual( -0.71, p71.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9276                 return false;
9277             }
9278             final Phylogeny p72 = factory.create( "((A,B)[],C)", new NHXParser() )[ 0 ];
9279             if ( !p72.toNewHampshireX().equals( "((A,B),C)" ) ) {
9280                 return false;
9281             }
9282             final Phylogeny p73 = factory.create( "((A,B)[12x],C)", new NHXParser() )[ 0 ];
9283             if ( !p73.toNewHampshireX().equals( "((A,B),C)" ) ) {
9284                 return false;
9285             }
9286             final Phylogeny p74 = factory.create( "((A,B)[12+],C)", new NHXParser() )[ 0 ];
9287             if ( !p74.toNewHampshireX().equals( "((A,B),C)" ) ) {
9288                 return false;
9289             }
9290             final Phylogeny p75 = factory.create( "((A,B)ab[222]:3,C)", new NHXParser() )[ 0 ];
9291             if ( !isEqual( 222, p75.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9292                 return false;
9293             }
9294             final Phylogeny p76 = factory.create( "((A,B)[100]:12,C)", new NHXParser() )[ 0 ];
9295             if ( !isEqual( 100, p76.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9296                 return false;
9297             }
9298             final Phylogeny p77 = factory.create( "((A,B)abcde:13[77],C)", new NHXParser() )[ 0 ];
9299             if ( !isEqual( 77, p77.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9300                 return false;
9301             }
9302             final Phylogeny p78 = factory.create( "((A,B):14[0],C)", new NHXParser() )[ 0 ];
9303             if ( !isEqual( 0, p78.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9304                 return false;
9305             }
9306             final String the_one = "((((((a,b)ab:3.0[2],c):12.0[100],(d,e)de)abcde:13.0[2],f):14.0[0]):0.0[0]):0.0[0];";
9307             final Phylogeny p79 = factory.create(
9308                                                   "((((((a,b)ab[2]:3,c)[100]:12,(d,e)de)abcde:13[2],f):14[0]):0[0])[0]:0;",
9309                                                   new NHXParser() )[ 0 ];
9310             final String str79 = p79.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
9311             if ( !str79.equals( the_one ) ) {
9312                 System.out.println( str79 );
9313                 return false;
9314             }
9315             final Phylogeny p80 = factory.create(
9316                                                   "((((((a[a)],b[12])ab[2]:3,c)[+100]:12,(d,e)de[12d,)])ab[]c[]de:13[2],f):14[0]):0[0])[0]:0;",
9317                                                   new NHXParser() )[ 0 ];
9318             final String str80 = p80.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
9319             if ( !str80.equals( the_one ) ) {
9320                 System.out.println( str80 );
9321                 return false;
9322             }
9323         }
9324         catch ( final Exception e ) {
9325             e.printStackTrace( System.out );
9326             return false;
9327         }
9328         return true;
9329     }
9330
9331     private static boolean testNHParsingSpecialChars() {
9332         try {
9333             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9334             final String i0 = "(A!+=~QWERTY!@#$%^&*-,€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ)";
9335             final Phylogeny p0 = factory.create( i0, new NHXParser() )[ 0 ];
9336             if ( !p0.toNewHampshireX().equals( i0 ) ) {
9337                 System.out.println();
9338                 System.out.println( p0.toNewHampshireX() );
9339                 System.out.println( i0 );
9340                 return false;
9341             }
9342             final String i1 = "(हिंदी,한글,ไทย,'Tiếng Việt',ひらがなカタカナ漢字,繁體字,русский)";
9343             final Phylogeny p1 = factory.create( i1, new NHXParser() )[ 0 ];
9344             if ( !p1.toNewHampshireX().equals( i1 ) ) {
9345                 System.out.println();
9346                 System.out.println( p1.toNewHampshireX() );
9347                 System.out.println( i1 );
9348                 return false;
9349             }
9350         }
9351         catch ( final Exception e ) {
9352             e.printStackTrace( System.out );
9353             return false;
9354         }
9355         return true;
9356     }
9357
9358     private static boolean testNHParsingIter() {
9359         try {
9360             final String p0_str = "(A,B);";
9361             final NHXParser p = new NHXParser();
9362             p.setSource( p0_str );
9363             if ( !p.hasNext() ) {
9364                 return false;
9365             }
9366             final Phylogeny p0 = p.next();
9367             if ( !p0.toNewHampshire().equals( p0_str ) ) {
9368                 System.out.println( p0.toNewHampshire() );
9369                 return false;
9370             }
9371             if ( p.hasNext() ) {
9372                 return false;
9373             }
9374             if ( p.next() != null ) {
9375                 return false;
9376             }
9377             //
9378             final String p00_str = "(A,B)root;";
9379             p.setSource( p00_str );
9380             final Phylogeny p00 = p.next();
9381             if ( !p00.toNewHampshire().equals( p00_str ) ) {
9382                 System.out.println( p00.toNewHampshire() );
9383                 return false;
9384             }
9385             //
9386             final String p000_str = "A;";
9387             p.setSource( p000_str );
9388             final Phylogeny p000 = p.next();
9389             if ( !p000.toNewHampshire().equals( p000_str ) ) {
9390                 System.out.println( p000.toNewHampshire() );
9391                 return false;
9392             }
9393             //
9394             final String p0000_str = "A";
9395             p.setSource( p0000_str );
9396             final Phylogeny p0000 = p.next();
9397             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
9398                 System.out.println( p0000.toNewHampshire() );
9399                 return false;
9400             }
9401             //
9402             p.setSource( "(A)" );
9403             final Phylogeny p00000 = p.next();
9404             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
9405                 System.out.println( p00000.toNewHampshire() );
9406                 return false;
9407             }
9408             //
9409             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
9410             p.setSource( p1_str );
9411             if ( !p.hasNext() ) {
9412                 return false;
9413             }
9414             final Phylogeny p1_0 = p.next();
9415             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
9416                 System.out.println( p1_0.toNewHampshire() );
9417                 return false;
9418             }
9419             if ( !p.hasNext() ) {
9420                 return false;
9421             }
9422             final Phylogeny p1_1 = p.next();
9423             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
9424                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
9425                 return false;
9426             }
9427             if ( !p.hasNext() ) {
9428                 return false;
9429             }
9430             final Phylogeny p1_2 = p.next();
9431             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
9432                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
9433                 return false;
9434             }
9435             if ( !p.hasNext() ) {
9436                 return false;
9437             }
9438             final Phylogeny p1_3 = p.next();
9439             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
9440                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
9441                 return false;
9442             }
9443             if ( p.hasNext() ) {
9444                 return false;
9445             }
9446             if ( p.next() != null ) {
9447                 return false;
9448             }
9449             //
9450             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
9451             p.setSource( p2_str );
9452             if ( !p.hasNext() ) {
9453                 return false;
9454             }
9455             Phylogeny p2_0 = p.next();
9456             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9457                 System.out.println( p2_0.toNewHampshire() );
9458                 return false;
9459             }
9460             if ( !p.hasNext() ) {
9461                 return false;
9462             }
9463             Phylogeny p2_1 = p.next();
9464             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9465                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9466                 return false;
9467             }
9468             if ( !p.hasNext() ) {
9469                 return false;
9470             }
9471             Phylogeny p2_2 = p.next();
9472             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9473                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9474                 return false;
9475             }
9476             if ( !p.hasNext() ) {
9477                 return false;
9478             }
9479             Phylogeny p2_3 = p.next();
9480             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9481                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9482                 return false;
9483             }
9484             if ( !p.hasNext() ) {
9485                 return false;
9486             }
9487             Phylogeny p2_4 = p.next();
9488             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9489                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9490                 return false;
9491             }
9492             if ( p.hasNext() ) {
9493                 return false;
9494             }
9495             if ( p.next() != null ) {
9496                 return false;
9497             }
9498             ////
9499             p.reset();
9500             if ( !p.hasNext() ) {
9501                 return false;
9502             }
9503             p2_0 = p.next();
9504             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9505                 System.out.println( p2_0.toNewHampshire() );
9506                 return false;
9507             }
9508             if ( !p.hasNext() ) {
9509                 return false;
9510             }
9511             p2_1 = p.next();
9512             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9513                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9514                 return false;
9515             }
9516             if ( !p.hasNext() ) {
9517                 return false;
9518             }
9519             p2_2 = p.next();
9520             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9521                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9522                 return false;
9523             }
9524             if ( !p.hasNext() ) {
9525                 return false;
9526             }
9527             p2_3 = p.next();
9528             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9529                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9530                 return false;
9531             }
9532             if ( !p.hasNext() ) {
9533                 return false;
9534             }
9535             p2_4 = p.next();
9536             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9537                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9538                 return false;
9539             }
9540             if ( p.hasNext() ) {
9541                 return false;
9542             }
9543             if ( p.next() != null ) {
9544                 return false;
9545             }
9546             //
9547             final String p3_str = "((A,B),C)abc";
9548             p.setSource( p3_str );
9549             if ( !p.hasNext() ) {
9550                 return false;
9551             }
9552             final Phylogeny p3_0 = p.next();
9553             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
9554                 return false;
9555             }
9556             if ( p.hasNext() ) {
9557                 return false;
9558             }
9559             if ( p.next() != null ) {
9560                 return false;
9561             }
9562             //
9563             final String p4_str = "((A,B)ab,C)abc";
9564             p.setSource( p4_str );
9565             if ( !p.hasNext() ) {
9566                 return false;
9567             }
9568             final Phylogeny p4_0 = p.next();
9569             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
9570                 return false;
9571             }
9572             if ( p.hasNext() ) {
9573                 return false;
9574             }
9575             if ( p.next() != null ) {
9576                 return false;
9577             }
9578             //
9579             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
9580             p.setSource( p5_str );
9581             if ( !p.hasNext() ) {
9582                 return false;
9583             }
9584             final Phylogeny p5_0 = p.next();
9585             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
9586                 return false;
9587             }
9588             if ( p.hasNext() ) {
9589                 return false;
9590             }
9591             if ( p.next() != null ) {
9592                 return false;
9593             }
9594             //
9595             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
9596             p.setSource( p6_str );
9597             if ( !p.hasNext() ) {
9598                 return false;
9599             }
9600             Phylogeny p6_0 = p.next();
9601             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9602                 return false;
9603             }
9604             if ( p.hasNext() ) {
9605                 return false;
9606             }
9607             if ( p.next() != null ) {
9608                 return false;
9609             }
9610             p.reset();
9611             if ( !p.hasNext() ) {
9612                 return false;
9613             }
9614             p6_0 = p.next();
9615             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9616                 return false;
9617             }
9618             if ( p.hasNext() ) {
9619                 return false;
9620             }
9621             if ( p.next() != null ) {
9622                 return false;
9623             }
9624             //
9625             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
9626             p.setSource( p7_str );
9627             if ( !p.hasNext() ) {
9628                 return false;
9629             }
9630             Phylogeny p7_0 = p.next();
9631             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9632                 return false;
9633             }
9634             if ( p.hasNext() ) {
9635                 return false;
9636             }
9637             if ( p.next() != null ) {
9638                 return false;
9639             }
9640             p.reset();
9641             if ( !p.hasNext() ) {
9642                 return false;
9643             }
9644             p7_0 = p.next();
9645             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9646                 return false;
9647             }
9648             if ( p.hasNext() ) {
9649                 return false;
9650             }
9651             if ( p.next() != null ) {
9652                 return false;
9653             }
9654             //
9655             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
9656             p.setSource( p8_str );
9657             if ( !p.hasNext() ) {
9658                 return false;
9659             }
9660             Phylogeny p8_0 = p.next();
9661             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9662                 return false;
9663             }
9664             if ( !p.hasNext() ) {
9665                 return false;
9666             }
9667             if ( !p.hasNext() ) {
9668                 return false;
9669             }
9670             Phylogeny p8_1 = p.next();
9671             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9672                 return false;
9673             }
9674             if ( p.hasNext() ) {
9675                 return false;
9676             }
9677             if ( p.next() != null ) {
9678                 return false;
9679             }
9680             p.reset();
9681             if ( !p.hasNext() ) {
9682                 return false;
9683             }
9684             p8_0 = p.next();
9685             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9686                 return false;
9687             }
9688             if ( !p.hasNext() ) {
9689                 return false;
9690             }
9691             p8_1 = p.next();
9692             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9693                 return false;
9694             }
9695             if ( p.hasNext() ) {
9696                 return false;
9697             }
9698             if ( p.next() != null ) {
9699                 return false;
9700             }
9701             p.reset();
9702             //
9703             p.setSource( "" );
9704             if ( p.hasNext() ) {
9705                 return false;
9706             }
9707             //
9708             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
9709             if ( !p.hasNext() ) {
9710                 return false;
9711             }
9712             Phylogeny p_27 = p.next();
9713             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9714                 System.out.println( p_27.toNewHampshireX() );
9715                 System.exit( -1 );
9716                 return false;
9717             }
9718             if ( p.hasNext() ) {
9719                 return false;
9720             }
9721             if ( p.next() != null ) {
9722                 return false;
9723             }
9724             p.reset();
9725             if ( !p.hasNext() ) {
9726                 return false;
9727             }
9728             p_27 = p.next();
9729             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9730                 System.out.println( p_27.toNewHampshireX() );
9731                 System.exit( -1 );
9732                 return false;
9733             }
9734             if ( p.hasNext() ) {
9735                 return false;
9736             }
9737             if ( p.next() != null ) {
9738                 return false;
9739             }
9740             //
9741             final String p30_str = "(A,B);(C,D)";
9742             final NHXParser p30 = new NHXParser();
9743             p30.setSource( p30_str );
9744             if ( !p30.hasNext() ) {
9745                 return false;
9746             }
9747             Phylogeny phy30 = p30.next();
9748             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9749                 System.out.println( phy30.toNewHampshire() );
9750                 return false;
9751             }
9752             if ( !p30.hasNext() ) {
9753                 return false;
9754             }
9755             Phylogeny phy301 = p30.next();
9756             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9757                 System.out.println( phy301.toNewHampshire() );
9758                 return false;
9759             }
9760             if ( p30.hasNext() ) {
9761                 return false;
9762             }
9763             if ( p30.hasNext() ) {
9764                 return false;
9765             }
9766             if ( p30.next() != null ) {
9767                 return false;
9768             }
9769             if ( p30.next() != null ) {
9770                 return false;
9771             }
9772             p30.reset();
9773             if ( !p30.hasNext() ) {
9774                 return false;
9775             }
9776             phy30 = p30.next();
9777             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9778                 System.out.println( phy30.toNewHampshire() );
9779                 return false;
9780             }
9781             if ( !p30.hasNext() ) {
9782                 return false;
9783             }
9784             phy301 = p30.next();
9785             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9786                 System.out.println( phy301.toNewHampshire() );
9787                 return false;
9788             }
9789             if ( p30.hasNext() ) {
9790                 return false;
9791             }
9792             if ( p30.hasNext() ) {
9793                 return false;
9794             }
9795             if ( p30.next() != null ) {
9796                 return false;
9797             }
9798             if ( p30.next() != null ) {
9799                 return false;
9800             }
9801         }
9802         catch ( final Exception e ) {
9803             e.printStackTrace( System.out );
9804             return false;
9805         }
9806         return true;
9807     }
9808
9809     private static boolean testNHXconversion() {
9810         try {
9811             final PhylogenyNode n1 = new PhylogenyNode();
9812             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9813             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9814             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9815             final PhylogenyNode n5 = PhylogenyNode
9816                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
9817             final PhylogenyNode n6 = PhylogenyNode
9818                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
9819             if ( !n1.toNewHampshireX().equals( "" ) ) {
9820                 return false;
9821             }
9822             if ( !n2.toNewHampshireX().equals( "" ) ) {
9823                 return false;
9824             }
9825             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
9826                 return false;
9827             }
9828             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
9829                 return false;
9830             }
9831             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
9832                 return false;
9833             }
9834             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9835                 System.out.println( n6.toNewHampshireX() );
9836                 return false;
9837             }
9838             final PhylogenyNode n7 = new PhylogenyNode();
9839             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9840             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9841                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9842                 System.out.println( n7
9843                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9844                 return false;
9845             }
9846         }
9847         catch ( final Exception e ) {
9848             e.printStackTrace( System.out );
9849             return false;
9850         }
9851         return true;
9852     }
9853
9854     private static boolean testNHXNodeParsing() {
9855         try {
9856             final PhylogenyNode n1 = new PhylogenyNode();
9857             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9858             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9859             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9860             final PhylogenyNode n5 = PhylogenyNode
9861                     .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]" );
9862             if ( !n3.getName().equals( "n3" ) ) {
9863                 return false;
9864             }
9865             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9866                 return false;
9867             }
9868             if ( n3.isDuplication() ) {
9869                 return false;
9870             }
9871             if ( n3.isHasAssignedEvent() ) {
9872                 return false;
9873             }
9874             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9875                 return false;
9876             }
9877             if ( !n4.getName().equals( "n4" ) ) {
9878                 return false;
9879             }
9880             if ( n4.getDistanceToParent() != 0.01 ) {
9881                 return false;
9882             }
9883             if ( !n5.getName().equals( "n5" ) ) {
9884                 return false;
9885             }
9886             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9887                 return false;
9888             }
9889             if ( n5.getDistanceToParent() != 0.1 ) {
9890                 return false;
9891             }
9892             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9893                 return false;
9894             }
9895             if ( !n5.isDuplication() ) {
9896                 return false;
9897             }
9898             if ( !n5.isHasAssignedEvent() ) {
9899                 return false;
9900             }
9901             final PhylogenyNode n8 = PhylogenyNode
9902                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9903                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9904             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9905                 return false;
9906             }
9907             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9908                 return false;
9909             }
9910             final PhylogenyNode n9 = PhylogenyNode
9911                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9912                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9913             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9914                 return false;
9915             }
9916             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9917                 return false;
9918             }
9919             final PhylogenyNode n10 = PhylogenyNode
9920                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9921             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9922                 return false;
9923             }
9924             final PhylogenyNode n20 = PhylogenyNode
9925                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9926             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9927                 return false;
9928             }
9929             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9930                 return false;
9931             }
9932             final PhylogenyNode n20x = PhylogenyNode
9933                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9934             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9935                 return false;
9936             }
9937             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9938                 return false;
9939             }
9940             final PhylogenyNode n20xx = PhylogenyNode
9941                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9942             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9943                 return false;
9944             }
9945             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9946                 return false;
9947             }
9948             final PhylogenyNode n20xxx = PhylogenyNode
9949                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9950             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9951                 return false;
9952             }
9953             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9954                 return false;
9955             }
9956             final PhylogenyNode n20xxxx = PhylogenyNode
9957                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9958             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9959                 return false;
9960             }
9961             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9962                 return false;
9963             }
9964             final PhylogenyNode n21 = PhylogenyNode
9965                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9966             if ( !n21.getName().equals( "N21_PIG" ) ) {
9967                 return false;
9968             }
9969             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9970                 return false;
9971             }
9972             final PhylogenyNode n21x = PhylogenyNode
9973                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9974             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9975                 return false;
9976             }
9977             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9978                 return false;
9979             }
9980             final PhylogenyNode n22 = PhylogenyNode
9981                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9982             if ( !n22.getName().equals( "n22/PIG" ) ) {
9983                 return false;
9984             }
9985             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9986                 return false;
9987             }
9988             final PhylogenyNode n23 = PhylogenyNode
9989                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9990             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9991                 return false;
9992             }
9993             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9994                 return false;
9995             }
9996             final PhylogenyNode a = PhylogenyNode
9997                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9998             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9999                 return false;
10000             }
10001             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
10002                 return false;
10003             }
10004             final PhylogenyNode c1 = PhylogenyNode
10005                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
10006                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10007             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
10008                 return false;
10009             }
10010             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
10011                 return false;
10012             }
10013             final PhylogenyNode c2 = PhylogenyNode
10014                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
10015                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10016             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
10017                 return false;
10018             }
10019             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
10020                 return false;
10021             }
10022             final PhylogenyNode e3 = PhylogenyNode
10023                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10024             if ( !e3.getName().equals( "n10_RAT~" ) ) {
10025                 return false;
10026             }
10027             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
10028                 return false;
10029             }
10030             final PhylogenyNode n11 = PhylogenyNode
10031                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
10032                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10033             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
10034                 return false;
10035             }
10036             if ( n11.getDistanceToParent() != 0.4 ) {
10037                 return false;
10038             }
10039             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
10040                 return false;
10041             }
10042             final PhylogenyNode n12 = PhylogenyNode
10043                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
10044                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10045             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
10046                 return false;
10047             }
10048             if ( n12.getDistanceToParent() != 0.4 ) {
10049                 return false;
10050             }
10051             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
10052                 return false;
10053             }
10054             final PhylogenyNode o = PhylogenyNode
10055                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10056             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
10057                 return false;
10058             }
10059             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
10060                 return false;
10061             }
10062             if ( n1.getName().compareTo( "" ) != 0 ) {
10063                 return false;
10064             }
10065             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
10066                 return false;
10067             }
10068             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
10069                 return false;
10070             }
10071             if ( n2.getName().compareTo( "" ) != 0 ) {
10072                 return false;
10073             }
10074             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
10075                 return false;
10076             }
10077             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
10078                 return false;
10079             }
10080             final PhylogenyNode n00 = PhylogenyNode
10081                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
10082             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
10083                 return false;
10084             }
10085             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
10086                 return false;
10087             }
10088             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
10089             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
10090                 return false;
10091             }
10092             final PhylogenyNode n13 = PhylogenyNode
10093                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10094             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
10095                 return false;
10096             }
10097             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
10098                 return false;
10099             }
10100             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10101                 return false;
10102             }
10103             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
10104                 return false;
10105             }
10106             final PhylogenyNode n14 = PhylogenyNode
10107                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10108             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
10109                 return false;
10110             }
10111             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
10112                 return false;
10113             }
10114             final PhylogenyNode n15 = PhylogenyNode
10115                     .createInstanceFromNhxString( "something_wicked[123]",
10116                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10117             if ( !n15.getName().equals( "something_wicked" ) ) {
10118                 return false;
10119             }
10120             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
10121                 return false;
10122             }
10123             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
10124                 return false;
10125             }
10126             final PhylogenyNode n16 = PhylogenyNode
10127                     .createInstanceFromNhxString( "something_wicked2[9]",
10128                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10129             if ( !n16.getName().equals( "something_wicked2" ) ) {
10130                 return false;
10131             }
10132             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
10133                 return false;
10134             }
10135             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
10136                 return false;
10137             }
10138             final PhylogenyNode n17 = PhylogenyNode
10139                     .createInstanceFromNhxString( "something_wicked3[a]",
10140                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10141             if ( !n17.getName().equals( "something_wicked3" ) ) {
10142                 return false;
10143             }
10144             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
10145                 return false;
10146             }
10147             final PhylogenyNode n18 = PhylogenyNode
10148                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10149             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
10150                 return false;
10151             }
10152             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
10153                 return false;
10154             }
10155             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
10156                 return false;
10157             }
10158             final PhylogenyNode n19 = PhylogenyNode
10159                     .createInstanceFromNhxString( "BLAH_1-roejojoej",
10160                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10161             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
10162                 return false;
10163             }
10164             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
10165                 return false;
10166             }
10167             final PhylogenyNode n30 = PhylogenyNode
10168                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
10169                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10170             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
10171                 return false;
10172             }
10173             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
10174                 return false;
10175             }
10176             final PhylogenyNode n31 = PhylogenyNode
10177                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
10178                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10179             if ( n31.getNodeData().isHasTaxonomy() ) {
10180                 return false;
10181             }
10182             final PhylogenyNode n32 = PhylogenyNode
10183                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10184             if ( n32.getNodeData().isHasTaxonomy() ) {
10185                 return false;
10186             }
10187             final PhylogenyNode n40 = PhylogenyNode
10188                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10189             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10190                 return false;
10191             }
10192             final PhylogenyNode n41 = PhylogenyNode
10193                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10194             if ( n41.getNodeData().isHasTaxonomy() ) {
10195                 return false;
10196             }
10197             final PhylogenyNode n42 = PhylogenyNode
10198                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10199             if ( n42.getNodeData().isHasTaxonomy() ) {
10200                 return false;
10201             }
10202             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
10203                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
10204             if ( n43.getNodeData().isHasTaxonomy() ) {
10205                 return false;
10206             }
10207             final PhylogenyNode n44 = PhylogenyNode
10208                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10209             if ( n44.getNodeData().isHasTaxonomy() ) {
10210                 return false;
10211             }
10212         }
10213         catch ( final Exception e ) {
10214             e.printStackTrace( System.out );
10215             return false;
10216         }
10217         return true;
10218     }
10219
10220     private static boolean testNHXNodeParsing2() {
10221         try {
10222             final PhylogenyNode n0_0 = PhylogenyNode.createInstanceFromNhxString( "n0:[ignore me 123]:1E-3",
10223                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10224                                                                                   true,
10225                                                                                   true );
10226             if ( !n0_0.getName().equals( "n0" ) ) {
10227                 return false;
10228             }
10229             if ( !isEqual( n0_0.getDistanceToParent(), 0.001 ) ) {
10230                 return false;
10231             }
10232             final PhylogenyNode n0_1 = PhylogenyNode.createInstanceFromNhxString( "n0[ignore me 123]:1E-3",
10233                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10234                                                                                   true,
10235                                                                                   true );
10236             if ( !n0_1.getName().equals( "n0" ) ) {
10237                 return false;
10238             }
10239             if ( !isEqual( n0_1.getDistanceToParent(), 0.001 ) ) {
10240                 return false;
10241             }
10242             final PhylogenyNode n0_2 = PhylogenyNode.createInstanceFromNhxString( "n0:1E-3[ignore me 123]",
10243                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10244                                                                                   true,
10245                                                                                   true );
10246             if ( !n0_2.getName().equals( "n0" ) ) {
10247                 return false;
10248             }
10249             if ( !isEqual( n0_2.getDistanceToParent(), 0.001 ) ) {
10250                 return false;
10251             }
10252             final PhylogenyNode n0_3 = PhylogenyNode.createInstanceFromNhxString( "n0:1E-3:[ignore me 123]",
10253                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10254                                                                                   true,
10255                                                                                   true );
10256             if ( !n0_3.getName().equals( "n0" ) ) {
10257                 return false;
10258             }
10259             if ( !isEqual( n0_3.getDistanceToParent(), 0.001 ) ) {
10260                 return false;
10261             }
10262             final PhylogenyNode n0_4 = PhylogenyNode.createInstanceFromNhxString( "n0:0.001:[ignore me 123]",
10263                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10264                                                                                   true,
10265                                                                                   true );
10266             if ( !n0_4.getName().equals( "n0" ) ) {
10267                 return false;
10268             }
10269             if ( !isEqual( n0_4.getDistanceToParent(), 0.001 ) ) {
10270                 return false;
10271             }
10272             final PhylogenyNode n1_0 = PhylogenyNode
10273                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]",
10274                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10275                                                   true,
10276                                                   true );
10277             if ( !n1_0.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10278                 return false;
10279             }
10280             if ( n1_0.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10281                 return false;
10282             }
10283             final PhylogenyNode n1_1 = PhylogenyNode
10284                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]:0.001",
10285                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10286                                                   true,
10287                                                   true );
10288             if ( !n1_1.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10289                 return false;
10290             }
10291             if ( n1_1.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10292                 return false;
10293             }
10294             if ( !isEqual( n1_1.getDistanceToParent(), 0.001 ) ) {
10295                 return false;
10296             }
10297             final PhylogenyNode n1_2 = PhylogenyNode
10298                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:0.001[&!color=#FFFFFF]",
10299                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10300                                                   true,
10301                                                   true );
10302             if ( !n1_2.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10303                 return false;
10304             }
10305             if ( n1_2.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10306                 return false;
10307             }
10308             if ( !isEqual( n1_2.getDistanceToParent(), 0.001 ) ) {
10309                 return false;
10310             }
10311             final PhylogenyNode n1_3 = PhylogenyNode
10312                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[&boostrap=69,&!color=#FFFFFF]",
10313                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10314                                                   true,
10315                                                   true );
10316             if ( !n1_3.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10317                 return false;
10318             }
10319             if ( n1_3.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10320                 return false;
10321             }
10322             if ( !isEqual( n1_3.getDistanceToParent(), 0.001 ) ) {
10323                 return false;
10324             }
10325             if ( !isEqual( n1_3.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
10326                 return false;
10327             }
10328             if ( !n1_3.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
10329                 return false;
10330             }
10331             final PhylogenyNode n1_4 = PhylogenyNode
10332                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&bootstrap=69,&!colour=#FFFFFF]:1e-3",
10333                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10334                                                   true,
10335                                                   true );
10336             if ( !n1_4.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10337                 return false;
10338             }
10339             if ( n1_4.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10340                 return false;
10341             }
10342             if ( !isEqual( n1_4.getDistanceToParent(), 0.001 ) ) {
10343                 return false;
10344             }
10345             if ( !isEqual( n1_4.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
10346                 return false;
10347             }
10348             if ( !n1_4.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
10349                 return false;
10350             }
10351             final PhylogenyNode n1_5 = PhylogenyNode
10352                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[69.0]",
10353                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10354                                                   true,
10355                                                   true );
10356             if ( !n1_5.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10357                 return false;
10358             }
10359             if ( !isEqual( n1_5.getDistanceToParent(), 0.001 ) ) {
10360                 return false;
10361             }
10362             if ( !isEqual( n1_5.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
10363                 return false;
10364             }
10365             final PhylogenyNode n1_6 = PhylogenyNode
10366                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00]:1e-3",
10367                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10368                                                   true,
10369                                                   true );
10370             if ( !n1_6.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10371                 return false;
10372             }
10373             if ( !isEqual( n1_6.getDistanceToParent(), 0.001 ) ) {
10374                 return false;
10375             }
10376             if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getStandardDeviation(), 0.11 ) ) {
10377                 return false;
10378             }
10379             if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getValue(), 0.95 ) ) {
10380                 return false;
10381             }
10382             if ( !n1_6.getBranchData().getConfidence( 0 ).getType().equals( "posterior probability" ) ) {
10383                 return false;
10384             }
10385         }
10386         catch ( final Exception e ) {
10387             e.printStackTrace( System.out );
10388             return false;
10389         }
10390         return true;
10391     }
10392
10393     private static boolean testNHXParsing() {
10394         try {
10395             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10396             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])",
10397                                                  new NHXParser() )[ 0 ];
10398             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
10399                 return false;
10400             }
10401             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]";
10402             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
10403             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10404                 return false;
10405             }
10406             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]";
10407             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
10408             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
10409                 return false;
10410             }
10411             final Phylogeny[] p3 = factory.create(
10412                                                    "[  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]",
10413                                                    new NHXParser() );
10414             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10415                 return false;
10416             }
10417             final Phylogeny[] p4 = factory.create(
10418                                                    "(((((((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(]",
10419                                                    new NHXParser() );
10420             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10421                 return false;
10422             }
10423             final Phylogeny[] p5 = factory.create(
10424                                                    "[]  (  [][ ][   ]  ([((( &&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(((]",
10425                                                    new NHXParser() );
10426             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10427                 return false;
10428             }
10429             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)";
10430             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)";
10431             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
10432             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
10433                 return false;
10434             }
10435             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)))";
10436             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)))";
10437             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
10438             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
10439                 return false;
10440             }
10441             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])   ))[,,, ])))))))";
10442             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
10443             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
10444             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
10445                 return false;
10446             }
10447             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
10448             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10449                 return false;
10450             }
10451             final Phylogeny p10 = factory.create(
10452                                                   " [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]",
10453                                                   new NHXParser() )[ 0 ];
10454             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10455                 return false;
10456             }
10457             final Phylogeny p11 = factory.create(
10458                                                   " [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]",
10459                                                   new NHXParser() )[ 0 ];
10460             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10461                 return false;
10462             }
10463             final Phylogeny p12 = factory.create( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]",
10464                                                   new NHXParser() )[ 0 ];
10465             if ( !p12.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10466                 return false;
10467             }
10468         }
10469         catch ( final Exception e ) {
10470             e.printStackTrace( System.out );
10471             return false;
10472         }
10473         return true;
10474     }
10475
10476     private static boolean testNHXParsingMB() {
10477         try {
10478             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10479             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
10480                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10481                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
10482                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
10483                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
10484                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10485                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
10486                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
10487                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
10488             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
10489                 return false;
10490             }
10491             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
10492                 return false;
10493             }
10494             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
10495                            0.1100000000000000e+00 ) ) {
10496                 return false;
10497             }
10498             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
10499                 return false;
10500             }
10501             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
10502                 return false;
10503             }
10504             final Phylogeny p2 = factory
10505                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
10506                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10507                             + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
10508                             + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
10509                             + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
10510                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10511                             + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
10512                             + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
10513                             + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
10514             if ( p2.getNode( "1" ) == null ) {
10515                 return false;
10516             }
10517             if ( p2.getNode( "2" ) == null ) {
10518                 return false;
10519             }
10520         }
10521         catch ( final Exception e ) {
10522             e.printStackTrace( System.out );
10523             System.exit( -1 );
10524             return false;
10525         }
10526         return true;
10527     }
10528
10529     private static boolean testNHXParsingQuotes() {
10530         try {
10531             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10532             final NHXParser p = new NHXParser();
10533             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
10534             if ( phylogenies_0.length != 5 ) {
10535                 return false;
10536             }
10537             final Phylogeny phy = phylogenies_0[ 4 ];
10538             if ( phy.getNumberOfExternalNodes() != 7 ) {
10539                 return false;
10540             }
10541             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
10542                 return false;
10543             }
10544             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
10545                 return false;
10546             }
10547             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
10548                     .getScientificName().equals( "hsapiens" ) ) {
10549                 return false;
10550             }
10551             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
10552                 return false;
10553             }
10554             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
10555                 return false;
10556             }
10557             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
10558                 return false;
10559             }
10560             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
10561                 return false;
10562             }
10563             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
10564                 return false;
10565             }
10566             final NHXParser p1p = new NHXParser();
10567             p1p.setIgnoreQuotes( true );
10568             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
10569             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
10570                 return false;
10571             }
10572             final NHXParser p2p = new NHXParser();
10573             p1p.setIgnoreQuotes( false );
10574             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
10575             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
10576                 return false;
10577             }
10578             final NHXParser p3p = new NHXParser();
10579             p3p.setIgnoreQuotes( false );
10580             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
10581             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
10582                 return false;
10583             }
10584             final NHXParser p4p = new NHXParser();
10585             p4p.setIgnoreQuotes( false );
10586             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
10587             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
10588                 return false;
10589             }
10590             final Phylogeny p10 = factory.create(
10591                                                   " [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]",
10592                                                   new NHXParser() )[ 0 ];
10593             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]";
10594             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
10595                 return false;
10596             }
10597             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
10598             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
10599                 return false;
10600             }
10601             final Phylogeny p12 = factory.create(
10602                                                   " [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]",
10603                                                   new NHXParser() )[ 0 ];
10604             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]";
10605             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
10606                 return false;
10607             }
10608             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
10609             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
10610                 return false;
10611             }
10612             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;";
10613             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
10614                 return false;
10615             }
10616             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
10617             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
10618                 return false;
10619             }
10620         }
10621         catch ( final Exception e ) {
10622             e.printStackTrace( System.out );
10623             return false;
10624         }
10625         return true;
10626     }
10627
10628     private static boolean testNodeRemoval() {
10629         try {
10630             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10631             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
10632             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
10633             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
10634                 return false;
10635             }
10636             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
10637             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
10638             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
10639                 return false;
10640             }
10641             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
10642             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
10643             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
10644                 return false;
10645             }
10646         }
10647         catch ( final Exception e ) {
10648             e.printStackTrace( System.out );
10649             return false;
10650         }
10651         return true;
10652     }
10653
10654     private static boolean testPhylogenyBranch() {
10655         try {
10656             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
10657             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
10658             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
10659             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
10660             if ( !a1b1.equals( a1b1 ) ) {
10661                 return false;
10662             }
10663             if ( !a1b1.equals( b1a1 ) ) {
10664                 return false;
10665             }
10666             if ( !b1a1.equals( a1b1 ) ) {
10667                 return false;
10668             }
10669             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
10670             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
10671             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
10672             if ( a1_b1.equals( b1_a1 ) ) {
10673                 return false;
10674             }
10675             if ( a1_b1.equals( a1_b1_ ) ) {
10676                 return false;
10677             }
10678             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
10679             if ( !a1_b1.equals( b1_a1_ ) ) {
10680                 return false;
10681             }
10682             if ( a1_b1_.equals( b1_a1_ ) ) {
10683                 return false;
10684             }
10685             if ( !a1_b1_.equals( b1_a1 ) ) {
10686                 return false;
10687             }
10688         }
10689         catch ( final Exception e ) {
10690             e.printStackTrace( System.out );
10691             return false;
10692         }
10693         return true;
10694     }
10695
10696     private static boolean testPhyloXMLparsingOfDistributionElement() {
10697         try {
10698             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10699             PhyloXmlParser xml_parser = null;
10700             try {
10701                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
10702             }
10703             catch ( final Exception e ) {
10704                 // Do nothing -- means were not running from jar.
10705             }
10706             if ( xml_parser == null ) {
10707                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
10708                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
10709                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
10710                 }
10711                 else {
10712                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
10713                 }
10714             }
10715             final Phylogeny[] phylogenies_0 = factory
10716                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml" ), xml_parser );
10717             if ( xml_parser.getErrorCount() > 0 ) {
10718                 System.out.println( xml_parser.getErrorMessages().toString() );
10719                 return false;
10720             }
10721             if ( phylogenies_0.length != 1 ) {
10722                 return false;
10723             }
10724             final Phylogeny t1 = phylogenies_0[ 0 ];
10725             PhylogenyNode n = null;
10726             Distribution d = null;
10727             n = t1.getNode( "root node" );
10728             if ( !n.getNodeData().isHasDistribution() ) {
10729                 return false;
10730             }
10731             if ( n.getNodeData().getDistributions().size() != 1 ) {
10732                 return false;
10733             }
10734             d = n.getNodeData().getDistribution();
10735             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10736                 return false;
10737             }
10738             if ( d.getPoints().size() != 1 ) {
10739                 return false;
10740             }
10741             if ( d.getPolygons() != null ) {
10742                 return false;
10743             }
10744             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10745                 return false;
10746             }
10747             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10748                 return false;
10749             }
10750             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10751                 return false;
10752             }
10753             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10754                 return false;
10755             }
10756             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10757                 return false;
10758             }
10759             n = t1.getNode( "node a" );
10760             if ( !n.getNodeData().isHasDistribution() ) {
10761                 return false;
10762             }
10763             if ( n.getNodeData().getDistributions().size() != 2 ) {
10764                 return false;
10765             }
10766             d = n.getNodeData().getDistribution( 1 );
10767             if ( !d.getDesc().equals( "San Diego" ) ) {
10768                 return false;
10769             }
10770             if ( d.getPoints().size() != 1 ) {
10771                 return false;
10772             }
10773             if ( d.getPolygons() != null ) {
10774                 return false;
10775             }
10776             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10777                 return false;
10778             }
10779             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10780                 return false;
10781             }
10782             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10783                 return false;
10784             }
10785             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10786                 return false;
10787             }
10788             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10789                 return false;
10790             }
10791             n = t1.getNode( "node bb" );
10792             if ( !n.getNodeData().isHasDistribution() ) {
10793                 return false;
10794             }
10795             if ( n.getNodeData().getDistributions().size() != 1 ) {
10796                 return false;
10797             }
10798             d = n.getNodeData().getDistribution( 0 );
10799             if ( d.getPoints().size() != 3 ) {
10800                 return false;
10801             }
10802             if ( d.getPolygons().size() != 2 ) {
10803                 return false;
10804             }
10805             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10806                 return false;
10807             }
10808             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10809                 return false;
10810             }
10811             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10812                 return false;
10813             }
10814             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10815                 return false;
10816             }
10817             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10818                 return false;
10819             }
10820             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10821                 return false;
10822             }
10823             Polygon p = d.getPolygons().get( 0 );
10824             if ( p.getPoints().size() != 3 ) {
10825                 return false;
10826             }
10827             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10828                 return false;
10829             }
10830             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10831                 return false;
10832             }
10833             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10834                 return false;
10835             }
10836             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10837                 return false;
10838             }
10839             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10840                 return false;
10841             }
10842             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10843                 return false;
10844             }
10845             p = d.getPolygons().get( 1 );
10846             if ( p.getPoints().size() != 3 ) {
10847                 return false;
10848             }
10849             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10850                 return false;
10851             }
10852             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10853                 return false;
10854             }
10855             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10856                 return false;
10857             }
10858             // Roundtrip:
10859             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
10860             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
10861             if ( rt.length != 1 ) {
10862                 return false;
10863             }
10864             final Phylogeny t1_rt = rt[ 0 ];
10865             n = t1_rt.getNode( "root node" );
10866             if ( !n.getNodeData().isHasDistribution() ) {
10867                 return false;
10868             }
10869             if ( n.getNodeData().getDistributions().size() != 1 ) {
10870                 return false;
10871             }
10872             d = n.getNodeData().getDistribution();
10873             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10874                 return false;
10875             }
10876             if ( d.getPoints().size() != 1 ) {
10877                 return false;
10878             }
10879             if ( d.getPolygons() != null ) {
10880                 return false;
10881             }
10882             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10883                 return false;
10884             }
10885             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10886                 return false;
10887             }
10888             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10889                 return false;
10890             }
10891             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10892                 return false;
10893             }
10894             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10895                 return false;
10896             }
10897             n = t1_rt.getNode( "node a" );
10898             if ( !n.getNodeData().isHasDistribution() ) {
10899                 return false;
10900             }
10901             if ( n.getNodeData().getDistributions().size() != 2 ) {
10902                 return false;
10903             }
10904             d = n.getNodeData().getDistribution( 1 );
10905             if ( !d.getDesc().equals( "San Diego" ) ) {
10906                 return false;
10907             }
10908             if ( d.getPoints().size() != 1 ) {
10909                 return false;
10910             }
10911             if ( d.getPolygons() != null ) {
10912                 return false;
10913             }
10914             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10915                 return false;
10916             }
10917             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10918                 return false;
10919             }
10920             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10921                 return false;
10922             }
10923             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10924                 return false;
10925             }
10926             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10927                 return false;
10928             }
10929             n = t1_rt.getNode( "node bb" );
10930             if ( !n.getNodeData().isHasDistribution() ) {
10931                 return false;
10932             }
10933             if ( n.getNodeData().getDistributions().size() != 1 ) {
10934                 return false;
10935             }
10936             d = n.getNodeData().getDistribution( 0 );
10937             if ( d.getPoints().size() != 3 ) {
10938                 return false;
10939             }
10940             if ( d.getPolygons().size() != 2 ) {
10941                 return false;
10942             }
10943             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10944                 return false;
10945             }
10946             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10947                 return false;
10948             }
10949             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10950                 return false;
10951             }
10952             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10953                 return false;
10954             }
10955             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10956                 return false;
10957             }
10958             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10959                 return false;
10960             }
10961             p = d.getPolygons().get( 0 );
10962             if ( p.getPoints().size() != 3 ) {
10963                 return false;
10964             }
10965             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10966                 return false;
10967             }
10968             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10969                 return false;
10970             }
10971             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10972                 return false;
10973             }
10974             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10975                 return false;
10976             }
10977             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10978                 return false;
10979             }
10980             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10981                 return false;
10982             }
10983             p = d.getPolygons().get( 1 );
10984             if ( p.getPoints().size() != 3 ) {
10985                 return false;
10986             }
10987             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10988                 return false;
10989             }
10990             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10991                 return false;
10992             }
10993             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10994                 return false;
10995             }
10996         }
10997         catch ( final Exception e ) {
10998             e.printStackTrace( System.out );
10999             return false;
11000         }
11001         return true;
11002     }
11003
11004     private static boolean testPostOrderIterator() {
11005         try {
11006             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11007             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
11008             PhylogenyNodeIterator it0;
11009             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
11010                 it0.next();
11011             }
11012             for( it0.reset(); it0.hasNext(); ) {
11013                 it0.next();
11014             }
11015             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r",
11016                                                  new NHXParser() )[ 0 ];
11017             final PhylogenyNodeIterator it = t1.iteratorPostorder();
11018             if ( !it.next().getName().equals( "A" ) ) {
11019                 return false;
11020             }
11021             if ( !it.next().getName().equals( "B" ) ) {
11022                 return false;
11023             }
11024             if ( !it.next().getName().equals( "ab" ) ) {
11025                 return false;
11026             }
11027             if ( !it.next().getName().equals( "C" ) ) {
11028                 return false;
11029             }
11030             if ( !it.next().getName().equals( "D" ) ) {
11031                 return false;
11032             }
11033             if ( !it.next().getName().equals( "cd" ) ) {
11034                 return false;
11035             }
11036             if ( !it.next().getName().equals( "abcd" ) ) {
11037                 return false;
11038             }
11039             if ( !it.next().getName().equals( "E" ) ) {
11040                 return false;
11041             }
11042             if ( !it.next().getName().equals( "F" ) ) {
11043                 return false;
11044             }
11045             if ( !it.next().getName().equals( "ef" ) ) {
11046                 return false;
11047             }
11048             if ( !it.next().getName().equals( "G" ) ) {
11049                 return false;
11050             }
11051             if ( !it.next().getName().equals( "H" ) ) {
11052                 return false;
11053             }
11054             if ( !it.next().getName().equals( "gh" ) ) {
11055                 return false;
11056             }
11057             if ( !it.next().getName().equals( "efgh" ) ) {
11058                 return false;
11059             }
11060             if ( !it.next().getName().equals( "r" ) ) {
11061                 return false;
11062             }
11063             if ( it.hasNext() ) {
11064                 return false;
11065             }
11066         }
11067         catch ( final Exception e ) {
11068             e.printStackTrace( System.out );
11069             return false;
11070         }
11071         return true;
11072     }
11073
11074     private static boolean testPreOrderIterator() {
11075         try {
11076             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11077             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
11078             PhylogenyNodeIterator it0;
11079             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
11080                 it0.next();
11081             }
11082             for( it0.reset(); it0.hasNext(); ) {
11083                 it0.next();
11084             }
11085             PhylogenyNodeIterator it = t0.iteratorPreorder();
11086             if ( !it.next().getName().equals( "r" ) ) {
11087                 return false;
11088             }
11089             if ( !it.next().getName().equals( "ab" ) ) {
11090                 return false;
11091             }
11092             if ( !it.next().getName().equals( "A" ) ) {
11093                 return false;
11094             }
11095             if ( !it.next().getName().equals( "B" ) ) {
11096                 return false;
11097             }
11098             if ( !it.next().getName().equals( "cd" ) ) {
11099                 return false;
11100             }
11101             if ( !it.next().getName().equals( "C" ) ) {
11102                 return false;
11103             }
11104             if ( !it.next().getName().equals( "D" ) ) {
11105                 return false;
11106             }
11107             if ( it.hasNext() ) {
11108                 return false;
11109             }
11110             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r",
11111                                                  new NHXParser() )[ 0 ];
11112             it = t1.iteratorPreorder();
11113             if ( !it.next().getName().equals( "r" ) ) {
11114                 return false;
11115             }
11116             if ( !it.next().getName().equals( "abcd" ) ) {
11117                 return false;
11118             }
11119             if ( !it.next().getName().equals( "ab" ) ) {
11120                 return false;
11121             }
11122             if ( !it.next().getName().equals( "A" ) ) {
11123                 return false;
11124             }
11125             if ( !it.next().getName().equals( "B" ) ) {
11126                 return false;
11127             }
11128             if ( !it.next().getName().equals( "cd" ) ) {
11129                 return false;
11130             }
11131             if ( !it.next().getName().equals( "C" ) ) {
11132                 return false;
11133             }
11134             if ( !it.next().getName().equals( "D" ) ) {
11135                 return false;
11136             }
11137             if ( !it.next().getName().equals( "efgh" ) ) {
11138                 return false;
11139             }
11140             if ( !it.next().getName().equals( "ef" ) ) {
11141                 return false;
11142             }
11143             if ( !it.next().getName().equals( "E" ) ) {
11144                 return false;
11145             }
11146             if ( !it.next().getName().equals( "F" ) ) {
11147                 return false;
11148             }
11149             if ( !it.next().getName().equals( "gh" ) ) {
11150                 return false;
11151             }
11152             if ( !it.next().getName().equals( "G" ) ) {
11153                 return false;
11154             }
11155             if ( !it.next().getName().equals( "H" ) ) {
11156                 return false;
11157             }
11158             if ( it.hasNext() ) {
11159                 return false;
11160             }
11161         }
11162         catch ( final Exception e ) {
11163             e.printStackTrace( System.out );
11164             return false;
11165         }
11166         return true;
11167     }
11168
11169     private static boolean testPropertiesMap() {
11170         try {
11171             final PropertiesList pm = new PropertiesList();
11172             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
11173             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
11174             final Property p2 = new Property( "something:else",
11175                                               "?",
11176                                               "improbable:research",
11177                                               "xsd:decimal",
11178                                               AppliesTo.NODE );
11179             pm.addProperty( p0 );
11180             pm.addProperty( p1 );
11181             pm.addProperty( p2 );
11182             if ( !pm.getProperties( "dimensions:diameter" ).get( 0 ).getValue().equals( "1" ) ) {
11183                 return false;
11184             }
11185             if ( !pm.getProperties( "dimensions:length" ).get( 0 ).getValue().equals( "2" ) ) {
11186                 return false;
11187             }
11188             if ( pm.getProperties().size() != 3 ) {
11189                 return false;
11190             }
11191             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
11192                 return false;
11193             }
11194             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
11195                 return false;
11196             }
11197             if ( pm.getProperties().size() != 3 ) {
11198                 return false;
11199             }
11200         }
11201         catch ( final Exception e ) {
11202             e.printStackTrace( System.out );
11203             return false;
11204         }
11205         return true;
11206     }
11207
11208     private static boolean testProteinId() {
11209         try {
11210             final ProteinId id1 = new ProteinId( "a" );
11211             final ProteinId id2 = new ProteinId( "a" );
11212             final ProteinId id3 = new ProteinId( "A" );
11213             final ProteinId id4 = new ProteinId( "b" );
11214             if ( !id1.equals( id1 ) ) {
11215                 return false;
11216             }
11217             if ( id1.getId().equals( "x" ) ) {
11218                 return false;
11219             }
11220             if ( id1.getId().equals( null ) ) {
11221                 return false;
11222             }
11223             if ( !id1.equals( id2 ) ) {
11224                 return false;
11225             }
11226             if ( id1.equals( id3 ) ) {
11227                 return false;
11228             }
11229             if ( id1.hashCode() != id1.hashCode() ) {
11230                 return false;
11231             }
11232             if ( id1.hashCode() != id2.hashCode() ) {
11233                 return false;
11234             }
11235             if ( id1.hashCode() == id3.hashCode() ) {
11236                 return false;
11237             }
11238             if ( id1.compareTo( id1 ) != 0 ) {
11239                 return false;
11240             }
11241             if ( id1.compareTo( id2 ) != 0 ) {
11242                 return false;
11243             }
11244             if ( id1.compareTo( id3 ) != 0 ) {
11245                 return false;
11246             }
11247             if ( id1.compareTo( id4 ) >= 0 ) {
11248                 return false;
11249             }
11250             if ( id4.compareTo( id1 ) <= 0 ) {
11251                 return false;
11252             }
11253             if ( !id4.getId().equals( "b" ) ) {
11254                 return false;
11255             }
11256             final ProteinId id5 = new ProteinId( " C " );
11257             if ( !id5.getId().equals( "C" ) ) {
11258                 return false;
11259             }
11260             if ( id5.equals( id1 ) ) {
11261                 return false;
11262             }
11263         }
11264         catch ( final Exception e ) {
11265             e.printStackTrace( System.out );
11266             return false;
11267         }
11268         return true;
11269     }
11270
11271     private static boolean testReIdMethods() {
11272         try {
11273             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11274             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
11275             final long count = PhylogenyNode.getNodeCount();
11276             p.levelOrderReID();
11277             if ( p.getNode( "r" ).getId() != count ) {
11278                 return false;
11279             }
11280             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
11281                 return false;
11282             }
11283             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
11284                 return false;
11285             }
11286             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
11287                 return false;
11288             }
11289             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
11290                 return false;
11291             }
11292             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
11293                 return false;
11294             }
11295             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
11296                 return false;
11297             }
11298             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
11299                 return false;
11300             }
11301             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
11302                 return false;
11303             }
11304             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
11305                 return false;
11306             }
11307             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
11308                 return false;
11309             }
11310             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
11311                 return false;
11312             }
11313             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
11314                 return false;
11315             }
11316             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
11317                 return false;
11318             }
11319             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
11320                 return false;
11321             }
11322         }
11323         catch ( final Exception e ) {
11324             e.printStackTrace( System.out );
11325             return false;
11326         }
11327         return true;
11328     }
11329
11330     private static boolean testRerooting() {
11331         try {
11332             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11333             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",
11334                                                  new NHXParser() )[ 0 ];
11335             if ( !t1.isRooted() ) {
11336                 return false;
11337             }
11338             t1.reRoot( t1.getNode( "D" ) );
11339             t1.reRoot( t1.getNode( "CD" ) );
11340             t1.reRoot( t1.getNode( "A" ) );
11341             t1.reRoot( t1.getNode( "B" ) );
11342             t1.reRoot( t1.getNode( "AB" ) );
11343             t1.reRoot( t1.getNode( "D" ) );
11344             t1.reRoot( t1.getNode( "C" ) );
11345             t1.reRoot( t1.getNode( "CD" ) );
11346             t1.reRoot( t1.getNode( "A" ) );
11347             t1.reRoot( t1.getNode( "B" ) );
11348             t1.reRoot( t1.getNode( "AB" ) );
11349             t1.reRoot( t1.getNode( "D" ) );
11350             t1.reRoot( t1.getNode( "D" ) );
11351             t1.reRoot( t1.getNode( "C" ) );
11352             t1.reRoot( t1.getNode( "A" ) );
11353             t1.reRoot( t1.getNode( "B" ) );
11354             t1.reRoot( t1.getNode( "AB" ) );
11355             t1.reRoot( t1.getNode( "C" ) );
11356             t1.reRoot( t1.getNode( "D" ) );
11357             t1.reRoot( t1.getNode( "CD" ) );
11358             t1.reRoot( t1.getNode( "D" ) );
11359             t1.reRoot( t1.getNode( "A" ) );
11360             t1.reRoot( t1.getNode( "B" ) );
11361             t1.reRoot( t1.getNode( "AB" ) );
11362             t1.reRoot( t1.getNode( "C" ) );
11363             t1.reRoot( t1.getNode( "D" ) );
11364             t1.reRoot( t1.getNode( "CD" ) );
11365             t1.reRoot( t1.getNode( "D" ) );
11366             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
11367                 return false;
11368             }
11369             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
11370                 return false;
11371             }
11372             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
11373                 return false;
11374             }
11375             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
11376                 return false;
11377             }
11378             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
11379                 return false;
11380             }
11381             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
11382                 return false;
11383             }
11384             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",
11385                                                  new NHXParser() )[ 0 ];
11386             t2.reRoot( t2.getNode( "A" ) );
11387             t2.reRoot( t2.getNode( "D" ) );
11388             t2.reRoot( t2.getNode( "ABC" ) );
11389             t2.reRoot( t2.getNode( "A" ) );
11390             t2.reRoot( t2.getNode( "B" ) );
11391             t2.reRoot( t2.getNode( "D" ) );
11392             t2.reRoot( t2.getNode( "C" ) );
11393             t2.reRoot( t2.getNode( "ABC" ) );
11394             t2.reRoot( t2.getNode( "A" ) );
11395             t2.reRoot( t2.getNode( "B" ) );
11396             t2.reRoot( t2.getNode( "AB" ) );
11397             t2.reRoot( t2.getNode( "AB" ) );
11398             t2.reRoot( t2.getNode( "D" ) );
11399             t2.reRoot( t2.getNode( "C" ) );
11400             t2.reRoot( t2.getNode( "B" ) );
11401             t2.reRoot( t2.getNode( "AB" ) );
11402             t2.reRoot( t2.getNode( "D" ) );
11403             t2.reRoot( t2.getNode( "D" ) );
11404             t2.reRoot( t2.getNode( "ABC" ) );
11405             t2.reRoot( t2.getNode( "A" ) );
11406             t2.reRoot( t2.getNode( "B" ) );
11407             t2.reRoot( t2.getNode( "AB" ) );
11408             t2.reRoot( t2.getNode( "D" ) );
11409             t2.reRoot( t2.getNode( "C" ) );
11410             t2.reRoot( t2.getNode( "ABC" ) );
11411             t2.reRoot( t2.getNode( "A" ) );
11412             t2.reRoot( t2.getNode( "B" ) );
11413             t2.reRoot( t2.getNode( "AB" ) );
11414             t2.reRoot( t2.getNode( "D" ) );
11415             t2.reRoot( t2.getNode( "D" ) );
11416             t2.reRoot( t2.getNode( "C" ) );
11417             t2.reRoot( t2.getNode( "A" ) );
11418             t2.reRoot( t2.getNode( "B" ) );
11419             t2.reRoot( t2.getNode( "AB" ) );
11420             t2.reRoot( t2.getNode( "C" ) );
11421             t2.reRoot( t2.getNode( "D" ) );
11422             t2.reRoot( t2.getNode( "ABC" ) );
11423             t2.reRoot( t2.getNode( "D" ) );
11424             t2.reRoot( t2.getNode( "A" ) );
11425             t2.reRoot( t2.getNode( "B" ) );
11426             t2.reRoot( t2.getNode( "AB" ) );
11427             t2.reRoot( t2.getNode( "C" ) );
11428             t2.reRoot( t2.getNode( "D" ) );
11429             t2.reRoot( t2.getNode( "ABC" ) );
11430             t2.reRoot( t2.getNode( "D" ) );
11431             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11432                 return false;
11433             }
11434             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11435                 return false;
11436             }
11437             t2.reRoot( t2.getNode( "ABC" ) );
11438             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11439                 return false;
11440             }
11441             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11442                 return false;
11443             }
11444             t2.reRoot( t2.getNode( "AB" ) );
11445             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11446                 return false;
11447             }
11448             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11449                 return false;
11450             }
11451             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11452                 return false;
11453             }
11454             t2.reRoot( t2.getNode( "AB" ) );
11455             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11456                 return false;
11457             }
11458             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11459                 return false;
11460             }
11461             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11462                 return false;
11463             }
11464             t2.reRoot( t2.getNode( "D" ) );
11465             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11466                 return false;
11467             }
11468             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11469                 return false;
11470             }
11471             t2.reRoot( t2.getNode( "ABC" ) );
11472             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11473                 return false;
11474             }
11475             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11476                 return false;
11477             }
11478             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
11479                                                  new NHXParser() )[ 0 ];
11480             t3.reRoot( t3.getNode( "B" ) );
11481             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11482                 return false;
11483             }
11484             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11485                 return false;
11486             }
11487             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11488                 return false;
11489             }
11490             t3.reRoot( t3.getNode( "B" ) );
11491             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11492                 return false;
11493             }
11494             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11495                 return false;
11496             }
11497             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11498                 return false;
11499             }
11500             t3.reRoot( t3.getRoot() );
11501             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11502                 return false;
11503             }
11504             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11505                 return false;
11506             }
11507             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11508                 return false;
11509             }
11510         }
11511         catch ( final Exception e ) {
11512             e.printStackTrace( System.out );
11513             return false;
11514         }
11515         return true;
11516     }
11517
11518     private static boolean testSDIse() {
11519         try {
11520             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11521             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
11522             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
11523             gene1.setRooted( true );
11524             species1.setRooted( true );
11525             final SDI sdi = new SDI( gene1, species1 );
11526             if ( !gene1.getRoot().isDuplication() ) {
11527                 return false;
11528             }
11529             final Phylogeny species2 = factory.create(
11530                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11531                                                        new NHXParser() )[ 0 ];
11532             final Phylogeny gene2 = factory.create(
11533                                                     "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11534                                                     new NHXParser() )[ 0 ];
11535             species2.setRooted( true );
11536             gene2.setRooted( true );
11537             final SDI sdi2 = new SDI( gene2, species2 );
11538             if ( sdi2.getDuplicationsSum() != 0 ) {
11539                 return false;
11540             }
11541             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
11542                 return false;
11543             }
11544             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
11545                 return false;
11546             }
11547             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
11548                 return false;
11549             }
11550             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
11551                 return false;
11552             }
11553             if ( !gene2.getNode( "r" ).isSpeciation() ) {
11554                 return false;
11555             }
11556             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
11557                 return false;
11558             }
11559             final Phylogeny species3 = factory.create(
11560                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11561                                                        new NHXParser() )[ 0 ];
11562             final Phylogeny gene3 = factory.create(
11563                                                     "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11564                                                     new NHXParser() )[ 0 ];
11565             species3.setRooted( true );
11566             gene3.setRooted( true );
11567             final SDI sdi3 = new SDI( gene3, species3 );
11568             if ( sdi3.getDuplicationsSum() != 1 ) {
11569                 return false;
11570             }
11571             if ( !gene3.getNode( "aa" ).isDuplication() ) {
11572                 return false;
11573             }
11574             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
11575                 return false;
11576             }
11577             final Phylogeny species4 = factory.create(
11578                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11579                                                        new NHXParser() )[ 0 ];
11580             final Phylogeny gene4 = factory.create(
11581                                                     "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11582                                                     new NHXParser() )[ 0 ];
11583             species4.setRooted( true );
11584             gene4.setRooted( true );
11585             final SDI sdi4 = new SDI( gene4, species4 );
11586             if ( sdi4.getDuplicationsSum() != 1 ) {
11587                 return false;
11588             }
11589             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
11590                 return false;
11591             }
11592             if ( !gene4.getNode( "abc" ).isDuplication() ) {
11593                 return false;
11594             }
11595             if ( gene4.getNode( "abcd" ).isDuplication() ) {
11596                 return false;
11597             }
11598             if ( species4.getNumberOfExternalNodes() != 6 ) {
11599                 return false;
11600             }
11601             if ( gene4.getNumberOfExternalNodes() != 6 ) {
11602                 return false;
11603             }
11604             final Phylogeny species5 = factory.create(
11605                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11606                                                        new NHXParser() )[ 0 ];
11607             final Phylogeny gene5 = factory.create(
11608                                                     "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11609                                                     new NHXParser() )[ 0 ];
11610             species5.setRooted( true );
11611             gene5.setRooted( true );
11612             final SDI sdi5 = new SDI( gene5, species5 );
11613             if ( sdi5.getDuplicationsSum() != 2 ) {
11614                 return false;
11615             }
11616             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
11617                 return false;
11618             }
11619             if ( !gene5.getNode( "adc" ).isDuplication() ) {
11620                 return false;
11621             }
11622             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
11623                 return false;
11624             }
11625             if ( species5.getNumberOfExternalNodes() != 6 ) {
11626                 return false;
11627             }
11628             if ( gene5.getNumberOfExternalNodes() != 6 ) {
11629                 return false;
11630             }
11631             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
11632             // Conjecture for Comparing Molecular Phylogenies"
11633             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
11634             final Phylogeny species6 = factory.create(
11635                                                        "(((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,"
11636                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11637                                                        new NHXParser() )[ 0 ];
11638             final Phylogeny gene6 = factory.create(
11639                                                     "(((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,"
11640                                                             + "((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,"
11641                                                             + "(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;",
11642                                                     new NHXParser() )[ 0 ];
11643             species6.setRooted( true );
11644             gene6.setRooted( true );
11645             final SDI sdi6 = new SDI( gene6, species6 );
11646             if ( sdi6.getDuplicationsSum() != 3 ) {
11647                 return false;
11648             }
11649             if ( !gene6.getNode( "r" ).isDuplication() ) {
11650                 return false;
11651             }
11652             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
11653                 return false;
11654             }
11655             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
11656                 return false;
11657             }
11658             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
11659                 return false;
11660             }
11661             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
11662                 return false;
11663             }
11664             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
11665                 return false;
11666             }
11667             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
11668                 return false;
11669             }
11670             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
11671                 return false;
11672             }
11673             sdi6.computeMappingCostL();
11674             if ( sdi6.computeMappingCostL() != 17 ) {
11675                 return false;
11676             }
11677             if ( species6.getNumberOfExternalNodes() != 9 ) {
11678                 return false;
11679             }
11680             if ( gene6.getNumberOfExternalNodes() != 9 ) {
11681                 return false;
11682             }
11683             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
11684                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
11685                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
11686                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
11687                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
11688             species7.setRooted( true );
11689             final Phylogeny gene7_1 = Test
11690                     .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])" );
11691             gene7_1.setRooted( true );
11692             final SDI sdi7 = new SDI( gene7_1, species7 );
11693             if ( sdi7.getDuplicationsSum() != 0 ) {
11694                 return false;
11695             }
11696             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
11697                 return false;
11698             }
11699             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
11700                 return false;
11701             }
11702             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
11703                 return false;
11704             }
11705             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
11706                 return false;
11707             }
11708             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
11709                 return false;
11710             }
11711             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
11712                 return false;
11713             }
11714             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
11715                 return false;
11716             }
11717             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
11718                 return false;
11719             }
11720             final Phylogeny gene7_2 = Test
11721                     .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])" );
11722             gene7_2.setRooted( true );
11723             final SDI sdi7_2 = new SDI( gene7_2, species7 );
11724             if ( sdi7_2.getDuplicationsSum() != 1 ) {
11725                 return false;
11726             }
11727             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
11728                 return false;
11729             }
11730             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
11731                 return false;
11732             }
11733             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
11734                 return false;
11735             }
11736             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
11737                 return false;
11738             }
11739             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
11740                 return false;
11741             }
11742             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
11743                 return false;
11744             }
11745             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
11746                 return false;
11747             }
11748             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
11749                 return false;
11750             }
11751             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
11752                 return false;
11753             }
11754         }
11755         catch ( final Exception e ) {
11756             return false;
11757         }
11758         return true;
11759     }
11760
11761     private static boolean testSDIunrooted() {
11762         try {
11763             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11764             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef",
11765                                                  new NHXParser() )[ 0 ];
11766             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
11767             final Iterator<PhylogenyBranch> iter = l.iterator();
11768             PhylogenyBranch br = iter.next();
11769             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
11770                 return false;
11771             }
11772             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
11773                 return false;
11774             }
11775             br = iter.next();
11776             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11777                 return false;
11778             }
11779             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11780                 return false;
11781             }
11782             br = iter.next();
11783             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
11784                 return false;
11785             }
11786             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
11787                 return false;
11788             }
11789             br = iter.next();
11790             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11791                 return false;
11792             }
11793             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11794                 return false;
11795             }
11796             br = iter.next();
11797             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11798                 return false;
11799             }
11800             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11801                 return false;
11802             }
11803             br = iter.next();
11804             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11805                 return false;
11806             }
11807             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11808                 return false;
11809             }
11810             br = iter.next();
11811             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11812                 return false;
11813             }
11814             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11815                 return false;
11816             }
11817             br = iter.next();
11818             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11819                 return false;
11820             }
11821             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11822                 return false;
11823             }
11824             br = iter.next();
11825             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11826                 return false;
11827             }
11828             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11829                 return false;
11830             }
11831             br = iter.next();
11832             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11833                 return false;
11834             }
11835             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11836                 return false;
11837             }
11838             br = iter.next();
11839             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11840                 return false;
11841             }
11842             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11843                 return false;
11844             }
11845             br = iter.next();
11846             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
11847                 return false;
11848             }
11849             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
11850                 return false;
11851             }
11852             br = iter.next();
11853             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11854                 return false;
11855             }
11856             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11857                 return false;
11858             }
11859             br = iter.next();
11860             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
11861                 return false;
11862             }
11863             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
11864                 return false;
11865             }
11866             br = iter.next();
11867             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
11868                 return false;
11869             }
11870             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
11871                 return false;
11872             }
11873             if ( iter.hasNext() ) {
11874                 return false;
11875             }
11876             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
11877             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
11878             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
11879             br = iter1.next();
11880             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11881                 return false;
11882             }
11883             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11884                 return false;
11885             }
11886             br = iter1.next();
11887             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11888                 return false;
11889             }
11890             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11891                 return false;
11892             }
11893             br = iter1.next();
11894             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11895                 return false;
11896             }
11897             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11898                 return false;
11899             }
11900             if ( iter1.hasNext() ) {
11901                 return false;
11902             }
11903             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
11904             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
11905             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
11906             br = iter2.next();
11907             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11908                 return false;
11909             }
11910             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11911                 return false;
11912             }
11913             br = iter2.next();
11914             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11915                 return false;
11916             }
11917             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11918                 return false;
11919             }
11920             br = iter2.next();
11921             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11922                 return false;
11923             }
11924             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11925                 return false;
11926             }
11927             if ( iter2.hasNext() ) {
11928                 return false;
11929             }
11930             final Phylogeny species0 = factory.create(
11931                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11932                                                        new NHXParser() )[ 0 ];
11933             final Phylogeny gene1 = factory.create(
11934                                                     "(((((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])",
11935                                                     new NHXParser() )[ 0 ];
11936             species0.setRooted( true );
11937             gene1.setRooted( true );
11938             final SDIR sdi_unrooted = new SDIR();
11939             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
11940             if ( sdi_unrooted.getCount() != 1 ) {
11941                 return false;
11942             }
11943             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
11944                 return false;
11945             }
11946             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
11947                 return false;
11948             }
11949             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
11950                 return false;
11951             }
11952             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11953                 return false;
11954             }
11955             final Phylogeny gene2 = factory.create(
11956                                                     "(((((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])",
11957                                                     new NHXParser() )[ 0 ];
11958             gene2.setRooted( true );
11959             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
11960             if ( sdi_unrooted.getCount() != 1 ) {
11961                 return false;
11962             }
11963             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11964                 return false;
11965             }
11966             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11967                 return false;
11968             }
11969             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
11970                 return false;
11971             }
11972             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11973                 return false;
11974             }
11975             final Phylogeny species6 = factory.create(
11976                                                        "(((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,"
11977                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11978                                                        new NHXParser() )[ 0 ];
11979             final Phylogeny gene6 = factory.create(
11980                                                     "((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],"
11981                                                             + "(((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],"
11982                                                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11983                                                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11984                                                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11985                                                     new NHXParser() )[ 0 ];
11986             species6.setRooted( true );
11987             gene6.setRooted( true );
11988             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
11989             if ( sdi_unrooted.getCount() != 1 ) {
11990                 return false;
11991             }
11992             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11993                 return false;
11994             }
11995             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11996                 return false;
11997             }
11998             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11999                 return false;
12000             }
12001             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
12002                 return false;
12003             }
12004             if ( !p6[ 0 ].getRoot().isDuplication() ) {
12005                 return false;
12006             }
12007             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
12008                 return false;
12009             }
12010             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
12011                 return false;
12012             }
12013             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
12014                 return false;
12015             }
12016             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
12017                 return false;
12018             }
12019             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
12020                 return false;
12021             }
12022             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
12023                 return false;
12024             }
12025             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
12026                 return false;
12027             }
12028             p6 = null;
12029             final Phylogeny species7 = factory.create(
12030                                                        "(((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,"
12031                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
12032                                                        new NHXParser() )[ 0 ];
12033             final Phylogeny gene7 = factory.create(
12034                                                     "((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],"
12035                                                             + "(((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],"
12036                                                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
12037                                                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
12038                                                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
12039                                                     new NHXParser() )[ 0 ];
12040             species7.setRooted( true );
12041             gene7.setRooted( true );
12042             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
12043             if ( sdi_unrooted.getCount() != 1 ) {
12044                 return false;
12045             }
12046             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
12047                 return false;
12048             }
12049             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
12050                 return false;
12051             }
12052             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
12053                 return false;
12054             }
12055             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
12056                 return false;
12057             }
12058             if ( !p7[ 0 ].getRoot().isDuplication() ) {
12059                 return false;
12060             }
12061             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
12062                 return false;
12063             }
12064             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
12065                 return false;
12066             }
12067             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
12068                 return false;
12069             }
12070             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
12071                 return false;
12072             }
12073             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
12074                 return false;
12075             }
12076             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
12077                 return false;
12078             }
12079             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
12080                 return false;
12081             }
12082             p7 = null;
12083             final Phylogeny species8 = factory.create(
12084                                                        "(((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,"
12085                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
12086                                                        new NHXParser() )[ 0 ];
12087             final Phylogeny gene8 = factory.create(
12088                                                     "((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],"
12089                                                             + "(((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],"
12090                                                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
12091                                                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
12092                                                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
12093                                                     new NHXParser() )[ 0 ];
12094             species8.setRooted( true );
12095             gene8.setRooted( true );
12096             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
12097             if ( sdi_unrooted.getCount() != 1 ) {
12098                 return false;
12099             }
12100             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
12101                 return false;
12102             }
12103             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
12104                 return false;
12105             }
12106             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
12107                 return false;
12108             }
12109             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
12110                 return false;
12111             }
12112             if ( !p8[ 0 ].getRoot().isDuplication() ) {
12113                 return false;
12114             }
12115             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
12116                 return false;
12117             }
12118             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
12119                 return false;
12120             }
12121             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
12122                 return false;
12123             }
12124             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
12125                 return false;
12126             }
12127             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
12128                 return false;
12129             }
12130             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
12131                 return false;
12132             }
12133             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
12134                 return false;
12135             }
12136             p8 = null;
12137         }
12138         catch ( final Exception e ) {
12139             e.printStackTrace( System.out );
12140             return false;
12141         }
12142         return true;
12143     }
12144
12145     private static boolean testSequenceDbWsTools1() {
12146         try {
12147             final PhylogenyNode n = new PhylogenyNode();
12148             n.setName( "NP_001025424" );
12149             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
12150             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
12151                     || !acc.getValue().equals( "NP_001025424" ) ) {
12152                 return false;
12153             }
12154             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
12155             acc = SequenceDbWsTools.obtainSeqAccession( n );
12156             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
12157                     || !acc.getValue().equals( "NP_001025424" ) ) {
12158                 return false;
12159             }
12160             n.setName( "NP_001025424.1" );
12161             acc = SequenceDbWsTools.obtainSeqAccession( n );
12162             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
12163                     || !acc.getValue().equals( "NP_001025424" ) ) {
12164                 return false;
12165             }
12166             n.setName( "NM_001030253" );
12167             acc = SequenceDbWsTools.obtainSeqAccession( n );
12168             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
12169                     || !acc.getValue().equals( "NM_001030253" ) ) {
12170                 return false;
12171             }
12172             n.setName( "BCL2_HUMAN" );
12173             acc = SequenceDbWsTools.obtainSeqAccession( n );
12174             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
12175                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
12176                 System.out.println( acc.toString() );
12177                 return false;
12178             }
12179             n.setName( "P10415" );
12180             acc = SequenceDbWsTools.obtainSeqAccession( n );
12181             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
12182                     || !acc.getValue().equals( "P10415" ) ) {
12183                 System.out.println( acc.toString() );
12184                 return false;
12185             }
12186             n.setName( " P10415 " );
12187             acc = SequenceDbWsTools.obtainSeqAccession( n );
12188             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
12189                     || !acc.getValue().equals( "P10415" ) ) {
12190                 System.out.println( acc.toString() );
12191                 return false;
12192             }
12193             n.setName( "_P10415|" );
12194             acc = SequenceDbWsTools.obtainSeqAccession( n );
12195             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
12196                     || !acc.getValue().equals( "P10415" ) ) {
12197                 System.out.println( acc.toString() );
12198                 return false;
12199             }
12200             n.setName( "AY695820" );
12201             acc = SequenceDbWsTools.obtainSeqAccession( n );
12202             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12203                     || !acc.getValue().equals( "AY695820" ) ) {
12204                 System.out.println( acc.toString() );
12205                 return false;
12206             }
12207             n.setName( "_AY695820_" );
12208             acc = SequenceDbWsTools.obtainSeqAccession( n );
12209             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12210                     || !acc.getValue().equals( "AY695820" ) ) {
12211                 System.out.println( acc.toString() );
12212                 return false;
12213             }
12214             n.setName( "AAA59452" );
12215             acc = SequenceDbWsTools.obtainSeqAccession( n );
12216             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12217                     || !acc.getValue().equals( "AAA59452" ) ) {
12218                 System.out.println( acc.toString() );
12219                 return false;
12220             }
12221             n.setName( "_AAA59452_" );
12222             acc = SequenceDbWsTools.obtainSeqAccession( n );
12223             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12224                     || !acc.getValue().equals( "AAA59452" ) ) {
12225                 System.out.println( acc.toString() );
12226                 return false;
12227             }
12228             n.setName( "AAA59452.1" );
12229             acc = SequenceDbWsTools.obtainSeqAccession( n );
12230             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12231                     || !acc.getValue().equals( "AAA59452.1" ) ) {
12232                 System.out.println( acc.toString() );
12233                 return false;
12234             }
12235             n.setName( "_AAA59452.1_" );
12236             acc = SequenceDbWsTools.obtainSeqAccession( n );
12237             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12238                     || !acc.getValue().equals( "AAA59452.1" ) ) {
12239                 System.out.println( acc.toString() );
12240                 return false;
12241             }
12242             n.setName( "GI:94894583" );
12243             acc = SequenceDbWsTools.obtainSeqAccession( n );
12244             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
12245                     || !acc.getValue().equals( "94894583" ) ) {
12246                 System.out.println( acc.toString() );
12247                 return false;
12248             }
12249             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
12250             acc = SequenceDbWsTools.obtainSeqAccession( n );
12251             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
12252                     || !acc.getValue().equals( "71845847" ) ) {
12253                 System.out.println( acc.toString() );
12254                 return false;
12255             }
12256             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
12257             acc = SequenceDbWsTools.obtainSeqAccession( n );
12258             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12259                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
12260                 System.out.println( acc.toString() );
12261                 return false;
12262             }
12263         }
12264         catch ( final Exception e ) {
12265             return false;
12266         }
12267         return true;
12268     }
12269
12270     private static boolean testSequenceDbWsTools2() {
12271         try {
12272             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
12273             SequenceDbWsTools.obtainSeqInformation( n1 );
12274             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
12275                 return false;
12276             }
12277             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
12278                 return false;
12279             }
12280             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
12281                 return false;
12282             }
12283             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
12284                 return false;
12285             }
12286             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
12287             SequenceDbWsTools.obtainSeqInformation( n2 );
12288             if ( !n2.getNodeData().getSequence().getName()
12289                     .equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
12290                 return false;
12291             }
12292             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
12293                 return false;
12294             }
12295             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
12296                 return false;
12297             }
12298             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
12299                 return false;
12300             }
12301             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
12302             SequenceDbWsTools.obtainSeqInformation( n3 );
12303             if ( !n3.getNodeData().getSequence().getName()
12304                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
12305                 return false;
12306             }
12307             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
12308                 return false;
12309             }
12310             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
12311                 return false;
12312             }
12313             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
12314                 return false;
12315             }
12316         }
12317         catch ( final IOException e ) {
12318             System.out.println();
12319             System.out.println( "the following might be due to absence internet connection:" );
12320             e.printStackTrace( System.out );
12321             return true;
12322         }
12323         catch ( final Exception e ) {
12324             e.printStackTrace();
12325             return false;
12326         }
12327         return true;
12328     }
12329
12330     private static boolean testSequenceIdParsing() {
12331         try {
12332             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
12333             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12334                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
12335                 if ( id != null ) {
12336                     System.out.println( "value   =" + id.getValue() );
12337                     System.out.println( "provider=" + id.getSource() );
12338                 }
12339                 return false;
12340             }
12341             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
12342             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12343                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
12344                 if ( id != null ) {
12345                     System.out.println( "value   =" + id.getValue() );
12346                     System.out.println( "provider=" + id.getSource() );
12347                 }
12348                 return false;
12349             }
12350             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
12351             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12352                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
12353                 if ( id != null ) {
12354                     System.out.println( "value   =" + id.getValue() );
12355                     System.out.println( "provider=" + id.getSource() );
12356                 }
12357                 return false;
12358             }
12359             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
12360             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12361                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
12362                 if ( id != null ) {
12363                     System.out.println( "value   =" + id.getValue() );
12364                     System.out.println( "provider=" + id.getSource() );
12365                 }
12366                 return false;
12367             }
12368             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
12369             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12370                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
12371                 if ( id != null ) {
12372                     System.out.println( "value   =" + id.getValue() );
12373                     System.out.println( "provider=" + id.getSource() );
12374                 }
12375                 return false;
12376             }
12377             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
12378             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12379                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
12380                 if ( id != null ) {
12381                     System.out.println( "value   =" + id.getValue() );
12382                     System.out.println( "provider=" + id.getSource() );
12383                 }
12384                 return false;
12385             }
12386             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
12387             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12388                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
12389                 if ( id != null ) {
12390                     System.out.println( "value   =" + id.getValue() );
12391                     System.out.println( "provider=" + id.getSource() );
12392                 }
12393                 return false;
12394             }
12395             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
12396             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12397                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
12398                 if ( id != null ) {
12399                     System.out.println( "value   =" + id.getValue() );
12400                     System.out.println( "provider=" + id.getSource() );
12401                 }
12402                 return false;
12403             }
12404             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
12405             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12406                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
12407                 if ( id != null ) {
12408                     System.out.println( "value   =" + id.getValue() );
12409                     System.out.println( "provider=" + id.getSource() );
12410                 }
12411                 return false;
12412             }
12413             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
12414             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12415                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
12416                 if ( id != null ) {
12417                     System.out.println( "value   =" + id.getValue() );
12418                     System.out.println( "provider=" + id.getSource() );
12419                 }
12420                 return false;
12421             }
12422             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
12423             if ( id != null ) {
12424                 System.out.println( "value   =" + id.getValue() );
12425                 System.out.println( "provider=" + id.getSource() );
12426                 return false;
12427             }
12428             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
12429             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12430                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
12431                 if ( id != null ) {
12432                     System.out.println( "value   =" + id.getValue() );
12433                     System.out.println( "provider=" + id.getSource() );
12434                 }
12435                 return false;
12436             }
12437             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
12438             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12439                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
12440                 if ( id != null ) {
12441                     System.out.println( "value   =" + id.getValue() );
12442                     System.out.println( "provider=" + id.getSource() );
12443                 }
12444                 return false;
12445             }
12446             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
12447             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12448                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
12449                 if ( id != null ) {
12450                     System.out.println( "value   =" + id.getValue() );
12451                     System.out.println( "provider=" + id.getSource() );
12452                 }
12453                 return false;
12454             }
12455             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
12456             if ( id != null ) {
12457                 System.out.println( "value   =" + id.getValue() );
12458                 System.out.println( "provider=" + id.getSource() );
12459                 return false;
12460             }
12461         }
12462         catch ( final Exception e ) {
12463             e.printStackTrace( System.out );
12464             return false;
12465         }
12466         return true;
12467     }
12468
12469     private static boolean testSequenceWriter() {
12470         try {
12471             final String n = ForesterUtil.LINE_SEPARATOR;
12472             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
12473                 return false;
12474             }
12475             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
12476                 return false;
12477             }
12478             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
12479                 return false;
12480             }
12481             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
12482                 return false;
12483             }
12484             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
12485                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
12486                 return false;
12487             }
12488             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
12489                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
12490                 return false;
12491             }
12492         }
12493         catch ( final Exception e ) {
12494             e.printStackTrace();
12495             return false;
12496         }
12497         return true;
12498     }
12499
12500     private static boolean testSpecies() {
12501         try {
12502             final Species s1 = new BasicSpecies( "a" );
12503             final Species s2 = new BasicSpecies( "a" );
12504             final Species s3 = new BasicSpecies( "A" );
12505             final Species s4 = new BasicSpecies( "b" );
12506             if ( !s1.equals( s1 ) ) {
12507                 return false;
12508             }
12509             if ( s1.getSpeciesId().equals( "x" ) ) {
12510                 return false;
12511             }
12512             if ( s1.getSpeciesId().equals( null ) ) {
12513                 return false;
12514             }
12515             if ( !s1.equals( s2 ) ) {
12516                 return false;
12517             }
12518             if ( s1.equals( s3 ) ) {
12519                 return false;
12520             }
12521             if ( s1.hashCode() != s1.hashCode() ) {
12522                 return false;
12523             }
12524             if ( s1.hashCode() != s2.hashCode() ) {
12525                 return false;
12526             }
12527             if ( s1.hashCode() == s3.hashCode() ) {
12528                 return false;
12529             }
12530             if ( s1.compareTo( s1 ) != 0 ) {
12531                 return false;
12532             }
12533             if ( s1.compareTo( s2 ) != 0 ) {
12534                 return false;
12535             }
12536             if ( s1.compareTo( s3 ) != 0 ) {
12537                 return false;
12538             }
12539             if ( s1.compareTo( s4 ) >= 0 ) {
12540                 return false;
12541             }
12542             if ( s4.compareTo( s1 ) <= 0 ) {
12543                 return false;
12544             }
12545             if ( !s4.getSpeciesId().equals( "b" ) ) {
12546                 return false;
12547             }
12548             final Species s5 = new BasicSpecies( " C " );
12549             if ( !s5.getSpeciesId().equals( "C" ) ) {
12550                 return false;
12551             }
12552             if ( s5.equals( s1 ) ) {
12553                 return false;
12554             }
12555         }
12556         catch ( final Exception e ) {
12557             e.printStackTrace( System.out );
12558             return false;
12559         }
12560         return true;
12561     }
12562
12563     private static boolean testSplit() {
12564         try {
12565             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12566             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12567             //Archaeopteryx.createApplication( p0 );
12568             final Set<PhylogenyNode> ex = new HashSet<>();
12569             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12570             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12571             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12572             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12573             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12574             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12575             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12576             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12577             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12578             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
12579             // System.out.println( s0.toString() );
12580             //
12581             Set<PhylogenyNode> query_nodes = new HashSet<>();
12582             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12583             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12584             if ( s0.match( query_nodes ) ) {
12585                 return false;
12586             }
12587             query_nodes = new HashSet<>();
12588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12589             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12590             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12591             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12592             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12593             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12594             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12595             if ( !s0.match( query_nodes ) ) {
12596                 return false;
12597             }
12598             //
12599             query_nodes = new HashSet<>();
12600             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12601             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12602             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12603             if ( !s0.match( query_nodes ) ) {
12604                 return false;
12605             }
12606             //
12607             query_nodes = new HashSet<>();
12608             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12609             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12610             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12611             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12612             if ( !s0.match( query_nodes ) ) {
12613                 return false;
12614             }
12615             //
12616             query_nodes = new HashSet<>();
12617             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12618             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12619             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12620             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12621             if ( !s0.match( query_nodes ) ) {
12622                 return false;
12623             }
12624             //
12625             query_nodes = new HashSet<>();
12626             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12627             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12628             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12629             if ( !s0.match( query_nodes ) ) {
12630                 return false;
12631             }
12632             query_nodes = new HashSet<>();
12633             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12634             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12635             if ( !s0.match( query_nodes ) ) {
12636                 return false;
12637             }
12638             query_nodes = new HashSet<>();
12639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12640             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12641             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12642             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12643             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12644             if ( !s0.match( query_nodes ) ) {
12645                 return false;
12646             }
12647             query_nodes = new HashSet<>();
12648             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12649             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12650             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12651             if ( !s0.match( query_nodes ) ) {
12652                 return false;
12653             }
12654             query_nodes = new HashSet<>();
12655             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12656             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12657             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12658             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12659             if ( !s0.match( query_nodes ) ) {
12660                 return false;
12661             }
12662             query_nodes = new HashSet<>();
12663             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12664             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12665             if ( s0.match( query_nodes ) ) {
12666                 return false;
12667             }
12668             query_nodes = new HashSet<>();
12669             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12670             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12671             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12672             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12673             if ( s0.match( query_nodes ) ) {
12674                 return false;
12675             }
12676             query_nodes = new HashSet<>();
12677             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12678             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12679             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12680             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12681             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12682             if ( s0.match( query_nodes ) ) {
12683                 return false;
12684             }
12685             query_nodes = new HashSet<>();
12686             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12688             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12689             if ( s0.match( query_nodes ) ) {
12690                 return false;
12691             }
12692             query_nodes = new HashSet<>();
12693             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12694             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12695             if ( s0.match( query_nodes ) ) {
12696                 return false;
12697             }
12698             query_nodes = new HashSet<>();
12699             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12700             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12701             if ( s0.match( query_nodes ) ) {
12702                 return false;
12703             }
12704             query_nodes = new HashSet<>();
12705             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12706             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12707             if ( s0.match( query_nodes ) ) {
12708                 return false;
12709             }
12710             query_nodes = new HashSet<>();
12711             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12712             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12713             if ( s0.match( query_nodes ) ) {
12714                 return false;
12715             }
12716             query_nodes = new HashSet<>();
12717             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12718             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12719             if ( s0.match( query_nodes ) ) {
12720                 return false;
12721             }
12722             query_nodes = new HashSet<>();
12723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12724             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12725             if ( s0.match( query_nodes ) ) {
12726                 return false;
12727             }
12728             query_nodes = new HashSet<>();
12729             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12730             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12731             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12732             if ( s0.match( query_nodes ) ) {
12733                 return false;
12734             }
12735             query_nodes = new HashSet<>();
12736             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12737             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12738             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12739             if ( s0.match( query_nodes ) ) {
12740                 return false;
12741             }
12742             query_nodes = new HashSet<>();
12743             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12744             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12745             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12746             if ( s0.match( query_nodes ) ) {
12747                 return false;
12748             }
12749             query_nodes = new HashSet<>();
12750             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12751             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12752             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12753             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12754             if ( s0.match( query_nodes ) ) {
12755                 return false;
12756             }
12757             /////////
12758             //            query_nodes = new HashSet<PhylogenyNode>();
12759             //            query_nodes.add( new PhylogenyNode( "X" ) );
12760             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12761             //            query_nodes.add( new PhylogenyNode( "A" ) );
12762             //            query_nodes.add( new PhylogenyNode( "B" ) );
12763             //            query_nodes.add( new PhylogenyNode( "C" ) );
12764             //            query_nodes.add( new PhylogenyNode( "D" ) );
12765             //            query_nodes.add( new PhylogenyNode( "E" ) );
12766             //            query_nodes.add( new PhylogenyNode( "F" ) );
12767             //            query_nodes.add( new PhylogenyNode( "G" ) );
12768             //            if ( !s0.match( query_nodes ) ) {
12769             //                return false;
12770             //            }
12771             //            query_nodes = new HashSet<PhylogenyNode>();
12772             //            query_nodes.add( new PhylogenyNode( "X" ) );
12773             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12774             //            query_nodes.add( new PhylogenyNode( "A" ) );
12775             //            query_nodes.add( new PhylogenyNode( "B" ) );
12776             //            query_nodes.add( new PhylogenyNode( "C" ) );
12777             //            if ( !s0.match( query_nodes ) ) {
12778             //                return false;
12779             //            }
12780             //            //
12781             //            query_nodes = new HashSet<PhylogenyNode>();
12782             //            query_nodes.add( new PhylogenyNode( "X" ) );
12783             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12784             //            query_nodes.add( new PhylogenyNode( "D" ) );
12785             //            query_nodes.add( new PhylogenyNode( "E" ) );
12786             //            query_nodes.add( new PhylogenyNode( "F" ) );
12787             //            query_nodes.add( new PhylogenyNode( "G" ) );
12788             //            if ( !s0.match( query_nodes ) ) {
12789             //                return false;
12790             //            }
12791             //            //
12792             //            query_nodes = new HashSet<PhylogenyNode>();
12793             //            query_nodes.add( new PhylogenyNode( "X" ) );
12794             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12795             //            query_nodes.add( new PhylogenyNode( "A" ) );
12796             //            query_nodes.add( new PhylogenyNode( "B" ) );
12797             //            query_nodes.add( new PhylogenyNode( "C" ) );
12798             //            query_nodes.add( new PhylogenyNode( "D" ) );
12799             //            if ( !s0.match( query_nodes ) ) {
12800             //                return false;
12801             //            }
12802             //            //
12803             //            query_nodes = new HashSet<PhylogenyNode>();
12804             //            query_nodes.add( new PhylogenyNode( "X" ) );
12805             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12806             //            query_nodes.add( new PhylogenyNode( "E" ) );
12807             //            query_nodes.add( new PhylogenyNode( "F" ) );
12808             //            query_nodes.add( new PhylogenyNode( "G" ) );
12809             //            if ( !s0.match( query_nodes ) ) {
12810             //                return false;
12811             //            }
12812             //            //
12813             //            query_nodes = new HashSet<PhylogenyNode>();
12814             //            query_nodes.add( new PhylogenyNode( "X" ) );
12815             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12816             //            query_nodes.add( new PhylogenyNode( "F" ) );
12817             //            query_nodes.add( new PhylogenyNode( "G" ) );
12818             //            if ( !s0.match( query_nodes ) ) {
12819             //                return false;
12820             //            }
12821             //
12822             query_nodes = new HashSet<>();
12823             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12824             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12825             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12826             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12827             if ( s0.match( query_nodes ) ) {
12828                 return false;
12829             }
12830             //
12831             query_nodes = new HashSet<>();
12832             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12833             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12834             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12835             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12836             if ( s0.match( query_nodes ) ) {
12837                 return false;
12838             }
12839             ///////////////////////////
12840             //
12841             query_nodes = new HashSet<>();
12842             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12843             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12844             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12845             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12846             if ( s0.match( query_nodes ) ) {
12847                 return false;
12848             }
12849             //
12850             query_nodes = new HashSet<>();
12851             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12852             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12853             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12854             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12855             if ( s0.match( query_nodes ) ) {
12856                 return false;
12857             }
12858             //
12859             query_nodes = new HashSet<>();
12860             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12861             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12862             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12863             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12864             if ( s0.match( query_nodes ) ) {
12865                 return false;
12866             }
12867             //
12868             query_nodes = new HashSet<>();
12869             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12872             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12873             if ( s0.match( query_nodes ) ) {
12874                 return false;
12875             }
12876             //
12877             query_nodes = new HashSet<>();
12878             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12879             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12880             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12881             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12882             if ( s0.match( query_nodes ) ) {
12883                 return false;
12884             }
12885             //
12886             query_nodes = new HashSet<>();
12887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12890             if ( s0.match( query_nodes ) ) {
12891                 return false;
12892             }
12893             //
12894             query_nodes = new HashSet<>();
12895             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12896             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12897             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12898             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12899             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12900             if ( s0.match( query_nodes ) ) {
12901                 return false;
12902             }
12903             //
12904             query_nodes = new HashSet<>();
12905             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12908             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12909             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12910             if ( s0.match( query_nodes ) ) {
12911                 return false;
12912             }
12913             //
12914             query_nodes = new HashSet<>();
12915             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12916             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12917             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12918             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12919             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12920             if ( s0.match( query_nodes ) ) {
12921                 return false;
12922             }
12923             //
12924             query_nodes = new HashSet<>();
12925             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12926             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12927             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12928             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12929             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12930             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12931             if ( s0.match( query_nodes ) ) {
12932                 return false;
12933             }
12934         }
12935         catch ( final Exception e ) {
12936             e.printStackTrace();
12937             return false;
12938         }
12939         return true;
12940     }
12941
12942     private static boolean testSplitStrict() {
12943         try {
12944             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12945             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12946             final Set<PhylogenyNode> ex = new HashSet<>();
12947             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12948             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12949             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12950             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12951             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12952             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12953             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12954             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
12955             Set<PhylogenyNode> query_nodes = new HashSet<>();
12956             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12957             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12958             if ( s0.match( query_nodes ) ) {
12959                 return false;
12960             }
12961             query_nodes = new HashSet<>();
12962             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12963             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12964             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12965             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12966             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12967             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12968             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12969             if ( !s0.match( query_nodes ) ) {
12970                 return false;
12971             }
12972             //
12973             query_nodes = new HashSet<>();
12974             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12975             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12976             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12977             if ( !s0.match( query_nodes ) ) {
12978                 return false;
12979             }
12980             //
12981             query_nodes = new HashSet<>();
12982             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12983             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12984             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12985             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12986             if ( !s0.match( query_nodes ) ) {
12987                 return false;
12988             }
12989             //
12990             query_nodes = new HashSet<>();
12991             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12992             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12993             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12994             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12995             if ( !s0.match( query_nodes ) ) {
12996                 return false;
12997             }
12998             //
12999             query_nodes = new HashSet<>();
13000             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
13001             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
13002             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
13003             if ( !s0.match( query_nodes ) ) {
13004                 return false;
13005             }
13006             //
13007             query_nodes = new HashSet<>();
13008             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
13009             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
13010             if ( !s0.match( query_nodes ) ) {
13011                 return false;
13012             }
13013             //
13014             query_nodes = new HashSet<>();
13015             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
13016             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
13017             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
13018             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
13019             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13020             if ( !s0.match( query_nodes ) ) {
13021                 return false;
13022             }
13023             //
13024             query_nodes = new HashSet<>();
13025             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
13026             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
13027             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
13028             if ( !s0.match( query_nodes ) ) {
13029                 return false;
13030             }
13031             //
13032             query_nodes = new HashSet<>();
13033             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
13034             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
13035             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
13036             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
13037             if ( !s0.match( query_nodes ) ) {
13038                 return false;
13039             }
13040             //
13041             query_nodes = new HashSet<>();
13042             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
13043             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13044             if ( s0.match( query_nodes ) ) {
13045                 return false;
13046             }
13047             //
13048             query_nodes = new HashSet<>();
13049             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13050             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
13051             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
13052             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
13053             if ( s0.match( query_nodes ) ) {
13054                 return false;
13055             }
13056             //
13057             query_nodes = new HashSet<>();
13058             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
13059             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
13060             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
13061             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
13062             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
13063             if ( s0.match( query_nodes ) ) {
13064                 return false;
13065             }
13066             //
13067             query_nodes = new HashSet<>();
13068             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13069             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
13070             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
13071             if ( s0.match( query_nodes ) ) {
13072                 return false;
13073             }
13074             //
13075             query_nodes = new HashSet<>();
13076             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13077             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
13078             if ( s0.match( query_nodes ) ) {
13079                 return false;
13080             }
13081             //
13082             query_nodes = new HashSet<>();
13083             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13084             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
13085             if ( s0.match( query_nodes ) ) {
13086                 return false;
13087             }
13088             //
13089             query_nodes = new HashSet<>();
13090             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13091             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
13092             if ( s0.match( query_nodes ) ) {
13093                 return false;
13094             }
13095             //
13096             query_nodes = new HashSet<>();
13097             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13098             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
13099             if ( s0.match( query_nodes ) ) {
13100                 return false;
13101             }
13102             //
13103             query_nodes = new HashSet<>();
13104             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13105             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
13106             if ( s0.match( query_nodes ) ) {
13107                 return false;
13108             }
13109             //
13110             query_nodes = new HashSet<>();
13111             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13112             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
13113             if ( s0.match( query_nodes ) ) {
13114                 return false;
13115             }
13116             //
13117             query_nodes = new HashSet<>();
13118             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13119             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
13120             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
13121             if ( s0.match( query_nodes ) ) {
13122                 return false;
13123             }
13124             //
13125             query_nodes = new HashSet<>();
13126             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13127             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
13128             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
13129             if ( s0.match( query_nodes ) ) {
13130                 return false;
13131             }
13132             //
13133             query_nodes = new HashSet<>();
13134             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
13135             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
13136             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13137             if ( s0.match( query_nodes ) ) {
13138                 return false;
13139             }
13140             //
13141             query_nodes = new HashSet<>();
13142             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
13143             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
13144             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13145             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
13146             if ( s0.match( query_nodes ) ) {
13147                 return false;
13148             }
13149         }
13150         catch ( final Exception e ) {
13151             e.printStackTrace();
13152             return false;
13153         }
13154         return true;
13155     }
13156
13157     private static boolean testSubtreeDeletion() {
13158         try {
13159             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13160             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
13161             t1.deleteSubtree( t1.getNode( "A" ), false );
13162             if ( t1.getNumberOfExternalNodes() != 5 ) {
13163                 return false;
13164             }
13165             t1.toNewHampshireX();
13166             t1.deleteSubtree( t1.getNode( "E" ), false );
13167             if ( t1.getNumberOfExternalNodes() != 4 ) {
13168                 return false;
13169             }
13170             t1.toNewHampshireX();
13171             t1.deleteSubtree( t1.getNode( "F" ), false );
13172             if ( t1.getNumberOfExternalNodes() != 3 ) {
13173                 return false;
13174             }
13175             t1.toNewHampshireX();
13176             t1.deleteSubtree( t1.getNode( "D" ), false );
13177             t1.toNewHampshireX();
13178             if ( t1.getNumberOfExternalNodes() != 3 ) {
13179                 return false;
13180             }
13181             t1.deleteSubtree( t1.getNode( "def" ), false );
13182             t1.toNewHampshireX();
13183             if ( t1.getNumberOfExternalNodes() != 2 ) {
13184                 return false;
13185             }
13186             t1.deleteSubtree( t1.getNode( "B" ), false );
13187             t1.toNewHampshireX();
13188             if ( t1.getNumberOfExternalNodes() != 1 ) {
13189                 return false;
13190             }
13191             t1.deleteSubtree( t1.getNode( "C" ), false );
13192             t1.toNewHampshireX();
13193             if ( t1.getNumberOfExternalNodes() != 1 ) {
13194                 return false;
13195             }
13196             t1.deleteSubtree( t1.getNode( "abc" ), false );
13197             t1.toNewHampshireX();
13198             if ( t1.getNumberOfExternalNodes() != 1 ) {
13199                 return false;
13200             }
13201             t1.deleteSubtree( t1.getNode( "r" ), false );
13202             if ( t1.getNumberOfExternalNodes() != 0 ) {
13203                 return false;
13204             }
13205             if ( !t1.isEmpty() ) {
13206                 return false;
13207             }
13208             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
13209             t2.deleteSubtree( t2.getNode( "A" ), false );
13210             t2.toNewHampshireX();
13211             if ( t2.getNumberOfExternalNodes() != 5 ) {
13212                 return false;
13213             }
13214             t2.deleteSubtree( t2.getNode( "abc" ), false );
13215             t2.toNewHampshireX();
13216             if ( t2.getNumberOfExternalNodes() != 3 ) {
13217                 return false;
13218             }
13219             t2.deleteSubtree( t2.getNode( "def" ), false );
13220             t2.toNewHampshireX();
13221             if ( t2.getNumberOfExternalNodes() != 1 ) {
13222                 return false;
13223             }
13224         }
13225         catch ( final Exception e ) {
13226             e.printStackTrace( System.out );
13227             return false;
13228         }
13229         return true;
13230     }
13231
13232     private static boolean testSupportCount() {
13233         try {
13234             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13235             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
13236             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
13237                     + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
13238                     + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))" + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
13239                                                               new NHXParser() );
13240             SupportCount.count( t0_1, phylogenies_1, true, false );
13241             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
13242             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
13243                     + "(((((A,B),C),D),E),((F,G),X))" + "(((((A,Y),B),C),D),((F,G),E))" + "(((((A,B),C),D),E),(F,G))"
13244                     + "(((((A,B),C),D),E),(F,G))" + "(((((A,B),C),D),E),(F,G))" + "(((((A,B),C),D),E),(F,G),Z)"
13245                     + "(((((A,B),C),D),E),(F,G))" + "((((((A,B),C),D),E),F),G)" + "(((((X,Y),F,G),E),((A,B),C)),D)",
13246                                                               new NHXParser() );
13247             SupportCount.count( t0_2, phylogenies_2, true, false );
13248             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
13249             while ( it.hasNext() ) {
13250                 final PhylogenyNode n = it.next();
13251                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
13252                     return false;
13253                 }
13254             }
13255             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
13256             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
13257                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
13258             SupportCount.count( t0_3, phylogenies_3, true, false );
13259             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
13260             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
13261                 return false;
13262             }
13263             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
13264                 return false;
13265             }
13266             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
13267                 return false;
13268             }
13269             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
13270                 return false;
13271             }
13272             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
13273                 return false;
13274             }
13275             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
13276                 return false;
13277             }
13278             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
13279                 return false;
13280             }
13281             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
13282                 return false;
13283             }
13284             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
13285                 return false;
13286             }
13287             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
13288                 return false;
13289             }
13290             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13291             final Phylogeny[] phylogenies_4 = factory
13292                     .create( "((((((A,X),C),B),D),E),F) " + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
13293             SupportCount.count( t0_4, phylogenies_4, true, false );
13294             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
13295             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
13296                 return false;
13297             }
13298             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
13299                 return false;
13300             }
13301             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
13302                 return false;
13303             }
13304             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
13305                 return false;
13306             }
13307             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
13308                 return false;
13309             }
13310             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
13311                 return false;
13312             }
13313             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
13314                 return false;
13315             }
13316             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
13317                 return false;
13318             }
13319             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
13320                 return false;
13321             }
13322             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
13323                 return false;
13324             }
13325             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13326             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13327             double d = SupportCount.compare( b1, a, true, true, true );
13328             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
13329                 return false;
13330             }
13331             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13332             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13333             d = SupportCount.compare( b2, a, true, true, true );
13334             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
13335                 return false;
13336             }
13337             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13338             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
13339             d = SupportCount.compare( b3, a, true, true, true );
13340             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
13341                 return false;
13342             }
13343             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
13344             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
13345             d = SupportCount.compare( b4, a, true, true, false );
13346             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
13347                 return false;
13348             }
13349         }
13350         catch ( final Exception e ) {
13351             e.printStackTrace( System.out );
13352             return false;
13353         }
13354         return true;
13355     }
13356
13357     private static boolean testSupportTransfer() {
13358         try {
13359             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13360             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)",
13361                                                  new NHXParser() )[ 0 ];
13362             final Phylogeny p2 = factory.create(
13363                                                  "(((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)",
13364                                                  new NHXParser() )[ 0 ];
13365             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
13366                 return false;
13367             }
13368             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
13369                 return false;
13370             }
13371             support_transfer.moveBranchLengthsToBootstrap( p1 );
13372             support_transfer.transferSupportValues( p1, p2 );
13373             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
13374                 return false;
13375             }
13376             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
13377                 return false;
13378             }
13379             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
13380                 return false;
13381             }
13382             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
13383                 return false;
13384             }
13385             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
13386                 return false;
13387             }
13388             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
13389                 return false;
13390             }
13391             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
13392                 return false;
13393             }
13394             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
13395                 return false;
13396             }
13397         }
13398         catch ( final Exception e ) {
13399             e.printStackTrace( System.out );
13400             return false;
13401         }
13402         return true;
13403     }
13404
13405     private static boolean testTaxonomyExtraction() {
13406         try {
13407             final PhylogenyNode n0 = PhylogenyNode
13408                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13409             if ( n0.getNodeData().isHasTaxonomy() ) {
13410                 return false;
13411             }
13412             final PhylogenyNode n1 = PhylogenyNode
13413                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13414             if ( n1.getNodeData().isHasTaxonomy() ) {
13415                 System.out.println( n1.toString() );
13416                 return false;
13417             }
13418             final PhylogenyNode n2x = PhylogenyNode
13419                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13420             if ( n2x.getNodeData().isHasTaxonomy() ) {
13421                 return false;
13422             }
13423             final PhylogenyNode n3 = PhylogenyNode
13424                     .createInstanceFromNhxString( "BLAGG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13425             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13426                 System.out.println( n3.toString() );
13427                 return false;
13428             }
13429             final PhylogenyNode n4 = PhylogenyNode
13430                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13431             if ( n4.getNodeData().isHasTaxonomy() ) {
13432                 System.out.println( n4.toString() );
13433                 return false;
13434             }
13435             final PhylogenyNode n5 = PhylogenyNode
13436                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13437             if ( n5.getNodeData().isHasTaxonomy() ) {
13438                 System.out.println( n5.toString() );
13439                 return false;
13440             }
13441             final PhylogenyNode n6 = PhylogenyNode
13442                     .createInstanceFromNhxString( "BLAGG-12345-blag",
13443                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13444             if ( n6.getNodeData().isHasTaxonomy() ) {
13445                 System.out.println( n6.toString() );
13446                 return false;
13447             }
13448             final PhylogenyNode n7 = PhylogenyNode
13449                     .createInstanceFromNhxString( "BL-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13450             if ( n7.getNodeData().isHasTaxonomy() ) {
13451                 System.out.println( n7.toString() );
13452                 return false;
13453             }
13454             final PhylogenyNode n8 = PhylogenyNode
13455                     .createInstanceFromNhxString( "BLAGG_12345-blag",
13456                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13457             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13458                 System.out.println( n8.toString() );
13459                 return false;
13460             }
13461             final PhylogenyNode n9 = PhylogenyNode
13462                     .createInstanceFromNhxString( "BLAGG_12345/blag",
13463                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13464             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13465                 System.out.println( n9.toString() );
13466                 return false;
13467             }
13468             final PhylogenyNode n10x = PhylogenyNode
13469                     .createInstanceFromNhxString( "BLAG!_12X45-blag",
13470                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13471             if ( n10x.getNodeData().isHasTaxonomy() ) {
13472                 System.out.println( n10x.toString() );
13473                 return false;
13474             }
13475             final PhylogenyNode n10xx = PhylogenyNode
13476                     .createInstanceFromNhxString( "BLAG!_1YX45-blag",
13477                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13478             if ( n10xx.getNodeData().isHasTaxonomy() ) {
13479                 System.out.println( n10xx.toString() );
13480                 return false;
13481             }
13482             final PhylogenyNode n10 = PhylogenyNode
13483                     .createInstanceFromNhxString( "BLAGG_9YX45-blag",
13484                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13485             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
13486                 System.out.println( n10.toString() );
13487                 return false;
13488             }
13489             final PhylogenyNode n10v = PhylogenyNode
13490                     .createInstanceFromNhxString( "BLAGG_BPM1-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13491             if ( !n10v.getNodeData().getTaxonomy().getTaxonomyCode().equals( "BPM1" ) ) {
13492                 System.out.println( n10v.toString() );
13493                 return false;
13494             }
13495             final PhylogenyNode n10v2 = PhylogenyNode
13496                     .createInstanceFromNhxString( "BLAGG_ABV-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13497             if ( !n10v2.getNodeData().getTaxonomy().getTaxonomyCode().equals( "ABV" ) ) {
13498                 System.out.println( n10v2.toString() );
13499                 return false;
13500             }
13501             final PhylogenyNode n11 = PhylogenyNode
13502                     .createInstanceFromNhxString( "BLAG@_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13503             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13504                 System.out.println( n11.toString() );
13505                 return false;
13506             }
13507             final PhylogenyNode n12 = PhylogenyNode
13508                     .createInstanceFromNhxString( "BLA_G_Mus_musculus_musculus",
13509                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13510             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13511                 System.out.println( n12.toString() );
13512                 return false;
13513             }
13514             final PhylogenyNode n13 = PhylogenyNode
13515                     .createInstanceFromNhxString( "BLAaG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13516             if ( n13.getNodeData().isHasTaxonomy() ) {
13517                 System.out.println( n13.toString() );
13518                 return false;
13519             }
13520             final PhylogenyNode n14 = PhylogenyNode
13521                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13522             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13523                 System.out.println( n14.toString() );
13524                 return false;
13525             }
13526             final PhylogenyNode n15 = PhylogenyNode
13527                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13528             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13529                 System.out.println( n15.toString() );
13530                 return false;
13531             }
13532             final PhylogenyNode n16 = PhylogenyNode
13533                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13534             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13535                 System.out.println( n16.toString() );
13536                 return false;
13537             }
13538             final PhylogenyNode n17 = PhylogenyNode
13539                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13540             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13541                 System.out.println( n17.toString() );
13542                 return false;
13543             }
13544             final PhylogenyNode n18 = PhylogenyNode
13545                     .createInstanceFromNhxString( "Mus_musculus_musculus_392",
13546                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13547             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13548                 System.out.println( n18.toString() );
13549                 return false;
13550             }
13551             final PhylogenyNode n19 = PhylogenyNode
13552                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
13553                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13554             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13555                 System.out.println( n19.toString() );
13556                 return false;
13557             }
13558             final PhylogenyNode n20 = PhylogenyNode
13559                     .createInstanceFromNhxString( "Mus musculus musculus 392",
13560                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13561             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13562                 System.out.println( n20.toString() );
13563                 return false;
13564             }
13565             final PhylogenyNode n21 = PhylogenyNode
13566                     .createInstanceFromNhxString( "Mus musculus musculus K392",
13567                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13568             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13569                 System.out.println( n21.toString() );
13570                 return false;
13571             }
13572             final PhylogenyNode n23 = PhylogenyNode
13573                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
13574                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13575             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13576                 System.out.println( n23.toString() );
13577                 return false;
13578             }
13579             final PhylogenyNode n24 = PhylogenyNode
13580                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13581             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13582                 System.out.println( n24.toString() );
13583                 return false;
13584             }
13585             //
13586             final PhylogenyNode n25 = PhylogenyNode
13587                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
13588                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13589             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
13590                 System.out.println( n25.toString() );
13591                 return false;
13592             }
13593             final PhylogenyNode n26 = PhylogenyNode
13594                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
13595                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13596             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13597                 System.out.println( n26.toString() );
13598                 return false;
13599             }
13600             final PhylogenyNode n27 = PhylogenyNode
13601                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13602             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13603                 System.out.println( n27.toString() );
13604                 return false;
13605             }
13606         }
13607         catch ( final Exception e ) {
13608             e.printStackTrace( System.out );
13609             return false;
13610         }
13611         return true;
13612     }
13613
13614     private static boolean testTreeCopy() {
13615         try {
13616             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
13617             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
13618             final Phylogeny t1 = t0.copy();
13619             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
13620                 return false;
13621             }
13622             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13623                 return false;
13624             }
13625             t0.deleteSubtree( t0.getNode( "c" ), true );
13626             t0.deleteSubtree( t0.getNode( "a" ), true );
13627             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
13628             t0.getNode( "b" ).setName( "Bee" );
13629             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
13630                 return false;
13631             }
13632             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13633                 return false;
13634             }
13635             t0.deleteSubtree( t0.getNode( "e" ), true );
13636             t0.deleteSubtree( t0.getNode( "Bee" ), true );
13637             t0.deleteSubtree( t0.getNode( "d" ), true );
13638             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13639                 return false;
13640             }
13641         }
13642         catch ( final Exception e ) {
13643             e.printStackTrace();
13644             return false;
13645         }
13646         return true;
13647     }
13648
13649     private static boolean testTreeMethods() {
13650         try {
13651             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13652             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
13653             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
13654             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
13655                 System.out.println( t0.toNewHampshireX() );
13656                 return false;
13657             }
13658             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
13659             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
13660             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
13661                 return false;
13662             }
13663             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
13664                 return false;
13665             }
13666             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
13667                 return false;
13668             }
13669         }
13670         catch ( final Exception e ) {
13671             e.printStackTrace( System.out );
13672             return false;
13673         }
13674         return true;
13675     }
13676
13677     private static boolean testPhylogenyMethods() {
13678         try {
13679             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13680             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)r", new NHXParser() )[ 0 ];
13681             if ( PhylogenyMethods.calculateLevel( t0.getNode( "A" ) ) != 0 ) {
13682                 return false;
13683             }
13684             if ( PhylogenyMethods.calculateLevel( t0.getNode( "B" ) ) != 0 ) {
13685                 return false;
13686             }
13687             if ( PhylogenyMethods.calculateLevel( t0.getNode( "ab" ) ) != 1 ) {
13688                 return false;
13689             }
13690             if ( PhylogenyMethods.calculateLevel( t0.getNode( "C" ) ) != 0 ) {
13691                 return false;
13692             }
13693             if ( PhylogenyMethods.calculateLevel( t0.getNode( "abc" ) ) != 2 ) {
13694                 return false;
13695             }
13696             if ( PhylogenyMethods.calculateLevel( t0.getNode( "D" ) ) != 0 ) {
13697                 return false;
13698             }
13699             if ( PhylogenyMethods.calculateLevel( t0.getNode( "abcd" ) ) != 3 ) {
13700                 return false;
13701             }
13702             if ( PhylogenyMethods.calculateLevel( t0.getNode( "E" ) ) != 0 ) {
13703                 return false;
13704             }
13705             if ( PhylogenyMethods.calculateLevel( t0.getNode( "r" ) ) != 4 ) {
13706                 return false;
13707             }
13708             final Phylogeny t1 = factory.create( "((((A,B)ab,C)abc,D)abcd,E,((((((X)1)2)3)4)5)6)r",
13709                                                  new NHXParser() )[ 0 ];
13710             if ( PhylogenyMethods.calculateLevel( t1.getNode( "r" ) ) != 7 ) {
13711                 return false;
13712             }
13713             if ( PhylogenyMethods.calculateLevel( t1.getNode( "X" ) ) != 0 ) {
13714                 return false;
13715             }
13716             if ( PhylogenyMethods.calculateLevel( t1.getNode( "6" ) ) != 6 ) {
13717                 return false;
13718             }
13719             if ( PhylogenyMethods.calculateLevel( t1.getNode( "5" ) ) != 5 ) {
13720                 return false;
13721             }
13722             if ( PhylogenyMethods.calculateLevel( t1.getNode( "4" ) ) != 4 ) {
13723                 return false;
13724             }
13725             if ( PhylogenyMethods.calculateLevel( t1.getNode( "3" ) ) != 3 ) {
13726                 return false;
13727             }
13728             if ( PhylogenyMethods.calculateLevel( t1.getNode( "2" ) ) != 2 ) {
13729                 return false;
13730             }
13731             if ( PhylogenyMethods.calculateLevel( t1.getNode( "1" ) ) != 1 ) {
13732                 return false;
13733             }
13734             if ( PhylogenyMethods.calculateLevel( t1.getNode( "abcd" ) ) != 3 ) {
13735                 return false;
13736             }
13737         }
13738         catch ( final Exception e ) {
13739             e.printStackTrace( System.out );
13740             return false;
13741         }
13742         return true;
13743     }
13744
13745     private static boolean testUniprotEntryRetrieval() {
13746         try {
13747             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 5000 );
13748             if ( !entry.getAccession().equals( "P12345" ) ) {
13749                 return false;
13750             }
13751             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
13752                 return false;
13753             }
13754             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
13755                 return false;
13756             }
13757             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
13758                 return false;
13759             }
13760             if ( !entry.getGeneName().equals( "GOT2" ) ) {
13761                 return false;
13762             }
13763             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
13764                 return false;
13765             }
13766             if ( entry.getMolecularSequence() == null ) {
13767                 return false;
13768             }
13769             if ( !entry.getMolecularSequence().getMolecularSequenceAsString()
13770                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
13771                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
13772                 System.out.println( "got: " + entry.getMolecularSequence().getMolecularSequenceAsString() );
13773                 System.out.println( "expected something else." );
13774                 return false;
13775             }
13776         }
13777         catch ( final IOException e ) {
13778             System.out.println();
13779             System.out.println( "the following might be due to absence internet connection:" );
13780             e.printStackTrace( System.out );
13781             return true;
13782         }
13783         catch ( final NullPointerException f ) {
13784             f.printStackTrace( System.out );
13785             return false;
13786         }
13787         catch ( final Exception e ) {
13788             return false;
13789         }
13790         return true;
13791     }
13792
13793     private static boolean testUniprotTaxonomySearch() {
13794         try {
13795             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
13796                                                                                                  10 );
13797             if ( results.size() != 1 ) {
13798                 return false;
13799             }
13800             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13801                 return false;
13802             }
13803             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13804                 return false;
13805             }
13806             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13807                 return false;
13808             }
13809             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13810                 return false;
13811             }
13812             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13813                 return false;
13814             }
13815             results = null;
13816             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
13817             if ( results.size() != 1 ) {
13818                 return false;
13819             }
13820             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13821                 return false;
13822             }
13823             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13824                 return false;
13825             }
13826             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13827                 return false;
13828             }
13829             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13830                 return false;
13831             }
13832             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13833                 return false;
13834             }
13835             results = null;
13836             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
13837             if ( results.size() != 1 ) {
13838                 return false;
13839             }
13840             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13841                 return false;
13842             }
13843             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13844                 return false;
13845             }
13846             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13847                 return false;
13848             }
13849             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13850                 return false;
13851             }
13852             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13853                 return false;
13854             }
13855             results = null;
13856             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
13857             if ( results.size() != 1 ) {
13858                 return false;
13859             }
13860             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13861                 return false;
13862             }
13863             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13864                 return false;
13865             }
13866             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13867                 return false;
13868             }
13869             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13870                 return false;
13871             }
13872             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13873                 return false;
13874             }
13875             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
13876                 return false;
13877             }
13878             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
13879                 return false;
13880             }
13881             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13882                     .equals( "Nematostella vectensis" ) ) {
13883                 System.out.println( results.get( 0 ).getLineage() );
13884                 return false;
13885             }
13886             //
13887             results = null;
13888             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
13889             if ( results.size() != 1 ) {
13890                 return false;
13891             }
13892             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13893                 return false;
13894             }
13895             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13896                 return false;
13897             }
13898             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13899                 return false;
13900             }
13901             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13902                 return false;
13903             }
13904             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13905                 return false;
13906             }
13907             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13908                     .equals( "Xenopus tropicalis" ) ) {
13909                 System.out.println( results.get( 0 ).getLineage() );
13910                 return false;
13911             }
13912             //
13913             results = null;
13914             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
13915             if ( results.size() != 1 ) {
13916                 return false;
13917             }
13918             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13919                 return false;
13920             }
13921             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13922                 return false;
13923             }
13924             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13925                 return false;
13926             }
13927             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13928                 return false;
13929             }
13930             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13931                 return false;
13932             }
13933             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13934                     .equals( "Xenopus tropicalis" ) ) {
13935                 System.out.println( results.get( 0 ).getLineage() );
13936                 return false;
13937             }
13938             //
13939             results = null;
13940             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
13941             if ( results.size() != 1 ) {
13942                 return false;
13943             }
13944             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13945                 return false;
13946             }
13947             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13948                 return false;
13949             }
13950             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13951                 return false;
13952             }
13953             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13954                 return false;
13955             }
13956             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13957                 return false;
13958             }
13959             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13960                     .equals( "Xenopus tropicalis" ) ) {
13961                 System.out.println( results.get( 0 ).getLineage() );
13962                 return false;
13963             }
13964         }
13965         catch ( final IOException e ) {
13966             System.out.println();
13967             System.out.println( "the following might be due to absence internet connection:" );
13968             e.printStackTrace( System.out );
13969             return true;
13970         }
13971         catch ( final Exception e ) {
13972             return false;
13973         }
13974         return true;
13975     }
13976 }