dba82fdb5207407d116431654cb9881aabc645f6
[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.development.DevelopmentTools;
48 import org.forester.evoinference.TestPhylogenyReconstruction;
49 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
50 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
51 import org.forester.go.TestGo;
52 import org.forester.io.parsers.FastaParser;
53 import org.forester.io.parsers.GeneralMsaParser;
54 import org.forester.io.parsers.HmmscanPerDomainTableParser;
55 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
56 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
57 import org.forester.io.parsers.nexus.NexusCharactersParser;
58 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
59 import org.forester.io.parsers.nhx.NHXParser;
60 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
61 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
62 import org.forester.io.parsers.tol.TolParser;
63 import org.forester.io.parsers.util.ParserUtils;
64 import org.forester.io.writers.PhylogenyWriter;
65 import org.forester.io.writers.SequenceWriter;
66 import org.forester.msa.BasicMsa;
67 import org.forester.msa.DeleteableMsa;
68 import org.forester.msa.Mafft;
69 import org.forester.msa.Msa;
70 import org.forester.msa.Msa.MSA_FORMAT;
71 import org.forester.msa.MsaInferrer;
72 import org.forester.msa.MsaMethods;
73 import org.forester.pccx.TestPccx;
74 import org.forester.phylogeny.Phylogeny;
75 import org.forester.phylogeny.PhylogenyBranch;
76 import org.forester.phylogeny.PhylogenyMethods;
77 import org.forester.phylogeny.PhylogenyNode;
78 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
79 import org.forester.phylogeny.data.Accession;
80 import org.forester.phylogeny.data.Accession.Source;
81 import org.forester.phylogeny.data.BinaryCharacters;
82 import org.forester.phylogeny.data.BranchWidth;
83 import org.forester.phylogeny.data.Confidence;
84 import org.forester.phylogeny.data.Distribution;
85 import org.forester.phylogeny.data.DomainArchitecture;
86 import org.forester.phylogeny.data.Event;
87 import org.forester.phylogeny.data.Identifier;
88 import org.forester.phylogeny.data.PhylogenyData;
89 import org.forester.phylogeny.data.PhylogenyDataUtil;
90 import org.forester.phylogeny.data.Polygon;
91 import org.forester.phylogeny.data.PropertiesMap;
92 import org.forester.phylogeny.data.Property;
93 import org.forester.phylogeny.data.Property.AppliesTo;
94 import org.forester.phylogeny.data.ProteinDomain;
95 import org.forester.phylogeny.data.Taxonomy;
96 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
97 import org.forester.phylogeny.factories.PhylogenyFactory;
98 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
99 import org.forester.protein.BasicDomain;
100 import org.forester.protein.BasicProtein;
101 import org.forester.protein.Domain;
102 import org.forester.protein.Protein;
103 import org.forester.protein.ProteinId;
104 import org.forester.rio.TestRIO;
105 import org.forester.sdi.SDI;
106 import org.forester.sdi.SDIR;
107 import org.forester.sdi.TestGSDI;
108 import org.forester.sequence.BasicSequence;
109 import org.forester.sequence.MolecularSequence;
110 import org.forester.species.BasicSpecies;
111 import org.forester.species.Species;
112 import org.forester.surfacing.TestSurfacing;
113 import org.forester.tools.ConfidenceAssessor;
114 import org.forester.tools.SupportCount;
115 import org.forester.tools.TreeSplitMatrix;
116 import org.forester.util.AsciiHistogram;
117 import org.forester.util.BasicDescriptiveStatistics;
118 import org.forester.util.BasicTable;
119 import org.forester.util.BasicTableParser;
120 import org.forester.util.DescriptiveStatistics;
121 import org.forester.util.ForesterConstants;
122 import org.forester.util.ForesterUtil;
123 import org.forester.util.GeneralTable;
124 import org.forester.util.SequenceAccessionTools;
125 import org.forester.ws.seqdb.SequenceDatabaseEntry;
126 import org.forester.ws.seqdb.SequenceDbWsTools;
127 import org.forester.ws.seqdb.UniProtTaxonomy;
128
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"
135             + ForesterUtil.getFileSeparator();
136     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
137             + ForesterUtil.getFileSeparator() + "test_data"
138             + ForesterUtil.getFileSeparator();
139     private final static boolean PERFORM_DB_TESTS          = true;
140     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
141     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
142             + ForesterConstants.PHYLO_XML_VERSION + "/"
143             + ForesterConstants.PHYLO_XML_XSD;
144     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
145             + ForesterConstants.PHYLO_XML_VERSION + "/"
146             + ForesterConstants.PHYLO_XML_XSD;
147     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
148     private final static double  ZERO_DIFF                 = 1.0E-9;
149
150     public static boolean isEqual( final double a, final double b ) {
151         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
152     }
153
154     public static void main( final String[] args ) {
155         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
156         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
157                             + "]" );
158         Locale.setDefault( Locale.US );
159         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
160         int failed = 0;
161         int succeeded = 0;
162         System.out.print( "[Test if directory with files for testing exists/is readable: " );
163         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
164             System.out.println( "OK.]" );
165         }
166         else {
167             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
168             System.out.println( "Testing aborted." );
169             System.exit( -1 );
170         }
171         System.out.print( "[Test if resources directory exists/is readable: " );
172         if ( testDir( PATH_TO_RESOURCES ) ) {
173             System.out.println( "OK.]" );
174         }
175         else {
176             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
177             System.out.println( "Testing aborted." );
178             System.exit( -1 );
179         }
180         final long start_time = new Date().getTime();
181         System.out.print( "Basic node methods: " );
182         if ( Test.testBasicNodeMethods() ) {
183             System.out.println( "OK." );
184             succeeded++;
185         }
186         else {
187             System.out.println( "failed." );
188             failed++;
189         }
190         System.out.print( "Protein id: " );
191         if ( !testProteinId() ) {
192             System.out.println( "failed." );
193             failed++;
194         }
195         else {
196             succeeded++;
197         }
198         System.out.println( "OK." );
199         System.out.print( "Species: " );
200         if ( !testSpecies() ) {
201             System.out.println( "failed." );
202             failed++;
203         }
204         else {
205             succeeded++;
206         }
207         System.out.println( "OK." );
208         System.out.print( "Basic domain: " );
209         if ( !testBasicDomain() ) {
210             System.out.println( "failed." );
211             failed++;
212         }
213         else {
214             succeeded++;
215         }
216         System.out.println( "OK." );
217         System.out.print( "Basic protein: " );
218         if ( !testBasicProtein() ) {
219             System.out.println( "failed." );
220             failed++;
221         }
222         else {
223             succeeded++;
224         }
225         System.out.println( "OK." );
226         System.out.print( "Sequence writer: " );
227         if ( testSequenceWriter() ) {
228             System.out.println( "OK." );
229             succeeded++;
230         }
231         else {
232             System.out.println( "failed." );
233             failed++;
234         }
235         System.out.print( "Sequence id parsing: " );
236         if ( testSequenceIdParsing() ) {
237             System.out.println( "OK." );
238             succeeded++;
239         }
240         else {
241             System.out.println( "failed." );
242             failed++;
243         }
244         System.out.print( "UniProtKB id extraction: " );
245         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
246             System.out.println( "OK." );
247             succeeded++;
248         }
249         else {
250             System.out.println( "failed." );
251             failed++;
252         }
253         System.out.print( "Sequence DB tools 1: " );
254         if ( testSequenceDbWsTools1() ) {
255             System.out.println( "OK." );
256             succeeded++;
257         }
258         else {
259             System.out.println( "failed." );
260             failed++;
261         }
262         System.out.print( "Hmmscan output parser: " );
263         if ( testHmmscanOutputParser() ) {
264             System.out.println( "OK." );
265             succeeded++;
266         }
267         else {
268             System.out.println( "failed." );
269             failed++;
270         }
271         System.out.print( "Overlap removal: " );
272         if ( !org.forester.test.Test.testOverlapRemoval() ) {
273             System.out.println( "failed." );
274             failed++;
275         }
276         else {
277             succeeded++;
278         }
279         System.out.println( "OK." );
280         System.out.print( "Engulfing overlap removal: " );
281         if ( !Test.testEngulfingOverlapRemoval() ) {
282             System.out.println( "failed." );
283             failed++;
284         }
285         else {
286             succeeded++;
287         }
288         System.out.println( "OK." );
289         System.out.print( "Taxonomy data extraction: " );
290         if ( Test.testExtractTaxonomyDataFromNodeName() ) {
291             System.out.println( "OK." );
292             succeeded++;
293         }
294         else {
295             System.out.println( "failed." );
296             failed++;
297         }
298         System.out.print( "Taxonomy code extraction: " );
299         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
300             System.out.println( "OK." );
301             succeeded++;
302         }
303         else {
304             System.out.println( "failed." );
305             failed++;
306         }
307         System.out.print( "SN extraction: " );
308         if ( Test.testExtractSNFromNodeName() ) {
309             System.out.println( "OK." );
310             succeeded++;
311         }
312         else {
313             System.out.println( "failed." );
314             failed++;
315         }
316         System.out.print( "Taxonomy extraction (general): " );
317         if ( Test.testTaxonomyExtraction() ) {
318             System.out.println( "OK." );
319             succeeded++;
320         }
321         else {
322             System.out.println( "failed." );
323             failed++;
324         }
325         System.out.print( "Uri for Aptx web sequence accession: " );
326         if ( Test.testCreateUriForSeqWeb() ) {
327             System.out.println( "OK." );
328             succeeded++;
329         }
330         else {
331             System.out.println( "failed." );
332             failed++;
333         }
334         System.out.print( "Basic node construction and parsing of NHX (node level): " );
335         if ( Test.testNHXNodeParsing() ) {
336             System.out.println( "OK." );
337             succeeded++;
338         }
339         else {
340             System.out.println( "failed." );
341             failed++;
342         }
343         System.out.print( "NHX parsing iterating: " );
344         if ( Test.testNHParsingIter() ) {
345             System.out.println( "OK." );
346             succeeded++;
347         }
348         else {
349             System.out.println( "failed." );
350             failed++;
351         }
352         System.out.print( "NH parsing: " );
353         if ( Test.testNHParsing() ) {
354             System.out.println( "OK." );
355             succeeded++;
356         }
357         else {
358             System.out.println( "failed." );
359             failed++;
360         }
361         System.out.print( "Conversion to NHX (node level): " );
362         if ( Test.testNHXconversion() ) {
363             System.out.println( "OK." );
364             succeeded++;
365         }
366         else {
367             System.out.println( "failed." );
368             failed++;
369         }
370         System.out.print( "NHX parsing: " );
371         if ( Test.testNHXParsing() ) {
372             System.out.println( "OK." );
373             succeeded++;
374         }
375         else {
376             System.out.println( "failed." );
377             failed++;
378         }
379         System.out.print( "NHX parsing with quotes: " );
380         if ( Test.testNHXParsingQuotes() ) {
381             System.out.println( "OK." );
382             succeeded++;
383         }
384         else {
385             System.out.println( "failed." );
386             failed++;
387         }
388         System.out.print( "NHX parsing (MrBayes): " );
389         if ( Test.testNHXParsingMB() ) {
390             System.out.println( "OK." );
391             succeeded++;
392         }
393         else {
394             System.out.println( "failed." );
395             failed++;
396         }
397         System.out.print( "Nexus characters parsing: " );
398         if ( Test.testNexusCharactersParsing() ) {
399             System.out.println( "OK." );
400             succeeded++;
401         }
402         else {
403             System.out.println( "failed." );
404             failed++;
405         }
406         System.out.print( "Nexus tree parsing iterating: " );
407         if ( Test.testNexusTreeParsingIterating() ) {
408             System.out.println( "OK." );
409             succeeded++;
410         }
411         else {
412             System.out.println( "failed." );
413             failed++;
414         }
415         System.out.print( "Nexus tree parsing: " );
416         if ( Test.testNexusTreeParsing() ) {
417             System.out.println( "OK." );
418             succeeded++;
419         }
420         else {
421             System.out.println( "failed." );
422             failed++;
423         }
424         System.out.print( "Nexus tree parsing (translating): " );
425         if ( Test.testNexusTreeParsingTranslating() ) {
426             System.out.println( "OK." );
427             succeeded++;
428         }
429         else {
430             System.out.println( "failed." );
431             failed++;
432         }
433         System.out.print( "Nexus matrix parsing: " );
434         if ( Test.testNexusMatrixParsing() ) {
435             System.out.println( "OK." );
436             succeeded++;
437         }
438         else {
439             System.out.println( "failed." );
440             failed++;
441         }
442         System.out.print( "Basic phyloXML parsing: " );
443         if ( Test.testBasicPhyloXMLparsing() ) {
444             System.out.println( "OK." );
445             succeeded++;
446         }
447         else {
448             System.out.println( "failed." );
449             failed++;
450         }
451         System.out.print( "Basic phyloXML parsing (validating against schema): " );
452         if ( testBasicPhyloXMLparsingValidating() ) {
453             System.out.println( "OK." );
454             succeeded++;
455         }
456         else {
457             System.out.println( "failed." );
458             failed++;
459         }
460         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
461         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
462             System.out.println( "OK." );
463             succeeded++;
464         }
465         else {
466             System.out.println( "failed." );
467             failed++;
468         }
469         System.out.print( "phyloXML Distribution Element: " );
470         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
471             System.out.println( "OK." );
472             succeeded++;
473         }
474         else {
475             System.out.println( "failed." );
476             failed++;
477         }
478         System.out.print( "Tol XML parsing: " );
479         if ( Test.testBasicTolXMLparsing() ) {
480             System.out.println( "OK." );
481             succeeded++;
482         }
483         else {
484             System.out.println( "failed." );
485             failed++;
486         }
487         System.out.print( "Copying of node data: " );
488         if ( Test.testCopyOfNodeData() ) {
489             System.out.println( "OK." );
490             succeeded++;
491         }
492         else {
493             System.out.println( "failed." );
494             failed++;
495         }
496         System.out.print( "Tree copy: " );
497         if ( Test.testTreeCopy() ) {
498             System.out.println( "OK." );
499             succeeded++;
500         }
501         else {
502             System.out.println( "failed." );
503             failed++;
504         }
505         System.out.print( "Basic tree methods: " );
506         if ( Test.testBasicTreeMethods() ) {
507             System.out.println( "OK." );
508             succeeded++;
509         }
510         else {
511             System.out.println( "failed." );
512             failed++;
513         }
514         System.out.print( "Tree methods: " );
515         if ( Test.testTreeMethods() ) {
516             System.out.println( "OK." );
517             succeeded++;
518         }
519         else {
520             System.out.println( "failed." );
521             failed++;
522         }
523         System.out.print( "Postorder Iterator: " );
524         if ( Test.testPostOrderIterator() ) {
525             System.out.println( "OK." );
526             succeeded++;
527         }
528         else {
529             System.out.println( "failed." );
530             failed++;
531         }
532         System.out.print( "Preorder Iterator: " );
533         if ( Test.testPreOrderIterator() ) {
534             System.out.println( "OK." );
535             succeeded++;
536         }
537         else {
538             System.out.println( "failed." );
539             failed++;
540         }
541         System.out.print( "Levelorder Iterator: " );
542         if ( Test.testLevelOrderIterator() ) {
543             System.out.println( "OK." );
544             succeeded++;
545         }
546         else {
547             System.out.println( "failed." );
548             failed++;
549         }
550         System.out.print( "Re-id methods: " );
551         if ( Test.testReIdMethods() ) {
552             System.out.println( "OK." );
553             succeeded++;
554         }
555         else {
556             System.out.println( "failed." );
557             failed++;
558         }
559         System.out.print( "Methods on last external nodes: " );
560         if ( Test.testLastExternalNodeMethods() ) {
561             System.out.println( "OK." );
562             succeeded++;
563         }
564         else {
565             System.out.println( "failed." );
566             failed++;
567         }
568         System.out.print( "Methods on external nodes: " );
569         if ( Test.testExternalNodeRelatedMethods() ) {
570             System.out.println( "OK." );
571             succeeded++;
572         }
573         else {
574             System.out.println( "failed." );
575             failed++;
576         }
577         System.out.print( "Deletion of external nodes: " );
578         if ( Test.testDeletionOfExternalNodes() ) {
579             System.out.println( "OK." );
580             succeeded++;
581         }
582         else {
583             System.out.println( "failed." );
584             failed++;
585         }
586         System.out.print( "Subtree deletion: " );
587         if ( Test.testSubtreeDeletion() ) {
588             System.out.println( "OK." );
589             succeeded++;
590         }
591         else {
592             System.out.println( "failed." );
593             failed++;
594         }
595         System.out.print( "Phylogeny branch: " );
596         if ( Test.testPhylogenyBranch() ) {
597             System.out.println( "OK." );
598             succeeded++;
599         }
600         else {
601             System.out.println( "failed." );
602             failed++;
603         }
604         System.out.print( "Rerooting: " );
605         if ( Test.testRerooting() ) {
606             System.out.println( "OK." );
607             succeeded++;
608         }
609         else {
610             System.out.println( "failed." );
611             failed++;
612         }
613         System.out.print( "Mipoint rooting: " );
614         if ( Test.testMidpointrooting() ) {
615             System.out.println( "OK." );
616             succeeded++;
617         }
618         else {
619             System.out.println( "failed." );
620             failed++;
621         }
622         System.out.print( "Node removal: " );
623         if ( Test.testNodeRemoval() ) {
624             System.out.println( "OK." );
625             succeeded++;
626         }
627         else {
628             System.out.println( "failed." );
629             failed++;
630         }
631         System.out.print( "Support count: " );
632         if ( Test.testSupportCount() ) {
633             System.out.println( "OK." );
634             succeeded++;
635         }
636         else {
637             System.out.println( "failed." );
638             failed++;
639         }
640         System.out.print( "Support transfer: " );
641         if ( Test.testSupportTransfer() ) {
642             System.out.println( "OK." );
643             succeeded++;
644         }
645         else {
646             System.out.println( "failed." );
647             failed++;
648         }
649         System.out.print( "Finding of LCA: " );
650         if ( Test.testGetLCA() ) {
651             System.out.println( "OK." );
652             succeeded++;
653         }
654         else {
655             System.out.println( "failed." );
656             failed++;
657         }
658         System.out.print( "Finding of LCA 2: " );
659         if ( Test.testGetLCA2() ) {
660             System.out.println( "OK." );
661             succeeded++;
662         }
663         else {
664             System.out.println( "failed." );
665             failed++;
666         }
667         System.out.print( "Calculation of distance between nodes: " );
668         if ( Test.testGetDistance() ) {
669             System.out.println( "OK." );
670             succeeded++;
671         }
672         else {
673             System.out.println( "failed." );
674             failed++;
675         }
676         System.out.print( "Descriptive statistics: " );
677         if ( Test.testDescriptiveStatistics() ) {
678             System.out.println( "OK." );
679             succeeded++;
680         }
681         else {
682             System.out.println( "failed." );
683             failed++;
684         }
685         System.out.print( "Data objects and methods: " );
686         if ( Test.testDataObjects() ) {
687             System.out.println( "OK." );
688             succeeded++;
689         }
690         else {
691             System.out.println( "failed." );
692             failed++;
693         }
694         System.out.print( "Properties map: " );
695         if ( Test.testPropertiesMap() ) {
696             System.out.println( "OK." );
697             succeeded++;
698         }
699         else {
700             System.out.println( "failed." );
701             failed++;
702         }
703         System.out.print( "SDIse: " );
704         if ( Test.testSDIse() ) {
705             System.out.println( "OK." );
706             succeeded++;
707         }
708         else {
709             System.out.println( "failed." );
710             failed++;
711         }
712         System.out.print( "SDIunrooted: " );
713         if ( Test.testSDIunrooted() ) {
714             System.out.println( "OK." );
715             succeeded++;
716         }
717         else {
718             System.out.println( "failed." );
719             failed++;
720         }
721         System.out.print( "GSDI: " );
722         if ( TestGSDI.test() ) {
723             System.out.println( "OK." );
724             succeeded++;
725         }
726         else {
727             System.out.println( "failed." );
728             failed++;
729         }
730         System.out.print( "RIO: " );
731         if ( TestRIO.test() ) {
732             System.out.println( "OK." );
733             succeeded++;
734         }
735         else {
736             System.out.println( "failed." );
737             failed++;
738         }
739         System.out.print( "Phylogeny reconstruction:" );
740         System.out.println();
741         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
742             System.out.println( "OK." );
743             succeeded++;
744         }
745         else {
746             System.out.println( "failed." );
747             failed++;
748         }
749         System.out.print( "Analysis of domain architectures: " );
750         System.out.println();
751         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
752             System.out.println( "OK." );
753             succeeded++;
754         }
755         else {
756             System.out.println( "failed." );
757             failed++;
758         }
759         System.out.print( "GO: " );
760         System.out.println();
761         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
762             System.out.println( "OK." );
763             succeeded++;
764         }
765         else {
766             System.out.println( "failed." );
767             failed++;
768         }
769         System.out.print( "Modeling tools: " );
770         if ( TestPccx.test() ) {
771             System.out.println( "OK." );
772             succeeded++;
773         }
774         else {
775             System.out.println( "failed." );
776             failed++;
777         }
778         System.out.print( "Split Matrix strict: " );
779         if ( Test.testSplitStrict() ) {
780             System.out.println( "OK." );
781             succeeded++;
782         }
783         else {
784             System.out.println( "failed." );
785             failed++;
786         }
787         System.out.print( "Split Matrix: " );
788         if ( Test.testSplit() ) {
789             System.out.println( "OK." );
790             succeeded++;
791         }
792         else {
793             System.out.println( "failed." );
794             failed++;
795         }
796         System.out.print( "Confidence Assessor: " );
797         if ( Test.testConfidenceAssessor() ) {
798             System.out.println( "OK." );
799             succeeded++;
800         }
801         else {
802             System.out.println( "failed." );
803             failed++;
804         }
805         System.out.print( "Basic table: " );
806         if ( Test.testBasicTable() ) {
807             System.out.println( "OK." );
808             succeeded++;
809         }
810         else {
811             System.out.println( "failed." );
812             failed++;
813         }
814         System.out.print( "General table: " );
815         if ( Test.testGeneralTable() ) {
816             System.out.println( "OK." );
817             succeeded++;
818         }
819         else {
820             System.out.println( "failed." );
821             failed++;
822         }
823         System.out.print( "Amino acid sequence: " );
824         if ( Test.testAminoAcidSequence() ) {
825             System.out.println( "OK." );
826             succeeded++;
827         }
828         else {
829             System.out.println( "failed." );
830             failed++;
831         }
832         System.out.print( "General MSA parser: " );
833         if ( Test.testGeneralMsaParser() ) {
834             System.out.println( "OK." );
835             succeeded++;
836         }
837         else {
838             System.out.println( "failed." );
839             failed++;
840         }
841         System.out.print( "Fasta parser for msa: " );
842         if ( Test.testFastaParser() ) {
843             System.out.println( "OK." );
844             succeeded++;
845         }
846         else {
847             System.out.println( "failed." );
848             failed++;
849         }
850         System.out.print( "Creation of balanced phylogeny: " );
851         if ( Test.testCreateBalancedPhylogeny() ) {
852             System.out.println( "OK." );
853             succeeded++;
854         }
855         else {
856             System.out.println( "failed." );
857             failed++;
858         }
859         System.out.print( "Genbank accessor parsing: " );
860         if ( Test.testGenbankAccessorParsing() ) {
861             System.out.println( "OK." );
862             succeeded++;
863         }
864         else {
865             System.out.println( "failed." );
866             failed++;
867         }
868         String path = "";
869         final String os = ForesterUtil.OS_NAME.toLowerCase();
870         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
871             path = "/usr/local/bin/mafft";
872         }
873         else if ( os.indexOf( "win" ) >= 0 ) {
874             path = "C:\\Program Files\\mafft-win\\mafft.bat";
875         }
876         else {
877             path = "mafft";
878             if ( !MsaInferrer.isInstalled( path ) ) {
879                 path = "/usr/bin/mafft";
880             }
881             if ( !MsaInferrer.isInstalled( path ) ) {
882                 path = "/usr/local/bin/mafft";
883             }
884         }
885         if ( MsaInferrer.isInstalled( path ) ) {
886             System.out.print( "MAFFT (external program): " );
887             if ( Test.testMafft( path ) ) {
888                 System.out.println( "OK." );
889                 succeeded++;
890             }
891             else {
892                 System.out.println( "failed [will not count towards failed tests]" );
893             }
894         }
895         System.out.print( "Next nodes with collapsed: " );
896         if ( Test.testNextNodeWithCollapsing() ) {
897             System.out.println( "OK." );
898             succeeded++;
899         }
900         else {
901             System.out.println( "failed." );
902             failed++;
903         }
904         System.out.print( "Simple MSA quality: " );
905         if ( Test.testMsaQualityMethod() ) {
906             System.out.println( "OK." );
907             succeeded++;
908         }
909         else {
910             System.out.println( "failed." );
911             failed++;
912         }
913         System.out.print( "Deleteable MSA: " );
914         if ( Test.testDeleteableMsa() ) {
915             System.out.println( "OK." );
916             succeeded++;
917         }
918         else {
919             System.out.println( "failed." );
920             failed++;
921         }
922         System.out.print( "MSA entropy: " );
923         if ( Test.testMsaEntropy() ) {
924             System.out.println( "OK." );
925             succeeded++;
926         }
927         else {
928             System.out.println( "failed." );
929             failed++;
930         }
931         if ( PERFORM_DB_TESTS ) {
932             System.out.print( "Uniprot Entry Retrieval: " );
933             if ( Test.testUniprotEntryRetrieval() ) {
934                 System.out.println( "OK." );
935                 succeeded++;
936             }
937             else {
938                 System.out.println( "failed." );
939                 failed++;
940             }
941             System.out.print( "Ebi Entry Retrieval: " );
942             if ( Test.testEbiEntryRetrieval() ) {
943                 System.out.println( "OK." );
944                 succeeded++;
945             }
946             else {
947                 System.out.println( "failed." );
948                 failed++;
949             }
950             System.out.print( "Sequence DB tools 2: " );
951             if ( testSequenceDbWsTools2() ) {
952                 System.out.println( "OK." );
953                 succeeded++;
954             }
955             else {
956                 System.out.println( "failed." );
957                 failed++;
958                 System.exit( -1 );
959             }
960             System.out.print( "Uniprot Taxonomy Search: " );
961             if ( Test.testUniprotTaxonomySearch() ) {
962                 System.out.println( "OK." );
963                 succeeded++;
964             }
965             else {
966                 System.out.println( "failed." );
967                 failed++;
968             }
969         }
970         if ( PERFORM_WEB_TREE_ACCESS ) {
971             System.out.print( "NHX parsing from URL: " );
972             if ( Test.testNHXparsingFromURL() ) {
973                 System.out.println( "OK." );
974                 succeeded++;
975             }
976             else {
977                 System.out.println( "failed." );
978                 failed++;
979             }
980             System.out.print( "NHX parsing from URL 2: " );
981             if ( Test.testNHXparsingFromURL2() ) {
982                 System.out.println( "OK." );
983                 succeeded++;
984             }
985             else {
986                 System.out.println( "failed." );
987                 failed++;
988             }
989             System.out.print( "phyloXML parsing from URL: " );
990             if ( Test.testPhyloXMLparsingFromURL() ) {
991                 System.out.println( "OK." );
992                 succeeded++;
993             }
994             else {
995                 System.out.println( "failed." );
996                 failed++;
997             }
998             System.out.print( "TreeBase acccess: " );
999             if ( Test.testTreeBaseReading() ) {
1000                 System.out.println( "OK." );
1001                 succeeded++;
1002             }
1003             else {
1004                 System.out.println( "failed." );
1005                 failed++;
1006             }
1007             //
1008             System.out.print( "ToL access: " );
1009             if ( Test.testToLReading() ) {
1010                 System.out.println( "OK." );
1011                 succeeded++;
1012             }
1013             else {
1014                 System.out.println( "failed." );
1015                 failed++;
1016             }
1017             //
1018             System.out.print( "TreeFam access: " );
1019             if ( Test.testTreeFamReading() ) {
1020                 System.out.println( "OK." );
1021                 succeeded++;
1022             }
1023             else {
1024                 System.out.println( "failed." );
1025                 failed++;
1026             }
1027             //
1028             //
1029             System.out.print( "Pfam tree access: " );
1030             if ( Test.testPfamTreeReading() ) {
1031                 System.out.println( "OK." );
1032                 succeeded++;
1033             }
1034             else {
1035                 System.out.println( "failed." );
1036                 failed++;
1037             }
1038         }
1039         System.out.println();
1040         final Runtime rt = java.lang.Runtime.getRuntime();
1041         final long free_memory = rt.freeMemory() / 1000000;
1042         final long total_memory = rt.totalMemory() / 1000000;
1043         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1044                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1045         System.out.println();
1046         System.out.println( "Successful tests: " + succeeded );
1047         System.out.println( "Failed     tests: " + failed );
1048         System.out.println();
1049         if ( failed < 1 ) {
1050             System.out.println( "OK." );
1051         }
1052         else {
1053             System.out.println( "Not OK." );
1054         }
1055     }
1056
1057     public static boolean testEngulfingOverlapRemoval() {
1058         try {
1059             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1060             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1061             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1062             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1063             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1064             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1065             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1066             final List<Boolean> covered = new ArrayList<Boolean>();
1067             covered.add( true ); // 0
1068             covered.add( false ); // 1
1069             covered.add( true ); // 2
1070             covered.add( false ); // 3
1071             covered.add( true ); // 4
1072             covered.add( true ); // 5
1073             covered.add( false ); // 6
1074             covered.add( true ); // 7
1075             covered.add( true ); // 8
1076             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1077                 return false;
1078             }
1079             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1080                 return false;
1081             }
1082             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1083                 return false;
1084             }
1085             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1086                 return false;
1087             }
1088             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1089                 return false;
1090             }
1091             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1092                 return false;
1093             }
1094             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1095                 return false;
1096             }
1097             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1098             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1099             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1100             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1101             abc.addProteinDomain( a );
1102             abc.addProteinDomain( b );
1103             abc.addProteinDomain( c );
1104             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1105             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1106             if ( abc.getNumberOfProteinDomains() != 3 ) {
1107                 return false;
1108             }
1109             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1110                 return false;
1111             }
1112             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1113                 return false;
1114             }
1115             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1116                 return false;
1117             }
1118             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1119                 return false;
1120             }
1121             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1122             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1123             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1124             final Protein def = new BasicProtein( "def", "nemve", 0 );
1125             def.addProteinDomain( d );
1126             def.addProteinDomain( e );
1127             def.addProteinDomain( f );
1128             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1129             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1130             if ( def.getNumberOfProteinDomains() != 3 ) {
1131                 return false;
1132             }
1133             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1134                 return false;
1135             }
1136             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1137                 return false;
1138             }
1139             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1140                 return false;
1141             }
1142             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1143                 return false;
1144             }
1145             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1146                 return false;
1147             }
1148         }
1149         catch ( final Exception e ) {
1150             e.printStackTrace( System.out );
1151             return false;
1152         }
1153         return true;
1154     }
1155
1156     public static final boolean testNHXparsingFromURL2() {
1157         try {
1158             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1159             final Phylogeny phys[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1160                                                                       false,
1161                                                                       false,
1162                                                                       false,
1163                                                                       TAXONOMY_EXTRACTION.NO,
1164                                                                       false );
1165             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1166                 return false;
1167             }
1168             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1169                 System.out.println( phys[ 0 ].toNewHampshire() );
1170                 return false;
1171             }
1172             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1173                 System.out.println( phys[ 1 ].toNewHampshire() );
1174                 return false;
1175             }
1176             final Phylogeny phys2[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1177                                                                        false,
1178                                                                        false,
1179                                                                        false,
1180                                                                        TAXONOMY_EXTRACTION.NO,
1181                                                                        false );
1182             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1183                 return false;
1184             }
1185             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1186                 System.out.println( phys2[ 0 ].toNewHampshire() );
1187                 return false;
1188             }
1189             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1190                 System.out.println( phys2[ 1 ].toNewHampshire() );
1191                 return false;
1192             }
1193             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1194                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1195             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1196                 return false;
1197             }
1198             if ( !phys3[ 0 ]
1199                     .toNewHampshire()
1200                     .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))))));" ) ) {
1201                 System.out.println( phys3[ 0 ].toNewHampshire() );
1202                 return false;
1203             }
1204             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1205                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1206             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1207                 return false;
1208             }
1209             if ( !phys4[ 0 ]
1210                     .toNewHampshire()
1211                     .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))))));" ) ) {
1212                 System.out.println( phys4[ 0 ].toNewHampshire() );
1213                 return false;
1214             }
1215         }
1216         catch ( final Exception e ) {
1217             e.printStackTrace();
1218             return false;
1219         }
1220         return true;
1221     }
1222
1223     public static final boolean testNHXparsingFromURL() {
1224         try {
1225             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1226             final URL u = new URL( s );
1227             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1228             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1229             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1230                 return false;
1231             }
1232             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1233                 System.out.println( phys[ 0 ].toNewHampshire() );
1234                 return false;
1235             }
1236             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1237                 System.out.println( phys[ 1 ].toNewHampshire() );
1238                 return false;
1239             }
1240             final URL u2 = new URL( s );
1241             final Phylogeny[] phys2 = factory.create( u2.openStream(), new NHXParser() );
1242             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1243                 return false;
1244             }
1245             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1246                 System.out.println( phys2[ 0 ].toNewHampshire() );
1247                 return false;
1248             }
1249             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1250             final NHXParser p = new NHXParser();
1251             final URL u3 = new URL( s );
1252             p.setSource( u3 );
1253             if ( !p.hasNext() ) {
1254                 return false;
1255             }
1256             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1257                 return false;
1258             }
1259             if ( !p.hasNext() ) {
1260                 return false;
1261             }
1262             p.reset();
1263             if ( !p.hasNext() ) {
1264                 return false;
1265             }
1266             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1267                 return false;
1268             }
1269             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1270                 return false;
1271             }
1272             p.reset();
1273             if ( !p.hasNext() ) {
1274                 return false;
1275             }
1276             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1277                 return false;
1278             }
1279             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1280                 return false;
1281             }
1282         }
1283         catch ( final Exception e ) {
1284             System.out.println( e.toString() );
1285             e.printStackTrace();
1286             return false;
1287         }
1288         return true;
1289     }
1290
1291     public static boolean testOverlapRemoval() {
1292         try {
1293             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1294             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1295             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1296             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1297             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1298             final List<Boolean> covered = new ArrayList<Boolean>();
1299             covered.add( true ); // 0
1300             covered.add( false ); // 1
1301             covered.add( true ); // 2
1302             covered.add( false ); // 3
1303             covered.add( true ); // 4
1304             covered.add( true ); // 5
1305             covered.add( false ); // 6
1306             covered.add( true ); // 7
1307             covered.add( true ); // 8
1308             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1309                 return false;
1310             }
1311             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1312                 return false;
1313             }
1314             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1315                 return false;
1316             }
1317             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1318                 return false;
1319             }
1320             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1321                 return false;
1322             }
1323             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1324             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1325             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1326             ab.addProteinDomain( a );
1327             ab.addProteinDomain( b );
1328             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1329             if ( ab.getNumberOfProteinDomains() != 2 ) {
1330                 return false;
1331             }
1332             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1333                 return false;
1334             }
1335             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1336                 return false;
1337             }
1338             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1339             if ( ab.getNumberOfProteinDomains() != 2 ) {
1340                 return false;
1341             }
1342             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1343                 return false;
1344             }
1345             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1346             final Domain d = new BasicDomain( "d",
1347                                               ( short ) 10000,
1348                                               ( short ) 10500,
1349                                               ( short ) 1,
1350                                               ( short ) 1,
1351                                               0.0000001,
1352                                               1 );
1353             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1354             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1355             cde.addProteinDomain( c );
1356             cde.addProteinDomain( d );
1357             cde.addProteinDomain( e );
1358             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1359             if ( cde.getNumberOfProteinDomains() != 3 ) {
1360                 return false;
1361             }
1362             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1363                 return false;
1364             }
1365             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1366             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1367             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1368             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1369             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1370             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1371             fghi.addProteinDomain( f );
1372             fghi.addProteinDomain( g );
1373             fghi.addProteinDomain( h );
1374             fghi.addProteinDomain( i );
1375             fghi.addProteinDomain( i );
1376             fghi.addProteinDomain( i );
1377             fghi.addProteinDomain( i2 );
1378             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1379             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1380                 return false;
1381             }
1382             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1383                 return false;
1384             }
1385             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1386                 return false;
1387             }
1388             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1389             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1390                 return false;
1391             }
1392             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1393                 return false;
1394             }
1395             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1396             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1397             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1398             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1399             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1400             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1401             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1402             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1403             jklm.addProteinDomain( j );
1404             jklm.addProteinDomain( k );
1405             jklm.addProteinDomain( l );
1406             jklm.addProteinDomain( m );
1407             jklm.addProteinDomain( m0 );
1408             jklm.addProteinDomain( m1 );
1409             jklm.addProteinDomain( m2 );
1410             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1411             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1412                 return false;
1413             }
1414             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1415                 return false;
1416             }
1417             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1418                 return false;
1419             }
1420             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1421             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1422                 return false;
1423             }
1424             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1425                 return false;
1426             }
1427             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1428             final Protein od = new BasicProtein( "od", "varanus", 0 );
1429             od.addProteinDomain( only );
1430             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1431             if ( od.getNumberOfProteinDomains() != 1 ) {
1432                 return false;
1433             }
1434             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1435                 return false;
1436             }
1437         }
1438         catch ( final Exception e ) {
1439             e.printStackTrace( System.out );
1440             return false;
1441         }
1442         return true;
1443     }
1444
1445     public static final boolean testPfamTreeReading() {
1446         try {
1447             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1448             final NHXParser parser = new NHXParser();
1449             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1450             parser.setReplaceUnderscores( false );
1451             parser.setGuessRootedness( true );
1452             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1453             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1454             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1455                 return false;
1456             }
1457             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1458                 return false;
1459             }
1460         }
1461         catch ( final Exception e ) {
1462             e.printStackTrace();
1463         }
1464         return true;
1465     }
1466
1467     public static final boolean testPhyloXMLparsingFromURL() {
1468         try {
1469             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1470             final URL u = new URL( s );
1471             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1472             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1473             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1474                 return false;
1475             }
1476         }
1477         catch ( final Exception e ) {
1478             e.printStackTrace();
1479         }
1480         return true;
1481     }
1482
1483     public static final boolean testToLReading() {
1484         try {
1485             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1486             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1487             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1488             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1489                 return false;
1490             }
1491             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1492                 return false;
1493             }
1494             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1495                 return false;
1496             }
1497             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1498                 return false;
1499             }
1500         }
1501         catch ( final Exception e ) {
1502             e.printStackTrace();
1503         }
1504         return true;
1505     }
1506
1507     public static final boolean testTreeBaseReading() {
1508         try {
1509             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1510             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1511             parser.setReplaceUnderscores( true );
1512             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1513             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1514             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1515                 return false;
1516             }
1517             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1518             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1519             parser2.setReplaceUnderscores( true );
1520             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1521             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1522             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1523                 return false;
1524             }
1525         }
1526         catch ( final Exception e ) {
1527             e.printStackTrace();
1528         }
1529         return true;
1530     }
1531
1532     public static final boolean testTreeFamReading() {
1533         try {
1534             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1535             final NHXParser parser = new NHXParser();
1536             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1537             parser.setReplaceUnderscores( false );
1538             parser.setGuessRootedness( true );
1539             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1540             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1541             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1542                 return false;
1543             }
1544             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1545                 return false;
1546             }
1547         }
1548         catch ( final Exception e ) {
1549             e.printStackTrace();
1550         }
1551         return true;
1552     }
1553
1554     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1555         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1556         return p;
1557     }
1558
1559     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1560         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1561     }
1562
1563     private static boolean testAminoAcidSequence() {
1564         try {
1565             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1566             if ( aa1.getLength() != 13 ) {
1567                 return false;
1568             }
1569             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1570                 return false;
1571             }
1572             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1573                 return false;
1574             }
1575             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1576                 return false;
1577             }
1578             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1579             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1580                 return false;
1581             }
1582             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1583             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1584                 return false;
1585             }
1586             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1587             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1588                 return false;
1589             }
1590         }
1591         catch ( final Exception e ) {
1592             e.printStackTrace();
1593             return false;
1594         }
1595         return true;
1596     }
1597
1598     private static boolean testBasicDomain() {
1599         try {
1600             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1601             if ( !pd.getDomainId().equals( "id" ) ) {
1602                 return false;
1603             }
1604             if ( pd.getNumber() != 1 ) {
1605                 return false;
1606             }
1607             if ( pd.getTotalCount() != 4 ) {
1608                 return false;
1609             }
1610             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1611                 return false;
1612             }
1613             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1614             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1615             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1616             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1617             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1618             if ( !a1.equals( a1 ) ) {
1619                 return false;
1620             }
1621             if ( !a1.equals( a1_copy ) ) {
1622                 return false;
1623             }
1624             if ( !a1.equals( a1_equal ) ) {
1625                 return false;
1626             }
1627             if ( !a1.equals( a2 ) ) {
1628                 return false;
1629             }
1630             if ( a1.equals( a3 ) ) {
1631                 return false;
1632             }
1633             if ( a1.compareTo( a1 ) != 0 ) {
1634                 return false;
1635             }
1636             if ( a1.compareTo( a1_copy ) != 0 ) {
1637                 return false;
1638             }
1639             if ( a1.compareTo( a1_equal ) != 0 ) {
1640                 return false;
1641             }
1642             if ( a1.compareTo( a2 ) != 0 ) {
1643                 return false;
1644             }
1645             if ( a1.compareTo( a3 ) == 0 ) {
1646                 return false;
1647             }
1648         }
1649         catch ( final Exception e ) {
1650             e.printStackTrace( System.out );
1651             return false;
1652         }
1653         return true;
1654     }
1655
1656     private static boolean testBasicNodeMethods() {
1657         try {
1658             if ( PhylogenyNode.getNodeCount() != 0 ) {
1659                 return false;
1660             }
1661             final PhylogenyNode n1 = new PhylogenyNode();
1662             final PhylogenyNode n2 = PhylogenyNode
1663                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1664             final PhylogenyNode n3 = PhylogenyNode
1665                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1666             final PhylogenyNode n4 = PhylogenyNode
1667                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1668             if ( n1.isHasAssignedEvent() ) {
1669                 return false;
1670             }
1671             if ( PhylogenyNode.getNodeCount() != 4 ) {
1672                 return false;
1673             }
1674             if ( n3.getIndicator() != 0 ) {
1675                 return false;
1676             }
1677             if ( n3.getNumberOfExternalNodes() != 1 ) {
1678                 return false;
1679             }
1680             if ( !n3.isExternal() ) {
1681                 return false;
1682             }
1683             if ( !n3.isRoot() ) {
1684                 return false;
1685             }
1686             if ( !n4.getName().equals( "n4" ) ) {
1687                 return false;
1688             }
1689         }
1690         catch ( final Exception e ) {
1691             e.printStackTrace( System.out );
1692             return false;
1693         }
1694         return true;
1695     }
1696
1697     private static boolean testBasicPhyloXMLparsing() {
1698         try {
1699             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1700             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1701             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1702                                                               xml_parser );
1703             if ( xml_parser.getErrorCount() > 0 ) {
1704                 System.out.println( xml_parser.getErrorMessages().toString() );
1705                 return false;
1706             }
1707             if ( phylogenies_0.length != 4 ) {
1708                 return false;
1709             }
1710             final Phylogeny t1 = phylogenies_0[ 0 ];
1711             final Phylogeny t2 = phylogenies_0[ 1 ];
1712             final Phylogeny t3 = phylogenies_0[ 2 ];
1713             final Phylogeny t4 = phylogenies_0[ 3 ];
1714             if ( t1.getNumberOfExternalNodes() != 1 ) {
1715                 return false;
1716             }
1717             if ( !t1.isRooted() ) {
1718                 return false;
1719             }
1720             if ( t1.isRerootable() ) {
1721                 return false;
1722             }
1723             if ( !t1.getType().equals( "gene_tree" ) ) {
1724                 return false;
1725             }
1726             if ( t2.getNumberOfExternalNodes() != 2 ) {
1727                 return false;
1728             }
1729             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1730                 return false;
1731             }
1732             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1733                 return false;
1734             }
1735             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1736                 return false;
1737             }
1738             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1739                 return false;
1740             }
1741             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1742                 return false;
1743             }
1744             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1745                 return false;
1746             }
1747             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1748                     .startsWith( "actgtgggggt" ) ) {
1749                 return false;
1750             }
1751             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1752                     .startsWith( "ctgtgatgcat" ) ) {
1753                 return false;
1754             }
1755             if ( t3.getNumberOfExternalNodes() != 4 ) {
1756                 return false;
1757             }
1758             if ( !t1.getName().equals( "t1" ) ) {
1759                 return false;
1760             }
1761             if ( !t2.getName().equals( "t2" ) ) {
1762                 return false;
1763             }
1764             if ( !t3.getName().equals( "t3" ) ) {
1765                 return false;
1766             }
1767             if ( !t4.getName().equals( "t4" ) ) {
1768                 return false;
1769             }
1770             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1771                 return false;
1772             }
1773             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1774                 return false;
1775             }
1776             if ( !t3.getNode( "root node" ).isDuplication() ) {
1777                 return false;
1778             }
1779             if ( !t3.getNode( "node a" ).isDuplication() ) {
1780                 return false;
1781             }
1782             if ( t3.getNode( "node a" ).isSpeciation() ) {
1783                 return false;
1784             }
1785             if ( t3.getNode( "node bc" ).isDuplication() ) {
1786                 return false;
1787             }
1788             if ( !t3.getNode( "node bc" ).isSpeciation() ) {
1789                 return false;
1790             }
1791             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1792                 return false;
1793             }
1794             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1795                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1796                 return false;
1797             }
1798             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1799                 return false;
1800             }
1801             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1802                 return false;
1803             }
1804             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1805                 return false;
1806             }
1807             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1808                     .equals( "apoptosis" ) ) {
1809                 return false;
1810             }
1811             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1812                     .equals( "GO:0006915" ) ) {
1813                 return false;
1814             }
1815             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1816                     .equals( "UniProtKB" ) ) {
1817                 return false;
1818             }
1819             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1820                     .equals( "experimental" ) ) {
1821                 return false;
1822             }
1823             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1824                     .equals( "function" ) ) {
1825                 return false;
1826             }
1827             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1828                     .getValue() != 1 ) {
1829                 return false;
1830             }
1831             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1832                     .getType().equals( "ml" ) ) {
1833                 return false;
1834             }
1835             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1836                     .equals( "apoptosis" ) ) {
1837                 return false;
1838             }
1839             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1840                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1841                 return false;
1842             }
1843             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1844                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1845                 return false;
1846             }
1847             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1848                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1849                 return false;
1850             }
1851             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1852                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1853                 return false;
1854             }
1855             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1856                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1857                 return false;
1858             }
1859             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1860                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1861                 return false;
1862             }
1863             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1864                     .equals( "GO:0005829" ) ) {
1865                 return false;
1866             }
1867             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1868                     .equals( "intracellular organelle" ) ) {
1869                 return false;
1870             }
1871             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1872                 return false;
1873             }
1874             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1875                     .equals( "UniProt link" ) ) ) {
1876                 return false;
1877             }
1878             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1879                 return false;
1880             }
1881             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1882             if ( x.size() != 4 ) {
1883                 return false;
1884             }
1885             int c = 0;
1886             for( final Accession acc : x ) {
1887                 if ( c == 0 ) {
1888                     if ( !acc.getSource().equals( "KEGG" ) ) {
1889                         return false;
1890                     }
1891                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1892                         return false;
1893                     }
1894                 }
1895                 c++;
1896             }
1897         }
1898         catch ( final Exception e ) {
1899             e.printStackTrace( System.out );
1900             return false;
1901         }
1902         return true;
1903     }
1904
1905     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1906         try {
1907             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1908             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1909             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1910                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1911             }
1912             else {
1913                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1914             }
1915             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1916                                                               xml_parser );
1917             if ( xml_parser.getErrorCount() > 0 ) {
1918                 System.out.println( xml_parser.getErrorMessages().toString() );
1919                 return false;
1920             }
1921             if ( phylogenies_0.length != 4 ) {
1922                 return false;
1923             }
1924             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1925             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1926             if ( phylogenies_t1.length != 1 ) {
1927                 return false;
1928             }
1929             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1930             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1931                 return false;
1932             }
1933             if ( !t1_rt.isRooted() ) {
1934                 return false;
1935             }
1936             if ( t1_rt.isRerootable() ) {
1937                 return false;
1938             }
1939             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1940                 return false;
1941             }
1942             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1943             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1944             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1945             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1946                 return false;
1947             }
1948             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1949                 return false;
1950             }
1951             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1952                 return false;
1953             }
1954             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1955                 return false;
1956             }
1957             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1958                     .startsWith( "actgtgggggt" ) ) {
1959                 return false;
1960             }
1961             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1962                     .startsWith( "ctgtgatgcat" ) ) {
1963                 return false;
1964             }
1965             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1966             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1967             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1968             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1969             if ( phylogenies_1.length != 1 ) {
1970                 return false;
1971             }
1972             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1973             if ( !t3_rt.getName().equals( "t3" ) ) {
1974                 return false;
1975             }
1976             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1977                 return false;
1978             }
1979             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1980                 return false;
1981             }
1982             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1983                 return false;
1984             }
1985             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1986                 return false;
1987             }
1988             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1989                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1990                 return false;
1991             }
1992             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1993                 return false;
1994             }
1995             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1996                 return false;
1997             }
1998             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1999                     .equals( "UniProtKB" ) ) {
2000                 return false;
2001             }
2002             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2003                     .equals( "apoptosis" ) ) {
2004                 return false;
2005             }
2006             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2007                     .equals( "GO:0006915" ) ) {
2008                 return false;
2009             }
2010             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2011                     .equals( "UniProtKB" ) ) {
2012                 return false;
2013             }
2014             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2015                     .equals( "experimental" ) ) {
2016                 return false;
2017             }
2018             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2019                     .equals( "function" ) ) {
2020                 return false;
2021             }
2022             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2023                     .getValue() != 1 ) {
2024                 return false;
2025             }
2026             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2027                     .getType().equals( "ml" ) ) {
2028                 return false;
2029             }
2030             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2031                     .equals( "apoptosis" ) ) {
2032                 return false;
2033             }
2034             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2035                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2036                 return false;
2037             }
2038             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2039                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2040                 return false;
2041             }
2042             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2043                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2044                 return false;
2045             }
2046             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2047                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2048                 return false;
2049             }
2050             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2051                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2052                 return false;
2053             }
2054             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2055                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2056                 return false;
2057             }
2058             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2059                     .equals( "GO:0005829" ) ) {
2060                 return false;
2061             }
2062             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2063                     .equals( "intracellular organelle" ) ) {
2064                 return false;
2065             }
2066             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2067                 return false;
2068             }
2069             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2070                     .equals( "UniProt link" ) ) ) {
2071                 return false;
2072             }
2073             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2074                 return false;
2075             }
2076             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
2077                 return false;
2078             }
2079             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2080                     .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." ) ) ) {
2081                 return false;
2082             }
2083             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2084                 return false;
2085             }
2086             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2087                 return false;
2088             }
2089             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
2090                 return false;
2091             }
2092             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2093                 return false;
2094             }
2095             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2096                     .equals( "ncbi" ) ) {
2097                 return false;
2098             }
2099             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2100                 return false;
2101             }
2102             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2103                     .getName().equals( "B" ) ) {
2104                 return false;
2105             }
2106             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2107                     .getFrom() != 21 ) {
2108                 return false;
2109             }
2110             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2111                 return false;
2112             }
2113             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2114                     .getLength() != 24 ) {
2115                 return false;
2116             }
2117             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2118                     .getConfidence() != 0 ) {
2119                 return false;
2120             }
2121             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2122                     .equals( "pfam" ) ) {
2123                 return false;
2124             }
2125             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2126                 return false;
2127             }
2128             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2129                 return false;
2130             }
2131             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2132                 return false;
2133             }
2134             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2135                 return false;
2136             }
2137             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2138             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2139                 return false;
2140             }
2141             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2142                 return false;
2143             }
2144             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2145                 return false;
2146             }
2147             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2148                 return false;
2149             }
2150             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2151                 return false;
2152             }
2153             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2154                 return false;
2155             }
2156             if ( taxbb.getSynonyms().size() != 2 ) {
2157                 return false;
2158             }
2159             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2160                 return false;
2161             }
2162             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2163                 return false;
2164             }
2165             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2166                 return false;
2167             }
2168             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2169                 return false;
2170             }
2171             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2172                 return false;
2173             }
2174             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2175                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2176                 return false;
2177             }
2178             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2179                 return false;
2180             }
2181             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2182                 return false;
2183             }
2184             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2185                 return false;
2186             }
2187             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2188                 return false;
2189             }
2190             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2191                 return false;
2192             }
2193             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2194                 return false;
2195             }
2196             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2197                 return false;
2198             }
2199             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2200                 return false;
2201             }
2202             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2203                     .equalsIgnoreCase( "435" ) ) {
2204                 return false;
2205             }
2206             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2207                 return false;
2208             }
2209             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2210                     .equalsIgnoreCase( "443.7" ) ) {
2211                 return false;
2212             }
2213             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2214                 return false;
2215             }
2216             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2217                 return false;
2218             }
2219             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2220                     .equalsIgnoreCase( "433" ) ) {
2221                 return false;
2222             }
2223             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2224                     .getCrossReferences();
2225             if ( x.size() != 4 ) {
2226                 return false;
2227             }
2228             int c = 0;
2229             for( final Accession acc : x ) {
2230                 if ( c == 0 ) {
2231                     if ( !acc.getSource().equals( "KEGG" ) ) {
2232                         return false;
2233                     }
2234                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2235                         return false;
2236                     }
2237                 }
2238                 c++;
2239             }
2240         }
2241         catch ( final Exception e ) {
2242             e.printStackTrace( System.out );
2243             return false;
2244         }
2245         return true;
2246     }
2247
2248     private static boolean testBasicPhyloXMLparsingValidating() {
2249         try {
2250             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2251             PhyloXmlParser xml_parser = null;
2252             try {
2253                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2254             }
2255             catch ( final Exception e ) {
2256                 // Do nothing -- means were not running from jar.
2257             }
2258             if ( xml_parser == null ) {
2259                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2260                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2261                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2262                 }
2263                 else {
2264                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2265                 }
2266             }
2267             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2268                                                               xml_parser );
2269             if ( xml_parser.getErrorCount() > 0 ) {
2270                 System.out.println( xml_parser.getErrorMessages().toString() );
2271                 return false;
2272             }
2273             if ( phylogenies_0.length != 4 ) {
2274                 return false;
2275             }
2276             final Phylogeny t1 = phylogenies_0[ 0 ];
2277             final Phylogeny t2 = phylogenies_0[ 1 ];
2278             final Phylogeny t3 = phylogenies_0[ 2 ];
2279             final Phylogeny t4 = phylogenies_0[ 3 ];
2280             if ( !t1.getName().equals( "t1" ) ) {
2281                 return false;
2282             }
2283             if ( !t2.getName().equals( "t2" ) ) {
2284                 return false;
2285             }
2286             if ( !t3.getName().equals( "t3" ) ) {
2287                 return false;
2288             }
2289             if ( !t4.getName().equals( "t4" ) ) {
2290                 return false;
2291             }
2292             if ( t1.getNumberOfExternalNodes() != 1 ) {
2293                 return false;
2294             }
2295             if ( t2.getNumberOfExternalNodes() != 2 ) {
2296                 return false;
2297             }
2298             if ( t3.getNumberOfExternalNodes() != 4 ) {
2299                 return false;
2300             }
2301             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2302             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2303             if ( xml_parser.getErrorCount() > 0 ) {
2304                 System.out.println( "errors:" );
2305                 System.out.println( xml_parser.getErrorMessages().toString() );
2306                 return false;
2307             }
2308             if ( phylogenies_1.length != 4 ) {
2309                 return false;
2310             }
2311             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2312                                                               xml_parser );
2313             if ( xml_parser.getErrorCount() > 0 ) {
2314                 System.out.println( "errors:" );
2315                 System.out.println( xml_parser.getErrorMessages().toString() );
2316                 return false;
2317             }
2318             if ( phylogenies_2.length != 1 ) {
2319                 return false;
2320             }
2321             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2322                 return false;
2323             }
2324             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2325                                                               xml_parser );
2326             if ( xml_parser.getErrorCount() > 0 ) {
2327                 System.out.println( xml_parser.getErrorMessages().toString() );
2328                 return false;
2329             }
2330             if ( phylogenies_3.length != 2 ) {
2331                 return false;
2332             }
2333             final Phylogeny a = phylogenies_3[ 0 ];
2334             if ( !a.getName().equals( "tree 4" ) ) {
2335                 return false;
2336             }
2337             if ( a.getNumberOfExternalNodes() != 3 ) {
2338                 return false;
2339             }
2340             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2341                 return false;
2342             }
2343             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2344                 return false;
2345             }
2346             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2347                                                               xml_parser );
2348             if ( xml_parser.getErrorCount() > 0 ) {
2349                 System.out.println( xml_parser.getErrorMessages().toString() );
2350                 return false;
2351             }
2352             if ( phylogenies_4.length != 1 ) {
2353                 return false;
2354             }
2355             final Phylogeny s = phylogenies_4[ 0 ];
2356             if ( s.getNumberOfExternalNodes() != 6 ) {
2357                 return false;
2358             }
2359             s.getNode( "first" );
2360             s.getNode( "<>" );
2361             s.getNode( "\"<a'b&c'd\">\"" );
2362             s.getNode( "'''\"" );
2363             s.getNode( "\"\"\"" );
2364             s.getNode( "dick & doof" );
2365         }
2366         catch ( final Exception e ) {
2367             e.printStackTrace( System.out );
2368             return false;
2369         }
2370         return true;
2371     }
2372
2373     private static boolean testBasicProtein() {
2374         try {
2375             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2376             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2377             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2378             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2379             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2380             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2381             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2382             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2383             p0.addProteinDomain( y );
2384             p0.addProteinDomain( e );
2385             p0.addProteinDomain( b );
2386             p0.addProteinDomain( c );
2387             p0.addProteinDomain( d );
2388             p0.addProteinDomain( a );
2389             p0.addProteinDomain( x );
2390             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2391                 return false;
2392             }
2393             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2394                 return false;
2395             }
2396             //
2397             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2398             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2399             aa0.addProteinDomain( a1 );
2400             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2401                 return false;
2402             }
2403             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2404                 return false;
2405             }
2406             //
2407             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2408             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2409             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2410             aa1.addProteinDomain( a11 );
2411             aa1.addProteinDomain( a12 );
2412             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2413                 return false;
2414             }
2415             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2416                 return false;
2417             }
2418             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2419             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2420                 return false;
2421             }
2422             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2423                 return false;
2424             }
2425             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2426                 return false;
2427             }
2428             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2429             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2430                 return false;
2431             }
2432             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2433                 return false;
2434             }
2435             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2436                 return false;
2437             }
2438             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2439                 return false;
2440             }
2441             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2442             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2443                 return false;
2444             }
2445             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2446                 return false;
2447             }
2448             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2449                 return false;
2450             }
2451             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2452                 return false;
2453             }
2454             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2455             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2456                 return false;
2457             }
2458             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2459                 return false;
2460             }
2461             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2462                 return false;
2463             }
2464             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2465                 return false;
2466             }
2467             //
2468             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2469             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2470             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2471             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2472             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2473             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2474             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2475             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2476             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2477             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2478             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2479             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2480             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2481             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2482             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2483             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2484             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2485             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2486             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2487             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2488             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2489             p00.addProteinDomain( y0 );
2490             p00.addProteinDomain( e0 );
2491             p00.addProteinDomain( b0 );
2492             p00.addProteinDomain( c0 );
2493             p00.addProteinDomain( d0 );
2494             p00.addProteinDomain( a0 );
2495             p00.addProteinDomain( x0 );
2496             p00.addProteinDomain( y1 );
2497             p00.addProteinDomain( y2 );
2498             p00.addProteinDomain( y3 );
2499             p00.addProteinDomain( e1 );
2500             p00.addProteinDomain( e2 );
2501             p00.addProteinDomain( e3 );
2502             p00.addProteinDomain( e4 );
2503             p00.addProteinDomain( e5 );
2504             p00.addProteinDomain( z0 );
2505             p00.addProteinDomain( z1 );
2506             p00.addProteinDomain( z2 );
2507             p00.addProteinDomain( zz0 );
2508             p00.addProteinDomain( zz1 );
2509             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2510                 return false;
2511             }
2512             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2513                 return false;
2514             }
2515             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2516                 return false;
2517             }
2518             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2519                 return false;
2520             }
2521             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" ) ) {
2522                 return false;
2523             }
2524             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2525             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2526             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2527             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2528             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2529             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2530             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2531             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2532             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2533             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2534             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2535             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2536             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2537             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2538             p.addProteinDomain( B15 );
2539             p.addProteinDomain( C50 );
2540             p.addProteinDomain( A60 );
2541             p.addProteinDomain( A30 );
2542             p.addProteinDomain( C70 );
2543             p.addProteinDomain( B35 );
2544             p.addProteinDomain( B40 );
2545             p.addProteinDomain( A0 );
2546             p.addProteinDomain( A10 );
2547             p.addProteinDomain( A20 );
2548             p.addProteinDomain( B25 );
2549             p.addProteinDomain( D80 );
2550             List<String> domains_ids = new ArrayList<String>();
2551             domains_ids.add( "A" );
2552             domains_ids.add( "B" );
2553             domains_ids.add( "C" );
2554             if ( !p.contains( domains_ids, false ) ) {
2555                 return false;
2556             }
2557             if ( !p.contains( domains_ids, true ) ) {
2558                 return false;
2559             }
2560             domains_ids.add( "X" );
2561             if ( p.contains( domains_ids, false ) ) {
2562                 return false;
2563             }
2564             if ( p.contains( domains_ids, true ) ) {
2565                 return false;
2566             }
2567             domains_ids = new ArrayList<String>();
2568             domains_ids.add( "A" );
2569             domains_ids.add( "C" );
2570             domains_ids.add( "D" );
2571             if ( !p.contains( domains_ids, false ) ) {
2572                 return false;
2573             }
2574             if ( !p.contains( domains_ids, true ) ) {
2575                 return false;
2576             }
2577             domains_ids = new ArrayList<String>();
2578             domains_ids.add( "A" );
2579             domains_ids.add( "D" );
2580             domains_ids.add( "C" );
2581             if ( !p.contains( domains_ids, false ) ) {
2582                 return false;
2583             }
2584             if ( p.contains( domains_ids, true ) ) {
2585                 return false;
2586             }
2587             domains_ids = new ArrayList<String>();
2588             domains_ids.add( "A" );
2589             domains_ids.add( "A" );
2590             domains_ids.add( "B" );
2591             if ( !p.contains( domains_ids, false ) ) {
2592                 return false;
2593             }
2594             if ( !p.contains( domains_ids, true ) ) {
2595                 return false;
2596             }
2597             domains_ids = new ArrayList<String>();
2598             domains_ids.add( "A" );
2599             domains_ids.add( "A" );
2600             domains_ids.add( "A" );
2601             domains_ids.add( "B" );
2602             domains_ids.add( "B" );
2603             if ( !p.contains( domains_ids, false ) ) {
2604                 return false;
2605             }
2606             if ( !p.contains( domains_ids, true ) ) {
2607                 return false;
2608             }
2609             domains_ids = new ArrayList<String>();
2610             domains_ids.add( "A" );
2611             domains_ids.add( "A" );
2612             domains_ids.add( "B" );
2613             domains_ids.add( "A" );
2614             domains_ids.add( "B" );
2615             domains_ids.add( "B" );
2616             domains_ids.add( "A" );
2617             domains_ids.add( "B" );
2618             domains_ids.add( "C" );
2619             domains_ids.add( "A" );
2620             domains_ids.add( "C" );
2621             domains_ids.add( "D" );
2622             if ( !p.contains( domains_ids, false ) ) {
2623                 return false;
2624             }
2625             if ( p.contains( domains_ids, true ) ) {
2626                 return false;
2627             }
2628         }
2629         catch ( final Exception e ) {
2630             e.printStackTrace( System.out );
2631             return false;
2632         }
2633         return true;
2634     }
2635
2636     private static boolean testBasicTable() {
2637         try {
2638             final BasicTable<String> t0 = new BasicTable<String>();
2639             if ( t0.getNumberOfColumns() != 0 ) {
2640                 return false;
2641             }
2642             if ( t0.getNumberOfRows() != 0 ) {
2643                 return false;
2644             }
2645             t0.setValue( 3, 2, "23" );
2646             t0.setValue( 10, 1, "error" );
2647             t0.setValue( 10, 1, "110" );
2648             t0.setValue( 9, 1, "19" );
2649             t0.setValue( 1, 10, "101" );
2650             t0.setValue( 10, 10, "1010" );
2651             t0.setValue( 100, 10, "10100" );
2652             t0.setValue( 0, 0, "00" );
2653             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2654                 return false;
2655             }
2656             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2657                 return false;
2658             }
2659             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2660                 return false;
2661             }
2662             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2663                 return false;
2664             }
2665             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2666                 return false;
2667             }
2668             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2669                 return false;
2670             }
2671             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2672                 return false;
2673             }
2674             if ( t0.getNumberOfColumns() != 101 ) {
2675                 return false;
2676             }
2677             if ( t0.getNumberOfRows() != 11 ) {
2678                 return false;
2679             }
2680             if ( t0.getValueAsString( 49, 4 ) != null ) {
2681                 return false;
2682             }
2683             final String l = ForesterUtil.getLineSeparator();
2684             final StringBuffer source = new StringBuffer();
2685             source.append( "" + l );
2686             source.append( "# 1 1 1 1 1 1 1 1" + l );
2687             source.append( " 00 01 02 03" + l );
2688             source.append( "   10 11 12 13  " + l );
2689             source.append( "20 21 22 23 " + l );
2690             source.append( "    30  31    32 33" + l );
2691             source.append( "40 41 42 43" + l );
2692             source.append( "  # 1 1 1 1 1 " + l );
2693             source.append( "50 51 52 53 54" + l );
2694             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2695             if ( t1.getNumberOfColumns() != 5 ) {
2696                 return false;
2697             }
2698             if ( t1.getNumberOfRows() != 6 ) {
2699                 return false;
2700             }
2701             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2702                 return false;
2703             }
2704             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2705                 return false;
2706             }
2707             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2708                 return false;
2709             }
2710             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2711                 return false;
2712             }
2713             final StringBuffer source1 = new StringBuffer();
2714             source1.append( "" + l );
2715             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2716             source1.append( " 00; 01 ;02;03" + l );
2717             source1.append( "   10; 11; 12; 13  " + l );
2718             source1.append( "20; 21; 22; 23 " + l );
2719             source1.append( "    30;  31;    32; 33" + l );
2720             source1.append( "40;41;42;43" + l );
2721             source1.append( "  # 1 1 1 1 1 " + l );
2722             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2723             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2724             if ( t2.getNumberOfColumns() != 5 ) {
2725                 return false;
2726             }
2727             if ( t2.getNumberOfRows() != 6 ) {
2728                 return false;
2729             }
2730             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2731                 return false;
2732             }
2733             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2734                 return false;
2735             }
2736             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2737                 return false;
2738             }
2739             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2740                 return false;
2741             }
2742             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2743                 return false;
2744             }
2745             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2746                 return false;
2747             }
2748             final StringBuffer source2 = new StringBuffer();
2749             source2.append( "" + l );
2750             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2751             source2.append( " 00; 01 ;02;03" + l );
2752             source2.append( "   10; 11; 12; 13  " + l );
2753             source2.append( "20; 21; 22; 23 " + l );
2754             source2.append( "                     " + l );
2755             source2.append( "    30;  31;    32; 33" + l );
2756             source2.append( "40;41;42;43" + l );
2757             source2.append( "  comment: 1 1 1 1 1 " + l );
2758             source2.append( ";;;50  ;   52; 53;;54   " + l );
2759             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2760                                                                         ';',
2761                                                                         false,
2762                                                                         false,
2763                                                                         "comment:",
2764                                                                         false );
2765             if ( tl.size() != 2 ) {
2766                 return false;
2767             }
2768             final BasicTable<String> t3 = tl.get( 0 );
2769             final BasicTable<String> t4 = tl.get( 1 );
2770             if ( t3.getNumberOfColumns() != 4 ) {
2771                 return false;
2772             }
2773             if ( t3.getNumberOfRows() != 3 ) {
2774                 return false;
2775             }
2776             if ( t4.getNumberOfColumns() != 4 ) {
2777                 return false;
2778             }
2779             if ( t4.getNumberOfRows() != 3 ) {
2780                 return false;
2781             }
2782             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2783                 return false;
2784             }
2785             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2786                 return false;
2787             }
2788         }
2789         catch ( final Exception e ) {
2790             e.printStackTrace( System.out );
2791             return false;
2792         }
2793         return true;
2794     }
2795
2796     private static boolean testBasicTolXMLparsing() {
2797         try {
2798             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2799             final TolParser parser = new TolParser();
2800             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2801             if ( parser.getErrorCount() > 0 ) {
2802                 System.out.println( parser.getErrorMessages().toString() );
2803                 return false;
2804             }
2805             if ( phylogenies_0.length != 1 ) {
2806                 return false;
2807             }
2808             final Phylogeny t1 = phylogenies_0[ 0 ];
2809             if ( t1.getNumberOfExternalNodes() != 5 ) {
2810                 return false;
2811             }
2812             if ( !t1.isRooted() ) {
2813                 return false;
2814             }
2815             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2816                 return false;
2817             }
2818             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2819                 return false;
2820             }
2821             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2822                 return false;
2823             }
2824             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2825                 return false;
2826             }
2827             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2828             if ( parser.getErrorCount() > 0 ) {
2829                 System.out.println( parser.getErrorMessages().toString() );
2830                 return false;
2831             }
2832             if ( phylogenies_1.length != 1 ) {
2833                 return false;
2834             }
2835             final Phylogeny t2 = phylogenies_1[ 0 ];
2836             if ( t2.getNumberOfExternalNodes() != 664 ) {
2837                 return false;
2838             }
2839             if ( !t2.isRooted() ) {
2840                 return false;
2841             }
2842             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2843                 return false;
2844             }
2845             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2846                 return false;
2847             }
2848             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2849                 return false;
2850             }
2851             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2852                 return false;
2853             }
2854             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2855                 return false;
2856             }
2857             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2858                     .equals( "Aquifex" ) ) {
2859                 return false;
2860             }
2861             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2862             if ( parser.getErrorCount() > 0 ) {
2863                 System.out.println( parser.getErrorMessages().toString() );
2864                 return false;
2865             }
2866             if ( phylogenies_2.length != 1 ) {
2867                 return false;
2868             }
2869             final Phylogeny t3 = phylogenies_2[ 0 ];
2870             if ( t3.getNumberOfExternalNodes() != 184 ) {
2871                 return false;
2872             }
2873             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2874                 return false;
2875             }
2876             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2877                 return false;
2878             }
2879             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2880                 return false;
2881             }
2882             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2883             if ( parser.getErrorCount() > 0 ) {
2884                 System.out.println( parser.getErrorMessages().toString() );
2885                 return false;
2886             }
2887             if ( phylogenies_3.length != 1 ) {
2888                 return false;
2889             }
2890             final Phylogeny t4 = phylogenies_3[ 0 ];
2891             if ( t4.getNumberOfExternalNodes() != 1 ) {
2892                 return false;
2893             }
2894             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2895                 return false;
2896             }
2897             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2898                 return false;
2899             }
2900             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2901                 return false;
2902             }
2903             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2904             if ( parser.getErrorCount() > 0 ) {
2905                 System.out.println( parser.getErrorMessages().toString() );
2906                 return false;
2907             }
2908             if ( phylogenies_4.length != 1 ) {
2909                 return false;
2910             }
2911             final Phylogeny t5 = phylogenies_4[ 0 ];
2912             if ( t5.getNumberOfExternalNodes() != 13 ) {
2913                 return false;
2914             }
2915             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2916                 return false;
2917             }
2918             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2919                 return false;
2920             }
2921             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2922                 return false;
2923             }
2924         }
2925         catch ( final Exception e ) {
2926             e.printStackTrace( System.out );
2927             return false;
2928         }
2929         return true;
2930     }
2931
2932     private static boolean testBasicTreeMethods() {
2933         try {
2934             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2935             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2936             if ( t2.getNumberOfExternalNodes() != 4 ) {
2937                 return false;
2938             }
2939             if ( t2.getHeight() != 8.5 ) {
2940                 return false;
2941             }
2942             if ( !t2.isCompletelyBinary() ) {
2943                 return false;
2944             }
2945             if ( t2.isEmpty() ) {
2946                 return false;
2947             }
2948             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2949             if ( t3.getNumberOfExternalNodes() != 5 ) {
2950                 return false;
2951             }
2952             if ( t3.getHeight() != 11 ) {
2953                 return false;
2954             }
2955             if ( t3.isCompletelyBinary() ) {
2956                 return false;
2957             }
2958             final PhylogenyNode n = t3.getNode( "ABC" );
2959             final Phylogeny t4 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3,(F,G,H,I))", new NHXParser() )[ 0 ];
2960             if ( t4.getNumberOfExternalNodes() != 9 ) {
2961                 return false;
2962             }
2963             if ( t4.getHeight() != 11 ) {
2964                 return false;
2965             }
2966             if ( t4.isCompletelyBinary() ) {
2967                 return false;
2968             }
2969             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)" );
2970             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2971             if ( t5.getNumberOfExternalNodes() != 8 ) {
2972                 return false;
2973             }
2974             if ( t5.getHeight() != 15 ) {
2975                 return false;
2976             }
2977             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)" );
2978             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2979             if ( t6.getHeight() != 15 ) {
2980                 return false;
2981             }
2982             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)" );
2983             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2984             if ( t7.getHeight() != 15 ) {
2985                 return false;
2986             }
2987             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)" );
2988             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2989             if ( t8.getNumberOfExternalNodes() != 10 ) {
2990                 return false;
2991             }
2992             if ( t8.getHeight() != 15 ) {
2993                 return false;
2994             }
2995             final char[] a9 = new char[] { 'a' };
2996             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2997             if ( t9.getHeight() != 0 ) {
2998                 return false;
2999             }
3000             final char[] a10 = new char[] { 'a', ':', '6' };
3001             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
3002             if ( t10.getHeight() != 6 ) {
3003                 return false;
3004             }
3005         }
3006         catch ( final Exception e ) {
3007             e.printStackTrace( System.out );
3008             return false;
3009         }
3010         return true;
3011     }
3012
3013     private static boolean testConfidenceAssessor() {
3014         try {
3015             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3016             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3017             final Phylogeny[] ev0 = factory
3018                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3019                              new NHXParser() );
3020             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3021             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3022                 return false;
3023             }
3024             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3025                 return false;
3026             }
3027             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3028             final Phylogeny[] ev1 = factory
3029                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));",
3030                              new NHXParser() );
3031             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3032             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3033                 return false;
3034             }
3035             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3036                 return false;
3037             }
3038             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3039             final Phylogeny[] ev_b = factory
3040                     .create( "((A,C),X);((A,X),C);(A,C);((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));((((A,C)ac,D)acd,E)acde,B)abcd",
3041                              new NHXParser() );
3042             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3043             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3044                 return false;
3045             }
3046             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3047                 return false;
3048             }
3049             //
3050             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3051             final Phylogeny[] ev1x = factory
3052                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));",
3053                              new NHXParser() );
3054             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3055             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3056                 return false;
3057             }
3058             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3059                 return false;
3060             }
3061             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3062             final Phylogeny[] ev_bx = factory
3063                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));((((A,C)ac,D)acd,E)acde,B)abcd",
3064                              new NHXParser() );
3065             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3066             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3067                 return false;
3068             }
3069             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3070                 return false;
3071             }
3072             final Phylogeny[] t2 = factory
3073                     .create( "((((a,b),c),d),e);(((a,b),c),(d,e));(((((a,b),c),d),e),f);((((a,b),c),(d,e)),f);(((a,b),c),d,e);((a,b,c),d,e);",
3074                              new NHXParser() );
3075             final Phylogeny[] ev2 = factory
3076                     .create( "((((a,b),c),d),e);((((a,b),c),d),e);((((a,b),e),d),c);((((a,b),e),d),c);(((a,b),(c,d)),e);((a,b),x);((a,b),(x,y));(a,b);(a,e);(a,b,c);",
3077                              new NHXParser() );
3078             for( final Phylogeny target : t2 ) {
3079                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3080             }
3081             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3082                                                  new NHXParser() )[ 0 ];
3083             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3084             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3085             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3086                 return false;
3087             }
3088             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3089                 return false;
3090             }
3091             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3092                 return false;
3093             }
3094         }
3095         catch ( final Exception e ) {
3096             e.printStackTrace();
3097             return false;
3098         }
3099         return true;
3100     }
3101
3102     private static boolean testCopyOfNodeData() {
3103         try {
3104             final PhylogenyNode n1 = PhylogenyNode
3105                     .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]" );
3106             final PhylogenyNode n2 = n1.copyNodeData();
3107             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3108                 return false;
3109             }
3110         }
3111         catch ( final Exception e ) {
3112             e.printStackTrace();
3113             return false;
3114         }
3115         return true;
3116     }
3117
3118     private static boolean testCreateBalancedPhylogeny() {
3119         try {
3120             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3121             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3122                 return false;
3123             }
3124             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3125                 return false;
3126             }
3127             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3128             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3129                 return false;
3130             }
3131             if ( p1.getNumberOfExternalNodes() != 100 ) {
3132                 return false;
3133             }
3134         }
3135         catch ( final Exception e ) {
3136             e.printStackTrace();
3137             return false;
3138         }
3139         return true;
3140     }
3141
3142     private static boolean testCreateUriForSeqWeb() {
3143         try {
3144             final PhylogenyNode n = new PhylogenyNode();
3145             n.setName( "tr|B3RJ64" );
3146             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3147                 return false;
3148             }
3149             n.setName( "B0LM41_HUMAN" );
3150             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3151                 return false;
3152             }
3153             n.setName( "NP_001025424" );
3154             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3155                 return false;
3156             }
3157             n.setName( "_NM_001030253-" );
3158             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3159                 return false;
3160             }
3161             n.setName( "XM_002122186" );
3162             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3163                 return false;
3164             }
3165             n.setName( "dgh_AAA34956_gdg" );
3166             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3167                 return false;
3168             }
3169             n.setName( "AAA34956" );
3170             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3171                 return false;
3172             }
3173             n.setName( "GI:394892" );
3174             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3175                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3176                 return false;
3177             }
3178             n.setName( "gi_394892" );
3179             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3180                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3181                 return false;
3182             }
3183             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3184             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3185                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3186                 return false;
3187             }
3188             n.setName( "P12345" );
3189             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3190                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3191                 return false;
3192             }
3193             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3194             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3195                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3196                 return false;
3197             }
3198         }
3199         catch ( final Exception e ) {
3200             e.printStackTrace( System.out );
3201             return false;
3202         }
3203         return true;
3204     }
3205
3206     private static boolean testDataObjects() {
3207         try {
3208             final Confidence s0 = new Confidence();
3209             final Confidence s1 = new Confidence();
3210             if ( !s0.isEqual( s1 ) ) {
3211                 return false;
3212             }
3213             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3214             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3215             if ( s2.isEqual( s1 ) ) {
3216                 return false;
3217             }
3218             if ( !s2.isEqual( s3 ) ) {
3219                 return false;
3220             }
3221             final Confidence s4 = ( Confidence ) s3.copy();
3222             if ( !s4.isEqual( s3 ) ) {
3223                 return false;
3224             }
3225             s3.asSimpleText();
3226             s3.asText();
3227             // Taxonomy
3228             // ----------
3229             final Taxonomy t1 = new Taxonomy();
3230             final Taxonomy t2 = new Taxonomy();
3231             final Taxonomy t3 = new Taxonomy();
3232             final Taxonomy t4 = new Taxonomy();
3233             final Taxonomy t5 = new Taxonomy();
3234             t1.setIdentifier( new Identifier( "ecoli" ) );
3235             t1.setTaxonomyCode( "ECOLI" );
3236             t1.setScientificName( "E. coli" );
3237             t1.setCommonName( "coli" );
3238             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3239             if ( !t1.isEqual( t0 ) ) {
3240                 return false;
3241             }
3242             t2.setIdentifier( new Identifier( "ecoli" ) );
3243             t2.setTaxonomyCode( "OTHER" );
3244             t2.setScientificName( "what" );
3245             t2.setCommonName( "something" );
3246             if ( !t1.isEqual( t2 ) ) {
3247                 return false;
3248             }
3249             t2.setIdentifier( new Identifier( "nemve" ) );
3250             if ( t1.isEqual( t2 ) ) {
3251                 return false;
3252             }
3253             t1.setIdentifier( null );
3254             t3.setTaxonomyCode( "ECOLI" );
3255             t3.setScientificName( "what" );
3256             t3.setCommonName( "something" );
3257             if ( !t1.isEqual( t3 ) ) {
3258                 return false;
3259             }
3260             t1.setIdentifier( null );
3261             t1.setTaxonomyCode( "" );
3262             t4.setScientificName( "E. ColI" );
3263             t4.setCommonName( "something" );
3264             if ( !t1.isEqual( t4 ) ) {
3265                 return false;
3266             }
3267             t4.setScientificName( "B. subtilis" );
3268             t4.setCommonName( "something" );
3269             if ( t1.isEqual( t4 ) ) {
3270                 return false;
3271             }
3272             t1.setIdentifier( null );
3273             t1.setTaxonomyCode( "" );
3274             t1.setScientificName( "" );
3275             t5.setCommonName( "COLI" );
3276             if ( !t1.isEqual( t5 ) ) {
3277                 return false;
3278             }
3279             t5.setCommonName( "vibrio" );
3280             if ( t1.isEqual( t5 ) ) {
3281                 return false;
3282             }
3283             // Identifier
3284             // ----------
3285             final Identifier id0 = new Identifier( "123", "pfam" );
3286             final Identifier id1 = ( Identifier ) id0.copy();
3287             if ( !id1.isEqual( id1 ) ) {
3288                 return false;
3289             }
3290             if ( !id1.isEqual( id0 ) ) {
3291                 return false;
3292             }
3293             if ( !id0.isEqual( id1 ) ) {
3294                 return false;
3295             }
3296             id1.asSimpleText();
3297             id1.asText();
3298             // ProteinDomain
3299             // ---------------
3300             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3301             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3302             if ( !pd1.isEqual( pd1 ) ) {
3303                 return false;
3304             }
3305             if ( !pd1.isEqual( pd0 ) ) {
3306                 return false;
3307             }
3308             pd1.asSimpleText();
3309             pd1.asText();
3310             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3311             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3312             if ( !pd3.isEqual( pd3 ) ) {
3313                 return false;
3314             }
3315             if ( !pd2.isEqual( pd3 ) ) {
3316                 return false;
3317             }
3318             if ( !pd0.isEqual( pd3 ) ) {
3319                 return false;
3320             }
3321             pd3.asSimpleText();
3322             pd3.asText();
3323             // DomainArchitecture
3324             // ------------------
3325             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3326             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3327             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3328             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3329             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3330             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3331             domains0.add( d2 );
3332             domains0.add( d0 );
3333             domains0.add( d3 );
3334             domains0.add( d1 );
3335             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3336             if ( ds0.getNumberOfDomains() != 4 ) {
3337                 return false;
3338             }
3339             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3340             if ( !ds0.isEqual( ds0 ) ) {
3341                 return false;
3342             }
3343             if ( !ds0.isEqual( ds1 ) ) {
3344                 return false;
3345             }
3346             if ( ds1.getNumberOfDomains() != 4 ) {
3347                 return false;
3348             }
3349             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3350             domains1.add( d1 );
3351             domains1.add( d2 );
3352             domains1.add( d4 );
3353             domains1.add( d0 );
3354             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3355             if ( ds0.isEqual( ds2 ) ) {
3356                 return false;
3357             }
3358             ds1.asSimpleText();
3359             ds1.asText();
3360             ds1.toNHX();
3361             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3362             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3363                 System.out.println( ds3.toNHX() );
3364                 return false;
3365             }
3366             if ( ds3.getNumberOfDomains() != 3 ) {
3367                 return false;
3368             }
3369             // Event
3370             // -----
3371             final Event e1 = new Event( Event.EventType.fusion );
3372             if ( e1.isDuplication() ) {
3373                 return false;
3374             }
3375             if ( !e1.isFusion() ) {
3376                 return false;
3377             }
3378             if ( !e1.asText().toString().equals( "fusion" ) ) {
3379                 return false;
3380             }
3381             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3382                 return false;
3383             }
3384             final Event e11 = new Event( Event.EventType.fusion );
3385             if ( !e11.isEqual( e1 ) ) {
3386                 return false;
3387             }
3388             if ( !e11.toNHX().toString().equals( "" ) ) {
3389                 return false;
3390             }
3391             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3392             if ( e2.isDuplication() ) {
3393                 return false;
3394             }
3395             if ( !e2.isSpeciationOrDuplication() ) {
3396                 return false;
3397             }
3398             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3399                 return false;
3400             }
3401             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3402                 return false;
3403             }
3404             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3405                 return false;
3406             }
3407             if ( e11.isEqual( e2 ) ) {
3408                 return false;
3409             }
3410             final Event e2c = ( Event ) e2.copy();
3411             if ( !e2c.isEqual( e2 ) ) {
3412                 return false;
3413             }
3414             Event e3 = new Event( 1, 2, 3 );
3415             if ( e3.isDuplication() ) {
3416                 return false;
3417             }
3418             if ( e3.isSpeciation() ) {
3419                 return false;
3420             }
3421             if ( e3.isGeneLoss() ) {
3422                 return false;
3423             }
3424             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3425                 return false;
3426             }
3427             final Event e3c = ( Event ) e3.copy();
3428             final Event e3cc = ( Event ) e3c.copy();
3429             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3430                 return false;
3431             }
3432             e3 = null;
3433             if ( !e3c.isEqual( e3cc ) ) {
3434                 return false;
3435             }
3436             Event e4 = new Event( 1, 2, 3 );
3437             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3438                 return false;
3439             }
3440             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3441                 return false;
3442             }
3443             final Event e4c = ( Event ) e4.copy();
3444             e4 = null;
3445             final Event e4cc = ( Event ) e4c.copy();
3446             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3447                 return false;
3448             }
3449             if ( !e4c.isEqual( e4cc ) ) {
3450                 return false;
3451             }
3452             final Event e5 = new Event();
3453             if ( !e5.isUnassigned() ) {
3454                 return false;
3455             }
3456             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3457                 return false;
3458             }
3459             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3460                 return false;
3461             }
3462             final Event e6 = new Event( 1, 0, 0 );
3463             if ( !e6.asText().toString().equals( "duplication" ) ) {
3464                 return false;
3465             }
3466             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3467                 return false;
3468             }
3469             final Event e7 = new Event( 0, 1, 0 );
3470             if ( !e7.asText().toString().equals( "speciation" ) ) {
3471                 return false;
3472             }
3473             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3474                 return false;
3475             }
3476             final Event e8 = new Event( 0, 0, 1 );
3477             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3478                 return false;
3479             }
3480             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3481                 return false;
3482             }
3483         }
3484         catch ( final Exception e ) {
3485             e.printStackTrace( System.out );
3486             return false;
3487         }
3488         return true;
3489     }
3490
3491     private static boolean testDeletionOfExternalNodes() {
3492         try {
3493             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3494             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3495             final PhylogenyWriter w = new PhylogenyWriter();
3496             if ( t0.isEmpty() ) {
3497                 return false;
3498             }
3499             if ( t0.getNumberOfExternalNodes() != 1 ) {
3500                 return false;
3501             }
3502             t0.deleteSubtree( t0.getNode( "A" ), false );
3503             if ( t0.getNumberOfExternalNodes() != 0 ) {
3504                 return false;
3505             }
3506             if ( !t0.isEmpty() ) {
3507                 return false;
3508             }
3509             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3510             if ( t1.getNumberOfExternalNodes() != 2 ) {
3511                 return false;
3512             }
3513             t1.deleteSubtree( t1.getNode( "A" ), false );
3514             if ( t1.getNumberOfExternalNodes() != 1 ) {
3515                 return false;
3516             }
3517             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3518                 return false;
3519             }
3520             t1.deleteSubtree( t1.getNode( "B" ), false );
3521             if ( t1.getNumberOfExternalNodes() != 1 ) {
3522                 return false;
3523             }
3524             t1.deleteSubtree( t1.getNode( "r" ), false );
3525             if ( !t1.isEmpty() ) {
3526                 return false;
3527             }
3528             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3529             if ( t2.getNumberOfExternalNodes() != 3 ) {
3530                 return false;
3531             }
3532             t2.deleteSubtree( t2.getNode( "B" ), false );
3533             if ( t2.getNumberOfExternalNodes() != 2 ) {
3534                 return false;
3535             }
3536             t2.toNewHampshireX();
3537             PhylogenyNode n = t2.getNode( "A" );
3538             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3539                 return false;
3540             }
3541             t2.deleteSubtree( t2.getNode( "A" ), false );
3542             if ( t2.getNumberOfExternalNodes() != 2 ) {
3543                 return false;
3544             }
3545             t2.deleteSubtree( t2.getNode( "C" ), true );
3546             if ( t2.getNumberOfExternalNodes() != 1 ) {
3547                 return false;
3548             }
3549             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3550             if ( t3.getNumberOfExternalNodes() != 4 ) {
3551                 return false;
3552             }
3553             t3.deleteSubtree( t3.getNode( "B" ), true );
3554             if ( t3.getNumberOfExternalNodes() != 3 ) {
3555                 return false;
3556             }
3557             n = t3.getNode( "A" );
3558             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3559                 return false;
3560             }
3561             n = n.getNextExternalNode();
3562             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3563                 return false;
3564             }
3565             t3.deleteSubtree( t3.getNode( "A" ), true );
3566             if ( t3.getNumberOfExternalNodes() != 2 ) {
3567                 return false;
3568             }
3569             n = t3.getNode( "C" );
3570             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3571                 return false;
3572             }
3573             t3.deleteSubtree( t3.getNode( "C" ), true );
3574             if ( t3.getNumberOfExternalNodes() != 1 ) {
3575                 return false;
3576             }
3577             t3.deleteSubtree( t3.getNode( "D" ), true );
3578             if ( t3.getNumberOfExternalNodes() != 0 ) {
3579                 return false;
3580             }
3581             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3582             if ( t4.getNumberOfExternalNodes() != 6 ) {
3583                 return false;
3584             }
3585             t4.deleteSubtree( t4.getNode( "B2" ), true );
3586             if ( t4.getNumberOfExternalNodes() != 5 ) {
3587                 return false;
3588             }
3589             String s = w.toNewHampshire( t4, true ).toString();
3590             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3591                 return false;
3592             }
3593             t4.deleteSubtree( t4.getNode( "B11" ), true );
3594             if ( t4.getNumberOfExternalNodes() != 4 ) {
3595                 return false;
3596             }
3597             t4.deleteSubtree( t4.getNode( "C" ), true );
3598             if ( t4.getNumberOfExternalNodes() != 3 ) {
3599                 return false;
3600             }
3601             n = t4.getNode( "A" );
3602             n = n.getNextExternalNode();
3603             if ( !n.getName().equals( "B12" ) ) {
3604                 return false;
3605             }
3606             n = n.getNextExternalNode();
3607             if ( !n.getName().equals( "D" ) ) {
3608                 return false;
3609             }
3610             s = w.toNewHampshire( t4, true ).toString();
3611             if ( !s.equals( "((A,B12),D);" ) ) {
3612                 return false;
3613             }
3614             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3615             t5.deleteSubtree( t5.getNode( "A" ), true );
3616             if ( t5.getNumberOfExternalNodes() != 5 ) {
3617                 return false;
3618             }
3619             s = w.toNewHampshire( t5, true ).toString();
3620             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3621                 return false;
3622             }
3623             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3624             t6.deleteSubtree( t6.getNode( "B11" ), true );
3625             if ( t6.getNumberOfExternalNodes() != 5 ) {
3626                 return false;
3627             }
3628             s = w.toNewHampshire( t6, false ).toString();
3629             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3630                 return false;
3631             }
3632             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3633             t7.deleteSubtree( t7.getNode( "B12" ), true );
3634             if ( t7.getNumberOfExternalNodes() != 5 ) {
3635                 return false;
3636             }
3637             s = w.toNewHampshire( t7, true ).toString();
3638             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3639                 return false;
3640             }
3641             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3642             t8.deleteSubtree( t8.getNode( "B2" ), true );
3643             if ( t8.getNumberOfExternalNodes() != 5 ) {
3644                 return false;
3645             }
3646             s = w.toNewHampshire( t8, false ).toString();
3647             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3648                 return false;
3649             }
3650             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3651             t9.deleteSubtree( t9.getNode( "C" ), true );
3652             if ( t9.getNumberOfExternalNodes() != 5 ) {
3653                 return false;
3654             }
3655             s = w.toNewHampshire( t9, true ).toString();
3656             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3657                 return false;
3658             }
3659             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3660             t10.deleteSubtree( t10.getNode( "D" ), true );
3661             if ( t10.getNumberOfExternalNodes() != 5 ) {
3662                 return false;
3663             }
3664             s = w.toNewHampshire( t10, true ).toString();
3665             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3666                 return false;
3667             }
3668             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3669             t11.deleteSubtree( t11.getNode( "A" ), true );
3670             if ( t11.getNumberOfExternalNodes() != 2 ) {
3671                 return false;
3672             }
3673             s = w.toNewHampshire( t11, true ).toString();
3674             if ( !s.equals( "(B,C);" ) ) {
3675                 return false;
3676             }
3677             t11.deleteSubtree( t11.getNode( "C" ), true );
3678             if ( t11.getNumberOfExternalNodes() != 1 ) {
3679                 return false;
3680             }
3681             s = w.toNewHampshire( t11, false ).toString();
3682             if ( !s.equals( "B;" ) ) {
3683                 return false;
3684             }
3685             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3686             t12.deleteSubtree( t12.getNode( "B2" ), true );
3687             if ( t12.getNumberOfExternalNodes() != 8 ) {
3688                 return false;
3689             }
3690             s = w.toNewHampshire( t12, true ).toString();
3691             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3692                 return false;
3693             }
3694             t12.deleteSubtree( t12.getNode( "B3" ), true );
3695             if ( t12.getNumberOfExternalNodes() != 7 ) {
3696                 return false;
3697             }
3698             s = w.toNewHampshire( t12, true ).toString();
3699             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3700                 return false;
3701             }
3702             t12.deleteSubtree( t12.getNode( "C3" ), true );
3703             if ( t12.getNumberOfExternalNodes() != 6 ) {
3704                 return false;
3705             }
3706             s = w.toNewHampshire( t12, true ).toString();
3707             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3708                 return false;
3709             }
3710             t12.deleteSubtree( t12.getNode( "A1" ), true );
3711             if ( t12.getNumberOfExternalNodes() != 5 ) {
3712                 return false;
3713             }
3714             s = w.toNewHampshire( t12, true ).toString();
3715             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3716                 return false;
3717             }
3718             t12.deleteSubtree( t12.getNode( "B1" ), true );
3719             if ( t12.getNumberOfExternalNodes() != 4 ) {
3720                 return false;
3721             }
3722             s = w.toNewHampshire( t12, true ).toString();
3723             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3724                 return false;
3725             }
3726             t12.deleteSubtree( t12.getNode( "A3" ), true );
3727             if ( t12.getNumberOfExternalNodes() != 3 ) {
3728                 return false;
3729             }
3730             s = w.toNewHampshire( t12, true ).toString();
3731             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3732                 return false;
3733             }
3734             t12.deleteSubtree( t12.getNode( "A2" ), true );
3735             if ( t12.getNumberOfExternalNodes() != 2 ) {
3736                 return false;
3737             }
3738             s = w.toNewHampshire( t12, true ).toString();
3739             if ( !s.equals( "(C1,C2);" ) ) {
3740                 return false;
3741             }
3742             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3743             t13.deleteSubtree( t13.getNode( "D" ), true );
3744             if ( t13.getNumberOfExternalNodes() != 4 ) {
3745                 return false;
3746             }
3747             s = w.toNewHampshire( t13, true ).toString();
3748             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3749                 return false;
3750             }
3751             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3752             t14.deleteSubtree( t14.getNode( "E" ), true );
3753             if ( t14.getNumberOfExternalNodes() != 5 ) {
3754                 return false;
3755             }
3756             s = w.toNewHampshire( t14, true ).toString();
3757             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3758                 return false;
3759             }
3760             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3761             t15.deleteSubtree( t15.getNode( "B2" ), true );
3762             if ( t15.getNumberOfExternalNodes() != 11 ) {
3763                 return false;
3764             }
3765             t15.deleteSubtree( t15.getNode( "B1" ), true );
3766             if ( t15.getNumberOfExternalNodes() != 10 ) {
3767                 return false;
3768             }
3769             t15.deleteSubtree( t15.getNode( "B3" ), true );
3770             if ( t15.getNumberOfExternalNodes() != 9 ) {
3771                 return false;
3772             }
3773             t15.deleteSubtree( t15.getNode( "B4" ), true );
3774             if ( t15.getNumberOfExternalNodes() != 8 ) {
3775                 return false;
3776             }
3777             t15.deleteSubtree( t15.getNode( "A1" ), true );
3778             if ( t15.getNumberOfExternalNodes() != 7 ) {
3779                 return false;
3780             }
3781             t15.deleteSubtree( t15.getNode( "C4" ), true );
3782             if ( t15.getNumberOfExternalNodes() != 6 ) {
3783                 return false;
3784             }
3785         }
3786         catch ( final Exception e ) {
3787             e.printStackTrace( System.out );
3788             return false;
3789         }
3790         return true;
3791     }
3792
3793     private static boolean testDescriptiveStatistics() {
3794         try {
3795             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3796             dss1.addValue( 82 );
3797             dss1.addValue( 78 );
3798             dss1.addValue( 70 );
3799             dss1.addValue( 58 );
3800             dss1.addValue( 42 );
3801             if ( dss1.getN() != 5 ) {
3802                 return false;
3803             }
3804             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3805                 return false;
3806             }
3807             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3808                 return false;
3809             }
3810             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3811                 return false;
3812             }
3813             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3814                 return false;
3815             }
3816             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3817                 return false;
3818             }
3819             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3820                 return false;
3821             }
3822             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3823                 return false;
3824             }
3825             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3826                 return false;
3827             }
3828             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3829                 return false;
3830             }
3831             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3832                 return false;
3833             }
3834             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3835                 return false;
3836             }
3837             dss1.addValue( 123 );
3838             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3839                 return false;
3840             }
3841             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3842                 return false;
3843             }
3844             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3845                 return false;
3846             }
3847             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3848             dss2.addValue( -1.85 );
3849             dss2.addValue( 57.5 );
3850             dss2.addValue( 92.78 );
3851             dss2.addValue( 57.78 );
3852             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3853                 return false;
3854             }
3855             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3856                 return false;
3857             }
3858             final double[] a = dss2.getDataAsDoubleArray();
3859             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3860                 return false;
3861             }
3862             dss2.addValue( -100 );
3863             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3864                 return false;
3865             }
3866             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3867                 return false;
3868             }
3869             final double[] ds = new double[ 14 ];
3870             ds[ 0 ] = 34;
3871             ds[ 1 ] = 23;
3872             ds[ 2 ] = 1;
3873             ds[ 3 ] = 32;
3874             ds[ 4 ] = 11;
3875             ds[ 5 ] = 2;
3876             ds[ 6 ] = 12;
3877             ds[ 7 ] = 33;
3878             ds[ 8 ] = 13;
3879             ds[ 9 ] = 22;
3880             ds[ 10 ] = 21;
3881             ds[ 11 ] = 35;
3882             ds[ 12 ] = 24;
3883             ds[ 13 ] = 31;
3884             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3885             if ( bins.length != 4 ) {
3886                 return false;
3887             }
3888             if ( bins[ 0 ] != 2 ) {
3889                 return false;
3890             }
3891             if ( bins[ 1 ] != 3 ) {
3892                 return false;
3893             }
3894             if ( bins[ 2 ] != 4 ) {
3895                 return false;
3896             }
3897             if ( bins[ 3 ] != 5 ) {
3898                 return false;
3899             }
3900             final double[] ds1 = new double[ 9 ];
3901             ds1[ 0 ] = 10.0;
3902             ds1[ 1 ] = 19.0;
3903             ds1[ 2 ] = 9.999;
3904             ds1[ 3 ] = 0.0;
3905             ds1[ 4 ] = 39.9;
3906             ds1[ 5 ] = 39.999;
3907             ds1[ 6 ] = 30.0;
3908             ds1[ 7 ] = 19.999;
3909             ds1[ 8 ] = 30.1;
3910             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3911             if ( bins1.length != 4 ) {
3912                 return false;
3913             }
3914             if ( bins1[ 0 ] != 2 ) {
3915                 return false;
3916             }
3917             if ( bins1[ 1 ] != 3 ) {
3918                 return false;
3919             }
3920             if ( bins1[ 2 ] != 0 ) {
3921                 return false;
3922             }
3923             if ( bins1[ 3 ] != 4 ) {
3924                 return false;
3925             }
3926             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3927             if ( bins1_1.length != 3 ) {
3928                 return false;
3929             }
3930             if ( bins1_1[ 0 ] != 3 ) {
3931                 return false;
3932             }
3933             if ( bins1_1[ 1 ] != 2 ) {
3934                 return false;
3935             }
3936             if ( bins1_1[ 2 ] != 4 ) {
3937                 return false;
3938             }
3939             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3940             if ( bins1_2.length != 3 ) {
3941                 return false;
3942             }
3943             if ( bins1_2[ 0 ] != 2 ) {
3944                 return false;
3945             }
3946             if ( bins1_2[ 1 ] != 2 ) {
3947                 return false;
3948             }
3949             if ( bins1_2[ 2 ] != 2 ) {
3950                 return false;
3951             }
3952             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3953             dss3.addValue( 1 );
3954             dss3.addValue( 1 );
3955             dss3.addValue( 1 );
3956             dss3.addValue( 2 );
3957             dss3.addValue( 3 );
3958             dss3.addValue( 4 );
3959             dss3.addValue( 5 );
3960             dss3.addValue( 5 );
3961             dss3.addValue( 5 );
3962             dss3.addValue( 6 );
3963             dss3.addValue( 7 );
3964             dss3.addValue( 8 );
3965             dss3.addValue( 9 );
3966             dss3.addValue( 10 );
3967             dss3.addValue( 10 );
3968             dss3.addValue( 10 );
3969             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3970             histo.toStringBuffer( 10, '=', 40, 5 );
3971             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3972         }
3973         catch ( final Exception e ) {
3974             e.printStackTrace( System.out );
3975             return false;
3976         }
3977         return true;
3978     }
3979
3980     private static boolean testDir( final String file ) {
3981         try {
3982             final File f = new File( file );
3983             if ( !f.exists() ) {
3984                 return false;
3985             }
3986             if ( !f.isDirectory() ) {
3987                 return false;
3988             }
3989             if ( !f.canRead() ) {
3990                 return false;
3991             }
3992         }
3993         catch ( final Exception e ) {
3994             return false;
3995         }
3996         return true;
3997     }
3998
3999     private static boolean testEbiEntryRetrieval() {
4000         try {
4001             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
4002             if ( !entry.getAccession().equals( "AAK41263" ) ) {
4003                 System.out.println( entry.getAccession() );
4004                 return false;
4005             }
4006             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
4007                 System.out.println( entry.getTaxonomyScientificName() );
4008                 return false;
4009             }
4010             if ( !entry.getSequenceName()
4011                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4012                 System.out.println( entry.getSequenceName() );
4013                 return false;
4014             }
4015             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4016                 System.out.println( entry.getGeneName() );
4017                 return false;
4018             }
4019             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4020                 System.out.println( entry.getTaxonomyIdentifier() );
4021                 return false;
4022             }
4023             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4024                 System.out.println( entry.getAnnotations().first().getRefValue() );
4025                 return false;
4026             }
4027             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4028                 System.out.println( entry.getAnnotations().first().getRefSource() );
4029                 return false;
4030             }
4031             if ( entry.getCrossReferences().size() < 1 ) {
4032                 return false;
4033             }
4034             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4035             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4036                 return false;
4037             }
4038             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4039                 System.out.println( entry1.getTaxonomyScientificName() );
4040                 return false;
4041             }
4042             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4043                 System.out.println( entry1.getSequenceName() );
4044                 return false;
4045             }
4046             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4047                 System.out.println( entry1.getTaxonomyIdentifier() );
4048                 return false;
4049             }
4050             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4051                 System.out.println( entry1.getGeneName() );
4052                 return false;
4053             }
4054             if ( entry1.getCrossReferences().size() < 1 ) {
4055                 return false;
4056             }
4057             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4058             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4059                 return false;
4060             }
4061             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4062                 System.out.println( entry2.getTaxonomyScientificName() );
4063                 return false;
4064             }
4065             if ( !entry2.getSequenceName()
4066                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4067                 System.out.println( entry2.getSequenceName() );
4068                 return false;
4069             }
4070             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4071                 System.out.println( entry2.getTaxonomyIdentifier() );
4072                 return false;
4073             }
4074             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4075                 System.out.println( entry2.getGeneName() );
4076                 return false;
4077             }
4078             if ( entry2.getCrossReferences().size() < 1 ) {
4079                 return false;
4080             }
4081             if ( !entry2.getChromosome().equals( "20" ) ) {
4082                 return false;
4083             }
4084             if ( !entry2.getMap().equals( "20q11.22" ) ) {
4085                 return false;
4086             }
4087             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4088             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4089                 return false;
4090             }
4091             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4092                 System.out.println( entry3.getTaxonomyScientificName() );
4093                 return false;
4094             }
4095             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4096                 System.out.println( entry3.getSequenceName() );
4097                 return false;
4098             }
4099             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4100                 System.out.println( entry3.getTaxonomyIdentifier() );
4101                 return false;
4102             }
4103             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4104                 System.out.println( entry3.getSequenceSymbol() );
4105                 return false;
4106             }
4107             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4108                 return false;
4109             }
4110             if ( entry3.getCrossReferences().size() < 1 ) {
4111                 return false;
4112             }
4113             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4114             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4115                 return false;
4116             }
4117             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4118                 System.out.println( entry4.getTaxonomyScientificName() );
4119                 return false;
4120             }
4121             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4122                 System.out.println( entry4.getSequenceName() );
4123                 return false;
4124             }
4125             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4126                 System.out.println( entry4.getTaxonomyIdentifier() );
4127                 return false;
4128             }
4129             if ( !entry4.getGeneName().equals( "ras" ) ) {
4130                 System.out.println( entry4.getGeneName() );
4131                 return false;
4132             }
4133             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4134             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4135                 return false;
4136             }
4137             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4138                 System.out.println( entry5.getTaxonomyScientificName() );
4139                 return false;
4140             }
4141             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4142                 System.out.println( entry5.getSequenceName() );
4143                 return false;
4144             }
4145             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4146                 System.out.println( entry5.getTaxonomyIdentifier() );
4147                 return false;
4148             }
4149             final SequenceDatabaseEntry entry6 = SequenceDbWsTools.obtainEntry( "M30539" );
4150             if ( !entry6.getAccession().equals( "M30539" ) ) {
4151                 return false;
4152             }
4153             if ( !entry6.getGeneName().equals( "ras" ) ) {
4154                 return false;
4155             }
4156             if ( !entry6.getSequenceName().equals( "Human SK2 c-Ha-ras-1 oncogene-encoded protein gene, exon 1" ) ) {
4157                 return false;
4158             }
4159             if ( !entry6.getTaxonomyIdentifier().equals( "9606" ) ) {
4160                 return false;
4161             }
4162             if ( !entry6.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4163                 return false;
4164             }
4165             if ( entry6.getCrossReferences().size() < 1 ) {
4166                 return false;
4167             }
4168         }
4169         catch ( final IOException e ) {
4170             System.out.println();
4171             System.out.println( "the following might be due to absence internet connection:" );
4172             e.printStackTrace( System.out );
4173             return true;
4174         }
4175         catch ( final Exception e ) {
4176             e.printStackTrace();
4177             return false;
4178         }
4179         return true;
4180     }
4181
4182     private static boolean testExternalNodeRelatedMethods() {
4183         try {
4184             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4185             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4186             PhylogenyNode n = t1.getNode( "A" );
4187             n = n.getNextExternalNode();
4188             if ( !n.getName().equals( "B" ) ) {
4189                 return false;
4190             }
4191             n = n.getNextExternalNode();
4192             if ( !n.getName().equals( "C" ) ) {
4193                 return false;
4194             }
4195             n = n.getNextExternalNode();
4196             if ( !n.getName().equals( "D" ) ) {
4197                 return false;
4198             }
4199             n = t1.getNode( "B" );
4200             while ( !n.isLastExternalNode() ) {
4201                 n = n.getNextExternalNode();
4202             }
4203             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4204             n = t2.getNode( "A" );
4205             n = n.getNextExternalNode();
4206             if ( !n.getName().equals( "B" ) ) {
4207                 return false;
4208             }
4209             n = n.getNextExternalNode();
4210             if ( !n.getName().equals( "C" ) ) {
4211                 return false;
4212             }
4213             n = n.getNextExternalNode();
4214             if ( !n.getName().equals( "D" ) ) {
4215                 return false;
4216             }
4217             n = t2.getNode( "B" );
4218             while ( !n.isLastExternalNode() ) {
4219                 n = n.getNextExternalNode();
4220             }
4221             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4222             n = t3.getNode( "A" );
4223             n = n.getNextExternalNode();
4224             if ( !n.getName().equals( "B" ) ) {
4225                 return false;
4226             }
4227             n = n.getNextExternalNode();
4228             if ( !n.getName().equals( "C" ) ) {
4229                 return false;
4230             }
4231             n = n.getNextExternalNode();
4232             if ( !n.getName().equals( "D" ) ) {
4233                 return false;
4234             }
4235             n = n.getNextExternalNode();
4236             if ( !n.getName().equals( "E" ) ) {
4237                 return false;
4238             }
4239             n = n.getNextExternalNode();
4240             if ( !n.getName().equals( "F" ) ) {
4241                 return false;
4242             }
4243             n = n.getNextExternalNode();
4244             if ( !n.getName().equals( "G" ) ) {
4245                 return false;
4246             }
4247             n = n.getNextExternalNode();
4248             if ( !n.getName().equals( "H" ) ) {
4249                 return false;
4250             }
4251             n = t3.getNode( "B" );
4252             while ( !n.isLastExternalNode() ) {
4253                 n = n.getNextExternalNode();
4254             }
4255             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4256             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4257                 final PhylogenyNode node = iter.next();
4258             }
4259             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4260             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4261                 final PhylogenyNode node = iter.next();
4262             }
4263             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4264             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4265             if ( !iter.next().getName().equals( "A" ) ) {
4266                 return false;
4267             }
4268             if ( !iter.next().getName().equals( "B" ) ) {
4269                 return false;
4270             }
4271             if ( !iter.next().getName().equals( "C" ) ) {
4272                 return false;
4273             }
4274             if ( !iter.next().getName().equals( "D" ) ) {
4275                 return false;
4276             }
4277             if ( !iter.next().getName().equals( "E" ) ) {
4278                 return false;
4279             }
4280             if ( !iter.next().getName().equals( "F" ) ) {
4281                 return false;
4282             }
4283             if ( iter.hasNext() ) {
4284                 return false;
4285             }
4286         }
4287         catch ( final Exception e ) {
4288             e.printStackTrace( System.out );
4289             return false;
4290         }
4291         return true;
4292     }
4293
4294     private static boolean testExtractSNFromNodeName() {
4295         try {
4296             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4297                 return false;
4298             }
4299             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4300                 return false;
4301             }
4302             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4303                 return false;
4304             }
4305             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4306                     .equals( "Mus musculus musculus" ) ) {
4307                 return false;
4308             }
4309             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4310                     .equals( "Mus musculus musculus" ) ) {
4311                 return false;
4312             }
4313             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4314                     .equals( "Mus musculus musculus" ) ) {
4315                 return false;
4316             }
4317             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4318                     .equals( "Mus musculus musculus" ) ) {
4319                 return false;
4320             }
4321             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4322                 return false;
4323             }
4324             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4325                     .equals( "Mus musculus musculus" ) ) {
4326                 return false;
4327             }
4328             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4329                     .equals( "Mus musculus musculus" ) ) {
4330                 return false;
4331             }
4332             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4333                 return false;
4334             }
4335             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4336                 return false;
4337             }
4338             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4339                 return false;
4340             }
4341             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4342                 return false;
4343             }
4344             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4345                     .equals( "Mus musculus musculus" ) ) {
4346                 return false;
4347             }
4348             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4349                 return false;
4350             }
4351             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4352                 return false;
4353             }
4354             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4355                 return false;
4356             }
4357             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4358                 return false;
4359             }
4360             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4361                 return false;
4362             }
4363             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4364                 return false;
4365             }
4366             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4367                 return false;
4368             }
4369             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4370                 return false;
4371             }
4372             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4373                     .equals( "Mus musculus" ) ) {
4374                 return false;
4375             }
4376             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4377                     .equals( "Mus musculus" ) ) {
4378                 return false;
4379             }
4380             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4381                 return false;
4382             }
4383             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4384                     .equals( "Mus musculus musculus" ) ) {
4385                 return false;
4386             }
4387             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4388                     .equals( "Mus musculus musculus" ) ) {
4389                 return false;
4390             }
4391             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4392                     .equals( "Mus musculus musculus" ) ) {
4393                 return false;
4394             }
4395             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4396                 return false;
4397             }
4398             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4399                     .equals( "Pilostyles mexicana" ) ) {
4400                 return false;
4401             }
4402             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4403                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4404                 return false;
4405             }
4406             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4407                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4408                 return false;
4409             }
4410             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4411                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4412                 return false;
4413             }
4414             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4415                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4416                 return false;
4417             }
4418             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4419                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4420                 return false;
4421             }
4422             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4423                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4424                 return false;
4425             }
4426             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4427                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4428                 return false;
4429             }
4430             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4431                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4432                 return false;
4433             }
4434             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4435                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4436                 return false;
4437             }
4438             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4439                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4440                 return false;
4441             }
4442             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4443                     .equals( "Escherichia coli (strain K12)" ) ) {
4444                 return false;
4445             }
4446             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4447                     .equals( "Escherichia coli (strain K12)" ) ) {
4448                 return false;
4449             }
4450             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4451                     .equals( "Escherichia coli (str. K12)" ) ) {
4452                 return false;
4453             }
4454             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4455                     .equals( "Escherichia coli (str. K12)" ) ) {
4456                 return false;
4457             }
4458             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4459                     .equals( "Escherichia coli (str. K12)" ) ) {
4460                 return false;
4461             }
4462             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4463                     .equals( "Escherichia coli (var. K12)" ) ) {
4464                 return false;
4465             }
4466             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4467                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4468                 return false;
4469             }
4470             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4471                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4472                 return false;
4473             }
4474             if ( !ParserUtils
4475                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4476                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4477                 return false;
4478             }
4479             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4480                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4481                 return false;
4482             }
4483             if ( !ParserUtils
4484                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4485                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4486                 return false;
4487             }
4488             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4489                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4490                 return false;
4491             }
4492             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4493                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4494                 return false;
4495             }
4496             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4497                 return false;
4498             }
4499             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4500                 return false;
4501             }
4502             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4503                 return false;
4504             }
4505             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4506                     .equals( "Macrocera sp." ) ) {
4507                 return false;
4508             }
4509             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4510                 return false;
4511             }
4512             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4513                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4514                 return false;
4515             }
4516             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4517                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4518                 return false;
4519             }
4520             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4521                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4522                 return false;
4523             }
4524             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4525                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4526                 return false;
4527             }
4528         }
4529         catch ( final Exception e ) {
4530             e.printStackTrace( System.out );
4531             return false;
4532         }
4533         return true;
4534     }
4535
4536     private static boolean testExtractTaxonomyDataFromNodeName() {
4537         try {
4538             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
4539             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4540                 return false;
4541             }
4542             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
4543             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4544                 return false;
4545             }
4546             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
4547             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4548                 return false;
4549             }
4550             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
4551             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4552                 return false;
4553             }
4554             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
4555             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4556                 return false;
4557             }
4558             n = new PhylogenyNode( "HNRPR_HUMAN" );
4559             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4560                 return false;
4561             }
4562             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
4563             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4564                 return false;
4565             }
4566         }
4567         catch ( final Exception e ) {
4568             e.printStackTrace( System.out );
4569             return false;
4570         }
4571         return true;
4572     }
4573
4574     private static boolean testExtractTaxonomyCodeFromNodeName() {
4575         try {
4576             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4577                 return false;
4578             }
4579             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4580                     .equals( "SOYBN" ) ) {
4581                 return false;
4582             }
4583             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4584                     .equals( "ARATH" ) ) {
4585                 return false;
4586             }
4587             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4588                     .equals( "ARATH" ) ) {
4589                 return false;
4590             }
4591             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4592                 return false;
4593             }
4594             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4595                 return false;
4596             }
4597             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4598                 return false;
4599             }
4600             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4601                     .equals( "SOYBN" ) ) {
4602                 return false;
4603             }
4604             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4605                     .equals( "SOYBN" ) ) {
4606                 return false;
4607             }
4608             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4609                     .equals( "SOYBN" ) ) {
4610                 return false;
4611             }
4612             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4613                     .equals( "SOYBN" ) ) {
4614                 return false;
4615             }
4616             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4617                     .equals( "SOYBN" ) ) {
4618                 return false;
4619             }
4620             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4621                     .equals( "SOYBN" ) ) {
4622                 return false;
4623             }
4624             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4625                     .equals( "SOYBN" ) ) {
4626                 return false;
4627             }
4628             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4629                     .equals( "SOYBN" ) ) {
4630                 return false;
4631             }
4632             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4633                 return false;
4634             }
4635             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4636                     .equals( "SOYBN" ) ) {
4637                 return false;
4638             }
4639             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4640                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4641                 return false;
4642             }
4643             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4644                     .equals( "9YX45" ) ) {
4645                 return false;
4646             }
4647             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4648                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4649                                                                .equals( "MOUSE" ) ) {
4650                 return false;
4651             }
4652             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4653                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4654                                                                .equals( "MOUSE" ) ) {
4655                 return false;
4656             }
4657             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4658                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4659                                                                .equals( "MOUSE" ) ) {
4660                 return false;
4661             }
4662             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4663                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4664                 return false;
4665             }
4666             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4667                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4668                 return false;
4669             }
4670             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4671                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4672                 return false;
4673             }
4674             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4675                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4676                 return false;
4677             }
4678             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4679                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4680                 return false;
4681             }
4682             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4683                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4684                 return false;
4685             }
4686             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4687                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4688                 return false;
4689             }
4690             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4691                     .equals( "RAT" ) ) {
4692                 return false;
4693             }
4694             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4695                     .equals( "PIG" ) ) {
4696                 return false;
4697             }
4698             if ( !ParserUtils
4699                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4700                     .equals( "MOUSE" ) ) {
4701                 return false;
4702             }
4703             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4704                     .equals( "MOUSE" ) ) {
4705                 return false;
4706             }
4707             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4708                 return false;
4709             }
4710         }
4711         catch ( final Exception e ) {
4712             e.printStackTrace( System.out );
4713             return false;
4714         }
4715         return true;
4716     }
4717
4718     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4719         try {
4720             PhylogenyNode n = new PhylogenyNode();
4721             n.setName( "tr|B3RJ64" );
4722             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4723                 return false;
4724             }
4725             n.setName( "tr.B3RJ64" );
4726             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4727                 return false;
4728             }
4729             n.setName( "tr=B3RJ64" );
4730             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4731                 return false;
4732             }
4733             n.setName( "tr-B3RJ64" );
4734             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4735                 return false;
4736             }
4737             n.setName( "tr/B3RJ64" );
4738             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4739                 return false;
4740             }
4741             n.setName( "tr\\B3RJ64" );
4742             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4743                 return false;
4744             }
4745             n.setName( "tr_B3RJ64" );
4746             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4747                 return false;
4748             }
4749             n.setName( " tr|B3RJ64 " );
4750             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4751                 return false;
4752             }
4753             n.setName( "-tr|B3RJ64-" );
4754             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4755                 return false;
4756             }
4757             n.setName( "-tr=B3RJ64-" );
4758             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4759                 return false;
4760             }
4761             n.setName( "_tr=B3RJ64_" );
4762             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4763                 return false;
4764             }
4765             n.setName( " tr_tr|B3RJ64_sp|123 " );
4766             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4767                 return false;
4768             }
4769             n.setName( "B3RJ64" );
4770             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4771                 return false;
4772             }
4773             n.setName( "sp|B3RJ64" );
4774             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4775                 return false;
4776             }
4777             n.setName( "sp|B3RJ64C" );
4778             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4779                 return false;
4780             }
4781             n.setName( "sp B3RJ64" );
4782             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4783                 return false;
4784             }
4785             n.setName( "sp|B3RJ6X" );
4786             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4787                 return false;
4788             }
4789             n.setName( "sp|B3RJ6" );
4790             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4791                 return false;
4792             }
4793             n.setName( "K1PYK7_CRAGI" );
4794             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4795                 return false;
4796             }
4797             n.setName( "K1PYK7_PEA" );
4798             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4799                 return false;
4800             }
4801             n.setName( "K1PYK7_RAT" );
4802             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4803                 return false;
4804             }
4805             n.setName( "K1PYK7_PIG" );
4806             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4807                 return false;
4808             }
4809             n.setName( "~K1PYK7_PIG~" );
4810             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4811                 return false;
4812             }
4813             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4814             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4815                 return false;
4816             }
4817             n.setName( "K1PYKX_CRAGI" );
4818             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4819                 return false;
4820             }
4821             n.setName( "XXXXX_CRAGI" );
4822             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4823                 return false;
4824             }
4825             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4826             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4827                 return false;
4828             }
4829             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4830             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4831                 return false;
4832             }
4833             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4834             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4835                 return false;
4836             }
4837             n = new PhylogenyNode();
4838             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4839             seq.setSymbol( "K1PYK7_CRAGI" );
4840             n.getNodeData().addSequence( seq );
4841             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4842                 return false;
4843             }
4844             seq.setSymbol( "tr|B3RJ64" );
4845             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4846                 return false;
4847             }
4848             n = new PhylogenyNode();
4849             seq = new org.forester.phylogeny.data.Sequence();
4850             seq.setName( "K1PYK7_CRAGI" );
4851             n.getNodeData().addSequence( seq );
4852             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4853                 return false;
4854             }
4855             seq.setName( "tr|B3RJ64" );
4856             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4857                 return false;
4858             }
4859             n = new PhylogenyNode();
4860             seq = new org.forester.phylogeny.data.Sequence();
4861             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4862             n.getNodeData().addSequence( seq );
4863             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4864                 return false;
4865             }
4866             n = new PhylogenyNode();
4867             seq = new org.forester.phylogeny.data.Sequence();
4868             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4869             n.getNodeData().addSequence( seq );
4870             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4871                 return false;
4872             }
4873             //
4874             n = new PhylogenyNode();
4875             n.setName( "ACP19736" );
4876             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4877                 return false;
4878             }
4879             n = new PhylogenyNode();
4880             n.setName( "|ACP19736|" );
4881             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4882                 return false;
4883             }
4884         }
4885         catch ( final Exception e ) {
4886             e.printStackTrace( System.out );
4887             return false;
4888         }
4889         return true;
4890     }
4891
4892     private static boolean testFastaParser() {
4893         try {
4894             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4895                 return false;
4896             }
4897             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4898                 return false;
4899             }
4900             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4901             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4902                 return false;
4903             }
4904             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4905                 return false;
4906             }
4907             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4908                 return false;
4909             }
4910             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
4911                 return false;
4912             }
4913             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4914                 return false;
4915             }
4916             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4917                 return false;
4918             }
4919         }
4920         catch ( final Exception e ) {
4921             e.printStackTrace();
4922             return false;
4923         }
4924         return true;
4925     }
4926
4927     private static boolean testGenbankAccessorParsing() {
4928         //The format for GenBank Accession numbers are:
4929         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4930         //Protein:    3 letters + 5 numerals
4931         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4932         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4933             return false;
4934         }
4935         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4936             return false;
4937         }
4938         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4939             return false;
4940         }
4941         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4942             return false;
4943         }
4944         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4945             return false;
4946         }
4947         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4948             return false;
4949         }
4950         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4951             return false;
4952         }
4953         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4954             return false;
4955         }
4956         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4957             return false;
4958         }
4959         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4960             return false;
4961         }
4962         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4963             return false;
4964         }
4965         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4966             return false;
4967         }
4968         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4969             return false;
4970         }
4971         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4972             return false;
4973         }
4974         return true;
4975     }
4976
4977     private static boolean testGeneralMsaParser() {
4978         try {
4979             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4980             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4981             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4982             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4983             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4984             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4985             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4986             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4987             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4988                 return false;
4989             }
4990             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4991                 return false;
4992             }
4993             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4994                 return false;
4995             }
4996             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4997                 return false;
4998             }
4999             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5000                 return false;
5001             }
5002             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5003                 return false;
5004             }
5005             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5006                 return false;
5007             }
5008             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5009                 return false;
5010             }
5011             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5012                 return false;
5013             }
5014             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5015                 return false;
5016             }
5017             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5018                 return false;
5019             }
5020             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5021                 return false;
5022             }
5023             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5024             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5025                 return false;
5026             }
5027             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5028                 return false;
5029             }
5030             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5031                 return false;
5032             }
5033             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5034             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5035                 return false;
5036             }
5037             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5038                 return false;
5039             }
5040             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5041                 return false;
5042             }
5043             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5044             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5045                 return false;
5046             }
5047             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5048                 return false;
5049             }
5050             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5051                 return false;
5052             }
5053         }
5054         catch ( final Exception e ) {
5055             e.printStackTrace();
5056             return false;
5057         }
5058         return true;
5059     }
5060
5061     private static boolean testGeneralTable() {
5062         try {
5063             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5064             t0.setValue( 3, 2, "23" );
5065             t0.setValue( 10, 1, "error" );
5066             t0.setValue( 10, 1, "110" );
5067             t0.setValue( 9, 1, "19" );
5068             t0.setValue( 1, 10, "101" );
5069             t0.setValue( 10, 10, "1010" );
5070             t0.setValue( 100, 10, "10100" );
5071             t0.setValue( 0, 0, "00" );
5072             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5073                 return false;
5074             }
5075             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5076                 return false;
5077             }
5078             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5079                 return false;
5080             }
5081             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5082                 return false;
5083             }
5084             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5085                 return false;
5086             }
5087             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5088                 return false;
5089             }
5090             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5091                 return false;
5092             }
5093             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5094                 return false;
5095             }
5096             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5097                 return false;
5098             }
5099             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5100             t1.setValue( "3", "2", "23" );
5101             t1.setValue( "10", "1", "error" );
5102             t1.setValue( "10", "1", "110" );
5103             t1.setValue( "9", "1", "19" );
5104             t1.setValue( "1", "10", "101" );
5105             t1.setValue( "10", "10", "1010" );
5106             t1.setValue( "100", "10", "10100" );
5107             t1.setValue( "0", "0", "00" );
5108             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5109             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5110                 return false;
5111             }
5112             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5113                 return false;
5114             }
5115             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5116                 return false;
5117             }
5118             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5119                 return false;
5120             }
5121             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5122                 return false;
5123             }
5124             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5125                 return false;
5126             }
5127             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5128                 return false;
5129             }
5130             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5131                 return false;
5132             }
5133             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5134                 return false;
5135             }
5136             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5137                 return false;
5138             }
5139         }
5140         catch ( final Exception e ) {
5141             e.printStackTrace( System.out );
5142             return false;
5143         }
5144         return true;
5145     }
5146
5147     private static boolean testGetDistance() {
5148         try {
5149             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5150             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",
5151                                                  new NHXParser() )[ 0 ];
5152             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5153                 return false;
5154             }
5155             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5156                 return false;
5157             }
5158             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5159                 return false;
5160             }
5161             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5162                 return false;
5163             }
5164             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5165                 return false;
5166             }
5167             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5168                 return false;
5169             }
5170             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5171                 return false;
5172             }
5173             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5174                 return false;
5175             }
5176             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5177                 return false;
5178             }
5179             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5180                 return false;
5181             }
5182             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5183                 return false;
5184             }
5185             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5186                 return false;
5187             }
5188             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5189                 return false;
5190             }
5191             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5192                 return false;
5193             }
5194             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5195                 return false;
5196             }
5197             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5198                 return false;
5199             }
5200             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5201                 return false;
5202             }
5203             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5204                 return false;
5205             }
5206             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5207                 return false;
5208             }
5209             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5210                 return false;
5211             }
5212             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5213                 return false;
5214             }
5215             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5216                 return false;
5217             }
5218             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5219                 return false;
5220             }
5221             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5222                 return false;
5223             }
5224             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5225                 return false;
5226             }
5227             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5228                 return false;
5229             }
5230             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5231                 return false;
5232             }
5233             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5234                 return false;
5235             }
5236             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5237                 return false;
5238             }
5239             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5240                 return false;
5241             }
5242             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5243                 return false;
5244             }
5245             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",
5246                                                  new NHXParser() )[ 0 ];
5247             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5248                 return false;
5249             }
5250             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5251                 return false;
5252             }
5253             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5254                 return false;
5255             }
5256             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5257                 return false;
5258             }
5259             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5260                 return false;
5261             }
5262             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5263                 return false;
5264             }
5265             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5266                 return false;
5267             }
5268             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5269                 return false;
5270             }
5271             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5272                 return false;
5273             }
5274             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5275                 return false;
5276             }
5277             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5278                 return false;
5279             }
5280         }
5281         catch ( final Exception e ) {
5282             e.printStackTrace( System.out );
5283             return false;
5284         }
5285         return true;
5286     }
5287
5288     private static boolean testGetLCA() {
5289         try {
5290             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5291             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5292                                                  new NHXParser() )[ 0 ];
5293             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5294             if ( !A.getName().equals( "A" ) ) {
5295                 return false;
5296             }
5297             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5298             if ( !gh.getName().equals( "gh" ) ) {
5299                 return false;
5300             }
5301             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5302             if ( !ab.getName().equals( "ab" ) ) {
5303                 return false;
5304             }
5305             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5306             if ( !ab2.getName().equals( "ab" ) ) {
5307                 return false;
5308             }
5309             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5310             if ( !gh2.getName().equals( "gh" ) ) {
5311                 return false;
5312             }
5313             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5314             if ( !gh3.getName().equals( "gh" ) ) {
5315                 return false;
5316             }
5317             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5318             if ( !abc.getName().equals( "abc" ) ) {
5319                 return false;
5320             }
5321             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5322             if ( !abc2.getName().equals( "abc" ) ) {
5323                 return false;
5324             }
5325             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5326             if ( !abcd.getName().equals( "abcd" ) ) {
5327                 return false;
5328             }
5329             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5330             if ( !abcd2.getName().equals( "abcd" ) ) {
5331                 return false;
5332             }
5333             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5334             if ( !abcdef.getName().equals( "abcdef" ) ) {
5335                 return false;
5336             }
5337             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5338             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5339                 return false;
5340             }
5341             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5342             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5343                 return false;
5344             }
5345             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5346             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5347                 return false;
5348             }
5349             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5350             if ( !abcde.getName().equals( "abcde" ) ) {
5351                 return false;
5352             }
5353             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5354             if ( !abcde2.getName().equals( "abcde" ) ) {
5355                 return false;
5356             }
5357             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5358             if ( !r.getName().equals( "abcdefgh" ) ) {
5359                 return false;
5360             }
5361             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5362             if ( !r2.getName().equals( "abcdefgh" ) ) {
5363                 return false;
5364             }
5365             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5366             if ( !r3.getName().equals( "abcdefgh" ) ) {
5367                 return false;
5368             }
5369             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5370             if ( !abcde3.getName().equals( "abcde" ) ) {
5371                 return false;
5372             }
5373             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5374             if ( !abcde4.getName().equals( "abcde" ) ) {
5375                 return false;
5376             }
5377             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5378             if ( !ab3.getName().equals( "ab" ) ) {
5379                 return false;
5380             }
5381             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5382             if ( !ab4.getName().equals( "ab" ) ) {
5383                 return false;
5384             }
5385             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5386             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5387             if ( !cd.getName().equals( "cd" ) ) {
5388                 return false;
5389             }
5390             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5391             if ( !cd2.getName().equals( "cd" ) ) {
5392                 return false;
5393             }
5394             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5395             if ( !cde.getName().equals( "cde" ) ) {
5396                 return false;
5397             }
5398             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5399             if ( !cde2.getName().equals( "cde" ) ) {
5400                 return false;
5401             }
5402             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5403             if ( !cdef.getName().equals( "cdef" ) ) {
5404                 return false;
5405             }
5406             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5407             if ( !cdef2.getName().equals( "cdef" ) ) {
5408                 return false;
5409             }
5410             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5411             if ( !cdef3.getName().equals( "cdef" ) ) {
5412                 return false;
5413             }
5414             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5415             if ( !rt.getName().equals( "r" ) ) {
5416                 return false;
5417             }
5418             final Phylogeny p3 = factory
5419                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5420                              new NHXParser() )[ 0 ];
5421             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5422             if ( !bc_3.getName().equals( "bc" ) ) {
5423                 return false;
5424             }
5425             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5426             if ( !ac_3.getName().equals( "abc" ) ) {
5427                 return false;
5428             }
5429             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5430             if ( !ad_3.getName().equals( "abcde" ) ) {
5431                 return false;
5432             }
5433             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5434             if ( !af_3.getName().equals( "abcdef" ) ) {
5435                 return false;
5436             }
5437             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5438             if ( !ag_3.getName().equals( "" ) ) {
5439                 return false;
5440             }
5441             if ( !ag_3.isRoot() ) {
5442                 return false;
5443             }
5444             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5445             if ( !al_3.getName().equals( "" ) ) {
5446                 return false;
5447             }
5448             if ( !al_3.isRoot() ) {
5449                 return false;
5450             }
5451             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5452             if ( !kl_3.getName().equals( "" ) ) {
5453                 return false;
5454             }
5455             if ( !kl_3.isRoot() ) {
5456                 return false;
5457             }
5458             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5459             if ( !fl_3.getName().equals( "" ) ) {
5460                 return false;
5461             }
5462             if ( !fl_3.isRoot() ) {
5463                 return false;
5464             }
5465             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5466             if ( !gk_3.getName().equals( "ghijk" ) ) {
5467                 return false;
5468             }
5469             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5470             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5471             if ( !r_4.getName().equals( "r" ) ) {
5472                 return false;
5473             }
5474             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5475             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5476             if ( !r_5.getName().equals( "root" ) ) {
5477                 return false;
5478             }
5479             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5480             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5481             if ( !r_6.getName().equals( "rot" ) ) {
5482                 return false;
5483             }
5484             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5485             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5486             if ( !r_7.getName().equals( "rott" ) ) {
5487                 return false;
5488             }
5489         }
5490         catch ( final Exception e ) {
5491             e.printStackTrace( System.out );
5492             return false;
5493         }
5494         return true;
5495     }
5496
5497     private static boolean testGetLCA2() {
5498         try {
5499             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5500             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5501             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5502             PhylogenyMethods.preOrderReId( p_a );
5503             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5504                                                                                               p_a.getNode( "a" ) );
5505             if ( !p_a_1.getName().equals( "a" ) ) {
5506                 return false;
5507             }
5508             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5509             PhylogenyMethods.preOrderReId( p_b );
5510             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5511                                                                                               p_b.getNode( "a" ) );
5512             if ( !p_b_1.getName().equals( "b" ) ) {
5513                 return false;
5514             }
5515             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5516                                                                                               p_b.getNode( "b" ) );
5517             if ( !p_b_2.getName().equals( "b" ) ) {
5518                 return false;
5519             }
5520             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5521             PhylogenyMethods.preOrderReId( p_c );
5522             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5523                                                                                               p_c.getNode( "a" ) );
5524             if ( !p_c_1.getName().equals( "b" ) ) {
5525                 return false;
5526             }
5527             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5528                                                                                               p_c.getNode( "c" ) );
5529             if ( !p_c_2.getName().equals( "c" ) ) {
5530                 System.out.println( p_c_2.getName() );
5531                 System.exit( -1 );
5532                 return false;
5533             }
5534             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5535                                                                                               p_c.getNode( "b" ) );
5536             if ( !p_c_3.getName().equals( "b" ) ) {
5537                 return false;
5538             }
5539             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5540                                                                                               p_c.getNode( "a" ) );
5541             if ( !p_c_4.getName().equals( "c" ) ) {
5542                 return false;
5543             }
5544             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5545                                                  new NHXParser() )[ 0 ];
5546             PhylogenyMethods.preOrderReId( p1 );
5547             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5548                                                                                           p1.getNode( "A" ) );
5549             if ( !A.getName().equals( "A" ) ) {
5550                 return false;
5551             }
5552             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5553                                                                                            p1.getNode( "gh" ) );
5554             if ( !gh.getName().equals( "gh" ) ) {
5555                 return false;
5556             }
5557             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5558                                                                                            p1.getNode( "B" ) );
5559             if ( !ab.getName().equals( "ab" ) ) {
5560                 return false;
5561             }
5562             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5563                                                                                             p1.getNode( "A" ) );
5564             if ( !ab2.getName().equals( "ab" ) ) {
5565                 return false;
5566             }
5567             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5568                                                                                             p1.getNode( "G" ) );
5569             if ( !gh2.getName().equals( "gh" ) ) {
5570                 return false;
5571             }
5572             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5573                                                                                             p1.getNode( "H" ) );
5574             if ( !gh3.getName().equals( "gh" ) ) {
5575                 return false;
5576             }
5577             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5578                                                                                             p1.getNode( "A" ) );
5579             if ( !abc.getName().equals( "abc" ) ) {
5580                 return false;
5581             }
5582             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5583                                                                                              p1.getNode( "C" ) );
5584             if ( !abc2.getName().equals( "abc" ) ) {
5585                 return false;
5586             }
5587             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5588                                                                                              p1.getNode( "D" ) );
5589             if ( !abcd.getName().equals( "abcd" ) ) {
5590                 return false;
5591             }
5592             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5593                                                                                               p1.getNode( "A" ) );
5594             if ( !abcd2.getName().equals( "abcd" ) ) {
5595                 return false;
5596             }
5597             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5598                                                                                                p1.getNode( "F" ) );
5599             if ( !abcdef.getName().equals( "abcdef" ) ) {
5600                 return false;
5601             }
5602             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5603                                                                                                 p1.getNode( "A" ) );
5604             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5605                 return false;
5606             }
5607             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5608                                                                                                 p1.getNode( "F" ) );
5609             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5610                 return false;
5611             }
5612             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5613                                                                                                 p1.getNode( "ab" ) );
5614             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5615                 return false;
5616             }
5617             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5618                                                                                               p1.getNode( "E" ) );
5619             if ( !abcde.getName().equals( "abcde" ) ) {
5620                 return false;
5621             }
5622             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5623                                                                                                p1.getNode( "A" ) );
5624             if ( !abcde2.getName().equals( "abcde" ) ) {
5625                 return false;
5626             }
5627             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5628                                                                                           p1.getNode( "abcdefgh" ) );
5629             if ( !r.getName().equals( "abcdefgh" ) ) {
5630                 return false;
5631             }
5632             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5633                                                                                            p1.getNode( "H" ) );
5634             if ( !r2.getName().equals( "abcdefgh" ) ) {
5635                 return false;
5636             }
5637             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5638                                                                                            p1.getNode( "A" ) );
5639             if ( !r3.getName().equals( "abcdefgh" ) ) {
5640                 return false;
5641             }
5642             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5643                                                                                                p1.getNode( "abcde" ) );
5644             if ( !abcde3.getName().equals( "abcde" ) ) {
5645                 return false;
5646             }
5647             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5648                                                                                                p1.getNode( "E" ) );
5649             if ( !abcde4.getName().equals( "abcde" ) ) {
5650                 return false;
5651             }
5652             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5653                                                                                             p1.getNode( "B" ) );
5654             if ( !ab3.getName().equals( "ab" ) ) {
5655                 return false;
5656             }
5657             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5658                                                                                             p1.getNode( "ab" ) );
5659             if ( !ab4.getName().equals( "ab" ) ) {
5660                 return false;
5661             }
5662             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5663             PhylogenyMethods.preOrderReId( p2 );
5664             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5665                                                                                            p2.getNode( "d" ) );
5666             if ( !cd.getName().equals( "cd" ) ) {
5667                 return false;
5668             }
5669             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5670                                                                                             p2.getNode( "c" ) );
5671             if ( !cd2.getName().equals( "cd" ) ) {
5672                 return false;
5673             }
5674             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5675                                                                                             p2.getNode( "e" ) );
5676             if ( !cde.getName().equals( "cde" ) ) {
5677                 return false;
5678             }
5679             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5680                                                                                              p2.getNode( "c" ) );
5681             if ( !cde2.getName().equals( "cde" ) ) {
5682                 return false;
5683             }
5684             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5685                                                                                              p2.getNode( "f" ) );
5686             if ( !cdef.getName().equals( "cdef" ) ) {
5687                 return false;
5688             }
5689             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5690                                                                                               p2.getNode( "f" ) );
5691             if ( !cdef2.getName().equals( "cdef" ) ) {
5692                 return false;
5693             }
5694             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5695                                                                                               p2.getNode( "d" ) );
5696             if ( !cdef3.getName().equals( "cdef" ) ) {
5697                 return false;
5698             }
5699             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5700                                                                                            p2.getNode( "a" ) );
5701             if ( !rt.getName().equals( "r" ) ) {
5702                 return false;
5703             }
5704             final Phylogeny p3 = factory
5705                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5706                              new NHXParser() )[ 0 ];
5707             PhylogenyMethods.preOrderReId( p3 );
5708             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5709                                                                                              p3.getNode( "c" ) );
5710             if ( !bc_3.getName().equals( "bc" ) ) {
5711                 return false;
5712             }
5713             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5714                                                                                              p3.getNode( "c" ) );
5715             if ( !ac_3.getName().equals( "abc" ) ) {
5716                 return false;
5717             }
5718             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5719                                                                                              p3.getNode( "d" ) );
5720             if ( !ad_3.getName().equals( "abcde" ) ) {
5721                 return false;
5722             }
5723             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5724                                                                                              p3.getNode( "f" ) );
5725             if ( !af_3.getName().equals( "abcdef" ) ) {
5726                 return false;
5727             }
5728             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5729                                                                                              p3.getNode( "g" ) );
5730             if ( !ag_3.getName().equals( "" ) ) {
5731                 return false;
5732             }
5733             if ( !ag_3.isRoot() ) {
5734                 return false;
5735             }
5736             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5737                                                                                              p3.getNode( "l" ) );
5738             if ( !al_3.getName().equals( "" ) ) {
5739                 return false;
5740             }
5741             if ( !al_3.isRoot() ) {
5742                 return false;
5743             }
5744             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5745                                                                                              p3.getNode( "l" ) );
5746             if ( !kl_3.getName().equals( "" ) ) {
5747                 return false;
5748             }
5749             if ( !kl_3.isRoot() ) {
5750                 return false;
5751             }
5752             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5753                                                                                              p3.getNode( "l" ) );
5754             if ( !fl_3.getName().equals( "" ) ) {
5755                 return false;
5756             }
5757             if ( !fl_3.isRoot() ) {
5758                 return false;
5759             }
5760             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5761                                                                                              p3.getNode( "k" ) );
5762             if ( !gk_3.getName().equals( "ghijk" ) ) {
5763                 return false;
5764             }
5765             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5766             PhylogenyMethods.preOrderReId( p4 );
5767             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5768                                                                                             p4.getNode( "c" ) );
5769             if ( !r_4.getName().equals( "r" ) ) {
5770                 return false;
5771             }
5772             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5773             PhylogenyMethods.preOrderReId( p5 );
5774             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5775                                                                                             p5.getNode( "c" ) );
5776             if ( !r_5.getName().equals( "root" ) ) {
5777                 return false;
5778             }
5779             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5780             PhylogenyMethods.preOrderReId( p6 );
5781             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5782                                                                                             p6.getNode( "a" ) );
5783             if ( !r_6.getName().equals( "rot" ) ) {
5784                 return false;
5785             }
5786             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5787             PhylogenyMethods.preOrderReId( p7 );
5788             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5789                                                                                             p7.getNode( "e" ) );
5790             if ( !r_7.getName().equals( "rott" ) ) {
5791                 return false;
5792             }
5793             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5794                                                                                              p7.getNode( "a" ) );
5795             if ( !r_71.getName().equals( "rott" ) ) {
5796                 return false;
5797             }
5798             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5799                                                                                              p7.getNode( "rott" ) );
5800             if ( !r_72.getName().equals( "rott" ) ) {
5801                 return false;
5802             }
5803             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5804                                                                                              p7.getNode( "a" ) );
5805             if ( !r_73.getName().equals( "rott" ) ) {
5806                 return false;
5807             }
5808             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5809                                                                                              p7.getNode( "rott" ) );
5810             if ( !r_74.getName().equals( "rott" ) ) {
5811                 return false;
5812             }
5813             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5814                                                                                              p7.getNode( "e" ) );
5815             if ( !r_75.getName().equals( "e" ) ) {
5816                 return false;
5817             }
5818         }
5819         catch ( final Exception e ) {
5820             e.printStackTrace( System.out );
5821             return false;
5822         }
5823         return true;
5824     }
5825
5826     private static boolean testHmmscanOutputParser() {
5827         final String test_dir = Test.PATH_TO_TEST_DATA;
5828         try {
5829             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5830                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5831             parser1.parse();
5832             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5833                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5834             final List<Protein> proteins = parser2.parse();
5835             if ( parser2.getProteinsEncountered() != 4 ) {
5836                 return false;
5837             }
5838             if ( proteins.size() != 4 ) {
5839                 return false;
5840             }
5841             if ( parser2.getDomainsEncountered() != 69 ) {
5842                 return false;
5843             }
5844             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5845                 return false;
5846             }
5847             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5848                 return false;
5849             }
5850             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5851                 return false;
5852             }
5853             final Protein p1 = proteins.get( 0 );
5854             if ( p1.getNumberOfProteinDomains() != 15 ) {
5855                 return false;
5856             }
5857             if ( p1.getLength() != 850 ) {
5858                 return false;
5859             }
5860             final Protein p2 = proteins.get( 1 );
5861             if ( p2.getNumberOfProteinDomains() != 51 ) {
5862                 return false;
5863             }
5864             if ( p2.getLength() != 1291 ) {
5865                 return false;
5866             }
5867             final Protein p3 = proteins.get( 2 );
5868             if ( p3.getNumberOfProteinDomains() != 2 ) {
5869                 return false;
5870             }
5871             final Protein p4 = proteins.get( 3 );
5872             if ( p4.getNumberOfProteinDomains() != 1 ) {
5873                 return false;
5874             }
5875             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5876                 return false;
5877             }
5878             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5879                 return false;
5880             }
5881             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5882                 return false;
5883             }
5884             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5885                 return false;
5886             }
5887             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5888                 return false;
5889             }
5890             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5891                 return false;
5892             }
5893             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5894                 return false;
5895             }
5896         }
5897         catch ( final Exception e ) {
5898             e.printStackTrace( System.out );
5899             return false;
5900         }
5901         return true;
5902     }
5903
5904     private static boolean testLastExternalNodeMethods() {
5905         try {
5906             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5907             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5908             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5909             final PhylogenyNode n1 = t0.getNode( "A" );
5910             if ( n1.isLastExternalNode() ) {
5911                 return false;
5912             }
5913             final PhylogenyNode n2 = t0.getNode( "B" );
5914             if ( n2.isLastExternalNode() ) {
5915                 return false;
5916             }
5917             final PhylogenyNode n3 = t0.getNode( "C" );
5918             if ( n3.isLastExternalNode() ) {
5919                 return false;
5920             }
5921             final PhylogenyNode n4 = t0.getNode( "D" );
5922             if ( !n4.isLastExternalNode() ) {
5923                 return false;
5924             }
5925         }
5926         catch ( final Exception e ) {
5927             e.printStackTrace( System.out );
5928             return false;
5929         }
5930         return true;
5931     }
5932
5933     private static boolean testLevelOrderIterator() {
5934         try {
5935             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5936             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5937             PhylogenyNodeIterator it0;
5938             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5939                 it0.next();
5940             }
5941             for( it0.reset(); it0.hasNext(); ) {
5942                 it0.next();
5943             }
5944             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5945             if ( !it.next().getName().equals( "r" ) ) {
5946                 return false;
5947             }
5948             if ( !it.next().getName().equals( "ab" ) ) {
5949                 return false;
5950             }
5951             if ( !it.next().getName().equals( "cd" ) ) {
5952                 return false;
5953             }
5954             if ( !it.next().getName().equals( "A" ) ) {
5955                 return false;
5956             }
5957             if ( !it.next().getName().equals( "B" ) ) {
5958                 return false;
5959             }
5960             if ( !it.next().getName().equals( "C" ) ) {
5961                 return false;
5962             }
5963             if ( !it.next().getName().equals( "D" ) ) {
5964                 return false;
5965             }
5966             if ( it.hasNext() ) {
5967                 return false;
5968             }
5969             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",
5970                                                  new NHXParser() )[ 0 ];
5971             PhylogenyNodeIterator it2;
5972             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5973                 it2.next();
5974             }
5975             for( it2.reset(); it2.hasNext(); ) {
5976                 it2.next();
5977             }
5978             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5979             if ( !it3.next().getName().equals( "r" ) ) {
5980                 return false;
5981             }
5982             if ( !it3.next().getName().equals( "abc" ) ) {
5983                 return false;
5984             }
5985             if ( !it3.next().getName().equals( "defg" ) ) {
5986                 return false;
5987             }
5988             if ( !it3.next().getName().equals( "A" ) ) {
5989                 return false;
5990             }
5991             if ( !it3.next().getName().equals( "B" ) ) {
5992                 return false;
5993             }
5994             if ( !it3.next().getName().equals( "C" ) ) {
5995                 return false;
5996             }
5997             if ( !it3.next().getName().equals( "D" ) ) {
5998                 return false;
5999             }
6000             if ( !it3.next().getName().equals( "E" ) ) {
6001                 return false;
6002             }
6003             if ( !it3.next().getName().equals( "F" ) ) {
6004                 return false;
6005             }
6006             if ( !it3.next().getName().equals( "G" ) ) {
6007                 return false;
6008             }
6009             if ( !it3.next().getName().equals( "1" ) ) {
6010                 return false;
6011             }
6012             if ( !it3.next().getName().equals( "2" ) ) {
6013                 return false;
6014             }
6015             if ( !it3.next().getName().equals( "3" ) ) {
6016                 return false;
6017             }
6018             if ( !it3.next().getName().equals( "4" ) ) {
6019                 return false;
6020             }
6021             if ( !it3.next().getName().equals( "5" ) ) {
6022                 return false;
6023             }
6024             if ( !it3.next().getName().equals( "6" ) ) {
6025                 return false;
6026             }
6027             if ( !it3.next().getName().equals( "f1" ) ) {
6028                 return false;
6029             }
6030             if ( !it3.next().getName().equals( "f2" ) ) {
6031                 return false;
6032             }
6033             if ( !it3.next().getName().equals( "f3" ) ) {
6034                 return false;
6035             }
6036             if ( !it3.next().getName().equals( "a" ) ) {
6037                 return false;
6038             }
6039             if ( !it3.next().getName().equals( "b" ) ) {
6040                 return false;
6041             }
6042             if ( !it3.next().getName().equals( "f21" ) ) {
6043                 return false;
6044             }
6045             if ( !it3.next().getName().equals( "X" ) ) {
6046                 return false;
6047             }
6048             if ( !it3.next().getName().equals( "Y" ) ) {
6049                 return false;
6050             }
6051             if ( !it3.next().getName().equals( "Z" ) ) {
6052                 return false;
6053             }
6054             if ( it3.hasNext() ) {
6055                 return false;
6056             }
6057             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6058             PhylogenyNodeIterator it4;
6059             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6060                 it4.next();
6061             }
6062             for( it4.reset(); it4.hasNext(); ) {
6063                 it4.next();
6064             }
6065             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6066             if ( !it5.next().getName().equals( "r" ) ) {
6067                 return false;
6068             }
6069             if ( !it5.next().getName().equals( "A" ) ) {
6070                 return false;
6071             }
6072             if ( !it5.next().getName().equals( "B" ) ) {
6073                 return false;
6074             }
6075             if ( !it5.next().getName().equals( "C" ) ) {
6076                 return false;
6077             }
6078             if ( !it5.next().getName().equals( "D" ) ) {
6079                 return false;
6080             }
6081             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6082             PhylogenyNodeIterator it6;
6083             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6084                 it6.next();
6085             }
6086             for( it6.reset(); it6.hasNext(); ) {
6087                 it6.next();
6088             }
6089             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6090             if ( !it7.next().getName().equals( "A" ) ) {
6091                 return false;
6092             }
6093             if ( it.hasNext() ) {
6094                 return false;
6095             }
6096         }
6097         catch ( final Exception e ) {
6098             e.printStackTrace( System.out );
6099             return false;
6100         }
6101         return true;
6102     }
6103
6104     private static boolean testMafft( final String path ) {
6105         try {
6106             final List<String> opts = new ArrayList<String>();
6107             opts.add( "--maxiterate" );
6108             opts.add( "1000" );
6109             opts.add( "--localpair" );
6110             opts.add( "--quiet" );
6111             Msa msa = null;
6112             final MsaInferrer mafft = Mafft.createInstance( path );
6113             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6114             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6115                 return false;
6116             }
6117             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6118                 return false;
6119             }
6120         }
6121         catch ( final Exception e ) {
6122             e.printStackTrace( System.out );
6123             return false;
6124         }
6125         return true;
6126     }
6127
6128     private static boolean testMidpointrooting() {
6129         try {
6130             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6131             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6132             PhylogenyMethods.midpointRoot( t0 );
6133             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6134                 return false;
6135             }
6136             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6137                 return false;
6138             }
6139             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6140                            1 ) ) {
6141                 return false;
6142             }
6143             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",
6144                                                  new NHXParser() )[ 0 ];
6145             if ( !t1.isRooted() ) {
6146                 return false;
6147             }
6148             PhylogenyMethods.midpointRoot( t1 );
6149             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6150                 return false;
6151             }
6152             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6153                 return false;
6154             }
6155             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6156                 return false;
6157             }
6158             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6159                 return false;
6160             }
6161             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6162                 return false;
6163             }
6164             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6165                 return false;
6166             }
6167             t1.reRoot( t1.getNode( "A" ) );
6168             PhylogenyMethods.midpointRoot( t1 );
6169             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6170                 return false;
6171             }
6172             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6173                 return false;
6174             }
6175             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6176                 return false;
6177             }
6178             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6179                 return false;
6180             }
6181             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6182                 System.exit( -1 );
6183                 return false;
6184             }
6185             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6186                 return false;
6187             }
6188         }
6189         catch ( final Exception e ) {
6190             e.printStackTrace( System.out );
6191             return false;
6192         }
6193         return true;
6194     }
6195
6196     private static boolean testMsaQualityMethod() {
6197         try {
6198             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6199             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6200             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6201             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6202             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6203             l.add( s0 );
6204             l.add( s1 );
6205             l.add( s2 );
6206             l.add( s3 );
6207             final Msa msa = BasicMsa.createInstance( l );
6208             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6209                 return false;
6210             }
6211             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6212                 return false;
6213             }
6214             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6215                 return false;
6216             }
6217             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6218                 return false;
6219             }
6220             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6221                 return false;
6222             }
6223             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6224                 return false;
6225             }
6226             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6227                 return false;
6228             }
6229         }
6230         catch ( final Exception e ) {
6231             e.printStackTrace( System.out );
6232             return false;
6233         }
6234         return true;
6235     }
6236
6237     private static boolean testMsaEntropy() {
6238         try {
6239             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6240             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6241             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6242             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6243             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6244             l.add( s0 );
6245             l.add( s1 );
6246             l.add( s2 );
6247             l.add( s3 );
6248             final Msa msa = BasicMsa.createInstance( l );
6249             //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6250             //FIXME
6251             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6252             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6253             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6254             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6255             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6256             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6257             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6258             //            System.out.println();
6259             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6260             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6261             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6262             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6263             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6264             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6265             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6266             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6267             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6268             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6269             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6270             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6271             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6272             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6273             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6274             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6275             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6276             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6277             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6278             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6279             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6280             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6281             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6282             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6283             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6284             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6285             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6286             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6287             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6288             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6289             final Msa msa2 = BasicMsa.createInstance( l2 );
6290             //            System.out.println();
6291             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6292             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6293             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6294         }
6295         catch ( final Exception e ) {
6296             e.printStackTrace( System.out );
6297             return false;
6298         }
6299         return true;
6300     }
6301
6302     private static boolean testDeleteableMsa() {
6303         try {
6304             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6305             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6306             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6307             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6308             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6309             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6310             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6311             l0.add( s0 );
6312             l0.add( s1 );
6313             l0.add( s2 );
6314             l0.add( s3 );
6315             l0.add( s4 );
6316             l0.add( s5 );
6317             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6318             dmsa0.deleteRow( "b", false );
6319             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6320                 return false;
6321             }
6322             dmsa0.deleteRow( "e", false );
6323             dmsa0.deleteRow( "a", false );
6324             dmsa0.deleteRow( "f", false );
6325             if ( dmsa0.getLength() != 4 ) {
6326                 return false;
6327             }
6328             if ( dmsa0.getNumberOfSequences() != 2 ) {
6329                 return false;
6330             }
6331             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6332                 return false;
6333             }
6334             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6335                 return false;
6336             }
6337             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6338                 return false;
6339             }
6340             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6341                 return false;
6342             }
6343             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6344                 return false;
6345             }
6346             dmsa0.deleteRow( "c", false );
6347             dmsa0.deleteRow( "d", false );
6348             if ( dmsa0.getNumberOfSequences() != 0 ) {
6349                 return false;
6350             }
6351             //
6352             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6353             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6354             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6355             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6356             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6357             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6358             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6359             l1.add( s_0 );
6360             l1.add( s_1 );
6361             l1.add( s_2 );
6362             l1.add( s_3 );
6363             l1.add( s_4 );
6364             l1.add( s_5 );
6365             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6366             dmsa1.deleteGapOnlyColumns();
6367             dmsa1.deleteRow( "a", false );
6368             dmsa1.deleteRow( "f", false );
6369             dmsa1.deleteRow( "d", false );
6370             dmsa1.deleteGapOnlyColumns();
6371             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6372                 return false;
6373             }
6374             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6375                 return false;
6376             }
6377             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6378                 return false;
6379             }
6380             dmsa1.deleteRow( "c", false );
6381             dmsa1.deleteGapOnlyColumns();
6382             final Writer w0 = new StringWriter();
6383             dmsa1.write( w0, MSA_FORMAT.FASTA );
6384             final Writer w1 = new StringWriter();
6385             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6386             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6387                 return false;
6388             }
6389             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6390                 return false;
6391             }
6392             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6393             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6394             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6395             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6396             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6397             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6398             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6399             l2.add( s__0 );
6400             l2.add( s__1 );
6401             l2.add( s__2 );
6402             l2.add( s__3 );
6403             l2.add( s__4 );
6404             l2.add( s__5 );
6405             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6406             dmsa2.deleteGapColumns( 0.5 );
6407             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6408                 return false;
6409             }
6410             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6411                 return false;
6412             }
6413             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6414                 return false;
6415             }
6416             dmsa2.deleteGapColumns( 0.2 );
6417             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6418                 return false;
6419             }
6420             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6421                 return false;
6422             }
6423             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6424                 return false;
6425             }
6426             dmsa2.deleteGapColumns( 0 );
6427             dmsa2.deleteRow( "a", false );
6428             dmsa2.deleteRow( "b", false );
6429             dmsa2.deleteRow( "f", false );
6430             dmsa2.deleteRow( "e", false );
6431             dmsa2.setIdentifier( 0, "new_c" );
6432             dmsa2.setIdentifier( 1, "new_d" );
6433             dmsa2.setResidueAt( 0, 0, 'x' );
6434             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6435             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6436                 return false;
6437             }
6438             final Writer w = new StringWriter();
6439             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6440             final String phylip = w.toString();
6441             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6442                 System.out.println( phylip );
6443                 return false;
6444             }
6445             final Writer w2 = new StringWriter();
6446             dmsa2.write( w2, MSA_FORMAT.FASTA );
6447             final String fasta = w2.toString();
6448             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6449                 System.out.println( fasta );
6450                 return false;
6451             }
6452         }
6453         catch ( final Exception e ) {
6454             e.printStackTrace( System.out );
6455             return false;
6456         }
6457         return true;
6458     }
6459
6460     private static boolean testNextNodeWithCollapsing() {
6461         try {
6462             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6463             PhylogenyNode n;
6464             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6465             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6466             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6467             t0.getNode( "cd" ).setCollapse( true );
6468             t0.getNode( "cde" ).setCollapse( true );
6469             n = t0.getFirstExternalNode();
6470             while ( n != null ) {
6471                 ext.add( n );
6472                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6473             }
6474             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6475                 return false;
6476             }
6477             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6478                 return false;
6479             }
6480             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6481                 return false;
6482             }
6483             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6484                 return false;
6485             }
6486             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6487                 return false;
6488             }
6489             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6490                 return false;
6491             }
6492             ext.clear();
6493             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6494             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6495             t1.getNode( "ab" ).setCollapse( true );
6496             t1.getNode( "cd" ).setCollapse( true );
6497             t1.getNode( "cde" ).setCollapse( true );
6498             n = t1.getNode( "ab" );
6499             ext = new ArrayList<PhylogenyNode>();
6500             while ( n != null ) {
6501                 ext.add( n );
6502                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6503             }
6504             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6505                 return false;
6506             }
6507             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6508                 return false;
6509             }
6510             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6511                 return false;
6512             }
6513             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6514                 return false;
6515             }
6516             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6517                 return false;
6518             }
6519             ext.clear();
6520             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6521             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6522             t2.getNode( "ab" ).setCollapse( true );
6523             t2.getNode( "cd" ).setCollapse( true );
6524             t2.getNode( "cde" ).setCollapse( true );
6525             t2.getNode( "c" ).setCollapse( true );
6526             t2.getNode( "d" ).setCollapse( true );
6527             t2.getNode( "e" ).setCollapse( true );
6528             t2.getNode( "gh" ).setCollapse( true );
6529             n = t2.getNode( "ab" );
6530             ext = new ArrayList<PhylogenyNode>();
6531             while ( n != null ) {
6532                 ext.add( n );
6533                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6534             }
6535             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6536                 return false;
6537             }
6538             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6539                 return false;
6540             }
6541             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6542                 return false;
6543             }
6544             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6545                 return false;
6546             }
6547             ext.clear();
6548             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6549             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6550             t3.getNode( "ab" ).setCollapse( true );
6551             t3.getNode( "cd" ).setCollapse( true );
6552             t3.getNode( "cde" ).setCollapse( true );
6553             t3.getNode( "c" ).setCollapse( true );
6554             t3.getNode( "d" ).setCollapse( true );
6555             t3.getNode( "e" ).setCollapse( true );
6556             t3.getNode( "gh" ).setCollapse( true );
6557             t3.getNode( "fgh" ).setCollapse( true );
6558             n = t3.getNode( "ab" );
6559             ext = new ArrayList<PhylogenyNode>();
6560             while ( n != null ) {
6561                 ext.add( n );
6562                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6563             }
6564             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6565                 return false;
6566             }
6567             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6568                 return false;
6569             }
6570             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6571                 return false;
6572             }
6573             ext.clear();
6574             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6575             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6576             t4.getNode( "ab" ).setCollapse( true );
6577             t4.getNode( "cd" ).setCollapse( true );
6578             t4.getNode( "cde" ).setCollapse( true );
6579             t4.getNode( "c" ).setCollapse( true );
6580             t4.getNode( "d" ).setCollapse( true );
6581             t4.getNode( "e" ).setCollapse( true );
6582             t4.getNode( "gh" ).setCollapse( true );
6583             t4.getNode( "fgh" ).setCollapse( true );
6584             t4.getNode( "abcdefgh" ).setCollapse( true );
6585             n = t4.getNode( "abcdefgh" );
6586             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6587                 return false;
6588             }
6589             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6590             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6591             ext.clear();
6592             n = t5.getFirstExternalNode();
6593             while ( n != null ) {
6594                 ext.add( n );
6595                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6596             }
6597             if ( ext.size() != 8 ) {
6598                 return false;
6599             }
6600             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6601                 return false;
6602             }
6603             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6604                 return false;
6605             }
6606             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6607                 return false;
6608             }
6609             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6610                 return false;
6611             }
6612             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6613                 return false;
6614             }
6615             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6616                 return false;
6617             }
6618             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6619                 return false;
6620             }
6621             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6622                 return false;
6623             }
6624             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6625             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6626             ext.clear();
6627             t6.getNode( "ab" ).setCollapse( true );
6628             n = t6.getNode( "ab" );
6629             while ( n != null ) {
6630                 ext.add( n );
6631                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6632             }
6633             if ( ext.size() != 7 ) {
6634                 return false;
6635             }
6636             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6637                 return false;
6638             }
6639             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6640                 return false;
6641             }
6642             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6643                 return false;
6644             }
6645             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6646                 return false;
6647             }
6648             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6649                 return false;
6650             }
6651             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6652                 return false;
6653             }
6654             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6655                 return false;
6656             }
6657             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6658             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6659             ext.clear();
6660             t7.getNode( "cd" ).setCollapse( true );
6661             n = t7.getNode( "a" );
6662             while ( n != null ) {
6663                 ext.add( n );
6664                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6665             }
6666             if ( ext.size() != 7 ) {
6667                 return false;
6668             }
6669             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6670                 return false;
6671             }
6672             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6673                 return false;
6674             }
6675             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6676                 return false;
6677             }
6678             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6679                 return false;
6680             }
6681             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6682                 return false;
6683             }
6684             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6685                 return false;
6686             }
6687             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6688                 return false;
6689             }
6690             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6691             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6692             ext.clear();
6693             t8.getNode( "cd" ).setCollapse( true );
6694             t8.getNode( "c" ).setCollapse( true );
6695             t8.getNode( "d" ).setCollapse( true );
6696             n = t8.getNode( "a" );
6697             while ( n != null ) {
6698                 ext.add( n );
6699                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6700             }
6701             if ( ext.size() != 7 ) {
6702                 return false;
6703             }
6704             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6705                 return false;
6706             }
6707             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6708                 return false;
6709             }
6710             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6711                 System.out.println( "2 fail" );
6712                 return false;
6713             }
6714             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6715                 return false;
6716             }
6717             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6718                 return false;
6719             }
6720             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6721                 return false;
6722             }
6723             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6724                 return false;
6725             }
6726             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6727             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6728             ext.clear();
6729             t9.getNode( "gh" ).setCollapse( true );
6730             n = t9.getNode( "a" );
6731             while ( n != null ) {
6732                 ext.add( n );
6733                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6734             }
6735             if ( ext.size() != 7 ) {
6736                 return false;
6737             }
6738             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6739                 return false;
6740             }
6741             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6742                 return false;
6743             }
6744             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6745                 return false;
6746             }
6747             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6748                 return false;
6749             }
6750             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6751                 return false;
6752             }
6753             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6754                 return false;
6755             }
6756             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6757                 return false;
6758             }
6759             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6760             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6761             ext.clear();
6762             t10.getNode( "gh" ).setCollapse( true );
6763             t10.getNode( "g" ).setCollapse( true );
6764             t10.getNode( "h" ).setCollapse( true );
6765             n = t10.getNode( "a" );
6766             while ( n != null ) {
6767                 ext.add( n );
6768                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6769             }
6770             if ( ext.size() != 7 ) {
6771                 return false;
6772             }
6773             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6774                 return false;
6775             }
6776             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6777                 return false;
6778             }
6779             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6780                 return false;
6781             }
6782             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6783                 return false;
6784             }
6785             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6786                 return false;
6787             }
6788             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6789                 return false;
6790             }
6791             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6792                 return false;
6793             }
6794             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6795             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6796             ext.clear();
6797             t11.getNode( "gh" ).setCollapse( true );
6798             t11.getNode( "fgh" ).setCollapse( true );
6799             n = t11.getNode( "a" );
6800             while ( n != null ) {
6801                 ext.add( n );
6802                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6803             }
6804             if ( ext.size() != 6 ) {
6805                 return false;
6806             }
6807             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6808                 return false;
6809             }
6810             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6811                 return false;
6812             }
6813             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6814                 return false;
6815             }
6816             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6817                 return false;
6818             }
6819             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6820                 return false;
6821             }
6822             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6823                 return false;
6824             }
6825             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6826             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6827             ext.clear();
6828             t12.getNode( "gh" ).setCollapse( true );
6829             t12.getNode( "fgh" ).setCollapse( true );
6830             t12.getNode( "g" ).setCollapse( true );
6831             t12.getNode( "h" ).setCollapse( true );
6832             t12.getNode( "f" ).setCollapse( true );
6833             n = t12.getNode( "a" );
6834             while ( n != null ) {
6835                 ext.add( n );
6836                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6837             }
6838             if ( ext.size() != 6 ) {
6839                 return false;
6840             }
6841             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6842                 return false;
6843             }
6844             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6845                 return false;
6846             }
6847             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6848                 return false;
6849             }
6850             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6851                 return false;
6852             }
6853             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6854                 return false;
6855             }
6856             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6857                 return false;
6858             }
6859             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6860             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6861             ext.clear();
6862             t13.getNode( "ab" ).setCollapse( true );
6863             t13.getNode( "b" ).setCollapse( true );
6864             t13.getNode( "fgh" ).setCollapse( true );
6865             t13.getNode( "gh" ).setCollapse( true );
6866             n = t13.getNode( "ab" );
6867             while ( n != null ) {
6868                 ext.add( n );
6869                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6870             }
6871             if ( ext.size() != 5 ) {
6872                 return false;
6873             }
6874             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6875                 return false;
6876             }
6877             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6878                 return false;
6879             }
6880             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6881                 return false;
6882             }
6883             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6884                 return false;
6885             }
6886             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6887                 return false;
6888             }
6889             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6890             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6891             ext.clear();
6892             t14.getNode( "ab" ).setCollapse( true );
6893             t14.getNode( "a" ).setCollapse( true );
6894             t14.getNode( "fgh" ).setCollapse( true );
6895             t14.getNode( "gh" ).setCollapse( true );
6896             n = t14.getNode( "ab" );
6897             while ( n != null ) {
6898                 ext.add( n );
6899                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6900             }
6901             if ( ext.size() != 5 ) {
6902                 return false;
6903             }
6904             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6905                 return false;
6906             }
6907             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6908                 return false;
6909             }
6910             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6911                 return false;
6912             }
6913             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6914                 return false;
6915             }
6916             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6917                 return false;
6918             }
6919             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" );
6920             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6921             ext.clear();
6922             t15.getNode( "ab" ).setCollapse( true );
6923             t15.getNode( "a" ).setCollapse( true );
6924             t15.getNode( "fgh" ).setCollapse( true );
6925             t15.getNode( "gh" ).setCollapse( true );
6926             n = t15.getNode( "ab" );
6927             while ( n != null ) {
6928                 ext.add( n );
6929                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6930             }
6931             if ( ext.size() != 6 ) {
6932                 return false;
6933             }
6934             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6935                 return false;
6936             }
6937             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6938                 return false;
6939             }
6940             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6941                 return false;
6942             }
6943             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6944                 return false;
6945             }
6946             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6947                 return false;
6948             }
6949             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6950                 return false;
6951             }
6952             //
6953             //
6954             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" );
6955             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6956             ext.clear();
6957             t16.getNode( "ab" ).setCollapse( true );
6958             t16.getNode( "a" ).setCollapse( true );
6959             t16.getNode( "fgh" ).setCollapse( true );
6960             t16.getNode( "gh" ).setCollapse( true );
6961             t16.getNode( "cd" ).setCollapse( true );
6962             t16.getNode( "cde" ).setCollapse( true );
6963             t16.getNode( "d" ).setCollapse( true );
6964             t16.getNode( "x" ).setCollapse( true );
6965             n = t16.getNode( "ab" );
6966             while ( n != null ) {
6967                 ext.add( n );
6968                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6969             }
6970             if ( ext.size() != 4 ) {
6971                 return false;
6972             }
6973             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6974                 return false;
6975             }
6976             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6977                 return false;
6978             }
6979             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6980                 return false;
6981             }
6982             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6983                 return false;
6984             }
6985         }
6986         catch ( final Exception e ) {
6987             e.printStackTrace( System.out );
6988             return false;
6989         }
6990         return true;
6991     }
6992
6993     private static boolean testNexusCharactersParsing() {
6994         try {
6995             final NexusCharactersParser parser = new NexusCharactersParser();
6996             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6997             parser.parse();
6998             String[] labels = parser.getCharStateLabels();
6999             if ( labels.length != 7 ) {
7000                 return false;
7001             }
7002             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7003                 return false;
7004             }
7005             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7006                 return false;
7007             }
7008             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7009                 return false;
7010             }
7011             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7012                 return false;
7013             }
7014             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7015                 return false;
7016             }
7017             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7018                 return false;
7019             }
7020             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7021                 return false;
7022             }
7023             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7024             parser.parse();
7025             labels = parser.getCharStateLabels();
7026             if ( labels.length != 7 ) {
7027                 return false;
7028             }
7029             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7030                 return false;
7031             }
7032             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7033                 return false;
7034             }
7035             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7036                 return false;
7037             }
7038             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7039                 return false;
7040             }
7041             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7042                 return false;
7043             }
7044             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7045                 return false;
7046             }
7047             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7048                 return false;
7049             }
7050         }
7051         catch ( final Exception e ) {
7052             e.printStackTrace( System.out );
7053             return false;
7054         }
7055         return true;
7056     }
7057
7058     private static boolean testNexusMatrixParsing() {
7059         try {
7060             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7061             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7062             parser.parse();
7063             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7064             if ( m.getNumberOfCharacters() != 9 ) {
7065                 return false;
7066             }
7067             if ( m.getNumberOfIdentifiers() != 5 ) {
7068                 return false;
7069             }
7070             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7071                 return false;
7072             }
7073             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7074                 return false;
7075             }
7076             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7077                 return false;
7078             }
7079             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7080                 return false;
7081             }
7082             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7083                 return false;
7084             }
7085             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7086                 return false;
7087             }
7088             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7089                 return false;
7090             }
7091             //            if ( labels.length != 7 ) {
7092             //                return false;
7093             //            }
7094             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7095             //                return false;
7096             //            }
7097             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7098             //                return false;
7099             //            }
7100             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7101             //                return false;
7102             //            }
7103             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7104             //                return false;
7105             //            }
7106             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7107             //                return false;
7108             //            }
7109             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7110             //                return false;
7111             //            }
7112             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7113             //                return false;
7114             //            }
7115             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7116             //            parser.parse();
7117             //            labels = parser.getCharStateLabels();
7118             //            if ( labels.length != 7 ) {
7119             //                return false;
7120             //            }
7121             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7122             //                return false;
7123             //            }
7124             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7125             //                return false;
7126             //            }
7127             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7128             //                return false;
7129             //            }
7130             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7131             //                return false;
7132             //            }
7133             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7134             //                return false;
7135             //            }
7136             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7137             //                return false;
7138             //            }
7139             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7140             //                return false;
7141             //            }
7142         }
7143         catch ( final Exception e ) {
7144             e.printStackTrace( System.out );
7145             return false;
7146         }
7147         return true;
7148     }
7149
7150     private static boolean testNexusTreeParsing() {
7151         try {
7152             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7153             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7154             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7155             if ( phylogenies.length != 1 ) {
7156                 return false;
7157             }
7158             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7159                 return false;
7160             }
7161             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7162                 return false;
7163             }
7164             phylogenies = null;
7165             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7166             if ( phylogenies.length != 1 ) {
7167                 return false;
7168             }
7169             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7170                 return false;
7171             }
7172             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7173                 return false;
7174             }
7175             phylogenies = null;
7176             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7177             if ( phylogenies.length != 1 ) {
7178                 return false;
7179             }
7180             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7181                 return false;
7182             }
7183             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7184                 return false;
7185             }
7186             if ( phylogenies[ 0 ].isRooted() ) {
7187                 return false;
7188             }
7189             phylogenies = null;
7190             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7191             if ( phylogenies.length != 18 ) {
7192                 return false;
7193             }
7194             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7195                 return false;
7196             }
7197             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7198                 return false;
7199             }
7200             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7201                 return false;
7202             }
7203             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7204                 return false;
7205             }
7206             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7207                 return false;
7208             }
7209             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7210                 return false;
7211             }
7212             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7213                 return false;
7214             }
7215             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7216                 return false;
7217             }
7218             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7219                 return false;
7220             }
7221             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7222                 return false;
7223             }
7224             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7225                 return false;
7226             }
7227             if ( phylogenies[ 8 ].isRooted() ) {
7228                 return false;
7229             }
7230             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7231                 return false;
7232             }
7233             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7234                 return false;
7235             }
7236             if ( !phylogenies[ 9 ].isRooted() ) {
7237                 return false;
7238             }
7239             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7240                 return false;
7241             }
7242             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7243                 return false;
7244             }
7245             if ( !phylogenies[ 10 ].isRooted() ) {
7246                 return false;
7247             }
7248             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7249                 return false;
7250             }
7251             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7252                 return false;
7253             }
7254             if ( phylogenies[ 11 ].isRooted() ) {
7255                 return false;
7256             }
7257             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7258                 return false;
7259             }
7260             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7261                 return false;
7262             }
7263             if ( !phylogenies[ 12 ].isRooted() ) {
7264                 return false;
7265             }
7266             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7267                 return false;
7268             }
7269             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7270                 return false;
7271             }
7272             if ( !phylogenies[ 13 ].isRooted() ) {
7273                 return false;
7274             }
7275             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7276                 return false;
7277             }
7278             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7279                 return false;
7280             }
7281             if ( !phylogenies[ 14 ].isRooted() ) {
7282                 return false;
7283             }
7284             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7285                 return false;
7286             }
7287             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7288                 return false;
7289             }
7290             if ( phylogenies[ 15 ].isRooted() ) {
7291                 return false;
7292             }
7293             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7294                 return false;
7295             }
7296             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7297                 return false;
7298             }
7299             if ( !phylogenies[ 16 ].isRooted() ) {
7300                 return false;
7301             }
7302             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7303                 return false;
7304             }
7305             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7306                 return false;
7307             }
7308             if ( phylogenies[ 17 ].isRooted() ) {
7309                 return false;
7310             }
7311             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7312                 return false;
7313             }
7314             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7315             phylogenies = null;
7316             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7317             if ( phylogenies.length != 9 ) {
7318                 return false;
7319             }
7320             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7321                            .getDistanceToParent() ) ) {
7322                 return false;
7323             }
7324             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7325                            .getDistanceToParent() ) ) {
7326                 return false;
7327             }
7328             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7329                 return false;
7330             }
7331             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7332                 return false;
7333             }
7334             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7335                 return false;
7336             }
7337             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7338                 return false;
7339             }
7340             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7341                 return false;
7342             }
7343         }
7344         catch ( final Exception e ) {
7345             e.printStackTrace( System.out );
7346             return false;
7347         }
7348         return true;
7349     }
7350
7351     private static boolean testNexusTreeParsingIterating() {
7352         try {
7353             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7354             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7355             if ( !p.hasNext() ) {
7356                 return false;
7357             }
7358             Phylogeny phy = p.next();
7359             if ( phy == null ) {
7360                 return false;
7361             }
7362             if ( phy.getNumberOfExternalNodes() != 25 ) {
7363                 return false;
7364             }
7365             if ( !phy.getName().equals( "" ) ) {
7366                 return false;
7367             }
7368             if ( p.hasNext() ) {
7369                 return false;
7370             }
7371             phy = p.next();
7372             if ( phy != null ) {
7373                 return false;
7374             }
7375             p.reset();
7376             if ( !p.hasNext() ) {
7377                 return false;
7378             }
7379             phy = p.next();
7380             if ( phy == null ) {
7381                 return false;
7382             }
7383             if ( phy.getNumberOfExternalNodes() != 25 ) {
7384                 return false;
7385             }
7386             if ( !phy.getName().equals( "" ) ) {
7387                 return false;
7388             }
7389             if ( p.hasNext() ) {
7390                 return false;
7391             }
7392             phy = p.next();
7393             if ( phy != null ) {
7394                 return false;
7395             }
7396             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7397             if ( !p.hasNext() ) {
7398                 return false;
7399             }
7400             phy = p.next();
7401             if ( phy == null ) {
7402                 return false;
7403             }
7404             if ( phy.getNumberOfExternalNodes() != 10 ) {
7405                 return false;
7406             }
7407             if ( !phy.getName().equals( "name" ) ) {
7408                 return false;
7409             }
7410             if ( p.hasNext() ) {
7411                 return false;
7412             }
7413             phy = p.next();
7414             if ( phy != null ) {
7415                 return false;
7416             }
7417             p.reset();
7418             if ( !p.hasNext() ) {
7419                 return false;
7420             }
7421             phy = p.next();
7422             if ( phy == null ) {
7423                 return false;
7424             }
7425             if ( phy.getNumberOfExternalNodes() != 10 ) {
7426                 return false;
7427             }
7428             if ( !phy.getName().equals( "name" ) ) {
7429                 return false;
7430             }
7431             if ( p.hasNext() ) {
7432                 return false;
7433             }
7434             phy = p.next();
7435             if ( phy != null ) {
7436                 return false;
7437             }
7438             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7439             if ( !p.hasNext() ) {
7440                 return false;
7441             }
7442             phy = p.next();
7443             if ( phy == null ) {
7444                 return false;
7445             }
7446             if ( phy.getNumberOfExternalNodes() != 3 ) {
7447                 return false;
7448             }
7449             if ( !phy.getName().equals( "" ) ) {
7450                 return false;
7451             }
7452             if ( phy.isRooted() ) {
7453                 return false;
7454             }
7455             if ( p.hasNext() ) {
7456                 return false;
7457             }
7458             phy = p.next();
7459             if ( phy != null ) {
7460                 return false;
7461             }
7462             //
7463             p.reset();
7464             if ( !p.hasNext() ) {
7465                 return false;
7466             }
7467             phy = p.next();
7468             if ( phy == null ) {
7469                 return false;
7470             }
7471             if ( phy.getNumberOfExternalNodes() != 3 ) {
7472                 return false;
7473             }
7474             if ( !phy.getName().equals( "" ) ) {
7475                 return false;
7476             }
7477             if ( p.hasNext() ) {
7478                 return false;
7479             }
7480             phy = p.next();
7481             if ( phy != null ) {
7482                 return false;
7483             }
7484             //
7485             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7486             if ( !p.hasNext() ) {
7487                 return false;
7488             }
7489             //0
7490             phy = p.next();
7491             if ( phy == null ) {
7492                 return false;
7493             }
7494             if ( phy.getNumberOfExternalNodes() != 10 ) {
7495                 return false;
7496             }
7497             if ( !phy.getName().equals( "tree 0" ) ) {
7498                 return false;
7499             }
7500             //1
7501             if ( !p.hasNext() ) {
7502                 return false;
7503             }
7504             phy = p.next();
7505             if ( phy == null ) {
7506                 return false;
7507             }
7508             if ( phy.getNumberOfExternalNodes() != 10 ) {
7509                 return false;
7510             }
7511             if ( !phy.getName().equals( "tree 1" ) ) {
7512                 return false;
7513             }
7514             //2
7515             if ( !p.hasNext() ) {
7516                 return false;
7517             }
7518             phy = p.next();
7519             if ( phy == null ) {
7520                 return false;
7521             }
7522             if ( phy.getNumberOfExternalNodes() != 3 ) {
7523                 System.out.println( phy.toString() );
7524                 return false;
7525             }
7526             if ( !phy.getName().equals( "" ) ) {
7527                 return false;
7528             }
7529             if ( phy.isRooted() ) {
7530                 return false;
7531             }
7532             //3
7533             if ( !p.hasNext() ) {
7534                 return false;
7535             }
7536             phy = p.next();
7537             if ( phy == null ) {
7538                 return false;
7539             }
7540             if ( phy.getNumberOfExternalNodes() != 4 ) {
7541                 return false;
7542             }
7543             if ( !phy.getName().equals( "" ) ) {
7544                 return false;
7545             }
7546             if ( !phy.isRooted() ) {
7547                 return false;
7548             }
7549             //4
7550             if ( !p.hasNext() ) {
7551                 return false;
7552             }
7553             phy = p.next();
7554             if ( phy == null ) {
7555                 return false;
7556             }
7557             if ( phy.getNumberOfExternalNodes() != 5 ) {
7558                 System.out.println( phy.getNumberOfExternalNodes() );
7559                 return false;
7560             }
7561             if ( !phy.getName().equals( "" ) ) {
7562                 return false;
7563             }
7564             if ( !phy.isRooted() ) {
7565                 return false;
7566             }
7567             //5
7568             if ( !p.hasNext() ) {
7569                 return false;
7570             }
7571             phy = p.next();
7572             if ( phy == null ) {
7573                 return false;
7574             }
7575             if ( phy.getNumberOfExternalNodes() != 3 ) {
7576                 return false;
7577             }
7578             if ( !phy.getName().equals( "" ) ) {
7579                 return false;
7580             }
7581             if ( phy.isRooted() ) {
7582                 return false;
7583             }
7584             //6
7585             if ( !p.hasNext() ) {
7586                 return false;
7587             }
7588             phy = p.next();
7589             if ( phy == null ) {
7590                 return false;
7591             }
7592             if ( phy.getNumberOfExternalNodes() != 2 ) {
7593                 return false;
7594             }
7595             if ( !phy.getName().equals( "" ) ) {
7596                 return false;
7597             }
7598             if ( !phy.isRooted() ) {
7599                 return false;
7600             }
7601             //7
7602             if ( !p.hasNext() ) {
7603                 return false;
7604             }
7605             phy = p.next();
7606             if ( phy.getNumberOfExternalNodes() != 3 ) {
7607                 return false;
7608             }
7609             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7610                 return false;
7611             }
7612             if ( !phy.isRooted() ) {
7613                 return false;
7614             }
7615             //8
7616             if ( !p.hasNext() ) {
7617                 return false;
7618             }
7619             phy = p.next();
7620             if ( phy.getNumberOfExternalNodes() != 3 ) {
7621                 return false;
7622             }
7623             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7624                 return false;
7625             }
7626             if ( !phy.getName().equals( "tree 8" ) ) {
7627                 return false;
7628             }
7629             //9
7630             if ( !p.hasNext() ) {
7631                 return false;
7632             }
7633             phy = p.next();
7634             if ( phy.getNumberOfExternalNodes() != 3 ) {
7635                 return false;
7636             }
7637             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7638                 return false;
7639             }
7640             if ( !phy.getName().equals( "tree 9" ) ) {
7641                 return false;
7642             }
7643             //10
7644             if ( !p.hasNext() ) {
7645                 return false;
7646             }
7647             phy = p.next();
7648             if ( phy.getNumberOfExternalNodes() != 3 ) {
7649                 return false;
7650             }
7651             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7652                 return false;
7653             }
7654             if ( !phy.getName().equals( "tree 10" ) ) {
7655                 return false;
7656             }
7657             if ( !phy.isRooted() ) {
7658                 return false;
7659             }
7660             //11
7661             if ( !p.hasNext() ) {
7662                 return false;
7663             }
7664             phy = p.next();
7665             if ( phy.getNumberOfExternalNodes() != 3 ) {
7666                 return false;
7667             }
7668             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7669                 return false;
7670             }
7671             if ( !phy.getName().equals( "tree 11" ) ) {
7672                 return false;
7673             }
7674             if ( phy.isRooted() ) {
7675                 return false;
7676             }
7677             //12
7678             if ( !p.hasNext() ) {
7679                 return false;
7680             }
7681             phy = p.next();
7682             if ( phy.getNumberOfExternalNodes() != 3 ) {
7683                 return false;
7684             }
7685             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7686                 return false;
7687             }
7688             if ( !phy.getName().equals( "tree 12" ) ) {
7689                 return false;
7690             }
7691             if ( !phy.isRooted() ) {
7692                 return false;
7693             }
7694             //13
7695             if ( !p.hasNext() ) {
7696                 return false;
7697             }
7698             phy = p.next();
7699             if ( phy.getNumberOfExternalNodes() != 3 ) {
7700                 return false;
7701             }
7702             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7703                 return false;
7704             }
7705             if ( !phy.getName().equals( "tree 13" ) ) {
7706                 return false;
7707             }
7708             if ( !phy.isRooted() ) {
7709                 return false;
7710             }
7711             //14
7712             if ( !p.hasNext() ) {
7713                 return false;
7714             }
7715             phy = p.next();
7716             if ( phy.getNumberOfExternalNodes() != 10 ) {
7717                 System.out.println( phy.getNumberOfExternalNodes() );
7718                 return false;
7719             }
7720             if ( !phy
7721                     .toNewHampshire()
7722                     .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;" ) ) {
7723                 System.out.println( phy.toNewHampshire() );
7724                 return false;
7725             }
7726             if ( !phy.getName().equals( "tree 14" ) ) {
7727                 return false;
7728             }
7729             if ( !phy.isRooted() ) {
7730                 return false;
7731             }
7732             //15
7733             if ( !p.hasNext() ) {
7734                 return false;
7735             }
7736             phy = p.next();
7737             if ( phy.getNumberOfExternalNodes() != 10 ) {
7738                 System.out.println( phy.getNumberOfExternalNodes() );
7739                 return false;
7740             }
7741             if ( !phy
7742                     .toNewHampshire()
7743                     .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;" ) ) {
7744                 System.out.println( phy.toNewHampshire() );
7745                 return false;
7746             }
7747             if ( !phy.getName().equals( "tree 15" ) ) {
7748                 return false;
7749             }
7750             if ( phy.isRooted() ) {
7751                 return false;
7752             }
7753             //16
7754             if ( !p.hasNext() ) {
7755                 return false;
7756             }
7757             phy = p.next();
7758             if ( phy.getNumberOfExternalNodes() != 10 ) {
7759                 System.out.println( phy.getNumberOfExternalNodes() );
7760                 return false;
7761             }
7762             if ( !phy
7763                     .toNewHampshire()
7764                     .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;" ) ) {
7765                 System.out.println( phy.toNewHampshire() );
7766                 return false;
7767             }
7768             if ( !phy.getName().equals( "tree 16" ) ) {
7769                 return false;
7770             }
7771             if ( !phy.isRooted() ) {
7772                 return false;
7773             }
7774             //17
7775             if ( !p.hasNext() ) {
7776                 return false;
7777             }
7778             phy = p.next();
7779             if ( phy.getNumberOfExternalNodes() != 10 ) {
7780                 System.out.println( phy.getNumberOfExternalNodes() );
7781                 return false;
7782             }
7783             if ( !phy
7784                     .toNewHampshire()
7785                     .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;" ) ) {
7786                 System.out.println( phy.toNewHampshire() );
7787                 return false;
7788             }
7789             if ( !phy.getName().equals( "tree 17" ) ) {
7790                 return false;
7791             }
7792             if ( phy.isRooted() ) {
7793                 return false;
7794             }
7795             //
7796             if ( p.hasNext() ) {
7797                 return false;
7798             }
7799             phy = p.next();
7800             if ( phy != null ) {
7801                 return false;
7802             }
7803             p.reset();
7804             //0
7805             if ( !p.hasNext() ) {
7806                 return false;
7807             }
7808             phy = p.next();
7809             if ( phy == null ) {
7810                 return false;
7811             }
7812             if ( phy.getNumberOfExternalNodes() != 10 ) {
7813                 return false;
7814             }
7815             if ( !phy.getName().equals( "tree 0" ) ) {
7816                 return false;
7817             }
7818             //1
7819             if ( !p.hasNext() ) {
7820                 return false;
7821             }
7822             phy = p.next();
7823             if ( phy == null ) {
7824                 return false;
7825             }
7826             if ( phy.getNumberOfExternalNodes() != 10 ) {
7827                 return false;
7828             }
7829             if ( !phy.getName().equals( "tree 1" ) ) {
7830                 return false;
7831             }
7832             //2
7833             if ( !p.hasNext() ) {
7834                 return false;
7835             }
7836             phy = p.next();
7837             if ( phy == null ) {
7838                 return false;
7839             }
7840             if ( phy.getNumberOfExternalNodes() != 3 ) {
7841                 return false;
7842             }
7843             if ( !phy.getName().equals( "" ) ) {
7844                 return false;
7845             }
7846             if ( phy.isRooted() ) {
7847                 return false;
7848             }
7849             //3
7850             if ( !p.hasNext() ) {
7851                 return false;
7852             }
7853             phy = p.next();
7854             if ( phy == null ) {
7855                 return false;
7856             }
7857             if ( phy.getNumberOfExternalNodes() != 4 ) {
7858                 return false;
7859             }
7860             if ( !phy.getName().equals( "" ) ) {
7861                 return false;
7862             }
7863             if ( !phy.isRooted() ) {
7864                 return false;
7865             }
7866             //4
7867             if ( !p.hasNext() ) {
7868                 return false;
7869             }
7870             phy = p.next();
7871             if ( phy == null ) {
7872                 return false;
7873             }
7874             if ( phy.getNumberOfExternalNodes() != 5 ) {
7875                 System.out.println( phy.getNumberOfExternalNodes() );
7876                 return false;
7877             }
7878             if ( !phy.getName().equals( "" ) ) {
7879                 return false;
7880             }
7881             if ( !phy.isRooted() ) {
7882                 return false;
7883             }
7884             //5
7885             if ( !p.hasNext() ) {
7886                 return false;
7887             }
7888             phy = p.next();
7889             if ( phy == null ) {
7890                 return false;
7891             }
7892             if ( phy.getNumberOfExternalNodes() != 3 ) {
7893                 return false;
7894             }
7895             if ( !phy.getName().equals( "" ) ) {
7896                 return false;
7897             }
7898             if ( phy.isRooted() ) {
7899                 return false;
7900             }
7901             //
7902             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7903             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7904             // 0
7905             if ( !p2.hasNext() ) {
7906                 return false;
7907             }
7908             phy = p2.next();
7909             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7910                 return false;
7911             }
7912             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7913                 return false;
7914             }
7915             // 1
7916             if ( !p2.hasNext() ) {
7917                 return false;
7918             }
7919             phy = p2.next();
7920             // 2
7921             if ( !p2.hasNext() ) {
7922                 return false;
7923             }
7924             phy = p2.next();
7925             // 3
7926             if ( !p2.hasNext() ) {
7927                 return false;
7928             }
7929             phy = p2.next();
7930             // 4
7931             if ( !p2.hasNext() ) {
7932                 return false;
7933             }
7934             phy = p2.next();
7935             // 5
7936             if ( !p2.hasNext() ) {
7937                 return false;
7938             }
7939             phy = p2.next();
7940             // 6
7941             if ( !p2.hasNext() ) {
7942                 return false;
7943             }
7944             phy = p2.next();
7945             // 7
7946             if ( !p2.hasNext() ) {
7947                 return false;
7948             }
7949             phy = p2.next();
7950             // 8
7951             if ( !p2.hasNext() ) {
7952                 return false;
7953             }
7954             phy = p2.next();
7955             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7956                 return false;
7957             }
7958             if ( p2.hasNext() ) {
7959                 return false;
7960             }
7961             phy = p2.next();
7962             if ( phy != null ) {
7963                 return false;
7964             }
7965             // 0
7966             p2.reset();
7967             if ( !p2.hasNext() ) {
7968                 return false;
7969             }
7970             phy = p2.next();
7971             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7972                 return false;
7973             }
7974             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7975                 return false;
7976             }
7977         }
7978         catch ( final Exception e ) {
7979             e.printStackTrace( System.out );
7980             return false;
7981         }
7982         return true;
7983     }
7984
7985     private static boolean testNexusTreeParsingTranslating() {
7986         try {
7987             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7988             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7989             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7990             if ( phylogenies.length != 1 ) {
7991                 return false;
7992             }
7993             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7994                 return false;
7995             }
7996             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7997                 return false;
7998             }
7999             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8000                 return false;
8001             }
8002             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8003                 return false;
8004             }
8005             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8006                     .equals( "Aranaeus" ) ) {
8007                 return false;
8008             }
8009             phylogenies = null;
8010             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
8011             if ( phylogenies.length != 3 ) {
8012                 return false;
8013             }
8014             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8015                 return false;
8016             }
8017             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8018                 return false;
8019             }
8020             if ( phylogenies[ 0 ].isRooted() ) {
8021                 return false;
8022             }
8023             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8024                 return false;
8025             }
8026             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8027                 return false;
8028             }
8029             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8030                     .equals( "Aranaeus" ) ) {
8031                 return false;
8032             }
8033             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8034                 return false;
8035             }
8036             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8037                 return false;
8038             }
8039             if ( phylogenies[ 1 ].isRooted() ) {
8040                 return false;
8041             }
8042             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8043                 return false;
8044             }
8045             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8046                 return false;
8047             }
8048             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8049                     .equals( "Aranaeus" ) ) {
8050                 return false;
8051             }
8052             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8053                 return false;
8054             }
8055             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8056                 return false;
8057             }
8058             if ( !phylogenies[ 2 ].isRooted() ) {
8059                 return false;
8060             }
8061             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8062                 return false;
8063             }
8064             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8065                 return false;
8066             }
8067             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8068                     .equals( "Aranaeus" ) ) {
8069                 return false;
8070             }
8071             phylogenies = null;
8072             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8073             if ( phylogenies.length != 3 ) {
8074                 return false;
8075             }
8076             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8077                 return false;
8078             }
8079             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8080                 return false;
8081             }
8082             if ( phylogenies[ 0 ].isRooted() ) {
8083                 return false;
8084             }
8085             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8086                 return false;
8087             }
8088             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8089                 return false;
8090             }
8091             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8092                     .equals( "Aranaeus" ) ) {
8093                 return false;
8094             }
8095             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8096                 return false;
8097             }
8098             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8099                 return false;
8100             }
8101             if ( phylogenies[ 1 ].isRooted() ) {
8102                 return false;
8103             }
8104             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8105                 return false;
8106             }
8107             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8108                 return false;
8109             }
8110             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8111                     .equals( "Aranaeus" ) ) {
8112                 return false;
8113             }
8114             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8115                 return false;
8116             }
8117             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8118                 return false;
8119             }
8120             if ( !phylogenies[ 2 ].isRooted() ) {
8121                 return false;
8122             }
8123             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8124                 return false;
8125             }
8126             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8127                 return false;
8128             }
8129             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8130                     .equals( "Aranaeus" ) ) {
8131                 return false;
8132             }
8133             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8134             if ( phylogenies.length != 3 ) {
8135                 return false;
8136             }
8137             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8138                            0.00100049 ) ) {
8139                 return false;
8140             }
8141         }
8142         catch ( final Exception e ) {
8143             e.printStackTrace( System.out );
8144             return false;
8145         }
8146         return true;
8147     }
8148
8149     private static boolean testNHParsing() {
8150         try {
8151             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8152             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8153             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8154                 return false;
8155             }
8156             final NHXParser nhxp = new NHXParser();
8157             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8158             nhxp.setReplaceUnderscores( true );
8159             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8160             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8161                 return false;
8162             }
8163             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8164                 return false;
8165             }
8166             final Phylogeny p1b = factory
8167                     .create( "   \n  \t  \b   \r \f   ; (  \n  \t  \b   \r \f; A ;  \n  \t  \b   \r \f,  \n  \t  \b   \r \f; B ;   \n  \t  \b   \r \f 1  \n  \t  \b   \r \f ;  \n  \t  \b   \r \f );;;;; \n  \t  \b   \r \f;;;  \n  \t  \b   \r \f ",
8168                              new NHXParser() )[ 0 ];
8169             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8170                 return false;
8171             }
8172             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8173                 return false;
8174             }
8175             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
8176             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8177             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8178             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
8179             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8180             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8181             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8182             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8183             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8184             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8185             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8186                     + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8187                     + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8188                     new NHXParser() );
8189             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8190                 return false;
8191             }
8192             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8193                 return false;
8194             }
8195             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8196                 return false;
8197             }
8198             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8199                 return false;
8200             }
8201             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8202             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8203             final String p16_S = "((A,B),C)";
8204             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8205             if ( p16.length != 1 ) {
8206                 return false;
8207             }
8208             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8209                 return false;
8210             }
8211             final String p17_S = "(C,(A,B))";
8212             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8213             if ( p17.length != 1 ) {
8214                 return false;
8215             }
8216             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8217                 return false;
8218             }
8219             final String p18_S = "((A,B),(C,D))";
8220             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8221             if ( p18.length != 1 ) {
8222                 return false;
8223             }
8224             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8225                 return false;
8226             }
8227             final String p19_S = "(((A,B),C),D)";
8228             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8229             if ( p19.length != 1 ) {
8230                 return false;
8231             }
8232             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8233                 return false;
8234             }
8235             final String p20_S = "(A,(B,(C,D)))";
8236             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8237             if ( p20.length != 1 ) {
8238                 return false;
8239             }
8240             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8241                 return false;
8242             }
8243             final String p21_S = "(A,(B,(C,(D,E))))";
8244             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8245             if ( p21.length != 1 ) {
8246                 return false;
8247             }
8248             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8249                 return false;
8250             }
8251             final String p22_S = "((((A,B),C),D),E)";
8252             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8253             if ( p22.length != 1 ) {
8254                 return false;
8255             }
8256             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8257                 return false;
8258             }
8259             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8260             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8261             if ( p23.length != 1 ) {
8262                 System.out.println( "xl=" + p23.length );
8263                 System.exit( -1 );
8264                 return false;
8265             }
8266             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8267                 return false;
8268             }
8269             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8270             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8271             if ( p24.length != 1 ) {
8272                 return false;
8273             }
8274             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8275                 return false;
8276             }
8277             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8278             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8279             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8280             if ( p241.length != 2 ) {
8281                 return false;
8282             }
8283             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8284                 return false;
8285             }
8286             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8287                 return false;
8288             }
8289             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8290                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8291                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8292                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8293                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8294                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8295                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8296                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8297             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8298             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8299                 return false;
8300             }
8301             final String p26_S = "(A,B)ab";
8302             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8303             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8304                 return false;
8305             }
8306             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8307             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8308             if ( p27s.length != 1 ) {
8309                 System.out.println( "xxl=" + p27s.length );
8310                 System.exit( -1 );
8311                 return false;
8312             }
8313             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8314                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8315                 System.exit( -1 );
8316                 return false;
8317             }
8318             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8319                                                     new NHXParser() );
8320             if ( p27.length != 1 ) {
8321                 System.out.println( "yl=" + p27.length );
8322                 System.exit( -1 );
8323                 return false;
8324             }
8325             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8326                 System.out.println( p27[ 0 ].toNewHampshireX() );
8327                 System.exit( -1 );
8328                 return false;
8329             }
8330             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8331             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8332             final String p28_S3 = "(A,B)ab";
8333             final String p28_S4 = "((((A,B),C),D),;E;)";
8334             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8335                                                     new NHXParser() );
8336             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8337                 return false;
8338             }
8339             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8340                 return false;
8341             }
8342             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8343                 return false;
8344             }
8345             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8346                 return false;
8347             }
8348             if ( p28.length != 4 ) {
8349                 return false;
8350             }
8351             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";
8352             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8353             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8354                 return false;
8355             }
8356             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";
8357             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8358             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8359                 return false;
8360             }
8361             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8362             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8363             if ( ( p32.length != 0 ) ) {
8364                 return false;
8365             }
8366             final String p33_S = "A";
8367             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8368             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8369                 return false;
8370             }
8371             final String p34_S = "B;";
8372             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8373             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8374                 return false;
8375             }
8376             final String p35_S = "B:0.2";
8377             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8378             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8379                 return false;
8380             }
8381             final String p36_S = "(A)";
8382             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8383             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8384                 return false;
8385             }
8386             final String p37_S = "((A))";
8387             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8388             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8389                 return false;
8390             }
8391             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8392             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8393             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8394                 return false;
8395             }
8396             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8397             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8398             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8399                 return false;
8400             }
8401             final String p40_S = "(A,B,C)";
8402             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8403             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8404                 return false;
8405             }
8406             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8407             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8408             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8409                 return false;
8410             }
8411             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8412             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8413             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8414                 return false;
8415             }
8416             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)";
8417             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8418             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8419                 return false;
8420             }
8421             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)))";
8422             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8423             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8424                 return false;
8425             }
8426             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8427             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8428             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8429                 return false;
8430             }
8431             final String p46_S = "";
8432             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8433             if ( p46.length != 0 ) {
8434                 return false;
8435             }
8436             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8437             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8438                 return false;
8439             }
8440             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8441             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8442                 return false;
8443             }
8444             final Phylogeny p49 = factory
8445                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8446                              new NHXParser() )[ 0 ];
8447             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8448                 return false;
8449             }
8450             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8451             if ( p50.getNode( "A" ) == null ) {
8452                 return false;
8453             }
8454             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8455                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8456                 return false;
8457             }
8458             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8459                 return false;
8460             }
8461             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8462                     .equals( "((A,B)88:2.0,C);" ) ) {
8463                 return false;
8464             }
8465             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8466             if ( p51.getNode( "A(A" ) == null ) {
8467                 return false;
8468             }
8469             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8470             if ( p52.getNode( "A(A" ) == null ) {
8471                 return false;
8472             }
8473             final Phylogeny p53 = factory
8474                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8475                              new NHXParser() )[ 0 ];
8476             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8477                 return false;
8478             }
8479             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8480             if ( p54.getNode( "A" ) == null ) {
8481                 return false;
8482             }
8483             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8484                 return false;
8485             }
8486             final Phylogeny p55 = factory
8487                     .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);" ),
8488                              new NHXParser() )[ 0 ];
8489             if ( !p55
8490                     .toNewHampshire()
8491                     .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);" ) ) {
8492                 System.out.println( p55.toNewHampshire() );
8493                 return false;
8494             }
8495             final Phylogeny p56 = factory
8496                     .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);" ),
8497                              new NHXParser() )[ 0 ];
8498             if ( !p56
8499                     .toNewHampshire()
8500                     .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);" ) ) {
8501                 System.out.println( p56.toNewHampshire() );
8502                 return false;
8503             }
8504             final Phylogeny p57 = factory
8505                     .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);" ),
8506                              new NHXParser() )[ 0 ];
8507             if ( !p57
8508                     .toNewHampshire()
8509                     .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);" ) ) {
8510                 System.out.println( p56.toNewHampshire() );
8511                 return false;
8512             }
8513             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8514             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8515             if ( !p58.toNewHampshire().equals( s58 ) ) {
8516                 System.out.println( p58.toNewHampshire() );
8517                 return false;
8518             }
8519             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8520             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8521             if ( !p59.toNewHampshire().equals( s59 ) ) {
8522                 System.out.println( p59.toNewHampshire() );
8523                 return false;
8524             }
8525             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8526             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8527             if ( !p60.toNewHampshire().equals( s60 ) ) {
8528                 System.out.println( p60.toNewHampshire() );
8529                 return false;
8530             }
8531             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8532             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8533             if ( !p61.toNewHampshire()
8534                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8535                 System.out.println( p61.toNewHampshire() );
8536                 return false;
8537             }
8538         }
8539         catch ( final Exception e ) {
8540             e.printStackTrace( System.out );
8541             return false;
8542         }
8543         return true;
8544     }
8545
8546     private static boolean testNHParsingIter() {
8547         try {
8548             final String p0_str = "(A,B);";
8549             final NHXParser p = new NHXParser();
8550             p.setSource( p0_str );
8551             if ( !p.hasNext() ) {
8552                 return false;
8553             }
8554             final Phylogeny p0 = p.next();
8555             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8556                 System.out.println( p0.toNewHampshire() );
8557                 return false;
8558             }
8559             if ( p.hasNext() ) {
8560                 return false;
8561             }
8562             if ( p.next() != null ) {
8563                 return false;
8564             }
8565             //
8566             final String p00_str = "(A,B)root;";
8567             p.setSource( p00_str );
8568             final Phylogeny p00 = p.next();
8569             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8570                 System.out.println( p00.toNewHampshire() );
8571                 return false;
8572             }
8573             //
8574             final String p000_str = "A;";
8575             p.setSource( p000_str );
8576             final Phylogeny p000 = p.next();
8577             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8578                 System.out.println( p000.toNewHampshire() );
8579                 return false;
8580             }
8581             //
8582             final String p0000_str = "A";
8583             p.setSource( p0000_str );
8584             final Phylogeny p0000 = p.next();
8585             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8586                 System.out.println( p0000.toNewHampshire() );
8587                 return false;
8588             }
8589             //
8590             p.setSource( "(A)" );
8591             final Phylogeny p00000 = p.next();
8592             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8593                 System.out.println( p00000.toNewHampshire() );
8594                 return false;
8595             }
8596             //
8597             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8598             p.setSource( p1_str );
8599             if ( !p.hasNext() ) {
8600                 return false;
8601             }
8602             final Phylogeny p1_0 = p.next();
8603             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8604                 System.out.println( p1_0.toNewHampshire() );
8605                 return false;
8606             }
8607             if ( !p.hasNext() ) {
8608                 return false;
8609             }
8610             final Phylogeny p1_1 = p.next();
8611             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8612                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8613                 return false;
8614             }
8615             if ( !p.hasNext() ) {
8616                 return false;
8617             }
8618             final Phylogeny p1_2 = p.next();
8619             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8620                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8621                 return false;
8622             }
8623             if ( !p.hasNext() ) {
8624                 return false;
8625             }
8626             final Phylogeny p1_3 = p.next();
8627             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8628                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8629                 return false;
8630             }
8631             if ( p.hasNext() ) {
8632                 return false;
8633             }
8634             if ( p.next() != null ) {
8635                 return false;
8636             }
8637             //
8638             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8639             p.setSource( p2_str );
8640             if ( !p.hasNext() ) {
8641                 return false;
8642             }
8643             Phylogeny p2_0 = p.next();
8644             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8645                 System.out.println( p2_0.toNewHampshire() );
8646                 return false;
8647             }
8648             if ( !p.hasNext() ) {
8649                 return false;
8650             }
8651             Phylogeny p2_1 = p.next();
8652             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8653                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8654                 return false;
8655             }
8656             if ( !p.hasNext() ) {
8657                 return false;
8658             }
8659             Phylogeny p2_2 = p.next();
8660             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8661                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8662                 return false;
8663             }
8664             if ( !p.hasNext() ) {
8665                 return false;
8666             }
8667             Phylogeny p2_3 = p.next();
8668             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8669                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8670                 return false;
8671             }
8672             if ( !p.hasNext() ) {
8673                 return false;
8674             }
8675             Phylogeny p2_4 = p.next();
8676             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8677                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8678                 return false;
8679             }
8680             if ( p.hasNext() ) {
8681                 return false;
8682             }
8683             if ( p.next() != null ) {
8684                 return false;
8685             }
8686             ////
8687             p.reset();
8688             if ( !p.hasNext() ) {
8689                 return false;
8690             }
8691             p2_0 = p.next();
8692             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8693                 System.out.println( p2_0.toNewHampshire() );
8694                 return false;
8695             }
8696             if ( !p.hasNext() ) {
8697                 return false;
8698             }
8699             p2_1 = p.next();
8700             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8701                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8702                 return false;
8703             }
8704             if ( !p.hasNext() ) {
8705                 return false;
8706             }
8707             p2_2 = p.next();
8708             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8709                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8710                 return false;
8711             }
8712             if ( !p.hasNext() ) {
8713                 return false;
8714             }
8715             p2_3 = p.next();
8716             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8717                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8718                 return false;
8719             }
8720             if ( !p.hasNext() ) {
8721                 return false;
8722             }
8723             p2_4 = p.next();
8724             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8725                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8726                 return false;
8727             }
8728             if ( p.hasNext() ) {
8729                 return false;
8730             }
8731             if ( p.next() != null ) {
8732                 return false;
8733             }
8734             //
8735             final String p3_str = "((A,B),C)abc";
8736             p.setSource( p3_str );
8737             if ( !p.hasNext() ) {
8738                 return false;
8739             }
8740             final Phylogeny p3_0 = p.next();
8741             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8742                 return false;
8743             }
8744             if ( p.hasNext() ) {
8745                 return false;
8746             }
8747             if ( p.next() != null ) {
8748                 return false;
8749             }
8750             //
8751             final String p4_str = "((A,B)ab,C)abc";
8752             p.setSource( p4_str );
8753             if ( !p.hasNext() ) {
8754                 return false;
8755             }
8756             final Phylogeny p4_0 = p.next();
8757             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8758                 return false;
8759             }
8760             if ( p.hasNext() ) {
8761                 return false;
8762             }
8763             if ( p.next() != null ) {
8764                 return false;
8765             }
8766             //
8767             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8768             p.setSource( p5_str );
8769             if ( !p.hasNext() ) {
8770                 return false;
8771             }
8772             final Phylogeny p5_0 = p.next();
8773             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8774                 return false;
8775             }
8776             if ( p.hasNext() ) {
8777                 return false;
8778             }
8779             if ( p.next() != null ) {
8780                 return false;
8781             }
8782             //
8783             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8784             p.setSource( p6_str );
8785             if ( !p.hasNext() ) {
8786                 return false;
8787             }
8788             Phylogeny p6_0 = p.next();
8789             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8790                 return false;
8791             }
8792             if ( p.hasNext() ) {
8793                 return false;
8794             }
8795             if ( p.next() != null ) {
8796                 return false;
8797             }
8798             p.reset();
8799             if ( !p.hasNext() ) {
8800                 return false;
8801             }
8802             p6_0 = p.next();
8803             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8804                 return false;
8805             }
8806             if ( p.hasNext() ) {
8807                 return false;
8808             }
8809             if ( p.next() != null ) {
8810                 return false;
8811             }
8812             //
8813             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8814             p.setSource( p7_str );
8815             if ( !p.hasNext() ) {
8816                 return false;
8817             }
8818             Phylogeny p7_0 = p.next();
8819             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8820                 return false;
8821             }
8822             if ( p.hasNext() ) {
8823                 return false;
8824             }
8825             if ( p.next() != null ) {
8826                 return false;
8827             }
8828             p.reset();
8829             if ( !p.hasNext() ) {
8830                 return false;
8831             }
8832             p7_0 = p.next();
8833             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8834                 return false;
8835             }
8836             if ( p.hasNext() ) {
8837                 return false;
8838             }
8839             if ( p.next() != null ) {
8840                 return false;
8841             }
8842             //
8843             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8844             p.setSource( p8_str );
8845             if ( !p.hasNext() ) {
8846                 return false;
8847             }
8848             Phylogeny p8_0 = p.next();
8849             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8850                 return false;
8851             }
8852             if ( !p.hasNext() ) {
8853                 return false;
8854             }
8855             if ( !p.hasNext() ) {
8856                 return false;
8857             }
8858             Phylogeny p8_1 = p.next();
8859             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8860                 return false;
8861             }
8862             if ( p.hasNext() ) {
8863                 return false;
8864             }
8865             if ( p.next() != null ) {
8866                 return false;
8867             }
8868             p.reset();
8869             if ( !p.hasNext() ) {
8870                 return false;
8871             }
8872             p8_0 = p.next();
8873             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8874                 return false;
8875             }
8876             if ( !p.hasNext() ) {
8877                 return false;
8878             }
8879             p8_1 = p.next();
8880             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8881                 return false;
8882             }
8883             if ( p.hasNext() ) {
8884                 return false;
8885             }
8886             if ( p.next() != null ) {
8887                 return false;
8888             }
8889             p.reset();
8890             //
8891             p.setSource( "" );
8892             if ( p.hasNext() ) {
8893                 return false;
8894             }
8895             //
8896             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8897             if ( !p.hasNext() ) {
8898                 return false;
8899             }
8900             Phylogeny p_27 = p.next();
8901             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8902                 System.out.println( p_27.toNewHampshireX() );
8903                 System.exit( -1 );
8904                 return false;
8905             }
8906             if ( p.hasNext() ) {
8907                 return false;
8908             }
8909             if ( p.next() != null ) {
8910                 return false;
8911             }
8912             p.reset();
8913             if ( !p.hasNext() ) {
8914                 return false;
8915             }
8916             p_27 = p.next();
8917             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8918                 System.out.println( p_27.toNewHampshireX() );
8919                 System.exit( -1 );
8920                 return false;
8921             }
8922             if ( p.hasNext() ) {
8923                 return false;
8924             }
8925             if ( p.next() != null ) {
8926                 return false;
8927             }
8928             //
8929             final String p30_str = "(A,B);(C,D)";
8930             final NHXParser p30 = new NHXParser();
8931             p30.setSource( p30_str );
8932             if ( !p30.hasNext() ) {
8933                 return false;
8934             }
8935             Phylogeny phy30 = p30.next();
8936             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8937                 System.out.println( phy30.toNewHampshire() );
8938                 return false;
8939             }
8940             if ( !p30.hasNext() ) {
8941                 return false;
8942             }
8943             Phylogeny phy301 = p30.next();
8944             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8945                 System.out.println( phy301.toNewHampshire() );
8946                 return false;
8947             }
8948             if ( p30.hasNext() ) {
8949                 return false;
8950             }
8951             if ( p30.hasNext() ) {
8952                 return false;
8953             }
8954             if ( p30.next() != null ) {
8955                 return false;
8956             }
8957             if ( p30.next() != null ) {
8958                 return false;
8959             }
8960             p30.reset();
8961             if ( !p30.hasNext() ) {
8962                 return false;
8963             }
8964             phy30 = p30.next();
8965             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8966                 System.out.println( phy30.toNewHampshire() );
8967                 return false;
8968             }
8969             if ( !p30.hasNext() ) {
8970                 return false;
8971             }
8972             phy301 = p30.next();
8973             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8974                 System.out.println( phy301.toNewHampshire() );
8975                 return false;
8976             }
8977             if ( p30.hasNext() ) {
8978                 return false;
8979             }
8980             if ( p30.hasNext() ) {
8981                 return false;
8982             }
8983             if ( p30.next() != null ) {
8984                 return false;
8985             }
8986             if ( p30.next() != null ) {
8987                 return false;
8988             }
8989         }
8990         catch ( final Exception e ) {
8991             e.printStackTrace( System.out );
8992             return false;
8993         }
8994         return true;
8995     }
8996
8997     private static boolean testNHXconversion() {
8998         try {
8999             final PhylogenyNode n1 = new PhylogenyNode();
9000             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9001             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9002             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9003             final PhylogenyNode n5 = PhylogenyNode
9004                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
9005             final PhylogenyNode n6 = PhylogenyNode
9006                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
9007             if ( !n1.toNewHampshireX().equals( "" ) ) {
9008                 return false;
9009             }
9010             if ( !n2.toNewHampshireX().equals( "" ) ) {
9011                 return false;
9012             }
9013             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
9014                 return false;
9015             }
9016             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
9017                 return false;
9018             }
9019             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
9020                 return false;
9021             }
9022             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9023                 System.out.println( n6.toNewHampshireX() );
9024                 return false;
9025             }
9026             final PhylogenyNode n7 = new PhylogenyNode();
9027             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9028             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9029                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9030                 System.out.println( n7
9031                                     .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9032                 return false;
9033             }
9034         }
9035         catch ( final Exception e ) {
9036             e.printStackTrace( System.out );
9037             return false;
9038         }
9039         return true;
9040     }
9041
9042     private static boolean testNHXNodeParsing() {
9043         try {
9044             final PhylogenyNode n1 = new PhylogenyNode();
9045             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9046             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9047             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9048             final PhylogenyNode n5 = PhylogenyNode
9049                     .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]" );
9050             if ( !n3.getName().equals( "n3" ) ) {
9051                 return false;
9052             }
9053             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9054                 return false;
9055             }
9056             if ( n3.isDuplication() ) {
9057                 return false;
9058             }
9059             if ( n3.isHasAssignedEvent() ) {
9060                 return false;
9061             }
9062             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9063                 return false;
9064             }
9065             if ( !n4.getName().equals( "n4" ) ) {
9066                 return false;
9067             }
9068             if ( n4.getDistanceToParent() != 0.01 ) {
9069                 return false;
9070             }
9071             if ( !n5.getName().equals( "n5" ) ) {
9072                 return false;
9073             }
9074             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9075                 return false;
9076             }
9077             if ( n5.getDistanceToParent() != 0.1 ) {
9078                 return false;
9079             }
9080             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9081                 return false;
9082             }
9083             if ( !n5.isDuplication() ) {
9084                 return false;
9085             }
9086             if ( !n5.isHasAssignedEvent() ) {
9087                 return false;
9088             }
9089             final PhylogenyNode n8 = PhylogenyNode
9090                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9091                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9092             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9093                 return false;
9094             }
9095             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9096                 return false;
9097             }
9098             final PhylogenyNode n9 = PhylogenyNode
9099                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9100                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9101             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9102                 return false;
9103             }
9104             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9105                 return false;
9106             }
9107             final PhylogenyNode n10 = PhylogenyNode
9108                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9109             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9110                 return false;
9111             }
9112             final PhylogenyNode n20 = PhylogenyNode
9113                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9114             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9115                 return false;
9116             }
9117             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9118                 return false;
9119             }
9120             final PhylogenyNode n20x = PhylogenyNode
9121                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9122             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9123                 return false;
9124             }
9125             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9126                 return false;
9127             }
9128             final PhylogenyNode n20xx = PhylogenyNode
9129                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9130             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9131                 return false;
9132             }
9133             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9134                 return false;
9135             }
9136             final PhylogenyNode n20xxx = PhylogenyNode
9137                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9138             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9139                 return false;
9140             }
9141             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9142                 return false;
9143             }
9144             final PhylogenyNode n20xxxx = PhylogenyNode
9145                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9146             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9147                 return false;
9148             }
9149             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9150                 return false;
9151             }
9152             final PhylogenyNode n21 = PhylogenyNode
9153                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9154             if ( !n21.getName().equals( "N21_PIG" ) ) {
9155                 return false;
9156             }
9157             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9158                 return false;
9159             }
9160             final PhylogenyNode n21x = PhylogenyNode
9161                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9162             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9163                 return false;
9164             }
9165             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9166                 return false;
9167             }
9168             final PhylogenyNode n22 = PhylogenyNode
9169                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9170             if ( !n22.getName().equals( "n22/PIG" ) ) {
9171                 return false;
9172             }
9173             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9174                 return false;
9175             }
9176             final PhylogenyNode n23 = PhylogenyNode
9177                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9178             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9179                 return false;
9180             }
9181             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9182                 return false;
9183             }
9184             final PhylogenyNode a = PhylogenyNode
9185                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9186             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9187                 return false;
9188             }
9189             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9190                 return false;
9191             }
9192             final PhylogenyNode c1 = PhylogenyNode
9193                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9194                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9195             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9196                 return false;
9197             }
9198             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9199                 return false;
9200             }
9201             final PhylogenyNode c2 = PhylogenyNode
9202                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9203                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9204             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9205                 return false;
9206             }
9207             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9208                 return false;
9209             }
9210             final PhylogenyNode e3 = PhylogenyNode
9211                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9212             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9213                 return false;
9214             }
9215             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9216                 return false;
9217             }
9218             final PhylogenyNode n11 = PhylogenyNode
9219                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9220                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9221             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9222                 return false;
9223             }
9224             if ( n11.getDistanceToParent() != 0.4 ) {
9225                 return false;
9226             }
9227             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9228                 return false;
9229             }
9230             final PhylogenyNode n12 = PhylogenyNode
9231                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9232                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9233             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9234                 return false;
9235             }
9236             if ( n12.getDistanceToParent() != 0.4 ) {
9237                 return false;
9238             }
9239             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9240                 return false;
9241             }
9242             final PhylogenyNode o = PhylogenyNode
9243                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9244             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9245                 return false;
9246             }
9247             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9248                 return false;
9249             }
9250             if ( n1.getName().compareTo( "" ) != 0 ) {
9251                 return false;
9252             }
9253             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9254                 return false;
9255             }
9256             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9257                 return false;
9258             }
9259             if ( n2.getName().compareTo( "" ) != 0 ) {
9260                 return false;
9261             }
9262             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9263                 return false;
9264             }
9265             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9266                 return false;
9267             }
9268             final PhylogenyNode n00 = PhylogenyNode
9269                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9270             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9271                 return false;
9272             }
9273             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9274                 return false;
9275             }
9276             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9277             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9278                 return false;
9279             }
9280             final PhylogenyNode n13 = PhylogenyNode
9281                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9282             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9283                 return false;
9284             }
9285             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9286                 return false;
9287             }
9288             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9289                 return false;
9290             }
9291             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9292                 return false;
9293             }
9294             final PhylogenyNode n14 = PhylogenyNode
9295                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9296             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9297                 return false;
9298             }
9299             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9300                 return false;
9301             }
9302             final PhylogenyNode n15 = PhylogenyNode
9303                     .createInstanceFromNhxString( "something_wicked[123]",
9304                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9305             if ( !n15.getName().equals( "something_wicked" ) ) {
9306                 return false;
9307             }
9308             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9309                 return false;
9310             }
9311             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9312                 return false;
9313             }
9314             final PhylogenyNode n16 = PhylogenyNode
9315                     .createInstanceFromNhxString( "something_wicked2[9]",
9316                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9317             if ( !n16.getName().equals( "something_wicked2" ) ) {
9318                 return false;
9319             }
9320             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9321                 return false;
9322             }
9323             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9324                 return false;
9325             }
9326             final PhylogenyNode n17 = PhylogenyNode
9327                     .createInstanceFromNhxString( "something_wicked3[a]",
9328                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9329             if ( !n17.getName().equals( "something_wicked3" ) ) {
9330                 return false;
9331             }
9332             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9333                 return false;
9334             }
9335             final PhylogenyNode n18 = PhylogenyNode
9336                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9337             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9338                 return false;
9339             }
9340             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9341                 return false;
9342             }
9343             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9344                 return false;
9345             }
9346             final PhylogenyNode n19 = PhylogenyNode
9347                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9348             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9349                 return false;
9350             }
9351             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9352                 return false;
9353             }
9354             final PhylogenyNode n30 = PhylogenyNode
9355                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9356                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9357             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9358                 return false;
9359             }
9360             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9361                 return false;
9362             }
9363             final PhylogenyNode n31 = PhylogenyNode
9364                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9365                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9366             if ( n31.getNodeData().isHasTaxonomy() ) {
9367                 return false;
9368             }
9369             final PhylogenyNode n32 = PhylogenyNode
9370                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9371             if ( n32.getNodeData().isHasTaxonomy() ) {
9372                 return false;
9373             }
9374             final PhylogenyNode n40 = PhylogenyNode
9375                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9376             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9377                 return false;
9378             }
9379             final PhylogenyNode n41 = PhylogenyNode
9380                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9381             if ( n41.getNodeData().isHasTaxonomy() ) {
9382                 return false;
9383             }
9384             final PhylogenyNode n42 = PhylogenyNode
9385                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9386             if ( n42.getNodeData().isHasTaxonomy() ) {
9387                 return false;
9388             }
9389             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9390                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9391             if ( n43.getNodeData().isHasTaxonomy() ) {
9392                 return false;
9393             }
9394             final PhylogenyNode n44 = PhylogenyNode
9395                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9396             if ( n44.getNodeData().isHasTaxonomy() ) {
9397                 return false;
9398             }
9399         }
9400         catch ( final Exception e ) {
9401             e.printStackTrace( System.out );
9402             return false;
9403         }
9404         return true;
9405     }
9406
9407     private static boolean testNHXParsing() {
9408         try {
9409             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9410             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9411             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9412                 return false;
9413             }
9414             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]";
9415             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9416             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9417                 return false;
9418             }
9419             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]";
9420             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9421             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9422                 return false;
9423             }
9424             final Phylogeny[] p3 = factory
9425                     .create( "[  comment&&NHX,())))](((((((A:0.2[&&NHX:S=qwerty]):0.2[&&NHX:S=uiop]):0.3[&&NHX:S=asdf]):0.4[&&NHX:S=zxc]):0.5[&&NHX:S=a]):0.6[&&NHX:S=asd]):0.7[&&NHX:S=za]):0.8[&&NHX:S=zaq]",
9426                              new NHXParser() );
9427             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9428                 return false;
9429             }
9430             final Phylogeny[] p4 = factory
9431                     .create( "(((((((A:0.2[&&NHX:S=qwerty]):0.2[&&NHX:S=uiop]):0.3[&&NHX:S=asdf]):0.4[&&NHX:S=zxc]):0.5[&&NHX:S=a]):0.6[&&NHX:S=asd]):0.7[&&NHX:S=za]):0.8[&&NHX:S=zaq][comment(]",
9432                              new NHXParser() );
9433             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9434                 return false;
9435             }
9436             final Phylogeny[] p5 = factory
9437                     .create( "[]  (  [][ ][   ]  ([((( &&NHXcomment only![[[[[[]([]((((A:0.2[&&NHX:S=q[comment )))]werty][,,,,))]):0.2[&&NHX:S=uiop]):0.3[&&NHX:S=a[comment,,))]sdf])[comment(((]:0.4[&&NHX:S=zxc][comment(((][comment(((]):0.5[&&NHX:S=a]):0.6[&&NHX:S=a[comment(((]sd]):0.7[&&NHX:S=za]):0.8[&&NHX:S=zaq][comment(((]",
9438                              new NHXParser() );
9439             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9440                 return false;
9441             }
9442             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)";
9443             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)";
9444             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9445             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9446                 return false;
9447             }
9448             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)))";
9449             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)))";
9450             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9451             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9452                 return false;
9453             }
9454             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])   ))[,,, ])))))))";
9455             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9456             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9457             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9458                 return false;
9459             }
9460             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9461             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9462                 return false;
9463             }
9464             final Phylogeny p10 = factory
9465                     .create( " [79]   ( (A [co mment] :0 .2[comment],B:0.3[com])[com ment]: 0. 5 \t[ 9 1 ][ comment],C: 0.1)[comment]root:0.1[100] [comment]",
9466                              new NHXParser() )[ 0 ];
9467             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9468                 return false;
9469             }
9470             final Phylogeny p11 = factory
9471                     .create( " [79]   ( ('A: \" ' [co mment] :0 .2[comment],B:0.3[com])[com ment]: 0. 5 \t[ 9 1 ][ comment],C: 0.1)[comment]root:0.1[100] [comment]",
9472                              new NHXParser() )[ 0 ];
9473             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9474                 return false;
9475             }
9476             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]",
9477                                                   new NHXParser() )[ 0 ];
9478             if ( !p12.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9479                 return false;
9480             }
9481         }
9482         catch ( final Exception e ) {
9483             e.printStackTrace( System.out );
9484             return false;
9485         }
9486         return true;
9487     }
9488
9489     private static boolean testNHXParsingMB() {
9490         try {
9491             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9492             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9493                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9494                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9495                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9496                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9497                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9498                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9499                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9500                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9501             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9502                 return false;
9503             }
9504             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9505                 return false;
9506             }
9507             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9508                            0.1100000000000000e+00 ) ) {
9509                 return false;
9510             }
9511             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9512                 return false;
9513             }
9514             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9515                 return false;
9516             }
9517             final Phylogeny p2 = factory
9518                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9519                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9520                             + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9521                             + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9522                             + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9523                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9524                             + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9525                             + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9526                             + "7.369400000000000e-02}])",
9527                             new NHXParser() )[ 0 ];
9528             if ( p2.getNode( "1" ) == null ) {
9529                 return false;
9530             }
9531             if ( p2.getNode( "2" ) == null ) {
9532                 return false;
9533             }
9534         }
9535         catch ( final Exception e ) {
9536             e.printStackTrace( System.out );
9537             System.exit( -1 );
9538             return false;
9539         }
9540         return true;
9541     }
9542
9543     private static boolean testNHXParsingQuotes() {
9544         try {
9545             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9546             final NHXParser p = new NHXParser();
9547             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9548             if ( phylogenies_0.length != 5 ) {
9549                 return false;
9550             }
9551             final Phylogeny phy = phylogenies_0[ 4 ];
9552             if ( phy.getNumberOfExternalNodes() != 7 ) {
9553                 return false;
9554             }
9555             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9556                 return false;
9557             }
9558             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9559                 return false;
9560             }
9561             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9562                     .getScientificName().equals( "hsapiens" ) ) {
9563                 return false;
9564             }
9565             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9566                 return false;
9567             }
9568             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9569                 return false;
9570             }
9571             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9572                 return false;
9573             }
9574             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9575                 return false;
9576             }
9577             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9578                 return false;
9579             }
9580             final NHXParser p1p = new NHXParser();
9581             p1p.setIgnoreQuotes( true );
9582             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9583             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9584                 return false;
9585             }
9586             final NHXParser p2p = new NHXParser();
9587             p1p.setIgnoreQuotes( false );
9588             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9589             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9590                 return false;
9591             }
9592             final NHXParser p3p = new NHXParser();
9593             p3p.setIgnoreQuotes( false );
9594             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9595             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9596                 return false;
9597             }
9598             final NHXParser p4p = new NHXParser();
9599             p4p.setIgnoreQuotes( false );
9600             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9601             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9602                 return false;
9603             }
9604             final Phylogeny p10 = factory
9605                     .create( " [79]   ( (\"A \n\tB \" [co mment] :0 .2[comment],'B':0.3[com])[com ment]: 0. 5 \t[ 9 1 ][ comment],'C (or D?\\//;,))': 0.1)[comment]'\nroot is here (cool,  was! ) ':0.1[100] [comment]",
9606                              new NHXParser() )[ 0 ];
9607             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]";
9608             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9609                 return false;
9610             }
9611             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9612             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9613                 return false;
9614             }
9615             final Phylogeny p12 = factory
9616                     .create( " [79]   ( (\"A \n\tB \" [[][] :0 .2[comment][\t&\t&\n N\tH\tX:S=mo\tnkey !],'\tB\t\b\t\n\f\rB B ':0.0\b3[])\t[com ment]: 0. 5 \t[ 9 1 ][ \ncomment],'C\t (or D?\\//;,))': 0.\b1)[comment]'\nroot \tis here (cool, \b\t\n\f\r was! ) ':0.1[100] [comment]",
9617                              new NHXParser() )[ 0 ];
9618             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]";
9619             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9620                 return false;
9621             }
9622             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9623             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9624                 return false;
9625             }
9626             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;";
9627             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9628                 return false;
9629             }
9630             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9631             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9632                 return false;
9633             }
9634         }
9635         catch ( final Exception e ) {
9636             e.printStackTrace( System.out );
9637             return false;
9638         }
9639         return true;
9640     }
9641
9642     private static boolean testNodeRemoval() {
9643         try {
9644             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9645             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9646             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9647             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9648                 return false;
9649             }
9650             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9651             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9652             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9653                 return false;
9654             }
9655             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9656             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9657             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9658                 return false;
9659             }
9660         }
9661         catch ( final Exception e ) {
9662             e.printStackTrace( System.out );
9663             return false;
9664         }
9665         return true;
9666     }
9667
9668     private static boolean testPhylogenyBranch() {
9669         try {
9670             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9671             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9672             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9673             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9674             if ( !a1b1.equals( a1b1 ) ) {
9675                 return false;
9676             }
9677             if ( !a1b1.equals( b1a1 ) ) {
9678                 return false;
9679             }
9680             if ( !b1a1.equals( a1b1 ) ) {
9681                 return false;
9682             }
9683             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9684             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9685             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9686             if ( a1_b1.equals( b1_a1 ) ) {
9687                 return false;
9688             }
9689             if ( a1_b1.equals( a1_b1_ ) ) {
9690                 return false;
9691             }
9692             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9693             if ( !a1_b1.equals( b1_a1_ ) ) {
9694                 return false;
9695             }
9696             if ( a1_b1_.equals( b1_a1_ ) ) {
9697                 return false;
9698             }
9699             if ( !a1_b1_.equals( b1_a1 ) ) {
9700                 return false;
9701             }
9702         }
9703         catch ( final Exception e ) {
9704             e.printStackTrace( System.out );
9705             return false;
9706         }
9707         return true;
9708     }
9709
9710     private static boolean testPhyloXMLparsingOfDistributionElement() {
9711         try {
9712             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9713             PhyloXmlParser xml_parser = null;
9714             try {
9715                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9716             }
9717             catch ( final Exception e ) {
9718                 // Do nothing -- means were not running from jar.
9719             }
9720             if ( xml_parser == null ) {
9721                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9722                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9723                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9724                 }
9725                 else {
9726                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9727                 }
9728             }
9729             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9730                                                               xml_parser );
9731             if ( xml_parser.getErrorCount() > 0 ) {
9732                 System.out.println( xml_parser.getErrorMessages().toString() );
9733                 return false;
9734             }
9735             if ( phylogenies_0.length != 1 ) {
9736                 return false;
9737             }
9738             final Phylogeny t1 = phylogenies_0[ 0 ];
9739             PhylogenyNode n = null;
9740             Distribution d = null;
9741             n = t1.getNode( "root node" );
9742             if ( !n.getNodeData().isHasDistribution() ) {
9743                 return false;
9744             }
9745             if ( n.getNodeData().getDistributions().size() != 1 ) {
9746                 return false;
9747             }
9748             d = n.getNodeData().getDistribution();
9749             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9750                 return false;
9751             }
9752             if ( d.getPoints().size() != 1 ) {
9753                 return false;
9754             }
9755             if ( d.getPolygons() != null ) {
9756                 return false;
9757             }
9758             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9759                 return false;
9760             }
9761             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9762                 return false;
9763             }
9764             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9765                 return false;
9766             }
9767             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9768                 return false;
9769             }
9770             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9771                 return false;
9772             }
9773             n = t1.getNode( "node a" );
9774             if ( !n.getNodeData().isHasDistribution() ) {
9775                 return false;
9776             }
9777             if ( n.getNodeData().getDistributions().size() != 2 ) {
9778                 return false;
9779             }
9780             d = n.getNodeData().getDistribution( 1 );
9781             if ( !d.getDesc().equals( "San Diego" ) ) {
9782                 return false;
9783             }
9784             if ( d.getPoints().size() != 1 ) {
9785                 return false;
9786             }
9787             if ( d.getPolygons() != null ) {
9788                 return false;
9789             }
9790             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9791                 return false;
9792             }
9793             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9794                 return false;
9795             }
9796             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9797                 return false;
9798             }
9799             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9800                 return false;
9801             }
9802             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9803                 return false;
9804             }
9805             n = t1.getNode( "node bb" );
9806             if ( !n.getNodeData().isHasDistribution() ) {
9807                 return false;
9808             }
9809             if ( n.getNodeData().getDistributions().size() != 1 ) {
9810                 return false;
9811             }
9812             d = n.getNodeData().getDistribution( 0 );
9813             if ( d.getPoints().size() != 3 ) {
9814                 return false;
9815             }
9816             if ( d.getPolygons().size() != 2 ) {
9817                 return false;
9818             }
9819             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9820                 return false;
9821             }
9822             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9823                 return false;
9824             }
9825             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9826                 return false;
9827             }
9828             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9829                 return false;
9830             }
9831             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9832                 return false;
9833             }
9834             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9835                 return false;
9836             }
9837             Polygon p = d.getPolygons().get( 0 );
9838             if ( p.getPoints().size() != 3 ) {
9839                 return false;
9840             }
9841             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9842                 return false;
9843             }
9844             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9845                 return false;
9846             }
9847             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9848                 return false;
9849             }
9850             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9851                 return false;
9852             }
9853             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9854                 return false;
9855             }
9856             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9857                 return false;
9858             }
9859             p = d.getPolygons().get( 1 );
9860             if ( p.getPoints().size() != 3 ) {
9861                 return false;
9862             }
9863             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9864                 return false;
9865             }
9866             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9867                 return false;
9868             }
9869             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9870                 return false;
9871             }
9872             // Roundtrip:
9873             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9874             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9875             if ( rt.length != 1 ) {
9876                 return false;
9877             }
9878             final Phylogeny t1_rt = rt[ 0 ];
9879             n = t1_rt.getNode( "root node" );
9880             if ( !n.getNodeData().isHasDistribution() ) {
9881                 return false;
9882             }
9883             if ( n.getNodeData().getDistributions().size() != 1 ) {
9884                 return false;
9885             }
9886             d = n.getNodeData().getDistribution();
9887             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9888                 return false;
9889             }
9890             if ( d.getPoints().size() != 1 ) {
9891                 return false;
9892             }
9893             if ( d.getPolygons() != null ) {
9894                 return false;
9895             }
9896             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9897                 return false;
9898             }
9899             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9900                 return false;
9901             }
9902             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9903                 return false;
9904             }
9905             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9906                 return false;
9907             }
9908             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9909                 return false;
9910             }
9911             n = t1_rt.getNode( "node a" );
9912             if ( !n.getNodeData().isHasDistribution() ) {
9913                 return false;
9914             }
9915             if ( n.getNodeData().getDistributions().size() != 2 ) {
9916                 return false;
9917             }
9918             d = n.getNodeData().getDistribution( 1 );
9919             if ( !d.getDesc().equals( "San Diego" ) ) {
9920                 return false;
9921             }
9922             if ( d.getPoints().size() != 1 ) {
9923                 return false;
9924             }
9925             if ( d.getPolygons() != null ) {
9926                 return false;
9927             }
9928             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9929                 return false;
9930             }
9931             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9932                 return false;
9933             }
9934             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9935                 return false;
9936             }
9937             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9938                 return false;
9939             }
9940             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9941                 return false;
9942             }
9943             n = t1_rt.getNode( "node bb" );
9944             if ( !n.getNodeData().isHasDistribution() ) {
9945                 return false;
9946             }
9947             if ( n.getNodeData().getDistributions().size() != 1 ) {
9948                 return false;
9949             }
9950             d = n.getNodeData().getDistribution( 0 );
9951             if ( d.getPoints().size() != 3 ) {
9952                 return false;
9953             }
9954             if ( d.getPolygons().size() != 2 ) {
9955                 return false;
9956             }
9957             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9958                 return false;
9959             }
9960             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9961                 return false;
9962             }
9963             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9964                 return false;
9965             }
9966             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9967                 return false;
9968             }
9969             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9970                 return false;
9971             }
9972             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9973                 return false;
9974             }
9975             p = d.getPolygons().get( 0 );
9976             if ( p.getPoints().size() != 3 ) {
9977                 return false;
9978             }
9979             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9980                 return false;
9981             }
9982             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9983                 return false;
9984             }
9985             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9986                 return false;
9987             }
9988             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9989                 return false;
9990             }
9991             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9992                 return false;
9993             }
9994             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9995                 return false;
9996             }
9997             p = d.getPolygons().get( 1 );
9998             if ( p.getPoints().size() != 3 ) {
9999                 return false;
10000             }
10001             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10002                 return false;
10003             }
10004             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10005                 return false;
10006             }
10007             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10008                 return false;
10009             }
10010         }
10011         catch ( final Exception e ) {
10012             e.printStackTrace( System.out );
10013             return false;
10014         }
10015         return true;
10016     }
10017
10018     private static boolean testPostOrderIterator() {
10019         try {
10020             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10021             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10022             PhylogenyNodeIterator it0;
10023             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
10024                 it0.next();
10025             }
10026             for( it0.reset(); it0.hasNext(); ) {
10027                 it0.next();
10028             }
10029             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10030             final PhylogenyNodeIterator it = t1.iteratorPostorder();
10031             if ( !it.next().getName().equals( "A" ) ) {
10032                 return false;
10033             }
10034             if ( !it.next().getName().equals( "B" ) ) {
10035                 return false;
10036             }
10037             if ( !it.next().getName().equals( "ab" ) ) {
10038                 return false;
10039             }
10040             if ( !it.next().getName().equals( "C" ) ) {
10041                 return false;
10042             }
10043             if ( !it.next().getName().equals( "D" ) ) {
10044                 return false;
10045             }
10046             if ( !it.next().getName().equals( "cd" ) ) {
10047                 return false;
10048             }
10049             if ( !it.next().getName().equals( "abcd" ) ) {
10050                 return false;
10051             }
10052             if ( !it.next().getName().equals( "E" ) ) {
10053                 return false;
10054             }
10055             if ( !it.next().getName().equals( "F" ) ) {
10056                 return false;
10057             }
10058             if ( !it.next().getName().equals( "ef" ) ) {
10059                 return false;
10060             }
10061             if ( !it.next().getName().equals( "G" ) ) {
10062                 return false;
10063             }
10064             if ( !it.next().getName().equals( "H" ) ) {
10065                 return false;
10066             }
10067             if ( !it.next().getName().equals( "gh" ) ) {
10068                 return false;
10069             }
10070             if ( !it.next().getName().equals( "efgh" ) ) {
10071                 return false;
10072             }
10073             if ( !it.next().getName().equals( "r" ) ) {
10074                 return false;
10075             }
10076             if ( it.hasNext() ) {
10077                 return false;
10078             }
10079         }
10080         catch ( final Exception e ) {
10081             e.printStackTrace( System.out );
10082             return false;
10083         }
10084         return true;
10085     }
10086
10087     private static boolean testPreOrderIterator() {
10088         try {
10089             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10090             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10091             PhylogenyNodeIterator it0;
10092             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10093                 it0.next();
10094             }
10095             for( it0.reset(); it0.hasNext(); ) {
10096                 it0.next();
10097             }
10098             PhylogenyNodeIterator it = t0.iteratorPreorder();
10099             if ( !it.next().getName().equals( "r" ) ) {
10100                 return false;
10101             }
10102             if ( !it.next().getName().equals( "ab" ) ) {
10103                 return false;
10104             }
10105             if ( !it.next().getName().equals( "A" ) ) {
10106                 return false;
10107             }
10108             if ( !it.next().getName().equals( "B" ) ) {
10109                 return false;
10110             }
10111             if ( !it.next().getName().equals( "cd" ) ) {
10112                 return false;
10113             }
10114             if ( !it.next().getName().equals( "C" ) ) {
10115                 return false;
10116             }
10117             if ( !it.next().getName().equals( "D" ) ) {
10118                 return false;
10119             }
10120             if ( it.hasNext() ) {
10121                 return false;
10122             }
10123             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10124             it = t1.iteratorPreorder();
10125             if ( !it.next().getName().equals( "r" ) ) {
10126                 return false;
10127             }
10128             if ( !it.next().getName().equals( "abcd" ) ) {
10129                 return false;
10130             }
10131             if ( !it.next().getName().equals( "ab" ) ) {
10132                 return false;
10133             }
10134             if ( !it.next().getName().equals( "A" ) ) {
10135                 return false;
10136             }
10137             if ( !it.next().getName().equals( "B" ) ) {
10138                 return false;
10139             }
10140             if ( !it.next().getName().equals( "cd" ) ) {
10141                 return false;
10142             }
10143             if ( !it.next().getName().equals( "C" ) ) {
10144                 return false;
10145             }
10146             if ( !it.next().getName().equals( "D" ) ) {
10147                 return false;
10148             }
10149             if ( !it.next().getName().equals( "efgh" ) ) {
10150                 return false;
10151             }
10152             if ( !it.next().getName().equals( "ef" ) ) {
10153                 return false;
10154             }
10155             if ( !it.next().getName().equals( "E" ) ) {
10156                 return false;
10157             }
10158             if ( !it.next().getName().equals( "F" ) ) {
10159                 return false;
10160             }
10161             if ( !it.next().getName().equals( "gh" ) ) {
10162                 return false;
10163             }
10164             if ( !it.next().getName().equals( "G" ) ) {
10165                 return false;
10166             }
10167             if ( !it.next().getName().equals( "H" ) ) {
10168                 return false;
10169             }
10170             if ( it.hasNext() ) {
10171                 return false;
10172             }
10173         }
10174         catch ( final Exception e ) {
10175             e.printStackTrace( System.out );
10176             return false;
10177         }
10178         return true;
10179     }
10180
10181     private static boolean testPropertiesMap() {
10182         try {
10183             final PropertiesMap pm = new PropertiesMap();
10184             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10185             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10186             final Property p2 = new Property( "something:else",
10187                                               "?",
10188                                               "improbable:research",
10189                                               "xsd:decimal",
10190                                               AppliesTo.NODE );
10191             pm.addProperty( p0 );
10192             pm.addProperty( p1 );
10193             pm.addProperty( p2 );
10194             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10195                 return false;
10196             }
10197             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10198                 return false;
10199             }
10200             if ( pm.getProperties().size() != 3 ) {
10201                 return false;
10202             }
10203             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10204                 return false;
10205             }
10206             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10207                 return false;
10208             }
10209             if ( pm.getProperties().size() != 3 ) {
10210                 return false;
10211             }
10212             pm.removeProperty( "dimensions:diameter" );
10213             if ( pm.getProperties().size() != 2 ) {
10214                 return false;
10215             }
10216             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10217                 return false;
10218             }
10219             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10220                 return false;
10221             }
10222         }
10223         catch ( final Exception e ) {
10224             e.printStackTrace( System.out );
10225             return false;
10226         }
10227         return true;
10228     }
10229
10230     private static boolean testProteinId() {
10231         try {
10232             final ProteinId id1 = new ProteinId( "a" );
10233             final ProteinId id2 = new ProteinId( "a" );
10234             final ProteinId id3 = new ProteinId( "A" );
10235             final ProteinId id4 = new ProteinId( "b" );
10236             if ( !id1.equals( id1 ) ) {
10237                 return false;
10238             }
10239             if ( id1.getId().equals( "x" ) ) {
10240                 return false;
10241             }
10242             if ( id1.getId().equals( null ) ) {
10243                 return false;
10244             }
10245             if ( !id1.equals( id2 ) ) {
10246                 return false;
10247             }
10248             if ( id1.equals( id3 ) ) {
10249                 return false;
10250             }
10251             if ( id1.hashCode() != id1.hashCode() ) {
10252                 return false;
10253             }
10254             if ( id1.hashCode() != id2.hashCode() ) {
10255                 return false;
10256             }
10257             if ( id1.hashCode() == id3.hashCode() ) {
10258                 return false;
10259             }
10260             if ( id1.compareTo( id1 ) != 0 ) {
10261                 return false;
10262             }
10263             if ( id1.compareTo( id2 ) != 0 ) {
10264                 return false;
10265             }
10266             if ( id1.compareTo( id3 ) != 0 ) {
10267                 return false;
10268             }
10269             if ( id1.compareTo( id4 ) >= 0 ) {
10270                 return false;
10271             }
10272             if ( id4.compareTo( id1 ) <= 0 ) {
10273                 return false;
10274             }
10275             if ( !id4.getId().equals( "b" ) ) {
10276                 return false;
10277             }
10278             final ProteinId id5 = new ProteinId( " C " );
10279             if ( !id5.getId().equals( "C" ) ) {
10280                 return false;
10281             }
10282             if ( id5.equals( id1 ) ) {
10283                 return false;
10284             }
10285         }
10286         catch ( final Exception e ) {
10287             e.printStackTrace( System.out );
10288             return false;
10289         }
10290         return true;
10291     }
10292
10293     private static boolean testReIdMethods() {
10294         try {
10295             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10296             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10297             final long count = PhylogenyNode.getNodeCount();
10298             p.levelOrderReID();
10299             if ( p.getNode( "r" ).getId() != count ) {
10300                 return false;
10301             }
10302             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10303                 return false;
10304             }
10305             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10306                 return false;
10307             }
10308             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10309                 return false;
10310             }
10311             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10312                 return false;
10313             }
10314             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10315                 return false;
10316             }
10317             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10318                 return false;
10319             }
10320             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10321                 return false;
10322             }
10323             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10324                 return false;
10325             }
10326             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10327                 return false;
10328             }
10329             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10330                 return false;
10331             }
10332             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10333                 return false;
10334             }
10335             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10336                 return false;
10337             }
10338             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10339                 return false;
10340             }
10341             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10342                 return false;
10343             }
10344         }
10345         catch ( final Exception e ) {
10346             e.printStackTrace( System.out );
10347             return false;
10348         }
10349         return true;
10350     }
10351
10352     private static boolean testRerooting() {
10353         try {
10354             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10355             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",
10356                                                  new NHXParser() )[ 0 ];
10357             if ( !t1.isRooted() ) {
10358                 return false;
10359             }
10360             t1.reRoot( t1.getNode( "D" ) );
10361             t1.reRoot( t1.getNode( "CD" ) );
10362             t1.reRoot( t1.getNode( "A" ) );
10363             t1.reRoot( t1.getNode( "B" ) );
10364             t1.reRoot( t1.getNode( "AB" ) );
10365             t1.reRoot( t1.getNode( "D" ) );
10366             t1.reRoot( t1.getNode( "C" ) );
10367             t1.reRoot( t1.getNode( "CD" ) );
10368             t1.reRoot( t1.getNode( "A" ) );
10369             t1.reRoot( t1.getNode( "B" ) );
10370             t1.reRoot( t1.getNode( "AB" ) );
10371             t1.reRoot( t1.getNode( "D" ) );
10372             t1.reRoot( t1.getNode( "D" ) );
10373             t1.reRoot( t1.getNode( "C" ) );
10374             t1.reRoot( t1.getNode( "A" ) );
10375             t1.reRoot( t1.getNode( "B" ) );
10376             t1.reRoot( t1.getNode( "AB" ) );
10377             t1.reRoot( t1.getNode( "C" ) );
10378             t1.reRoot( t1.getNode( "D" ) );
10379             t1.reRoot( t1.getNode( "CD" ) );
10380             t1.reRoot( t1.getNode( "D" ) );
10381             t1.reRoot( t1.getNode( "A" ) );
10382             t1.reRoot( t1.getNode( "B" ) );
10383             t1.reRoot( t1.getNode( "AB" ) );
10384             t1.reRoot( t1.getNode( "C" ) );
10385             t1.reRoot( t1.getNode( "D" ) );
10386             t1.reRoot( t1.getNode( "CD" ) );
10387             t1.reRoot( t1.getNode( "D" ) );
10388             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10389                 return false;
10390             }
10391             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10392                 return false;
10393             }
10394             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10395                 return false;
10396             }
10397             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10398                 return false;
10399             }
10400             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10401                 return false;
10402             }
10403             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10404                 return false;
10405             }
10406             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",
10407                                                  new NHXParser() )[ 0 ];
10408             t2.reRoot( t2.getNode( "A" ) );
10409             t2.reRoot( t2.getNode( "D" ) );
10410             t2.reRoot( t2.getNode( "ABC" ) );
10411             t2.reRoot( t2.getNode( "A" ) );
10412             t2.reRoot( t2.getNode( "B" ) );
10413             t2.reRoot( t2.getNode( "D" ) );
10414             t2.reRoot( t2.getNode( "C" ) );
10415             t2.reRoot( t2.getNode( "ABC" ) );
10416             t2.reRoot( t2.getNode( "A" ) );
10417             t2.reRoot( t2.getNode( "B" ) );
10418             t2.reRoot( t2.getNode( "AB" ) );
10419             t2.reRoot( t2.getNode( "AB" ) );
10420             t2.reRoot( t2.getNode( "D" ) );
10421             t2.reRoot( t2.getNode( "C" ) );
10422             t2.reRoot( t2.getNode( "B" ) );
10423             t2.reRoot( t2.getNode( "AB" ) );
10424             t2.reRoot( t2.getNode( "D" ) );
10425             t2.reRoot( t2.getNode( "D" ) );
10426             t2.reRoot( t2.getNode( "ABC" ) );
10427             t2.reRoot( t2.getNode( "A" ) );
10428             t2.reRoot( t2.getNode( "B" ) );
10429             t2.reRoot( t2.getNode( "AB" ) );
10430             t2.reRoot( t2.getNode( "D" ) );
10431             t2.reRoot( t2.getNode( "C" ) );
10432             t2.reRoot( t2.getNode( "ABC" ) );
10433             t2.reRoot( t2.getNode( "A" ) );
10434             t2.reRoot( t2.getNode( "B" ) );
10435             t2.reRoot( t2.getNode( "AB" ) );
10436             t2.reRoot( t2.getNode( "D" ) );
10437             t2.reRoot( t2.getNode( "D" ) );
10438             t2.reRoot( t2.getNode( "C" ) );
10439             t2.reRoot( t2.getNode( "A" ) );
10440             t2.reRoot( t2.getNode( "B" ) );
10441             t2.reRoot( t2.getNode( "AB" ) );
10442             t2.reRoot( t2.getNode( "C" ) );
10443             t2.reRoot( t2.getNode( "D" ) );
10444             t2.reRoot( t2.getNode( "ABC" ) );
10445             t2.reRoot( t2.getNode( "D" ) );
10446             t2.reRoot( t2.getNode( "A" ) );
10447             t2.reRoot( t2.getNode( "B" ) );
10448             t2.reRoot( t2.getNode( "AB" ) );
10449             t2.reRoot( t2.getNode( "C" ) );
10450             t2.reRoot( t2.getNode( "D" ) );
10451             t2.reRoot( t2.getNode( "ABC" ) );
10452             t2.reRoot( t2.getNode( "D" ) );
10453             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10454                 return false;
10455             }
10456             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10457                 return false;
10458             }
10459             t2.reRoot( t2.getNode( "ABC" ) );
10460             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10461                 return false;
10462             }
10463             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10464                 return false;
10465             }
10466             t2.reRoot( t2.getNode( "AB" ) );
10467             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10468                 return false;
10469             }
10470             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10471                 return false;
10472             }
10473             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10474                 return false;
10475             }
10476             t2.reRoot( t2.getNode( "AB" ) );
10477             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10478                 return false;
10479             }
10480             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10481                 return false;
10482             }
10483             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10484                 return false;
10485             }
10486             t2.reRoot( t2.getNode( "D" ) );
10487             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10488                 return false;
10489             }
10490             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10491                 return false;
10492             }
10493             t2.reRoot( t2.getNode( "ABC" ) );
10494             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10495                 return false;
10496             }
10497             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10498                 return false;
10499             }
10500             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10501                                                  new NHXParser() )[ 0 ];
10502             t3.reRoot( t3.getNode( "B" ) );
10503             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10504                 return false;
10505             }
10506             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10507                 return false;
10508             }
10509             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10510                 return false;
10511             }
10512             t3.reRoot( t3.getNode( "B" ) );
10513             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10514                 return false;
10515             }
10516             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10517                 return false;
10518             }
10519             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10520                 return false;
10521             }
10522             t3.reRoot( t3.getRoot() );
10523             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10524                 return false;
10525             }
10526             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10527                 return false;
10528             }
10529             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10530                 return false;
10531             }
10532         }
10533         catch ( final Exception e ) {
10534             e.printStackTrace( System.out );
10535             return false;
10536         }
10537         return true;
10538     }
10539
10540     private static boolean testSDIse() {
10541         try {
10542             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10543             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10544             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10545             gene1.setRooted( true );
10546             species1.setRooted( true );
10547             final SDI sdi = new SDI( gene1, species1 );
10548             if ( !gene1.getRoot().isDuplication() ) {
10549                 return false;
10550             }
10551             final Phylogeny species2 = factory
10552                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10553                              new NHXParser() )[ 0 ];
10554             final Phylogeny gene2 = factory
10555                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10556                              new NHXParser() )[ 0 ];
10557             species2.setRooted( true );
10558             gene2.setRooted( true );
10559             final SDI sdi2 = new SDI( gene2, species2 );
10560             if ( sdi2.getDuplicationsSum() != 0 ) {
10561                 return false;
10562             }
10563             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10564                 return false;
10565             }
10566             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10567                 return false;
10568             }
10569             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10570                 return false;
10571             }
10572             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10573                 return false;
10574             }
10575             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10576                 return false;
10577             }
10578             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10579                 return false;
10580             }
10581             final Phylogeny species3 = factory
10582                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10583                              new NHXParser() )[ 0 ];
10584             final Phylogeny gene3 = factory
10585                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10586                              new NHXParser() )[ 0 ];
10587             species3.setRooted( true );
10588             gene3.setRooted( true );
10589             final SDI sdi3 = new SDI( gene3, species3 );
10590             if ( sdi3.getDuplicationsSum() != 1 ) {
10591                 return false;
10592             }
10593             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10594                 return false;
10595             }
10596             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10597                 return false;
10598             }
10599             final Phylogeny species4 = factory
10600                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10601                              new NHXParser() )[ 0 ];
10602             final Phylogeny gene4 = factory
10603                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10604                              new NHXParser() )[ 0 ];
10605             species4.setRooted( true );
10606             gene4.setRooted( true );
10607             final SDI sdi4 = new SDI( gene4, species4 );
10608             if ( sdi4.getDuplicationsSum() != 1 ) {
10609                 return false;
10610             }
10611             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10612                 return false;
10613             }
10614             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10615                 return false;
10616             }
10617             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10618                 return false;
10619             }
10620             if ( species4.getNumberOfExternalNodes() != 6 ) {
10621                 return false;
10622             }
10623             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10624                 return false;
10625             }
10626             final Phylogeny species5 = factory
10627                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10628                              new NHXParser() )[ 0 ];
10629             final Phylogeny gene5 = factory
10630                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10631                              new NHXParser() )[ 0 ];
10632             species5.setRooted( true );
10633             gene5.setRooted( true );
10634             final SDI sdi5 = new SDI( gene5, species5 );
10635             if ( sdi5.getDuplicationsSum() != 2 ) {
10636                 return false;
10637             }
10638             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10639                 return false;
10640             }
10641             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10642                 return false;
10643             }
10644             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10645                 return false;
10646             }
10647             if ( species5.getNumberOfExternalNodes() != 6 ) {
10648                 return false;
10649             }
10650             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10651                 return false;
10652             }
10653             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10654             // Conjecture for Comparing Molecular Phylogenies"
10655             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10656             final Phylogeny species6 = factory
10657                     .create( "(((1:[&&NHX:S=1],5:[&&NHX:S=5])1-5,((4:[&&NHX:S=4],6:[&&NHX:S=6])4-6,2:[&&NHX:S=2])4-6-2)1-5-4-6-2,"
10658                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10659                             new NHXParser() )[ 0 ];
10660             final Phylogeny gene6 = factory
10661                     .create( "(((1:0.1[&&NHX:S=1],2:0.1[&&NHX:S=2])1-2:0.1,3:0.1[&&NHX:S=3])1-2-3:0.1,"
10662                             + "((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,"
10663                             + "(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;",
10664                             new NHXParser() )[ 0 ];
10665             species6.setRooted( true );
10666             gene6.setRooted( true );
10667             final SDI sdi6 = new SDI( gene6, species6 );
10668             if ( sdi6.getDuplicationsSum() != 3 ) {
10669                 return false;
10670             }
10671             if ( !gene6.getNode( "r" ).isDuplication() ) {
10672                 return false;
10673             }
10674             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10675                 return false;
10676             }
10677             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10678                 return false;
10679             }
10680             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10681                 return false;
10682             }
10683             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10684                 return false;
10685             }
10686             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10687                 return false;
10688             }
10689             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10690                 return false;
10691             }
10692             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10693                 return false;
10694             }
10695             sdi6.computeMappingCostL();
10696             if ( sdi6.computeMappingCostL() != 17 ) {
10697                 return false;
10698             }
10699             if ( species6.getNumberOfExternalNodes() != 9 ) {
10700                 return false;
10701             }
10702             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10703                 return false;
10704             }
10705             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10706                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10707                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10708                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10709                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10710             species7.setRooted( true );
10711             final Phylogeny gene7_1 = Test
10712                     .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])" );
10713             gene7_1.setRooted( true );
10714             final SDI sdi7 = new SDI( gene7_1, species7 );
10715             if ( sdi7.getDuplicationsSum() != 0 ) {
10716                 return false;
10717             }
10718             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10719                 return false;
10720             }
10721             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10722                 return false;
10723             }
10724             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10725                 return false;
10726             }
10727             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10728                 return false;
10729             }
10730             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10731                 return false;
10732             }
10733             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10734                 return false;
10735             }
10736             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10737                 return false;
10738             }
10739             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10740                 return false;
10741             }
10742             final Phylogeny gene7_2 = Test
10743                     .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])" );
10744             gene7_2.setRooted( true );
10745             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10746             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10747                 return false;
10748             }
10749             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10750                 return false;
10751             }
10752             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10753                 return false;
10754             }
10755             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10756                 return false;
10757             }
10758             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10759                 return false;
10760             }
10761             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10762                 return false;
10763             }
10764             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10765                 return false;
10766             }
10767             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10768                 return false;
10769             }
10770             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10771                 return false;
10772             }
10773             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10774                 return false;
10775             }
10776         }
10777         catch ( final Exception e ) {
10778             return false;
10779         }
10780         return true;
10781     }
10782
10783     private static boolean testSDIunrooted() {
10784         try {
10785             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10786             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10787             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10788             final Iterator<PhylogenyBranch> iter = l.iterator();
10789             PhylogenyBranch br = iter.next();
10790             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10791                 return false;
10792             }
10793             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10794                 return false;
10795             }
10796             br = iter.next();
10797             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10798                 return false;
10799             }
10800             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10801                 return false;
10802             }
10803             br = iter.next();
10804             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10805                 return false;
10806             }
10807             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10808                 return false;
10809             }
10810             br = iter.next();
10811             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10812                 return false;
10813             }
10814             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10815                 return false;
10816             }
10817             br = iter.next();
10818             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10819                 return false;
10820             }
10821             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10822                 return false;
10823             }
10824             br = iter.next();
10825             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10826                 return false;
10827             }
10828             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10829                 return false;
10830             }
10831             br = iter.next();
10832             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10833                 return false;
10834             }
10835             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10836                 return false;
10837             }
10838             br = iter.next();
10839             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10840                 return false;
10841             }
10842             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10843                 return false;
10844             }
10845             br = iter.next();
10846             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10847                 return false;
10848             }
10849             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10850                 return false;
10851             }
10852             br = iter.next();
10853             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10854                 return false;
10855             }
10856             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10857                 return false;
10858             }
10859             br = iter.next();
10860             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10861                 return false;
10862             }
10863             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10864                 return false;
10865             }
10866             br = iter.next();
10867             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10868                 return false;
10869             }
10870             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10871                 return false;
10872             }
10873             br = iter.next();
10874             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10875                 return false;
10876             }
10877             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10878                 return false;
10879             }
10880             br = iter.next();
10881             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10882                 return false;
10883             }
10884             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10885                 return false;
10886             }
10887             br = iter.next();
10888             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10889                 return false;
10890             }
10891             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10892                 return false;
10893             }
10894             if ( iter.hasNext() ) {
10895                 return false;
10896             }
10897             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10898             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10899             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10900             br = iter1.next();
10901             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10902                 return false;
10903             }
10904             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10905                 return false;
10906             }
10907             br = iter1.next();
10908             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10909                 return false;
10910             }
10911             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10912                 return false;
10913             }
10914             br = iter1.next();
10915             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10916                 return false;
10917             }
10918             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10919                 return false;
10920             }
10921             if ( iter1.hasNext() ) {
10922                 return false;
10923             }
10924             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10925             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10926             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10927             br = iter2.next();
10928             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10929                 return false;
10930             }
10931             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10932                 return false;
10933             }
10934             br = iter2.next();
10935             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10936                 return false;
10937             }
10938             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10939                 return false;
10940             }
10941             br = iter2.next();
10942             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10943                 return false;
10944             }
10945             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10946                 return false;
10947             }
10948             if ( iter2.hasNext() ) {
10949                 return false;
10950             }
10951             final Phylogeny species0 = factory
10952                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10953                              new NHXParser() )[ 0 ];
10954             final Phylogeny gene1 = factory
10955                     .create( "(((((A:0.6[&&NHX:S=A],B:0.1[&&NHX:S=B])ab:0.1,C:0.1[&&NHX:S=C])abc:0.3,D:1.0[&&NHX:S=D])abcd:0.2,E:0.1[&&NHX:S=E])abcde:0.2,F:0.2[&&NHX:S=F])",
10956                              new NHXParser() )[ 0 ];
10957             species0.setRooted( true );
10958             gene1.setRooted( true );
10959             final SDIR sdi_unrooted = new SDIR();
10960             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10961             if ( sdi_unrooted.getCount() != 1 ) {
10962                 return false;
10963             }
10964             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10965                 return false;
10966             }
10967             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10968                 return false;
10969             }
10970             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10971                 return false;
10972             }
10973             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10974                 return false;
10975             }
10976             final Phylogeny gene2 = factory
10977                     .create( "(((((A:2.6[&&NHX:S=A],B:0.1[&&NHX:S=B])ab:0.1,C:0.1[&&NHX:S=C])abc:0.3,D:1.0[&&NHX:S=D])abcd:0.2,E:0.1[&&NHX:S=E])abcde:0.2,F:0.2[&&NHX:S=F])",
10978                              new NHXParser() )[ 0 ];
10979             gene2.setRooted( true );
10980             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10981             if ( sdi_unrooted.getCount() != 1 ) {
10982                 return false;
10983             }
10984             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10985                 return false;
10986             }
10987             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10988                 return false;
10989             }
10990             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10991                 return false;
10992             }
10993             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10994                 return false;
10995             }
10996             final Phylogeny species6 = factory
10997                     .create( "(((1:[&&NHX:S=1],5:[&&NHX:S=5])1-5,((4:[&&NHX:S=4],6:[&&NHX:S=6])4-6,2:[&&NHX:S=2])4-6-2)1-5-4-6-2,"
10998                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10999                             new NHXParser() )[ 0 ];
11000             final Phylogeny gene6 = factory
11001                     .create( "((5:0.1[&&NHX:S=5],6:0.1[&&NHX:S=6])5-6:0.05[&&NHX:S=6],(4:0.1[&&NHX:S=4],"
11002                             + "(((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],"
11003                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11004                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11005                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11006                             new NHXParser() )[ 0 ];
11007             species6.setRooted( true );
11008             gene6.setRooted( true );
11009             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
11010             if ( sdi_unrooted.getCount() != 1 ) {
11011                 return false;
11012             }
11013             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11014                 return false;
11015             }
11016             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11017                 return false;
11018             }
11019             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11020                 return false;
11021             }
11022             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11023                 return false;
11024             }
11025             if ( !p6[ 0 ].getRoot().isDuplication() ) {
11026                 return false;
11027             }
11028             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11029                 return false;
11030             }
11031             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11032                 return false;
11033             }
11034             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11035                 return false;
11036             }
11037             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11038                 return false;
11039             }
11040             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11041                 return false;
11042             }
11043             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11044                 return false;
11045             }
11046             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11047                 return false;
11048             }
11049             p6 = null;
11050             final Phylogeny species7 = factory
11051                     .create( "(((1:[&&NHX:S=1],5:[&&NHX:S=5])1-5,((4:[&&NHX:S=4],6:[&&NHX:S=6])4-6,2:[&&NHX:S=2])4-6-2)1-5-4-6-2,"
11052                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11053                             new NHXParser() )[ 0 ];
11054             final Phylogeny gene7 = factory
11055                     .create( "((5:0.1[&&NHX:S=5],6:0.1[&&NHX:S=6])5-6:0.05[&&NHX:S=6],(4:0.1[&&NHX:S=4],"
11056                             + "(((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],"
11057                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11058                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11059                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11060                             new NHXParser() )[ 0 ];
11061             species7.setRooted( true );
11062             gene7.setRooted( true );
11063             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11064             if ( sdi_unrooted.getCount() != 1 ) {
11065                 return false;
11066             }
11067             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11068                 return false;
11069             }
11070             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11071                 return false;
11072             }
11073             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11074                 return false;
11075             }
11076             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11077                 return false;
11078             }
11079             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11080                 return false;
11081             }
11082             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11083                 return false;
11084             }
11085             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11086                 return false;
11087             }
11088             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11089                 return false;
11090             }
11091             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11092                 return false;
11093             }
11094             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11095                 return false;
11096             }
11097             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11098                 return false;
11099             }
11100             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11101                 return false;
11102             }
11103             p7 = null;
11104             final Phylogeny species8 = factory
11105                     .create( "(((1:[&&NHX:S=1],5:[&&NHX:S=5])1-5,((4:[&&NHX:S=4],6:[&&NHX:S=6])4-6,2:[&&NHX:S=2])4-6-2)1-5-4-6-2,"
11106                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11107                             new NHXParser() )[ 0 ];
11108             final Phylogeny gene8 = factory
11109                     .create( "((5:0.1[&&NHX:S=5],6:0.1[&&NHX:S=6])5-6:0.05[&&NHX:S=6],(4:0.1[&&NHX:S=4],"
11110                             + "(((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],"
11111                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11112                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11113                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11114                             new NHXParser() )[ 0 ];
11115             species8.setRooted( true );
11116             gene8.setRooted( true );
11117             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11118             if ( sdi_unrooted.getCount() != 1 ) {
11119                 return false;
11120             }
11121             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11122                 return false;
11123             }
11124             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11125                 return false;
11126             }
11127             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11128                 return false;
11129             }
11130             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11131                 return false;
11132             }
11133             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11134                 return false;
11135             }
11136             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11137                 return false;
11138             }
11139             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11140                 return false;
11141             }
11142             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11143                 return false;
11144             }
11145             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11146                 return false;
11147             }
11148             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11149                 return false;
11150             }
11151             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11152                 return false;
11153             }
11154             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11155                 return false;
11156             }
11157             p8 = null;
11158         }
11159         catch ( final Exception e ) {
11160             e.printStackTrace( System.out );
11161             return false;
11162         }
11163         return true;
11164     }
11165
11166     private static boolean testSequenceDbWsTools1() {
11167         try {
11168             final PhylogenyNode n = new PhylogenyNode();
11169             n.setName( "NP_001025424" );
11170             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11171             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11172                     || !acc.getValue().equals( "NP_001025424" ) ) {
11173                 return false;
11174             }
11175             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11176             acc = SequenceDbWsTools.obtainSeqAccession( n );
11177             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11178                     || !acc.getValue().equals( "NP_001025424" ) ) {
11179                 return false;
11180             }
11181             n.setName( "NP_001025424.1" );
11182             acc = SequenceDbWsTools.obtainSeqAccession( n );
11183             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11184                     || !acc.getValue().equals( "NP_001025424" ) ) {
11185                 return false;
11186             }
11187             n.setName( "NM_001030253" );
11188             acc = SequenceDbWsTools.obtainSeqAccession( n );
11189             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11190                     || !acc.getValue().equals( "NM_001030253" ) ) {
11191                 return false;
11192             }
11193             n.setName( "BCL2_HUMAN" );
11194             acc = SequenceDbWsTools.obtainSeqAccession( n );
11195             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11196                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11197                 System.out.println( acc.toString() );
11198                 return false;
11199             }
11200             n.setName( "P10415" );
11201             acc = SequenceDbWsTools.obtainSeqAccession( n );
11202             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11203                     || !acc.getValue().equals( "P10415" ) ) {
11204                 System.out.println( acc.toString() );
11205                 return false;
11206             }
11207             n.setName( " P10415 " );
11208             acc = SequenceDbWsTools.obtainSeqAccession( n );
11209             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11210                     || !acc.getValue().equals( "P10415" ) ) {
11211                 System.out.println( acc.toString() );
11212                 return false;
11213             }
11214             n.setName( "_P10415|" );
11215             acc = SequenceDbWsTools.obtainSeqAccession( n );
11216             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11217                     || !acc.getValue().equals( "P10415" ) ) {
11218                 System.out.println( acc.toString() );
11219                 return false;
11220             }
11221             n.setName( "AY695820" );
11222             acc = SequenceDbWsTools.obtainSeqAccession( n );
11223             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11224                     || !acc.getValue().equals( "AY695820" ) ) {
11225                 System.out.println( acc.toString() );
11226                 return false;
11227             }
11228             n.setName( "_AY695820_" );
11229             acc = SequenceDbWsTools.obtainSeqAccession( n );
11230             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11231                     || !acc.getValue().equals( "AY695820" ) ) {
11232                 System.out.println( acc.toString() );
11233                 return false;
11234             }
11235             n.setName( "AAA59452" );
11236             acc = SequenceDbWsTools.obtainSeqAccession( n );
11237             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11238                     || !acc.getValue().equals( "AAA59452" ) ) {
11239                 System.out.println( acc.toString() );
11240                 return false;
11241             }
11242             n.setName( "_AAA59452_" );
11243             acc = SequenceDbWsTools.obtainSeqAccession( n );
11244             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11245                     || !acc.getValue().equals( "AAA59452" ) ) {
11246                 System.out.println( acc.toString() );
11247                 return false;
11248             }
11249             n.setName( "AAA59452.1" );
11250             acc = SequenceDbWsTools.obtainSeqAccession( n );
11251             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11252                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11253                 System.out.println( acc.toString() );
11254                 return false;
11255             }
11256             n.setName( "_AAA59452.1_" );
11257             acc = SequenceDbWsTools.obtainSeqAccession( n );
11258             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11259                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11260                 System.out.println( acc.toString() );
11261                 return false;
11262             }
11263             n.setName( "GI:94894583" );
11264             acc = SequenceDbWsTools.obtainSeqAccession( n );
11265             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11266                     || !acc.getValue().equals( "94894583" ) ) {
11267                 System.out.println( acc.toString() );
11268                 return false;
11269             }
11270             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11271             acc = SequenceDbWsTools.obtainSeqAccession( n );
11272             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11273                     || !acc.getValue().equals( "71845847" ) ) {
11274                 System.out.println( acc.toString() );
11275                 return false;
11276             }
11277             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11278             acc = SequenceDbWsTools.obtainSeqAccession( n );
11279             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11280                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11281                 System.out.println( acc.toString() );
11282                 return false;
11283             }
11284         }
11285         catch ( final Exception e ) {
11286             return false;
11287         }
11288         return true;
11289     }
11290
11291     private static boolean testSequenceDbWsTools2() {
11292         try {
11293             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11294             SequenceDbWsTools.obtainSeqInformation( n1 );
11295             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11296                 return false;
11297             }
11298             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11299                 return false;
11300             }
11301             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11302                 return false;
11303             }
11304             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11305                 return false;
11306             }
11307             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11308             SequenceDbWsTools.obtainSeqInformation( n2 );
11309             if ( !n2.getNodeData().getSequence().getName().equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
11310                 return false;
11311             }
11312             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11313                 return false;
11314             }
11315             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11316                 return false;
11317             }
11318             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11319                 return false;
11320             }
11321             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11322             SequenceDbWsTools.obtainSeqInformation( n3 );
11323             if ( !n3.getNodeData().getSequence().getName()
11324                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11325                 return false;
11326             }
11327             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11328                 return false;
11329             }
11330             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11331                 return false;
11332             }
11333             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11334                 return false;
11335             }
11336         }
11337         catch ( final IOException e ) {
11338             System.out.println();
11339             System.out.println( "the following might be due to absence internet connection:" );
11340             e.printStackTrace( System.out );
11341             return true;
11342         }
11343         catch ( final Exception e ) {
11344             e.printStackTrace();
11345             return false;
11346         }
11347         return true;
11348     }
11349
11350     private static boolean testSequenceIdParsing() {
11351         try {
11352             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11353             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11354                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11355                 if ( id != null ) {
11356                     System.out.println( "value   =" + id.getValue() );
11357                     System.out.println( "provider=" + id.getSource() );
11358                 }
11359                 return false;
11360             }
11361             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11362             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11363                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11364                 if ( id != null ) {
11365                     System.out.println( "value   =" + id.getValue() );
11366                     System.out.println( "provider=" + id.getSource() );
11367                 }
11368                 return false;
11369             }
11370             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11371             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11372                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11373                 if ( id != null ) {
11374                     System.out.println( "value   =" + id.getValue() );
11375                     System.out.println( "provider=" + id.getSource() );
11376                 }
11377                 return false;
11378             }
11379             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11380             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11381                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11382                 if ( id != null ) {
11383                     System.out.println( "value   =" + id.getValue() );
11384                     System.out.println( "provider=" + id.getSource() );
11385                 }
11386                 return false;
11387             }
11388             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11389             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11390                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11391                 if ( id != null ) {
11392                     System.out.println( "value   =" + id.getValue() );
11393                     System.out.println( "provider=" + id.getSource() );
11394                 }
11395                 return false;
11396             }
11397             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11398             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11399                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11400                 if ( id != null ) {
11401                     System.out.println( "value   =" + id.getValue() );
11402                     System.out.println( "provider=" + id.getSource() );
11403                 }
11404                 return false;
11405             }
11406             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11407             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11408                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11409                 if ( id != null ) {
11410                     System.out.println( "value   =" + id.getValue() );
11411                     System.out.println( "provider=" + id.getSource() );
11412                 }
11413                 return false;
11414             }
11415             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11416             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11417                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11418                 if ( id != null ) {
11419                     System.out.println( "value   =" + id.getValue() );
11420                     System.out.println( "provider=" + id.getSource() );
11421                 }
11422                 return false;
11423             }
11424             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11425             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11426                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11427                 if ( id != null ) {
11428                     System.out.println( "value   =" + id.getValue() );
11429                     System.out.println( "provider=" + id.getSource() );
11430                 }
11431                 return false;
11432             }
11433             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11434             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11435                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11436                 if ( id != null ) {
11437                     System.out.println( "value   =" + id.getValue() );
11438                     System.out.println( "provider=" + id.getSource() );
11439                 }
11440                 return false;
11441             }
11442             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11443             if ( id != null ) {
11444                 System.out.println( "value   =" + id.getValue() );
11445                 System.out.println( "provider=" + id.getSource() );
11446                 return false;
11447             }
11448             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
11449             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11450                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
11451                 if ( id != null ) {
11452                     System.out.println( "value   =" + id.getValue() );
11453                     System.out.println( "provider=" + id.getSource() );
11454                 }
11455                 return false;
11456             }
11457             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
11458             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11459                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11460                 if ( id != null ) {
11461                     System.out.println( "value   =" + id.getValue() );
11462                     System.out.println( "provider=" + id.getSource() );
11463                 }
11464                 return false;
11465             }
11466             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
11467             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11468                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11469                 if ( id != null ) {
11470                     System.out.println( "value   =" + id.getValue() );
11471                     System.out.println( "provider=" + id.getSource() );
11472                 }
11473                 return false;
11474             }
11475             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
11476             if ( id != null ) {
11477                 System.out.println( "value   =" + id.getValue() );
11478                 System.out.println( "provider=" + id.getSource() );
11479                 return false;
11480             }
11481         }
11482         catch ( final Exception e ) {
11483             e.printStackTrace( System.out );
11484             return false;
11485         }
11486         return true;
11487     }
11488
11489     private static boolean testSequenceWriter() {
11490         try {
11491             final String n = ForesterUtil.LINE_SEPARATOR;
11492             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11493                 return false;
11494             }
11495             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11496                 return false;
11497             }
11498             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11499                 return false;
11500             }
11501             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11502                 return false;
11503             }
11504             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11505                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11506                 return false;
11507             }
11508             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11509                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11510                 return false;
11511             }
11512         }
11513         catch ( final Exception e ) {
11514             e.printStackTrace();
11515             return false;
11516         }
11517         return true;
11518     }
11519
11520     private static boolean testSpecies() {
11521         try {
11522             final Species s1 = new BasicSpecies( "a" );
11523             final Species s2 = new BasicSpecies( "a" );
11524             final Species s3 = new BasicSpecies( "A" );
11525             final Species s4 = new BasicSpecies( "b" );
11526             if ( !s1.equals( s1 ) ) {
11527                 return false;
11528             }
11529             if ( s1.getSpeciesId().equals( "x" ) ) {
11530                 return false;
11531             }
11532             if ( s1.getSpeciesId().equals( null ) ) {
11533                 return false;
11534             }
11535             if ( !s1.equals( s2 ) ) {
11536                 return false;
11537             }
11538             if ( s1.equals( s3 ) ) {
11539                 return false;
11540             }
11541             if ( s1.hashCode() != s1.hashCode() ) {
11542                 return false;
11543             }
11544             if ( s1.hashCode() != s2.hashCode() ) {
11545                 return false;
11546             }
11547             if ( s1.hashCode() == s3.hashCode() ) {
11548                 return false;
11549             }
11550             if ( s1.compareTo( s1 ) != 0 ) {
11551                 return false;
11552             }
11553             if ( s1.compareTo( s2 ) != 0 ) {
11554                 return false;
11555             }
11556             if ( s1.compareTo( s3 ) != 0 ) {
11557                 return false;
11558             }
11559             if ( s1.compareTo( s4 ) >= 0 ) {
11560                 return false;
11561             }
11562             if ( s4.compareTo( s1 ) <= 0 ) {
11563                 return false;
11564             }
11565             if ( !s4.getSpeciesId().equals( "b" ) ) {
11566                 return false;
11567             }
11568             final Species s5 = new BasicSpecies( " C " );
11569             if ( !s5.getSpeciesId().equals( "C" ) ) {
11570                 return false;
11571             }
11572             if ( s5.equals( s1 ) ) {
11573                 return false;
11574             }
11575         }
11576         catch ( final Exception e ) {
11577             e.printStackTrace( System.out );
11578             return false;
11579         }
11580         return true;
11581     }
11582
11583     private static boolean testSplit() {
11584         try {
11585             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11586             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11587             //Archaeopteryx.createApplication( p0 );
11588             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11589             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11590             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11591             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11592             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11593             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11594             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11595             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11596             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11597             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11598             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11599             // System.out.println( s0.toString() );
11600             //
11601             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11602             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11603             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11604             if ( s0.match( query_nodes ) ) {
11605                 return false;
11606             }
11607             query_nodes = new HashSet<PhylogenyNode>();
11608             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11609             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11610             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11611             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11612             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11613             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11614             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11615             if ( !s0.match( query_nodes ) ) {
11616                 return false;
11617             }
11618             //
11619             query_nodes = new HashSet<PhylogenyNode>();
11620             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11621             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11622             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11623             if ( !s0.match( query_nodes ) ) {
11624                 return false;
11625             }
11626             //
11627             query_nodes = new HashSet<PhylogenyNode>();
11628             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11629             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11630             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11631             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11632             if ( !s0.match( query_nodes ) ) {
11633                 return false;
11634             }
11635             //
11636             query_nodes = new HashSet<PhylogenyNode>();
11637             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11638             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11640             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11641             if ( !s0.match( query_nodes ) ) {
11642                 return false;
11643             }
11644             //
11645             query_nodes = new HashSet<PhylogenyNode>();
11646             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11647             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11648             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11649             if ( !s0.match( query_nodes ) ) {
11650                 return false;
11651             }
11652             query_nodes = new HashSet<PhylogenyNode>();
11653             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11654             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11655             if ( !s0.match( query_nodes ) ) {
11656                 return false;
11657             }
11658             query_nodes = new HashSet<PhylogenyNode>();
11659             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11660             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11661             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11662             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11663             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11664             if ( !s0.match( query_nodes ) ) {
11665                 return false;
11666             }
11667             query_nodes = new HashSet<PhylogenyNode>();
11668             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11669             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11670             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11671             if ( !s0.match( query_nodes ) ) {
11672                 return false;
11673             }
11674             query_nodes = new HashSet<PhylogenyNode>();
11675             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11676             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11677             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11678             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11679             if ( !s0.match( query_nodes ) ) {
11680                 return false;
11681             }
11682             query_nodes = new HashSet<PhylogenyNode>();
11683             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11684             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11685             if ( s0.match( query_nodes ) ) {
11686                 return false;
11687             }
11688             query_nodes = new HashSet<PhylogenyNode>();
11689             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11690             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11691             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11692             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11693             if ( s0.match( query_nodes ) ) {
11694                 return false;
11695             }
11696             query_nodes = new HashSet<PhylogenyNode>();
11697             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11698             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11699             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11700             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11701             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11702             if ( s0.match( query_nodes ) ) {
11703                 return false;
11704             }
11705             query_nodes = new HashSet<PhylogenyNode>();
11706             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11707             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11708             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11709             if ( s0.match( query_nodes ) ) {
11710                 return false;
11711             }
11712             query_nodes = new HashSet<PhylogenyNode>();
11713             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11714             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11715             if ( s0.match( query_nodes ) ) {
11716                 return false;
11717             }
11718             query_nodes = new HashSet<PhylogenyNode>();
11719             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11720             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11721             if ( s0.match( query_nodes ) ) {
11722                 return false;
11723             }
11724             query_nodes = new HashSet<PhylogenyNode>();
11725             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11726             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11727             if ( s0.match( query_nodes ) ) {
11728                 return false;
11729             }
11730             query_nodes = new HashSet<PhylogenyNode>();
11731             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11732             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11733             if ( s0.match( query_nodes ) ) {
11734                 return false;
11735             }
11736             query_nodes = new HashSet<PhylogenyNode>();
11737             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11738             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11739             if ( s0.match( query_nodes ) ) {
11740                 return false;
11741             }
11742             query_nodes = new HashSet<PhylogenyNode>();
11743             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11744             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11745             if ( s0.match( query_nodes ) ) {
11746                 return false;
11747             }
11748             query_nodes = new HashSet<PhylogenyNode>();
11749             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11750             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11751             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11752             if ( s0.match( query_nodes ) ) {
11753                 return false;
11754             }
11755             query_nodes = new HashSet<PhylogenyNode>();
11756             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11757             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11758             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11759             if ( s0.match( query_nodes ) ) {
11760                 return false;
11761             }
11762             query_nodes = new HashSet<PhylogenyNode>();
11763             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11764             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11765             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11766             if ( s0.match( query_nodes ) ) {
11767                 return false;
11768             }
11769             query_nodes = new HashSet<PhylogenyNode>();
11770             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11771             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11772             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11773             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11774             if ( s0.match( query_nodes ) ) {
11775                 return false;
11776             }
11777             /////////
11778             //            query_nodes = new HashSet<PhylogenyNode>();
11779             //            query_nodes.add( new PhylogenyNode( "X" ) );
11780             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11781             //            query_nodes.add( new PhylogenyNode( "A" ) );
11782             //            query_nodes.add( new PhylogenyNode( "B" ) );
11783             //            query_nodes.add( new PhylogenyNode( "C" ) );
11784             //            query_nodes.add( new PhylogenyNode( "D" ) );
11785             //            query_nodes.add( new PhylogenyNode( "E" ) );
11786             //            query_nodes.add( new PhylogenyNode( "F" ) );
11787             //            query_nodes.add( new PhylogenyNode( "G" ) );
11788             //            if ( !s0.match( query_nodes ) ) {
11789             //                return false;
11790             //            }
11791             //            query_nodes = new HashSet<PhylogenyNode>();
11792             //            query_nodes.add( new PhylogenyNode( "X" ) );
11793             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11794             //            query_nodes.add( new PhylogenyNode( "A" ) );
11795             //            query_nodes.add( new PhylogenyNode( "B" ) );
11796             //            query_nodes.add( new PhylogenyNode( "C" ) );
11797             //            if ( !s0.match( query_nodes ) ) {
11798             //                return false;
11799             //            }
11800             //            //
11801             //            query_nodes = new HashSet<PhylogenyNode>();
11802             //            query_nodes.add( new PhylogenyNode( "X" ) );
11803             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11804             //            query_nodes.add( new PhylogenyNode( "D" ) );
11805             //            query_nodes.add( new PhylogenyNode( "E" ) );
11806             //            query_nodes.add( new PhylogenyNode( "F" ) );
11807             //            query_nodes.add( new PhylogenyNode( "G" ) );
11808             //            if ( !s0.match( query_nodes ) ) {
11809             //                return false;
11810             //            }
11811             //            //
11812             //            query_nodes = new HashSet<PhylogenyNode>();
11813             //            query_nodes.add( new PhylogenyNode( "X" ) );
11814             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11815             //            query_nodes.add( new PhylogenyNode( "A" ) );
11816             //            query_nodes.add( new PhylogenyNode( "B" ) );
11817             //            query_nodes.add( new PhylogenyNode( "C" ) );
11818             //            query_nodes.add( new PhylogenyNode( "D" ) );
11819             //            if ( !s0.match( query_nodes ) ) {
11820             //                return false;
11821             //            }
11822             //            //
11823             //            query_nodes = new HashSet<PhylogenyNode>();
11824             //            query_nodes.add( new PhylogenyNode( "X" ) );
11825             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11826             //            query_nodes.add( new PhylogenyNode( "E" ) );
11827             //            query_nodes.add( new PhylogenyNode( "F" ) );
11828             //            query_nodes.add( new PhylogenyNode( "G" ) );
11829             //            if ( !s0.match( query_nodes ) ) {
11830             //                return false;
11831             //            }
11832             //            //
11833             //            query_nodes = new HashSet<PhylogenyNode>();
11834             //            query_nodes.add( new PhylogenyNode( "X" ) );
11835             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11836             //            query_nodes.add( new PhylogenyNode( "F" ) );
11837             //            query_nodes.add( new PhylogenyNode( "G" ) );
11838             //            if ( !s0.match( query_nodes ) ) {
11839             //                return false;
11840             //            }
11841             //
11842             query_nodes = new HashSet<PhylogenyNode>();
11843             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11844             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11845             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11846             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11847             if ( s0.match( query_nodes ) ) {
11848                 return false;
11849             }
11850             //
11851             query_nodes = new HashSet<PhylogenyNode>();
11852             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11853             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11854             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11855             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11856             if ( s0.match( query_nodes ) ) {
11857                 return false;
11858             }
11859             ///////////////////////////
11860             //
11861             query_nodes = new HashSet<PhylogenyNode>();
11862             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11863             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11864             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11865             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11866             if ( s0.match( query_nodes ) ) {
11867                 return false;
11868             }
11869             //
11870             query_nodes = new HashSet<PhylogenyNode>();
11871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11872             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11873             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11874             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11875             if ( s0.match( query_nodes ) ) {
11876                 return false;
11877             }
11878             //
11879             query_nodes = new HashSet<PhylogenyNode>();
11880             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11881             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11882             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11883             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11884             if ( s0.match( query_nodes ) ) {
11885                 return false;
11886             }
11887             //
11888             query_nodes = new HashSet<PhylogenyNode>();
11889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11890             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11891             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11892             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11893             if ( s0.match( query_nodes ) ) {
11894                 return false;
11895             }
11896             //
11897             query_nodes = new HashSet<PhylogenyNode>();
11898             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11899             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11900             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11901             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11902             if ( s0.match( query_nodes ) ) {
11903                 return false;
11904             }
11905             //
11906             query_nodes = new HashSet<PhylogenyNode>();
11907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11908             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11909             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11910             if ( s0.match( query_nodes ) ) {
11911                 return false;
11912             }
11913             //
11914             query_nodes = new HashSet<PhylogenyNode>();
11915             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11916             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11917             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11918             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11919             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11920             if ( s0.match( query_nodes ) ) {
11921                 return false;
11922             }
11923             //
11924             query_nodes = new HashSet<PhylogenyNode>();
11925             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11926             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11927             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11928             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11929             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11930             if ( s0.match( query_nodes ) ) {
11931                 return false;
11932             }
11933             //
11934             query_nodes = new HashSet<PhylogenyNode>();
11935             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11936             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11937             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11938             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11939             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11940             if ( s0.match( query_nodes ) ) {
11941                 return false;
11942             }
11943             //
11944             query_nodes = new HashSet<PhylogenyNode>();
11945             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11946             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11947             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11948             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11949             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11950             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11951             if ( s0.match( query_nodes ) ) {
11952                 return false;
11953             }
11954         }
11955         catch ( final Exception e ) {
11956             e.printStackTrace();
11957             return false;
11958         }
11959         return true;
11960     }
11961
11962     private static boolean testSplitStrict() {
11963         try {
11964             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11965             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11966             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11967             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11968             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11969             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11970             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11971             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11972             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11973             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11974             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11975             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11976             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11977             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11978             if ( s0.match( query_nodes ) ) {
11979                 return false;
11980             }
11981             query_nodes = new HashSet<PhylogenyNode>();
11982             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11983             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11984             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11985             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11986             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11987             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11988             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11989             if ( !s0.match( query_nodes ) ) {
11990                 return false;
11991             }
11992             //
11993             query_nodes = new HashSet<PhylogenyNode>();
11994             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11995             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11996             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11997             if ( !s0.match( query_nodes ) ) {
11998                 return false;
11999             }
12000             //
12001             query_nodes = new HashSet<PhylogenyNode>();
12002             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12003             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12004             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12005             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12006             if ( !s0.match( query_nodes ) ) {
12007                 return false;
12008             }
12009             //
12010             query_nodes = new HashSet<PhylogenyNode>();
12011             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12012             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12013             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12014             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12015             if ( !s0.match( query_nodes ) ) {
12016                 return false;
12017             }
12018             //
12019             query_nodes = new HashSet<PhylogenyNode>();
12020             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12023             if ( !s0.match( query_nodes ) ) {
12024                 return false;
12025             }
12026             //
12027             query_nodes = new HashSet<PhylogenyNode>();
12028             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12029             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12030             if ( !s0.match( query_nodes ) ) {
12031                 return false;
12032             }
12033             //
12034             query_nodes = new HashSet<PhylogenyNode>();
12035             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12036             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12037             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12040             if ( !s0.match( query_nodes ) ) {
12041                 return false;
12042             }
12043             //
12044             query_nodes = new HashSet<PhylogenyNode>();
12045             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12046             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12048             if ( !s0.match( query_nodes ) ) {
12049                 return false;
12050             }
12051             //
12052             query_nodes = new HashSet<PhylogenyNode>();
12053             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12054             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12055             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12056             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12057             if ( !s0.match( query_nodes ) ) {
12058                 return false;
12059             }
12060             //
12061             query_nodes = new HashSet<PhylogenyNode>();
12062             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12063             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12064             if ( s0.match( query_nodes ) ) {
12065                 return false;
12066             }
12067             //
12068             query_nodes = new HashSet<PhylogenyNode>();
12069             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12070             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12071             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12072             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12073             if ( s0.match( query_nodes ) ) {
12074                 return false;
12075             }
12076             //
12077             query_nodes = new HashSet<PhylogenyNode>();
12078             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12079             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12080             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12081             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12082             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12083             if ( s0.match( query_nodes ) ) {
12084                 return false;
12085             }
12086             //
12087             query_nodes = new HashSet<PhylogenyNode>();
12088             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12089             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12090             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12091             if ( s0.match( query_nodes ) ) {
12092                 return false;
12093             }
12094             //
12095             query_nodes = new HashSet<PhylogenyNode>();
12096             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12097             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12098             if ( s0.match( query_nodes ) ) {
12099                 return false;
12100             }
12101             //
12102             query_nodes = new HashSet<PhylogenyNode>();
12103             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12104             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12105             if ( s0.match( query_nodes ) ) {
12106                 return false;
12107             }
12108             //
12109             query_nodes = new HashSet<PhylogenyNode>();
12110             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12111             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12112             if ( s0.match( query_nodes ) ) {
12113                 return false;
12114             }
12115             //
12116             query_nodes = new HashSet<PhylogenyNode>();
12117             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12118             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12119             if ( s0.match( query_nodes ) ) {
12120                 return false;
12121             }
12122             //
12123             query_nodes = new HashSet<PhylogenyNode>();
12124             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12125             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12126             if ( s0.match( query_nodes ) ) {
12127                 return false;
12128             }
12129             //
12130             query_nodes = new HashSet<PhylogenyNode>();
12131             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12132             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12133             if ( s0.match( query_nodes ) ) {
12134                 return false;
12135             }
12136             //
12137             query_nodes = new HashSet<PhylogenyNode>();
12138             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12139             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12140             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12141             if ( s0.match( query_nodes ) ) {
12142                 return false;
12143             }
12144             //
12145             query_nodes = new HashSet<PhylogenyNode>();
12146             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12147             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12148             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12149             if ( s0.match( query_nodes ) ) {
12150                 return false;
12151             }
12152             //
12153             query_nodes = new HashSet<PhylogenyNode>();
12154             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12155             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12156             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12157             if ( s0.match( query_nodes ) ) {
12158                 return false;
12159             }
12160             //
12161             query_nodes = new HashSet<PhylogenyNode>();
12162             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12163             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12164             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12165             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12166             if ( s0.match( query_nodes ) ) {
12167                 return false;
12168             }
12169         }
12170         catch ( final Exception e ) {
12171             e.printStackTrace();
12172             return false;
12173         }
12174         return true;
12175     }
12176
12177     private static boolean testSubtreeDeletion() {
12178         try {
12179             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12180             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12181             t1.deleteSubtree( t1.getNode( "A" ), false );
12182             if ( t1.getNumberOfExternalNodes() != 5 ) {
12183                 return false;
12184             }
12185             t1.toNewHampshireX();
12186             t1.deleteSubtree( t1.getNode( "E" ), false );
12187             if ( t1.getNumberOfExternalNodes() != 4 ) {
12188                 return false;
12189             }
12190             t1.toNewHampshireX();
12191             t1.deleteSubtree( t1.getNode( "F" ), false );
12192             if ( t1.getNumberOfExternalNodes() != 3 ) {
12193                 return false;
12194             }
12195             t1.toNewHampshireX();
12196             t1.deleteSubtree( t1.getNode( "D" ), false );
12197             t1.toNewHampshireX();
12198             if ( t1.getNumberOfExternalNodes() != 3 ) {
12199                 return false;
12200             }
12201             t1.deleteSubtree( t1.getNode( "def" ), false );
12202             t1.toNewHampshireX();
12203             if ( t1.getNumberOfExternalNodes() != 2 ) {
12204                 return false;
12205             }
12206             t1.deleteSubtree( t1.getNode( "B" ), false );
12207             t1.toNewHampshireX();
12208             if ( t1.getNumberOfExternalNodes() != 1 ) {
12209                 return false;
12210             }
12211             t1.deleteSubtree( t1.getNode( "C" ), false );
12212             t1.toNewHampshireX();
12213             if ( t1.getNumberOfExternalNodes() != 1 ) {
12214                 return false;
12215             }
12216             t1.deleteSubtree( t1.getNode( "abc" ), false );
12217             t1.toNewHampshireX();
12218             if ( t1.getNumberOfExternalNodes() != 1 ) {
12219                 return false;
12220             }
12221             t1.deleteSubtree( t1.getNode( "r" ), false );
12222             if ( t1.getNumberOfExternalNodes() != 0 ) {
12223                 return false;
12224             }
12225             if ( !t1.isEmpty() ) {
12226                 return false;
12227             }
12228             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12229             t2.deleteSubtree( t2.getNode( "A" ), false );
12230             t2.toNewHampshireX();
12231             if ( t2.getNumberOfExternalNodes() != 5 ) {
12232                 return false;
12233             }
12234             t2.deleteSubtree( t2.getNode( "abc" ), false );
12235             t2.toNewHampshireX();
12236             if ( t2.getNumberOfExternalNodes() != 3 ) {
12237                 return false;
12238             }
12239             t2.deleteSubtree( t2.getNode( "def" ), false );
12240             t2.toNewHampshireX();
12241             if ( t2.getNumberOfExternalNodes() != 1 ) {
12242                 return false;
12243             }
12244         }
12245         catch ( final Exception e ) {
12246             e.printStackTrace( System.out );
12247             return false;
12248         }
12249         return true;
12250     }
12251
12252     private static boolean testSupportCount() {
12253         try {
12254             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12255             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12256             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12257                     + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12258                     + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12259                     + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12260                     + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12261                     new NHXParser() );
12262             SupportCount.count( t0_1, phylogenies_1, true, false );
12263             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12264             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12265                     + "(((((A,B),C),D),E),((F,G),X))"
12266                     + "(((((A,Y),B),C),D),((F,G),E))"
12267                     + "(((((A,B),C),D),E),(F,G))"
12268                     + "(((((A,B),C),D),E),(F,G))"
12269                     + "(((((A,B),C),D),E),(F,G))"
12270                     + "(((((A,B),C),D),E),(F,G),Z)"
12271                     + "(((((A,B),C),D),E),(F,G))"
12272                     + "((((((A,B),C),D),E),F),G)"
12273                     + "(((((X,Y),F,G),E),((A,B),C)),D)",
12274                     new NHXParser() );
12275             SupportCount.count( t0_2, phylogenies_2, true, false );
12276             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12277             while ( it.hasNext() ) {
12278                 final PhylogenyNode n = it.next();
12279                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12280                     return false;
12281                 }
12282             }
12283             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12284             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12285                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12286             SupportCount.count( t0_3, phylogenies_3, true, false );
12287             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12288             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12289                 return false;
12290             }
12291             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12292                 return false;
12293             }
12294             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12295                 return false;
12296             }
12297             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12298                 return false;
12299             }
12300             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12301                 return false;
12302             }
12303             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12304                 return false;
12305             }
12306             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12307                 return false;
12308             }
12309             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12310                 return false;
12311             }
12312             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12313                 return false;
12314             }
12315             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12316                 return false;
12317             }
12318             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12319             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12320                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12321             SupportCount.count( t0_4, phylogenies_4, true, false );
12322             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12323             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12324                 return false;
12325             }
12326             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12327                 return false;
12328             }
12329             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12330                 return false;
12331             }
12332             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12333                 return false;
12334             }
12335             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12336                 return false;
12337             }
12338             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12339                 return false;
12340             }
12341             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12342                 return false;
12343             }
12344             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12345                 return false;
12346             }
12347             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12348                 return false;
12349             }
12350             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12351                 return false;
12352             }
12353             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12354             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12355             double d = SupportCount.compare( b1, a, true, true, true );
12356             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12357                 return false;
12358             }
12359             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12360             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12361             d = SupportCount.compare( b2, a, true, true, true );
12362             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12363                 return false;
12364             }
12365             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12366             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12367             d = SupportCount.compare( b3, a, true, true, true );
12368             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12369                 return false;
12370             }
12371             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12372             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12373             d = SupportCount.compare( b4, a, true, true, false );
12374             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12375                 return false;
12376             }
12377         }
12378         catch ( final Exception e ) {
12379             e.printStackTrace( System.out );
12380             return false;
12381         }
12382         return true;
12383     }
12384
12385     private static boolean testSupportTransfer() {
12386         try {
12387             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12388             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)",
12389                                                  new NHXParser() )[ 0 ];
12390             final Phylogeny p2 = factory
12391                     .create( "(((A:0.1,B:0.3)ab:0.4,C)abc:0.5,((D,E)de,(F,G)fg,(H,I)hi:0.59)defghi)", new NHXParser() )[ 0 ];
12392             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12393                 return false;
12394             }
12395             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12396                 return false;
12397             }
12398             support_transfer.moveBranchLengthsToBootstrap( p1 );
12399             support_transfer.transferSupportValues( p1, p2 );
12400             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12401                 return false;
12402             }
12403             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12404                 return false;
12405             }
12406             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12407                 return false;
12408             }
12409             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12410                 return false;
12411             }
12412             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12413                 return false;
12414             }
12415             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12416                 return false;
12417             }
12418             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12419                 return false;
12420             }
12421             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12422                 return false;
12423             }
12424         }
12425         catch ( final Exception e ) {
12426             e.printStackTrace( System.out );
12427             return false;
12428         }
12429         return true;
12430     }
12431
12432     private static boolean testTaxonomyExtraction() {
12433         try {
12434             final PhylogenyNode n0 = PhylogenyNode
12435                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12436             if ( n0.getNodeData().isHasTaxonomy() ) {
12437                 return false;
12438             }
12439             final PhylogenyNode n1 = PhylogenyNode
12440                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12441             if ( n1.getNodeData().isHasTaxonomy() ) {
12442                 System.out.println( n1.toString() );
12443                 return false;
12444             }
12445             final PhylogenyNode n2x = PhylogenyNode
12446                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12447             if ( n2x.getNodeData().isHasTaxonomy() ) {
12448                 return false;
12449             }
12450             final PhylogenyNode n3 = PhylogenyNode
12451                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12452             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12453                 System.out.println( n3.toString() );
12454                 return false;
12455             }
12456             final PhylogenyNode n4 = PhylogenyNode
12457                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12458             if ( n4.getNodeData().isHasTaxonomy() ) {
12459                 System.out.println( n4.toString() );
12460                 return false;
12461             }
12462             final PhylogenyNode n5 = PhylogenyNode
12463                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12464             if ( n5.getNodeData().isHasTaxonomy() ) {
12465                 System.out.println( n5.toString() );
12466                 return false;
12467             }
12468             final PhylogenyNode n6 = PhylogenyNode
12469                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12470             if ( n6.getNodeData().isHasTaxonomy() ) {
12471                 System.out.println( n6.toString() );
12472                 return false;
12473             }
12474             final PhylogenyNode n7 = PhylogenyNode
12475                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12476             if ( n7.getNodeData().isHasTaxonomy() ) {
12477                 System.out.println( n7.toString() );
12478                 return false;
12479             }
12480             final PhylogenyNode n8 = PhylogenyNode
12481                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12482             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12483                 System.out.println( n8.toString() );
12484                 return false;
12485             }
12486             final PhylogenyNode n9 = PhylogenyNode
12487                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12488             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12489                 System.out.println( n9.toString() );
12490                 return false;
12491             }
12492             final PhylogenyNode n10x = PhylogenyNode
12493                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12494             if ( n10x.getNodeData().isHasTaxonomy() ) {
12495                 System.out.println( n10x.toString() );
12496                 return false;
12497             }
12498             final PhylogenyNode n10xx = PhylogenyNode
12499                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12500             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12501                 System.out.println( n10xx.toString() );
12502                 return false;
12503             }
12504             final PhylogenyNode n10 = PhylogenyNode
12505                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12506             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12507                 System.out.println( n10.toString() );
12508                 return false;
12509             }
12510             final PhylogenyNode n11 = PhylogenyNode
12511                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12512             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12513                 System.out.println( n11.toString() );
12514                 return false;
12515             }
12516             final PhylogenyNode n12 = PhylogenyNode
12517                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12518                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12519             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12520                 System.out.println( n12.toString() );
12521                 return false;
12522             }
12523             final PhylogenyNode n13 = PhylogenyNode
12524                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12525             if ( n13.getNodeData().isHasTaxonomy() ) {
12526                 System.out.println( n13.toString() );
12527                 return false;
12528             }
12529             final PhylogenyNode n14 = PhylogenyNode
12530                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12531             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12532                 System.out.println( n14.toString() );
12533                 return false;
12534             }
12535             final PhylogenyNode n15 = PhylogenyNode
12536                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12537             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12538                 System.out.println( n15.toString() );
12539                 return false;
12540             }
12541             final PhylogenyNode n16 = PhylogenyNode
12542                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12543             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12544                 System.out.println( n16.toString() );
12545                 return false;
12546             }
12547             final PhylogenyNode n17 = PhylogenyNode
12548                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12549             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12550                 System.out.println( n17.toString() );
12551                 return false;
12552             }
12553             final PhylogenyNode n18 = PhylogenyNode
12554                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12555             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12556                 System.out.println( n18.toString() );
12557                 return false;
12558             }
12559             final PhylogenyNode n19 = PhylogenyNode
12560                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12561                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12562             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12563                 System.out.println( n19.toString() );
12564                 return false;
12565             }
12566             final PhylogenyNode n20 = PhylogenyNode
12567                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12568             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12569                 System.out.println( n20.toString() );
12570                 return false;
12571             }
12572             final PhylogenyNode n21 = PhylogenyNode
12573                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12574                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12575             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12576                 System.out.println( n21.toString() );
12577                 return false;
12578             }
12579             final PhylogenyNode n23 = PhylogenyNode
12580                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12581                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12582             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12583                 System.out.println( n23.toString() );
12584                 return false;
12585             }
12586             final PhylogenyNode n24 = PhylogenyNode
12587                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12588             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12589                 System.out.println( n24.toString() );
12590                 return false;
12591             }
12592             //
12593             final PhylogenyNode n25 = PhylogenyNode
12594                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12595                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12596             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12597                 System.out.println( n25.toString() );
12598                 return false;
12599             }
12600             final PhylogenyNode n26 = PhylogenyNode
12601                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12602                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12603             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12604                 System.out.println( n26.toString() );
12605                 return false;
12606             }
12607             final PhylogenyNode n27 = PhylogenyNode
12608                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12609             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12610                 System.out.println( n27.toString() );
12611                 return false;
12612             }
12613         }
12614         catch ( final Exception e ) {
12615             e.printStackTrace( System.out );
12616             return false;
12617         }
12618         return true;
12619     }
12620
12621     private static boolean testTreeCopy() {
12622         try {
12623             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12624             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12625             final Phylogeny t1 = t0.copy();
12626             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12627                 return false;
12628             }
12629             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12630                 return false;
12631             }
12632             t0.deleteSubtree( t0.getNode( "c" ), true );
12633             t0.deleteSubtree( t0.getNode( "a" ), true );
12634             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12635             t0.getNode( "b" ).setName( "Bee" );
12636             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12637                 return false;
12638             }
12639             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12640                 return false;
12641             }
12642             t0.deleteSubtree( t0.getNode( "e" ), true );
12643             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12644             t0.deleteSubtree( t0.getNode( "d" ), true );
12645             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12646                 return false;
12647             }
12648         }
12649         catch ( final Exception e ) {
12650             e.printStackTrace();
12651             return false;
12652         }
12653         return true;
12654     }
12655
12656     private static boolean testTreeMethods() {
12657         try {
12658             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12659             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12660             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12661             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12662                 System.out.println( t0.toNewHampshireX() );
12663                 return false;
12664             }
12665             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12666             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12667             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12668                 return false;
12669             }
12670             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12671                 return false;
12672             }
12673             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12674                 return false;
12675             }
12676         }
12677         catch ( final Exception e ) {
12678             e.printStackTrace( System.out );
12679             return false;
12680         }
12681         return true;
12682     }
12683
12684     private static boolean testUniprotEntryRetrieval() {
12685         try {
12686             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 5000 );
12687             if ( !entry.getAccession().equals( "P12345" ) ) {
12688                 return false;
12689             }
12690             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12691                 return false;
12692             }
12693             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12694                 return false;
12695             }
12696             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12697                 return false;
12698             }
12699             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12700                 return false;
12701             }
12702             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12703                 return false;
12704             }
12705             if ( entry.getMolecularSequence() == null ) {
12706                 return false;
12707             }
12708             if ( !entry
12709                     .getMolecularSequence()
12710                     .getMolecularSequenceAsString()
12711                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
12712                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
12713                 System.out.println( "got: " + entry.getMolecularSequence().getMolecularSequenceAsString() );
12714                 System.out.println( "expected something else." );
12715                 return false;
12716             }
12717         }
12718         catch ( final IOException e ) {
12719             System.out.println();
12720             System.out.println( "the following might be due to absence internet connection:" );
12721             e.printStackTrace( System.out );
12722             return true;
12723         }
12724         catch ( final NullPointerException f ) {
12725             f.printStackTrace( System.out );
12726             return false;
12727         }
12728         catch ( final Exception e ) {
12729             return false;
12730         }
12731         return true;
12732     }
12733
12734     private static boolean testUniprotTaxonomySearch() {
12735         try {
12736             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12737                                                                                                  10 );
12738             if ( results.size() != 1 ) {
12739                 return false;
12740             }
12741             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12742                 return false;
12743             }
12744             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12745                 return false;
12746             }
12747             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12748                 return false;
12749             }
12750             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12751                 return false;
12752             }
12753             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12754                 return false;
12755             }
12756             results = null;
12757             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12758             if ( results.size() != 1 ) {
12759                 return false;
12760             }
12761             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12762                 return false;
12763             }
12764             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12765                 return false;
12766             }
12767             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12768                 return false;
12769             }
12770             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12771                 return false;
12772             }
12773             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12774                 return false;
12775             }
12776             results = null;
12777             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12778             if ( results.size() != 1 ) {
12779                 return false;
12780             }
12781             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12782                 return false;
12783             }
12784             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12785                 return false;
12786             }
12787             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12788                 return false;
12789             }
12790             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12791                 return false;
12792             }
12793             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12794                 return false;
12795             }
12796             results = null;
12797             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12798             if ( results.size() != 1 ) {
12799                 return false;
12800             }
12801             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12802                 return false;
12803             }
12804             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12805                 return false;
12806             }
12807             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12808                 return false;
12809             }
12810             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12811                 return false;
12812             }
12813             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12814                 return false;
12815             }
12816             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12817                 return false;
12818             }
12819             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12820                 return false;
12821             }
12822             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12823                     .equals( "Nematostella vectensis" ) ) {
12824                 System.out.println( results.get( 0 ).getLineage() );
12825                 return false;
12826             }
12827             //
12828             results = null;
12829             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12830             if ( results.size() != 1 ) {
12831                 return false;
12832             }
12833             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12834                 return false;
12835             }
12836             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12837                 return false;
12838             }
12839             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12840                 return false;
12841             }
12842             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12843                 return false;
12844             }
12845             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12846                 return false;
12847             }
12848             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12849                     .equals( "Xenopus tropicalis" ) ) {
12850                 System.out.println( results.get( 0 ).getLineage() );
12851                 return false;
12852             }
12853             //
12854             results = null;
12855             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12856             if ( results.size() != 1 ) {
12857                 return false;
12858             }
12859             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12860                 return false;
12861             }
12862             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12863                 return false;
12864             }
12865             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12866                 return false;
12867             }
12868             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12869                 return false;
12870             }
12871             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12872                 return false;
12873             }
12874             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12875                     .equals( "Xenopus tropicalis" ) ) {
12876                 System.out.println( results.get( 0 ).getLineage() );
12877                 return false;
12878             }
12879             //
12880             results = null;
12881             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12882             if ( results.size() != 1 ) {
12883                 return false;
12884             }
12885             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12886                 return false;
12887             }
12888             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12889                 return false;
12890             }
12891             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12892                 return false;
12893             }
12894             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12895                 return false;
12896             }
12897             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12898                 return false;
12899             }
12900             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12901                     .equals( "Xenopus tropicalis" ) ) {
12902                 System.out.println( results.get( 0 ).getLineage() );
12903                 return false;
12904             }
12905         }
12906         catch ( final IOException e ) {
12907             System.out.println();
12908             System.out.println( "the following might be due to absence internet connection:" );
12909             e.printStackTrace( System.out );
12910             return true;
12911         }
12912         catch ( final Exception e ) {
12913             return false;
12914         }
12915         return true;
12916     }
12917 }