in progress
[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 javax.net.ssl.HttpsURLConnection;
44 import javax.net.ssl.SSLContext;
45
46 import org.forester.application.support_transfer;
47 import org.forester.archaeopteryx.AptxUtil;
48 import org.forester.archaeopteryx.TreePanelUtil;
49 import org.forester.archaeopteryx.webservices.WebserviceUtil;
50 import org.forester.development.DevelopmentTools;
51 import org.forester.evoinference.TestPhylogenyReconstruction;
52 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
53 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
54 import org.forester.go.TestGo;
55 import org.forester.io.parsers.FastaParser;
56 import org.forester.io.parsers.GeneralMsaParser;
57 import org.forester.io.parsers.HmmscanPerDomainTableParser;
58 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
59 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
60 import org.forester.io.parsers.nexus.NexusCharactersParser;
61 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
62 import org.forester.io.parsers.nhx.NHXParser;
63 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
64 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
65 import org.forester.io.parsers.tol.TolParser;
66 import org.forester.io.parsers.util.ParserUtils;
67 import org.forester.io.writers.PhylogenyWriter;
68 import org.forester.io.writers.SequenceWriter;
69 import org.forester.msa.BasicMsa;
70 import org.forester.msa.DeleteableMsa;
71 import org.forester.msa.Mafft;
72 import org.forester.msa.Msa;
73 import org.forester.msa.Msa.MSA_FORMAT;
74 import org.forester.msa.MsaInferrer;
75 import org.forester.msa.MsaMethods;
76 import org.forester.pccx.TestPccx;
77 import org.forester.phylogeny.Phylogeny;
78 import org.forester.phylogeny.PhylogenyBranch;
79 import org.forester.phylogeny.PhylogenyMethods;
80 import org.forester.phylogeny.PhylogenyNode;
81 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
82 import org.forester.phylogeny.data.Accession;
83 import org.forester.phylogeny.data.Accession.Source;
84 import org.forester.phylogeny.data.BinaryCharacters;
85 import org.forester.phylogeny.data.BranchWidth;
86 import org.forester.phylogeny.data.Confidence;
87 import org.forester.phylogeny.data.Distribution;
88 import org.forester.phylogeny.data.DomainArchitecture;
89 import org.forester.phylogeny.data.Event;
90 import org.forester.phylogeny.data.Identifier;
91 import org.forester.phylogeny.data.PhylogenyData;
92 import org.forester.phylogeny.data.PhylogenyDataUtil;
93 import org.forester.phylogeny.data.Polygon;
94 import org.forester.phylogeny.data.PropertiesMap;
95 import org.forester.phylogeny.data.Property;
96 import org.forester.phylogeny.data.Property.AppliesTo;
97 import org.forester.phylogeny.data.ProteinDomain;
98 import org.forester.phylogeny.data.Taxonomy;
99 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
100 import org.forester.phylogeny.factories.PhylogenyFactory;
101 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
102 import org.forester.protein.BasicDomain;
103 import org.forester.protein.BasicProtein;
104 import org.forester.protein.Domain;
105 import org.forester.protein.Protein;
106 import org.forester.protein.ProteinId;
107 import org.forester.rio.TestRIO;
108 import org.forester.sdi.SDI;
109 import org.forester.sdi.SDIR;
110 import org.forester.sdi.TestGSDI;
111 import org.forester.sequence.BasicSequence;
112 import org.forester.sequence.MolecularSequence;
113 import org.forester.species.BasicSpecies;
114 import org.forester.species.Species;
115 import org.forester.surfacing.TestSurfacing;
116 import org.forester.tools.ConfidenceAssessor;
117 import org.forester.tools.SupportCount;
118 import org.forester.tools.TreeSplitMatrix;
119 import org.forester.util.AsciiHistogram;
120 import org.forester.util.BasicDescriptiveStatistics;
121 import org.forester.util.BasicTable;
122 import org.forester.util.BasicTableParser;
123 import org.forester.util.DescriptiveStatistics;
124 import org.forester.util.ForesterConstants;
125 import org.forester.util.ForesterUtil;
126 import org.forester.util.GeneralTable;
127 import org.forester.util.SequenceAccessionTools;
128 import org.forester.ws.seqdb.SequenceDatabaseEntry;
129 import org.forester.ws.seqdb.SequenceDbWsTools;
130 import org.forester.ws.seqdb.UniProtTaxonomy;
131
132
133 @SuppressWarnings( "unused")
134 public final class Test {
135
136     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
137             + ForesterUtil.getFileSeparator() + "resources"
138             + ForesterUtil.getFileSeparator();
139     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
140             + ForesterUtil.getFileSeparator() + "test_data"
141             + ForesterUtil.getFileSeparator();
142     private final static boolean PERFORM_DB_TESTS          = true;
143     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
144     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
145             + ForesterConstants.PHYLO_XML_VERSION + "/"
146             + ForesterConstants.PHYLO_XML_XSD;
147     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
148             + ForesterConstants.PHYLO_XML_VERSION + "/"
149             + ForesterConstants.PHYLO_XML_XSD;
150     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
151     private final static double  ZERO_DIFF                 = 1.0E-9;
152
153     private static boolean isEqual( final double a, final double b ) {
154         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
155     }
156
157     public static void main( final String[] args ) {
158         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
159         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
160                             + "]" );
161         Locale.setDefault( Locale.US );
162         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
163         int failed = 0;
164         int succeeded = 0;
165         System.out.print( "[Test if directory with files for testing exists/is readable: " );
166         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
167             System.out.println( "OK.]" );
168         }
169         else {
170             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
171             System.out.println( "Testing aborted." );
172             System.exit( -1 );
173         }
174         System.out.print( "[Test if resources directory exists/is readable: " );
175         if ( testDir( PATH_TO_RESOURCES ) ) {
176             System.out.println( "OK.]" );
177         }
178         else {
179             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
180             System.out.println( "Testing aborted." );
181             System.exit( -1 );
182         }
183         final long start_time = new Date().getTime();
184         
185         System.out.print( "Basic node methods: " );
186         if ( Test.testBasicNodeMethods() ) {
187             System.out.println( "OK." );
188             succeeded++;
189         }
190         else {
191             System.out.println( "failed." );
192             failed++;
193         }
194         System.out.print( "Protein id: " );
195         if ( !testProteinId() ) {
196             System.out.println( "failed." );
197             failed++;
198         }
199         else {
200             succeeded++;
201         }
202         System.out.println( "OK." );
203         System.out.print( "Species: " );
204         if ( !testSpecies() ) {
205             System.out.println( "failed." );
206             failed++;
207         }
208         else {
209             succeeded++;
210         }
211         System.out.println( "OK." );
212         System.out.print( "Basic domain: " );
213         if ( !testBasicDomain() ) {
214             System.out.println( "failed." );
215             failed++;
216         }
217         else {
218             succeeded++;
219         }
220         System.out.println( "OK." );
221         System.out.print( "Basic protein: " );
222         if ( !testBasicProtein() ) {
223             System.out.println( "failed." );
224             failed++;
225         }
226         else {
227             succeeded++;
228         }
229         System.out.println( "OK." );
230         System.out.print( "Sequence writer: " );
231         if ( testSequenceWriter() ) {
232             System.out.println( "OK." );
233             succeeded++;
234         }
235         else {
236             System.out.println( "failed." );
237             failed++;
238         }
239         System.out.print( "Sequence id parsing: " );
240         if ( testSequenceIdParsing() ) {
241             System.out.println( "OK." );
242             succeeded++;
243         }
244         else {
245             System.out.println( "failed." );
246             failed++;
247         }
248         System.out.print( "UniProtKB id extraction: " );
249         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
250             System.out.println( "OK." );
251             succeeded++;
252         }
253         else {
254             System.out.println( "failed." );
255             failed++;
256         }
257         System.out.print( "Sequence DB tools 1: " );
258         if ( testSequenceDbWsTools1() ) {
259             System.out.println( "OK." );
260             succeeded++;
261         }
262         else {
263             System.out.println( "failed." );
264             failed++;
265         }
266         System.out.print( "Hmmscan output parser: " );
267         if ( testHmmscanOutputParser() ) {
268             System.out.println( "OK." );
269             succeeded++;
270         }
271         else {
272             System.out.println( "failed." );
273             failed++;
274         }
275         System.out.print( "Overlap removal: " );
276         if ( !org.forester.test.Test.testOverlapRemoval() ) {
277             System.out.println( "failed." );
278             failed++;
279         }
280         else {
281             succeeded++;
282         }
283         System.out.println( "OK." );
284         System.out.print( "Engulfing overlap removal: " );
285         if ( !Test.testEngulfingOverlapRemoval() ) {
286             System.out.println( "failed." );
287             failed++;
288         }
289         else {
290             succeeded++;
291         }
292         System.out.println( "OK." );
293         System.out.print( "Taxonomy data extraction: " );
294         if ( Test.testExtractTaxonomyDataFromNodeName() ) {
295             System.out.println( "OK." );
296             succeeded++;
297         }
298         else {
299             System.out.println( "failed." );
300             failed++;
301         }
302         System.out.print( "Taxonomy code extraction: " );
303         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
304             System.out.println( "OK." );
305             succeeded++;
306         }
307         else {
308             System.out.println( "failed." );
309             failed++;
310         }
311         System.out.print( "SN extraction: " );
312         if ( Test.testExtractSNFromNodeName() ) {
313             System.out.println( "OK." );
314             succeeded++;
315         }
316         else {
317             System.out.println( "failed." );
318             failed++;
319         }
320         System.out.print( "Taxonomy extraction (general): " );
321         if ( Test.testTaxonomyExtraction() ) {
322             System.out.println( "OK." );
323             succeeded++;
324         }
325         else {
326             System.out.println( "failed." );
327             failed++;
328         }
329         System.out.print( "Uri for Aptx web sequence accession: " );
330         if ( Test.testCreateUriForSeqWeb() ) {
331             System.out.println( "OK." );
332             succeeded++;
333         }
334         else {
335             System.out.println( "failed." );
336             failed++;
337         }
338         System.out.print( "Basic node construction and parsing of NHX (node level): " );
339         if ( Test.testNHXNodeParsing() ) {
340             System.out.println( "OK." );
341             succeeded++;
342         }
343         else {
344             System.out.println( "failed." );
345             failed++;
346         }
347         System.out.print( "Node construction and parsing of NHX (node level): " );
348         if ( Test.testNHXNodeParsing2() ) {
349             System.out.println( "OK." );
350             succeeded++;
351         }
352         else {
353             System.out.println( "failed." );
354             failed++;
355         }
356         System.out.print( "NHX parsing iterating: " );
357         if ( Test.testNHParsingIter() ) {
358             System.out.println( "OK." );
359             succeeded++;
360         }
361         else {
362             System.out.println( "failed." );
363             failed++;
364         }
365         System.out.print( "NH parsing: " );
366         if ( Test.testNHParsing() ) {
367             System.out.println( "OK." );
368             succeeded++;
369         }
370         else {
371             System.out.println( "failed." );
372             failed++;
373         }
374         System.out.print( "NH parsing - special chars: " );
375         if ( Test.testNHParsingSpecialChars() ) {
376             System.out.println( "OK." );
377             succeeded++;
378         }
379         else {
380             System.out.println( "failed." );
381             failed++;
382         }
383         System.out.print( "Conversion to NHX (node level): " );
384         if ( Test.testNHXconversion() ) {
385             System.out.println( "OK." );
386             succeeded++;
387         }
388         else {
389             System.out.println( "failed." );
390             failed++;
391         }
392         System.out.print( "NHX parsing: " );
393         if ( Test.testNHXParsing() ) {
394             System.out.println( "OK." );
395             succeeded++;
396         }
397         else {
398             System.out.println( "failed." );
399             failed++;
400         }
401         System.out.print( "NHX parsing with quotes: " );
402         if ( Test.testNHXParsingQuotes() ) {
403             System.out.println( "OK." );
404             succeeded++;
405         }
406         else {
407             System.out.println( "failed." );
408             failed++;
409         }
410         System.out.print( "NHX parsing (MrBayes): " );
411         if ( Test.testNHXParsingMB() ) {
412             System.out.println( "OK." );
413             succeeded++;
414         }
415         else {
416             System.out.println( "failed." );
417             failed++;
418         }
419         System.out.print( "Nexus characters parsing: " );
420         if ( Test.testNexusCharactersParsing() ) {
421             System.out.println( "OK." );
422             succeeded++;
423         }
424         else {
425             System.out.println( "failed." );
426             failed++;
427         }
428         System.out.print( "Nexus tree parsing iterating: " );
429         if ( Test.testNexusTreeParsingIterating() ) {
430             System.out.println( "OK." );
431             succeeded++;
432         }
433         else {
434             System.out.println( "failed." );
435             failed++;
436         }
437         System.out.print( "Nexus tree parsing: " );
438         if ( Test.testNexusTreeParsing() ) {
439             System.out.println( "OK." );
440             succeeded++;
441         }
442         else {
443             System.out.println( "failed." );
444             failed++;
445         }
446         System.out.print( "Nexus tree parsing (translating): " );
447         if ( Test.testNexusTreeParsingTranslating() ) {
448             System.out.println( "OK." );
449             succeeded++;
450         }
451         else {
452             System.out.println( "failed." );
453             failed++;
454         }
455         System.out.print( "Nexus matrix parsing: " );
456         if ( Test.testNexusMatrixParsing() ) {
457             System.out.println( "OK." );
458             succeeded++;
459         }
460         else {
461             System.out.println( "failed." );
462             failed++;
463         }
464         System.out.print( "Basic phyloXML parsing: " );
465         if ( Test.testBasicPhyloXMLparsing() ) {
466             System.out.println( "OK." );
467             succeeded++;
468         }
469         else {
470             System.out.println( "failed." );
471             failed++;
472         }
473         System.out.print( "Basic phyloXML parsing (validating against schema): " );
474         if ( testBasicPhyloXMLparsingValidating() ) {
475             System.out.println( "OK." );
476             succeeded++;
477         }
478         else {
479             System.out.println( "failed." );
480             failed++;
481         }
482         System.out.print( "phyloXML parsing (validating against schema): " );
483         if ( testPhyloXMLparsingValidating() ) {
484             System.out.println( "OK." );
485             succeeded++;
486         }
487         else {
488             System.out.println( "failed." );
489             failed++;
490         }
491         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
492         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
493             System.out.println( "OK." );
494             succeeded++;
495         }
496         else {
497             System.out.println( "failed." );
498             failed++;
499         }
500         System.out.print( "phyloXML Distribution Element: " );
501         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
502             System.out.println( "OK." );
503             succeeded++;
504         }
505         else {
506             System.out.println( "failed." );
507             failed++;
508         }
509         System.out.print( "Tol XML parsing: " );
510         if ( Test.testBasicTolXMLparsing() ) {
511             System.out.println( "OK." );
512             succeeded++;
513         }
514         else {
515             System.out.println( "failed." );
516             failed++;
517         }
518         System.out.print( "UTF-8 parsing from file: " );
519         if ( Test.testUTF8ParsingFromFile() ) {
520             System.out.println( "OK." );
521             succeeded++;
522         }
523         else {
524             System.out.println( "failed." );
525             failed++;
526         }
527         System.out.print( "Copying of node data: " );
528         if ( Test.testCopyOfNodeData() ) {
529             System.out.println( "OK." );
530             succeeded++;
531         }
532         else {
533             System.out.println( "failed." );
534             failed++;
535         }
536         System.out.print( "Tree copy: " );
537         if ( Test.testTreeCopy() ) {
538             System.out.println( "OK." );
539             succeeded++;
540         }
541         else {
542             System.out.println( "failed." );
543             failed++;
544         }
545         System.out.print( "Basic tree methods: " );
546         if ( Test.testBasicTreeMethods() ) {
547             System.out.println( "OK." );
548             succeeded++;
549         }
550         else {
551             System.out.println( "failed." );
552             failed++;
553         }
554         System.out.print( "Tree methods: " );
555         if ( Test.testTreeMethods() ) {
556             System.out.println( "OK." );
557             succeeded++;
558         }
559         else {
560             System.out.println( "failed." );
561             failed++;
562         }
563         System.out.print( "Postorder Iterator: " );
564         if ( Test.testPostOrderIterator() ) {
565             System.out.println( "OK." );
566             succeeded++;
567         }
568         else {
569             System.out.println( "failed." );
570             failed++;
571         }
572         System.out.print( "Preorder Iterator: " );
573         if ( Test.testPreOrderIterator() ) {
574             System.out.println( "OK." );
575             succeeded++;
576         }
577         else {
578             System.out.println( "failed." );
579             failed++;
580         }
581         System.out.print( "Levelorder Iterator: " );
582         if ( Test.testLevelOrderIterator() ) {
583             System.out.println( "OK." );
584             succeeded++;
585         }
586         else {
587             System.out.println( "failed." );
588             failed++;
589         }
590         System.out.print( "Re-id methods: " );
591         if ( Test.testReIdMethods() ) {
592             System.out.println( "OK." );
593             succeeded++;
594         }
595         else {
596             System.out.println( "failed." );
597             failed++;
598         }
599         System.out.print( "Methods on last external nodes: " );
600         if ( Test.testLastExternalNodeMethods() ) {
601             System.out.println( "OK." );
602             succeeded++;
603         }
604         else {
605             System.out.println( "failed." );
606             failed++;
607         }
608         System.out.print( "Methods on external nodes: " );
609         if ( Test.testExternalNodeRelatedMethods() ) {
610             System.out.println( "OK." );
611             succeeded++;
612         }
613         else {
614             System.out.println( "failed." );
615             failed++;
616         }
617         System.out.print( "Deletion of external nodes: " );
618         if ( Test.testDeletionOfExternalNodes() ) {
619             System.out.println( "OK." );
620             succeeded++;
621         }
622         else {
623             System.out.println( "failed." );
624             failed++;
625         }
626         System.out.print( "Subtree deletion: " );
627         if ( Test.testSubtreeDeletion() ) {
628             System.out.println( "OK." );
629             succeeded++;
630         }
631         else {
632             System.out.println( "failed." );
633             failed++;
634         }
635         System.out.print( "Phylogeny branch: " );
636         if ( Test.testPhylogenyBranch() ) {
637             System.out.println( "OK." );
638             succeeded++;
639         }
640         else {
641             System.out.println( "failed." );
642             failed++;
643         }
644         System.out.print( "Rerooting: " );
645         if ( Test.testRerooting() ) {
646             System.out.println( "OK." );
647             succeeded++;
648         }
649         else {
650             System.out.println( "failed." );
651             failed++;
652         }
653         System.out.print( "Mipoint rooting: " );
654         if ( Test.testMidpointrooting() ) {
655             System.out.println( "OK." );
656             succeeded++;
657         }
658         else {
659             System.out.println( "failed." );
660             failed++;
661         }
662         System.out.print( "Node removal: " );
663         if ( Test.testNodeRemoval() ) {
664             System.out.println( "OK." );
665             succeeded++;
666         }
667         else {
668             System.out.println( "failed." );
669             failed++;
670         }
671         System.out.print( "Support count: " );
672         if ( Test.testSupportCount() ) {
673             System.out.println( "OK." );
674             succeeded++;
675         }
676         else {
677             System.out.println( "failed." );
678             failed++;
679         }
680         System.out.print( "Support transfer: " );
681         if ( Test.testSupportTransfer() ) {
682             System.out.println( "OK." );
683             succeeded++;
684         }
685         else {
686             System.out.println( "failed." );
687             failed++;
688         }
689         System.out.print( "Finding of LCA: " );
690         if ( Test.testGetLCA() ) {
691             System.out.println( "OK." );
692             succeeded++;
693         }
694         else {
695             System.out.println( "failed." );
696             failed++;
697         }
698         System.out.print( "Finding of LCA 2: " );
699         if ( Test.testGetLCA2() ) {
700             System.out.println( "OK." );
701             succeeded++;
702         }
703         else {
704             System.out.println( "failed." );
705             failed++;
706         }
707         System.out.print( "Calculation of distance between nodes: " );
708         if ( Test.testGetDistance() ) {
709             System.out.println( "OK." );
710             succeeded++;
711         }
712         else {
713             System.out.println( "failed." );
714             failed++;
715         }
716         System.out.print( "Descriptive statistics: " );
717         if ( Test.testDescriptiveStatistics() ) {
718             System.out.println( "OK." );
719             succeeded++;
720         }
721         else {
722             System.out.println( "failed." );
723             failed++;
724         }
725         System.out.print( "Data objects and methods: " );
726         if ( Test.testDataObjects() ) {
727             System.out.println( "OK." );
728             succeeded++;
729         }
730         else {
731             System.out.println( "failed." );
732             failed++;
733         }
734         System.out.print( "Properties map: " );
735         if ( Test.testPropertiesMap() ) {
736             System.out.println( "OK." );
737             succeeded++;
738         }
739         else {
740             System.out.println( "failed." );
741             failed++;
742         }
743         System.out.print( "SDIse: " );
744         if ( Test.testSDIse() ) {
745             System.out.println( "OK." );
746             succeeded++;
747         }
748         else {
749             System.out.println( "failed." );
750             failed++;
751         }
752         System.out.print( "SDIunrooted: " );
753         if ( Test.testSDIunrooted() ) {
754             System.out.println( "OK." );
755             succeeded++;
756         }
757         else {
758             System.out.println( "failed." );
759             failed++;
760         }
761         System.out.print( "GSDI: " );
762         if ( TestGSDI.test() ) {
763             System.out.println( "OK." );
764             succeeded++;
765         }
766         else {
767             System.out.println( "failed." );
768             failed++;
769         }
770         System.out.print( "RIO: " );
771         if ( TestRIO.test() ) {
772             System.out.println( "OK." );
773             succeeded++;
774         }
775         else {
776             System.out.println( "failed." );
777             failed++;
778         }
779         System.out.print( "Phylogeny reconstruction:" );
780         System.out.println();
781         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
782             System.out.println( "OK." );
783             succeeded++;
784         }
785         else {
786             System.out.println( "failed." );
787             failed++;
788         }
789         System.out.print( "Analysis of domain architectures: " );
790         System.out.println();
791         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
792             System.out.println( "OK." );
793             succeeded++;
794         }
795         else {
796             System.out.println( "failed." );
797             failed++;
798         }
799         System.out.print( "GO: " );
800         System.out.println();
801         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
802             System.out.println( "OK." );
803             succeeded++;
804         }
805         else {
806             System.out.println( "failed." );
807             failed++;
808         }
809         System.out.print( "Modeling tools: " );
810         if ( TestPccx.test() ) {
811             System.out.println( "OK." );
812             succeeded++;
813         }
814         else {
815             System.out.println( "failed." );
816             failed++;
817         }
818         System.out.print( "Split Matrix strict: " );
819         if ( Test.testSplitStrict() ) {
820             System.out.println( "OK." );
821             succeeded++;
822         }
823         else {
824             System.out.println( "failed." );
825             failed++;
826         }
827         System.out.print( "Split Matrix: " );
828         if ( Test.testSplit() ) {
829             System.out.println( "OK." );
830             succeeded++;
831         }
832         else {
833             System.out.println( "failed." );
834             failed++;
835         }
836         System.out.print( "Confidence Assessor: " );
837         if ( Test.testConfidenceAssessor() ) {
838             System.out.println( "OK." );
839             succeeded++;
840         }
841         else {
842             System.out.println( "failed." );
843             failed++;
844         }
845         System.out.print( "Basic table: " );
846         if ( Test.testBasicTable() ) {
847             System.out.println( "OK." );
848             succeeded++;
849         }
850         else {
851             System.out.println( "failed." );
852             failed++;
853         }
854         System.out.print( "General table: " );
855         if ( Test.testGeneralTable() ) {
856             System.out.println( "OK." );
857             succeeded++;
858         }
859         else {
860             System.out.println( "failed." );
861             failed++;
862         }
863         System.out.print( "Amino acid sequence: " );
864         if ( Test.testAminoAcidSequence() ) {
865             System.out.println( "OK." );
866             succeeded++;
867         }
868         else {
869             System.out.println( "failed." );
870             failed++;
871         }
872         System.out.print( "General MSA parser: " );
873         if ( Test.testGeneralMsaParser() ) {
874             System.out.println( "OK." );
875             succeeded++;
876         }
877         else {
878             System.out.println( "failed." );
879             failed++;
880         }
881         System.out.print( "Fasta parser for msa: " );
882         if ( Test.testFastaParser() ) {
883             System.out.println( "OK." );
884             succeeded++;
885         }
886         else {
887             System.out.println( "failed." );
888             failed++;
889         }
890         System.out.print( "Creation of balanced phylogeny: " );
891         if ( Test.testCreateBalancedPhylogeny() ) {
892             System.out.println( "OK." );
893             succeeded++;
894         }
895         else {
896             System.out.println( "failed." );
897             failed++;
898         }
899         System.out.print( "Genbank accessor parsing: " );
900         if ( Test.testGenbankAccessorParsing() ) {
901             System.out.println( "OK." );
902             succeeded++;
903         }
904         else {
905             System.out.println( "failed." );
906             failed++;
907         }
908         String path = "";
909         final String os = ForesterUtil.OS_NAME.toLowerCase();
910         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
911             path = "/usr/local/bin/mafft";
912         }
913         else if ( os.indexOf( "win" ) >= 0 ) {
914             path = "C:\\Program Files\\mafft-win\\mafft.bat";
915         }
916         else {
917             path = "mafft";
918             if ( !MsaInferrer.isInstalled( path ) ) {
919                 path = "/usr/bin/mafft";
920             }
921             if ( !MsaInferrer.isInstalled( path ) ) {
922                 path = "/usr/local/bin/mafft";
923             }
924         }
925         if ( MsaInferrer.isInstalled( path ) ) {
926             System.out.print( "MAFFT (external program): " );
927             if ( Test.testMafft( path ) ) {
928                 System.out.println( "OK." );
929                 succeeded++;
930             }
931             else {
932                 System.out.println( "failed [will not count towards failed tests]" );
933             }
934         }
935         System.out.print( "Next nodes with collapsed: " );
936         if ( Test.testNextNodeWithCollapsing() ) {
937             System.out.println( "OK." );
938             succeeded++;
939         }
940         else {
941             System.out.println( "failed." );
942             failed++;
943         }
944         System.out.print( "Simple MSA quality: " );
945         if ( Test.testMsaQualityMethod() ) {
946             System.out.println( "OK." );
947             succeeded++;
948         }
949         else {
950             System.out.println( "failed." );
951             failed++;
952         }
953         System.out.print( "Deleteable MSA: " );
954         if ( Test.testDeleteableMsa() ) {
955             System.out.println( "OK." );
956             succeeded++;
957         }
958         else {
959             System.out.println( "failed." );
960             failed++;
961         }
962         System.out.print( "MSA entropy: " );
963         if ( Test.testMsaEntropy() ) {
964             System.out.println( "OK." );
965             succeeded++;
966         }
967         else {
968             System.out.println( "failed." );
969             failed++;
970         }
971         if ( PERFORM_DB_TESTS ) {
972             System.out.print( "Uniprot Entry Retrieval: " );
973             if ( Test.testUniprotEntryRetrieval() ) {
974                 System.out.println( "OK." );
975                 succeeded++;
976             }
977             else {
978                 System.out.println( "failed." );
979                 failed++;
980             }
981             System.out.print( "Ebi Entry Retrieval: " );
982             if ( Test.testEbiEntryRetrieval() ) {
983                 System.out.println( "OK." );
984                 succeeded++;
985             }
986             else {
987                 System.out.println( "failed." );
988                 failed++;
989             }
990             System.out.print( "Sequence DB tools 2: " );
991             if ( testSequenceDbWsTools2() ) {
992                 System.out.println( "OK." );
993                 succeeded++;
994             }
995             else {
996                 System.out.println( "failed." );
997                 failed++;
998                 System.exit( -1 );
999             }
1000             System.out.print( "Uniprot Taxonomy Search: " );
1001             if ( Test.testUniprotTaxonomySearch() ) {
1002                 System.out.println( "OK." );
1003                 succeeded++;
1004             }
1005             else {
1006                 System.out.println( "failed." );
1007                 failed++;
1008             }
1009         }
1010         if ( PERFORM_WEB_TREE_ACCESS ) {
1011             System.out.print( "TreeBase acccess: " );
1012             if ( Test.testTreeBaseReading() ) {
1013                 System.out.println( "OK." );
1014                 succeeded++;
1015             }
1016             else {
1017                 System.out.println( "failed." );
1018                 failed++;
1019             }
1020             System.out.print( "ToL access: " );
1021             if ( Test.testToLReading() ) {
1022                 System.out.println( "OK." );
1023                 succeeded++;
1024             }
1025             else {
1026                 System.out.println( "failed." );
1027                 failed++;
1028             }
1029             System.out.print( "NHX parsing from URL: " );
1030             if ( Test.testNHXparsingFromURL() ) {
1031                 System.out.println( "OK." );
1032                 succeeded++;
1033             }
1034             else {
1035                 System.out.println( "failed." );
1036                 failed++;
1037             }
1038             System.out.print( "NHX parsing from URL 2: " );
1039             if ( Test.testNHXparsingFromURL2() ) {
1040                 System.out.println( "OK." );
1041                 succeeded++;
1042             }
1043             else {
1044                 System.out.println( "failed." );
1045                 failed++;
1046             }
1047             System.out.print( "phyloXML parsing from URL: " );
1048             if ( Test.testPhyloXMLparsingFromURL() ) {
1049                 System.out.println( "OK." );
1050                 succeeded++;
1051             }
1052             else {
1053                 System.out.println( "failed." );
1054                 failed++;
1055             }
1056             System.out.print( "TreeFam access: " );
1057             if ( Test.testTreeFamReading() ) {
1058                 System.out.println( "OK." );
1059                 succeeded++;
1060             }
1061             else {
1062                 System.out.println( "failed." );
1063                 failed++;
1064             }
1065             System.out.print( "Pfam tree access: " );
1066             if ( Test.testPfamTreeReading() ) {
1067                 System.out.println( "OK." );
1068                 succeeded++;
1069             }
1070             else {
1071                 System.out.println( "failed." );
1072                 failed++;
1073             }
1074         }
1075         System.out.println();
1076         final Runtime rt = java.lang.Runtime.getRuntime();
1077         final long free_memory = rt.freeMemory() / 1000000;
1078         final long total_memory = rt.totalMemory() / 1000000;
1079         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1080                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1081         System.out.println();
1082         System.out.println( "Successful tests: " + succeeded );
1083         System.out.println( "Failed     tests: " + failed );
1084         System.out.println();
1085         if ( failed < 1 ) {
1086             System.out.println( "OK." );
1087         }
1088         else {
1089             System.out.println( "Not OK." );
1090         }
1091     }
1092
1093     private static boolean testEngulfingOverlapRemoval() {
1094         try {
1095             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1096             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1097             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1098             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1099             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1100             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1101             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1102             final List<Boolean> covered = new ArrayList<Boolean>();
1103             covered.add( true ); // 0
1104             covered.add( false ); // 1
1105             covered.add( true ); // 2
1106             covered.add( false ); // 3
1107             covered.add( true ); // 4
1108             covered.add( true ); // 5
1109             covered.add( false ); // 6
1110             covered.add( true ); // 7
1111             covered.add( true ); // 8
1112             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1113                 return false;
1114             }
1115             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1116                 return false;
1117             }
1118             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1119                 return false;
1120             }
1121             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1122                 return false;
1123             }
1124             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1125                 return false;
1126             }
1127             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1128                 return false;
1129             }
1130             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1131                 return false;
1132             }
1133             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1134             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1135             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1136             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1137             abc.addProteinDomain( a );
1138             abc.addProteinDomain( b );
1139             abc.addProteinDomain( c );
1140             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1141             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1142             if ( abc.getNumberOfProteinDomains() != 3 ) {
1143                 return false;
1144             }
1145             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1146                 return false;
1147             }
1148             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1149                 return false;
1150             }
1151             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1152                 return false;
1153             }
1154             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1155                 return false;
1156             }
1157             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1158             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1159             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1160             final Protein def = new BasicProtein( "def", "nemve", 0 );
1161             def.addProteinDomain( d );
1162             def.addProteinDomain( e );
1163             def.addProteinDomain( f );
1164             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1165             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1166             if ( def.getNumberOfProteinDomains() != 3 ) {
1167                 return false;
1168             }
1169             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1170                 return false;
1171             }
1172             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1173                 return false;
1174             }
1175             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1176                 return false;
1177             }
1178             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1179                 return false;
1180             }
1181             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1182                 return false;
1183             }
1184         }
1185         catch ( final Exception e ) {
1186             e.printStackTrace( System.out );
1187             return false;
1188         }
1189         return true;
1190     }
1191
1192     private static final boolean testNHXparsingFromURL2() {
1193         try {
1194             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1195             final Phylogeny phys[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1196                                                                       false,
1197                                                                       false,
1198                                                                       false,
1199                                                                       TAXONOMY_EXTRACTION.NO,
1200                                                                       false );
1201             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1202                 return false;
1203             }
1204             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1205                 System.out.println( phys[ 0 ].toNewHampshire() );
1206                 return false;
1207             }
1208             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1209                 System.out.println( phys[ 1 ].toNewHampshire() );
1210                 return false;
1211             }
1212             final Phylogeny phys2[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1213                                                                        false,
1214                                                                        false,
1215                                                                        false,
1216                                                                        TAXONOMY_EXTRACTION.NO,
1217                                                                        false );
1218             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1219                 return false;
1220             }
1221             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1222                 System.out.println( phys2[ 0 ].toNewHampshire() );
1223                 return false;
1224             }
1225             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1226                 System.out.println( phys2[ 1 ].toNewHampshire() );
1227                 return false;
1228             }
1229             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1230                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1231             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1232                 return false;
1233             }
1234             if ( !phys3[ 0 ]
1235                     .toNewHampshire()
1236                     .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))))));" ) ) {
1237                 System.out.println( phys3[ 0 ].toNewHampshire() );
1238                 return false;
1239             }
1240             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1241                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1242             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1243                 return false;
1244             }
1245             if ( !phys4[ 0 ]
1246                     .toNewHampshire()
1247                     .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))))));" ) ) {
1248                 System.out.println( phys4[ 0 ].toNewHampshire() );
1249                 return false;
1250             }
1251         }
1252         catch ( final Exception e ) {
1253             e.printStackTrace();
1254             return false;
1255         }
1256         return true;
1257     }
1258
1259     private static final boolean testNHXparsingFromURL() {
1260         try {
1261             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1262             final URL u = new URL( s );
1263             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1264             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1265             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1266                 return false;
1267             }
1268             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1269                 System.out.println( phys[ 0 ].toNewHampshire() );
1270                 return false;
1271             }
1272             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1273                 System.out.println( phys[ 1 ].toNewHampshire() );
1274                 return false;
1275             }
1276             final URL u2 = new URL( s );
1277             final Phylogeny[] phys2 = factory.create( u2.openStream(), new NHXParser() );
1278             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1279                 return false;
1280             }
1281             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1282                 System.out.println( phys2[ 0 ].toNewHampshire() );
1283                 return false;
1284             }
1285             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1286             final NHXParser p = new NHXParser();
1287             final URL u3 = new URL( s );
1288             p.setSource( u3 );
1289             if ( !p.hasNext() ) {
1290                 return false;
1291             }
1292             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1293                 return false;
1294             }
1295             if ( !p.hasNext() ) {
1296                 return false;
1297             }
1298             p.reset();
1299             if ( !p.hasNext() ) {
1300                 return false;
1301             }
1302             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1303                 return false;
1304             }
1305             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1306                 return false;
1307             }
1308             p.reset();
1309             if ( !p.hasNext() ) {
1310                 return false;
1311             }
1312             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1313                 return false;
1314             }
1315             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1316                 return false;
1317             }
1318         }
1319         catch ( final Exception e ) {
1320             System.out.println( e.toString() );
1321             e.printStackTrace();
1322             return false;
1323         }
1324         return true;
1325     }
1326
1327     private static boolean testOverlapRemoval() {
1328         try {
1329             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1330             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1331             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1332             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1333             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1334             final List<Boolean> covered = new ArrayList<Boolean>();
1335             covered.add( true ); // 0
1336             covered.add( false ); // 1
1337             covered.add( true ); // 2
1338             covered.add( false ); // 3
1339             covered.add( true ); // 4
1340             covered.add( true ); // 5
1341             covered.add( false ); // 6
1342             covered.add( true ); // 7
1343             covered.add( true ); // 8
1344             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1345                 return false;
1346             }
1347             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1348                 return false;
1349             }
1350             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1351                 return false;
1352             }
1353             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1354                 return false;
1355             }
1356             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1357                 return false;
1358             }
1359             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1360             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1361             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1362             ab.addProteinDomain( a );
1363             ab.addProteinDomain( b );
1364             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1365             if ( ab.getNumberOfProteinDomains() != 2 ) {
1366                 return false;
1367             }
1368             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1369                 return false;
1370             }
1371             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1372                 return false;
1373             }
1374             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1375             if ( ab.getNumberOfProteinDomains() != 2 ) {
1376                 return false;
1377             }
1378             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1379                 return false;
1380             }
1381             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1382             final Domain d = new BasicDomain( "d",
1383                                               ( short ) 10000,
1384                                               ( short ) 10500,
1385                                               ( short ) 1,
1386                                               ( short ) 1,
1387                                               0.0000001,
1388                                               1 );
1389             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1390             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1391             cde.addProteinDomain( c );
1392             cde.addProteinDomain( d );
1393             cde.addProteinDomain( e );
1394             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1395             if ( cde.getNumberOfProteinDomains() != 3 ) {
1396                 return false;
1397             }
1398             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1399                 return false;
1400             }
1401             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1402             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1403             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1404             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1405             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1406             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1407             fghi.addProteinDomain( f );
1408             fghi.addProteinDomain( g );
1409             fghi.addProteinDomain( h );
1410             fghi.addProteinDomain( i );
1411             fghi.addProteinDomain( i );
1412             fghi.addProteinDomain( i );
1413             fghi.addProteinDomain( i2 );
1414             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1415             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1416                 return false;
1417             }
1418             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1419                 return false;
1420             }
1421             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1422                 return false;
1423             }
1424             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1425             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1426                 return false;
1427             }
1428             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1429                 return false;
1430             }
1431             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1432             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1433             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1434             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1435             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1436             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1437             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1438             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1439             jklm.addProteinDomain( j );
1440             jklm.addProteinDomain( k );
1441             jklm.addProteinDomain( l );
1442             jklm.addProteinDomain( m );
1443             jklm.addProteinDomain( m0 );
1444             jklm.addProteinDomain( m1 );
1445             jklm.addProteinDomain( m2 );
1446             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1447             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1448                 return false;
1449             }
1450             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1451                 return false;
1452             }
1453             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1454                 return false;
1455             }
1456             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1457             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1458                 return false;
1459             }
1460             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1461                 return false;
1462             }
1463             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1464             final Protein od = new BasicProtein( "od", "varanus", 0 );
1465             od.addProteinDomain( only );
1466             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1467             if ( od.getNumberOfProteinDomains() != 1 ) {
1468                 return false;
1469             }
1470             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1471                 return false;
1472             }
1473         }
1474         catch ( final Exception e ) {
1475             e.printStackTrace( System.out );
1476             return false;
1477         }
1478         return true;
1479     }
1480
1481     private static final boolean testPfamTreeReading() {
1482         try {
1483             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1484             final NHXParser parser = new NHXParser();
1485             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1486             parser.setReplaceUnderscores( false );
1487             parser.setGuessRootedness( true );
1488             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser);
1489             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1490                 return false;
1491             }
1492             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1493                 return false;
1494             }
1495         }
1496         catch ( final Exception e ) {
1497             e.printStackTrace();
1498             return false;
1499         }
1500         return true;
1501     }
1502
1503     private static final boolean testPhyloXMLparsingFromURL() {
1504         try {
1505             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1506             final URL u = new URL( s );
1507             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1508             
1509             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1510                 return false;
1511             }
1512             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1513             
1514             if ( ( phys2 == null ) || ( phys2.length != 2 ) ) {
1515                 return false;
1516             }
1517         }
1518         catch ( final Exception e ) {
1519             e.printStackTrace();
1520             return false;
1521         }
1522         return true;
1523     }
1524
1525     private static final boolean testToLReading() {
1526         try {
1527             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1528             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, new TolParser() );
1529             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1530                 return false;
1531             }
1532             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1533                 return false;
1534             }
1535             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1536                 return false;
1537             }
1538             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1539                 return false;
1540             }
1541             //
1542             final URL u2 = new URL( WebserviceUtil.TOL_URL_BASE + "17706" );
1543             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, new TolParser() );
1544             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
1545                 return false;
1546             }
1547             if ( !phys2[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "17706" ) ) {
1548                 return false;
1549             }
1550             if ( phys2[ 0 ].getNumberOfExternalNodes() < 5 ) {
1551                 return false;
1552             }
1553         }
1554         catch ( final Exception e ) {
1555             e.printStackTrace();
1556             return false;
1557         }
1558         return true;
1559     }
1560
1561     private static final boolean testTreeBaseReading() {
1562         try {
1563             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "72557?format=nexus" );  
1564             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1565             parser.setReplaceUnderscores( true );
1566             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1567             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1568                 return false;
1569             }
1570             final URL u_1 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2406?format=nexus" );  
1571             final NexusPhylogeniesParser parser_1 = new NexusPhylogeniesParser();
1572             final Phylogeny[] phys_1 = ForesterUtil.readPhylogeniesFromUrl( u_1, parser_1 );
1573             if ( ( phys_1 == null ) || ( phys_1.length != 1 ) ) {
1574                 return false;
1575             }
1576             final URL u_2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "422?format=nexus" );  
1577             final NexusPhylogeniesParser parser_2 = new NexusPhylogeniesParser();
1578             final Phylogeny[] phys_2 = ForesterUtil.readPhylogeniesFromUrl( u_2, parser_2 );
1579             if ( ( phys_2 == null ) || ( phys_2.length != 1 ) ) {
1580                 return false;
1581             }
1582             final URL u_3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2654?format=nexus" );  
1583             final NexusPhylogeniesParser parser_3 = new NexusPhylogeniesParser();
1584             final Phylogeny[] phys_3 = ForesterUtil.readPhylogeniesFromUrl( u_3, parser_3 );
1585              if ( ( phys_3 == null ) || ( phys_3.length != 1 ) ) {
1586                 return false;
1587             }
1588             final URL u_4 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );  
1589             final NexusPhylogeniesParser parser_4 = new NexusPhylogeniesParser();
1590             final Phylogeny[] phys_4 = ForesterUtil.readPhylogeniesFromUrl( u_4, parser_4 );
1591              if ( ( phys_4 == null ) || ( phys_4.length != 1 ) ) {
1592                 return false;
1593             }
1594             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1595             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1596             parser2.setReplaceUnderscores( true );
1597             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, parser2 );
1598             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1599                 return false;
1600             }
1601             final URL u3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14909?format=nexus" );
1602             final NexusPhylogeniesParser parser3 = new NexusPhylogeniesParser();
1603             final Phylogeny[] phys3 = ForesterUtil.readPhylogeniesFromUrl( u3, parser3 );
1604             if ( ( phys3 == null ) || ( phys3.length != 2 ) ) {
1605                 return false;
1606             }
1607             final Phylogeny[] phys4 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14525?format=nexus" ),
1608                     new NexusPhylogeniesParser() );
1609             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1610                 return false;
1611             }
1612             final Phylogeny[] phys5 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15632?format=nexus" ) ,
1613                     new NexusPhylogeniesParser() );
1614             if ( ( phys5 == null ) || ( phys5.length != 1 ) ) {
1615                 return false;
1616             }
1617             final Phylogeny[] phys6 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "10190?format=nexus" ) ,
1618                     new NexusPhylogeniesParser() );
1619             if ( ( phys6 == null ) || ( phys6.length != 1 ) ) {
1620                 return false;
1621             }
1622             final Phylogeny[] phys7 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "13246?format=nexus" ) ,
1623                     new NexusPhylogeniesParser() );
1624             if ( ( phys7 == null ) || ( phys7.length != 2 ) ) {
1625                 return false;
1626             }
1627             final Phylogeny[] phys8 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "11662?format=nexus" ) ,
1628                     new NexusPhylogeniesParser() );
1629             if ( ( phys8 == null ) || ( phys8.length != 2 ) ) {
1630                 return false;
1631             }
1632             final Phylogeny[] phys9 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "562?format=nexus" ) ,
1633                     new NexusPhylogeniesParser() );
1634             if ( ( phys9 == null ) || ( phys9.length != 4 ) ) {
1635                 return false;
1636             }
1637             final Phylogeny[] phys16424 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "16424?format=nexus" ) ,
1638                     new NexusPhylogeniesParser() );
1639             if ( ( phys16424 == null ) || ( phys16424.length != 1 ) ) {
1640                 return false;
1641             }
1642             final Phylogeny[] phys17878 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "17878?format=nexus" ) ,
1643                     new NexusPhylogeniesParser() );
1644             if ( ( phys17878 == null ) || ( phys17878.length != 17 ) ) {
1645                 return false;
1646             }
1647             final Phylogeny[] phys18804 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "18804?format=nexus" ) ,
1648                     new NexusPhylogeniesParser() );
1649             if ( ( phys18804 == null ) || ( phys18804.length != 2 ) ) {
1650                 return false;
1651             }
1652             final Phylogeny[] phys346 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "346?format=nexus" ) ,
1653                     new NexusPhylogeniesParser() );
1654             if ( ( phys346 == null ) || ( phys346.length != 1 ) ) {
1655                 return false;
1656             }
1657         }
1658         catch ( final Exception e ) {
1659             e.printStackTrace();
1660             return false;
1661         }
1662         return true;
1663     }
1664
1665     private static final boolean testTreeFamReading() {
1666         try {
1667             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1668             final NHXParser parser = new NHXParser();
1669             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1670             parser.setReplaceUnderscores( false );
1671             parser.setGuessRootedness( true );
1672             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1673             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1674                 return false;
1675             }
1676             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1677                 return false;
1678             }
1679         }
1680         catch ( final Exception e ) {
1681             e.printStackTrace();
1682             return false;
1683         }
1684         return true;
1685     }
1686
1687     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1688         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1689         return p;
1690     }
1691
1692     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1693         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1694     }
1695
1696     private static boolean testAminoAcidSequence() {
1697         try {
1698             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1699             if ( aa1.getLength() != 13 ) {
1700                 return false;
1701             }
1702             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1703                 return false;
1704             }
1705             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1706                 return false;
1707             }
1708             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1709                 return false;
1710             }
1711             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1712             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1713                 return false;
1714             }
1715             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1716             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1717                 return false;
1718             }
1719             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1720             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1721                 return false;
1722             }
1723         }
1724         catch ( final Exception e ) {
1725             e.printStackTrace();
1726             return false;
1727         }
1728         return true;
1729     }
1730
1731     private static boolean testBasicDomain() {
1732         try {
1733             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1734             if ( !pd.getDomainId().equals( "id" ) ) {
1735                 return false;
1736             }
1737             if ( pd.getNumber() != 1 ) {
1738                 return false;
1739             }
1740             if ( pd.getTotalCount() != 4 ) {
1741                 return false;
1742             }
1743             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1744                 return false;
1745             }
1746             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1747             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1748             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1749             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1750             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1751             if ( !a1.equals( a1 ) ) {
1752                 return false;
1753             }
1754             if ( !a1.equals( a1_copy ) ) {
1755                 return false;
1756             }
1757             if ( !a1.equals( a1_equal ) ) {
1758                 return false;
1759             }
1760             if ( !a1.equals( a2 ) ) {
1761                 return false;
1762             }
1763             if ( a1.equals( a3 ) ) {
1764                 return false;
1765             }
1766             if ( a1.compareTo( a1 ) != 0 ) {
1767                 return false;
1768             }
1769             if ( a1.compareTo( a1_copy ) != 0 ) {
1770                 return false;
1771             }
1772             if ( a1.compareTo( a1_equal ) != 0 ) {
1773                 return false;
1774             }
1775             if ( a1.compareTo( a2 ) != 0 ) {
1776                 return false;
1777             }
1778             if ( a1.compareTo( a3 ) == 0 ) {
1779                 return false;
1780             }
1781         }
1782         catch ( final Exception e ) {
1783             e.printStackTrace( System.out );
1784             return false;
1785         }
1786         return true;
1787     }
1788
1789     private static boolean testBasicNodeMethods() {
1790         try {
1791             if ( PhylogenyNode.getNodeCount() != 0 ) {
1792                 return false;
1793             }
1794             final PhylogenyNode n1 = new PhylogenyNode();
1795             final PhylogenyNode n2 = PhylogenyNode
1796                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1797             final PhylogenyNode n3 = PhylogenyNode
1798                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1799             final PhylogenyNode n4 = PhylogenyNode
1800                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1801             if ( n1.isHasAssignedEvent() ) {
1802                 return false;
1803             }
1804             if ( PhylogenyNode.getNodeCount() != 4 ) {
1805                 return false;
1806             }
1807             if ( n3.getIndicator() != 0 ) {
1808                 return false;
1809             }
1810             if ( n3.getNumberOfExternalNodes() != 1 ) {
1811                 return false;
1812             }
1813             if ( !n3.isExternal() ) {
1814                 return false;
1815             }
1816             if ( !n3.isRoot() ) {
1817                 return false;
1818             }
1819             if ( !n4.getName().equals( "n4" ) ) {
1820                 return false;
1821             }
1822         }
1823         catch ( final Exception e ) {
1824             e.printStackTrace( System.out );
1825             return false;
1826         }
1827         return true;
1828     }
1829     
1830     private static boolean testUTF8ParsingFromFile() {
1831         try {
1832             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1833             final Phylogeny[] phylogenies_xml = ParserBasedPhylogenyFactory.getInstance().create( new File( Test.PATH_TO_TEST_DATA + "chars.xml" ),
1834                                                               xml_parser );
1835             if ( xml_parser.getErrorCount() > 0 ) {
1836                 System.out.println( xml_parser.getErrorMessages().toString() );
1837                 return false;
1838             }
1839             if ( phylogenies_xml.length != 1 ) {
1840                 return false;
1841             }
1842          
1843             final Phylogeny[] phylogenies_xml2 = ParserBasedPhylogenyFactory.getInstance().create( new StringBuffer( phylogenies_xml[0].toPhyloXML( 0 )),
1844                                                                                                    xml_parser );
1845             
1846             final Phylogeny[] phylogenies_nh = ParserBasedPhylogenyFactory.getInstance().create( new File( Test.PATH_TO_TEST_DATA + "chars.nh" ), new NHXParser() );
1847             if ( phylogenies_nh.length != 1 ) {
1848                 return false;
1849             }
1850            
1851             final Phylogeny[] phylogenies_nex = ParserBasedPhylogenyFactory.getInstance().create( new File( Test.PATH_TO_TEST_DATA + "chars.nex" ), new NexusPhylogeniesParser() );
1852             if ( phylogenies_nex.length != 1 ) {
1853                 return false;
1854             }
1855           
1856             final String[] xml_n = phylogenies_xml[0].getAllExternalNodeNames();
1857             final String[] xml_n2 = phylogenies_xml2[0].getAllExternalNodeNames();
1858             final String[] nh_n = phylogenies_nh[0].getAllExternalNodeNames();
1859             final String[] nex_n = phylogenies_nex[0].getAllExternalNodeNames();
1860             final String n0 = "AQ~!@#$%^&*()_+-=\\{}|;:\"<>?,./";
1861             final String n1 = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ";
1862             final String n2 = "漢字ひらがなカタカナ";
1863             final String n3 = "อักษรไทย";
1864             final String n4 = "繁體字";
1865             final String n5 = "한글";
1866             final String n6 = "देवनागरी";
1867             
1868             final String n7 = "chữ Quốc ngữ";
1869             final String n8 = "ру́сский язы́к";
1870             final String n9 = "អក្សរខ្មែរ";
1871             
1872             if ( !xml_n[0].equals( n0 ) ) {
1873                 System.out.println( xml_n[0] );
1874                 System.out.println( n0 );
1875                 return false;
1876             }
1877             if ( !xml_n2[0].equals( n0 ) ) {
1878                 System.out.println( xml_n2[0] );
1879                 System.out.println( n0 );
1880                 return false;
1881             }
1882             if ( !nh_n[0].equals( n0 ) ) {
1883                 System.out.println( nh_n[0] );
1884                 System.out.println( n0 );
1885                 return false;
1886             }
1887             if ( !nex_n[0].equals( n0 ) ) {
1888                 System.out.println( nex_n[0] );
1889                 System.out.println( n0 );
1890                 return false;
1891             }
1892             
1893             if ( !xml_n[1].equals( n1 ) ) {
1894                 System.out.println( xml_n[1] );
1895                 System.out.println( n1 );
1896                 return false;
1897             }
1898             if ( !xml_n2[1].equals( n1 ) ) {
1899                 System.out.println( xml_n2[1] );
1900                 System.out.println( n1 );
1901                 return false;
1902             }
1903             if ( !nh_n[1].equals( n1 ) ) {
1904                 System.out.println( nh_n[1] );
1905                 System.out.println( n1 );
1906                 return false;
1907             }
1908             if ( !nex_n[1].equals( n1 ) ) {
1909                 System.out.println( nex_n[1] );
1910                 System.out.println( n1 );
1911                 return false;
1912             }
1913             
1914             if ( !xml_n[2].equals( n2 ) ) {
1915                 System.out.println( xml_n[2] );
1916                 System.out.println( n2 );
1917                 return false;
1918             }
1919             if ( !xml_n2[2].equals( n2 ) ) {
1920                 System.out.println( xml_n2[2] );
1921                 System.out.println( n2 );
1922                 return false;
1923             }
1924             if ( !nh_n[2].equals( n2 ) ) {
1925                 System.out.println( nh_n[2] );
1926                 System.out.println( n2 );
1927                 return false;
1928             }
1929             if ( !nex_n[2].equals( n2 ) ) {
1930                 System.out.println( nex_n[2] );
1931                 System.out.println( n2 );
1932                 return false;
1933             }
1934             //
1935             if ( !xml_n[3].equals( n3 ) ) {
1936                 System.out.println( xml_n[3] );
1937                 System.out.println( n3 );
1938                 return false;
1939             }
1940             if ( !xml_n2[3].equals( n3 ) ) {
1941                 System.out.println( xml_n2[3] );
1942                 System.out.println( n3 );
1943                 return false;
1944             }
1945             if ( !nh_n[3].equals( n3 ) ) {
1946                 System.out.println( nh_n[3] );
1947                 System.out.println( n3 );
1948                 return false;
1949             }
1950             if ( !nex_n[3].equals( n3 ) ) {
1951                 System.out.println( nex_n[3] );
1952                 System.out.println( n3 );
1953                 return false;
1954             }
1955             //
1956             if ( !xml_n[4].equals( n4 ) ) {
1957                 System.out.println( xml_n[4] );
1958                 System.out.println( n4 );
1959                 return false;
1960             }
1961             if ( !nh_n[4].equals( n4 ) ) {
1962                 System.out.println( nh_n[4] );
1963                 System.out.println( n4 );
1964                 return false;
1965             }
1966             if ( !nex_n[4].equals( n4 ) ) {
1967                 System.out.println( nex_n[4] );
1968                 System.out.println( n4 );
1969                 return false;
1970             }
1971             //
1972             if ( !xml_n[5].equals( n5 ) ) {
1973                 System.out.println( xml_n[5] );
1974                 System.out.println( n5 );
1975                 return false;
1976             }
1977             if ( !nh_n[5].equals( n5 ) ) {
1978                 System.out.println( nh_n[5] );
1979                 System.out.println( n5 );
1980                 return false;
1981             }
1982             if ( !nex_n[5].equals( n5 ) ) {
1983                 System.out.println( nex_n[5] );
1984                 System.out.println( n5 );
1985                 return false;
1986             }
1987             //
1988             if ( !xml_n[6].equals( n6 ) ) {
1989                 System.out.println( xml_n[6] );
1990                 System.out.println( n6 );
1991                 return false;
1992             }
1993             if ( !nh_n[6].equals( n6 ) ) {
1994                 System.out.println( nh_n[6] );
1995                 System.out.println( n6 );
1996                 return false;
1997             }
1998             if ( !nex_n[6].equals( n6 ) ) {
1999                 System.out.println( nex_n[6] );
2000                 System.out.println( n6 );
2001                 return false;
2002             }
2003             //
2004             if ( !xml_n[7].equals( n7 ) ) {
2005                 System.out.println( xml_n[7] );
2006                 System.out.println( n7 );
2007                 return false;
2008             }
2009             if ( !nh_n[7].equals( n7 ) ) {
2010                 System.out.println( nh_n[7] );
2011                 System.out.println( n7 );
2012                 return false;
2013             }
2014             if ( !nex_n[7].equals( n7 ) ) {
2015                 System.out.println( nex_n[7] );
2016                 System.out.println( n7 );
2017                 return false;
2018             }
2019             if ( !xml_n[8].equals( n8 ) ) {
2020                 System.out.println( xml_n[8] );
2021                 System.out.println( n8 );
2022                 return false;
2023             }
2024             if ( !nh_n[8].equals( n8 ) ) {
2025                 System.out.println( nh_n[8] );
2026                 System.out.println( n8 );
2027                 return false;
2028             }
2029             if ( !nex_n[8].equals( n8 ) ) {
2030                 System.out.println( nex_n[8] );
2031                 System.out.println( n8 );
2032                 return false;
2033             }
2034             if ( !xml_n[9].equals( n9 ) ) {
2035                 System.out.println( xml_n[9] );
2036                 System.out.println( n9 );
2037                 return false;
2038             }
2039             if ( !xml_n2[9].equals( n9 ) ) {
2040                 System.out.println( xml_n2[9] );
2041                 System.out.println( n9 );
2042                 return false;
2043             }
2044             if ( !nh_n[9].equals( n9 ) ) {
2045                 System.out.println( nh_n[9] );
2046                 System.out.println( n9 );
2047                 return false;
2048             }
2049             if ( !nex_n[9].equals( n9 ) ) {
2050                 System.out.println( nex_n[9] );
2051                 System.out.println( n9 );
2052                 return false;
2053             }
2054             if (!phylogenies_xml[0].toNewHampshire().equals( 
2055                                                             phylogenies_nh[0].toNewHampshire() ) ) {
2056                 System.out.println( phylogenies_xml[0].toNewHampshire() );
2057                 System.out.println( phylogenies_nh[0].toNewHampshire() );
2058                 return false;
2059             }
2060             if (!phylogenies_xml[0].toNewHampshire().equals( 
2061                                                             phylogenies_nex[0].toNewHampshire() ) ) {
2062                 System.out.println( phylogenies_xml[0].toNewHampshire() );
2063                 System.out.println( phylogenies_nex[0].toNewHampshire() );
2064                 return false;
2065             }
2066         }
2067         catch ( final Exception e ) {
2068             e.printStackTrace( System.out );
2069             return false;
2070         }
2071         return true;
2072     }
2073     
2074     
2075
2076     private static boolean testBasicPhyloXMLparsing() {
2077         try {
2078             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2079             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2080             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ),
2081                                                               xml_parser );
2082             if ( xml_parser.getErrorCount() > 0 ) {
2083                 System.out.println( xml_parser.getErrorMessages().toString() );
2084                 return false;
2085             }
2086             if ( phylogenies_0.length != 4 ) {
2087                 return false;
2088             }
2089             final Phylogeny t1 = phylogenies_0[ 0 ];
2090             final Phylogeny t2 = phylogenies_0[ 1 ];
2091             final Phylogeny t3 = phylogenies_0[ 2 ];
2092             final Phylogeny t4 = phylogenies_0[ 3 ];
2093             if ( t1.getNumberOfExternalNodes() != 1 ) {
2094                 return false;
2095             }
2096             if ( !t1.isRooted() ) {
2097                 return false;
2098             }
2099             if ( t1.isRerootable() ) {
2100                 return false;
2101             }
2102             if ( !t1.getType().equals( "gene_tree" ) ) {
2103                 return false;
2104             }
2105             if ( t2.getNumberOfExternalNodes() != 2 ) {
2106                 return false;
2107             }
2108             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
2109                 return false;
2110             }
2111             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
2112                 return false;
2113             }
2114             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2115                 return false;
2116             }
2117             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2118                 return false;
2119             }
2120             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2121                 return false;
2122             }
2123             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2124                 return false;
2125             }
2126             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2127                     .startsWith( "actgtgggggt" ) ) {
2128                 return false;
2129             }
2130             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2131                     .startsWith( "ctgtgatgcat" ) ) {
2132                 return false;
2133             }
2134             if ( t3.getNumberOfExternalNodes() != 4 ) {
2135                 return false;
2136             }
2137             if ( !t1.getName().equals( "t1" ) ) {
2138                 return false;
2139             }
2140             if ( !t2.getName().equals( "t2" ) ) {
2141                 return false;
2142             }
2143             if ( !t3.getName().equals( "t3" ) ) {
2144                 return false;
2145             }
2146             if ( !t4.getName().equals( "t4" ) ) {
2147                 return false;
2148             }
2149             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
2150                 return false;
2151             }
2152             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
2153                 return false;
2154             }
2155             if ( !t3.getNode( "root node" ).isDuplication() ) {
2156                 return false;
2157             }
2158             if ( !t3.getNode( "node a" ).isDuplication() ) {
2159                 return false;
2160             }
2161             if ( t3.getNode( "node a" ).isSpeciation() ) {
2162                 return false;
2163             }
2164             if ( t3.getNode( "node bc" ).isDuplication() ) {
2165                 return false;
2166             }
2167             if ( !t3.getNode( "node bc" ).isSpeciation() ) {
2168                 return false;
2169             }
2170             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2171                 return false;
2172             }
2173             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
2174                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2175                 return false;
2176             }
2177             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2178                 return false;
2179             }
2180             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2181                 return false;
2182             }
2183             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
2184                 return false;
2185             }
2186             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2187                     .equals( "apoptosis" ) ) {
2188                 return false;
2189             }
2190             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2191                     .equals( "GO:0006915" ) ) {
2192                 return false;
2193             }
2194             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2195                     .equals( "UniProtKB" ) ) {
2196                 return false;
2197             }
2198             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2199                     .equals( "experimental" ) ) {
2200                 return false;
2201             }
2202             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2203                     .equals( "function" ) ) {
2204                 return false;
2205             }
2206             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2207                     .getValue() != 1 ) {
2208                 return false;
2209             }
2210             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2211                     .getType().equals( "ml" ) ) {
2212                 return false;
2213             }
2214             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2215                     .equals( "apoptosis" ) ) {
2216                 return false;
2217             }
2218             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2219                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2220                 return false;
2221             }
2222             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2223                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2224                 return false;
2225             }
2226             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2227                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2228                 return false;
2229             }
2230             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2231                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2232                 return false;
2233             }
2234             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2235                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2236                 return false;
2237             }
2238             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2239                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2240                 return false;
2241             }
2242             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2243                     .equals( "GO:0005829" ) ) {
2244                 return false;
2245             }
2246             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2247                     .equals( "intracellular organelle" ) ) {
2248                 return false;
2249             }
2250             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2251                 return false;
2252             }
2253             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2254                     .equals( "UniProt link" ) ) ) {
2255                 return false;
2256             }
2257             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2258                 return false;
2259             }
2260             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
2261             if ( x.size() != 4 ) {
2262                 return false;
2263             }
2264             int c = 0;
2265             for( final Accession acc : x ) {
2266                 if ( c == 0 ) {
2267                     if ( !acc.getSource().equals( "KEGG" ) ) {
2268                         return false;
2269                     }
2270                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2271                         return false;
2272                     }
2273                 }
2274                 c++;
2275             }
2276         }
2277         catch ( final Exception e ) {
2278             e.printStackTrace( System.out );
2279             return false;
2280         }
2281         return true;
2282     }
2283
2284     private static boolean testBasicPhyloXMLparsingRoundtrip() {
2285         try {
2286             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2287             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2288             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2289                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2290             }
2291             else {
2292                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2293             }
2294             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ),
2295                                                               xml_parser );
2296             if ( xml_parser.getErrorCount() > 0 ) {
2297                 System.out.println( xml_parser.getErrorMessages().toString() );
2298                 return false;
2299             }
2300             if ( phylogenies_0.length != 4 ) {
2301                 return false;
2302             }
2303             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
2304             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
2305             if ( phylogenies_t1.length != 1 ) {
2306                 return false;
2307             }
2308             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
2309             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
2310                 return false;
2311             }
2312             if ( !t1_rt.isRooted() ) {
2313                 return false;
2314             }
2315             if ( t1_rt.isRerootable() ) {
2316                 return false;
2317             }
2318             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
2319                 return false;
2320             }
2321             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
2322             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
2323             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
2324             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2325                 return false;
2326             }
2327             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2328                 return false;
2329             }
2330             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2331                 return false;
2332             }
2333             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2334                 return false;
2335             }
2336             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2337                     .startsWith( "actgtgggggt" ) ) {
2338                 return false;
2339             }
2340             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2341                     .startsWith( "ctgtgatgcat" ) ) {
2342                 return false;
2343             }
2344             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
2345             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
2346             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
2347             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
2348             if ( phylogenies_1.length != 1 ) {
2349                 return false;
2350             }
2351             final Phylogeny t3_rt = phylogenies_1[ 0 ];
2352             if ( !t3_rt.getName().equals( "t3" ) ) {
2353                 return false;
2354             }
2355             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
2356                 return false;
2357             }
2358             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
2359                 return false;
2360             }
2361             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
2362                 return false;
2363             }
2364             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2365                 return false;
2366             }
2367             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
2368                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2369                 return false;
2370             }
2371             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2372                 return false;
2373             }
2374             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2375                 return false;
2376             }
2377             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2378                     .equals( "UniProtKB" ) ) {
2379                 return false;
2380             }
2381             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2382                     .equals( "apoptosis" ) ) {
2383                 return false;
2384             }
2385             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2386                     .equals( "GO:0006915" ) ) {
2387                 return false;
2388             }
2389             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2390                     .equals( "UniProtKB" ) ) {
2391                 return false;
2392             }
2393             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2394                     .equals( "experimental" ) ) {
2395                 return false;
2396             }
2397             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2398                     .equals( "function" ) ) {
2399                 return false;
2400             }
2401             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2402                     .getValue() != 1 ) {
2403                 return false;
2404             }
2405             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2406                     .getType().equals( "ml" ) ) {
2407                 return false;
2408             }
2409             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2410                     .equals( "apoptosis" ) ) {
2411                 return false;
2412             }
2413             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2414                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2415                 return false;
2416             }
2417             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2418                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2419                 return false;
2420             }
2421             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2422                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2423                 return false;
2424             }
2425             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2426                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2427                 return false;
2428             }
2429             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2430                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2431                 return false;
2432             }
2433             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2434                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2435                 return false;
2436             }
2437             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2438                     .equals( "GO:0005829" ) ) {
2439                 return false;
2440             }
2441             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2442                     .equals( "intracellular organelle" ) ) {
2443                 return false;
2444             }
2445             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2446                 return false;
2447             }
2448             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2449                     .equals( "UniProt link" ) ) ) {
2450                 return false;
2451             }
2452             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2453                 return false;
2454             }
2455             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
2456                 return false;
2457             }
2458             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2459                     .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." ) ) ) {
2460                 System.out.println( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription() );
2461                 return false;
2462             }
2463             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2464                 return false;
2465             }
2466             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2467                 return false;
2468             }
2469             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
2470                 return false;
2471             }
2472             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2473                 return false;
2474             }
2475             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2476                     .equals( "ncbi" ) ) {
2477                 return false;
2478             }
2479             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2480                 return false;
2481             }
2482             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2483                     .getName().equals( "B" ) ) {
2484                 return false;
2485             }
2486             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2487                     .getFrom() != 21 ) {
2488                 return false;
2489             }
2490             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2491                 return false;
2492             }
2493             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2494                     .getLength() != 24 ) {
2495                 return false;
2496             }
2497             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2498                     .getConfidence() != 0 ) {
2499                 return false;
2500             }
2501             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2502                     .equals( "pfam" ) ) {
2503                 return false;
2504             }
2505             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2506                 return false;
2507             }
2508             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2509                 return false;
2510             }
2511             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2512                 return false;
2513             }
2514             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2515                 return false;
2516             }
2517             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2518             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2519                 return false;
2520             }
2521             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2522                 return false;
2523             }
2524             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2525                 return false;
2526             }
2527             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2528                 return false;
2529             }
2530             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2531                 return false;
2532             }
2533             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2534                 return false;
2535             }
2536             if ( taxbb.getSynonyms().size() != 2 ) {
2537                 return false;
2538             }
2539             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2540                 return false;
2541             }
2542             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2543                 return false;
2544             }
2545             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2546                 return false;
2547             }
2548             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2549                 return false;
2550             }
2551             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2552                 return false;
2553             }
2554             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2555                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2556                 return false;
2557             }
2558             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2559                 return false;
2560             }
2561             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2562                 return false;
2563             }
2564             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2565                 return false;
2566             }
2567             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2568                 return false;
2569             }
2570             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2571                 return false;
2572             }
2573             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2574                 return false;
2575             }
2576             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2577                 return false;
2578             }
2579             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2580                 return false;
2581             }
2582             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2583                     .equalsIgnoreCase( "435" ) ) {
2584                 return false;
2585             }
2586             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2587                 return false;
2588             }
2589             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2590                     .equalsIgnoreCase( "443.7" ) ) {
2591                 return false;
2592             }
2593             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2594                 return false;
2595             }
2596             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2597                 return false;
2598             }
2599             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2600                     .equalsIgnoreCase( "433" ) ) {
2601                 return false;
2602             }
2603             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2604                     .getCrossReferences();
2605             if ( x.size() != 4 ) {
2606                 return false;
2607             }
2608             int c = 0;
2609             for( final Accession acc : x ) {
2610                 if ( c == 0 ) {
2611                     if ( !acc.getSource().equals( "KEGG" ) ) {
2612                         return false;
2613                     }
2614                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2615                         return false;
2616                     }
2617                 }
2618                 c++;
2619             }
2620         }
2621         catch ( final Exception e ) {
2622             e.printStackTrace( System.out );
2623             return false;
2624         }
2625         return true;
2626     }
2627
2628     private static boolean testBasicPhyloXMLparsingValidating() {
2629         try {
2630             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2631             PhyloXmlParser xml_parser = null;
2632             try {
2633                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2634             }
2635             catch ( final Exception e ) {
2636                 // Do nothing -- means were not running from jar.
2637             }
2638             if ( xml_parser == null ) {
2639                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2640                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2641                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2642                 }
2643                 else {
2644                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2645                 }
2646             }
2647             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ),
2648                                                               xml_parser );
2649             if ( xml_parser.getErrorCount() > 0 ) {
2650                 System.out.println( xml_parser.getErrorMessages().toString() );
2651                 return false;
2652             }
2653             if ( phylogenies_0.length != 4 ) {
2654                 return false;
2655             }
2656             final Phylogeny t1 = phylogenies_0[ 0 ];
2657             final Phylogeny t2 = phylogenies_0[ 1 ];
2658             final Phylogeny t3 = phylogenies_0[ 2 ];
2659             final Phylogeny t4 = phylogenies_0[ 3 ];
2660             if ( !t1.getName().equals( "t1" ) ) {
2661                 return false;
2662             }
2663             if ( !t2.getName().equals( "t2" ) ) {
2664                 return false;
2665             }
2666             if ( !t3.getName().equals( "t3" ) ) {
2667                 return false;
2668             }
2669             if ( !t4.getName().equals( "t4" ) ) {
2670                 return false;
2671             }
2672             if ( t1.getNumberOfExternalNodes() != 1 ) {
2673                 return false;
2674             }
2675             if ( t2.getNumberOfExternalNodes() != 2 ) {
2676                 return false;
2677             }
2678             if ( t3.getNumberOfExternalNodes() != 4 ) {
2679                 return false;
2680             }
2681             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2682             final Phylogeny[] phylogenies_1 = factory.create( new File( x2 ), xml_parser );
2683             if ( xml_parser.getErrorCount() > 0 ) {
2684                 System.out.println( "errors:" );
2685                 System.out.println( xml_parser.getErrorMessages().toString() );
2686                 return false;
2687             }
2688             if ( phylogenies_1.length != 4 ) {
2689                 return false;
2690             }
2691             final Phylogeny[] phylogenies_2 = factory.create( new File(Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml" ),
2692                                                               xml_parser );
2693             if ( xml_parser.getErrorCount() > 0 ) {
2694                 System.out.println( "errors:" );
2695                 System.out.println( xml_parser.getErrorMessages().toString() );
2696                 return false;
2697             }
2698             if ( phylogenies_2.length != 1 ) {
2699                 return false;
2700             }
2701             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2702                 return false;
2703             }
2704             final Phylogeny[] phylogenies_3 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml" ),
2705                                                               xml_parser );
2706             if ( xml_parser.getErrorCount() > 0 ) {
2707                 System.out.println( xml_parser.getErrorMessages().toString() );
2708                 return false;
2709             }
2710             if ( phylogenies_3.length != 2 ) {
2711                 return false;
2712             }
2713             final Phylogeny a = phylogenies_3[ 0 ];
2714             if ( !a.getName().equals( "tree 4" ) ) {
2715                 return false;
2716             }
2717             if ( a.getNumberOfExternalNodes() != 3 ) {
2718                 return false;
2719             }
2720             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2721                 return false;
2722             }
2723             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2724                 return false;
2725             }
2726             final Phylogeny[] phylogenies_4 = factory.create( new File( Test.PATH_TO_TEST_DATA + "special_characters.xml") ,
2727                                                               xml_parser );
2728             if ( xml_parser.getErrorCount() > 0 ) {
2729                 System.out.println( xml_parser.getErrorMessages().toString() );
2730                 return false;
2731             }
2732             if ( phylogenies_4.length != 1 ) {
2733                 return false;
2734             }
2735             final Phylogeny s = phylogenies_4[ 0 ];
2736             if ( s.getNumberOfExternalNodes() != 6 ) {
2737                 return false;
2738             }
2739             s.getNode( "first" );
2740             s.getNode( "<>" );
2741             s.getNode( "\"<a'b&c'd\">\"" );
2742             s.getNode( "'''\"" );
2743             s.getNode( "\"\"\"" );
2744             s.getNode( "dick & doof" );
2745         }
2746         catch ( final Exception e ) {
2747             e.printStackTrace( System.out );
2748             return false;
2749         }
2750         return true;
2751     }
2752     
2753     private static boolean testPhyloXMLparsingValidating() {
2754         try {
2755             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2756             PhyloXmlParser xml_parser = null;
2757             try {
2758                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2759             }
2760             catch ( final Exception e ) {
2761                 // Do nothing -- means were not running from jar.
2762             }
2763             if ( xml_parser == null ) {
2764                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2765                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2766                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2767                 }
2768                 else {
2769                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2770                 }
2771             }
2772             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_1.xml" ),
2773                                                               xml_parser );
2774             if ( xml_parser.getErrorCount() > 0 ) {
2775                 System.out.println( xml_parser.getErrorMessages().toString() );
2776                 return false;
2777             }
2778             if ( phylogenies_0.length != 3 ) {
2779                 return false;
2780             }
2781         }
2782         catch ( final Exception e ) {
2783             e.printStackTrace( System.out );
2784             return false;
2785         }
2786         return true;
2787     }
2788
2789     private static boolean testBasicProtein() {
2790         try {
2791             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2792             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2793             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2794             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2795             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2796             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2797             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2798             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2799             p0.addProteinDomain( y );
2800             p0.addProteinDomain( e );
2801             p0.addProteinDomain( b );
2802             p0.addProteinDomain( c );
2803             p0.addProteinDomain( d );
2804             p0.addProteinDomain( a );
2805             p0.addProteinDomain( x );
2806             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2807                 return false;
2808             }
2809             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2810                 return false;
2811             }
2812             //
2813             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2814             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2815             aa0.addProteinDomain( a1 );
2816             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2817                 return false;
2818             }
2819             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2820                 return false;
2821             }
2822             //
2823             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2824             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2825             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2826             aa1.addProteinDomain( a11 );
2827             aa1.addProteinDomain( a12 );
2828             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2829                 return false;
2830             }
2831             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2832                 return false;
2833             }
2834             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2835             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2836                 return false;
2837             }
2838             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2839                 return false;
2840             }
2841             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2842                 return false;
2843             }
2844             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2845             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2846                 return false;
2847             }
2848             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2849                 return false;
2850             }
2851             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2852                 return false;
2853             }
2854             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2855                 return false;
2856             }
2857             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2858             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2859                 return false;
2860             }
2861             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2862                 return false;
2863             }
2864             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2865                 return false;
2866             }
2867             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2868                 return false;
2869             }
2870             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2871             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2872                 return false;
2873             }
2874             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2875                 return false;
2876             }
2877             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2878                 return false;
2879             }
2880             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2881                 return false;
2882             }
2883             //
2884             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2885             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2886             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2887             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2888             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2889             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2890             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2891             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2892             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2893             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2894             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2895             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2896             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2897             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2898             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2899             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2900             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2901             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2902             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2903             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2904             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2905             p00.addProteinDomain( y0 );
2906             p00.addProteinDomain( e0 );
2907             p00.addProteinDomain( b0 );
2908             p00.addProteinDomain( c0 );
2909             p00.addProteinDomain( d0 );
2910             p00.addProteinDomain( a0 );
2911             p00.addProteinDomain( x0 );
2912             p00.addProteinDomain( y1 );
2913             p00.addProteinDomain( y2 );
2914             p00.addProteinDomain( y3 );
2915             p00.addProteinDomain( e1 );
2916             p00.addProteinDomain( e2 );
2917             p00.addProteinDomain( e3 );
2918             p00.addProteinDomain( e4 );
2919             p00.addProteinDomain( e5 );
2920             p00.addProteinDomain( z0 );
2921             p00.addProteinDomain( z1 );
2922             p00.addProteinDomain( z2 );
2923             p00.addProteinDomain( zz0 );
2924             p00.addProteinDomain( zz1 );
2925             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2926                 return false;
2927             }
2928             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2929                 return false;
2930             }
2931             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2932                 return false;
2933             }
2934             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2935                 return false;
2936             }
2937             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" ) ) {
2938                 return false;
2939             }
2940             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2941             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2942             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2943             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2944             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2945             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2946             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2947             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2948             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2949             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2950             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2951             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2952             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2953             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2954             p.addProteinDomain( B15 );
2955             p.addProteinDomain( C50 );
2956             p.addProteinDomain( A60 );
2957             p.addProteinDomain( A30 );
2958             p.addProteinDomain( C70 );
2959             p.addProteinDomain( B35 );
2960             p.addProteinDomain( B40 );
2961             p.addProteinDomain( A0 );
2962             p.addProteinDomain( A10 );
2963             p.addProteinDomain( A20 );
2964             p.addProteinDomain( B25 );
2965             p.addProteinDomain( D80 );
2966             List<String> domains_ids = new ArrayList<String>();
2967             domains_ids.add( "A" );
2968             domains_ids.add( "B" );
2969             domains_ids.add( "C" );
2970             if ( !p.contains( domains_ids, false ) ) {
2971                 return false;
2972             }
2973             if ( !p.contains( domains_ids, true ) ) {
2974                 return false;
2975             }
2976             domains_ids.add( "X" );
2977             if ( p.contains( domains_ids, false ) ) {
2978                 return false;
2979             }
2980             if ( p.contains( domains_ids, true ) ) {
2981                 return false;
2982             }
2983             domains_ids = new ArrayList<String>();
2984             domains_ids.add( "A" );
2985             domains_ids.add( "C" );
2986             domains_ids.add( "D" );
2987             if ( !p.contains( domains_ids, false ) ) {
2988                 return false;
2989             }
2990             if ( !p.contains( domains_ids, true ) ) {
2991                 return false;
2992             }
2993             domains_ids = new ArrayList<String>();
2994             domains_ids.add( "A" );
2995             domains_ids.add( "D" );
2996             domains_ids.add( "C" );
2997             if ( !p.contains( domains_ids, false ) ) {
2998                 return false;
2999             }
3000             if ( p.contains( domains_ids, true ) ) {
3001                 return false;
3002             }
3003             domains_ids = new ArrayList<String>();
3004             domains_ids.add( "A" );
3005             domains_ids.add( "A" );
3006             domains_ids.add( "B" );
3007             if ( !p.contains( domains_ids, false ) ) {
3008                 return false;
3009             }
3010             if ( !p.contains( domains_ids, true ) ) {
3011                 return false;
3012             }
3013             domains_ids = new ArrayList<String>();
3014             domains_ids.add( "A" );
3015             domains_ids.add( "A" );
3016             domains_ids.add( "A" );
3017             domains_ids.add( "B" );
3018             domains_ids.add( "B" );
3019             if ( !p.contains( domains_ids, false ) ) {
3020                 return false;
3021             }
3022             if ( !p.contains( domains_ids, true ) ) {
3023                 return false;
3024             }
3025             domains_ids = new ArrayList<String>();
3026             domains_ids.add( "A" );
3027             domains_ids.add( "A" );
3028             domains_ids.add( "B" );
3029             domains_ids.add( "A" );
3030             domains_ids.add( "B" );
3031             domains_ids.add( "B" );
3032             domains_ids.add( "A" );
3033             domains_ids.add( "B" );
3034             domains_ids.add( "C" );
3035             domains_ids.add( "A" );
3036             domains_ids.add( "C" );
3037             domains_ids.add( "D" );
3038             if ( !p.contains( domains_ids, false ) ) {
3039                 return false;
3040             }
3041             if ( p.contains( domains_ids, true ) ) {
3042                 return false;
3043             }
3044         }
3045         catch ( final Exception e ) {
3046             e.printStackTrace( System.out );
3047             return false;
3048         }
3049         return true;
3050     }
3051
3052     private static boolean testBasicTable() {
3053         try {
3054             final BasicTable<String> t0 = new BasicTable<String>();
3055             if ( t0.getNumberOfColumns() != 0 ) {
3056                 return false;
3057             }
3058             if ( t0.getNumberOfRows() != 0 ) {
3059                 return false;
3060             }
3061             t0.setValue( 3, 2, "23" );
3062             t0.setValue( 10, 1, "error" );
3063             t0.setValue( 10, 1, "110" );
3064             t0.setValue( 9, 1, "19" );
3065             t0.setValue( 1, 10, "101" );
3066             t0.setValue( 10, 10, "1010" );
3067             t0.setValue( 100, 10, "10100" );
3068             t0.setValue( 0, 0, "00" );
3069             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3070                 return false;
3071             }
3072             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3073                 return false;
3074             }
3075             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3076                 return false;
3077             }
3078             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3079                 return false;
3080             }
3081             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3082                 return false;
3083             }
3084             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3085                 return false;
3086             }
3087             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3088                 return false;
3089             }
3090             if ( t0.getNumberOfColumns() != 101 ) {
3091                 return false;
3092             }
3093             if ( t0.getNumberOfRows() != 11 ) {
3094                 return false;
3095             }
3096             if ( t0.getValueAsString( 49, 4 ) != null ) {
3097                 return false;
3098             }
3099             final String l = ForesterUtil.getLineSeparator();
3100             final StringBuffer source = new StringBuffer();
3101             source.append( "" + l );
3102             source.append( "# 1 1 1 1 1 1 1 1" + l );
3103             source.append( " 00 01 02 03" + l );
3104             source.append( "   10 11 12 13  " + l );
3105             source.append( "20 21 22 23 " + l );
3106             source.append( "    30  31    32 33" + l );
3107             source.append( "40 41 42 43" + l );
3108             source.append( "  # 1 1 1 1 1 " + l );
3109             source.append( "50 51 52 53 54" + l );
3110             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
3111             if ( t1.getNumberOfColumns() != 5 ) {
3112                 return false;
3113             }
3114             if ( t1.getNumberOfRows() != 6 ) {
3115                 return false;
3116             }
3117             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
3118                 return false;
3119             }
3120             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
3121                 return false;
3122             }
3123             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
3124                 return false;
3125             }
3126             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
3127                 return false;
3128             }
3129             final StringBuffer source1 = new StringBuffer();
3130             source1.append( "" + l );
3131             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3132             source1.append( " 00; 01 ;02;03" + l );
3133             source1.append( "   10; 11; 12; 13  " + l );
3134             source1.append( "20; 21; 22; 23 " + l );
3135             source1.append( "    30;  31;    32; 33" + l );
3136             source1.append( "40;41;42;43" + l );
3137             source1.append( "  # 1 1 1 1 1 " + l );
3138             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
3139             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
3140             if ( t2.getNumberOfColumns() != 5 ) {
3141                 return false;
3142             }
3143             if ( t2.getNumberOfRows() != 6 ) {
3144                 return false;
3145             }
3146             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
3147                 return false;
3148             }
3149             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
3150                 return false;
3151             }
3152             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
3153                 return false;
3154             }
3155             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
3156                 return false;
3157             }
3158             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
3159                 return false;
3160             }
3161             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
3162                 return false;
3163             }
3164             final StringBuffer source2 = new StringBuffer();
3165             source2.append( "" + l );
3166             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3167             source2.append( " 00; 01 ;02;03" + l );
3168             source2.append( "   10; 11; 12; 13  " + l );
3169             source2.append( "20; 21; 22; 23 " + l );
3170             source2.append( "                     " + l );
3171             source2.append( "    30;  31;    32; 33" + l );
3172             source2.append( "40;41;42;43" + l );
3173             source2.append( "  comment: 1 1 1 1 1 " + l );
3174             source2.append( ";;;50  ;   52; 53;;54   " + l );
3175             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
3176                                                                         ';',
3177                                                                         false,
3178                                                                         false,
3179                                                                         "comment:",
3180                                                                         false );
3181             if ( tl.size() != 2 ) {
3182                 return false;
3183             }
3184             final BasicTable<String> t3 = tl.get( 0 );
3185             final BasicTable<String> t4 = tl.get( 1 );
3186             if ( t3.getNumberOfColumns() != 4 ) {
3187                 return false;
3188             }
3189             if ( t3.getNumberOfRows() != 3 ) {
3190                 return false;
3191             }
3192             if ( t4.getNumberOfColumns() != 4 ) {
3193                 return false;
3194             }
3195             if ( t4.getNumberOfRows() != 3 ) {
3196                 return false;
3197             }
3198             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
3199                 return false;
3200             }
3201             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
3202                 return false;
3203             }
3204         }
3205         catch ( final Exception e ) {
3206             e.printStackTrace( System.out );
3207             return false;
3208         }
3209         return true;
3210     }
3211
3212     private static boolean testBasicTolXMLparsing() {
3213         try {
3214             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3215             final TolParser parser = new TolParser();
3216             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
3217             if ( parser.getErrorCount() > 0 ) {
3218                 System.out.println( parser.getErrorMessages().toString() );
3219                 return false;
3220             }
3221             if ( phylogenies_0.length != 1 ) {
3222                 return false;
3223             }
3224             final Phylogeny t1 = phylogenies_0[ 0 ];
3225             if ( t1.getNumberOfExternalNodes() != 5 ) {
3226                 return false;
3227             }
3228             if ( !t1.isRooted() ) {
3229                 return false;
3230             }
3231             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
3232                 return false;
3233             }
3234             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
3235                 return false;
3236             }
3237             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
3238                 return false;
3239             }
3240             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
3241                 return false;
3242             }
3243             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
3244             if ( parser.getErrorCount() > 0 ) {
3245                 System.out.println( parser.getErrorMessages().toString() );
3246                 return false;
3247             }
3248             if ( phylogenies_1.length != 1 ) {
3249                 return false;
3250             }
3251             final Phylogeny t2 = phylogenies_1[ 0 ];
3252             if ( t2.getNumberOfExternalNodes() != 664 ) {
3253                 return false;
3254             }
3255             if ( !t2.isRooted() ) {
3256                 return false;
3257             }
3258             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
3259                 return false;
3260             }
3261             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
3262                 return false;
3263             }
3264             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3265                 return false;
3266             }
3267             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3268                 return false;
3269             }
3270             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
3271                 return false;
3272             }
3273             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3274                     .equals( "Aquifex" ) ) {
3275                 return false;
3276             }
3277             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
3278             if ( parser.getErrorCount() > 0 ) {
3279                 System.out.println( parser.getErrorMessages().toString() );
3280                 return false;
3281             }
3282             if ( phylogenies_2.length != 1 ) {
3283                 return false;
3284             }
3285             final Phylogeny t3 = phylogenies_2[ 0 ];
3286             if ( t3.getNumberOfExternalNodes() != 184 ) {
3287                 return false;
3288             }
3289             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
3290                 return false;
3291             }
3292             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
3293                 return false;
3294             }
3295             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
3296                 return false;
3297             }
3298             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
3299             if ( parser.getErrorCount() > 0 ) {
3300                 System.out.println( parser.getErrorMessages().toString() );
3301                 return false;
3302             }
3303             if ( phylogenies_3.length != 1 ) {
3304                 return false;
3305             }
3306             final Phylogeny t4 = phylogenies_3[ 0 ];
3307             if ( t4.getNumberOfExternalNodes() != 1 ) {
3308                 return false;
3309             }
3310             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
3311                 return false;
3312             }
3313             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
3314                 return false;
3315             }
3316             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
3317                 return false;
3318             }
3319             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
3320             if ( parser.getErrorCount() > 0 ) {
3321                 System.out.println( parser.getErrorMessages().toString() );
3322                 return false;
3323             }
3324             if ( phylogenies_4.length != 1 ) {
3325                 return false;
3326             }
3327             final Phylogeny t5 = phylogenies_4[ 0 ];
3328             if ( t5.getNumberOfExternalNodes() != 13 ) {
3329                 return false;
3330             }
3331             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
3332                 return false;
3333             }
3334             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
3335                 return false;
3336             }
3337             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
3338                 return false;
3339             }
3340         }
3341         catch ( final Exception e ) {
3342             e.printStackTrace( System.out );
3343             return false;
3344         }
3345         return true;
3346     }
3347
3348     private static boolean testBasicTreeMethods() {
3349         try {
3350             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3351             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
3352             if ( t2.getNumberOfExternalNodes() != 4 ) {
3353                 return false;
3354             }
3355             if ( t2.calculateHeight(false) != 8.5 ) {
3356                 return false;
3357             }
3358             if ( !t2.isCompletelyBinary() ) {
3359                 return false;
3360             }
3361             if ( t2.isEmpty() ) {
3362                 return false;
3363             }
3364             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
3365             if ( t3.getNumberOfExternalNodes() != 5 ) {
3366                 return false;
3367             }
3368             if ( t3.calculateHeight(true) != 11 ) {
3369                 return false;
3370             }
3371             if ( t3.isCompletelyBinary() ) {
3372                 return false;
3373             }
3374             final PhylogenyNode n = t3.getNode( "ABC" );
3375             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 ];
3376             if ( t4.getNumberOfExternalNodes() != 9 ) {
3377                 return false;
3378             }
3379             if ( t4.calculateHeight(false) != 11 ) {
3380                 return false;
3381             }
3382             if ( t4.isCompletelyBinary() ) {
3383                 return false;
3384             }
3385             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)" );
3386             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
3387             if ( t5.getNumberOfExternalNodes() != 8 ) {
3388                 return false;
3389             }
3390             if ( t5.calculateHeight(false) != 15 ) {
3391                 return false;
3392             }
3393             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)" );
3394             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
3395             if ( t6.calculateHeight(true) != 15 ) {
3396                 return false;
3397             }
3398             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)" );
3399             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
3400             if ( t7.calculateHeight(true) != 15 ) {
3401                 return false;
3402             }
3403             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)" );
3404             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
3405             if ( t8.getNumberOfExternalNodes() != 10 ) {
3406                 return false;
3407             }
3408             if ( t8.calculateHeight(true) != 15 ) {
3409                 return false;
3410             }
3411             final char[] a9 = new char[] { 'a' };
3412             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
3413             if ( t9.calculateHeight(true) != 0 ) {
3414                 return false;
3415             }
3416             final char[] a10 = new char[] { 'a', ':', '6' };
3417             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
3418             if ( t10.calculateHeight(true) != 6 ) {
3419                 return false;
3420             }
3421         }
3422         catch ( final Exception e ) {
3423             e.printStackTrace( System.out );
3424             return false;
3425         }
3426         return true;
3427     }
3428
3429     private static boolean testConfidenceAssessor() {
3430         try {
3431             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3432             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3433             final Phylogeny[] ev0 = factory
3434                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3435                              new NHXParser() );
3436             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3437             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3438                 return false;
3439             }
3440             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3441                 return false;
3442             }
3443             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3444             final Phylogeny[] ev1 = factory
3445                     .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)));",
3446                              new NHXParser() );
3447             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3448             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3449                 return false;
3450             }
3451             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3452                 return false;
3453             }
3454             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3455             final Phylogeny[] ev_b = factory
3456                     .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",
3457                              new NHXParser() );
3458             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3459             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3460                 return false;
3461             }
3462             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3463                 return false;
3464             }
3465             //
3466             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3467             final Phylogeny[] ev1x = factory
3468                     .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)));",
3469                              new NHXParser() );
3470             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3471             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3472                 return false;
3473             }
3474             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3475                 return false;
3476             }
3477             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3478             final Phylogeny[] ev_bx = factory
3479                     .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",
3480                              new NHXParser() );
3481             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3482             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3483                 return false;
3484             }
3485             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3486                 return false;
3487             }
3488             final Phylogeny[] t2 = factory
3489                     .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);",
3490                              new NHXParser() );
3491             final Phylogeny[] ev2 = factory
3492                     .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);",
3493                              new NHXParser() );
3494             for( final Phylogeny target : t2 ) {
3495                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3496             }
3497             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3498                                                  new NHXParser() )[ 0 ];
3499             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3500             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3501             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3502                 return false;
3503             }
3504             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3505                 return false;
3506             }
3507             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3508                 return false;
3509             }
3510         }
3511         catch ( final Exception e ) {
3512             e.printStackTrace();
3513             return false;
3514         }
3515         return true;
3516     }
3517
3518     private static boolean testCopyOfNodeData() {
3519         try {
3520             final PhylogenyNode n1 = PhylogenyNode
3521                     .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]" );
3522             final PhylogenyNode n2 = n1.copyNodeData();
3523             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3524                 return false;
3525             }
3526         }
3527         catch ( final Exception e ) {
3528             e.printStackTrace();
3529             return false;
3530         }
3531         return true;
3532     }
3533
3534     private static boolean testCreateBalancedPhylogeny() {
3535         try {
3536             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3537             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3538                 return false;
3539             }
3540             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3541                 return false;
3542             }
3543             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3544             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3545                 return false;
3546             }
3547             if ( p1.getNumberOfExternalNodes() != 100 ) {
3548                 return false;
3549             }
3550         }
3551         catch ( final Exception e ) {
3552             e.printStackTrace();
3553             return false;
3554         }
3555         return true;
3556     }
3557
3558     private static boolean testCreateUriForSeqWeb() {
3559         try {
3560             final PhylogenyNode n = new PhylogenyNode();
3561             n.setName( "tr|B3RJ64" );
3562             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3563                 return false;
3564             }
3565             n.setName( "B0LM41_HUMAN" );
3566             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3567                 return false;
3568             }
3569             n.setName( "NP_001025424" );
3570             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3571                 return false;
3572             }
3573             n.setName( "_NM_001030253-" );
3574             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3575                 return false;
3576             }
3577             n.setName( "XM_002122186" );
3578             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3579                 return false;
3580             }
3581             n.setName( "dgh_AAA34956_gdg" );
3582             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3583                 return false;
3584             }
3585             n.setName( "AAA34956" );
3586             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3587                 return false;
3588             }
3589             n.setName( "GI:394892" );
3590             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3591                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3592                 return false;
3593             }
3594             n.setName( "gi_394892" );
3595             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3596                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3597                 return false;
3598             }
3599             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3600             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3601                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3602                 return false;
3603             }
3604             n.setName( "P12345" );
3605             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3606                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3607                 return false;
3608             }
3609             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3610             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3611                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3612                 return false;
3613             }
3614         }
3615         catch ( final Exception e ) {
3616             e.printStackTrace( System.out );
3617             return false;
3618         }
3619         return true;
3620     }
3621
3622     private static boolean testDataObjects() {
3623         try {
3624             final Confidence s0 = new Confidence();
3625             final Confidence s1 = new Confidence();
3626             if ( !s0.isEqual( s1 ) ) {
3627                 return false;
3628             }
3629             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3630             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3631             if ( s2.isEqual( s1 ) ) {
3632                 return false;
3633             }
3634             if ( !s2.isEqual( s3 ) ) {
3635                 return false;
3636             }
3637             final Confidence s4 = ( Confidence ) s3.copy();
3638             if ( !s4.isEqual( s3 ) ) {
3639                 return false;
3640             }
3641             s3.asSimpleText();
3642             s3.asText();
3643             // Taxonomy
3644             // ----------
3645             final Taxonomy t1 = new Taxonomy();
3646             final Taxonomy t2 = new Taxonomy();
3647             final Taxonomy t3 = new Taxonomy();
3648             final Taxonomy t4 = new Taxonomy();
3649             final Taxonomy t5 = new Taxonomy();
3650             t1.setIdentifier( new Identifier( "ecoli" ) );
3651             t1.setTaxonomyCode( "ECOLI" );
3652             t1.setScientificName( "E. coli" );
3653             t1.setCommonName( "coli" );
3654             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3655             if ( !t1.isEqual( t0 ) ) {
3656                 return false;
3657             }
3658             t2.setIdentifier( new Identifier( "ecoli" ) );
3659             t2.setTaxonomyCode( "OTHER" );
3660             t2.setScientificName( "what" );
3661             t2.setCommonName( "something" );
3662             if ( !t1.isEqual( t2 ) ) {
3663                 return false;
3664             }
3665             t2.setIdentifier( new Identifier( "nemve" ) );
3666             if ( t1.isEqual( t2 ) ) {
3667                 return false;
3668             }
3669             t1.setIdentifier( null );
3670             t3.setTaxonomyCode( "ECOLI" );
3671             t3.setScientificName( "what" );
3672             t3.setCommonName( "something" );
3673             if ( !t1.isEqual( t3 ) ) {
3674                 return false;
3675             }
3676             t1.setIdentifier( null );
3677             t1.setTaxonomyCode( "" );
3678             t4.setScientificName( "E. ColI" );
3679             t4.setCommonName( "something" );
3680             if ( !t1.isEqual( t4 ) ) {
3681                 return false;
3682             }
3683             t4.setScientificName( "B. subtilis" );
3684             t4.setCommonName( "something" );
3685             if ( t1.isEqual( t4 ) ) {
3686                 return false;
3687             }
3688             t1.setIdentifier( null );
3689             t1.setTaxonomyCode( "" );
3690             t1.setScientificName( "" );
3691             t5.setCommonName( "COLI" );
3692             if ( !t1.isEqual( t5 ) ) {
3693                 return false;
3694             }
3695             t5.setCommonName( "vibrio" );
3696             if ( t1.isEqual( t5 ) ) {
3697                 return false;
3698             }
3699             // Identifier
3700             // ----------
3701             final Identifier id0 = new Identifier( "123", "pfam" );
3702             final Identifier id1 = ( Identifier ) id0.copy();
3703             if ( !id1.isEqual( id1 ) ) {
3704                 return false;
3705             }
3706             if ( !id1.isEqual( id0 ) ) {
3707                 return false;
3708             }
3709             if ( !id0.isEqual( id1 ) ) {
3710                 return false;
3711             }
3712             id1.asSimpleText();
3713             id1.asText();
3714             // ProteinDomain
3715             // ---------------
3716             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3717             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3718             if ( !pd1.isEqual( pd1 ) ) {
3719                 return false;
3720             }
3721             if ( !pd1.isEqual( pd0 ) ) {
3722                 return false;
3723             }
3724             pd1.asSimpleText();
3725             pd1.asText();
3726             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3727             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3728             if ( !pd3.isEqual( pd3 ) ) {
3729                 return false;
3730             }
3731             if ( !pd2.isEqual( pd3 ) ) {
3732                 return false;
3733             }
3734             if ( !pd0.isEqual( pd3 ) ) {
3735                 return false;
3736             }
3737             pd3.asSimpleText();
3738             pd3.asText();
3739             // DomainArchitecture
3740             // ------------------
3741             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3742             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3743             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3744             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3745             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3746             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3747             domains0.add( d2 );
3748             domains0.add( d0 );
3749             domains0.add( d3 );
3750             domains0.add( d1 );
3751             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3752             if ( ds0.getNumberOfDomains() != 4 ) {
3753                 return false;
3754             }
3755             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3756             if ( !ds0.isEqual( ds0 ) ) {
3757                 return false;
3758             }
3759             if ( !ds0.isEqual( ds1 ) ) {
3760                 return false;
3761             }
3762             if ( ds1.getNumberOfDomains() != 4 ) {
3763                 return false;
3764             }
3765             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3766             domains1.add( d1 );
3767             domains1.add( d2 );
3768             domains1.add( d4 );
3769             domains1.add( d0 );
3770             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3771             if ( ds0.isEqual( ds2 ) ) {
3772                 return false;
3773             }
3774             ds1.asSimpleText();
3775             ds1.asText();
3776             ds1.toNHX();
3777             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3778             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3779                 System.out.println( ds3.toNHX() );
3780                 return false;
3781             }
3782             if ( ds3.getNumberOfDomains() != 3 ) {
3783                 return false;
3784             }
3785             // Event
3786             // -----
3787             final Event e1 = new Event( Event.EventType.fusion );
3788             if ( e1.isDuplication() ) {
3789                 return false;
3790             }
3791             if ( !e1.isFusion() ) {
3792                 return false;
3793             }
3794             if ( !e1.asText().toString().equals( "fusion" ) ) {
3795                 return false;
3796             }
3797             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3798                 return false;
3799             }
3800             final Event e11 = new Event( Event.EventType.fusion );
3801             if ( !e11.isEqual( e1 ) ) {
3802                 return false;
3803             }
3804             if ( !e11.toNHX().toString().equals( "" ) ) {
3805                 return false;
3806             }
3807             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3808             if ( e2.isDuplication() ) {
3809                 return false;
3810             }
3811             if ( !e2.isSpeciationOrDuplication() ) {
3812                 return false;
3813             }
3814             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3815                 return false;
3816             }
3817             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3818                 return false;
3819             }
3820             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3821                 return false;
3822             }
3823             if ( e11.isEqual( e2 ) ) {
3824                 return false;
3825             }
3826             final Event e2c = ( Event ) e2.copy();
3827             if ( !e2c.isEqual( e2 ) ) {
3828                 return false;
3829             }
3830             Event e3 = new Event( 1, 2, 3 );
3831             if ( e3.isDuplication() ) {
3832                 return false;
3833             }
3834             if ( e3.isSpeciation() ) {
3835                 return false;
3836             }
3837             if ( e3.isGeneLoss() ) {
3838                 return false;
3839             }
3840             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3841                 return false;
3842             }
3843             final Event e3c = ( Event ) e3.copy();
3844             final Event e3cc = ( Event ) e3c.copy();
3845             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3846                 return false;
3847             }
3848             e3 = null;
3849             if ( !e3c.isEqual( e3cc ) ) {
3850                 return false;
3851             }
3852             Event e4 = new Event( 1, 2, 3 );
3853             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3854                 return false;
3855             }
3856             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3857                 return false;
3858             }
3859             final Event e4c = ( Event ) e4.copy();
3860             e4 = null;
3861             final Event e4cc = ( Event ) e4c.copy();
3862             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3863                 return false;
3864             }
3865             if ( !e4c.isEqual( e4cc ) ) {
3866                 return false;
3867             }
3868             final Event e5 = new Event();
3869             if ( !e5.isUnassigned() ) {
3870                 return false;
3871             }
3872             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3873                 return false;
3874             }
3875             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3876                 return false;
3877             }
3878             final Event e6 = new Event( 1, 0, 0 );
3879             if ( !e6.asText().toString().equals( "duplication" ) ) {
3880                 return false;
3881             }
3882             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3883                 return false;
3884             }
3885             final Event e7 = new Event( 0, 1, 0 );
3886             if ( !e7.asText().toString().equals( "speciation" ) ) {
3887                 return false;
3888             }
3889             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3890                 return false;
3891             }
3892             final Event e8 = new Event( 0, 0, 1 );
3893             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3894                 return false;
3895             }
3896             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3897                 return false;
3898             }
3899         }
3900         catch ( final Exception e ) {
3901             e.printStackTrace( System.out );
3902             return false;
3903         }
3904         return true;
3905     }
3906
3907     private static boolean testDeletionOfExternalNodes() {
3908         try {
3909             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3910             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3911             final PhylogenyWriter w = new PhylogenyWriter();
3912             if ( t0.isEmpty() ) {
3913                 return false;
3914             }
3915             if ( t0.getNumberOfExternalNodes() != 1 ) {
3916                 return false;
3917             }
3918             t0.deleteSubtree( t0.getNode( "A" ), false );
3919             if ( t0.getNumberOfExternalNodes() != 0 ) {
3920                 return false;
3921             }
3922             if ( !t0.isEmpty() ) {
3923                 return false;
3924             }
3925             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3926             if ( t1.getNumberOfExternalNodes() != 2 ) {
3927                 return false;
3928             }
3929             t1.deleteSubtree( t1.getNode( "A" ), false );
3930             if ( t1.getNumberOfExternalNodes() != 1 ) {
3931                 return false;
3932             }
3933             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3934                 return false;
3935             }
3936             t1.deleteSubtree( t1.getNode( "B" ), false );
3937             if ( t1.getNumberOfExternalNodes() != 1 ) {
3938                 return false;
3939             }
3940             t1.deleteSubtree( t1.getNode( "r" ), false );
3941             if ( !t1.isEmpty() ) {
3942                 return false;
3943             }
3944             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3945             if ( t2.getNumberOfExternalNodes() != 3 ) {
3946                 return false;
3947             }
3948             t2.deleteSubtree( t2.getNode( "B" ), false );
3949             if ( t2.getNumberOfExternalNodes() != 2 ) {
3950                 return false;
3951             }
3952             t2.toNewHampshireX();
3953             PhylogenyNode n = t2.getNode( "A" );
3954             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3955                 return false;
3956             }
3957             t2.deleteSubtree( t2.getNode( "A" ), false );
3958             if ( t2.getNumberOfExternalNodes() != 2 ) {
3959                 return false;
3960             }
3961             t2.deleteSubtree( t2.getNode( "C" ), true );
3962             if ( t2.getNumberOfExternalNodes() != 1 ) {
3963                 return false;
3964             }
3965             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3966             if ( t3.getNumberOfExternalNodes() != 4 ) {
3967                 return false;
3968             }
3969             t3.deleteSubtree( t3.getNode( "B" ), true );
3970             if ( t3.getNumberOfExternalNodes() != 3 ) {
3971                 return false;
3972             }
3973             n = t3.getNode( "A" );
3974             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3975                 return false;
3976             }
3977             n = n.getNextExternalNode();
3978             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3979                 return false;
3980             }
3981             t3.deleteSubtree( t3.getNode( "A" ), true );
3982             if ( t3.getNumberOfExternalNodes() != 2 ) {
3983                 return false;
3984             }
3985             n = t3.getNode( "C" );
3986             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3987                 return false;
3988             }
3989             t3.deleteSubtree( t3.getNode( "C" ), true );
3990             if ( t3.getNumberOfExternalNodes() != 1 ) {
3991                 return false;
3992             }
3993             t3.deleteSubtree( t3.getNode( "D" ), true );
3994             if ( t3.getNumberOfExternalNodes() != 0 ) {
3995                 return false;
3996             }
3997             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3998             if ( t4.getNumberOfExternalNodes() != 6 ) {
3999                 return false;
4000             }
4001             t4.deleteSubtree( t4.getNode( "B2" ), true );
4002             if ( t4.getNumberOfExternalNodes() != 5 ) {
4003                 return false;
4004             }
4005             String s = w.toNewHampshire( t4, true ).toString();
4006             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
4007                 return false;
4008             }
4009             t4.deleteSubtree( t4.getNode( "B11" ), true );
4010             if ( t4.getNumberOfExternalNodes() != 4 ) {
4011                 return false;
4012             }
4013             t4.deleteSubtree( t4.getNode( "C" ), true );
4014             if ( t4.getNumberOfExternalNodes() != 3 ) {
4015                 return false;
4016             }
4017             n = t4.getNode( "A" );
4018             n = n.getNextExternalNode();
4019             if ( !n.getName().equals( "B12" ) ) {
4020                 return false;
4021             }
4022             n = n.getNextExternalNode();
4023             if ( !n.getName().equals( "D" ) ) {
4024                 return false;
4025             }
4026             s = w.toNewHampshire( t4, true ).toString();
4027             if ( !s.equals( "((A,B12),D);" ) ) {
4028                 return false;
4029             }
4030             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4031             t5.deleteSubtree( t5.getNode( "A" ), true );
4032             if ( t5.getNumberOfExternalNodes() != 5 ) {
4033                 return false;
4034             }
4035             s = w.toNewHampshire( t5, true ).toString();
4036             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
4037                 return false;
4038             }
4039             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4040             t6.deleteSubtree( t6.getNode( "B11" ), true );
4041             if ( t6.getNumberOfExternalNodes() != 5 ) {
4042                 return false;
4043             }
4044             s = w.toNewHampshire( t6, false ).toString();
4045             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
4046                 return false;
4047             }
4048             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4049             t7.deleteSubtree( t7.getNode( "B12" ), true );
4050             if ( t7.getNumberOfExternalNodes() != 5 ) {
4051                 return false;
4052             }
4053             s = w.toNewHampshire( t7, true ).toString();
4054             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
4055                 return false;
4056             }
4057             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4058             t8.deleteSubtree( t8.getNode( "B2" ), true );
4059             if ( t8.getNumberOfExternalNodes() != 5 ) {
4060                 return false;
4061             }
4062             s = w.toNewHampshire( t8, false ).toString();
4063             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
4064                 return false;
4065             }
4066             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4067             t9.deleteSubtree( t9.getNode( "C" ), true );
4068             if ( t9.getNumberOfExternalNodes() != 5 ) {
4069                 return false;
4070             }
4071             s = w.toNewHampshire( t9, true ).toString();
4072             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
4073                 return false;
4074             }
4075             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4076             t10.deleteSubtree( t10.getNode( "D" ), true );
4077             if ( t10.getNumberOfExternalNodes() != 5 ) {
4078                 return false;
4079             }
4080             s = w.toNewHampshire( t10, true ).toString();
4081             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
4082                 return false;
4083             }
4084             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
4085             t11.deleteSubtree( t11.getNode( "A" ), true );
4086             if ( t11.getNumberOfExternalNodes() != 2 ) {
4087                 return false;
4088             }
4089             s = w.toNewHampshire( t11, true ).toString();
4090             if ( !s.equals( "(B,C);" ) ) {
4091                 return false;
4092             }
4093             t11.deleteSubtree( t11.getNode( "C" ), true );
4094             if ( t11.getNumberOfExternalNodes() != 1 ) {
4095                 return false;
4096             }
4097             s = w.toNewHampshire( t11, false ).toString();
4098             if ( !s.equals( "B;" ) ) {
4099                 return false;
4100             }
4101             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
4102             t12.deleteSubtree( t12.getNode( "B2" ), true );
4103             if ( t12.getNumberOfExternalNodes() != 8 ) {
4104                 return false;
4105             }
4106             s = w.toNewHampshire( t12, true ).toString();
4107             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
4108                 return false;
4109             }
4110             t12.deleteSubtree( t12.getNode( "B3" ), true );
4111             if ( t12.getNumberOfExternalNodes() != 7 ) {
4112                 return false;
4113             }
4114             s = w.toNewHampshire( t12, true ).toString();
4115             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
4116                 return false;
4117             }
4118             t12.deleteSubtree( t12.getNode( "C3" ), true );
4119             if ( t12.getNumberOfExternalNodes() != 6 ) {
4120                 return false;
4121             }
4122             s = w.toNewHampshire( t12, true ).toString();
4123             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
4124                 return false;
4125             }
4126             t12.deleteSubtree( t12.getNode( "A1" ), true );
4127             if ( t12.getNumberOfExternalNodes() != 5 ) {
4128                 return false;
4129             }
4130             s = w.toNewHampshire( t12, true ).toString();
4131             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
4132                 return false;
4133             }
4134             t12.deleteSubtree( t12.getNode( "B1" ), true );
4135             if ( t12.getNumberOfExternalNodes() != 4 ) {
4136                 return false;
4137             }
4138             s = w.toNewHampshire( t12, true ).toString();
4139             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
4140                 return false;
4141             }
4142             t12.deleteSubtree( t12.getNode( "A3" ), true );
4143             if ( t12.getNumberOfExternalNodes() != 3 ) {
4144                 return false;
4145             }
4146             s = w.toNewHampshire( t12, true ).toString();
4147             if ( !s.equals( "(A2,(C1,C2));" ) ) {
4148                 return false;
4149             }
4150             t12.deleteSubtree( t12.getNode( "A2" ), true );
4151             if ( t12.getNumberOfExternalNodes() != 2 ) {
4152                 return false;
4153             }
4154             s = w.toNewHampshire( t12, true ).toString();
4155             if ( !s.equals( "(C1,C2);" ) ) {
4156                 return false;
4157             }
4158             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
4159             t13.deleteSubtree( t13.getNode( "D" ), true );
4160             if ( t13.getNumberOfExternalNodes() != 4 ) {
4161                 return false;
4162             }
4163             s = w.toNewHampshire( t13, true ).toString();
4164             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
4165                 return false;
4166             }
4167             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
4168             t14.deleteSubtree( t14.getNode( "E" ), true );
4169             if ( t14.getNumberOfExternalNodes() != 5 ) {
4170                 return false;
4171             }
4172             s = w.toNewHampshire( t14, true ).toString();
4173             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
4174                 return false;
4175             }
4176             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
4177             t15.deleteSubtree( t15.getNode( "B2" ), true );
4178             if ( t15.getNumberOfExternalNodes() != 11 ) {
4179                 return false;
4180             }
4181             t15.deleteSubtree( t15.getNode( "B1" ), true );
4182             if ( t15.getNumberOfExternalNodes() != 10 ) {
4183                 return false;
4184             }
4185             t15.deleteSubtree( t15.getNode( "B3" ), true );
4186             if ( t15.getNumberOfExternalNodes() != 9 ) {
4187                 return false;
4188             }
4189             t15.deleteSubtree( t15.getNode( "B4" ), true );
4190             if ( t15.getNumberOfExternalNodes() != 8 ) {
4191                 return false;
4192             }
4193             t15.deleteSubtree( t15.getNode( "A1" ), true );
4194             if ( t15.getNumberOfExternalNodes() != 7 ) {
4195                 return false;
4196             }
4197             t15.deleteSubtree( t15.getNode( "C4" ), true );
4198             if ( t15.getNumberOfExternalNodes() != 6 ) {
4199                 return false;
4200             }
4201         }
4202         catch ( final Exception e ) {
4203             e.printStackTrace( System.out );
4204             return false;
4205         }
4206         return true;
4207     }
4208
4209     private static boolean testDescriptiveStatistics() {
4210         try {
4211             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
4212             dss1.addValue( 82 );
4213             dss1.addValue( 78 );
4214             dss1.addValue( 70 );
4215             dss1.addValue( 58 );
4216             dss1.addValue( 42 );
4217             if ( dss1.getN() != 5 ) {
4218                 return false;
4219             }
4220             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
4221                 return false;
4222             }
4223             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
4224                 return false;
4225             }
4226             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
4227                 return false;
4228             }
4229             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
4230                 return false;
4231             }
4232             if ( !Test.isEqual( dss1.median(), 70 ) ) {
4233                 return false;
4234             }
4235             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
4236                 return false;
4237             }
4238             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
4239                 return false;
4240             }
4241             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
4242                 return false;
4243             }
4244             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
4245                 return false;
4246             }
4247             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
4248                 return false;
4249             }
4250             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
4251                 return false;
4252             }
4253             dss1.addValue( 123 );
4254             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
4255                 return false;
4256             }
4257             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
4258                 return false;
4259             }
4260             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
4261                 return false;
4262             }
4263             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
4264             dss2.addValue( -1.85 );
4265             dss2.addValue( 57.5 );
4266             dss2.addValue( 92.78 );
4267             dss2.addValue( 57.78 );
4268             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
4269                 return false;
4270             }
4271             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
4272                 return false;
4273             }
4274             final double[] a = dss2.getDataAsDoubleArray();
4275             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
4276                 return false;
4277             }
4278             dss2.addValue( -100 );
4279             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
4280                 return false;
4281             }
4282             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
4283                 return false;
4284             }
4285             final double[] ds = new double[ 14 ];
4286             ds[ 0 ] = 34;
4287             ds[ 1 ] = 23;
4288             ds[ 2 ] = 1;
4289             ds[ 3 ] = 32;
4290             ds[ 4 ] = 11;
4291             ds[ 5 ] = 2;
4292             ds[ 6 ] = 12;
4293             ds[ 7 ] = 33;
4294             ds[ 8 ] = 13;
4295             ds[ 9 ] = 22;
4296             ds[ 10 ] = 21;
4297             ds[ 11 ] = 35;
4298             ds[ 12 ] = 24;
4299             ds[ 13 ] = 31;
4300             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
4301             if ( bins.length != 4 ) {
4302                 return false;
4303             }
4304             if ( bins[ 0 ] != 2 ) {
4305                 return false;
4306             }
4307             if ( bins[ 1 ] != 3 ) {
4308                 return false;
4309             }
4310             if ( bins[ 2 ] != 4 ) {
4311                 return false;
4312             }
4313             if ( bins[ 3 ] != 5 ) {
4314                 return false;
4315             }
4316             final double[] ds1 = new double[ 9 ];
4317             ds1[ 0 ] = 10.0;
4318             ds1[ 1 ] = 19.0;
4319             ds1[ 2 ] = 9.999;
4320             ds1[ 3 ] = 0.0;
4321             ds1[ 4 ] = 39.9;
4322             ds1[ 5 ] = 39.999;
4323             ds1[ 6 ] = 30.0;
4324             ds1[ 7 ] = 19.999;
4325             ds1[ 8 ] = 30.1;
4326             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
4327             if ( bins1.length != 4 ) {
4328                 return false;
4329             }
4330             if ( bins1[ 0 ] != 2 ) {
4331                 return false;
4332             }
4333             if ( bins1[ 1 ] != 3 ) {
4334                 return false;
4335             }
4336             if ( bins1[ 2 ] != 0 ) {
4337                 return false;
4338             }
4339             if ( bins1[ 3 ] != 4 ) {
4340                 return false;
4341             }
4342             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
4343             if ( bins1_1.length != 3 ) {
4344                 return false;
4345             }
4346             if ( bins1_1[ 0 ] != 3 ) {
4347                 return false;
4348             }
4349             if ( bins1_1[ 1 ] != 2 ) {
4350                 return false;
4351             }
4352             if ( bins1_1[ 2 ] != 4 ) {
4353                 return false;
4354             }
4355             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
4356             if ( bins1_2.length != 3 ) {
4357                 return false;
4358             }
4359             if ( bins1_2[ 0 ] != 2 ) {
4360                 return false;
4361             }
4362             if ( bins1_2[ 1 ] != 2 ) {
4363                 return false;
4364             }
4365             if ( bins1_2[ 2 ] != 2 ) {
4366                 return false;
4367             }
4368             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
4369             dss3.addValue( 1 );
4370             dss3.addValue( 1 );
4371             dss3.addValue( 1 );
4372             dss3.addValue( 2 );
4373             dss3.addValue( 3 );
4374             dss3.addValue( 4 );
4375             dss3.addValue( 5 );
4376             dss3.addValue( 5 );
4377             dss3.addValue( 5 );
4378             dss3.addValue( 6 );
4379             dss3.addValue( 7 );
4380             dss3.addValue( 8 );
4381             dss3.addValue( 9 );
4382             dss3.addValue( 10 );
4383             dss3.addValue( 10 );
4384             dss3.addValue( 10 );
4385             final AsciiHistogram histo = new AsciiHistogram( dss3 );
4386             histo.toStringBuffer( 10, '=', 40, 5 );
4387             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
4388         }
4389         catch ( final Exception e ) {
4390             e.printStackTrace( System.out );
4391             return false;
4392         }
4393         return true;
4394     }
4395
4396     private static boolean testDir( final String file ) {
4397         try {
4398             final File f = new File( file );
4399             if ( !f.exists() ) {
4400                 return false;
4401             }
4402             if ( !f.isDirectory() ) {
4403                 return false;
4404             }
4405             if ( !f.canRead() ) {
4406                 return false;
4407             }
4408         }
4409         catch ( final Exception e ) {
4410             return false;
4411         }
4412         return true;
4413     }
4414
4415     private static boolean testEbiEntryRetrieval() {
4416         try {
4417             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
4418             if ( !entry.getAccession().equals( "AAK41263" ) ) {
4419                 System.out.println( entry.getAccession() );
4420                 return false;
4421             }
4422             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
4423                 System.out.println( entry.getTaxonomyScientificName() );
4424                 return false;
4425             }
4426             if ( !entry.getSequenceName()
4427                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4428                 System.out.println( entry.getSequenceName() );
4429                 return false;
4430             }
4431             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4432                 System.out.println( entry.getGeneName() );
4433                 return false;
4434             }
4435             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4436                 System.out.println( entry.getTaxonomyIdentifier() );
4437                 return false;
4438             }
4439             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4440                 System.out.println( entry.getAnnotations().first().getRefValue() );
4441                 return false;
4442             }
4443             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4444                 System.out.println( entry.getAnnotations().first().getRefSource() );
4445                 return false;
4446             }
4447             if ( entry.getCrossReferences().size() < 1 ) {
4448                 return false;
4449             }
4450             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4451             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4452                 return false;
4453             }
4454             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4455                 System.out.println( entry1.getTaxonomyScientificName() );
4456                 return false;
4457             }
4458             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4459                 System.out.println( entry1.getSequenceName() );
4460                 return false;
4461             }
4462             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4463                 System.out.println( entry1.getTaxonomyIdentifier() );
4464                 return false;
4465             }
4466             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4467                 System.out.println( entry1.getGeneName() );
4468                 return false;
4469             }
4470             if ( entry1.getCrossReferences().size() < 1 ) {
4471                 return false;
4472             }
4473             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4474             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4475                 return false;
4476             }
4477             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4478                 System.out.println( entry2.getTaxonomyScientificName() );
4479                 return false;
4480             }
4481             if ( !entry2.getSequenceName()
4482                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4483                 System.out.println( entry2.getSequenceName() );
4484                 return false;
4485             }
4486             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4487                 System.out.println( entry2.getTaxonomyIdentifier() );
4488                 return false;
4489             }
4490             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4491                 System.out.println( entry2.getGeneName() );
4492                 return false;
4493             }
4494             if ( entry2.getCrossReferences().size() < 1 ) {
4495                 return false;
4496             }
4497             if ( !entry2.getChromosome().equals( "20" ) ) {
4498                 return false;
4499             }
4500             if ( !entry2.getMap().equals( "20q11.22" ) ) {
4501                 return false;
4502             }
4503             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4504             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4505                 return false;
4506             }
4507             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4508                 System.out.println( entry3.getTaxonomyScientificName() );
4509                 return false;
4510             }
4511             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4512                 System.out.println( entry3.getSequenceName() );
4513                 return false;
4514             }
4515             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4516                 System.out.println( entry3.getTaxonomyIdentifier() );
4517                 return false;
4518             }
4519             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4520                 System.out.println( entry3.getSequenceSymbol() );
4521                 return false;
4522             }
4523             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4524                 return false;
4525             }
4526             if ( entry3.getCrossReferences().size() < 1 ) {
4527                 return false;
4528             }
4529             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4530             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4531                 return false;
4532             }
4533             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4534                 System.out.println( entry4.getTaxonomyScientificName() );
4535                 return false;
4536             }
4537             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4538                 System.out.println( entry4.getSequenceName() );
4539                 return false;
4540             }
4541             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4542                 System.out.println( entry4.getTaxonomyIdentifier() );
4543                 return false;
4544             }
4545             if ( !entry4.getGeneName().equals( "ras" ) ) {
4546                 System.out.println( entry4.getGeneName() );
4547                 return false;
4548             }
4549             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4550             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4551                 return false;
4552             }
4553             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4554                 System.out.println( entry5.getTaxonomyScientificName() );
4555                 return false;
4556             }
4557             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4558                 System.out.println( entry5.getSequenceName() );
4559                 return false;
4560             }
4561             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4562                 System.out.println( entry5.getTaxonomyIdentifier() );
4563                 return false;
4564             }
4565             final SequenceDatabaseEntry entry6 = SequenceDbWsTools.obtainEntry( "M30539" );
4566             if ( !entry6.getAccession().equals( "M30539" ) ) {
4567                 return false;
4568             }
4569             if ( !entry6.getGeneName().equals( "ras" ) ) {
4570                 return false;
4571             }
4572             if ( !entry6.getSequenceName().equals( "Human SK2 c-Ha-ras-1 oncogene-encoded protein gene, exon 1" ) ) {
4573                 return false;
4574             }
4575             if ( !entry6.getTaxonomyIdentifier().equals( "9606" ) ) {
4576                 return false;
4577             }
4578             if ( !entry6.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4579                 return false;
4580             }
4581             if ( entry6.getCrossReferences().size() < 1 ) {
4582                 return false;
4583             }
4584         }
4585         catch ( final IOException e ) {
4586             System.out.println();
4587             System.out.println( "the following might be due to absence internet connection:" );
4588             e.printStackTrace( System.out );
4589             return true;
4590         }
4591         catch ( final Exception e ) {
4592             e.printStackTrace();
4593             return false;
4594         }
4595         return true;
4596     }
4597
4598     private static boolean testExternalNodeRelatedMethods() {
4599         try {
4600             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4601             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4602             PhylogenyNode n = t1.getNode( "A" );
4603             n = n.getNextExternalNode();
4604             if ( !n.getName().equals( "B" ) ) {
4605                 return false;
4606             }
4607             n = n.getNextExternalNode();
4608             if ( !n.getName().equals( "C" ) ) {
4609                 return false;
4610             }
4611             n = n.getNextExternalNode();
4612             if ( !n.getName().equals( "D" ) ) {
4613                 return false;
4614             }
4615             n = t1.getNode( "B" );
4616             while ( !n.isLastExternalNode() ) {
4617                 n = n.getNextExternalNode();
4618             }
4619             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4620             n = t2.getNode( "A" );
4621             n = n.getNextExternalNode();
4622             if ( !n.getName().equals( "B" ) ) {
4623                 return false;
4624             }
4625             n = n.getNextExternalNode();
4626             if ( !n.getName().equals( "C" ) ) {
4627                 return false;
4628             }
4629             n = n.getNextExternalNode();
4630             if ( !n.getName().equals( "D" ) ) {
4631                 return false;
4632             }
4633             n = t2.getNode( "B" );
4634             while ( !n.isLastExternalNode() ) {
4635                 n = n.getNextExternalNode();
4636             }
4637             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4638             n = t3.getNode( "A" );
4639             n = n.getNextExternalNode();
4640             if ( !n.getName().equals( "B" ) ) {
4641                 return false;
4642             }
4643             n = n.getNextExternalNode();
4644             if ( !n.getName().equals( "C" ) ) {
4645                 return false;
4646             }
4647             n = n.getNextExternalNode();
4648             if ( !n.getName().equals( "D" ) ) {
4649                 return false;
4650             }
4651             n = n.getNextExternalNode();
4652             if ( !n.getName().equals( "E" ) ) {
4653                 return false;
4654             }
4655             n = n.getNextExternalNode();
4656             if ( !n.getName().equals( "F" ) ) {
4657                 return false;
4658             }
4659             n = n.getNextExternalNode();
4660             if ( !n.getName().equals( "G" ) ) {
4661                 return false;
4662             }
4663             n = n.getNextExternalNode();
4664             if ( !n.getName().equals( "H" ) ) {
4665                 return false;
4666             }
4667             n = t3.getNode( "B" );
4668             while ( !n.isLastExternalNode() ) {
4669                 n = n.getNextExternalNode();
4670             }
4671             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4672             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4673                 final PhylogenyNode node = iter.next();
4674             }
4675             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4676             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4677                 final PhylogenyNode node = iter.next();
4678             }
4679             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4680             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4681             if ( !iter.next().getName().equals( "A" ) ) {
4682                 return false;
4683             }
4684             if ( !iter.next().getName().equals( "B" ) ) {
4685                 return false;
4686             }
4687             if ( !iter.next().getName().equals( "C" ) ) {
4688                 return false;
4689             }
4690             if ( !iter.next().getName().equals( "D" ) ) {
4691                 return false;
4692             }
4693             if ( !iter.next().getName().equals( "E" ) ) {
4694                 return false;
4695             }
4696             if ( !iter.next().getName().equals( "F" ) ) {
4697                 return false;
4698             }
4699             if ( iter.hasNext() ) {
4700                 return false;
4701             }
4702         }
4703         catch ( final Exception e ) {
4704             e.printStackTrace( System.out );
4705             return false;
4706         }
4707         return true;
4708     }
4709
4710     private static boolean testExtractSNFromNodeName() {
4711         try {
4712             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4713                 return false;
4714             }
4715             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4716                 return false;
4717             }
4718             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4719                 return false;
4720             }
4721             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4722                     .equals( "Mus musculus musculus" ) ) {
4723                 return false;
4724             }
4725             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4726                     .equals( "Mus musculus musculus" ) ) {
4727                 return false;
4728             }
4729             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4730                     .equals( "Mus musculus musculus" ) ) {
4731                 return false;
4732             }
4733             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4734                     .equals( "Mus musculus musculus" ) ) {
4735                 return false;
4736             }
4737             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4738                 return false;
4739             }
4740             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4741                     .equals( "Mus musculus musculus" ) ) {
4742                 return false;
4743             }
4744             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4745                     .equals( "Mus musculus musculus" ) ) {
4746                 return false;
4747             }
4748             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4749                 return false;
4750             }
4751             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4752                 return false;
4753             }
4754             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4755                 return false;
4756             }
4757             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4758                 return false;
4759             }
4760             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4761                     .equals( "Mus musculus musculus" ) ) {
4762                 return false;
4763             }
4764             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4765                 return false;
4766             }
4767             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4768                 return false;
4769             }
4770             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4771                 return false;
4772             }
4773             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4774                 return false;
4775             }
4776             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4777                 return false;
4778             }
4779             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4780                 return false;
4781             }
4782             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4783                 return false;
4784             }
4785             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4786                 return false;
4787             }
4788             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4789                     .equals( "Mus musculus" ) ) {
4790                 return false;
4791             }
4792             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4793                     .equals( "Mus musculus" ) ) {
4794                 return false;
4795             }
4796             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4797                 return false;
4798             }
4799             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4800                     .equals( "Mus musculus musculus" ) ) {
4801                 return false;
4802             }
4803             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4804                     .equals( "Mus musculus musculus" ) ) {
4805                 return false;
4806             }
4807             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4808                     .equals( "Mus musculus musculus" ) ) {
4809                 return false;
4810             }
4811             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4812                 return false;
4813             }
4814             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4815                     .equals( "Pilostyles mexicana" ) ) {
4816                 return false;
4817             }
4818             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4819                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4820                 return false;
4821             }
4822             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4823                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4824                 return false;
4825             }
4826             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4827                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4828                 return false;
4829             }
4830             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4831                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4832                 return false;
4833             }
4834             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4835                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4836                 return false;
4837             }
4838             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4839                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4840                 return false;
4841             }
4842             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4843                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4844                 return false;
4845             }
4846             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4847                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4848                 return false;
4849             }
4850             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4851                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4852                 return false;
4853             }
4854             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4855                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4856                 return false;
4857             }
4858             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4859                     .equals( "Escherichia coli (strain K12)" ) ) {
4860                 return false;
4861             }
4862             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4863                     .equals( "Escherichia coli (strain K12)" ) ) {
4864                 return false;
4865             }
4866             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4867                     .equals( "Escherichia coli (str. K12)" ) ) {
4868                 return false;
4869             }
4870             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4871                     .equals( "Escherichia coli (str. K12)" ) ) {
4872                 return false;
4873             }
4874             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4875                     .equals( "Escherichia coli (str. K12)" ) ) {
4876                 return false;
4877             }
4878             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4879                     .equals( "Escherichia coli (var. K12)" ) ) {
4880                 return false;
4881             }
4882             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4883                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4884                 return false;
4885             }
4886             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4887                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4888                 return false;
4889             }
4890             if ( !ParserUtils
4891                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4892                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4893                 return false;
4894             }
4895             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4896                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4897                 return false;
4898             }
4899             if ( !ParserUtils
4900                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4901                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4902                 return false;
4903             }
4904             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4905                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4906                 return false;
4907             }
4908             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4909                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4910                 return false;
4911             }
4912             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4913                 return false;
4914             }
4915             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4916                 return false;
4917             }
4918             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4919                 return false;
4920             }
4921             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4922                     .equals( "Macrocera sp." ) ) {
4923                 return false;
4924             }
4925             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4926                 return false;
4927             }
4928             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4929                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4930                 return false;
4931             }
4932             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4933                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4934                 return false;
4935             }
4936             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4937                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4938                 return false;
4939             }
4940             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4941                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4942                 return false;
4943             }
4944         }
4945         catch ( final Exception e ) {
4946             e.printStackTrace( System.out );
4947             return false;
4948         }
4949         return true;
4950     }
4951
4952     private static boolean testExtractTaxonomyDataFromNodeName() {
4953         try {
4954             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
4955             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4956                 return false;
4957             }
4958             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
4959             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4960                 return false;
4961             }
4962             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
4963             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4964                 return false;
4965             }
4966             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
4967             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4968                 return false;
4969             }
4970             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
4971             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4972                 return false;
4973             }
4974             n = new PhylogenyNode( "HNRPR_HUMAN" );
4975             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4976                 return false;
4977             }
4978             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
4979             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4980                 return false;
4981             }
4982         }
4983         catch ( final Exception e ) {
4984             e.printStackTrace( System.out );
4985             return false;
4986         }
4987         return true;
4988     }
4989
4990     private static boolean testExtractTaxonomyCodeFromNodeName() {
4991         try {
4992             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4993                 return false;
4994             }
4995             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4996                     .equals( "SOYBN" ) ) {
4997                 return false;
4998             }
4999             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
5000                     .equals( "ARATH" ) ) {
5001                 return false;
5002             }
5003             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
5004                     .equals( "ARATH" ) ) {
5005                 return false;
5006             }
5007             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
5008                 return false;
5009             }
5010             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
5011                 return false;
5012             }
5013             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5014                 return false;
5015             }
5016             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5017                     .equals( "SOYBN" ) ) {
5018                 return false;
5019             }
5020             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5021                     .equals( "SOYBN" ) ) {
5022                 return false;
5023             }
5024             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5025                     .equals( "SOYBN" ) ) {
5026                 return false;
5027             }
5028             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5029                     .equals( "SOYBN" ) ) {
5030                 return false;
5031             }
5032             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5033                     .equals( "SOYBN" ) ) {
5034                 return false;
5035             }
5036             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5037                     .equals( "SOYBN" ) ) {
5038                 return false;
5039             }
5040             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
5041                     .equals( "SOYBN" ) ) {
5042                 return false;
5043             }
5044             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
5045                     .equals( "SOYBN" ) ) {
5046                 return false;
5047             }
5048             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
5049                 return false;
5050             }
5051             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
5052                     .equals( "SOYBN" ) ) {
5053                 return false;
5054             }
5055             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
5056                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
5057                 return false;
5058             }
5059             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
5060                     .equals( "9YX45" ) ) {
5061                 return false;
5062             }
5063             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
5064                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5065                                                                .equals( "MOUSE" ) ) {
5066                 return false;
5067             }
5068             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
5069                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5070                                                                .equals( "MOUSE" ) ) {
5071                 return false;
5072             }
5073             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
5074                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5075                                                                .equals( "MOUSE" ) ) {
5076                 return false;
5077             }
5078             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
5079                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5080                 return false;
5081             }
5082             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
5083                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5084                 return false;
5085             }
5086             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5087                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
5088                 return false;
5089             }
5090             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5091                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
5092                 return false;
5093             }
5094             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
5095                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
5096                 return false;
5097             }
5098             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
5099                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5100                 return false;
5101             }
5102             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
5103                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5104                 return false;
5105             }
5106             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5107                     .equals( "RAT" ) ) {
5108                 return false;
5109             }
5110             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5111                     .equals( "PIG" ) ) {
5112                 return false;
5113             }
5114             if ( !ParserUtils
5115                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5116                     .equals( "MOUSE" ) ) {
5117                 return false;
5118             }
5119             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5120                     .equals( "MOUSE" ) ) {
5121                 return false;
5122             }
5123             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5124                 return false;
5125             }
5126         }
5127         catch ( final Exception e ) {
5128             e.printStackTrace( System.out );
5129             return false;
5130         }
5131         return true;
5132     }
5133
5134     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
5135         try {
5136             PhylogenyNode n = new PhylogenyNode();
5137             n.setName( "tr|B3RJ64" );
5138             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5139                 return false;
5140             }
5141             n.setName( "tr.B3RJ64" );
5142             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5143                 return false;
5144             }
5145             n.setName( "tr=B3RJ64" );
5146             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5147                 return false;
5148             }
5149             n.setName( "tr-B3RJ64" );
5150             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5151                 return false;
5152             }
5153             n.setName( "tr/B3RJ64" );
5154             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5155                 return false;
5156             }
5157             n.setName( "tr\\B3RJ64" );
5158             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5159                 return false;
5160             }
5161             n.setName( "tr_B3RJ64" );
5162             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5163                 return false;
5164             }
5165             n.setName( " tr|B3RJ64 " );
5166             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5167                 return false;
5168             }
5169             n.setName( "-tr|B3RJ64-" );
5170             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5171                 return false;
5172             }
5173             n.setName( "-tr=B3RJ64-" );
5174             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5175                 return false;
5176             }
5177             n.setName( "_tr=B3RJ64_" );
5178             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5179                 return false;
5180             }
5181             n.setName( " tr_tr|B3RJ64_sp|123 " );
5182             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5183                 return false;
5184             }
5185             n.setName( "B3RJ64" );
5186             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5187                 return false;
5188             }
5189             n.setName( "sp|B3RJ64" );
5190             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5191                 return false;
5192             }
5193             n.setName( "sp|B3RJ64C" );
5194             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5195                 return false;
5196             }
5197             n.setName( "sp B3RJ64" );
5198             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5199                 return false;
5200             }
5201             n.setName( "sp|B3RJ6X" );
5202             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5203                 return false;
5204             }
5205             n.setName( "sp|B3RJ6" );
5206             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5207                 return false;
5208             }
5209             n.setName( "K1PYK7_CRAGI" );
5210             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5211                 return false;
5212             }
5213             n.setName( "K1PYK7_PEA" );
5214             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
5215                 return false;
5216             }
5217             n.setName( "K1PYK7_RAT" );
5218             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
5219                 return false;
5220             }
5221             n.setName( "K1PYK7_PIG" );
5222             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5223                 return false;
5224             }
5225             n.setName( "~K1PYK7_PIG~" );
5226             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5227                 return false;
5228             }
5229             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
5230             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5231                 return false;
5232             }
5233             n.setName( "K1PYKX_CRAGI" );
5234             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5235                 return false;
5236             }
5237             n.setName( "XXXXX_CRAGI" );
5238             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
5239                 return false;
5240             }
5241             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
5242             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
5243                 return false;
5244             }
5245             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
5246             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5247                 return false;
5248             }
5249             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
5250             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
5251                 return false;
5252             }
5253             n = new PhylogenyNode();
5254             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
5255             seq.setSymbol( "K1PYK7_CRAGI" );
5256             n.getNodeData().addSequence( seq );
5257             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5258                 return false;
5259             }
5260             seq.setSymbol( "tr|B3RJ64" );
5261             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5262                 return false;
5263             }
5264             n = new PhylogenyNode();
5265             seq = new org.forester.phylogeny.data.Sequence();
5266             seq.setName( "K1PYK7_CRAGI" );
5267             n.getNodeData().addSequence( seq );
5268             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5269                 return false;
5270             }
5271             seq.setName( "tr|B3RJ64" );
5272             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5273                 return false;
5274             }
5275             n = new PhylogenyNode();
5276             seq = new org.forester.phylogeny.data.Sequence();
5277             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
5278             n.getNodeData().addSequence( seq );
5279             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
5280                 return false;
5281             }
5282             n = new PhylogenyNode();
5283             seq = new org.forester.phylogeny.data.Sequence();
5284             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
5285             n.getNodeData().addSequence( seq );
5286             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5287                 return false;
5288             }
5289             //
5290             n = new PhylogenyNode();
5291             n.setName( "ACP19736" );
5292             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5293                 return false;
5294             }
5295             n = new PhylogenyNode();
5296             n.setName( "|ACP19736|" );
5297             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5298                 return false;
5299             }
5300         }
5301         catch ( final Exception e ) {
5302             e.printStackTrace( System.out );
5303             return false;
5304         }
5305         return true;
5306     }
5307
5308     private static boolean testFastaParser() {
5309         try {
5310             FileInputStream fis1 = new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" );
5311             if ( !FastaParser.isLikelyFasta( fis1 ) ) {
5312                 fis1.close();
5313                 return false;
5314             }
5315             else {
5316                 fis1.close();
5317             }
5318             FileInputStream fis2 = new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" );
5319             if ( FastaParser.isLikelyFasta( fis2 ) ) {
5320                 fis2.close();
5321                 return false;
5322             }
5323             else {
5324                 fis2.close();
5325             }
5326             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
5327             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
5328                 return false;
5329             }
5330             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
5331                 return false;
5332             }
5333             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
5334                 return false;
5335             }
5336             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
5337                 return false;
5338             }
5339             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
5340                 return false;
5341             }
5342             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
5343                 return false;
5344             }
5345         }
5346         catch ( final Exception e ) {
5347             e.printStackTrace();
5348             return false;
5349         }
5350         return true;
5351     }
5352
5353     private static boolean testGenbankAccessorParsing() {
5354         //The format for GenBank Accession numbers are:
5355         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
5356         //Protein:    3 letters + 5 numerals
5357         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
5358         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
5359             return false;
5360         }
5361         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
5362             return false;
5363         }
5364         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
5365             return false;
5366         }
5367         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
5368             return false;
5369         }
5370         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
5371             return false;
5372         }
5373         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
5374             return false;
5375         }
5376         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
5377             return false;
5378         }
5379         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
5380             return false;
5381         }
5382         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
5383             return false;
5384         }
5385         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
5386             return false;
5387         }
5388         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
5389             return false;
5390         }
5391         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
5392             return false;
5393         }
5394         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
5395             return false;
5396         }
5397         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
5398             return false;
5399         }
5400         return true;
5401     }
5402
5403     private static boolean testGeneralMsaParser() {
5404         try {
5405             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
5406             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
5407             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
5408             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
5409             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
5410             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
5411             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
5412             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
5413             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5414                 return false;
5415             }
5416             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5417                 return false;
5418             }
5419             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5420                 return false;
5421             }
5422             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5423                 return false;
5424             }
5425             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5426                 return false;
5427             }
5428             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5429                 return false;
5430             }
5431             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5432                 return false;
5433             }
5434             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5435                 return false;
5436             }
5437             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5438                 return false;
5439             }
5440             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5441                 return false;
5442             }
5443             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5444                 return false;
5445             }
5446             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5447                 return false;
5448             }
5449             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5450             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5451                 return false;
5452             }
5453             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5454                 return false;
5455             }
5456             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5457                 return false;
5458             }
5459             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5460             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5461                 return false;
5462             }
5463             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5464                 return false;
5465             }
5466             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5467                 return false;
5468             }
5469             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5470             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5471                 return false;
5472             }
5473             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5474                 return false;
5475             }
5476             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5477                 return false;
5478             }
5479         }
5480         catch ( final Exception e ) {
5481             e.printStackTrace();
5482             return false;
5483         }
5484         return true;
5485     }
5486
5487     private static boolean testGeneralTable() {
5488         try {
5489             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5490             t0.setValue( 3, 2, "23" );
5491             t0.setValue( 10, 1, "error" );
5492             t0.setValue( 10, 1, "110" );
5493             t0.setValue( 9, 1, "19" );
5494             t0.setValue( 1, 10, "101" );
5495             t0.setValue( 10, 10, "1010" );
5496             t0.setValue( 100, 10, "10100" );
5497             t0.setValue( 0, 0, "00" );
5498             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5499                 return false;
5500             }
5501             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5502                 return false;
5503             }
5504             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5505                 return false;
5506             }
5507             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5508                 return false;
5509             }
5510             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5511                 return false;
5512             }
5513             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5514                 return false;
5515             }
5516             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5517                 return false;
5518             }
5519             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5520                 return false;
5521             }
5522             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5523                 return false;
5524             }
5525             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5526             t1.setValue( "3", "2", "23" );
5527             t1.setValue( "10", "1", "error" );
5528             t1.setValue( "10", "1", "110" );
5529             t1.setValue( "9", "1", "19" );
5530             t1.setValue( "1", "10", "101" );
5531             t1.setValue( "10", "10", "1010" );
5532             t1.setValue( "100", "10", "10100" );
5533             t1.setValue( "0", "0", "00" );
5534             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5535             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5536                 return false;
5537             }
5538             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5539                 return false;
5540             }
5541             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5542                 return false;
5543             }
5544             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5545                 return false;
5546             }
5547             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5548                 return false;
5549             }
5550             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5551                 return false;
5552             }
5553             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5554                 return false;
5555             }
5556             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5557                 return false;
5558             }
5559             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5560                 return false;
5561             }
5562             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5563                 return false;
5564             }
5565         }
5566         catch ( final Exception e ) {
5567             e.printStackTrace( System.out );
5568             return false;
5569         }
5570         return true;
5571     }
5572
5573     private static boolean testGetDistance() {
5574         try {
5575             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5576             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",
5577                                                  new NHXParser() )[ 0 ];
5578             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5579                 return false;
5580             }
5581             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5582                 return false;
5583             }
5584             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5585                 return false;
5586             }
5587             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5588                 return false;
5589             }
5590             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5591                 return false;
5592             }
5593             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5594                 return false;
5595             }
5596             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5597                 return false;
5598             }
5599             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5600                 return false;
5601             }
5602             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5603                 return false;
5604             }
5605             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5606                 return false;
5607             }
5608             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5609                 return false;
5610             }
5611             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5612                 return false;
5613             }
5614             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5615                 return false;
5616             }
5617             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5618                 return false;
5619             }
5620             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5621                 return false;
5622             }
5623             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5624                 return false;
5625             }
5626             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5627                 return false;
5628             }
5629             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5630                 return false;
5631             }
5632             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5633                 return false;
5634             }
5635             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5636                 return false;
5637             }
5638             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5639                 return false;
5640             }
5641             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5642                 return false;
5643             }
5644             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5645                 return false;
5646             }
5647             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5648                 return false;
5649             }
5650             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5651                 return false;
5652             }
5653             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5654                 return false;
5655             }
5656             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5657                 return false;
5658             }
5659             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5660                 return false;
5661             }
5662             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5663                 return false;
5664             }
5665             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5666                 return false;
5667             }
5668             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5669                 return false;
5670             }
5671             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",
5672                                                  new NHXParser() )[ 0 ];
5673             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5674                 return false;
5675             }
5676             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5677                 return false;
5678             }
5679             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5680                 return false;
5681             }
5682             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5683                 return false;
5684             }
5685             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5686                 return false;
5687             }
5688             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5689                 return false;
5690             }
5691             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5692                 return false;
5693             }
5694             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5695                 return false;
5696             }
5697             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5698                 return false;
5699             }
5700             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5701                 return false;
5702             }
5703             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5704                 return false;
5705             }
5706         }
5707         catch ( final Exception e ) {
5708             e.printStackTrace( System.out );
5709             return false;
5710         }
5711         return true;
5712     }
5713
5714     private static boolean testGetLCA() {
5715         try {
5716             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5717             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5718                                                  new NHXParser() )[ 0 ];
5719             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5720             if ( !A.getName().equals( "A" ) ) {
5721                 return false;
5722             }
5723             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5724             if ( !gh.getName().equals( "gh" ) ) {
5725                 return false;
5726             }
5727             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5728             if ( !ab.getName().equals( "ab" ) ) {
5729                 return false;
5730             }
5731             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5732             if ( !ab2.getName().equals( "ab" ) ) {
5733                 return false;
5734             }
5735             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5736             if ( !gh2.getName().equals( "gh" ) ) {
5737                 return false;
5738             }
5739             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5740             if ( !gh3.getName().equals( "gh" ) ) {
5741                 return false;
5742             }
5743             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5744             if ( !abc.getName().equals( "abc" ) ) {
5745                 return false;
5746             }
5747             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5748             if ( !abc2.getName().equals( "abc" ) ) {
5749                 return false;
5750             }
5751             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5752             if ( !abcd.getName().equals( "abcd" ) ) {
5753                 return false;
5754             }
5755             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5756             if ( !abcd2.getName().equals( "abcd" ) ) {
5757                 return false;
5758             }
5759             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5760             if ( !abcdef.getName().equals( "abcdef" ) ) {
5761                 return false;
5762             }
5763             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5764             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5765                 return false;
5766             }
5767             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5768             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5769                 return false;
5770             }
5771             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5772             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5773                 return false;
5774             }
5775             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5776             if ( !abcde.getName().equals( "abcde" ) ) {
5777                 return false;
5778             }
5779             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5780             if ( !abcde2.getName().equals( "abcde" ) ) {
5781                 return false;
5782             }
5783             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5784             if ( !r.getName().equals( "abcdefgh" ) ) {
5785                 return false;
5786             }
5787             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5788             if ( !r2.getName().equals( "abcdefgh" ) ) {
5789                 return false;
5790             }
5791             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5792             if ( !r3.getName().equals( "abcdefgh" ) ) {
5793                 return false;
5794             }
5795             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5796             if ( !abcde3.getName().equals( "abcde" ) ) {
5797                 return false;
5798             }
5799             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5800             if ( !abcde4.getName().equals( "abcde" ) ) {
5801                 return false;
5802             }
5803             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5804             if ( !ab3.getName().equals( "ab" ) ) {
5805                 return false;
5806             }
5807             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5808             if ( !ab4.getName().equals( "ab" ) ) {
5809                 return false;
5810             }
5811             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5812             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5813             if ( !cd.getName().equals( "cd" ) ) {
5814                 return false;
5815             }
5816             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5817             if ( !cd2.getName().equals( "cd" ) ) {
5818                 return false;
5819             }
5820             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5821             if ( !cde.getName().equals( "cde" ) ) {
5822                 return false;
5823             }
5824             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5825             if ( !cde2.getName().equals( "cde" ) ) {
5826                 return false;
5827             }
5828             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5829             if ( !cdef.getName().equals( "cdef" ) ) {
5830                 return false;
5831             }
5832             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5833             if ( !cdef2.getName().equals( "cdef" ) ) {
5834                 return false;
5835             }
5836             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5837             if ( !cdef3.getName().equals( "cdef" ) ) {
5838                 return false;
5839             }
5840             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5841             if ( !rt.getName().equals( "r" ) ) {
5842                 return false;
5843             }
5844             final Phylogeny p3 = factory
5845                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5846                              new NHXParser() )[ 0 ];
5847             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5848             if ( !bc_3.getName().equals( "bc" ) ) {
5849                 return false;
5850             }
5851             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5852             if ( !ac_3.getName().equals( "abc" ) ) {
5853                 return false;
5854             }
5855             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5856             if ( !ad_3.getName().equals( "abcde" ) ) {
5857                 return false;
5858             }
5859             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5860             if ( !af_3.getName().equals( "abcdef" ) ) {
5861                 return false;
5862             }
5863             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5864             if ( !ag_3.getName().equals( "" ) ) {
5865                 return false;
5866             }
5867             if ( !ag_3.isRoot() ) {
5868                 return false;
5869             }
5870             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5871             if ( !al_3.getName().equals( "" ) ) {
5872                 return false;
5873             }
5874             if ( !al_3.isRoot() ) {
5875                 return false;
5876             }
5877             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5878             if ( !kl_3.getName().equals( "" ) ) {
5879                 return false;
5880             }
5881             if ( !kl_3.isRoot() ) {
5882                 return false;
5883             }
5884             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5885             if ( !fl_3.getName().equals( "" ) ) {
5886                 return false;
5887             }
5888             if ( !fl_3.isRoot() ) {
5889                 return false;
5890             }
5891             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5892             if ( !gk_3.getName().equals( "ghijk" ) ) {
5893                 return false;
5894             }
5895             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5896             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5897             if ( !r_4.getName().equals( "r" ) ) {
5898                 return false;
5899             }
5900             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5901             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5902             if ( !r_5.getName().equals( "root" ) ) {
5903                 return false;
5904             }
5905             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5906             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5907             if ( !r_6.getName().equals( "rot" ) ) {
5908                 return false;
5909             }
5910             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5911             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5912             if ( !r_7.getName().equals( "rott" ) ) {
5913                 return false;
5914             }
5915         }
5916         catch ( final Exception e ) {
5917             e.printStackTrace( System.out );
5918             return false;
5919         }
5920         return true;
5921     }
5922
5923     private static boolean testGetLCA2() {
5924         try {
5925             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5926             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5927             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5928             PhylogenyMethods.preOrderReId( p_a );
5929             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5930                                                                                               p_a.getNode( "a" ) );
5931             if ( !p_a_1.getName().equals( "a" ) ) {
5932                 return false;
5933             }
5934             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5935             PhylogenyMethods.preOrderReId( p_b );
5936             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5937                                                                                               p_b.getNode( "a" ) );
5938             if ( !p_b_1.getName().equals( "b" ) ) {
5939                 return false;
5940             }
5941             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5942                                                                                               p_b.getNode( "b" ) );
5943             if ( !p_b_2.getName().equals( "b" ) ) {
5944                 return false;
5945             }
5946             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5947             PhylogenyMethods.preOrderReId( p_c );
5948             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5949                                                                                               p_c.getNode( "a" ) );
5950             if ( !p_c_1.getName().equals( "b" ) ) {
5951                 return false;
5952             }
5953             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5954                                                                                               p_c.getNode( "c" ) );
5955             if ( !p_c_2.getName().equals( "c" ) ) {
5956                 System.out.println( p_c_2.getName() );
5957                 System.exit( -1 );
5958                 return false;
5959             }
5960             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5961                                                                                               p_c.getNode( "b" ) );
5962             if ( !p_c_3.getName().equals( "b" ) ) {
5963                 return false;
5964             }
5965             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5966                                                                                               p_c.getNode( "a" ) );
5967             if ( !p_c_4.getName().equals( "c" ) ) {
5968                 return false;
5969             }
5970             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5971                                                  new NHXParser() )[ 0 ];
5972             PhylogenyMethods.preOrderReId( p1 );
5973             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5974                                                                                           p1.getNode( "A" ) );
5975             if ( !A.getName().equals( "A" ) ) {
5976                 return false;
5977             }
5978             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5979                                                                                            p1.getNode( "gh" ) );
5980             if ( !gh.getName().equals( "gh" ) ) {
5981                 return false;
5982             }
5983             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5984                                                                                            p1.getNode( "B" ) );
5985             if ( !ab.getName().equals( "ab" ) ) {
5986                 return false;
5987             }
5988             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5989                                                                                             p1.getNode( "A" ) );
5990             if ( !ab2.getName().equals( "ab" ) ) {
5991                 return false;
5992             }
5993             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5994                                                                                             p1.getNode( "G" ) );
5995             if ( !gh2.getName().equals( "gh" ) ) {
5996                 return false;
5997             }
5998             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5999                                                                                             p1.getNode( "H" ) );
6000             if ( !gh3.getName().equals( "gh" ) ) {
6001                 return false;
6002             }
6003             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
6004                                                                                             p1.getNode( "A" ) );
6005             if ( !abc.getName().equals( "abc" ) ) {
6006                 return false;
6007             }
6008             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6009                                                                                              p1.getNode( "C" ) );
6010             if ( !abc2.getName().equals( "abc" ) ) {
6011                 return false;
6012             }
6013             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6014                                                                                              p1.getNode( "D" ) );
6015             if ( !abcd.getName().equals( "abcd" ) ) {
6016                 return false;
6017             }
6018             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
6019                                                                                               p1.getNode( "A" ) );
6020             if ( !abcd2.getName().equals( "abcd" ) ) {
6021                 return false;
6022             }
6023             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6024                                                                                                p1.getNode( "F" ) );
6025             if ( !abcdef.getName().equals( "abcdef" ) ) {
6026                 return false;
6027             }
6028             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
6029                                                                                                 p1.getNode( "A" ) );
6030             if ( !abcdef2.getName().equals( "abcdef" ) ) {
6031                 return false;
6032             }
6033             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
6034                                                                                                 p1.getNode( "F" ) );
6035             if ( !abcdef3.getName().equals( "abcdef" ) ) {
6036                 return false;
6037             }
6038             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
6039                                                                                                 p1.getNode( "ab" ) );
6040             if ( !abcdef4.getName().equals( "abcdef" ) ) {
6041                 return false;
6042             }
6043             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6044                                                                                               p1.getNode( "E" ) );
6045             if ( !abcde.getName().equals( "abcde" ) ) {
6046                 return false;
6047             }
6048             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6049                                                                                                p1.getNode( "A" ) );
6050             if ( !abcde2.getName().equals( "abcde" ) ) {
6051                 return false;
6052             }
6053             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
6054                                                                                           p1.getNode( "abcdefgh" ) );
6055             if ( !r.getName().equals( "abcdefgh" ) ) {
6056                 return false;
6057             }
6058             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6059                                                                                            p1.getNode( "H" ) );
6060             if ( !r2.getName().equals( "abcdefgh" ) ) {
6061                 return false;
6062             }
6063             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
6064                                                                                            p1.getNode( "A" ) );
6065             if ( !r3.getName().equals( "abcdefgh" ) ) {
6066                 return false;
6067             }
6068             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6069                                                                                                p1.getNode( "abcde" ) );
6070             if ( !abcde3.getName().equals( "abcde" ) ) {
6071                 return false;
6072             }
6073             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
6074                                                                                                p1.getNode( "E" ) );
6075             if ( !abcde4.getName().equals( "abcde" ) ) {
6076                 return false;
6077             }
6078             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
6079                                                                                             p1.getNode( "B" ) );
6080             if ( !ab3.getName().equals( "ab" ) ) {
6081                 return false;
6082             }
6083             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
6084                                                                                             p1.getNode( "ab" ) );
6085             if ( !ab4.getName().equals( "ab" ) ) {
6086                 return false;
6087             }
6088             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
6089             PhylogenyMethods.preOrderReId( p2 );
6090             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6091                                                                                            p2.getNode( "d" ) );
6092             if ( !cd.getName().equals( "cd" ) ) {
6093                 return false;
6094             }
6095             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6096                                                                                             p2.getNode( "c" ) );
6097             if ( !cd2.getName().equals( "cd" ) ) {
6098                 return false;
6099             }
6100             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6101                                                                                             p2.getNode( "e" ) );
6102             if ( !cde.getName().equals( "cde" ) ) {
6103                 return false;
6104             }
6105             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
6106                                                                                              p2.getNode( "c" ) );
6107             if ( !cde2.getName().equals( "cde" ) ) {
6108                 return false;
6109             }
6110             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6111                                                                                              p2.getNode( "f" ) );
6112             if ( !cdef.getName().equals( "cdef" ) ) {
6113                 return false;
6114             }
6115             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6116                                                                                               p2.getNode( "f" ) );
6117             if ( !cdef2.getName().equals( "cdef" ) ) {
6118                 return false;
6119             }
6120             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
6121                                                                                               p2.getNode( "d" ) );
6122             if ( !cdef3.getName().equals( "cdef" ) ) {
6123                 return false;
6124             }
6125             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6126                                                                                            p2.getNode( "a" ) );
6127             if ( !rt.getName().equals( "r" ) ) {
6128                 return false;
6129             }
6130             final Phylogeny p3 = factory
6131                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
6132                              new NHXParser() )[ 0 ];
6133             PhylogenyMethods.preOrderReId( p3 );
6134             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
6135                                                                                              p3.getNode( "c" ) );
6136             if ( !bc_3.getName().equals( "bc" ) ) {
6137                 return false;
6138             }
6139             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6140                                                                                              p3.getNode( "c" ) );
6141             if ( !ac_3.getName().equals( "abc" ) ) {
6142                 return false;
6143             }
6144             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6145                                                                                              p3.getNode( "d" ) );
6146             if ( !ad_3.getName().equals( "abcde" ) ) {
6147                 return false;
6148             }
6149             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6150                                                                                              p3.getNode( "f" ) );
6151             if ( !af_3.getName().equals( "abcdef" ) ) {
6152                 return false;
6153             }
6154             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6155                                                                                              p3.getNode( "g" ) );
6156             if ( !ag_3.getName().equals( "" ) ) {
6157                 return false;
6158             }
6159             if ( !ag_3.isRoot() ) {
6160                 return false;
6161             }
6162             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6163                                                                                              p3.getNode( "l" ) );
6164             if ( !al_3.getName().equals( "" ) ) {
6165                 return false;
6166             }
6167             if ( !al_3.isRoot() ) {
6168                 return false;
6169             }
6170             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
6171                                                                                              p3.getNode( "l" ) );
6172             if ( !kl_3.getName().equals( "" ) ) {
6173                 return false;
6174             }
6175             if ( !kl_3.isRoot() ) {
6176                 return false;
6177             }
6178             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
6179                                                                                              p3.getNode( "l" ) );
6180             if ( !fl_3.getName().equals( "" ) ) {
6181                 return false;
6182             }
6183             if ( !fl_3.isRoot() ) {
6184                 return false;
6185             }
6186             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
6187                                                                                              p3.getNode( "k" ) );
6188             if ( !gk_3.getName().equals( "ghijk" ) ) {
6189                 return false;
6190             }
6191             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
6192             PhylogenyMethods.preOrderReId( p4 );
6193             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
6194                                                                                             p4.getNode( "c" ) );
6195             if ( !r_4.getName().equals( "r" ) ) {
6196                 return false;
6197             }
6198             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
6199             PhylogenyMethods.preOrderReId( p5 );
6200             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
6201                                                                                             p5.getNode( "c" ) );
6202             if ( !r_5.getName().equals( "root" ) ) {
6203                 return false;
6204             }
6205             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
6206             PhylogenyMethods.preOrderReId( p6 );
6207             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
6208                                                                                             p6.getNode( "a" ) );
6209             if ( !r_6.getName().equals( "rot" ) ) {
6210                 return false;
6211             }
6212             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
6213             PhylogenyMethods.preOrderReId( p7 );
6214             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
6215                                                                                             p7.getNode( "e" ) );
6216             if ( !r_7.getName().equals( "rott" ) ) {
6217                 return false;
6218             }
6219             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6220                                                                                              p7.getNode( "a" ) );
6221             if ( !r_71.getName().equals( "rott" ) ) {
6222                 return false;
6223             }
6224             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6225                                                                                              p7.getNode( "rott" ) );
6226             if ( !r_72.getName().equals( "rott" ) ) {
6227                 return false;
6228             }
6229             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6230                                                                                              p7.getNode( "a" ) );
6231             if ( !r_73.getName().equals( "rott" ) ) {
6232                 return false;
6233             }
6234             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6235                                                                                              p7.getNode( "rott" ) );
6236             if ( !r_74.getName().equals( "rott" ) ) {
6237                 return false;
6238             }
6239             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6240                                                                                              p7.getNode( "e" ) );
6241             if ( !r_75.getName().equals( "e" ) ) {
6242                 return false;
6243             }
6244         }
6245         catch ( final Exception e ) {
6246             e.printStackTrace( System.out );
6247             return false;
6248         }
6249         return true;
6250     }
6251
6252     private static boolean testHmmscanOutputParser() {
6253         final String test_dir = Test.PATH_TO_TEST_DATA;
6254         try {
6255             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
6256                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
6257             parser1.parse();
6258             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
6259                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
6260             final List<Protein> proteins = parser2.parse();
6261             if ( parser2.getProteinsEncountered() != 4 ) {
6262                 return false;
6263             }
6264             if ( proteins.size() != 4 ) {
6265                 return false;
6266             }
6267             if ( parser2.getDomainsEncountered() != 69 ) {
6268                 return false;
6269             }
6270             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
6271                 return false;
6272             }
6273             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
6274                 return false;
6275             }
6276             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
6277                 return false;
6278             }
6279             final Protein p1 = proteins.get( 0 );
6280             if ( p1.getNumberOfProteinDomains() != 15 ) {
6281                 return false;
6282             }
6283             if ( p1.getLength() != 850 ) {
6284                 return false;
6285             }
6286             final Protein p2 = proteins.get( 1 );
6287             if ( p2.getNumberOfProteinDomains() != 51 ) {
6288                 return false;
6289             }
6290             if ( p2.getLength() != 1291 ) {
6291                 return false;
6292             }
6293             final Protein p3 = proteins.get( 2 );
6294             if ( p3.getNumberOfProteinDomains() != 2 ) {
6295                 return false;
6296             }
6297             final Protein p4 = proteins.get( 3 );
6298             if ( p4.getNumberOfProteinDomains() != 1 ) {
6299                 return false;
6300             }
6301             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
6302                 return false;
6303             }
6304             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
6305                 return false;
6306             }
6307             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
6308                 return false;
6309             }
6310             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
6311                 return false;
6312             }
6313             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
6314                 return false;
6315             }
6316             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
6317                 return false;
6318             }
6319             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
6320                 return false;
6321             }
6322         }
6323         catch ( final Exception e ) {
6324             e.printStackTrace( System.out );
6325             return false;
6326         }
6327         return true;
6328     }
6329
6330     private static boolean testLastExternalNodeMethods() {
6331         try {
6332             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6333             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
6334             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
6335             final PhylogenyNode n1 = t0.getNode( "A" );
6336             if ( n1.isLastExternalNode() ) {
6337                 return false;
6338             }
6339             final PhylogenyNode n2 = t0.getNode( "B" );
6340             if ( n2.isLastExternalNode() ) {
6341                 return false;
6342             }
6343             final PhylogenyNode n3 = t0.getNode( "C" );
6344             if ( n3.isLastExternalNode() ) {
6345                 return false;
6346             }
6347             final PhylogenyNode n4 = t0.getNode( "D" );
6348             if ( !n4.isLastExternalNode() ) {
6349                 return false;
6350             }
6351         }
6352         catch ( final Exception e ) {
6353             e.printStackTrace( System.out );
6354             return false;
6355         }
6356         return true;
6357     }
6358
6359     private static boolean testLevelOrderIterator() {
6360         try {
6361             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6362             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
6363             PhylogenyNodeIterator it0;
6364             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
6365                 it0.next();
6366             }
6367             for( it0.reset(); it0.hasNext(); ) {
6368                 it0.next();
6369             }
6370             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
6371             if ( !it.next().getName().equals( "r" ) ) {
6372                 return false;
6373             }
6374             if ( !it.next().getName().equals( "ab" ) ) {
6375                 return false;
6376             }
6377             if ( !it.next().getName().equals( "cd" ) ) {
6378                 return false;
6379             }
6380             if ( !it.next().getName().equals( "A" ) ) {
6381                 return false;
6382             }
6383             if ( !it.next().getName().equals( "B" ) ) {
6384                 return false;
6385             }
6386             if ( !it.next().getName().equals( "C" ) ) {
6387                 return false;
6388             }
6389             if ( !it.next().getName().equals( "D" ) ) {
6390                 return false;
6391             }
6392             if ( it.hasNext() ) {
6393                 return false;
6394             }
6395             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",
6396                                                  new NHXParser() )[ 0 ];
6397             PhylogenyNodeIterator it2;
6398             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
6399                 it2.next();
6400             }
6401             for( it2.reset(); it2.hasNext(); ) {
6402                 it2.next();
6403             }
6404             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
6405             if ( !it3.next().getName().equals( "r" ) ) {
6406                 return false;
6407             }
6408             if ( !it3.next().getName().equals( "abc" ) ) {
6409                 return false;
6410             }
6411             if ( !it3.next().getName().equals( "defg" ) ) {
6412                 return false;
6413             }
6414             if ( !it3.next().getName().equals( "A" ) ) {
6415                 return false;
6416             }
6417             if ( !it3.next().getName().equals( "B" ) ) {
6418                 return false;
6419             }
6420             if ( !it3.next().getName().equals( "C" ) ) {
6421                 return false;
6422             }
6423             if ( !it3.next().getName().equals( "D" ) ) {
6424                 return false;
6425             }
6426             if ( !it3.next().getName().equals( "E" ) ) {
6427                 return false;
6428             }
6429             if ( !it3.next().getName().equals( "F" ) ) {
6430                 return false;
6431             }
6432             if ( !it3.next().getName().equals( "G" ) ) {
6433                 return false;
6434             }
6435             if ( !it3.next().getName().equals( "1" ) ) {
6436                 return false;
6437             }
6438             if ( !it3.next().getName().equals( "2" ) ) {
6439                 return false;
6440             }
6441             if ( !it3.next().getName().equals( "3" ) ) {
6442                 return false;
6443             }
6444             if ( !it3.next().getName().equals( "4" ) ) {
6445                 return false;
6446             }
6447             if ( !it3.next().getName().equals( "5" ) ) {
6448                 return false;
6449             }
6450             if ( !it3.next().getName().equals( "6" ) ) {
6451                 return false;
6452             }
6453             if ( !it3.next().getName().equals( "f1" ) ) {
6454                 return false;
6455             }
6456             if ( !it3.next().getName().equals( "f2" ) ) {
6457                 return false;
6458             }
6459             if ( !it3.next().getName().equals( "f3" ) ) {
6460                 return false;
6461             }
6462             if ( !it3.next().getName().equals( "a" ) ) {
6463                 return false;
6464             }
6465             if ( !it3.next().getName().equals( "b" ) ) {
6466                 return false;
6467             }
6468             if ( !it3.next().getName().equals( "f21" ) ) {
6469                 return false;
6470             }
6471             if ( !it3.next().getName().equals( "X" ) ) {
6472                 return false;
6473             }
6474             if ( !it3.next().getName().equals( "Y" ) ) {
6475                 return false;
6476             }
6477             if ( !it3.next().getName().equals( "Z" ) ) {
6478                 return false;
6479             }
6480             if ( it3.hasNext() ) {
6481                 return false;
6482             }
6483             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6484             PhylogenyNodeIterator it4;
6485             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6486                 it4.next();
6487             }
6488             for( it4.reset(); it4.hasNext(); ) {
6489                 it4.next();
6490             }
6491             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6492             if ( !it5.next().getName().equals( "r" ) ) {
6493                 return false;
6494             }
6495             if ( !it5.next().getName().equals( "A" ) ) {
6496                 return false;
6497             }
6498             if ( !it5.next().getName().equals( "B" ) ) {
6499                 return false;
6500             }
6501             if ( !it5.next().getName().equals( "C" ) ) {
6502                 return false;
6503             }
6504             if ( !it5.next().getName().equals( "D" ) ) {
6505                 return false;
6506             }
6507             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6508             PhylogenyNodeIterator it6;
6509             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6510                 it6.next();
6511             }
6512             for( it6.reset(); it6.hasNext(); ) {
6513                 it6.next();
6514             }
6515             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6516             if ( !it7.next().getName().equals( "A" ) ) {
6517                 return false;
6518             }
6519             if ( it.hasNext() ) {
6520                 return false;
6521             }
6522         }
6523         catch ( final Exception e ) {
6524             e.printStackTrace( System.out );
6525             return false;
6526         }
6527         return true;
6528     }
6529
6530     private static boolean testMafft( final String path ) {
6531         try {
6532             final List<String> opts = new ArrayList<String>();
6533             opts.add( "--maxiterate" );
6534             opts.add( "1000" );
6535             opts.add( "--localpair" );
6536             opts.add( "--quiet" );
6537             Msa msa = null;
6538             final MsaInferrer mafft = Mafft.createInstance( path );
6539             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6540             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6541                 return false;
6542             }
6543             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6544                 return false;
6545             }
6546         }
6547         catch ( final Exception e ) {
6548             e.printStackTrace( System.out );
6549             return false;
6550         }
6551         return true;
6552     }
6553
6554     private static boolean testMidpointrooting() {
6555         try {
6556             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6557             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6558             PhylogenyMethods.midpointRoot( t0 );
6559             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6560                 return false;
6561             }
6562             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6563                 return false;
6564             }
6565             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6566                            1 ) ) {
6567                 return false;
6568             }
6569             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",
6570                                                  new NHXParser() )[ 0 ];
6571             if ( !t1.isRooted() ) {
6572                 return false;
6573             }
6574             PhylogenyMethods.midpointRoot( t1 );
6575             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6576                 return false;
6577             }
6578             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6579                 return false;
6580             }
6581             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6582                 return false;
6583             }
6584             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6585                 return false;
6586             }
6587             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6588                 return false;
6589             }
6590             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6591                 return false;
6592             }
6593             t1.reRoot( t1.getNode( "A" ) );
6594             PhylogenyMethods.midpointRoot( t1 );
6595             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6596                 return false;
6597             }
6598             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6599                 return false;
6600             }
6601             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6602                 return false;
6603             }
6604             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6605                 return false;
6606             }
6607             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6608                 System.exit( -1 );
6609                 return false;
6610             }
6611             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6612                 return false;
6613             }
6614         }
6615         catch ( final Exception e ) {
6616             e.printStackTrace( System.out );
6617             return false;
6618         }
6619         return true;
6620     }
6621
6622     private static boolean testMsaQualityMethod() {
6623         try {
6624             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6625             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6626             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6627             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6628             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6629             l.add( s0 );
6630             l.add( s1 );
6631             l.add( s2 );
6632             l.add( s3 );
6633             final Msa msa = BasicMsa.createInstance( l );
6634             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6635                 return false;
6636             }
6637             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6638                 return false;
6639             }
6640             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6641                 return false;
6642             }
6643             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6644                 return false;
6645             }
6646             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6647                 return false;
6648             }
6649             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6650                 return false;
6651             }
6652             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6653                 return false;
6654             }
6655         }
6656         catch ( final Exception e ) {
6657             e.printStackTrace( System.out );
6658             return false;
6659         }
6660         return true;
6661     }
6662
6663     private static boolean testMsaEntropy() {
6664         try {
6665             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6666             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6667             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6668             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6669             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6670             l.add( s0 );
6671             l.add( s1 );
6672             l.add( s2 );
6673             l.add( s3 );
6674             final Msa msa = BasicMsa.createInstance( l );
6675             //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6676             //FIXME
6677             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6678             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6679             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6680             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6681             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6682             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6683             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6684             //            System.out.println();
6685             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6686             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6687             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6688             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6689             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6690             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6691             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6692             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6693             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6694             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6695             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6696             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6697             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6698             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6699             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6700             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6701             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6702             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6703             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6704             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6705             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6706             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6707             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6708             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6709             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6710             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6711             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6712             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6713             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6714             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6715             final Msa msa2 = BasicMsa.createInstance( l2 );
6716             //            System.out.println();
6717             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6718             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6719             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6720         }
6721         catch ( final Exception e ) {
6722             e.printStackTrace( System.out );
6723             return false;
6724         }
6725         return true;
6726     }
6727
6728     private static boolean testDeleteableMsa() {
6729         try {
6730             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6731             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6732             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6733             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6734             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6735             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6736             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6737             l0.add( s0 );
6738             l0.add( s1 );
6739             l0.add( s2 );
6740             l0.add( s3 );
6741             l0.add( s4 );
6742             l0.add( s5 );
6743             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6744             dmsa0.deleteRow( "b", false );
6745             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6746                 return false;
6747             }
6748             dmsa0.deleteRow( "e", false );
6749             dmsa0.deleteRow( "a", false );
6750             dmsa0.deleteRow( "f", false );
6751             if ( dmsa0.getLength() != 4 ) {
6752                 return false;
6753             }
6754             if ( dmsa0.getNumberOfSequences() != 2 ) {
6755                 return false;
6756             }
6757             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6758                 return false;
6759             }
6760             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6761                 return false;
6762             }
6763             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6764                 return false;
6765             }
6766             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6767                 return false;
6768             }
6769             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6770                 return false;
6771             }
6772             dmsa0.deleteRow( "c", false );
6773             dmsa0.deleteRow( "d", false );
6774             if ( dmsa0.getNumberOfSequences() != 0 ) {
6775                 return false;
6776             }
6777             //
6778             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6779             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6780             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6781             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6782             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6783             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6784             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6785             l1.add( s_0 );
6786             l1.add( s_1 );
6787             l1.add( s_2 );
6788             l1.add( s_3 );
6789             l1.add( s_4 );
6790             l1.add( s_5 );
6791             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6792             dmsa1.deleteGapOnlyColumns();
6793             dmsa1.deleteRow( "a", false );
6794             dmsa1.deleteRow( "f", false );
6795             dmsa1.deleteRow( "d", false );
6796             dmsa1.deleteGapOnlyColumns();
6797             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6798                 return false;
6799             }
6800             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6801                 return false;
6802             }
6803             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6804                 return false;
6805             }
6806             dmsa1.deleteRow( "c", false );
6807             dmsa1.deleteGapOnlyColumns();
6808             final Writer w0 = new StringWriter();
6809             dmsa1.write( w0, MSA_FORMAT.FASTA );
6810             final Writer w1 = new StringWriter();
6811             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6812             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6813                 return false;
6814             }
6815             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6816                 return false;
6817             }
6818             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6819             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6820             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6821             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6822             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6823             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6824             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6825             l2.add( s__0 );
6826             l2.add( s__1 );
6827             l2.add( s__2 );
6828             l2.add( s__3 );
6829             l2.add( s__4 );
6830             l2.add( s__5 );
6831             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6832             dmsa2.deleteGapColumns( 0.5 );
6833             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6834                 return false;
6835             }
6836             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6837                 return false;
6838             }
6839             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6840                 return false;
6841             }
6842             dmsa2.deleteGapColumns( 0.2 );
6843             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6844                 return false;
6845             }
6846             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6847                 return false;
6848             }
6849             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6850                 return false;
6851             }
6852             dmsa2.deleteGapColumns( 0 );
6853             dmsa2.deleteRow( "a", false );
6854             dmsa2.deleteRow( "b", false );
6855             dmsa2.deleteRow( "f", false );
6856             dmsa2.deleteRow( "e", false );
6857             dmsa2.setIdentifier( 0, "new_c" );
6858             dmsa2.setIdentifier( 1, "new_d" );
6859             dmsa2.setResidueAt( 0, 0, 'x' );
6860             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6861             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6862                 return false;
6863             }
6864             final Writer w = new StringWriter();
6865             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6866             final String phylip = w.toString();
6867             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6868                 System.out.println( phylip );
6869                 return false;
6870             }
6871             final Writer w2 = new StringWriter();
6872             dmsa2.write( w2, MSA_FORMAT.FASTA );
6873             final String fasta = w2.toString();
6874             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6875                 System.out.println( fasta );
6876                 return false;
6877             }
6878         }
6879         catch ( final Exception e ) {
6880             e.printStackTrace( System.out );
6881             return false;
6882         }
6883         return true;
6884     }
6885
6886     private static boolean testNextNodeWithCollapsing() {
6887         try {
6888             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6889             PhylogenyNode n;
6890             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6891             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6892             final Phylogeny t0 = factory.create( sb0.toString(), new NHXParser() )[ 0 ];
6893             t0.getNode( "cd" ).setCollapse( true );
6894             t0.getNode( "cde" ).setCollapse( true );
6895             n = t0.getFirstExternalNode();
6896             while ( n != null ) {
6897                 ext.add( n );
6898                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6899             }
6900             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6901                 return false;
6902             }
6903             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6904                 return false;
6905             }
6906             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6907                 return false;
6908             }
6909             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6910                 return false;
6911             }
6912             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6913                 return false;
6914             }
6915             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6916                 return false;
6917             }
6918             ext.clear();
6919             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6920             final Phylogeny t1 = factory.create( sb1.toString(), new NHXParser() )[ 0 ];
6921             t1.getNode( "ab" ).setCollapse( true );
6922             t1.getNode( "cd" ).setCollapse( true );
6923             t1.getNode( "cde" ).setCollapse( true );
6924             n = t1.getNode( "ab" );
6925             ext = new ArrayList<PhylogenyNode>();
6926             while ( n != null ) {
6927                 ext.add( n );
6928                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6929             }
6930             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6931                 return false;
6932             }
6933             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6934                 return false;
6935             }
6936             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6937                 return false;
6938             }
6939             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6940                 return false;
6941             }
6942             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6943                 return false;
6944             }
6945             ext.clear();
6946             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6947             final Phylogeny t2 = factory.create( sb2.toString(), new NHXParser() )[ 0 ];
6948             t2.getNode( "ab" ).setCollapse( true );
6949             t2.getNode( "cd" ).setCollapse( true );
6950             t2.getNode( "cde" ).setCollapse( true );
6951             t2.getNode( "c" ).setCollapse( true );
6952             t2.getNode( "d" ).setCollapse( true );
6953             t2.getNode( "e" ).setCollapse( true );
6954             t2.getNode( "gh" ).setCollapse( true );
6955             n = t2.getNode( "ab" );
6956             ext = new ArrayList<PhylogenyNode>();
6957             while ( n != null ) {
6958                 ext.add( n );
6959                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6960             }
6961             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6962                 return false;
6963             }
6964             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6965                 return false;
6966             }
6967             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6968                 return false;
6969             }
6970             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6971                 return false;
6972             }
6973             ext.clear();
6974             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6975             final Phylogeny t3 = factory.create( sb3.toString(), new NHXParser() )[ 0 ];
6976             t3.getNode( "ab" ).setCollapse( true );
6977             t3.getNode( "cd" ).setCollapse( true );
6978             t3.getNode( "cde" ).setCollapse( true );
6979             t3.getNode( "c" ).setCollapse( true );
6980             t3.getNode( "d" ).setCollapse( true );
6981             t3.getNode( "e" ).setCollapse( true );
6982             t3.getNode( "gh" ).setCollapse( true );
6983             t3.getNode( "fgh" ).setCollapse( true );
6984             n = t3.getNode( "ab" );
6985             ext = new ArrayList<PhylogenyNode>();
6986             while ( n != null ) {
6987                 ext.add( n );
6988                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6989             }
6990             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6991                 return false;
6992             }
6993             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6994                 return false;
6995             }
6996             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6997                 return false;
6998             }
6999             ext.clear();
7000             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7001             final Phylogeny t4 = factory.create( sb4.toString(), new NHXParser() )[ 0 ];
7002             t4.getNode( "ab" ).setCollapse( true );
7003             t4.getNode( "cd" ).setCollapse( true );
7004             t4.getNode( "cde" ).setCollapse( true );
7005             t4.getNode( "c" ).setCollapse( true );
7006             t4.getNode( "d" ).setCollapse( true );
7007             t4.getNode( "e" ).setCollapse( true );
7008             t4.getNode( "gh" ).setCollapse( true );
7009             t4.getNode( "fgh" ).setCollapse( true );
7010             t4.getNode( "abcdefgh" ).setCollapse( true );
7011             n = t4.getNode( "abcdefgh" );
7012             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
7013                 return false;
7014             }
7015             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7016             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
7017             ext.clear();
7018             n = t5.getFirstExternalNode();
7019             while ( n != null ) {
7020                 ext.add( n );
7021                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7022             }
7023             if ( ext.size() != 8 ) {
7024                 return false;
7025             }
7026             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7027                 return false;
7028             }
7029             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7030                 return false;
7031             }
7032             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7033                 return false;
7034             }
7035             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7036                 return false;
7037             }
7038             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7039                 return false;
7040             }
7041             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7042                 return false;
7043             }
7044             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
7045                 return false;
7046             }
7047             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
7048                 return false;
7049             }
7050             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7051             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
7052             ext.clear();
7053             t6.getNode( "ab" ).setCollapse( true );
7054             n = t6.getNode( "ab" );
7055             while ( n != null ) {
7056                 ext.add( n );
7057                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7058             }
7059             if ( ext.size() != 7 ) {
7060                 return false;
7061             }
7062             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7063                 return false;
7064             }
7065             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7066                 return false;
7067             }
7068             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7069                 return false;
7070             }
7071             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7072                 return false;
7073             }
7074             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7075                 return false;
7076             }
7077             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7078                 return false;
7079             }
7080             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7081                 return false;
7082             }
7083             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7084             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
7085             ext.clear();
7086             t7.getNode( "cd" ).setCollapse( true );
7087             n = t7.getNode( "a" );
7088             while ( n != null ) {
7089                 ext.add( n );
7090                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7091             }
7092             if ( ext.size() != 7 ) {
7093                 return false;
7094             }
7095             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7096                 return false;
7097             }
7098             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7099                 return false;
7100             }
7101             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7102                 return false;
7103             }
7104             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7105                 return false;
7106             }
7107             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7108                 return false;
7109             }
7110             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7111                 return false;
7112             }
7113             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7114                 return false;
7115             }
7116             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7117             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
7118             ext.clear();
7119             t8.getNode( "cd" ).setCollapse( true );
7120             t8.getNode( "c" ).setCollapse( true );
7121             t8.getNode( "d" ).setCollapse( true );
7122             n = t8.getNode( "a" );
7123             while ( n != null ) {
7124                 ext.add( n );
7125                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7126             }
7127             if ( ext.size() != 7 ) {
7128                 return false;
7129             }
7130             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7131                 return false;
7132             }
7133             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7134                 return false;
7135             }
7136             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7137                 System.out.println( "2 fail" );
7138                 return false;
7139             }
7140             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7141                 return false;
7142             }
7143             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7144                 return false;
7145             }
7146             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7147                 return false;
7148             }
7149             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7150                 return false;
7151             }
7152             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7153             final Phylogeny t9 = factory.create( sb9.toString(), new NHXParser() )[ 0 ];
7154             ext.clear();
7155             t9.getNode( "gh" ).setCollapse( true );
7156             n = t9.getNode( "a" );
7157             while ( n != null ) {
7158                 ext.add( n );
7159                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7160             }
7161             if ( ext.size() != 7 ) {
7162                 return false;
7163             }
7164             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7165                 return false;
7166             }
7167             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7168                 return false;
7169             }
7170             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7171                 return false;
7172             }
7173             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7174                 return false;
7175             }
7176             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7177                 return false;
7178             }
7179             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7180                 return false;
7181             }
7182             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7183                 return false;
7184             }
7185             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7186             final Phylogeny t10 = factory.create( sb10.toString(), new NHXParser() )[ 0 ];
7187             ext.clear();
7188             t10.getNode( "gh" ).setCollapse( true );
7189             t10.getNode( "g" ).setCollapse( true );
7190             t10.getNode( "h" ).setCollapse( true );
7191             n = t10.getNode( "a" );
7192             while ( n != null ) {
7193                 ext.add( n );
7194                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7195             }
7196             if ( ext.size() != 7 ) {
7197                 return false;
7198             }
7199             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7200                 return false;
7201             }
7202             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7203                 return false;
7204             }
7205             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7206                 return false;
7207             }
7208             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7209                 return false;
7210             }
7211             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7212                 return false;
7213             }
7214             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7215                 return false;
7216             }
7217             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7218                 return false;
7219             }
7220             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7221             final Phylogeny t11 = factory.create( sb11.toString(), new NHXParser() )[ 0 ];
7222             ext.clear();
7223             t11.getNode( "gh" ).setCollapse( true );
7224             t11.getNode( "fgh" ).setCollapse( true );
7225             n = t11.getNode( "a" );
7226             while ( n != null ) {
7227                 ext.add( n );
7228                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7229             }
7230             if ( ext.size() != 6 ) {
7231                 return false;
7232             }
7233             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7234                 return false;
7235             }
7236             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7237                 return false;
7238             }
7239             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7240                 return false;
7241             }
7242             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7243                 return false;
7244             }
7245             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7246                 return false;
7247             }
7248             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7249                 return false;
7250             }
7251             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7252             final Phylogeny t12 = factory.create( sb12.toString(), new NHXParser() )[ 0 ];
7253             ext.clear();
7254             t12.getNode( "gh" ).setCollapse( true );
7255             t12.getNode( "fgh" ).setCollapse( true );
7256             t12.getNode( "g" ).setCollapse( true );
7257             t12.getNode( "h" ).setCollapse( true );
7258             t12.getNode( "f" ).setCollapse( true );
7259             n = t12.getNode( "a" );
7260             while ( n != null ) {
7261                 ext.add( n );
7262                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7263             }
7264             if ( ext.size() != 6 ) {
7265                 return false;
7266             }
7267             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7268                 return false;
7269             }
7270             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7271                 return false;
7272             }
7273             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7274                 return false;
7275             }
7276             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7277                 return false;
7278             }
7279             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7280                 return false;
7281             }
7282             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7283                 return false;
7284             }
7285             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7286             final Phylogeny t13 = factory.create( sb13.toString(), new NHXParser() )[ 0 ];
7287             ext.clear();
7288             t13.getNode( "ab" ).setCollapse( true );
7289             t13.getNode( "b" ).setCollapse( true );
7290             t13.getNode( "fgh" ).setCollapse( true );
7291             t13.getNode( "gh" ).setCollapse( true );
7292             n = t13.getNode( "ab" );
7293             while ( n != null ) {
7294                 ext.add( n );
7295                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7296             }
7297             if ( ext.size() != 5 ) {
7298                 return false;
7299             }
7300             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7301                 return false;
7302             }
7303             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7304                 return false;
7305             }
7306             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7307                 return false;
7308             }
7309             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7310                 return false;
7311             }
7312             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7313                 return false;
7314             }
7315             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
7316             final Phylogeny t14 = factory.create( sb14.toString(), new NHXParser() )[ 0 ];
7317             ext.clear();
7318             t14.getNode( "ab" ).setCollapse( true );
7319             t14.getNode( "a" ).setCollapse( true );
7320             t14.getNode( "fgh" ).setCollapse( true );
7321             t14.getNode( "gh" ).setCollapse( true );
7322             n = t14.getNode( "ab" );
7323             while ( n != null ) {
7324                 ext.add( n );
7325                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7326             }
7327             if ( ext.size() != 5 ) {
7328                 return false;
7329             }
7330             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7331                 return false;
7332             }
7333             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7334                 return false;
7335             }
7336             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7337                 return false;
7338             }
7339             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7340                 return false;
7341             }
7342             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7343                 return false;
7344             }
7345             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" );
7346             final Phylogeny t15 = factory.create( sb15.toString(), new NHXParser() )[ 0 ];
7347             ext.clear();
7348             t15.getNode( "ab" ).setCollapse( true );
7349             t15.getNode( "a" ).setCollapse( true );
7350             t15.getNode( "fgh" ).setCollapse( true );
7351             t15.getNode( "gh" ).setCollapse( true );
7352             n = t15.getNode( "ab" );
7353             while ( n != null ) {
7354                 ext.add( n );
7355                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7356             }
7357             if ( ext.size() != 6 ) {
7358                 return false;
7359             }
7360             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7361                 return false;
7362             }
7363             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7364                 return false;
7365             }
7366             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7367                 return false;
7368             }
7369             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7370                 return false;
7371             }
7372             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
7373                 return false;
7374             }
7375             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7376                 return false;
7377             }
7378             //
7379             //
7380             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" );
7381             final Phylogeny t16 = factory.create( sb16.toString(), new NHXParser() )[ 0 ];
7382             ext.clear();
7383             t16.getNode( "ab" ).setCollapse( true );
7384             t16.getNode( "a" ).setCollapse( true );
7385             t16.getNode( "fgh" ).setCollapse( true );
7386             t16.getNode( "gh" ).setCollapse( true );
7387             t16.getNode( "cd" ).setCollapse( true );
7388             t16.getNode( "cde" ).setCollapse( true );
7389             t16.getNode( "d" ).setCollapse( true );
7390             t16.getNode( "x" ).setCollapse( true );
7391             n = t16.getNode( "ab" );
7392             while ( n != null ) {
7393                 ext.add( n );
7394                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7395             }
7396             if ( ext.size() != 4 ) {
7397                 return false;
7398             }
7399             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7400                 return false;
7401             }
7402             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7403                 return false;
7404             }
7405             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
7406                 return false;
7407             }
7408             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
7409                 return false;
7410             }
7411         }
7412         catch ( final Exception e ) {
7413             e.printStackTrace( System.out );
7414             return false;
7415         }
7416         return true;
7417     }
7418
7419     private static boolean testNexusCharactersParsing() {
7420         try {
7421             final NexusCharactersParser parser = new NexusCharactersParser();
7422             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
7423             parser.parse();
7424             String[] labels = parser.getCharStateLabels();
7425             if ( labels.length != 7 ) {
7426                 return false;
7427             }
7428             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7429                 return false;
7430             }
7431             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7432                 return false;
7433             }
7434             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7435                 return false;
7436             }
7437             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7438                 return false;
7439             }
7440             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7441                 return false;
7442             }
7443             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7444                 return false;
7445             }
7446             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7447                 return false;
7448             }
7449             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7450             parser.parse();
7451             labels = parser.getCharStateLabels();
7452             if ( labels.length != 7 ) {
7453                 return false;
7454             }
7455             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7456                 return false;
7457             }
7458             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7459                 return false;
7460             }
7461             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7462                 return false;
7463             }
7464             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7465                 return false;
7466             }
7467             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7468                 return false;
7469             }
7470             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7471                 return false;
7472             }
7473             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7474                 return false;
7475             }
7476         }
7477         catch ( final Exception e ) {
7478             e.printStackTrace( System.out );
7479             return false;
7480         }
7481         return true;
7482     }
7483
7484     private static boolean testNexusMatrixParsing() {
7485         try {
7486             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7487             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7488             parser.parse();
7489             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7490             if ( m.getNumberOfCharacters() != 9 ) {
7491                 return false;
7492             }
7493             if ( m.getNumberOfIdentifiers() != 5 ) {
7494                 return false;
7495             }
7496             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7497                 return false;
7498             }
7499             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7500                 return false;
7501             }
7502             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7503                 return false;
7504             }
7505             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7506                 return false;
7507             }
7508             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7509                 return false;
7510             }
7511             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7512                 return false;
7513             }
7514             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7515                 return false;
7516             }
7517             //            if ( labels.length != 7 ) {
7518             //                return false;
7519             //            }
7520             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7521             //                return false;
7522             //            }
7523             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7524             //                return false;
7525             //            }
7526             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7527             //                return false;
7528             //            }
7529             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7530             //                return false;
7531             //            }
7532             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7533             //                return false;
7534             //            }
7535             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7536             //                return false;
7537             //            }
7538             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7539             //                return false;
7540             //            }
7541             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7542             //            parser.parse();
7543             //            labels = parser.getCharStateLabels();
7544             //            if ( labels.length != 7 ) {
7545             //                return false;
7546             //            }
7547             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7548             //                return false;
7549             //            }
7550             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7551             //                return false;
7552             //            }
7553             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7554             //                return false;
7555             //            }
7556             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7557             //                return false;
7558             //            }
7559             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7560             //                return false;
7561             //            }
7562             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7563             //                return false;
7564             //            }
7565             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7566             //                return false;
7567             //            }
7568         }
7569         catch ( final Exception e ) {
7570             e.printStackTrace( System.out );
7571             return false;
7572         }
7573         return true;
7574     }
7575
7576     private static boolean testNexusTreeParsing() {
7577         try {
7578             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7579             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7580             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7581             if ( phylogenies.length != 1 ) {
7582                 return false;
7583             }
7584             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7585                 return false;
7586             }
7587             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7588                 return false;
7589             }
7590             phylogenies = null;
7591             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7592             if ( phylogenies.length != 1 ) {
7593                 return false;
7594             }
7595             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7596                 return false;
7597             }
7598             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7599                 return false;
7600             }
7601             phylogenies = null;
7602             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7603             if ( phylogenies.length != 1 ) {
7604                 return false;
7605             }
7606             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7607                 return false;
7608             }
7609             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7610                 return false;
7611             }
7612             if ( phylogenies[ 0 ].isRooted() ) {
7613                 return false;
7614             }
7615             phylogenies = null;
7616             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7617             if ( phylogenies.length != 18 ) {
7618                 return false;
7619             }
7620             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7621                 return false;
7622             }
7623             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7624                 return false;
7625             }
7626             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7627                 return false;
7628             }
7629             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7630                 return false;
7631             }
7632             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7633                 return false;
7634             }
7635             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7636                 return false;
7637             }
7638             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7639                 return false;
7640             }
7641             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7642                 return false;
7643             }
7644             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7645                 return false;
7646             }
7647             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7648                 return false;
7649             }
7650             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7651                 return false;
7652             }
7653             if ( phylogenies[ 8 ].isRooted() ) {
7654                 return false;
7655             }
7656             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7657                 return false;
7658             }
7659             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7660                 return false;
7661             }
7662             if ( !phylogenies[ 9 ].isRooted() ) {
7663                 return false;
7664             }
7665             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7666                 return false;
7667             }
7668             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7669                 return false;
7670             }
7671             if ( !phylogenies[ 10 ].isRooted() ) {
7672                 return false;
7673             }
7674             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7675                 return false;
7676             }
7677             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7678                 return false;
7679             }
7680             if ( phylogenies[ 11 ].isRooted() ) {
7681                 return false;
7682             }
7683             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7684                 return false;
7685             }
7686             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7687                 return false;
7688             }
7689             if ( !phylogenies[ 12 ].isRooted() ) {
7690                 return false;
7691             }
7692             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7693                 return false;
7694             }
7695             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7696                 return false;
7697             }
7698             if ( !phylogenies[ 13 ].isRooted() ) {
7699                 return false;
7700             }
7701             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7702                 return false;
7703             }
7704             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7705                 return false;
7706             }
7707             if ( !phylogenies[ 14 ].isRooted() ) {
7708                 return false;
7709             }
7710             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7711                 return false;
7712             }
7713             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7714                 return false;
7715             }
7716             if ( phylogenies[ 15 ].isRooted() ) {
7717                 return false;
7718             }
7719             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7720                 return false;
7721             }
7722             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7723                 return false;
7724             }
7725             if ( !phylogenies[ 16 ].isRooted() ) {
7726                 return false;
7727             }
7728             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7729                 return false;
7730             }
7731             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7732                 return false;
7733             }
7734             if ( phylogenies[ 17 ].isRooted() ) {
7735                 return false;
7736             }
7737             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7738                 return false;
7739             }
7740             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7741             phylogenies = null;
7742             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7743             if ( phylogenies.length != 9 ) {
7744                 return false;
7745             }
7746             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7747                            .getDistanceToParent() ) ) {
7748                 return false;
7749             }
7750             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7751                            .getDistanceToParent() ) ) {
7752                 return false;
7753             }
7754             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7755                 return false;
7756             }
7757             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7758                 return false;
7759             }
7760             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7761                 return false;
7762             }
7763             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7764                 return false;
7765             }
7766             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7767                 return false;
7768             }
7769         }
7770         catch ( final Exception e ) {
7771             e.printStackTrace( System.out );
7772             return false;
7773         }
7774         return true;
7775     }
7776
7777     private static boolean testNexusTreeParsingIterating() {
7778         try {
7779             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7780             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7781             if ( !p.hasNext() ) {
7782                 return false;
7783             }
7784             Phylogeny phy = p.next();
7785             if ( phy == null ) {
7786                 return false;
7787             }
7788             if ( phy.getNumberOfExternalNodes() != 25 ) {
7789                 return false;
7790             }
7791             if ( !phy.getName().equals( "" ) ) {
7792                 return false;
7793             }
7794             if ( p.hasNext() ) {
7795                 return false;
7796             }
7797             phy = p.next();
7798             if ( phy != null ) {
7799                 return false;
7800             }
7801             p.reset();
7802             if ( !p.hasNext() ) {
7803                 return false;
7804             }
7805             phy = p.next();
7806             if ( phy == null ) {
7807                 return false;
7808             }
7809             if ( phy.getNumberOfExternalNodes() != 25 ) {
7810                 return false;
7811             }
7812             if ( !phy.getName().equals( "" ) ) {
7813                 return false;
7814             }
7815             if ( p.hasNext() ) {
7816                 return false;
7817             }
7818             phy = p.next();
7819             if ( phy != null ) {
7820                 return false;
7821             }
7822             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7823             if ( !p.hasNext() ) {
7824                 return false;
7825             }
7826             phy = p.next();
7827             if ( phy == null ) {
7828                 return false;
7829             }
7830             if ( phy.getNumberOfExternalNodes() != 10 ) {
7831                 return false;
7832             }
7833             if ( !phy.getName().equals( "name" ) ) {
7834                 return false;
7835             }
7836             if ( p.hasNext() ) {
7837                 return false;
7838             }
7839             phy = p.next();
7840             if ( phy != null ) {
7841                 return false;
7842             }
7843             p.reset();
7844             if ( !p.hasNext() ) {
7845                 return false;
7846             }
7847             phy = p.next();
7848             if ( phy == null ) {
7849                 return false;
7850             }
7851             if ( phy.getNumberOfExternalNodes() != 10 ) {
7852                 return false;
7853             }
7854             if ( !phy.getName().equals( "name" ) ) {
7855                 return false;
7856             }
7857             if ( p.hasNext() ) {
7858                 return false;
7859             }
7860             phy = p.next();
7861             if ( phy != null ) {
7862                 return false;
7863             }
7864             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7865             if ( !p.hasNext() ) {
7866                 return false;
7867             }
7868             phy = p.next();
7869             if ( phy == null ) {
7870                 return false;
7871             }
7872             if ( phy.getNumberOfExternalNodes() != 3 ) {
7873                 return false;
7874             }
7875             if ( !phy.getName().equals( "" ) ) {
7876                 return false;
7877             }
7878             if ( phy.isRooted() ) {
7879                 return false;
7880             }
7881             if ( p.hasNext() ) {
7882                 return false;
7883             }
7884             phy = p.next();
7885             if ( phy != null ) {
7886                 return false;
7887             }
7888             //
7889             p.reset();
7890             if ( !p.hasNext() ) {
7891                 return false;
7892             }
7893             phy = p.next();
7894             if ( phy == null ) {
7895                 return false;
7896             }
7897             if ( phy.getNumberOfExternalNodes() != 3 ) {
7898                 return false;
7899             }
7900             if ( !phy.getName().equals( "" ) ) {
7901                 return false;
7902             }
7903             if ( p.hasNext() ) {
7904                 return false;
7905             }
7906             phy = p.next();
7907             if ( phy != null ) {
7908                 return false;
7909             }
7910             //
7911             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7912             if ( !p.hasNext() ) {
7913                 return false;
7914             }
7915             //0
7916             phy = p.next();
7917             if ( phy == null ) {
7918                 return false;
7919             }
7920             if ( phy.getNumberOfExternalNodes() != 10 ) {
7921                 return false;
7922             }
7923             if ( !phy.getName().equals( "tree 0" ) ) {
7924                 return false;
7925             }
7926             //1
7927             if ( !p.hasNext() ) {
7928                 return false;
7929             }
7930             phy = p.next();
7931             if ( phy == null ) {
7932                 return false;
7933             }
7934             if ( phy.getNumberOfExternalNodes() != 10 ) {
7935                 return false;
7936             }
7937             if ( !phy.getName().equals( "tree 1" ) ) {
7938                 return false;
7939             }
7940             //2
7941             if ( !p.hasNext() ) {
7942                 return false;
7943             }
7944             phy = p.next();
7945             if ( phy == null ) {
7946                 return false;
7947             }
7948             if ( phy.getNumberOfExternalNodes() != 3 ) {
7949                 System.out.println( phy.toString() );
7950                 return false;
7951             }
7952             if ( !phy.getName().equals( "" ) ) {
7953                 return false;
7954             }
7955             if ( phy.isRooted() ) {
7956                 return false;
7957             }
7958             //3
7959             if ( !p.hasNext() ) {
7960                 return false;
7961             }
7962             phy = p.next();
7963             if ( phy == null ) {
7964                 return false;
7965             }
7966             if ( phy.getNumberOfExternalNodes() != 4 ) {
7967                 return false;
7968             }
7969             if ( !phy.getName().equals( "" ) ) {
7970                 return false;
7971             }
7972             if ( !phy.isRooted() ) {
7973                 return false;
7974             }
7975             //4
7976             if ( !p.hasNext() ) {
7977                 return false;
7978             }
7979             phy = p.next();
7980             if ( phy == null ) {
7981                 return false;
7982             }
7983             if ( phy.getNumberOfExternalNodes() != 5 ) {
7984                 System.out.println( phy.getNumberOfExternalNodes() );
7985                 return false;
7986             }
7987             if ( !phy.getName().equals( "" ) ) {
7988                 return false;
7989             }
7990             if ( !phy.isRooted() ) {
7991                 return false;
7992             }
7993             //5
7994             if ( !p.hasNext() ) {
7995                 return false;
7996             }
7997             phy = p.next();
7998             if ( phy == null ) {
7999                 return false;
8000             }
8001             if ( phy.getNumberOfExternalNodes() != 3 ) {
8002                 return false;
8003             }
8004             if ( !phy.getName().equals( "" ) ) {
8005                 return false;
8006             }
8007             if ( phy.isRooted() ) {
8008                 return false;
8009             }
8010             //6
8011             if ( !p.hasNext() ) {
8012                 return false;
8013             }
8014             phy = p.next();
8015             if ( phy == null ) {
8016                 return false;
8017             }
8018             if ( phy.getNumberOfExternalNodes() != 2 ) {
8019                 return false;
8020             }
8021             if ( !phy.getName().equals( "" ) ) {
8022                 return false;
8023             }
8024             if ( !phy.isRooted() ) {
8025                 return false;
8026             }
8027             //7
8028             if ( !p.hasNext() ) {
8029                 return false;
8030             }
8031             phy = p.next();
8032             if ( phy.getNumberOfExternalNodes() != 3 ) {
8033                 return false;
8034             }
8035             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8036                 return false;
8037             }
8038             if ( !phy.isRooted() ) {
8039                 return false;
8040             }
8041             //8
8042             if ( !p.hasNext() ) {
8043                 return false;
8044             }
8045             phy = p.next();
8046             if ( phy.getNumberOfExternalNodes() != 3 ) {
8047                 return false;
8048             }
8049             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
8050                 return false;
8051             }
8052             if ( !phy.getName().equals( "tree 8" ) ) {
8053                 return false;
8054             }
8055             //9
8056             if ( !p.hasNext() ) {
8057                 return false;
8058             }
8059             phy = p.next();
8060             if ( phy.getNumberOfExternalNodes() != 3 ) {
8061                 return false;
8062             }
8063             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
8064                 return false;
8065             }
8066             if ( !phy.getName().equals( "tree 9" ) ) {
8067                 return false;
8068             }
8069             //10
8070             if ( !p.hasNext() ) {
8071                 return false;
8072             }
8073             phy = p.next();
8074             if ( phy.getNumberOfExternalNodes() != 3 ) {
8075                 return false;
8076             }
8077             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8078                 return false;
8079             }
8080             if ( !phy.getName().equals( "tree 10" ) ) {
8081                 return false;
8082             }
8083             if ( !phy.isRooted() ) {
8084                 return false;
8085             }
8086             //11
8087             if ( !p.hasNext() ) {
8088                 return false;
8089             }
8090             phy = p.next();
8091             if ( phy.getNumberOfExternalNodes() != 3 ) {
8092                 return false;
8093             }
8094             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
8095                 return false;
8096             }
8097             if ( !phy.getName().equals( "tree 11" ) ) {
8098                 return false;
8099             }
8100             if ( phy.isRooted() ) {
8101                 return false;
8102             }
8103             //12
8104             if ( !p.hasNext() ) {
8105                 return false;
8106             }
8107             phy = p.next();
8108             if ( phy.getNumberOfExternalNodes() != 3 ) {
8109                 return false;
8110             }
8111             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
8112                 return false;
8113             }
8114             if ( !phy.getName().equals( "tree 12" ) ) {
8115                 return false;
8116             }
8117             if ( !phy.isRooted() ) {
8118                 return false;
8119             }
8120             //13
8121             if ( !p.hasNext() ) {
8122                 return false;
8123             }
8124             phy = p.next();
8125             if ( phy.getNumberOfExternalNodes() != 3 ) {
8126                 return false;
8127             }
8128             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8129                 return false;
8130             }
8131             if ( !phy.getName().equals( "tree 13" ) ) {
8132                 return false;
8133             }
8134             if ( !phy.isRooted() ) {
8135                 return false;
8136             }
8137             //14
8138             if ( !p.hasNext() ) {
8139                 return false;
8140             }
8141             phy = p.next();
8142             if ( phy.getNumberOfExternalNodes() != 10 ) {
8143                 System.out.println( phy.getNumberOfExternalNodes() );
8144                 return false;
8145             }
8146             if ( !phy
8147                     .toNewHampshire()
8148                     .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;" ) ) {
8149                 System.out.println( phy.toNewHampshire() );
8150                 return false;
8151             }
8152             if ( !phy.getName().equals( "tree 14" ) ) {
8153                 return false;
8154             }
8155             if ( !phy.isRooted() ) {
8156                 return false;
8157             }
8158             //15
8159             if ( !p.hasNext() ) {
8160                 return false;
8161             }
8162             phy = p.next();
8163             if ( phy.getNumberOfExternalNodes() != 10 ) {
8164                 System.out.println( phy.getNumberOfExternalNodes() );
8165                 return false;
8166             }
8167             if ( !phy
8168                     .toNewHampshire()
8169                     .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;" ) ) {
8170                 System.out.println( phy.toNewHampshire() );
8171                 return false;
8172             }
8173             if ( !phy.getName().equals( "tree 15" ) ) {
8174                 return false;
8175             }
8176             if ( phy.isRooted() ) {
8177                 return false;
8178             }
8179             //16
8180             if ( !p.hasNext() ) {
8181                 return false;
8182             }
8183             phy = p.next();
8184             if ( phy.getNumberOfExternalNodes() != 10 ) {
8185                 System.out.println( phy.getNumberOfExternalNodes() );
8186                 return false;
8187             }
8188             if ( !phy
8189                     .toNewHampshire()
8190                     .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;" ) ) {
8191                 System.out.println( phy.toNewHampshire() );
8192                 return false;
8193             }
8194             if ( !phy.getName().equals( "tree 16" ) ) {
8195                 return false;
8196             }
8197             if ( !phy.isRooted() ) {
8198                 return false;
8199             }
8200             //17
8201             if ( !p.hasNext() ) {
8202                 return false;
8203             }
8204             phy = p.next();
8205             if ( phy.getNumberOfExternalNodes() != 10 ) {
8206                 System.out.println( phy.getNumberOfExternalNodes() );
8207                 return false;
8208             }
8209             if ( !phy
8210                     .toNewHampshire()
8211                     .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;" ) ) {
8212                 System.out.println( phy.toNewHampshire() );
8213                 return false;
8214             }
8215             if ( !phy.getName().equals( "tree 17" ) ) {
8216                 return false;
8217             }
8218             if ( phy.isRooted() ) {
8219                 return false;
8220             }
8221             //
8222             if ( p.hasNext() ) {
8223                 return false;
8224             }
8225             phy = p.next();
8226             if ( phy != null ) {
8227                 return false;
8228             }
8229             p.reset();
8230             //0
8231             if ( !p.hasNext() ) {
8232                 return false;
8233             }
8234             phy = p.next();
8235             if ( phy == null ) {
8236                 return false;
8237             }
8238             if ( phy.getNumberOfExternalNodes() != 10 ) {
8239                 return false;
8240             }
8241             if ( !phy.getName().equals( "tree 0" ) ) {
8242                 return false;
8243             }
8244             //1
8245             if ( !p.hasNext() ) {
8246                 return false;
8247             }
8248             phy = p.next();
8249             if ( phy == null ) {
8250                 return false;
8251             }
8252             if ( phy.getNumberOfExternalNodes() != 10 ) {
8253                 return false;
8254             }
8255             if ( !phy.getName().equals( "tree 1" ) ) {
8256                 return false;
8257             }
8258             //2
8259             if ( !p.hasNext() ) {
8260                 return false;
8261             }
8262             phy = p.next();
8263             if ( phy == null ) {
8264                 return false;
8265             }
8266             if ( phy.getNumberOfExternalNodes() != 3 ) {
8267                 return false;
8268             }
8269             if ( !phy.getName().equals( "" ) ) {
8270                 return false;
8271             }
8272             if ( phy.isRooted() ) {
8273                 return false;
8274             }
8275             //3
8276             if ( !p.hasNext() ) {
8277                 return false;
8278             }
8279             phy = p.next();
8280             if ( phy == null ) {
8281                 return false;
8282             }
8283             if ( phy.getNumberOfExternalNodes() != 4 ) {
8284                 return false;
8285             }
8286             if ( !phy.getName().equals( "" ) ) {
8287                 return false;
8288             }
8289             if ( !phy.isRooted() ) {
8290                 return false;
8291             }
8292             //4
8293             if ( !p.hasNext() ) {
8294                 return false;
8295             }
8296             phy = p.next();
8297             if ( phy == null ) {
8298                 return false;
8299             }
8300             if ( phy.getNumberOfExternalNodes() != 5 ) {
8301                 System.out.println( phy.getNumberOfExternalNodes() );
8302                 return false;
8303             }
8304             if ( !phy.getName().equals( "" ) ) {
8305                 return false;
8306             }
8307             if ( !phy.isRooted() ) {
8308                 return false;
8309             }
8310             //5
8311             if ( !p.hasNext() ) {
8312                 return false;
8313             }
8314             phy = p.next();
8315             if ( phy == null ) {
8316                 return false;
8317             }
8318             if ( phy.getNumberOfExternalNodes() != 3 ) {
8319                 return false;
8320             }
8321             if ( !phy.getName().equals( "" ) ) {
8322                 return false;
8323             }
8324             if ( phy.isRooted() ) {
8325                 return false;
8326             }
8327             //
8328             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
8329             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
8330             // 0
8331             if ( !p2.hasNext() ) {
8332                 return false;
8333             }
8334             phy = p2.next();
8335             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8336                 return false;
8337             }
8338             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8339                 return false;
8340             }
8341             // 1
8342             if ( !p2.hasNext() ) {
8343                 return false;
8344             }
8345             phy = p2.next();
8346             // 2
8347             if ( !p2.hasNext() ) {
8348                 return false;
8349             }
8350             phy = p2.next();
8351             // 3
8352             if ( !p2.hasNext() ) {
8353                 return false;
8354             }
8355             phy = p2.next();
8356             // 4
8357             if ( !p2.hasNext() ) {
8358                 return false;
8359             }
8360             phy = p2.next();
8361             // 5
8362             if ( !p2.hasNext() ) {
8363                 return false;
8364             }
8365             phy = p2.next();
8366             // 6
8367             if ( !p2.hasNext() ) {
8368                 return false;
8369             }
8370             phy = p2.next();
8371             // 7
8372             if ( !p2.hasNext() ) {
8373                 return false;
8374             }
8375             phy = p2.next();
8376             // 8
8377             if ( !p2.hasNext() ) {
8378                 return false;
8379             }
8380             phy = p2.next();
8381             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
8382                 return false;
8383             }
8384             if ( p2.hasNext() ) {
8385                 return false;
8386             }
8387             phy = p2.next();
8388             if ( phy != null ) {
8389                 return false;
8390             }
8391             // 0
8392             p2.reset();
8393             if ( !p2.hasNext() ) {
8394                 return false;
8395             }
8396             phy = p2.next();
8397             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8398                 return false;
8399             }
8400             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8401                 return false;
8402             }
8403         }
8404         catch ( final Exception e ) {
8405             e.printStackTrace( System.out );
8406             return false;
8407         }
8408         return true;
8409     }
8410
8411     private static boolean testNexusTreeParsingTranslating() {
8412         try {
8413             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8414             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
8415             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
8416             if ( phylogenies.length != 1 ) {
8417                 return false;
8418             }
8419             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8420                 return false;
8421             }
8422             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8423                 return false;
8424             }
8425             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8426                 return false;
8427             }
8428             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8429                 return false;
8430             }
8431             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8432                     .equals( "Aranaeus" ) ) {
8433                 return false;
8434             }
8435             phylogenies = null;
8436             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
8437             if ( phylogenies.length != 3 ) {
8438                 return false;
8439             }
8440             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8441                 return false;
8442             }
8443             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8444                 return false;
8445             }
8446             if ( phylogenies[ 0 ].isRooted() ) {
8447                 return false;
8448             }
8449             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8450                 return false;
8451             }
8452             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8453                 return false;
8454             }
8455             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8456                     .equals( "Aranaeus" ) ) {
8457                 return false;
8458             }
8459             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8460                 return false;
8461             }
8462             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8463                 return false;
8464             }
8465             if ( phylogenies[ 1 ].isRooted() ) {
8466                 return false;
8467             }
8468             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8469                 return false;
8470             }
8471             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8472                 return false;
8473             }
8474             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8475                     .equals( "Aranaeus" ) ) {
8476                 return false;
8477             }
8478             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8479                 return false;
8480             }
8481             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8482                 return false;
8483             }
8484             if ( !phylogenies[ 2 ].isRooted() ) {
8485                 return false;
8486             }
8487             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8488                 return false;
8489             }
8490             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8491                 return false;
8492             }
8493             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8494                     .equals( "Aranaeus" ) ) {
8495                 return false;
8496             }
8497             phylogenies = null;
8498             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8499             if ( phylogenies.length != 3 ) {
8500                 return false;
8501             }
8502             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8503                 return false;
8504             }
8505             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8506                 return false;
8507             }
8508             if ( phylogenies[ 0 ].isRooted() ) {
8509                 return false;
8510             }
8511             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8512                 return false;
8513             }
8514             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8515                 return false;
8516             }
8517             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8518                     .equals( "Aranaeus" ) ) {
8519                 return false;
8520             }
8521             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8522                 return false;
8523             }
8524             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8525                 return false;
8526             }
8527             if ( phylogenies[ 1 ].isRooted() ) {
8528                 return false;
8529             }
8530             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8531                 return false;
8532             }
8533             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8534                 return false;
8535             }
8536             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8537                     .equals( "Aranaeus" ) ) {
8538                 return false;
8539             }
8540             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8541                 return false;
8542             }
8543             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8544                 return false;
8545             }
8546             if ( !phylogenies[ 2 ].isRooted() ) {
8547                 return false;
8548             }
8549             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8550                 return false;
8551             }
8552             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8553                 return false;
8554             }
8555             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8556                     .equals( "Aranaeus" ) ) {
8557                 return false;
8558             }
8559             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8560             if ( phylogenies.length != 3 ) {
8561                 return false;
8562             }
8563             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8564                            0.00100049 ) ) {
8565                 return false;
8566             }
8567         }
8568         catch ( final Exception e ) {
8569             e.printStackTrace( System.out );
8570             return false;
8571         }
8572         return true;
8573     }
8574
8575     private static boolean testNHParsing() {
8576         try {
8577             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8578             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8579             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8580                 return false;
8581             }
8582             final NHXParser nhxp = new NHXParser();
8583             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8584             nhxp.setReplaceUnderscores( true );
8585             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8586             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8587                 return false;
8588             }
8589             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8590                 return false;
8591             }
8592             final Phylogeny p1b = factory
8593                     .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 ",
8594                              new NHXParser() )[ 0 ];
8595             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8596                 return false;
8597             }
8598             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8599                 return false;
8600             }
8601             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ).toString(), new NHXParser() )[ 0 ];
8602             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8603             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8604             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ).toString(), new NHXParser() )[ 0 ];
8605             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8606             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8607             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8608             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8609             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8610             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8611             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8612                     + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8613                     + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8614                     new NHXParser() );
8615             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8616                 return false;
8617             }
8618             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8619                 return false;
8620             }
8621             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8622                 return false;
8623             }
8624             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8625                 return false;
8626             }
8627             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8628             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8629             final String p16_S = "((A,B),C)";
8630             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8631             if ( p16.length != 1 ) {
8632                 return false;
8633             }
8634             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8635                 return false;
8636             }
8637             final String p17_S = "(C,(A,B))";
8638             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8639             if ( p17.length != 1 ) {
8640                 return false;
8641             }
8642             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8643                 return false;
8644             }
8645             final String p18_S = "((A,B),(C,D))";
8646             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8647             if ( p18.length != 1 ) {
8648                 return false;
8649             }
8650             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8651                 return false;
8652             }
8653             final String p19_S = "(((A,B),C),D)";
8654             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8655             if ( p19.length != 1 ) {
8656                 return false;
8657             }
8658             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8659                 return false;
8660             }
8661             final String p20_S = "(A,(B,(C,D)))";
8662             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8663             if ( p20.length != 1 ) {
8664                 return false;
8665             }
8666             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8667                 return false;
8668             }
8669             final String p21_S = "(A,(B,(C,(D,E))))";
8670             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8671             if ( p21.length != 1 ) {
8672                 return false;
8673             }
8674             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8675                 return false;
8676             }
8677             final String p22_S = "((((A,B),C),D),E)";
8678             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8679             if ( p22.length != 1 ) {
8680                 return false;
8681             }
8682             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8683                 return false;
8684             }
8685             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8686             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8687             if ( p23.length != 1 ) {
8688                 System.out.println( "xl=" + p23.length );
8689                 System.exit( -1 );
8690                 return false;
8691             }
8692             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8693                 return false;
8694             }
8695             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8696             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8697             if ( p24.length != 1 ) {
8698                 return false;
8699             }
8700             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8701                 return false;
8702             }
8703             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8704             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8705             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8706             if ( p241.length != 2 ) {
8707                 return false;
8708             }
8709             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8710                 return false;
8711             }
8712             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8713                 return false;
8714             }
8715             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8716                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8717                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8718                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8719                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8720                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8721                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8722                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8723             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8724             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8725                 return false;
8726             }
8727             final String p26_S = "(A,B)ab";
8728             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8729             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8730                 return false;
8731             }
8732             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8733             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8734             if ( p27s.length != 1 ) {
8735                 System.out.println( "xxl=" + p27s.length );
8736                 System.exit( -1 );
8737                 return false;
8738             }
8739             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8740                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8741                 System.exit( -1 );
8742                 return false;
8743             }
8744             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8745                                                     new NHXParser() );
8746             if ( p27.length != 1 ) {
8747                 System.out.println( "yl=" + p27.length );
8748                 System.exit( -1 );
8749                 return false;
8750             }
8751             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8752                 System.out.println( p27[ 0 ].toNewHampshireX() );
8753                 System.exit( -1 );
8754                 return false;
8755             }
8756             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8757             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8758             final String p28_S3 = "(A,B)ab";
8759             final String p28_S4 = "((((A,B),C),D),;E;)";
8760             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8761                                                     new NHXParser() );
8762             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8763                 return false;
8764             }
8765             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8766                 return false;
8767             }
8768             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8769                 return false;
8770             }
8771             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8772                 return false;
8773             }
8774             if ( p28.length != 4 ) {
8775                 return false;
8776             }
8777             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";
8778             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8779             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8780                 return false;
8781             }
8782             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";
8783             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8784             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8785                 return false;
8786             }
8787             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8788             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8789             if ( ( p32.length != 0 ) ) {
8790                 return false;
8791             }
8792             final String p33_S = "A";
8793             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8794             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8795                 return false;
8796             }
8797             final String p34_S = "B;";
8798             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8799             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8800                 return false;
8801             }
8802             final String p35_S = "B:0.2";
8803             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8804             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8805                 return false;
8806             }
8807             final String p36_S = "(A)";
8808             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8809             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8810                 return false;
8811             }
8812             final String p37_S = "((A))";
8813             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8814             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8815                 return false;
8816             }
8817             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8818             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8819             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8820                 return false;
8821             }
8822             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8823             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8824             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8825                 return false;
8826             }
8827             final String p40_S = "(A,B,C)";
8828             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8829             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8830                 return false;
8831             }
8832             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8833             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8834             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8835                 return false;
8836             }
8837             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8838             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8839             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8840                 return false;
8841             }
8842             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)";
8843             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8844             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8845                 return false;
8846             }
8847             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)))";
8848             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8849             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8850                 return false;
8851             }
8852             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8853             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8854             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8855                 return false;
8856             }
8857             final String p46_S = "";
8858             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8859             if ( p46.length != 0 ) {
8860                 return false;
8861             }
8862             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ).toString(), new NHXParser() )[ 0 ];
8863             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8864                 return false;
8865             }
8866             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8867             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8868                 return false;
8869             }
8870             final Phylogeny p49 = factory
8871                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ).toString(),
8872                              new NHXParser() )[ 0 ];
8873             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8874                 return false;
8875             }
8876             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8877             if ( p50.getNode( "A" ) == null ) {
8878                 return false;
8879             }
8880             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8881                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8882                 return false;
8883             }
8884             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8885                 return false;
8886             }
8887             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8888                     .equals( "((A,B)88:2.0,C);" ) ) {
8889                 return false;
8890             }
8891             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8892             if ( p51.getNode( "A(A" ) == null ) {
8893                 return false;
8894             }
8895             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8896             if ( p52.getNode( "A(A" ) == null ) {
8897                 return false;
8898             }
8899             final Phylogeny p53 = factory
8900                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ).toString(),
8901                              new NHXParser() )[ 0 ];
8902             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8903                 return false;
8904             }
8905             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ).toString(), new NHXParser() )[ 0 ];
8906             if ( p54.getNode( "A" ) == null ) {
8907                 return false;
8908             }
8909             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8910                 return false;
8911             }
8912             final Phylogeny p55 = factory
8913                     .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);" ).toString(),
8914                              new NHXParser() )[ 0 ];
8915             if ( !p55
8916                     .toNewHampshire()
8917                     .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);" ) ) {
8918                 System.out.println( p55.toNewHampshire() );
8919                 return false;
8920             }
8921             final Phylogeny p56 = factory
8922                     .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);" ).toString(),
8923                              new NHXParser() )[ 0 ];
8924             if ( !p56
8925                     .toNewHampshire()
8926                     .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);" ) ) {
8927                 System.out.println( p56.toNewHampshire() );
8928                 return false;
8929             }
8930             final Phylogeny p57 = factory
8931                     .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);" ).toString(),
8932                              new NHXParser() )[ 0 ];
8933             if ( !p57
8934                     .toNewHampshire()
8935                     .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);" ) ) {
8936                 System.out.println( p56.toNewHampshire() );
8937                 return false;
8938             }
8939             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8940             final Phylogeny p58 = factory.create( s58, new NHXParser() )[ 0 ];
8941             if ( !p58.toNewHampshire().equals( s58 ) ) {
8942                 System.out.println( p58.toNewHampshire() );
8943                 return false;
8944             }
8945             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8946             final Phylogeny p59 = factory.create( s59 , new NHXParser() )[ 0 ];
8947             if ( !p59.toNewHampshire().equals( s59 ) ) {
8948                 System.out.println( p59.toNewHampshire() );
8949                 return false;
8950             }
8951             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8952             final Phylogeny p60 = factory.create( s60, new NHXParser() )[ 0 ];
8953             if ( !p60.toNewHampshire().equals( s60 ) ) {
8954                 System.out.println( p60.toNewHampshire() );
8955                 return false;
8956             }
8957             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8958             final Phylogeny p61 = factory.create( s61, new NHXParser() )[ 0 ];
8959             if ( !p61.toNewHampshire()
8960                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8961                 System.out.println( p61.toNewHampshire() );
8962                 return false;
8963             }
8964             final String s62 = "(1[&type=\"X\",size=123,subtree=(1,2);]:0.003,2[&type=\"(X,Y:3)\"]:0.004)[&type=\"(X,Y)\"]:0.0;";
8965             final Phylogeny p62 = factory.create( s62, new NHXParser() )[ 0 ];
8966             if ( !p62.toNewHampshire()
8967                     .equals( "(1:0.003,2:0.004):0.0;" ) ) {
8968                 System.out.println( p62.toNewHampshire() );
8969                 return false;
8970             }
8971             final String s63 = "(1:0.003[&type=\"X\",size=123,subtree=(1,2);],2:0.004[&type=\"(X,Y:3)\"]):0.0[&type=\"(X,Y)\"];";
8972             final Phylogeny p63 = factory.create( s63, new NHXParser() )[ 0 ];
8973             if ( !p63.toNewHampshire()
8974                     .equals( "(1:0.003,2:0.004):0.0;" ) ) {
8975                 System.out.println( p63.toNewHampshire() );
8976                 return false;
8977             }
8978             final String s64 = "((1,2):[95.5],3);";
8979             final Phylogeny p64 = factory.create( s64, new NHXParser() )[ 0 ];
8980             if ( !p64.toNewHampshireX()
8981                     .equals( "((1,2)[&&NHX:B=95.5],3)" ) ) {
8982                 System.out.println( p64.toNewHampshireX() );
8983                 return false;
8984             }
8985             final String s65 = "((1:0.1,2:0.2):0.3[10.2],3);";
8986             final Phylogeny p65 = factory.create( s65, new NHXParser() )[ 0 ];
8987             if ( !p65.toNewHampshireX()
8988                     .equals( "((1:0.1,2:0.2):0.3[&&NHX:B=10.2],3)" ) ) {
8989                 System.out.println( p65.toNewHampshireX() );
8990                 return false;
8991             }
8992         }
8993         catch ( final Exception e ) {
8994             e.printStackTrace( System.out );
8995             return false;
8996         }
8997         return true;
8998     }
8999     
9000     private static boolean testNHParsingSpecialChars() {
9001         try {
9002             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();   
9003             final String i0 = "(A!+=~QWERTY!@#$%^&*-,€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ)";
9004             final Phylogeny p0 = factory.create( i0, new NHXParser() )[ 0 ];
9005             if ( !p0.toNewHampshireX().equals( i0 ) ) {
9006                 System.out.println();
9007                 System.out.println( p0.toNewHampshireX() );
9008                 System.out.println( i0 );
9009                 return false;
9010             }
9011             final String i1 = "(हिंदी,한글,ไทย,'Tiếng Việt',ひらがなカタカナ漢字,繁體字,русский)";
9012             final Phylogeny p1 = factory.create( i1, new NHXParser() )[ 0 ];
9013             if ( !p1.toNewHampshireX().equals( i1 ) ) {
9014                 System.out.println();
9015                 System.out.println( p1.toNewHampshireX() );
9016                 System.out.println( i1 );
9017                 return false;
9018             }
9019         }
9020         catch ( final Exception e ) {
9021             e.printStackTrace( System.out );
9022             return false;
9023         }
9024         return true;
9025     }
9026     
9027     
9028     
9029     private static boolean testNHParsingIter() {
9030         try {
9031             final String p0_str = "(A,B);";
9032             final NHXParser p = new NHXParser();
9033             p.setSource( p0_str );
9034             if ( !p.hasNext() ) {
9035                 return false;
9036             }
9037             final Phylogeny p0 = p.next();
9038             if ( !p0.toNewHampshire().equals( p0_str ) ) {
9039                 System.out.println( p0.toNewHampshire() );
9040                 return false;
9041             }
9042             if ( p.hasNext() ) {
9043                 return false;
9044             }
9045             if ( p.next() != null ) {
9046                 return false;
9047             }
9048             //
9049             final String p00_str = "(A,B)root;";
9050             p.setSource( p00_str );
9051             final Phylogeny p00 = p.next();
9052             if ( !p00.toNewHampshire().equals( p00_str ) ) {
9053                 System.out.println( p00.toNewHampshire() );
9054                 return false;
9055             }
9056             //
9057             final String p000_str = "A;";
9058             p.setSource( p000_str );
9059             final Phylogeny p000 = p.next();
9060             if ( !p000.toNewHampshire().equals( p000_str ) ) {
9061                 System.out.println( p000.toNewHampshire() );
9062                 return false;
9063             }
9064             //
9065             final String p0000_str = "A";
9066             p.setSource( p0000_str );
9067             final Phylogeny p0000 = p.next();
9068             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
9069                 System.out.println( p0000.toNewHampshire() );
9070                 return false;
9071             }
9072             //
9073             p.setSource( "(A)" );
9074             final Phylogeny p00000 = p.next();
9075             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
9076                 System.out.println( p00000.toNewHampshire() );
9077                 return false;
9078             }
9079             //
9080             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
9081             p.setSource( p1_str );
9082             if ( !p.hasNext() ) {
9083                 return false;
9084             }
9085             final Phylogeny p1_0 = p.next();
9086             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
9087                 System.out.println( p1_0.toNewHampshire() );
9088                 return false;
9089             }
9090             if ( !p.hasNext() ) {
9091                 return false;
9092             }
9093             final Phylogeny p1_1 = p.next();
9094             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
9095                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
9096                 return false;
9097             }
9098             if ( !p.hasNext() ) {
9099                 return false;
9100             }
9101             final Phylogeny p1_2 = p.next();
9102             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
9103                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
9104                 return false;
9105             }
9106             if ( !p.hasNext() ) {
9107                 return false;
9108             }
9109             final Phylogeny p1_3 = p.next();
9110             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
9111                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
9112                 return false;
9113             }
9114             if ( p.hasNext() ) {
9115                 return false;
9116             }
9117             if ( p.next() != null ) {
9118                 return false;
9119             }
9120             //
9121             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
9122             p.setSource( p2_str );
9123             if ( !p.hasNext() ) {
9124                 return false;
9125             }
9126             Phylogeny p2_0 = p.next();
9127             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9128                 System.out.println( p2_0.toNewHampshire() );
9129                 return false;
9130             }
9131             if ( !p.hasNext() ) {
9132                 return false;
9133             }
9134             Phylogeny p2_1 = p.next();
9135             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9136                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9137                 return false;
9138             }
9139             if ( !p.hasNext() ) {
9140                 return false;
9141             }
9142             Phylogeny p2_2 = p.next();
9143             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9144                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9145                 return false;
9146             }
9147             if ( !p.hasNext() ) {
9148                 return false;
9149             }
9150             Phylogeny p2_3 = p.next();
9151             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9152                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9153                 return false;
9154             }
9155             if ( !p.hasNext() ) {
9156                 return false;
9157             }
9158             Phylogeny p2_4 = p.next();
9159             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9160                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9161                 return false;
9162             }
9163             if ( p.hasNext() ) {
9164                 return false;
9165             }
9166             if ( p.next() != null ) {
9167                 return false;
9168             }
9169             ////
9170             p.reset();
9171             if ( !p.hasNext() ) {
9172                 return false;
9173             }
9174             p2_0 = p.next();
9175             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9176                 System.out.println( p2_0.toNewHampshire() );
9177                 return false;
9178             }
9179             if ( !p.hasNext() ) {
9180                 return false;
9181             }
9182             p2_1 = p.next();
9183             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9184                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9185                 return false;
9186             }
9187             if ( !p.hasNext() ) {
9188                 return false;
9189             }
9190             p2_2 = p.next();
9191             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9192                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9193                 return false;
9194             }
9195             if ( !p.hasNext() ) {
9196                 return false;
9197             }
9198             p2_3 = p.next();
9199             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9200                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9201                 return false;
9202             }
9203             if ( !p.hasNext() ) {
9204                 return false;
9205             }
9206             p2_4 = p.next();
9207             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9208                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9209                 return false;
9210             }
9211             if ( p.hasNext() ) {
9212                 return false;
9213             }
9214             if ( p.next() != null ) {
9215                 return false;
9216             }
9217             //
9218             final String p3_str = "((A,B),C)abc";
9219             p.setSource( p3_str );
9220             if ( !p.hasNext() ) {
9221                 return false;
9222             }
9223             final Phylogeny p3_0 = p.next();
9224             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
9225                 return false;
9226             }
9227             if ( p.hasNext() ) {
9228                 return false;
9229             }
9230             if ( p.next() != null ) {
9231                 return false;
9232             }
9233             //
9234             final String p4_str = "((A,B)ab,C)abc";
9235             p.setSource( p4_str );
9236             if ( !p.hasNext() ) {
9237                 return false;
9238             }
9239             final Phylogeny p4_0 = p.next();
9240             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
9241                 return false;
9242             }
9243             if ( p.hasNext() ) {
9244                 return false;
9245             }
9246             if ( p.next() != null ) {
9247                 return false;
9248             }
9249             //
9250             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
9251             p.setSource( p5_str );
9252             if ( !p.hasNext() ) {
9253                 return false;
9254             }
9255             final Phylogeny p5_0 = p.next();
9256             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
9257                 return false;
9258             }
9259             if ( p.hasNext() ) {
9260                 return false;
9261             }
9262             if ( p.next() != null ) {
9263                 return false;
9264             }
9265             //
9266             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
9267             p.setSource( p6_str );
9268             if ( !p.hasNext() ) {
9269                 return false;
9270             }
9271             Phylogeny p6_0 = p.next();
9272             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9273                 return false;
9274             }
9275             if ( p.hasNext() ) {
9276                 return false;
9277             }
9278             if ( p.next() != null ) {
9279                 return false;
9280             }
9281             p.reset();
9282             if ( !p.hasNext() ) {
9283                 return false;
9284             }
9285             p6_0 = p.next();
9286             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9287                 return false;
9288             }
9289             if ( p.hasNext() ) {
9290                 return false;
9291             }
9292             if ( p.next() != null ) {
9293                 return false;
9294             }
9295             //
9296             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
9297             p.setSource( p7_str );
9298             if ( !p.hasNext() ) {
9299                 return false;
9300             }
9301             Phylogeny p7_0 = p.next();
9302             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9303                 return false;
9304             }
9305             if ( p.hasNext() ) {
9306                 return false;
9307             }
9308             if ( p.next() != null ) {
9309                 return false;
9310             }
9311             p.reset();
9312             if ( !p.hasNext() ) {
9313                 return false;
9314             }
9315             p7_0 = p.next();
9316             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9317                 return false;
9318             }
9319             if ( p.hasNext() ) {
9320                 return false;
9321             }
9322             if ( p.next() != null ) {
9323                 return false;
9324             }
9325             //
9326             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
9327             p.setSource( p8_str );
9328             if ( !p.hasNext() ) {
9329                 return false;
9330             }
9331             Phylogeny p8_0 = p.next();
9332             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9333                 return false;
9334             }
9335             if ( !p.hasNext() ) {
9336                 return false;
9337             }
9338             if ( !p.hasNext() ) {
9339                 return false;
9340             }
9341             Phylogeny p8_1 = p.next();
9342             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9343                 return false;
9344             }
9345             if ( p.hasNext() ) {
9346                 return false;
9347             }
9348             if ( p.next() != null ) {
9349                 return false;
9350             }
9351             p.reset();
9352             if ( !p.hasNext() ) {
9353                 return false;
9354             }
9355             p8_0 = p.next();
9356             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9357                 return false;
9358             }
9359             if ( !p.hasNext() ) {
9360                 return false;
9361             }
9362             p8_1 = p.next();
9363             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9364                 return false;
9365             }
9366             if ( p.hasNext() ) {
9367                 return false;
9368             }
9369             if ( p.next() != null ) {
9370                 return false;
9371             }
9372             p.reset();
9373             //
9374             p.setSource( "" );
9375             if ( p.hasNext() ) {
9376                 return false;
9377             }
9378             //
9379             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
9380             if ( !p.hasNext() ) {
9381                 return false;
9382             }
9383             Phylogeny p_27 = p.next();
9384             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9385                 System.out.println( p_27.toNewHampshireX() );
9386                 System.exit( -1 );
9387                 return false;
9388             }
9389             if ( p.hasNext() ) {
9390                 return false;
9391             }
9392             if ( p.next() != null ) {
9393                 return false;
9394             }
9395             p.reset();
9396             if ( !p.hasNext() ) {
9397                 return false;
9398             }
9399             p_27 = p.next();
9400             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9401                 System.out.println( p_27.toNewHampshireX() );
9402                 System.exit( -1 );
9403                 return false;
9404             }
9405             if ( p.hasNext() ) {
9406                 return false;
9407             }
9408             if ( p.next() != null ) {
9409                 return false;
9410             }
9411             //
9412             final String p30_str = "(A,B);(C,D)";
9413             final NHXParser p30 = new NHXParser();
9414             p30.setSource( p30_str );
9415             if ( !p30.hasNext() ) {
9416                 return false;
9417             }
9418             Phylogeny phy30 = p30.next();
9419             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9420                 System.out.println( phy30.toNewHampshire() );
9421                 return false;
9422             }
9423             if ( !p30.hasNext() ) {
9424                 return false;
9425             }
9426             Phylogeny phy301 = p30.next();
9427             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9428                 System.out.println( phy301.toNewHampshire() );
9429                 return false;
9430             }
9431             if ( p30.hasNext() ) {
9432                 return false;
9433             }
9434             if ( p30.hasNext() ) {
9435                 return false;
9436             }
9437             if ( p30.next() != null ) {
9438                 return false;
9439             }
9440             if ( p30.next() != null ) {
9441                 return false;
9442             }
9443             p30.reset();
9444             if ( !p30.hasNext() ) {
9445                 return false;
9446             }
9447             phy30 = p30.next();
9448             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9449                 System.out.println( phy30.toNewHampshire() );
9450                 return false;
9451             }
9452             if ( !p30.hasNext() ) {
9453                 return false;
9454             }
9455             phy301 = p30.next();
9456             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9457                 System.out.println( phy301.toNewHampshire() );
9458                 return false;
9459             }
9460             if ( p30.hasNext() ) {
9461                 return false;
9462             }
9463             if ( p30.hasNext() ) {
9464                 return false;
9465             }
9466             if ( p30.next() != null ) {
9467                 return false;
9468             }
9469             if ( p30.next() != null ) {
9470                 return false;
9471             }
9472         }
9473         catch ( final Exception e ) {
9474             e.printStackTrace( System.out );
9475             return false;
9476         }
9477         return true;
9478     }
9479
9480     private static boolean testNHXconversion() {
9481         try {
9482             final PhylogenyNode n1 = new PhylogenyNode();
9483             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9484             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9485             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9486             final PhylogenyNode n5 = PhylogenyNode
9487                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
9488             final PhylogenyNode n6 = PhylogenyNode
9489                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
9490             if ( !n1.toNewHampshireX().equals( "" ) ) {
9491                 return false;
9492             }
9493             if ( !n2.toNewHampshireX().equals( "" ) ) {
9494                 return false;
9495             }
9496             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
9497                 return false;
9498             }
9499             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
9500                 return false;
9501             }
9502             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
9503                 return false;
9504             }
9505             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9506                 System.out.println( n6.toNewHampshireX() );
9507                 return false;
9508             }
9509             final PhylogenyNode n7 = new PhylogenyNode();
9510             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9511             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9512                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9513                 System.out.println( n7
9514                                     .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9515                 return false;
9516             }
9517         }
9518         catch ( final Exception e ) {
9519             e.printStackTrace( System.out );
9520             return false;
9521         }
9522         return true;
9523     }
9524
9525     private static boolean testNHXNodeParsing() {
9526         try {
9527             final PhylogenyNode n1 = new PhylogenyNode();
9528             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9529             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9530             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9531             final PhylogenyNode n5 = PhylogenyNode
9532                     .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]" );
9533             if ( !n3.getName().equals( "n3" ) ) {
9534                 return false;
9535             }
9536             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9537                 return false;
9538             }
9539             if ( n3.isDuplication() ) {
9540                 return false;
9541             }
9542             if ( n3.isHasAssignedEvent() ) {
9543                 return false;
9544             }
9545             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9546                 return false;
9547             }
9548             if ( !n4.getName().equals( "n4" ) ) {
9549                 return false;
9550             }
9551             if ( n4.getDistanceToParent() != 0.01 ) {
9552                 return false;
9553             }
9554             if ( !n5.getName().equals( "n5" ) ) {
9555                 return false;
9556             }
9557             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9558                 return false;
9559             }
9560             if ( n5.getDistanceToParent() != 0.1 ) {
9561                 return false;
9562             }
9563             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9564                 return false;
9565             }
9566             if ( !n5.isDuplication() ) {
9567                 return false;
9568             }
9569             if ( !n5.isHasAssignedEvent() ) {
9570                 return false;
9571             }
9572             final PhylogenyNode n8 = PhylogenyNode
9573                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9574                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9575             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9576                 return false;
9577             }
9578             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9579                 return false;
9580             }
9581             final PhylogenyNode n9 = PhylogenyNode
9582                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9583                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9584             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9585                 return false;
9586             }
9587             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9588                 return false;
9589             }
9590             final PhylogenyNode n10 = PhylogenyNode
9591                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9592             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9593                 return false;
9594             }
9595             final PhylogenyNode n20 = PhylogenyNode
9596                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9597             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9598                 return false;
9599             }
9600             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9601                 return false;
9602             }
9603             final PhylogenyNode n20x = PhylogenyNode
9604                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9605             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9606                 return false;
9607             }
9608             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9609                 return false;
9610             }
9611             final PhylogenyNode n20xx = PhylogenyNode
9612                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9613             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9614                 return false;
9615             }
9616             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9617                 return false;
9618             }
9619             final PhylogenyNode n20xxx = PhylogenyNode
9620                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9621             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9622                 return false;
9623             }
9624             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9625                 return false;
9626             }
9627             final PhylogenyNode n20xxxx = PhylogenyNode
9628                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9629             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9630                 return false;
9631             }
9632             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9633                 return false;
9634             }
9635             final PhylogenyNode n21 = PhylogenyNode
9636                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9637             if ( !n21.getName().equals( "N21_PIG" ) ) {
9638                 return false;
9639             }
9640             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9641                 return false;
9642             }
9643             final PhylogenyNode n21x = PhylogenyNode
9644                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9645             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9646                 return false;
9647             }
9648             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9649                 return false;
9650             }
9651             final PhylogenyNode n22 = PhylogenyNode
9652                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9653             if ( !n22.getName().equals( "n22/PIG" ) ) {
9654                 return false;
9655             }
9656             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9657                 return false;
9658             }
9659             final PhylogenyNode n23 = PhylogenyNode
9660                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9661             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9662                 return false;
9663             }
9664             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9665                 return false;
9666             }
9667             final PhylogenyNode a = PhylogenyNode
9668                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9669             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9670                 return false;
9671             }
9672             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9673                 return false;
9674             }
9675             final PhylogenyNode c1 = PhylogenyNode
9676                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9677                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9678             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9679                 return false;
9680             }
9681             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9682                 return false;
9683             }
9684             final PhylogenyNode c2 = PhylogenyNode
9685                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9686                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9687             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9688                 return false;
9689             }
9690             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9691                 return false;
9692             }
9693             final PhylogenyNode e3 = PhylogenyNode
9694                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9695             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9696                 return false;
9697             }
9698             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9699                 return false;
9700             }
9701             final PhylogenyNode n11 = PhylogenyNode
9702                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9703                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9704             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9705                 return false;
9706             }
9707             if ( n11.getDistanceToParent() != 0.4 ) {
9708                 return false;
9709             }
9710             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9711                 return false;
9712             }
9713             final PhylogenyNode n12 = PhylogenyNode
9714                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9715                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9716             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9717                 return false;
9718             }
9719             if ( n12.getDistanceToParent() != 0.4 ) {
9720                 return false;
9721             }
9722             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9723                 return false;
9724             }
9725             final PhylogenyNode o = PhylogenyNode
9726                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9727             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9728                 return false;
9729             }
9730             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9731                 return false;
9732             }
9733             if ( n1.getName().compareTo( "" ) != 0 ) {
9734                 return false;
9735             }
9736             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9737                 return false;
9738             }
9739             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9740                 return false;
9741             }
9742             if ( n2.getName().compareTo( "" ) != 0 ) {
9743                 return false;
9744             }
9745             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9746                 return false;
9747             }
9748             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9749                 return false;
9750             }
9751             final PhylogenyNode n00 = PhylogenyNode
9752                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9753             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9754                 return false;
9755             }
9756             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9757                 return false;
9758             }
9759             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9760             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9761                 return false;
9762             }
9763             final PhylogenyNode n13 = PhylogenyNode
9764                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9765             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9766                 return false;
9767             }
9768             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9769                 return false;
9770             }
9771             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9772                 return false;
9773             }
9774             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9775                 return false;
9776             }
9777             final PhylogenyNode n14 = PhylogenyNode
9778                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9779             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9780                 return false;
9781             }
9782             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9783                 return false;
9784             }
9785             final PhylogenyNode n15 = PhylogenyNode
9786                     .createInstanceFromNhxString( "something_wicked[123]",
9787                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9788             if ( !n15.getName().equals( "something_wicked" ) ) {
9789                 return false;
9790             }
9791             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9792                 return false;
9793             }
9794             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9795                 return false;
9796             }
9797             final PhylogenyNode n16 = PhylogenyNode
9798                     .createInstanceFromNhxString( "something_wicked2[9]",
9799                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9800             if ( !n16.getName().equals( "something_wicked2" ) ) {
9801                 return false;
9802             }
9803             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9804                 return false;
9805             }
9806             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9807                 return false;
9808             }
9809             final PhylogenyNode n17 = PhylogenyNode
9810                     .createInstanceFromNhxString( "something_wicked3[a]",
9811                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9812             if ( !n17.getName().equals( "something_wicked3" ) ) {
9813                 return false;
9814             }
9815             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9816                 return false;
9817             }
9818             final PhylogenyNode n18 = PhylogenyNode
9819                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9820             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9821                 return false;
9822             }
9823             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9824                 return false;
9825             }
9826             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9827                 return false;
9828             }
9829             final PhylogenyNode n19 = PhylogenyNode
9830                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9831             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9832                 return false;
9833             }
9834             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9835                 return false;
9836             }
9837             final PhylogenyNode n30 = PhylogenyNode
9838                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9839                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9840             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9841                 return false;
9842             }
9843             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9844                 return false;
9845             }
9846             final PhylogenyNode n31 = PhylogenyNode
9847                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9848                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9849             if ( n31.getNodeData().isHasTaxonomy() ) {
9850                 return false;
9851             }
9852             final PhylogenyNode n32 = PhylogenyNode
9853                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9854             if ( n32.getNodeData().isHasTaxonomy() ) {
9855                 return false;
9856             }
9857             final PhylogenyNode n40 = PhylogenyNode
9858                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9859             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9860                 return false;
9861             }
9862             final PhylogenyNode n41 = PhylogenyNode
9863                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9864             if ( n41.getNodeData().isHasTaxonomy() ) {
9865                 return false;
9866             }
9867             final PhylogenyNode n42 = PhylogenyNode
9868                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9869             if ( n42.getNodeData().isHasTaxonomy() ) {
9870                 return false;
9871             }
9872             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9873                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9874             if ( n43.getNodeData().isHasTaxonomy() ) {
9875                 return false;
9876             }
9877             final PhylogenyNode n44 = PhylogenyNode
9878                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9879             if ( n44.getNodeData().isHasTaxonomy() ) {
9880                 return false;
9881             }
9882         }
9883         catch ( final Exception e ) {
9884             e.printStackTrace( System.out );
9885             return false;
9886         }
9887         return true;
9888     }
9889
9890     
9891     private static boolean testNHXNodeParsing2() {
9892         try {
9893           
9894             final PhylogenyNode n0_0 = PhylogenyNode
9895                     .createInstanceFromNhxString( "n0:[ignore me 123]:1E-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9896             if ( !n0_0.getName().equals( "n0" ) ) {
9897                 return false;
9898             }
9899             if ( !isEqual( n0_0.getDistanceToParent(), 0.001 ) ) {
9900                 return false;
9901             }
9902             final PhylogenyNode n0_1 = PhylogenyNode
9903                     .createInstanceFromNhxString( "n0[ignore me 123]:1E-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9904             if ( !n0_1.getName().equals( "n0" ) ) {
9905                 return false;
9906             }
9907             if ( !isEqual( n0_1.getDistanceToParent(), 0.001 ) ) {
9908                 return false;
9909             }
9910             final PhylogenyNode n0_2 = PhylogenyNode
9911                     .createInstanceFromNhxString( "n0:1E-3[ignore me 123]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9912             if ( !n0_2.getName().equals( "n0" ) ) {
9913                 return false;
9914             }
9915             if ( !isEqual( n0_2.getDistanceToParent(), 0.001 ) ) {
9916                 return false;
9917             }
9918             final PhylogenyNode n0_3 = PhylogenyNode
9919                     .createInstanceFromNhxString( "n0:1E-3:[ignore me 123]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9920             if ( !n0_3.getName().equals( "n0" ) ) {
9921                 return false;
9922             }
9923             if ( !isEqual( n0_3.getDistanceToParent(), 0.001 ) ) {
9924                 return false;
9925             }
9926             final PhylogenyNode n0_4 = PhylogenyNode
9927                     .createInstanceFromNhxString( "n0:0.001:[ignore me 123]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9928             if ( !n0_4.getName().equals( "n0" ) ) {
9929                 return false;
9930             }
9931             if ( !isEqual( n0_4.getDistanceToParent(), 0.001 ) ) {
9932                 return false;
9933             }
9934             final PhylogenyNode n1_0 = PhylogenyNode
9935                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9936             if ( !n1_0.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9937                 return false;
9938             }
9939             if ( n1_0.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
9940                return false;
9941             }
9942             final PhylogenyNode n1_1 = PhylogenyNode
9943                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]:0.001", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9944             if ( !n1_1.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9945                 return false;
9946             }
9947             if ( n1_1.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
9948                return false;
9949             }
9950             if ( !isEqual( n1_1.getDistanceToParent(), 0.001 ) ) {
9951                 return false;
9952             }
9953             final PhylogenyNode n1_2 = PhylogenyNode
9954                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:0.001[&!color=#FFFFFF]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9955             if ( !n1_2.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9956                 return false;
9957             }
9958             if ( n1_2.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
9959                return false;
9960             }
9961             if ( !isEqual( n1_2.getDistanceToParent(), 0.001 ) ) {
9962                 return false;
9963             }
9964             final PhylogenyNode n1_3 = PhylogenyNode
9965                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[&boostrap=69,&!color=#FFFFFF]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9966             if ( !n1_3.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9967                 return false;
9968             }
9969             if ( n1_3.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
9970                return false;
9971             }
9972             if ( !isEqual( n1_3.getDistanceToParent(), 0.001 ) ) {
9973                 return false;
9974             }
9975             if ( !isEqual( n1_3.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
9976                 return false;
9977             }
9978             if ( !n1_3.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
9979                 return false;
9980             }
9981             final PhylogenyNode n1_4 = PhylogenyNode
9982                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&bootstrap=69,&!colour=#FFFFFF]:1e-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9983             if ( !n1_4.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9984                 return false;
9985             }
9986             if ( n1_4.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
9987                return false;
9988             }
9989             if ( !isEqual( n1_4.getDistanceToParent(), 0.001 ) ) {
9990                 return false;
9991             }
9992             if ( !isEqual( n1_4.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
9993                 return false;
9994             }
9995             if ( !n1_4.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
9996                 return false;
9997             }
9998             final PhylogenyNode n1_5 = PhylogenyNode
9999                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[69.0]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
10000             if ( !n1_5.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10001                 return false;
10002             }
10003             if ( !isEqual( n1_5.getDistanceToParent(), 0.001 ) ) {
10004                 return false;
10005             }
10006             if ( !isEqual( n1_5.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
10007                 return false;
10008             }       
10009             final PhylogenyNode n1_6 = PhylogenyNode
10010                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00]:1e-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
10011             if ( !n1_6.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10012                 return false;
10013             }
10014            
10015             if ( !isEqual( n1_6.getDistanceToParent(), 0.001 ) ) {
10016                 return false;
10017             }
10018             if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getStandardDeviation(), 0.11 ) ) {
10019                 return false;
10020             }
10021             if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getValue(), 0.95 ) ) {
10022                 return false;
10023             }
10024             if ( !n1_6.getBranchData().getConfidence( 0 ).getType().equals( "posterior probability" ) ) {
10025                 return false;
10026             }
10027         }
10028         catch ( final Exception e ) {
10029             e.printStackTrace( System.out );
10030             return false;
10031         }
10032         return true;
10033     }
10034     
10035     private static boolean testNHXParsing() {
10036         try {
10037             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10038             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
10039             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
10040                 return false;
10041             }
10042             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]";
10043             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
10044             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10045                 return false;
10046             }
10047             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]";
10048             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
10049             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
10050                 return false;
10051             }
10052             final Phylogeny[] p3 = factory
10053                     .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]",
10054                              new NHXParser() );
10055             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10056                 return false;
10057             }
10058             final Phylogeny[] p4 = factory
10059                     .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(]",
10060                              new NHXParser() );
10061             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10062                 return false;
10063             }
10064             final Phylogeny[] p5 = factory
10065                     .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(((]",
10066                              new NHXParser() );
10067             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10068                 return false;
10069             }
10070             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)";
10071             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)";
10072             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
10073             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
10074                 return false;
10075             }
10076             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)))";
10077             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)))";
10078             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
10079             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
10080                 return false;
10081             }
10082             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])   ))[,,, ])))))))";
10083             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
10084             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
10085             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
10086                 return false;
10087             }
10088             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
10089             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10090                 return false;
10091             }
10092             final Phylogeny p10 = factory
10093                     .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]",
10094                              new NHXParser() )[ 0 ];
10095             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10096                 return false;
10097             }
10098             final Phylogeny p11 = factory
10099                     .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]",
10100                              new NHXParser() )[ 0 ];
10101             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10102                 return false;
10103             }
10104             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]",
10105                                                   new NHXParser() )[ 0 ];
10106             if ( !p12.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10107                 return false;
10108             }
10109         }
10110         catch ( final Exception e ) {
10111             e.printStackTrace( System.out );
10112             return false;
10113         }
10114         return true;
10115     }
10116
10117     private static boolean testNHXParsingMB() {
10118         try {
10119             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10120             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
10121                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10122                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
10123                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
10124                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
10125                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10126                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
10127                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
10128                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
10129             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
10130                 return false;
10131             }
10132             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
10133                 return false;
10134             }
10135             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
10136                            0.1100000000000000e+00 ) ) {
10137                 return false;
10138             }
10139             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
10140                 return false;
10141             }
10142             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
10143                 return false;
10144             }
10145             final Phylogeny p2 = factory
10146                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
10147                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10148                             + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
10149                             + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
10150                             + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
10151                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10152                             + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
10153                             + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
10154                             + "7.369400000000000e-02}])",
10155                             new NHXParser() )[ 0 ];
10156             if ( p2.getNode( "1" ) == null ) {
10157                 return false;
10158             }
10159             if ( p2.getNode( "2" ) == null ) {
10160                 return false;
10161             }
10162         }
10163         catch ( final Exception e ) {
10164             e.printStackTrace( System.out );
10165             System.exit( -1 );
10166             return false;
10167         }
10168         return true;
10169     }
10170
10171     private static boolean testNHXParsingQuotes() {
10172         try {
10173             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10174             final NHXParser p = new NHXParser();
10175             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
10176             if ( phylogenies_0.length != 5 ) {
10177                 return false;
10178             }
10179             final Phylogeny phy = phylogenies_0[ 4 ];
10180             if ( phy.getNumberOfExternalNodes() != 7 ) {
10181                 return false;
10182             }
10183             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
10184                 return false;
10185             }
10186             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
10187                 return false;
10188             }
10189             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
10190                     .getScientificName().equals( "hsapiens" ) ) {
10191                 return false;
10192             }
10193             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
10194                 return false;
10195             }
10196             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
10197                 return false;
10198             }
10199             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
10200                 return false;
10201             }
10202             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
10203                 return false;
10204             }
10205             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
10206                 return false;
10207             }
10208             final NHXParser p1p = new NHXParser();
10209             p1p.setIgnoreQuotes( true );
10210             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
10211             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
10212                 return false;
10213             }
10214             final NHXParser p2p = new NHXParser();
10215             p1p.setIgnoreQuotes( false );
10216             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
10217             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
10218                 return false;
10219             }
10220             final NHXParser p3p = new NHXParser();
10221             p3p.setIgnoreQuotes( false );
10222             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
10223             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
10224                 return false;
10225             }
10226             final NHXParser p4p = new NHXParser();
10227             p4p.setIgnoreQuotes( false );
10228             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
10229             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
10230                 return false;
10231             }
10232             final Phylogeny p10 = factory
10233                     .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]",
10234                              new NHXParser() )[ 0 ];
10235             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]";
10236             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
10237                 return false;
10238             }
10239             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
10240             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
10241                 return false;
10242             }
10243             final Phylogeny p12 = factory
10244                     .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]",
10245                              new NHXParser() )[ 0 ];
10246             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]";
10247             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
10248                 return false;
10249             }
10250             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
10251             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
10252                 return false;
10253             }
10254             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;";
10255             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
10256                 return false;
10257             }
10258             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
10259             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
10260                 return false;
10261             }
10262         }
10263         catch ( final Exception e ) {
10264             e.printStackTrace( System.out );
10265             return false;
10266         }
10267         return true;
10268     }
10269
10270     private static boolean testNodeRemoval() {
10271         try {
10272             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10273             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
10274             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
10275             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
10276                 return false;
10277             }
10278             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
10279             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
10280             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
10281                 return false;
10282             }
10283             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
10284             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
10285             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
10286                 return false;
10287             }
10288         }
10289         catch ( final Exception e ) {
10290             e.printStackTrace( System.out );
10291             return false;
10292         }
10293         return true;
10294     }
10295
10296     private static boolean testPhylogenyBranch() {
10297         try {
10298             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
10299             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
10300             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
10301             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
10302             if ( !a1b1.equals( a1b1 ) ) {
10303                 return false;
10304             }
10305             if ( !a1b1.equals( b1a1 ) ) {
10306                 return false;
10307             }
10308             if ( !b1a1.equals( a1b1 ) ) {
10309                 return false;
10310             }
10311             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
10312             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
10313             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
10314             if ( a1_b1.equals( b1_a1 ) ) {
10315                 return false;
10316             }
10317             if ( a1_b1.equals( a1_b1_ ) ) {
10318                 return false;
10319             }
10320             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
10321             if ( !a1_b1.equals( b1_a1_ ) ) {
10322                 return false;
10323             }
10324             if ( a1_b1_.equals( b1_a1_ ) ) {
10325                 return false;
10326             }
10327             if ( !a1_b1_.equals( b1_a1 ) ) {
10328                 return false;
10329             }
10330         }
10331         catch ( final Exception e ) {
10332             e.printStackTrace( System.out );
10333             return false;
10334         }
10335         return true;
10336     }
10337
10338     private static boolean testPhyloXMLparsingOfDistributionElement() {
10339         try {
10340             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10341             PhyloXmlParser xml_parser = null;
10342             try {
10343                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
10344             }
10345             catch ( final Exception e ) {
10346                 // Do nothing -- means were not running from jar.
10347             }
10348             if ( xml_parser == null ) {
10349                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
10350                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
10351                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
10352                 }
10353                 else {
10354                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
10355                 }
10356             }
10357             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml" ),
10358                                                               xml_parser );
10359             if ( xml_parser.getErrorCount() > 0 ) {
10360                 System.out.println( xml_parser.getErrorMessages().toString() );
10361                 return false;
10362             }
10363             if ( phylogenies_0.length != 1 ) {
10364                 return false;
10365             }
10366             final Phylogeny t1 = phylogenies_0[ 0 ];
10367             PhylogenyNode n = null;
10368             Distribution d = null;
10369             n = t1.getNode( "root node" );
10370             if ( !n.getNodeData().isHasDistribution() ) {
10371                 return false;
10372             }
10373             if ( n.getNodeData().getDistributions().size() != 1 ) {
10374                 return false;
10375             }
10376             d = n.getNodeData().getDistribution();
10377             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10378                 return false;
10379             }
10380             if ( d.getPoints().size() != 1 ) {
10381                 return false;
10382             }
10383             if ( d.getPolygons() != null ) {
10384                 return false;
10385             }
10386             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10387                 return false;
10388             }
10389             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10390                 return false;
10391             }
10392             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10393                 return false;
10394             }
10395             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10396                 return false;
10397             }
10398             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10399                 return false;
10400             }
10401             n = t1.getNode( "node a" );
10402             if ( !n.getNodeData().isHasDistribution() ) {
10403                 return false;
10404             }
10405             if ( n.getNodeData().getDistributions().size() != 2 ) {
10406                 return false;
10407             }
10408             d = n.getNodeData().getDistribution( 1 );
10409             if ( !d.getDesc().equals( "San Diego" ) ) {
10410                 return false;
10411             }
10412             if ( d.getPoints().size() != 1 ) {
10413                 return false;
10414             }
10415             if ( d.getPolygons() != null ) {
10416                 return false;
10417             }
10418             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10419                 return false;
10420             }
10421             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10422                 return false;
10423             }
10424             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10425                 return false;
10426             }
10427             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10428                 return false;
10429             }
10430             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10431                 return false;
10432             }
10433             n = t1.getNode( "node bb" );
10434             if ( !n.getNodeData().isHasDistribution() ) {
10435                 return false;
10436             }
10437             if ( n.getNodeData().getDistributions().size() != 1 ) {
10438                 return false;
10439             }
10440             d = n.getNodeData().getDistribution( 0 );
10441             if ( d.getPoints().size() != 3 ) {
10442                 return false;
10443             }
10444             if ( d.getPolygons().size() != 2 ) {
10445                 return false;
10446             }
10447             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10448                 return false;
10449             }
10450             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10451                 return false;
10452             }
10453             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10454                 return false;
10455             }
10456             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10457                 return false;
10458             }
10459             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10460                 return false;
10461             }
10462             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10463                 return false;
10464             }
10465             Polygon p = d.getPolygons().get( 0 );
10466             if ( p.getPoints().size() != 3 ) {
10467                 return false;
10468             }
10469             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10470                 return false;
10471             }
10472             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10473                 return false;
10474             }
10475             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10476                 return false;
10477             }
10478             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10479                 return false;
10480             }
10481             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10482                 return false;
10483             }
10484             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10485                 return false;
10486             }
10487             p = d.getPolygons().get( 1 );
10488             if ( p.getPoints().size() != 3 ) {
10489                 return false;
10490             }
10491             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10492                 return false;
10493             }
10494             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10495                 return false;
10496             }
10497             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10498                 return false;
10499             }
10500             // Roundtrip:
10501             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
10502             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
10503             if ( rt.length != 1 ) {
10504                 return false;
10505             }
10506             final Phylogeny t1_rt = rt[ 0 ];
10507             n = t1_rt.getNode( "root node" );
10508             if ( !n.getNodeData().isHasDistribution() ) {
10509                 return false;
10510             }
10511             if ( n.getNodeData().getDistributions().size() != 1 ) {
10512                 return false;
10513             }
10514             d = n.getNodeData().getDistribution();
10515             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10516                 return false;
10517             }
10518             if ( d.getPoints().size() != 1 ) {
10519                 return false;
10520             }
10521             if ( d.getPolygons() != null ) {
10522                 return false;
10523             }
10524             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10525                 return false;
10526             }
10527             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10528                 return false;
10529             }
10530             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10531                 return false;
10532             }
10533             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10534                 return false;
10535             }
10536             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10537                 return false;
10538             }
10539             n = t1_rt.getNode( "node a" );
10540             if ( !n.getNodeData().isHasDistribution() ) {
10541                 return false;
10542             }
10543             if ( n.getNodeData().getDistributions().size() != 2 ) {
10544                 return false;
10545             }
10546             d = n.getNodeData().getDistribution( 1 );
10547             if ( !d.getDesc().equals( "San Diego" ) ) {
10548                 return false;
10549             }
10550             if ( d.getPoints().size() != 1 ) {
10551                 return false;
10552             }
10553             if ( d.getPolygons() != null ) {
10554                 return false;
10555             }
10556             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10557                 return false;
10558             }
10559             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10560                 return false;
10561             }
10562             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10563                 return false;
10564             }
10565             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10566                 return false;
10567             }
10568             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10569                 return false;
10570             }
10571             n = t1_rt.getNode( "node bb" );
10572             if ( !n.getNodeData().isHasDistribution() ) {
10573                 return false;
10574             }
10575             if ( n.getNodeData().getDistributions().size() != 1 ) {
10576                 return false;
10577             }
10578             d = n.getNodeData().getDistribution( 0 );
10579             if ( d.getPoints().size() != 3 ) {
10580                 return false;
10581             }
10582             if ( d.getPolygons().size() != 2 ) {
10583                 return false;
10584             }
10585             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10586                 return false;
10587             }
10588             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10589                 return false;
10590             }
10591             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10592                 return false;
10593             }
10594             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10595                 return false;
10596             }
10597             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10598                 return false;
10599             }
10600             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10601                 return false;
10602             }
10603             p = d.getPolygons().get( 0 );
10604             if ( p.getPoints().size() != 3 ) {
10605                 return false;
10606             }
10607             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10608                 return false;
10609             }
10610             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10611                 return false;
10612             }
10613             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10614                 return false;
10615             }
10616             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10617                 return false;
10618             }
10619             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10620                 return false;
10621             }
10622             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10623                 return false;
10624             }
10625             p = d.getPolygons().get( 1 );
10626             if ( p.getPoints().size() != 3 ) {
10627                 return false;
10628             }
10629             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10630                 return false;
10631             }
10632             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10633                 return false;
10634             }
10635             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10636                 return false;
10637             }
10638         }
10639         catch ( final Exception e ) {
10640             e.printStackTrace( System.out );
10641             return false;
10642         }
10643         return true;
10644     }
10645
10646     private static boolean testPostOrderIterator() {
10647         try {
10648             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10649             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10650             PhylogenyNodeIterator it0;
10651             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
10652                 it0.next();
10653             }
10654             for( it0.reset(); it0.hasNext(); ) {
10655                 it0.next();
10656             }
10657             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10658             final PhylogenyNodeIterator it = t1.iteratorPostorder();
10659             if ( !it.next().getName().equals( "A" ) ) {
10660                 return false;
10661             }
10662             if ( !it.next().getName().equals( "B" ) ) {
10663                 return false;
10664             }
10665             if ( !it.next().getName().equals( "ab" ) ) {
10666                 return false;
10667             }
10668             if ( !it.next().getName().equals( "C" ) ) {
10669                 return false;
10670             }
10671             if ( !it.next().getName().equals( "D" ) ) {
10672                 return false;
10673             }
10674             if ( !it.next().getName().equals( "cd" ) ) {
10675                 return false;
10676             }
10677             if ( !it.next().getName().equals( "abcd" ) ) {
10678                 return false;
10679             }
10680             if ( !it.next().getName().equals( "E" ) ) {
10681                 return false;
10682             }
10683             if ( !it.next().getName().equals( "F" ) ) {
10684                 return false;
10685             }
10686             if ( !it.next().getName().equals( "ef" ) ) {
10687                 return false;
10688             }
10689             if ( !it.next().getName().equals( "G" ) ) {
10690                 return false;
10691             }
10692             if ( !it.next().getName().equals( "H" ) ) {
10693                 return false;
10694             }
10695             if ( !it.next().getName().equals( "gh" ) ) {
10696                 return false;
10697             }
10698             if ( !it.next().getName().equals( "efgh" ) ) {
10699                 return false;
10700             }
10701             if ( !it.next().getName().equals( "r" ) ) {
10702                 return false;
10703             }
10704             if ( it.hasNext() ) {
10705                 return false;
10706             }
10707         }
10708         catch ( final Exception e ) {
10709             e.printStackTrace( System.out );
10710             return false;
10711         }
10712         return true;
10713     }
10714
10715     private static boolean testPreOrderIterator() {
10716         try {
10717             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10718             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10719             PhylogenyNodeIterator it0;
10720             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10721                 it0.next();
10722             }
10723             for( it0.reset(); it0.hasNext(); ) {
10724                 it0.next();
10725             }
10726             PhylogenyNodeIterator it = t0.iteratorPreorder();
10727             if ( !it.next().getName().equals( "r" ) ) {
10728                 return false;
10729             }
10730             if ( !it.next().getName().equals( "ab" ) ) {
10731                 return false;
10732             }
10733             if ( !it.next().getName().equals( "A" ) ) {
10734                 return false;
10735             }
10736             if ( !it.next().getName().equals( "B" ) ) {
10737                 return false;
10738             }
10739             if ( !it.next().getName().equals( "cd" ) ) {
10740                 return false;
10741             }
10742             if ( !it.next().getName().equals( "C" ) ) {
10743                 return false;
10744             }
10745             if ( !it.next().getName().equals( "D" ) ) {
10746                 return false;
10747             }
10748             if ( it.hasNext() ) {
10749                 return false;
10750             }
10751             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10752             it = t1.iteratorPreorder();
10753             if ( !it.next().getName().equals( "r" ) ) {
10754                 return false;
10755             }
10756             if ( !it.next().getName().equals( "abcd" ) ) {
10757                 return false;
10758             }
10759             if ( !it.next().getName().equals( "ab" ) ) {
10760                 return false;
10761             }
10762             if ( !it.next().getName().equals( "A" ) ) {
10763                 return false;
10764             }
10765             if ( !it.next().getName().equals( "B" ) ) {
10766                 return false;
10767             }
10768             if ( !it.next().getName().equals( "cd" ) ) {
10769                 return false;
10770             }
10771             if ( !it.next().getName().equals( "C" ) ) {
10772                 return false;
10773             }
10774             if ( !it.next().getName().equals( "D" ) ) {
10775                 return false;
10776             }
10777             if ( !it.next().getName().equals( "efgh" ) ) {
10778                 return false;
10779             }
10780             if ( !it.next().getName().equals( "ef" ) ) {
10781                 return false;
10782             }
10783             if ( !it.next().getName().equals( "E" ) ) {
10784                 return false;
10785             }
10786             if ( !it.next().getName().equals( "F" ) ) {
10787                 return false;
10788             }
10789             if ( !it.next().getName().equals( "gh" ) ) {
10790                 return false;
10791             }
10792             if ( !it.next().getName().equals( "G" ) ) {
10793                 return false;
10794             }
10795             if ( !it.next().getName().equals( "H" ) ) {
10796                 return false;
10797             }
10798             if ( it.hasNext() ) {
10799                 return false;
10800             }
10801         }
10802         catch ( final Exception e ) {
10803             e.printStackTrace( System.out );
10804             return false;
10805         }
10806         return true;
10807     }
10808
10809     private static boolean testPropertiesMap() {
10810         try {
10811             final PropertiesMap pm = new PropertiesMap();
10812             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10813             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10814             final Property p2 = new Property( "something:else",
10815                                               "?",
10816                                               "improbable:research",
10817                                               "xsd:decimal",
10818                                               AppliesTo.NODE );
10819             pm.addProperty( p0 );
10820             pm.addProperty( p1 );
10821             pm.addProperty( p2 );
10822             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10823                 return false;
10824             }
10825             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10826                 return false;
10827             }
10828             if ( pm.getProperties().size() != 3 ) {
10829                 return false;
10830             }
10831             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10832                 return false;
10833             }
10834             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10835                 return false;
10836             }
10837             if ( pm.getProperties().size() != 3 ) {
10838                 return false;
10839             }
10840             pm.removeProperty( "dimensions:diameter" );
10841             if ( pm.getProperties().size() != 2 ) {
10842                 return false;
10843             }
10844             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10845                 return false;
10846             }
10847             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10848                 return false;
10849             }
10850         }
10851         catch ( final Exception e ) {
10852             e.printStackTrace( System.out );
10853             return false;
10854         }
10855         return true;
10856     }
10857
10858     private static boolean testProteinId() {
10859         try {
10860             final ProteinId id1 = new ProteinId( "a" );
10861             final ProteinId id2 = new ProteinId( "a" );
10862             final ProteinId id3 = new ProteinId( "A" );
10863             final ProteinId id4 = new ProteinId( "b" );
10864             if ( !id1.equals( id1 ) ) {
10865                 return false;
10866             }
10867             if ( id1.getId().equals( "x" ) ) {
10868                 return false;
10869             }
10870             if ( id1.getId().equals( null ) ) {
10871                 return false;
10872             }
10873             if ( !id1.equals( id2 ) ) {
10874                 return false;
10875             }
10876             if ( id1.equals( id3 ) ) {
10877                 return false;
10878             }
10879             if ( id1.hashCode() != id1.hashCode() ) {
10880                 return false;
10881             }
10882             if ( id1.hashCode() != id2.hashCode() ) {
10883                 return false;
10884             }
10885             if ( id1.hashCode() == id3.hashCode() ) {
10886                 return false;
10887             }
10888             if ( id1.compareTo( id1 ) != 0 ) {
10889                 return false;
10890             }
10891             if ( id1.compareTo( id2 ) != 0 ) {
10892                 return false;
10893             }
10894             if ( id1.compareTo( id3 ) != 0 ) {
10895                 return false;
10896             }
10897             if ( id1.compareTo( id4 ) >= 0 ) {
10898                 return false;
10899             }
10900             if ( id4.compareTo( id1 ) <= 0 ) {
10901                 return false;
10902             }
10903             if ( !id4.getId().equals( "b" ) ) {
10904                 return false;
10905             }
10906             final ProteinId id5 = new ProteinId( " C " );
10907             if ( !id5.getId().equals( "C" ) ) {
10908                 return false;
10909             }
10910             if ( id5.equals( id1 ) ) {
10911                 return false;
10912             }
10913         }
10914         catch ( final Exception e ) {
10915             e.printStackTrace( System.out );
10916             return false;
10917         }
10918         return true;
10919     }
10920
10921     private static boolean testReIdMethods() {
10922         try {
10923             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10924             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10925             final long count = PhylogenyNode.getNodeCount();
10926             p.levelOrderReID();
10927             if ( p.getNode( "r" ).getId() != count ) {
10928                 return false;
10929             }
10930             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10931                 return false;
10932             }
10933             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10934                 return false;
10935             }
10936             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10937                 return false;
10938             }
10939             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10940                 return false;
10941             }
10942             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10943                 return false;
10944             }
10945             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10946                 return false;
10947             }
10948             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10949                 return false;
10950             }
10951             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10952                 return false;
10953             }
10954             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10955                 return false;
10956             }
10957             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10958                 return false;
10959             }
10960             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10961                 return false;
10962             }
10963             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10964                 return false;
10965             }
10966             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10967                 return false;
10968             }
10969             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10970                 return false;
10971             }
10972         }
10973         catch ( final Exception e ) {
10974             e.printStackTrace( System.out );
10975             return false;
10976         }
10977         return true;
10978     }
10979
10980     private static boolean testRerooting() {
10981         try {
10982             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10983             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",
10984                                                  new NHXParser() )[ 0 ];
10985             if ( !t1.isRooted() ) {
10986                 return false;
10987             }
10988             t1.reRoot( t1.getNode( "D" ) );
10989             t1.reRoot( t1.getNode( "CD" ) );
10990             t1.reRoot( t1.getNode( "A" ) );
10991             t1.reRoot( t1.getNode( "B" ) );
10992             t1.reRoot( t1.getNode( "AB" ) );
10993             t1.reRoot( t1.getNode( "D" ) );
10994             t1.reRoot( t1.getNode( "C" ) );
10995             t1.reRoot( t1.getNode( "CD" ) );
10996             t1.reRoot( t1.getNode( "A" ) );
10997             t1.reRoot( t1.getNode( "B" ) );
10998             t1.reRoot( t1.getNode( "AB" ) );
10999             t1.reRoot( t1.getNode( "D" ) );
11000             t1.reRoot( t1.getNode( "D" ) );
11001             t1.reRoot( t1.getNode( "C" ) );
11002             t1.reRoot( t1.getNode( "A" ) );
11003             t1.reRoot( t1.getNode( "B" ) );
11004             t1.reRoot( t1.getNode( "AB" ) );
11005             t1.reRoot( t1.getNode( "C" ) );
11006             t1.reRoot( t1.getNode( "D" ) );
11007             t1.reRoot( t1.getNode( "CD" ) );
11008             t1.reRoot( t1.getNode( "D" ) );
11009             t1.reRoot( t1.getNode( "A" ) );
11010             t1.reRoot( t1.getNode( "B" ) );
11011             t1.reRoot( t1.getNode( "AB" ) );
11012             t1.reRoot( t1.getNode( "C" ) );
11013             t1.reRoot( t1.getNode( "D" ) );
11014             t1.reRoot( t1.getNode( "CD" ) );
11015             t1.reRoot( t1.getNode( "D" ) );
11016             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
11017                 return false;
11018             }
11019             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
11020                 return false;
11021             }
11022             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
11023                 return false;
11024             }
11025             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
11026                 return false;
11027             }
11028             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
11029                 return false;
11030             }
11031             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
11032                 return false;
11033             }
11034             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",
11035                                                  new NHXParser() )[ 0 ];
11036             t2.reRoot( t2.getNode( "A" ) );
11037             t2.reRoot( t2.getNode( "D" ) );
11038             t2.reRoot( t2.getNode( "ABC" ) );
11039             t2.reRoot( t2.getNode( "A" ) );
11040             t2.reRoot( t2.getNode( "B" ) );
11041             t2.reRoot( t2.getNode( "D" ) );
11042             t2.reRoot( t2.getNode( "C" ) );
11043             t2.reRoot( t2.getNode( "ABC" ) );
11044             t2.reRoot( t2.getNode( "A" ) );
11045             t2.reRoot( t2.getNode( "B" ) );
11046             t2.reRoot( t2.getNode( "AB" ) );
11047             t2.reRoot( t2.getNode( "AB" ) );
11048             t2.reRoot( t2.getNode( "D" ) );
11049             t2.reRoot( t2.getNode( "C" ) );
11050             t2.reRoot( t2.getNode( "B" ) );
11051             t2.reRoot( t2.getNode( "AB" ) );
11052             t2.reRoot( t2.getNode( "D" ) );
11053             t2.reRoot( t2.getNode( "D" ) );
11054             t2.reRoot( t2.getNode( "ABC" ) );
11055             t2.reRoot( t2.getNode( "A" ) );
11056             t2.reRoot( t2.getNode( "B" ) );
11057             t2.reRoot( t2.getNode( "AB" ) );
11058             t2.reRoot( t2.getNode( "D" ) );
11059             t2.reRoot( t2.getNode( "C" ) );
11060             t2.reRoot( t2.getNode( "ABC" ) );
11061             t2.reRoot( t2.getNode( "A" ) );
11062             t2.reRoot( t2.getNode( "B" ) );
11063             t2.reRoot( t2.getNode( "AB" ) );
11064             t2.reRoot( t2.getNode( "D" ) );
11065             t2.reRoot( t2.getNode( "D" ) );
11066             t2.reRoot( t2.getNode( "C" ) );
11067             t2.reRoot( t2.getNode( "A" ) );
11068             t2.reRoot( t2.getNode( "B" ) );
11069             t2.reRoot( t2.getNode( "AB" ) );
11070             t2.reRoot( t2.getNode( "C" ) );
11071             t2.reRoot( t2.getNode( "D" ) );
11072             t2.reRoot( t2.getNode( "ABC" ) );
11073             t2.reRoot( t2.getNode( "D" ) );
11074             t2.reRoot( t2.getNode( "A" ) );
11075             t2.reRoot( t2.getNode( "B" ) );
11076             t2.reRoot( t2.getNode( "AB" ) );
11077             t2.reRoot( t2.getNode( "C" ) );
11078             t2.reRoot( t2.getNode( "D" ) );
11079             t2.reRoot( t2.getNode( "ABC" ) );
11080             t2.reRoot( t2.getNode( "D" ) );
11081             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11082                 return false;
11083             }
11084             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11085                 return false;
11086             }
11087             t2.reRoot( t2.getNode( "ABC" ) );
11088             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11089                 return false;
11090             }
11091             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11092                 return false;
11093             }
11094             t2.reRoot( t2.getNode( "AB" ) );
11095             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11096                 return false;
11097             }
11098             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11099                 return false;
11100             }
11101             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11102                 return false;
11103             }
11104             t2.reRoot( t2.getNode( "AB" ) );
11105             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11106                 return false;
11107             }
11108             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11109                 return false;
11110             }
11111             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11112                 return false;
11113             }
11114             t2.reRoot( t2.getNode( "D" ) );
11115             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11116                 return false;
11117             }
11118             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11119                 return false;
11120             }
11121             t2.reRoot( t2.getNode( "ABC" ) );
11122             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11123                 return false;
11124             }
11125             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11126                 return false;
11127             }
11128             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
11129                                                  new NHXParser() )[ 0 ];
11130             t3.reRoot( t3.getNode( "B" ) );
11131             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11132                 return false;
11133             }
11134             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11135                 return false;
11136             }
11137             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11138                 return false;
11139             }
11140             t3.reRoot( t3.getNode( "B" ) );
11141             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11142                 return false;
11143             }
11144             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11145                 return false;
11146             }
11147             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11148                 return false;
11149             }
11150             t3.reRoot( t3.getRoot() );
11151             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11152                 return false;
11153             }
11154             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11155                 return false;
11156             }
11157             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11158                 return false;
11159             }
11160         }
11161         catch ( final Exception e ) {
11162             e.printStackTrace( System.out );
11163             return false;
11164         }
11165         return true;
11166     }
11167
11168     private static boolean testSDIse() {
11169         try {
11170             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11171             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
11172             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
11173             gene1.setRooted( true );
11174             species1.setRooted( true );
11175             final SDI sdi = new SDI( gene1, species1 );
11176             if ( !gene1.getRoot().isDuplication() ) {
11177                 return false;
11178             }
11179             final Phylogeny species2 = factory
11180                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11181                              new NHXParser() )[ 0 ];
11182             final Phylogeny gene2 = factory
11183                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11184                              new NHXParser() )[ 0 ];
11185             species2.setRooted( true );
11186             gene2.setRooted( true );
11187             final SDI sdi2 = new SDI( gene2, species2 );
11188             if ( sdi2.getDuplicationsSum() != 0 ) {
11189                 return false;
11190             }
11191             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
11192                 return false;
11193             }
11194             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
11195                 return false;
11196             }
11197             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
11198                 return false;
11199             }
11200             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
11201                 return false;
11202             }
11203             if ( !gene2.getNode( "r" ).isSpeciation() ) {
11204                 return false;
11205             }
11206             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
11207                 return false;
11208             }
11209             final Phylogeny species3 = factory
11210                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11211                              new NHXParser() )[ 0 ];
11212             final Phylogeny gene3 = factory
11213                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11214                              new NHXParser() )[ 0 ];
11215             species3.setRooted( true );
11216             gene3.setRooted( true );
11217             final SDI sdi3 = new SDI( gene3, species3 );
11218             if ( sdi3.getDuplicationsSum() != 1 ) {
11219                 return false;
11220             }
11221             if ( !gene3.getNode( "aa" ).isDuplication() ) {
11222                 return false;
11223             }
11224             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
11225                 return false;
11226             }
11227             final Phylogeny species4 = factory
11228                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11229                              new NHXParser() )[ 0 ];
11230             final Phylogeny gene4 = factory
11231                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11232                              new NHXParser() )[ 0 ];
11233             species4.setRooted( true );
11234             gene4.setRooted( true );
11235             final SDI sdi4 = new SDI( gene4, species4 );
11236             if ( sdi4.getDuplicationsSum() != 1 ) {
11237                 return false;
11238             }
11239             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
11240                 return false;
11241             }
11242             if ( !gene4.getNode( "abc" ).isDuplication() ) {
11243                 return false;
11244             }
11245             if ( gene4.getNode( "abcd" ).isDuplication() ) {
11246                 return false;
11247             }
11248             if ( species4.getNumberOfExternalNodes() != 6 ) {
11249                 return false;
11250             }
11251             if ( gene4.getNumberOfExternalNodes() != 6 ) {
11252                 return false;
11253             }
11254             final Phylogeny species5 = factory
11255                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11256                              new NHXParser() )[ 0 ];
11257             final Phylogeny gene5 = factory
11258                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11259                              new NHXParser() )[ 0 ];
11260             species5.setRooted( true );
11261             gene5.setRooted( true );
11262             final SDI sdi5 = new SDI( gene5, species5 );
11263             if ( sdi5.getDuplicationsSum() != 2 ) {
11264                 return false;
11265             }
11266             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
11267                 return false;
11268             }
11269             if ( !gene5.getNode( "adc" ).isDuplication() ) {
11270                 return false;
11271             }
11272             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
11273                 return false;
11274             }
11275             if ( species5.getNumberOfExternalNodes() != 6 ) {
11276                 return false;
11277             }
11278             if ( gene5.getNumberOfExternalNodes() != 6 ) {
11279                 return false;
11280             }
11281             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
11282             // Conjecture for Comparing Molecular Phylogenies"
11283             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
11284             final Phylogeny species6 = factory
11285                     .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,"
11286                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11287                             new NHXParser() )[ 0 ];
11288             final Phylogeny gene6 = factory
11289                     .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,"
11290                             + "((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,"
11291                             + "(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;",
11292                             new NHXParser() )[ 0 ];
11293             species6.setRooted( true );
11294             gene6.setRooted( true );
11295             final SDI sdi6 = new SDI( gene6, species6 );
11296             if ( sdi6.getDuplicationsSum() != 3 ) {
11297                 return false;
11298             }
11299             if ( !gene6.getNode( "r" ).isDuplication() ) {
11300                 return false;
11301             }
11302             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
11303                 return false;
11304             }
11305             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
11306                 return false;
11307             }
11308             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
11309                 return false;
11310             }
11311             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
11312                 return false;
11313             }
11314             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
11315                 return false;
11316             }
11317             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
11318                 return false;
11319             }
11320             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
11321                 return false;
11322             }
11323             sdi6.computeMappingCostL();
11324             if ( sdi6.computeMappingCostL() != 17 ) {
11325                 return false;
11326             }
11327             if ( species6.getNumberOfExternalNodes() != 9 ) {
11328                 return false;
11329             }
11330             if ( gene6.getNumberOfExternalNodes() != 9 ) {
11331                 return false;
11332             }
11333             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
11334                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
11335                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
11336                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
11337                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
11338             species7.setRooted( true );
11339             final Phylogeny gene7_1 = Test
11340                     .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])" );
11341             gene7_1.setRooted( true );
11342             final SDI sdi7 = new SDI( gene7_1, species7 );
11343             if ( sdi7.getDuplicationsSum() != 0 ) {
11344                 return false;
11345             }
11346             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
11347                 return false;
11348             }
11349             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
11350                 return false;
11351             }
11352             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
11353                 return false;
11354             }
11355             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
11356                 return false;
11357             }
11358             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
11359                 return false;
11360             }
11361             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
11362                 return false;
11363             }
11364             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
11365                 return false;
11366             }
11367             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
11368                 return false;
11369             }
11370             final Phylogeny gene7_2 = Test
11371                     .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])" );
11372             gene7_2.setRooted( true );
11373             final SDI sdi7_2 = new SDI( gene7_2, species7 );
11374             if ( sdi7_2.getDuplicationsSum() != 1 ) {
11375                 return false;
11376             }
11377             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
11378                 return false;
11379             }
11380             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
11381                 return false;
11382             }
11383             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
11384                 return false;
11385             }
11386             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
11387                 return false;
11388             }
11389             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
11390                 return false;
11391             }
11392             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
11393                 return false;
11394             }
11395             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
11396                 return false;
11397             }
11398             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
11399                 return false;
11400             }
11401             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
11402                 return false;
11403             }
11404         }
11405         catch ( final Exception e ) {
11406             return false;
11407         }
11408         return true;
11409     }
11410
11411     private static boolean testSDIunrooted() {
11412         try {
11413             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11414             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
11415             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
11416             final Iterator<PhylogenyBranch> iter = l.iterator();
11417             PhylogenyBranch br = iter.next();
11418             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
11419                 return false;
11420             }
11421             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
11422                 return false;
11423             }
11424             br = iter.next();
11425             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11426                 return false;
11427             }
11428             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11429                 return false;
11430             }
11431             br = iter.next();
11432             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
11433                 return false;
11434             }
11435             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
11436                 return false;
11437             }
11438             br = iter.next();
11439             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11440                 return false;
11441             }
11442             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11443                 return false;
11444             }
11445             br = iter.next();
11446             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11447                 return false;
11448             }
11449             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11450                 return false;
11451             }
11452             br = iter.next();
11453             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11454                 return false;
11455             }
11456             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11457                 return false;
11458             }
11459             br = iter.next();
11460             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11461                 return false;
11462             }
11463             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11464                 return false;
11465             }
11466             br = iter.next();
11467             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11468                 return false;
11469             }
11470             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11471                 return false;
11472             }
11473             br = iter.next();
11474             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11475                 return false;
11476             }
11477             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11478                 return false;
11479             }
11480             br = iter.next();
11481             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11482                 return false;
11483             }
11484             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11485                 return false;
11486             }
11487             br = iter.next();
11488             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11489                 return false;
11490             }
11491             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11492                 return false;
11493             }
11494             br = iter.next();
11495             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
11496                 return false;
11497             }
11498             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
11499                 return false;
11500             }
11501             br = iter.next();
11502             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11503                 return false;
11504             }
11505             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11506                 return false;
11507             }
11508             br = iter.next();
11509             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
11510                 return false;
11511             }
11512             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
11513                 return false;
11514             }
11515             br = iter.next();
11516             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
11517                 return false;
11518             }
11519             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
11520                 return false;
11521             }
11522             if ( iter.hasNext() ) {
11523                 return false;
11524             }
11525             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
11526             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
11527             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
11528             br = iter1.next();
11529             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11530                 return false;
11531             }
11532             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11533                 return false;
11534             }
11535             br = iter1.next();
11536             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11537                 return false;
11538             }
11539             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11540                 return false;
11541             }
11542             br = iter1.next();
11543             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11544                 return false;
11545             }
11546             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11547                 return false;
11548             }
11549             if ( iter1.hasNext() ) {
11550                 return false;
11551             }
11552             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
11553             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
11554             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
11555             br = iter2.next();
11556             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11557                 return false;
11558             }
11559             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11560                 return false;
11561             }
11562             br = iter2.next();
11563             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11564                 return false;
11565             }
11566             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11567                 return false;
11568             }
11569             br = iter2.next();
11570             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11571                 return false;
11572             }
11573             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11574                 return false;
11575             }
11576             if ( iter2.hasNext() ) {
11577                 return false;
11578             }
11579             final Phylogeny species0 = factory
11580                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11581                              new NHXParser() )[ 0 ];
11582             final Phylogeny gene1 = factory
11583                     .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])",
11584                              new NHXParser() )[ 0 ];
11585             species0.setRooted( true );
11586             gene1.setRooted( true );
11587             final SDIR sdi_unrooted = new SDIR();
11588             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
11589             if ( sdi_unrooted.getCount() != 1 ) {
11590                 return false;
11591             }
11592             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
11593                 return false;
11594             }
11595             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
11596                 return false;
11597             }
11598             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
11599                 return false;
11600             }
11601             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11602                 return false;
11603             }
11604             final Phylogeny gene2 = factory
11605                     .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])",
11606                              new NHXParser() )[ 0 ];
11607             gene2.setRooted( true );
11608             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
11609             if ( sdi_unrooted.getCount() != 1 ) {
11610                 return false;
11611             }
11612             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11613                 return false;
11614             }
11615             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11616                 return false;
11617             }
11618             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
11619                 return false;
11620             }
11621             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11622                 return false;
11623             }
11624             final Phylogeny species6 = factory
11625                     .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,"
11626                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11627                             new NHXParser() )[ 0 ];
11628             final Phylogeny gene6 = factory
11629                     .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],"
11630                             + "(((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],"
11631                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11632                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11633                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11634                             new NHXParser() )[ 0 ];
11635             species6.setRooted( true );
11636             gene6.setRooted( true );
11637             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
11638             if ( sdi_unrooted.getCount() != 1 ) {
11639                 return false;
11640             }
11641             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11642                 return false;
11643             }
11644             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11645                 return false;
11646             }
11647             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11648                 return false;
11649             }
11650             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11651                 return false;
11652             }
11653             if ( !p6[ 0 ].getRoot().isDuplication() ) {
11654                 return false;
11655             }
11656             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11657                 return false;
11658             }
11659             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11660                 return false;
11661             }
11662             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11663                 return false;
11664             }
11665             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11666                 return false;
11667             }
11668             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11669                 return false;
11670             }
11671             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11672                 return false;
11673             }
11674             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11675                 return false;
11676             }
11677             p6 = null;
11678             final Phylogeny species7 = factory
11679                     .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,"
11680                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11681                             new NHXParser() )[ 0 ];
11682             final Phylogeny gene7 = factory
11683                     .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],"
11684                             + "(((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],"
11685                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11686                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11687                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11688                             new NHXParser() )[ 0 ];
11689             species7.setRooted( true );
11690             gene7.setRooted( true );
11691             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11692             if ( sdi_unrooted.getCount() != 1 ) {
11693                 return false;
11694             }
11695             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11696                 return false;
11697             }
11698             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11699                 return false;
11700             }
11701             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11702                 return false;
11703             }
11704             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11705                 return false;
11706             }
11707             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11708                 return false;
11709             }
11710             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11711                 return false;
11712             }
11713             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11714                 return false;
11715             }
11716             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11717                 return false;
11718             }
11719             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11720                 return false;
11721             }
11722             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11723                 return false;
11724             }
11725             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11726                 return false;
11727             }
11728             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11729                 return false;
11730             }
11731             p7 = null;
11732             final Phylogeny species8 = factory
11733                     .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,"
11734                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11735                             new NHXParser() )[ 0 ];
11736             final Phylogeny gene8 = factory
11737                     .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],"
11738                             + "(((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],"
11739                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11740                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11741                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11742                             new NHXParser() )[ 0 ];
11743             species8.setRooted( true );
11744             gene8.setRooted( true );
11745             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11746             if ( sdi_unrooted.getCount() != 1 ) {
11747                 return false;
11748             }
11749             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11750                 return false;
11751             }
11752             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11753                 return false;
11754             }
11755             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11756                 return false;
11757             }
11758             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11759                 return false;
11760             }
11761             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11762                 return false;
11763             }
11764             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11765                 return false;
11766             }
11767             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11768                 return false;
11769             }
11770             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11771                 return false;
11772             }
11773             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11774                 return false;
11775             }
11776             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11777                 return false;
11778             }
11779             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11780                 return false;
11781             }
11782             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11783                 return false;
11784             }
11785             p8 = null;
11786         }
11787         catch ( final Exception e ) {
11788             e.printStackTrace( System.out );
11789             return false;
11790         }
11791         return true;
11792     }
11793
11794     private static boolean testSequenceDbWsTools1() {
11795         try {
11796             final PhylogenyNode n = new PhylogenyNode();
11797             n.setName( "NP_001025424" );
11798             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11799             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11800                     || !acc.getValue().equals( "NP_001025424" ) ) {
11801                 return false;
11802             }
11803             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11804             acc = SequenceDbWsTools.obtainSeqAccession( n );
11805             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11806                     || !acc.getValue().equals( "NP_001025424" ) ) {
11807                 return false;
11808             }
11809             n.setName( "NP_001025424.1" );
11810             acc = SequenceDbWsTools.obtainSeqAccession( n );
11811             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11812                     || !acc.getValue().equals( "NP_001025424" ) ) {
11813                 return false;
11814             }
11815             n.setName( "NM_001030253" );
11816             acc = SequenceDbWsTools.obtainSeqAccession( n );
11817             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11818                     || !acc.getValue().equals( "NM_001030253" ) ) {
11819                 return false;
11820             }
11821             n.setName( "BCL2_HUMAN" );
11822             acc = SequenceDbWsTools.obtainSeqAccession( n );
11823             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11824                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11825                 System.out.println( acc.toString() );
11826                 return false;
11827             }
11828             n.setName( "P10415" );
11829             acc = SequenceDbWsTools.obtainSeqAccession( n );
11830             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11831                     || !acc.getValue().equals( "P10415" ) ) {
11832                 System.out.println( acc.toString() );
11833                 return false;
11834             }
11835             n.setName( " P10415 " );
11836             acc = SequenceDbWsTools.obtainSeqAccession( n );
11837             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11838                     || !acc.getValue().equals( "P10415" ) ) {
11839                 System.out.println( acc.toString() );
11840                 return false;
11841             }
11842             n.setName( "_P10415|" );
11843             acc = SequenceDbWsTools.obtainSeqAccession( n );
11844             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11845                     || !acc.getValue().equals( "P10415" ) ) {
11846                 System.out.println( acc.toString() );
11847                 return false;
11848             }
11849             n.setName( "AY695820" );
11850             acc = SequenceDbWsTools.obtainSeqAccession( n );
11851             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11852                     || !acc.getValue().equals( "AY695820" ) ) {
11853                 System.out.println( acc.toString() );
11854                 return false;
11855             }
11856             n.setName( "_AY695820_" );
11857             acc = SequenceDbWsTools.obtainSeqAccession( n );
11858             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11859                     || !acc.getValue().equals( "AY695820" ) ) {
11860                 System.out.println( acc.toString() );
11861                 return false;
11862             }
11863             n.setName( "AAA59452" );
11864             acc = SequenceDbWsTools.obtainSeqAccession( n );
11865             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11866                     || !acc.getValue().equals( "AAA59452" ) ) {
11867                 System.out.println( acc.toString() );
11868                 return false;
11869             }
11870             n.setName( "_AAA59452_" );
11871             acc = SequenceDbWsTools.obtainSeqAccession( n );
11872             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11873                     || !acc.getValue().equals( "AAA59452" ) ) {
11874                 System.out.println( acc.toString() );
11875                 return false;
11876             }
11877             n.setName( "AAA59452.1" );
11878             acc = SequenceDbWsTools.obtainSeqAccession( n );
11879             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11880                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11881                 System.out.println( acc.toString() );
11882                 return false;
11883             }
11884             n.setName( "_AAA59452.1_" );
11885             acc = SequenceDbWsTools.obtainSeqAccession( n );
11886             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11887                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11888                 System.out.println( acc.toString() );
11889                 return false;
11890             }
11891             n.setName( "GI:94894583" );
11892             acc = SequenceDbWsTools.obtainSeqAccession( n );
11893             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11894                     || !acc.getValue().equals( "94894583" ) ) {
11895                 System.out.println( acc.toString() );
11896                 return false;
11897             }
11898             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11899             acc = SequenceDbWsTools.obtainSeqAccession( n );
11900             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11901                     || !acc.getValue().equals( "71845847" ) ) {
11902                 System.out.println( acc.toString() );
11903                 return false;
11904             }
11905             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11906             acc = SequenceDbWsTools.obtainSeqAccession( n );
11907             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11908                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11909                 System.out.println( acc.toString() );
11910                 return false;
11911             }
11912         }
11913         catch ( final Exception e ) {
11914             return false;
11915         }
11916         return true;
11917     }
11918
11919     private static boolean testSequenceDbWsTools2() {
11920         try {
11921             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11922             SequenceDbWsTools.obtainSeqInformation( n1 );
11923             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11924                 return false;
11925             }
11926             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11927                 return false;
11928             }
11929             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11930                 return false;
11931             }
11932             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11933                 return false;
11934             }
11935             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11936             SequenceDbWsTools.obtainSeqInformation( n2 );
11937             if ( !n2.getNodeData().getSequence().getName().equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
11938                 return false;
11939             }
11940             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11941                 return false;
11942             }
11943             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11944                 return false;
11945             }
11946             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11947                 return false;
11948             }
11949             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11950             SequenceDbWsTools.obtainSeqInformation( n3 );
11951             if ( !n3.getNodeData().getSequence().getName()
11952                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11953                 return false;
11954             }
11955             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11956                 return false;
11957             }
11958             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11959                 return false;
11960             }
11961             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11962                 return false;
11963             }
11964         }
11965         catch ( final IOException e ) {
11966             System.out.println();
11967             System.out.println( "the following might be due to absence internet connection:" );
11968             e.printStackTrace( System.out );
11969             return true;
11970         }
11971         catch ( final Exception e ) {
11972             e.printStackTrace();
11973             return false;
11974         }
11975         return true;
11976     }
11977
11978     private static boolean testSequenceIdParsing() {
11979         try {
11980             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11981             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11982                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11983                 if ( id != null ) {
11984                     System.out.println( "value   =" + id.getValue() );
11985                     System.out.println( "provider=" + id.getSource() );
11986                 }
11987                 return false;
11988             }
11989             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11990             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11991                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11992                 if ( id != null ) {
11993                     System.out.println( "value   =" + id.getValue() );
11994                     System.out.println( "provider=" + id.getSource() );
11995                 }
11996                 return false;
11997             }
11998             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11999             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12000                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
12001                 if ( id != null ) {
12002                     System.out.println( "value   =" + id.getValue() );
12003                     System.out.println( "provider=" + id.getSource() );
12004                 }
12005                 return false;
12006             }
12007             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
12008             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12009                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
12010                 if ( id != null ) {
12011                     System.out.println( "value   =" + id.getValue() );
12012                     System.out.println( "provider=" + id.getSource() );
12013                 }
12014                 return false;
12015             }
12016             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
12017             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12018                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
12019                 if ( id != null ) {
12020                     System.out.println( "value   =" + id.getValue() );
12021                     System.out.println( "provider=" + id.getSource() );
12022                 }
12023                 return false;
12024             }
12025             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
12026             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12027                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
12028                 if ( id != null ) {
12029                     System.out.println( "value   =" + id.getValue() );
12030                     System.out.println( "provider=" + id.getSource() );
12031                 }
12032                 return false;
12033             }
12034             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
12035             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12036                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
12037                 if ( id != null ) {
12038                     System.out.println( "value   =" + id.getValue() );
12039                     System.out.println( "provider=" + id.getSource() );
12040                 }
12041                 return false;
12042             }
12043             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
12044             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12045                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
12046                 if ( id != null ) {
12047                     System.out.println( "value   =" + id.getValue() );
12048                     System.out.println( "provider=" + id.getSource() );
12049                 }
12050                 return false;
12051             }
12052             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
12053             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12054                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
12055                 if ( id != null ) {
12056                     System.out.println( "value   =" + id.getValue() );
12057                     System.out.println( "provider=" + id.getSource() );
12058                 }
12059                 return false;
12060             }
12061             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
12062             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12063                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
12064                 if ( id != null ) {
12065                     System.out.println( "value   =" + id.getValue() );
12066                     System.out.println( "provider=" + id.getSource() );
12067                 }
12068                 return false;
12069             }
12070             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
12071             if ( id != null ) {
12072                 System.out.println( "value   =" + id.getValue() );
12073                 System.out.println( "provider=" + id.getSource() );
12074                 return false;
12075             }
12076             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
12077             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12078                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
12079                 if ( id != null ) {
12080                     System.out.println( "value   =" + id.getValue() );
12081                     System.out.println( "provider=" + id.getSource() );
12082                 }
12083                 return false;
12084             }
12085             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
12086             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12087                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
12088                 if ( id != null ) {
12089                     System.out.println( "value   =" + id.getValue() );
12090                     System.out.println( "provider=" + id.getSource() );
12091                 }
12092                 return false;
12093             }
12094             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
12095             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12096                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
12097                 if ( id != null ) {
12098                     System.out.println( "value   =" + id.getValue() );
12099                     System.out.println( "provider=" + id.getSource() );
12100                 }
12101                 return false;
12102             }
12103             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
12104             if ( id != null ) {
12105                 System.out.println( "value   =" + id.getValue() );
12106                 System.out.println( "provider=" + id.getSource() );
12107                 return false;
12108             }
12109         }
12110         catch ( final Exception e ) {
12111             e.printStackTrace( System.out );
12112             return false;
12113         }
12114         return true;
12115     }
12116
12117     private static boolean testSequenceWriter() {
12118         try {
12119             final String n = ForesterUtil.LINE_SEPARATOR;
12120             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
12121                 return false;
12122             }
12123             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
12124                 return false;
12125             }
12126             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
12127                 return false;
12128             }
12129             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
12130                 return false;
12131             }
12132             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
12133                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
12134                 return false;
12135             }
12136             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
12137                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
12138                 return false;
12139             }
12140         }
12141         catch ( final Exception e ) {
12142             e.printStackTrace();
12143             return false;
12144         }
12145         return true;
12146     }
12147
12148     private static boolean testSpecies() {
12149         try {
12150             final Species s1 = new BasicSpecies( "a" );
12151             final Species s2 = new BasicSpecies( "a" );
12152             final Species s3 = new BasicSpecies( "A" );
12153             final Species s4 = new BasicSpecies( "b" );
12154             if ( !s1.equals( s1 ) ) {
12155                 return false;
12156             }
12157             if ( s1.getSpeciesId().equals( "x" ) ) {
12158                 return false;
12159             }
12160             if ( s1.getSpeciesId().equals( null ) ) {
12161                 return false;
12162             }
12163             if ( !s1.equals( s2 ) ) {
12164                 return false;
12165             }
12166             if ( s1.equals( s3 ) ) {
12167                 return false;
12168             }
12169             if ( s1.hashCode() != s1.hashCode() ) {
12170                 return false;
12171             }
12172             if ( s1.hashCode() != s2.hashCode() ) {
12173                 return false;
12174             }
12175             if ( s1.hashCode() == s3.hashCode() ) {
12176                 return false;
12177             }
12178             if ( s1.compareTo( s1 ) != 0 ) {
12179                 return false;
12180             }
12181             if ( s1.compareTo( s2 ) != 0 ) {
12182                 return false;
12183             }
12184             if ( s1.compareTo( s3 ) != 0 ) {
12185                 return false;
12186             }
12187             if ( s1.compareTo( s4 ) >= 0 ) {
12188                 return false;
12189             }
12190             if ( s4.compareTo( s1 ) <= 0 ) {
12191                 return false;
12192             }
12193             if ( !s4.getSpeciesId().equals( "b" ) ) {
12194                 return false;
12195             }
12196             final Species s5 = new BasicSpecies( " C " );
12197             if ( !s5.getSpeciesId().equals( "C" ) ) {
12198                 return false;
12199             }
12200             if ( s5.equals( s1 ) ) {
12201                 return false;
12202             }
12203         }
12204         catch ( final Exception e ) {
12205             e.printStackTrace( System.out );
12206             return false;
12207         }
12208         return true;
12209     }
12210
12211     private static boolean testSplit() {
12212         try {
12213             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12214             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12215             //Archaeopteryx.createApplication( p0 );
12216             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
12217             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12218             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12219             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12220             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12221             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12222             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12223             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12224             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12225             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12226             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
12227             // System.out.println( s0.toString() );
12228             //
12229             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12230             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12231             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12232             if ( s0.match( query_nodes ) ) {
12233                 return false;
12234             }
12235             query_nodes = new HashSet<PhylogenyNode>();
12236             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12237             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12238             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12239             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12240             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12241             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12242             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12243             if ( !s0.match( query_nodes ) ) {
12244                 return false;
12245             }
12246             //
12247             query_nodes = new HashSet<PhylogenyNode>();
12248             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12249             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12250             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12251             if ( !s0.match( query_nodes ) ) {
12252                 return false;
12253             }
12254             //
12255             query_nodes = new HashSet<PhylogenyNode>();
12256             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12257             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12258             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12259             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12260             if ( !s0.match( query_nodes ) ) {
12261                 return false;
12262             }
12263             //
12264             query_nodes = new HashSet<PhylogenyNode>();
12265             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12266             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12267             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12268             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12269             if ( !s0.match( query_nodes ) ) {
12270                 return false;
12271             }
12272             //
12273             query_nodes = new HashSet<PhylogenyNode>();
12274             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12275             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12276             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12277             if ( !s0.match( query_nodes ) ) {
12278                 return false;
12279             }
12280             query_nodes = new HashSet<PhylogenyNode>();
12281             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12282             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12283             if ( !s0.match( query_nodes ) ) {
12284                 return false;
12285             }
12286             query_nodes = new HashSet<PhylogenyNode>();
12287             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12288             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12289             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12290             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12291             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12292             if ( !s0.match( query_nodes ) ) {
12293                 return false;
12294             }
12295             query_nodes = new HashSet<PhylogenyNode>();
12296             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12297             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12298             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12299             if ( !s0.match( query_nodes ) ) {
12300                 return false;
12301             }
12302             query_nodes = new HashSet<PhylogenyNode>();
12303             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12304             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12305             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12306             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12307             if ( !s0.match( query_nodes ) ) {
12308                 return false;
12309             }
12310             query_nodes = new HashSet<PhylogenyNode>();
12311             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12312             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12313             if ( s0.match( query_nodes ) ) {
12314                 return false;
12315             }
12316             query_nodes = new HashSet<PhylogenyNode>();
12317             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12318             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12319             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12320             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12321             if ( s0.match( query_nodes ) ) {
12322                 return false;
12323             }
12324             query_nodes = new HashSet<PhylogenyNode>();
12325             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12326             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12327             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12328             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12329             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12330             if ( s0.match( query_nodes ) ) {
12331                 return false;
12332             }
12333             query_nodes = new HashSet<PhylogenyNode>();
12334             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12335             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12336             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12337             if ( s0.match( query_nodes ) ) {
12338                 return false;
12339             }
12340             query_nodes = new HashSet<PhylogenyNode>();
12341             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12342             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12343             if ( s0.match( query_nodes ) ) {
12344                 return false;
12345             }
12346             query_nodes = new HashSet<PhylogenyNode>();
12347             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12348             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12349             if ( s0.match( query_nodes ) ) {
12350                 return false;
12351             }
12352             query_nodes = new HashSet<PhylogenyNode>();
12353             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12354             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12355             if ( s0.match( query_nodes ) ) {
12356                 return false;
12357             }
12358             query_nodes = new HashSet<PhylogenyNode>();
12359             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12360             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12361             if ( s0.match( query_nodes ) ) {
12362                 return false;
12363             }
12364             query_nodes = new HashSet<PhylogenyNode>();
12365             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12366             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12367             if ( s0.match( query_nodes ) ) {
12368                 return false;
12369             }
12370             query_nodes = new HashSet<PhylogenyNode>();
12371             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12372             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12373             if ( s0.match( query_nodes ) ) {
12374                 return false;
12375             }
12376             query_nodes = new HashSet<PhylogenyNode>();
12377             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12378             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12379             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12380             if ( s0.match( query_nodes ) ) {
12381                 return false;
12382             }
12383             query_nodes = new HashSet<PhylogenyNode>();
12384             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12385             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12386             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12387             if ( s0.match( query_nodes ) ) {
12388                 return false;
12389             }
12390             query_nodes = new HashSet<PhylogenyNode>();
12391             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12392             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12393             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12394             if ( s0.match( query_nodes ) ) {
12395                 return false;
12396             }
12397             query_nodes = new HashSet<PhylogenyNode>();
12398             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12399             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12400             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12401             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12402             if ( s0.match( query_nodes ) ) {
12403                 return false;
12404             }
12405             /////////
12406             //            query_nodes = new HashSet<PhylogenyNode>();
12407             //            query_nodes.add( new PhylogenyNode( "X" ) );
12408             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12409             //            query_nodes.add( new PhylogenyNode( "A" ) );
12410             //            query_nodes.add( new PhylogenyNode( "B" ) );
12411             //            query_nodes.add( new PhylogenyNode( "C" ) );
12412             //            query_nodes.add( new PhylogenyNode( "D" ) );
12413             //            query_nodes.add( new PhylogenyNode( "E" ) );
12414             //            query_nodes.add( new PhylogenyNode( "F" ) );
12415             //            query_nodes.add( new PhylogenyNode( "G" ) );
12416             //            if ( !s0.match( query_nodes ) ) {
12417             //                return false;
12418             //            }
12419             //            query_nodes = new HashSet<PhylogenyNode>();
12420             //            query_nodes.add( new PhylogenyNode( "X" ) );
12421             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12422             //            query_nodes.add( new PhylogenyNode( "A" ) );
12423             //            query_nodes.add( new PhylogenyNode( "B" ) );
12424             //            query_nodes.add( new PhylogenyNode( "C" ) );
12425             //            if ( !s0.match( query_nodes ) ) {
12426             //                return false;
12427             //            }
12428             //            //
12429             //            query_nodes = new HashSet<PhylogenyNode>();
12430             //            query_nodes.add( new PhylogenyNode( "X" ) );
12431             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12432             //            query_nodes.add( new PhylogenyNode( "D" ) );
12433             //            query_nodes.add( new PhylogenyNode( "E" ) );
12434             //            query_nodes.add( new PhylogenyNode( "F" ) );
12435             //            query_nodes.add( new PhylogenyNode( "G" ) );
12436             //            if ( !s0.match( query_nodes ) ) {
12437             //                return false;
12438             //            }
12439             //            //
12440             //            query_nodes = new HashSet<PhylogenyNode>();
12441             //            query_nodes.add( new PhylogenyNode( "X" ) );
12442             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12443             //            query_nodes.add( new PhylogenyNode( "A" ) );
12444             //            query_nodes.add( new PhylogenyNode( "B" ) );
12445             //            query_nodes.add( new PhylogenyNode( "C" ) );
12446             //            query_nodes.add( new PhylogenyNode( "D" ) );
12447             //            if ( !s0.match( query_nodes ) ) {
12448             //                return false;
12449             //            }
12450             //            //
12451             //            query_nodes = new HashSet<PhylogenyNode>();
12452             //            query_nodes.add( new PhylogenyNode( "X" ) );
12453             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12454             //            query_nodes.add( new PhylogenyNode( "E" ) );
12455             //            query_nodes.add( new PhylogenyNode( "F" ) );
12456             //            query_nodes.add( new PhylogenyNode( "G" ) );
12457             //            if ( !s0.match( query_nodes ) ) {
12458             //                return false;
12459             //            }
12460             //            //
12461             //            query_nodes = new HashSet<PhylogenyNode>();
12462             //            query_nodes.add( new PhylogenyNode( "X" ) );
12463             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12464             //            query_nodes.add( new PhylogenyNode( "F" ) );
12465             //            query_nodes.add( new PhylogenyNode( "G" ) );
12466             //            if ( !s0.match( query_nodes ) ) {
12467             //                return false;
12468             //            }
12469             //
12470             query_nodes = new HashSet<PhylogenyNode>();
12471             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12472             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12473             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12474             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12475             if ( s0.match( query_nodes ) ) {
12476                 return false;
12477             }
12478             //
12479             query_nodes = new HashSet<PhylogenyNode>();
12480             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12481             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12482             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12483             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12484             if ( s0.match( query_nodes ) ) {
12485                 return false;
12486             }
12487             ///////////////////////////
12488             //
12489             query_nodes = new HashSet<PhylogenyNode>();
12490             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12491             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12492             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12493             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12494             if ( s0.match( query_nodes ) ) {
12495                 return false;
12496             }
12497             //
12498             query_nodes = new HashSet<PhylogenyNode>();
12499             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12500             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12501             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12502             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12503             if ( s0.match( query_nodes ) ) {
12504                 return false;
12505             }
12506             //
12507             query_nodes = new HashSet<PhylogenyNode>();
12508             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12509             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12510             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12511             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12512             if ( s0.match( query_nodes ) ) {
12513                 return false;
12514             }
12515             //
12516             query_nodes = new HashSet<PhylogenyNode>();
12517             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12518             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12519             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12520             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12521             if ( s0.match( query_nodes ) ) {
12522                 return false;
12523             }
12524             //
12525             query_nodes = new HashSet<PhylogenyNode>();
12526             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12527             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12528             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12529             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12530             if ( s0.match( query_nodes ) ) {
12531                 return false;
12532             }
12533             //
12534             query_nodes = new HashSet<PhylogenyNode>();
12535             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12536             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12537             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12538             if ( s0.match( query_nodes ) ) {
12539                 return false;
12540             }
12541             //
12542             query_nodes = new HashSet<PhylogenyNode>();
12543             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12544             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12545             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12546             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12547             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12548             if ( s0.match( query_nodes ) ) {
12549                 return false;
12550             }
12551             //
12552             query_nodes = new HashSet<PhylogenyNode>();
12553             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12554             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12555             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12556             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12557             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12558             if ( s0.match( query_nodes ) ) {
12559                 return false;
12560             }
12561             //
12562             query_nodes = new HashSet<PhylogenyNode>();
12563             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12564             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12565             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12566             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12567             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12568             if ( s0.match( query_nodes ) ) {
12569                 return false;
12570             }
12571             //
12572             query_nodes = new HashSet<PhylogenyNode>();
12573             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12574             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12575             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12576             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12577             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12578             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12579             if ( s0.match( query_nodes ) ) {
12580                 return false;
12581             }
12582         }
12583         catch ( final Exception e ) {
12584             e.printStackTrace();
12585             return false;
12586         }
12587         return true;
12588     }
12589
12590     private static boolean testSplitStrict() {
12591         try {
12592             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12593             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12594             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
12595             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12596             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12597             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12598             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12599             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12600             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12601             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12602             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
12603             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12604             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12605             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12606             if ( s0.match( query_nodes ) ) {
12607                 return false;
12608             }
12609             query_nodes = new HashSet<PhylogenyNode>();
12610             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12611             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12612             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12613             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12614             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12615             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12616             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12617             if ( !s0.match( query_nodes ) ) {
12618                 return false;
12619             }
12620             //
12621             query_nodes = new HashSet<PhylogenyNode>();
12622             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12623             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12624             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12625             if ( !s0.match( query_nodes ) ) {
12626                 return false;
12627             }
12628             //
12629             query_nodes = new HashSet<PhylogenyNode>();
12630             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12631             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12632             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12633             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12634             if ( !s0.match( query_nodes ) ) {
12635                 return false;
12636             }
12637             //
12638             query_nodes = new HashSet<PhylogenyNode>();
12639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12640             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12641             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12642             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12643             if ( !s0.match( query_nodes ) ) {
12644                 return false;
12645             }
12646             //
12647             query_nodes = new HashSet<PhylogenyNode>();
12648             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12649             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12650             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12651             if ( !s0.match( query_nodes ) ) {
12652                 return false;
12653             }
12654             //
12655             query_nodes = new HashSet<PhylogenyNode>();
12656             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12657             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12658             if ( !s0.match( query_nodes ) ) {
12659                 return false;
12660             }
12661             //
12662             query_nodes = new HashSet<PhylogenyNode>();
12663             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12664             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12665             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12666             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12667             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12668             if ( !s0.match( query_nodes ) ) {
12669                 return false;
12670             }
12671             //
12672             query_nodes = new HashSet<PhylogenyNode>();
12673             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12674             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12675             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12676             if ( !s0.match( query_nodes ) ) {
12677                 return false;
12678             }
12679             //
12680             query_nodes = new HashSet<PhylogenyNode>();
12681             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12682             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12683             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12684             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12685             if ( !s0.match( query_nodes ) ) {
12686                 return false;
12687             }
12688             //
12689             query_nodes = new HashSet<PhylogenyNode>();
12690             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12691             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12692             if ( s0.match( query_nodes ) ) {
12693                 return false;
12694             }
12695             //
12696             query_nodes = new HashSet<PhylogenyNode>();
12697             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12698             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12699             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12700             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12701             if ( s0.match( query_nodes ) ) {
12702                 return false;
12703             }
12704             //
12705             query_nodes = new HashSet<PhylogenyNode>();
12706             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12707             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12708             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12709             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12710             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12711             if ( s0.match( query_nodes ) ) {
12712                 return false;
12713             }
12714             //
12715             query_nodes = new HashSet<PhylogenyNode>();
12716             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12717             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12718             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12719             if ( s0.match( query_nodes ) ) {
12720                 return false;
12721             }
12722             //
12723             query_nodes = new HashSet<PhylogenyNode>();
12724             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12725             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12726             if ( s0.match( query_nodes ) ) {
12727                 return false;
12728             }
12729             //
12730             query_nodes = new HashSet<PhylogenyNode>();
12731             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12732             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12733             if ( s0.match( query_nodes ) ) {
12734                 return false;
12735             }
12736             //
12737             query_nodes = new HashSet<PhylogenyNode>();
12738             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12739             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12740             if ( s0.match( query_nodes ) ) {
12741                 return false;
12742             }
12743             //
12744             query_nodes = new HashSet<PhylogenyNode>();
12745             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12746             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12747             if ( s0.match( query_nodes ) ) {
12748                 return false;
12749             }
12750             //
12751             query_nodes = new HashSet<PhylogenyNode>();
12752             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12753             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12754             if ( s0.match( query_nodes ) ) {
12755                 return false;
12756             }
12757             //
12758             query_nodes = new HashSet<PhylogenyNode>();
12759             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12760             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12761             if ( s0.match( query_nodes ) ) {
12762                 return false;
12763             }
12764             //
12765             query_nodes = new HashSet<PhylogenyNode>();
12766             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12767             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12768             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12769             if ( s0.match( query_nodes ) ) {
12770                 return false;
12771             }
12772             //
12773             query_nodes = new HashSet<PhylogenyNode>();
12774             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12775             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12776             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12777             if ( s0.match( query_nodes ) ) {
12778                 return false;
12779             }
12780             //
12781             query_nodes = new HashSet<PhylogenyNode>();
12782             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12783             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12784             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12785             if ( s0.match( query_nodes ) ) {
12786                 return false;
12787             }
12788             //
12789             query_nodes = new HashSet<PhylogenyNode>();
12790             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12791             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12792             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12793             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12794             if ( s0.match( query_nodes ) ) {
12795                 return false;
12796             }
12797         }
12798         catch ( final Exception e ) {
12799             e.printStackTrace();
12800             return false;
12801         }
12802         return true;
12803     }
12804
12805     private static boolean testSubtreeDeletion() {
12806         try {
12807             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12808             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12809             t1.deleteSubtree( t1.getNode( "A" ), false );
12810             if ( t1.getNumberOfExternalNodes() != 5 ) {
12811                 return false;
12812             }
12813             t1.toNewHampshireX();
12814             t1.deleteSubtree( t1.getNode( "E" ), false );
12815             if ( t1.getNumberOfExternalNodes() != 4 ) {
12816                 return false;
12817             }
12818             t1.toNewHampshireX();
12819             t1.deleteSubtree( t1.getNode( "F" ), false );
12820             if ( t1.getNumberOfExternalNodes() != 3 ) {
12821                 return false;
12822             }
12823             t1.toNewHampshireX();
12824             t1.deleteSubtree( t1.getNode( "D" ), false );
12825             t1.toNewHampshireX();
12826             if ( t1.getNumberOfExternalNodes() != 3 ) {
12827                 return false;
12828             }
12829             t1.deleteSubtree( t1.getNode( "def" ), false );
12830             t1.toNewHampshireX();
12831             if ( t1.getNumberOfExternalNodes() != 2 ) {
12832                 return false;
12833             }
12834             t1.deleteSubtree( t1.getNode( "B" ), false );
12835             t1.toNewHampshireX();
12836             if ( t1.getNumberOfExternalNodes() != 1 ) {
12837                 return false;
12838             }
12839             t1.deleteSubtree( t1.getNode( "C" ), false );
12840             t1.toNewHampshireX();
12841             if ( t1.getNumberOfExternalNodes() != 1 ) {
12842                 return false;
12843             }
12844             t1.deleteSubtree( t1.getNode( "abc" ), false );
12845             t1.toNewHampshireX();
12846             if ( t1.getNumberOfExternalNodes() != 1 ) {
12847                 return false;
12848             }
12849             t1.deleteSubtree( t1.getNode( "r" ), false );
12850             if ( t1.getNumberOfExternalNodes() != 0 ) {
12851                 return false;
12852             }
12853             if ( !t1.isEmpty() ) {
12854                 return false;
12855             }
12856             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12857             t2.deleteSubtree( t2.getNode( "A" ), false );
12858             t2.toNewHampshireX();
12859             if ( t2.getNumberOfExternalNodes() != 5 ) {
12860                 return false;
12861             }
12862             t2.deleteSubtree( t2.getNode( "abc" ), false );
12863             t2.toNewHampshireX();
12864             if ( t2.getNumberOfExternalNodes() != 3 ) {
12865                 return false;
12866             }
12867             t2.deleteSubtree( t2.getNode( "def" ), false );
12868             t2.toNewHampshireX();
12869             if ( t2.getNumberOfExternalNodes() != 1 ) {
12870                 return false;
12871             }
12872         }
12873         catch ( final Exception e ) {
12874             e.printStackTrace( System.out );
12875             return false;
12876         }
12877         return true;
12878     }
12879
12880     private static boolean testSupportCount() {
12881         try {
12882             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12883             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12884             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12885                     + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12886                     + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12887                     + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12888                     + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12889                     new NHXParser() );
12890             SupportCount.count( t0_1, phylogenies_1, true, false );
12891             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12892             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12893                     + "(((((A,B),C),D),E),((F,G),X))"
12894                     + "(((((A,Y),B),C),D),((F,G),E))"
12895                     + "(((((A,B),C),D),E),(F,G))"
12896                     + "(((((A,B),C),D),E),(F,G))"
12897                     + "(((((A,B),C),D),E),(F,G))"
12898                     + "(((((A,B),C),D),E),(F,G),Z)"
12899                     + "(((((A,B),C),D),E),(F,G))"
12900                     + "((((((A,B),C),D),E),F),G)"
12901                     + "(((((X,Y),F,G),E),((A,B),C)),D)",
12902                     new NHXParser() );
12903             SupportCount.count( t0_2, phylogenies_2, true, false );
12904             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12905             while ( it.hasNext() ) {
12906                 final PhylogenyNode n = it.next();
12907                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12908                     return false;
12909                 }
12910             }
12911             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12912             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12913                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12914             SupportCount.count( t0_3, phylogenies_3, true, false );
12915             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12916             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12917                 return false;
12918             }
12919             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12920                 return false;
12921             }
12922             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12923                 return false;
12924             }
12925             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12926                 return false;
12927             }
12928             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12929                 return false;
12930             }
12931             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12932                 return false;
12933             }
12934             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12935                 return false;
12936             }
12937             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12938                 return false;
12939             }
12940             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12941                 return false;
12942             }
12943             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12944                 return false;
12945             }
12946             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12947             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12948                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12949             SupportCount.count( t0_4, phylogenies_4, true, false );
12950             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12951             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12952                 return false;
12953             }
12954             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12955                 return false;
12956             }
12957             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12958                 return false;
12959             }
12960             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12961                 return false;
12962             }
12963             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12964                 return false;
12965             }
12966             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12967                 return false;
12968             }
12969             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12970                 return false;
12971             }
12972             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12973                 return false;
12974             }
12975             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12976                 return false;
12977             }
12978             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12979                 return false;
12980             }
12981             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12982             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12983             double d = SupportCount.compare( b1, a, true, true, true );
12984             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12985                 return false;
12986             }
12987             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12988             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12989             d = SupportCount.compare( b2, a, true, true, true );
12990             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12991                 return false;
12992             }
12993             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12994             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12995             d = SupportCount.compare( b3, a, true, true, true );
12996             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12997                 return false;
12998             }
12999             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
13000             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
13001             d = SupportCount.compare( b4, a, true, true, false );
13002             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
13003                 return false;
13004             }
13005         }
13006         catch ( final Exception e ) {
13007             e.printStackTrace( System.out );
13008             return false;
13009         }
13010         return true;
13011     }
13012
13013     private static boolean testSupportTransfer() {
13014         try {
13015             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13016             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)",
13017                                                  new NHXParser() )[ 0 ];
13018             final Phylogeny p2 = factory
13019                     .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 ];
13020             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
13021                 return false;
13022             }
13023             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
13024                 return false;
13025             }
13026             support_transfer.moveBranchLengthsToBootstrap( p1 );
13027             support_transfer.transferSupportValues( p1, p2 );
13028             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
13029                 return false;
13030             }
13031             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
13032                 return false;
13033             }
13034             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
13035                 return false;
13036             }
13037             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
13038                 return false;
13039             }
13040             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
13041                 return false;
13042             }
13043             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
13044                 return false;
13045             }
13046             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
13047                 return false;
13048             }
13049             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
13050                 return false;
13051             }
13052         }
13053         catch ( final Exception e ) {
13054             e.printStackTrace( System.out );
13055             return false;
13056         }
13057         return true;
13058     }
13059
13060     private static boolean testTaxonomyExtraction() {
13061         try {
13062             final PhylogenyNode n0 = PhylogenyNode
13063                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13064             if ( n0.getNodeData().isHasTaxonomy() ) {
13065                 return false;
13066             }
13067             final PhylogenyNode n1 = PhylogenyNode
13068                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13069             if ( n1.getNodeData().isHasTaxonomy() ) {
13070                 System.out.println( n1.toString() );
13071                 return false;
13072             }
13073             final PhylogenyNode n2x = PhylogenyNode
13074                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13075             if ( n2x.getNodeData().isHasTaxonomy() ) {
13076                 return false;
13077             }
13078             final PhylogenyNode n3 = PhylogenyNode
13079                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13080             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13081                 System.out.println( n3.toString() );
13082                 return false;
13083             }
13084             final PhylogenyNode n4 = PhylogenyNode
13085                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13086             if ( n4.getNodeData().isHasTaxonomy() ) {
13087                 System.out.println( n4.toString() );
13088                 return false;
13089             }
13090             final PhylogenyNode n5 = PhylogenyNode
13091                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13092             if ( n5.getNodeData().isHasTaxonomy() ) {
13093                 System.out.println( n5.toString() );
13094                 return false;
13095             }
13096             final PhylogenyNode n6 = PhylogenyNode
13097                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13098             if ( n6.getNodeData().isHasTaxonomy() ) {
13099                 System.out.println( n6.toString() );
13100                 return false;
13101             }
13102             final PhylogenyNode n7 = PhylogenyNode
13103                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13104             if ( n7.getNodeData().isHasTaxonomy() ) {
13105                 System.out.println( n7.toString() );
13106                 return false;
13107             }
13108             final PhylogenyNode n8 = PhylogenyNode
13109                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13110             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13111                 System.out.println( n8.toString() );
13112                 return false;
13113             }
13114             final PhylogenyNode n9 = PhylogenyNode
13115                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13116             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13117                 System.out.println( n9.toString() );
13118                 return false;
13119             }
13120             final PhylogenyNode n10x = PhylogenyNode
13121                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13122             if ( n10x.getNodeData().isHasTaxonomy() ) {
13123                 System.out.println( n10x.toString() );
13124                 return false;
13125             }
13126             final PhylogenyNode n10xx = PhylogenyNode
13127                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13128             if ( n10xx.getNodeData().isHasTaxonomy() ) {
13129                 System.out.println( n10xx.toString() );
13130                 return false;
13131             }
13132             final PhylogenyNode n10 = PhylogenyNode
13133                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13134             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
13135                 System.out.println( n10.toString() );
13136                 return false;
13137             }
13138             final PhylogenyNode n11 = PhylogenyNode
13139                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13140             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13141                 System.out.println( n11.toString() );
13142                 return false;
13143             }
13144             final PhylogenyNode n12 = PhylogenyNode
13145                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
13146                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13147             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13148                 System.out.println( n12.toString() );
13149                 return false;
13150             }
13151             final PhylogenyNode n13 = PhylogenyNode
13152                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13153             if ( n13.getNodeData().isHasTaxonomy() ) {
13154                 System.out.println( n13.toString() );
13155                 return false;
13156             }
13157             final PhylogenyNode n14 = PhylogenyNode
13158                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13159             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13160                 System.out.println( n14.toString() );
13161                 return false;
13162             }
13163             final PhylogenyNode n15 = PhylogenyNode
13164                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13165             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13166                 System.out.println( n15.toString() );
13167                 return false;
13168             }
13169             final PhylogenyNode n16 = PhylogenyNode
13170                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13171             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13172                 System.out.println( n16.toString() );
13173                 return false;
13174             }
13175             final PhylogenyNode n17 = PhylogenyNode
13176                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13177             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13178                 System.out.println( n17.toString() );
13179                 return false;
13180             }
13181             final PhylogenyNode n18 = PhylogenyNode
13182                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13183             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13184                 System.out.println( n18.toString() );
13185                 return false;
13186             }
13187             final PhylogenyNode n19 = PhylogenyNode
13188                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
13189                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13190             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13191                 System.out.println( n19.toString() );
13192                 return false;
13193             }
13194             final PhylogenyNode n20 = PhylogenyNode
13195                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13196             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13197                 System.out.println( n20.toString() );
13198                 return false;
13199             }
13200             final PhylogenyNode n21 = PhylogenyNode
13201                     .createInstanceFromNhxString( "Mus musculus musculus K392",
13202                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13203             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13204                 System.out.println( n21.toString() );
13205                 return false;
13206             }
13207             final PhylogenyNode n23 = PhylogenyNode
13208                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
13209                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13210             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13211                 System.out.println( n23.toString() );
13212                 return false;
13213             }
13214             final PhylogenyNode n24 = PhylogenyNode
13215                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13216             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13217                 System.out.println( n24.toString() );
13218                 return false;
13219             }
13220             //
13221             final PhylogenyNode n25 = PhylogenyNode
13222                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
13223                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13224             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
13225                 System.out.println( n25.toString() );
13226                 return false;
13227             }
13228             final PhylogenyNode n26 = PhylogenyNode
13229                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
13230                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13231             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13232                 System.out.println( n26.toString() );
13233                 return false;
13234             }
13235             final PhylogenyNode n27 = PhylogenyNode
13236                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13237             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13238                 System.out.println( n27.toString() );
13239                 return false;
13240             }
13241         }
13242         catch ( final Exception e ) {
13243             e.printStackTrace( System.out );
13244             return false;
13245         }
13246         return true;
13247     }
13248
13249     private static boolean testTreeCopy() {
13250         try {
13251             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
13252             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
13253             final Phylogeny t1 = t0.copy();
13254             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
13255                 return false;
13256             }
13257             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13258                 return false;
13259             }
13260             t0.deleteSubtree( t0.getNode( "c" ), true );
13261             t0.deleteSubtree( t0.getNode( "a" ), true );
13262             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
13263             t0.getNode( "b" ).setName( "Bee" );
13264             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
13265                 return false;
13266             }
13267             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13268                 return false;
13269             }
13270             t0.deleteSubtree( t0.getNode( "e" ), true );
13271             t0.deleteSubtree( t0.getNode( "Bee" ), true );
13272             t0.deleteSubtree( t0.getNode( "d" ), true );
13273             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13274                 return false;
13275             }
13276         }
13277         catch ( final Exception e ) {
13278             e.printStackTrace();
13279             return false;
13280         }
13281         return true;
13282     }
13283
13284     private static boolean testTreeMethods() {
13285         try {
13286             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13287             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
13288             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
13289             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
13290                 System.out.println( t0.toNewHampshireX() );
13291                 return false;
13292             }
13293             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
13294             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
13295             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
13296                 return false;
13297             }
13298             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
13299                 return false;
13300             }
13301             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
13302                 return false;
13303             }
13304         }
13305         catch ( final Exception e ) {
13306             e.printStackTrace( System.out );
13307             return false;
13308         }
13309         return true;
13310     }
13311
13312     private static boolean testUniprotEntryRetrieval() {
13313         try {
13314             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 5000 );
13315             if ( !entry.getAccession().equals( "P12345" ) ) {
13316                 return false;
13317             }
13318             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
13319                 return false;
13320             }
13321             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
13322                 return false;
13323             }
13324             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
13325                 return false;
13326             }
13327             if ( !entry.getGeneName().equals( "GOT2" ) ) {
13328                 return false;
13329             }
13330             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
13331                 return false;
13332             }
13333             if ( entry.getMolecularSequence() == null ) {
13334                 return false;
13335             }
13336             if ( !entry
13337                     .getMolecularSequence()
13338                     .getMolecularSequenceAsString()
13339                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
13340                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
13341                 System.out.println( "got: " + entry.getMolecularSequence().getMolecularSequenceAsString() );
13342                 System.out.println( "expected something else." );
13343                 return false;
13344             }
13345         }
13346         catch ( final IOException e ) {
13347             System.out.println();
13348             System.out.println( "the following might be due to absence internet connection:" );
13349             e.printStackTrace( System.out );
13350             return true;
13351         }
13352         catch ( final NullPointerException f ) {
13353             f.printStackTrace( System.out );
13354             return false;
13355         }
13356         catch ( final Exception e ) {
13357             return false;
13358         }
13359         return true;
13360     }
13361
13362     private static boolean testUniprotTaxonomySearch() {
13363         try {
13364             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
13365                                                                                                  10 );
13366             if ( results.size() != 1 ) {
13367                 return false;
13368             }
13369             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13370                 return false;
13371             }
13372             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13373                 return false;
13374             }
13375             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13376                 return false;
13377             }
13378             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13379                 return false;
13380             }
13381             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13382                 return false;
13383             }
13384             results = null;
13385             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
13386             if ( results.size() != 1 ) {
13387                 return false;
13388             }
13389             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13390                 return false;
13391             }
13392             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13393                 return false;
13394             }
13395             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13396                 return false;
13397             }
13398             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13399                 return false;
13400             }
13401             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13402                 return false;
13403             }
13404             results = null;
13405             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
13406             if ( results.size() != 1 ) {
13407                 return false;
13408             }
13409             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13410                 return false;
13411             }
13412             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13413                 return false;
13414             }
13415             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13416                 return false;
13417             }
13418             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13419                 return false;
13420             }
13421             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13422                 return false;
13423             }
13424             results = null;
13425             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
13426             if ( results.size() != 1 ) {
13427                 return false;
13428             }
13429             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13430                 return false;
13431             }
13432             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13433                 return false;
13434             }
13435             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13436                 return false;
13437             }
13438             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13439                 return false;
13440             }
13441             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13442                 return false;
13443             }
13444             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
13445                 return false;
13446             }
13447             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
13448                 return false;
13449             }
13450             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13451                     .equals( "Nematostella vectensis" ) ) {
13452                 System.out.println( results.get( 0 ).getLineage() );
13453                 return false;
13454             }
13455             //
13456             results = null;
13457             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
13458             if ( results.size() != 1 ) {
13459                 return false;
13460             }
13461             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13462                 return false;
13463             }
13464             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13465                 return false;
13466             }
13467             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13468                 return false;
13469             }
13470             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13471                 return false;
13472             }
13473             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13474                 return false;
13475             }
13476             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13477                     .equals( "Xenopus tropicalis" ) ) {
13478                 System.out.println( results.get( 0 ).getLineage() );
13479                 return false;
13480             }
13481             //
13482             results = null;
13483             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
13484             if ( results.size() != 1 ) {
13485                 return false;
13486             }
13487             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13488                 return false;
13489             }
13490             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13491                 return false;
13492             }
13493             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13494                 return false;
13495             }
13496             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13497                 return false;
13498             }
13499             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13500                 return false;
13501             }
13502             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13503                     .equals( "Xenopus tropicalis" ) ) {
13504                 System.out.println( results.get( 0 ).getLineage() );
13505                 return false;
13506             }
13507             //
13508             results = null;
13509             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
13510             if ( results.size() != 1 ) {
13511                 return false;
13512             }
13513             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13514                 return false;
13515             }
13516             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13517                 return false;
13518             }
13519             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13520                 return false;
13521             }
13522             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13523                 return false;
13524             }
13525             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13526                 return false;
13527             }
13528             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13529                     .equals( "Xenopus tropicalis" ) ) {
13530                 System.out.println( results.get( 0 ).getLineage() );
13531                 return false;
13532             }
13533         }
13534         catch ( final IOException e ) {
13535             System.out.println();
13536             System.out.println( "the following might be due to absence internet connection:" );
13537             e.printStackTrace( System.out );
13538             return true;
13539         }
13540         catch ( final Exception e ) {
13541             return false;
13542         }
13543         return true;
13544     }
13545     
13546     
13547 }