8ca0bd60c81c208a4303ac179f10fe6bffce01c1
[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( "NHX parsing iterating: " );
348         if ( Test.testNHParsingIter() ) {
349             System.out.println( "OK." );
350             succeeded++;
351         }
352         else {
353             System.out.println( "failed." );
354             failed++;
355         }
356         System.out.print( "NH parsing: " );
357         if ( Test.testNHParsing() ) {
358             System.out.println( "OK." );
359             succeeded++;
360         }
361         else {
362             System.out.println( "failed." );
363             failed++;
364         }
365         System.out.print( "NH parsing - special chars: " );
366         if ( Test.testNHParsingSpecialChars() ) {
367             System.out.println( "OK." );
368             succeeded++;
369         }
370         else {
371             System.out.println( "failed." );
372             failed++;
373         }
374         System.out.print( "Conversion to NHX (node level): " );
375         if ( Test.testNHXconversion() ) {
376             System.out.println( "OK." );
377             succeeded++;
378         }
379         else {
380             System.out.println( "failed." );
381             failed++;
382         }
383         System.out.print( "NHX parsing: " );
384         if ( Test.testNHXParsing() ) {
385             System.out.println( "OK." );
386             succeeded++;
387         }
388         else {
389             System.out.println( "failed." );
390             failed++;
391         }
392         System.out.print( "NHX parsing with quotes: " );
393         if ( Test.testNHXParsingQuotes() ) {
394             System.out.println( "OK." );
395             succeeded++;
396         }
397         else {
398             System.out.println( "failed." );
399             failed++;
400         }
401         System.out.print( "NHX parsing (MrBayes): " );
402         if ( Test.testNHXParsingMB() ) {
403             System.out.println( "OK." );
404             succeeded++;
405         }
406         else {
407             System.out.println( "failed." );
408             failed++;
409         }
410         System.out.print( "Nexus characters parsing: " );
411         if ( Test.testNexusCharactersParsing() ) {
412             System.out.println( "OK." );
413             succeeded++;
414         }
415         else {
416             System.out.println( "failed." );
417             failed++;
418         }
419         System.out.print( "Nexus tree parsing iterating: " );
420         if ( Test.testNexusTreeParsingIterating() ) {
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: " );
429         if ( Test.testNexusTreeParsing() ) {
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 (translating): " );
438         if ( Test.testNexusTreeParsingTranslating() ) {
439             System.out.println( "OK." );
440             succeeded++;
441         }
442         else {
443             System.out.println( "failed." );
444             failed++;
445         }
446         System.out.print( "Nexus matrix parsing: " );
447         if ( Test.testNexusMatrixParsing() ) {
448             System.out.println( "OK." );
449             succeeded++;
450         }
451         else {
452             System.out.println( "failed." );
453             failed++;
454         }
455         System.out.print( "Basic phyloXML parsing: " );
456         if ( Test.testBasicPhyloXMLparsing() ) {
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 (validating against schema): " );
465         if ( testBasicPhyloXMLparsingValidating() ) {
466             System.out.println( "OK." );
467             succeeded++;
468         }
469         else {
470             System.out.println( "failed." );
471             failed++;
472         }
473         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
474         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
475             System.out.println( "OK." );
476             succeeded++;
477         }
478         else {
479             System.out.println( "failed." );
480             failed++;
481         }
482         System.out.print( "phyloXML Distribution Element: " );
483         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
484             System.out.println( "OK." );
485             succeeded++;
486         }
487         else {
488             System.out.println( "failed." );
489             failed++;
490         }
491         System.out.print( "Tol XML parsing: " );
492         if ( Test.testBasicTolXMLparsing() ) {
493             System.out.println( "OK." );
494             succeeded++;
495         }
496         else {
497             System.out.println( "failed." );
498             failed++;
499         }
500         System.out.print( "UTF-8 parsing from file: " );
501         if ( Test.testUTF8ParsingFromFile() ) {
502             System.out.println( "OK." );
503             succeeded++;
504         }
505         else {
506             System.out.println( "failed." );
507             failed++;
508         }
509         System.out.print( "Copying of node data: " );
510         if ( Test.testCopyOfNodeData() ) {
511             System.out.println( "OK." );
512             succeeded++;
513         }
514         else {
515             System.out.println( "failed." );
516             failed++;
517         }
518         System.out.print( "Tree copy: " );
519         if ( Test.testTreeCopy() ) {
520             System.out.println( "OK." );
521             succeeded++;
522         }
523         else {
524             System.out.println( "failed." );
525             failed++;
526         }
527         System.out.print( "Basic tree methods: " );
528         if ( Test.testBasicTreeMethods() ) {
529             System.out.println( "OK." );
530             succeeded++;
531         }
532         else {
533             System.out.println( "failed." );
534             failed++;
535         }
536         System.out.print( "Tree methods: " );
537         if ( Test.testTreeMethods() ) {
538             System.out.println( "OK." );
539             succeeded++;
540         }
541         else {
542             System.out.println( "failed." );
543             failed++;
544         }
545         System.out.print( "Postorder Iterator: " );
546         if ( Test.testPostOrderIterator() ) {
547             System.out.println( "OK." );
548             succeeded++;
549         }
550         else {
551             System.out.println( "failed." );
552             failed++;
553         }
554         System.out.print( "Preorder Iterator: " );
555         if ( Test.testPreOrderIterator() ) {
556             System.out.println( "OK." );
557             succeeded++;
558         }
559         else {
560             System.out.println( "failed." );
561             failed++;
562         }
563         System.out.print( "Levelorder Iterator: " );
564         if ( Test.testLevelOrderIterator() ) {
565             System.out.println( "OK." );
566             succeeded++;
567         }
568         else {
569             System.out.println( "failed." );
570             failed++;
571         }
572         System.out.print( "Re-id methods: " );
573         if ( Test.testReIdMethods() ) {
574             System.out.println( "OK." );
575             succeeded++;
576         }
577         else {
578             System.out.println( "failed." );
579             failed++;
580         }
581         System.out.print( "Methods on last external nodes: " );
582         if ( Test.testLastExternalNodeMethods() ) {
583             System.out.println( "OK." );
584             succeeded++;
585         }
586         else {
587             System.out.println( "failed." );
588             failed++;
589         }
590         System.out.print( "Methods on external nodes: " );
591         if ( Test.testExternalNodeRelatedMethods() ) {
592             System.out.println( "OK." );
593             succeeded++;
594         }
595         else {
596             System.out.println( "failed." );
597             failed++;
598         }
599         System.out.print( "Deletion of external nodes: " );
600         if ( Test.testDeletionOfExternalNodes() ) {
601             System.out.println( "OK." );
602             succeeded++;
603         }
604         else {
605             System.out.println( "failed." );
606             failed++;
607         }
608         System.out.print( "Subtree deletion: " );
609         if ( Test.testSubtreeDeletion() ) {
610             System.out.println( "OK." );
611             succeeded++;
612         }
613         else {
614             System.out.println( "failed." );
615             failed++;
616         }
617         System.out.print( "Phylogeny branch: " );
618         if ( Test.testPhylogenyBranch() ) {
619             System.out.println( "OK." );
620             succeeded++;
621         }
622         else {
623             System.out.println( "failed." );
624             failed++;
625         }
626         System.out.print( "Rerooting: " );
627         if ( Test.testRerooting() ) {
628             System.out.println( "OK." );
629             succeeded++;
630         }
631         else {
632             System.out.println( "failed." );
633             failed++;
634         }
635         System.out.print( "Mipoint rooting: " );
636         if ( Test.testMidpointrooting() ) {
637             System.out.println( "OK." );
638             succeeded++;
639         }
640         else {
641             System.out.println( "failed." );
642             failed++;
643         }
644         System.out.print( "Node removal: " );
645         if ( Test.testNodeRemoval() ) {
646             System.out.println( "OK." );
647             succeeded++;
648         }
649         else {
650             System.out.println( "failed." );
651             failed++;
652         }
653         System.out.print( "Support count: " );
654         if ( Test.testSupportCount() ) {
655             System.out.println( "OK." );
656             succeeded++;
657         }
658         else {
659             System.out.println( "failed." );
660             failed++;
661         }
662         System.out.print( "Support transfer: " );
663         if ( Test.testSupportTransfer() ) {
664             System.out.println( "OK." );
665             succeeded++;
666         }
667         else {
668             System.out.println( "failed." );
669             failed++;
670         }
671         System.out.print( "Finding of LCA: " );
672         if ( Test.testGetLCA() ) {
673             System.out.println( "OK." );
674             succeeded++;
675         }
676         else {
677             System.out.println( "failed." );
678             failed++;
679         }
680         System.out.print( "Finding of LCA 2: " );
681         if ( Test.testGetLCA2() ) {
682             System.out.println( "OK." );
683             succeeded++;
684         }
685         else {
686             System.out.println( "failed." );
687             failed++;
688         }
689         System.out.print( "Calculation of distance between nodes: " );
690         if ( Test.testGetDistance() ) {
691             System.out.println( "OK." );
692             succeeded++;
693         }
694         else {
695             System.out.println( "failed." );
696             failed++;
697         }
698         System.out.print( "Descriptive statistics: " );
699         if ( Test.testDescriptiveStatistics() ) {
700             System.out.println( "OK." );
701             succeeded++;
702         }
703         else {
704             System.out.println( "failed." );
705             failed++;
706         }
707         System.out.print( "Data objects and methods: " );
708         if ( Test.testDataObjects() ) {
709             System.out.println( "OK." );
710             succeeded++;
711         }
712         else {
713             System.out.println( "failed." );
714             failed++;
715         }
716         System.out.print( "Properties map: " );
717         if ( Test.testPropertiesMap() ) {
718             System.out.println( "OK." );
719             succeeded++;
720         }
721         else {
722             System.out.println( "failed." );
723             failed++;
724         }
725         System.out.print( "SDIse: " );
726         if ( Test.testSDIse() ) {
727             System.out.println( "OK." );
728             succeeded++;
729         }
730         else {
731             System.out.println( "failed." );
732             failed++;
733         }
734         System.out.print( "SDIunrooted: " );
735         if ( Test.testSDIunrooted() ) {
736             System.out.println( "OK." );
737             succeeded++;
738         }
739         else {
740             System.out.println( "failed." );
741             failed++;
742         }
743         System.out.print( "GSDI: " );
744         if ( TestGSDI.test() ) {
745             System.out.println( "OK." );
746             succeeded++;
747         }
748         else {
749             System.out.println( "failed." );
750             failed++;
751         }
752         System.out.print( "RIO: " );
753         if ( TestRIO.test() ) {
754             System.out.println( "OK." );
755             succeeded++;
756         }
757         else {
758             System.out.println( "failed." );
759             failed++;
760         }
761         System.out.print( "Phylogeny reconstruction:" );
762         System.out.println();
763         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
764             System.out.println( "OK." );
765             succeeded++;
766         }
767         else {
768             System.out.println( "failed." );
769             failed++;
770         }
771         System.out.print( "Analysis of domain architectures: " );
772         System.out.println();
773         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
774             System.out.println( "OK." );
775             succeeded++;
776         }
777         else {
778             System.out.println( "failed." );
779             failed++;
780         }
781         System.out.print( "GO: " );
782         System.out.println();
783         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
784             System.out.println( "OK." );
785             succeeded++;
786         }
787         else {
788             System.out.println( "failed." );
789             failed++;
790         }
791         System.out.print( "Modeling tools: " );
792         if ( TestPccx.test() ) {
793             System.out.println( "OK." );
794             succeeded++;
795         }
796         else {
797             System.out.println( "failed." );
798             failed++;
799         }
800         System.out.print( "Split Matrix strict: " );
801         if ( Test.testSplitStrict() ) {
802             System.out.println( "OK." );
803             succeeded++;
804         }
805         else {
806             System.out.println( "failed." );
807             failed++;
808         }
809         System.out.print( "Split Matrix: " );
810         if ( Test.testSplit() ) {
811             System.out.println( "OK." );
812             succeeded++;
813         }
814         else {
815             System.out.println( "failed." );
816             failed++;
817         }
818         System.out.print( "Confidence Assessor: " );
819         if ( Test.testConfidenceAssessor() ) {
820             System.out.println( "OK." );
821             succeeded++;
822         }
823         else {
824             System.out.println( "failed." );
825             failed++;
826         }
827         System.out.print( "Basic table: " );
828         if ( Test.testBasicTable() ) {
829             System.out.println( "OK." );
830             succeeded++;
831         }
832         else {
833             System.out.println( "failed." );
834             failed++;
835         }
836         System.out.print( "General table: " );
837         if ( Test.testGeneralTable() ) {
838             System.out.println( "OK." );
839             succeeded++;
840         }
841         else {
842             System.out.println( "failed." );
843             failed++;
844         }
845         System.out.print( "Amino acid sequence: " );
846         if ( Test.testAminoAcidSequence() ) {
847             System.out.println( "OK." );
848             succeeded++;
849         }
850         else {
851             System.out.println( "failed." );
852             failed++;
853         }
854         System.out.print( "General MSA parser: " );
855         if ( Test.testGeneralMsaParser() ) {
856             System.out.println( "OK." );
857             succeeded++;
858         }
859         else {
860             System.out.println( "failed." );
861             failed++;
862         }
863         System.out.print( "Fasta parser for msa: " );
864         if ( Test.testFastaParser() ) {
865             System.out.println( "OK." );
866             succeeded++;
867         }
868         else {
869             System.out.println( "failed." );
870             failed++;
871         }
872         System.out.print( "Creation of balanced phylogeny: " );
873         if ( Test.testCreateBalancedPhylogeny() ) {
874             System.out.println( "OK." );
875             succeeded++;
876         }
877         else {
878             System.out.println( "failed." );
879             failed++;
880         }
881         System.out.print( "Genbank accessor parsing: " );
882         if ( Test.testGenbankAccessorParsing() ) {
883             System.out.println( "OK." );
884             succeeded++;
885         }
886         else {
887             System.out.println( "failed." );
888             failed++;
889         }
890         String path = "";
891         final String os = ForesterUtil.OS_NAME.toLowerCase();
892         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
893             path = "/usr/local/bin/mafft";
894         }
895         else if ( os.indexOf( "win" ) >= 0 ) {
896             path = "C:\\Program Files\\mafft-win\\mafft.bat";
897         }
898         else {
899             path = "mafft";
900             if ( !MsaInferrer.isInstalled( path ) ) {
901                 path = "/usr/bin/mafft";
902             }
903             if ( !MsaInferrer.isInstalled( path ) ) {
904                 path = "/usr/local/bin/mafft";
905             }
906         }
907         if ( MsaInferrer.isInstalled( path ) ) {
908             System.out.print( "MAFFT (external program): " );
909             if ( Test.testMafft( path ) ) {
910                 System.out.println( "OK." );
911                 succeeded++;
912             }
913             else {
914                 System.out.println( "failed [will not count towards failed tests]" );
915             }
916         }
917         System.out.print( "Next nodes with collapsed: " );
918         if ( Test.testNextNodeWithCollapsing() ) {
919             System.out.println( "OK." );
920             succeeded++;
921         }
922         else {
923             System.out.println( "failed." );
924             failed++;
925         }
926         System.out.print( "Simple MSA quality: " );
927         if ( Test.testMsaQualityMethod() ) {
928             System.out.println( "OK." );
929             succeeded++;
930         }
931         else {
932             System.out.println( "failed." );
933             failed++;
934         }
935         System.out.print( "Deleteable MSA: " );
936         if ( Test.testDeleteableMsa() ) {
937             System.out.println( "OK." );
938             succeeded++;
939         }
940         else {
941             System.out.println( "failed." );
942             failed++;
943         }
944         System.out.print( "MSA entropy: " );
945         if ( Test.testMsaEntropy() ) {
946             System.out.println( "OK." );
947             succeeded++;
948         }
949         else {
950             System.out.println( "failed." );
951             failed++;
952         }
953         if ( PERFORM_DB_TESTS ) {
954             System.out.print( "Uniprot Entry Retrieval: " );
955             if ( Test.testUniprotEntryRetrieval() ) {
956                 System.out.println( "OK." );
957                 succeeded++;
958             }
959             else {
960                 System.out.println( "failed." );
961                 failed++;
962             }
963             System.out.print( "Ebi Entry Retrieval: " );
964             if ( Test.testEbiEntryRetrieval() ) {
965                 System.out.println( "OK." );
966                 succeeded++;
967             }
968             else {
969                 System.out.println( "failed." );
970                 failed++;
971             }
972             System.out.print( "Sequence DB tools 2: " );
973             if ( testSequenceDbWsTools2() ) {
974                 System.out.println( "OK." );
975                 succeeded++;
976             }
977             else {
978                 System.out.println( "failed." );
979                 failed++;
980                 System.exit( -1 );
981             }
982             System.out.print( "Uniprot Taxonomy Search: " );
983             if ( Test.testUniprotTaxonomySearch() ) {
984                 System.out.println( "OK." );
985                 succeeded++;
986             }
987             else {
988                 System.out.println( "failed." );
989                 failed++;
990             }
991         }
992         if ( PERFORM_WEB_TREE_ACCESS ) {
993             System.out.print( "TreeBase acccess: " );
994             if ( Test.testTreeBaseReading() ) {
995                 System.out.println( "OK." );
996                 succeeded++;
997             }
998             else {
999                 System.out.println( "failed." );
1000                 failed++;
1001             }
1002             System.out.print( "ToL access: " );
1003             if ( Test.testToLReading() ) {
1004                 System.out.println( "OK." );
1005                 succeeded++;
1006             }
1007             else {
1008                 System.out.println( "failed." );
1009                 failed++;
1010             }
1011             System.out.print( "NHX parsing from URL: " );
1012             if ( Test.testNHXparsingFromURL() ) {
1013                 System.out.println( "OK." );
1014                 succeeded++;
1015             }
1016             else {
1017                 System.out.println( "failed." );
1018                 failed++;
1019             }
1020             System.out.print( "NHX parsing from URL 2: " );
1021             if ( Test.testNHXparsingFromURL2() ) {
1022                 System.out.println( "OK." );
1023                 succeeded++;
1024             }
1025             else {
1026                 System.out.println( "failed." );
1027                 failed++;
1028             }
1029             System.out.print( "phyloXML parsing from URL: " );
1030             if ( Test.testPhyloXMLparsingFromURL() ) {
1031                 System.out.println( "OK." );
1032                 succeeded++;
1033             }
1034             else {
1035                 System.out.println( "failed." );
1036                 failed++;
1037             }
1038             System.out.print( "TreeFam access: " );
1039             if ( Test.testTreeFamReading() ) {
1040                 System.out.println( "OK." );
1041                 succeeded++;
1042             }
1043             else {
1044                 System.out.println( "failed." );
1045                 failed++;
1046             }
1047             System.out.print( "Pfam tree access: " );
1048             if ( Test.testPfamTreeReading() ) {
1049                 System.out.println( "OK." );
1050                 succeeded++;
1051             }
1052             else {
1053                 System.out.println( "failed." );
1054                 failed++;
1055             }
1056         }
1057         System.out.println();
1058         final Runtime rt = java.lang.Runtime.getRuntime();
1059         final long free_memory = rt.freeMemory() / 1000000;
1060         final long total_memory = rt.totalMemory() / 1000000;
1061         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1062                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1063         System.out.println();
1064         System.out.println( "Successful tests: " + succeeded );
1065         System.out.println( "Failed     tests: " + failed );
1066         System.out.println();
1067         if ( failed < 1 ) {
1068             System.out.println( "OK." );
1069         }
1070         else {
1071             System.out.println( "Not OK." );
1072         }
1073     }
1074
1075     private static boolean testEngulfingOverlapRemoval() {
1076         try {
1077             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1078             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1079             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1080             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1081             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1082             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1083             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1084             final List<Boolean> covered = new ArrayList<Boolean>();
1085             covered.add( true ); // 0
1086             covered.add( false ); // 1
1087             covered.add( true ); // 2
1088             covered.add( false ); // 3
1089             covered.add( true ); // 4
1090             covered.add( true ); // 5
1091             covered.add( false ); // 6
1092             covered.add( true ); // 7
1093             covered.add( true ); // 8
1094             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1095                 return false;
1096             }
1097             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1098                 return false;
1099             }
1100             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1101                 return false;
1102             }
1103             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1104                 return false;
1105             }
1106             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1107                 return false;
1108             }
1109             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1110                 return false;
1111             }
1112             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1113                 return false;
1114             }
1115             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1116             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1117             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1118             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1119             abc.addProteinDomain( a );
1120             abc.addProteinDomain( b );
1121             abc.addProteinDomain( c );
1122             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1123             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1124             if ( abc.getNumberOfProteinDomains() != 3 ) {
1125                 return false;
1126             }
1127             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1128                 return false;
1129             }
1130             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1131                 return false;
1132             }
1133             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1134                 return false;
1135             }
1136             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1137                 return false;
1138             }
1139             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1140             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1141             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1142             final Protein def = new BasicProtein( "def", "nemve", 0 );
1143             def.addProteinDomain( d );
1144             def.addProteinDomain( e );
1145             def.addProteinDomain( f );
1146             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1147             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1148             if ( def.getNumberOfProteinDomains() != 3 ) {
1149                 return false;
1150             }
1151             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1152                 return false;
1153             }
1154             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1155                 return false;
1156             }
1157             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1158                 return false;
1159             }
1160             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1161                 return false;
1162             }
1163             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1164                 return false;
1165             }
1166         }
1167         catch ( final Exception e ) {
1168             e.printStackTrace( System.out );
1169             return false;
1170         }
1171         return true;
1172     }
1173
1174     private static final boolean testNHXparsingFromURL2() {
1175         try {
1176             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1177             final Phylogeny phys[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1178                                                                       false,
1179                                                                       false,
1180                                                                       false,
1181                                                                       TAXONOMY_EXTRACTION.NO,
1182                                                                       false );
1183             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1184                 return false;
1185             }
1186             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1187                 System.out.println( phys[ 0 ].toNewHampshire() );
1188                 return false;
1189             }
1190             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1191                 System.out.println( phys[ 1 ].toNewHampshire() );
1192                 return false;
1193             }
1194             final Phylogeny phys2[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1195                                                                        false,
1196                                                                        false,
1197                                                                        false,
1198                                                                        TAXONOMY_EXTRACTION.NO,
1199                                                                        false );
1200             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1201                 return false;
1202             }
1203             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1204                 System.out.println( phys2[ 0 ].toNewHampshire() );
1205                 return false;
1206             }
1207             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1208                 System.out.println( phys2[ 1 ].toNewHampshire() );
1209                 return false;
1210             }
1211             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1212                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1213             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1214                 return false;
1215             }
1216             if ( !phys3[ 0 ]
1217                     .toNewHampshire()
1218                     .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))))));" ) ) {
1219                 System.out.println( phys3[ 0 ].toNewHampshire() );
1220                 return false;
1221             }
1222             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1223                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1224             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1225                 return false;
1226             }
1227             if ( !phys4[ 0 ]
1228                     .toNewHampshire()
1229                     .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))))));" ) ) {
1230                 System.out.println( phys4[ 0 ].toNewHampshire() );
1231                 return false;
1232             }
1233         }
1234         catch ( final Exception e ) {
1235             e.printStackTrace();
1236             return false;
1237         }
1238         return true;
1239     }
1240
1241     private static final boolean testNHXparsingFromURL() {
1242         try {
1243             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1244             final URL u = new URL( s );
1245             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1246             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1247             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1248                 return false;
1249             }
1250             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1251                 System.out.println( phys[ 0 ].toNewHampshire() );
1252                 return false;
1253             }
1254             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1255                 System.out.println( phys[ 1 ].toNewHampshire() );
1256                 return false;
1257             }
1258             final URL u2 = new URL( s );
1259             final Phylogeny[] phys2 = factory.create( u2.openStream(), new NHXParser() );
1260             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1261                 return false;
1262             }
1263             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1264                 System.out.println( phys2[ 0 ].toNewHampshire() );
1265                 return false;
1266             }
1267             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1268             final NHXParser p = new NHXParser();
1269             final URL u3 = new URL( s );
1270             p.setSource( u3 );
1271             if ( !p.hasNext() ) {
1272                 return false;
1273             }
1274             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1275                 return false;
1276             }
1277             if ( !p.hasNext() ) {
1278                 return false;
1279             }
1280             p.reset();
1281             if ( !p.hasNext() ) {
1282                 return false;
1283             }
1284             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1285                 return false;
1286             }
1287             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1288                 return false;
1289             }
1290             p.reset();
1291             if ( !p.hasNext() ) {
1292                 return false;
1293             }
1294             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1295                 return false;
1296             }
1297             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1298                 return false;
1299             }
1300         }
1301         catch ( final Exception e ) {
1302             System.out.println( e.toString() );
1303             e.printStackTrace();
1304             return false;
1305         }
1306         return true;
1307     }
1308
1309     private static boolean testOverlapRemoval() {
1310         try {
1311             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1312             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1313             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1314             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1315             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1316             final List<Boolean> covered = new ArrayList<Boolean>();
1317             covered.add( true ); // 0
1318             covered.add( false ); // 1
1319             covered.add( true ); // 2
1320             covered.add( false ); // 3
1321             covered.add( true ); // 4
1322             covered.add( true ); // 5
1323             covered.add( false ); // 6
1324             covered.add( true ); // 7
1325             covered.add( true ); // 8
1326             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1327                 return false;
1328             }
1329             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1330                 return false;
1331             }
1332             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1333                 return false;
1334             }
1335             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1336                 return false;
1337             }
1338             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1339                 return false;
1340             }
1341             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1342             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1343             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1344             ab.addProteinDomain( a );
1345             ab.addProteinDomain( b );
1346             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1347             if ( ab.getNumberOfProteinDomains() != 2 ) {
1348                 return false;
1349             }
1350             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1351                 return false;
1352             }
1353             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1354                 return false;
1355             }
1356             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1357             if ( ab.getNumberOfProteinDomains() != 2 ) {
1358                 return false;
1359             }
1360             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1361                 return false;
1362             }
1363             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1364             final Domain d = new BasicDomain( "d",
1365                                               ( short ) 10000,
1366                                               ( short ) 10500,
1367                                               ( short ) 1,
1368                                               ( short ) 1,
1369                                               0.0000001,
1370                                               1 );
1371             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1372             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1373             cde.addProteinDomain( c );
1374             cde.addProteinDomain( d );
1375             cde.addProteinDomain( e );
1376             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1377             if ( cde.getNumberOfProteinDomains() != 3 ) {
1378                 return false;
1379             }
1380             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1381                 return false;
1382             }
1383             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1384             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1385             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1386             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1387             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1388             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1389             fghi.addProteinDomain( f );
1390             fghi.addProteinDomain( g );
1391             fghi.addProteinDomain( h );
1392             fghi.addProteinDomain( i );
1393             fghi.addProteinDomain( i );
1394             fghi.addProteinDomain( i );
1395             fghi.addProteinDomain( i2 );
1396             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1397             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1398                 return false;
1399             }
1400             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1401                 return false;
1402             }
1403             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1404                 return false;
1405             }
1406             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1407             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1408                 return false;
1409             }
1410             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1411                 return false;
1412             }
1413             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1414             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1415             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1416             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1417             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1418             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1419             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1420             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1421             jklm.addProteinDomain( j );
1422             jklm.addProteinDomain( k );
1423             jklm.addProteinDomain( l );
1424             jklm.addProteinDomain( m );
1425             jklm.addProteinDomain( m0 );
1426             jklm.addProteinDomain( m1 );
1427             jklm.addProteinDomain( m2 );
1428             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1429             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1430                 return false;
1431             }
1432             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1433                 return false;
1434             }
1435             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1436                 return false;
1437             }
1438             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1439             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1440                 return false;
1441             }
1442             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1443                 return false;
1444             }
1445             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1446             final Protein od = new BasicProtein( "od", "varanus", 0 );
1447             od.addProteinDomain( only );
1448             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1449             if ( od.getNumberOfProteinDomains() != 1 ) {
1450                 return false;
1451             }
1452             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1453                 return false;
1454             }
1455         }
1456         catch ( final Exception e ) {
1457             e.printStackTrace( System.out );
1458             return false;
1459         }
1460         return true;
1461     }
1462
1463     private static final boolean testPfamTreeReading() {
1464         try {
1465             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1466             final NHXParser parser = new NHXParser();
1467             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1468             parser.setReplaceUnderscores( false );
1469             parser.setGuessRootedness( true );
1470             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser);
1471             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1472                 return false;
1473             }
1474             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1475                 return false;
1476             }
1477             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u, parser);
1478             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
1479                 return false;
1480             }
1481             if ( phys2[ 0 ].getNumberOfExternalNodes() != phys[ 0 ].getNumberOfExternalNodes() ) {
1482                 return false;
1483             }
1484         }
1485         catch ( final Exception e ) {
1486             e.printStackTrace();
1487             return false;
1488         }
1489         return true;
1490     }
1491
1492     private static final boolean testPhyloXMLparsingFromURL() {
1493         try {
1494             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1495             final URL u = new URL( s );
1496             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1497             
1498             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1499                 return false;
1500             }
1501             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1502             
1503             if ( ( phys2 == null ) || ( phys2.length != 2 ) ) {
1504                 return false;
1505             }
1506         }
1507         catch ( final Exception e ) {
1508             e.printStackTrace();
1509             return false;
1510         }
1511         return true;
1512     }
1513
1514     private static final boolean testToLReading() {
1515         try {
1516             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1517             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, new TolParser() );
1518             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1519                 return false;
1520             }
1521             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1522                 return false;
1523             }
1524             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1525                 return false;
1526             }
1527             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1528                 return false;
1529             }
1530             //
1531             final URL u2 = new URL( WebserviceUtil.TOL_URL_BASE + "17706" );
1532             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, new TolParser() );
1533             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
1534                 return false;
1535             }
1536             if ( !phys2[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "17706" ) ) {
1537                 return false;
1538             }
1539             if ( phys2[ 0 ].getNumberOfExternalNodes() < 5 ) {
1540                 return false;
1541             }
1542         }
1543         catch ( final Exception e ) {
1544             e.printStackTrace();
1545             return false;
1546         }
1547         return true;
1548     }
1549
1550     private static final boolean testTreeBaseReading() {
1551         try {
1552             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "72557?format=nexus" );  
1553             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1554             parser.setReplaceUnderscores( true );
1555             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1556             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1557                 return false;
1558             }
1559             final URL u_1 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2406?format=nexus" );  
1560             final NexusPhylogeniesParser parser_1 = new NexusPhylogeniesParser();
1561             final Phylogeny[] phys_1 = ForesterUtil.readPhylogeniesFromUrl( u_1, parser_1 );
1562             if ( ( phys_1 == null ) || ( phys_1.length != 1 ) ) {
1563                 return false;
1564             }
1565             final URL u_2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "422?format=nexus" );  
1566             final NexusPhylogeniesParser parser_2 = new NexusPhylogeniesParser();
1567             final Phylogeny[] phys_2 = ForesterUtil.readPhylogeniesFromUrl( u_2, parser_2 );
1568             if ( ( phys_2 == null ) || ( phys_2.length != 1 ) ) {
1569                 return false;
1570             }
1571             final URL u_3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2654?format=nexus" );  
1572             final NexusPhylogeniesParser parser_3 = new NexusPhylogeniesParser();
1573             final Phylogeny[] phys_3 = ForesterUtil.readPhylogeniesFromUrl( u_3, parser_3 );
1574              if ( ( phys_3 == null ) || ( phys_3.length != 1 ) ) {
1575                 return false;
1576             }
1577             final URL u_4 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );  
1578             final NexusPhylogeniesParser parser_4 = new NexusPhylogeniesParser();
1579             final Phylogeny[] phys_4 = ForesterUtil.readPhylogeniesFromUrl( u_4, parser_4 );
1580              if ( ( phys_4 == null ) || ( phys_4.length != 1 ) ) {
1581                 return false;
1582             }
1583             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1584             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1585             parser2.setReplaceUnderscores( true );
1586             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, parser2 );
1587             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1588                 return false;
1589             }
1590             final URL u3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14909?format=nexus" );
1591             final NexusPhylogeniesParser parser3 = new NexusPhylogeniesParser();
1592             final Phylogeny[] phys3 = ForesterUtil.readPhylogeniesFromUrl( u3, parser3 );
1593             if ( ( phys3 == null ) || ( phys3.length != 2 ) ) {
1594                 return false;
1595             }
1596             final Phylogeny[] phys4 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14525?format=nexus" ),
1597                     new NexusPhylogeniesParser() );
1598             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1599                 return false;
1600             }
1601             final Phylogeny[] phys5 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15632?format=nexus" ) ,
1602                     new NexusPhylogeniesParser() );
1603             if ( ( phys5 == null ) || ( phys5.length != 1 ) ) {
1604                 return false;
1605             }
1606             final Phylogeny[] phys6 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "10190?format=nexus" ) ,
1607                     new NexusPhylogeniesParser() );
1608             if ( ( phys6 == null ) || ( phys6.length != 1 ) ) {
1609                 return false;
1610             }
1611             final Phylogeny[] phys7 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "13246?format=nexus" ) ,
1612                     new NexusPhylogeniesParser() );
1613             if ( ( phys7 == null ) || ( phys7.length != 2 ) ) {
1614                 return false;
1615             }
1616             final Phylogeny[] phys8 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "11662?format=nexus" ) ,
1617                     new NexusPhylogeniesParser() );
1618             if ( ( phys8 == null ) || ( phys8.length != 2 ) ) {
1619                 return false;
1620             }
1621             final Phylogeny[] phys9 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "562?format=nexus" ) ,
1622                     new NexusPhylogeniesParser() );
1623             if ( ( phys9 == null ) || ( phys9.length != 4 ) ) {
1624                 return false;
1625             }
1626             final Phylogeny[] phys16424 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "16424?format=nexus" ) ,
1627                     new NexusPhylogeniesParser() );
1628             if ( ( phys16424 == null ) || ( phys16424.length != 1 ) ) {
1629                 return false;
1630             }
1631             final Phylogeny[] phys17878 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "17878?format=nexus" ) ,
1632                     new NexusPhylogeniesParser() );
1633             if ( ( phys17878 == null ) || ( phys17878.length != 17 ) ) {
1634                 return false;
1635             }
1636             final Phylogeny[] phys18804 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "18804?format=nexus" ) ,
1637                     new NexusPhylogeniesParser() );
1638             if ( ( phys18804 == null ) || ( phys18804.length != 2 ) ) {
1639                 return false;
1640             }
1641             final Phylogeny[] phys346 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "346?format=nexus" ) ,
1642                     new NexusPhylogeniesParser() );
1643             if ( ( phys346 == null ) || ( phys346.length != 1 ) ) {
1644                 return false;
1645             }
1646         }
1647         catch ( final Exception e ) {
1648             e.printStackTrace();
1649             return false;
1650         }
1651         return true;
1652     }
1653
1654     private static final boolean testTreeFamReading() {
1655         try {
1656             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1657             final NHXParser parser = new NHXParser();
1658             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1659             parser.setReplaceUnderscores( false );
1660             parser.setGuessRootedness( true );
1661             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1662             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1663                 return false;
1664             }
1665             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1666                 return false;
1667             }
1668         }
1669         catch ( final Exception e ) {
1670             e.printStackTrace();
1671             return false;
1672         }
1673         return true;
1674     }
1675
1676     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1677         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1678         return p;
1679     }
1680
1681     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1682         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1683     }
1684
1685     private static boolean testAminoAcidSequence() {
1686         try {
1687             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1688             if ( aa1.getLength() != 13 ) {
1689                 return false;
1690             }
1691             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1692                 return false;
1693             }
1694             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1695                 return false;
1696             }
1697             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1698                 return false;
1699             }
1700             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1701             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1702                 return false;
1703             }
1704             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1705             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1706                 return false;
1707             }
1708             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1709             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1710                 return false;
1711             }
1712         }
1713         catch ( final Exception e ) {
1714             e.printStackTrace();
1715             return false;
1716         }
1717         return true;
1718     }
1719
1720     private static boolean testBasicDomain() {
1721         try {
1722             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1723             if ( !pd.getDomainId().equals( "id" ) ) {
1724                 return false;
1725             }
1726             if ( pd.getNumber() != 1 ) {
1727                 return false;
1728             }
1729             if ( pd.getTotalCount() != 4 ) {
1730                 return false;
1731             }
1732             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1733                 return false;
1734             }
1735             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1736             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1737             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1738             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1739             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1740             if ( !a1.equals( a1 ) ) {
1741                 return false;
1742             }
1743             if ( !a1.equals( a1_copy ) ) {
1744                 return false;
1745             }
1746             if ( !a1.equals( a1_equal ) ) {
1747                 return false;
1748             }
1749             if ( !a1.equals( a2 ) ) {
1750                 return false;
1751             }
1752             if ( a1.equals( a3 ) ) {
1753                 return false;
1754             }
1755             if ( a1.compareTo( a1 ) != 0 ) {
1756                 return false;
1757             }
1758             if ( a1.compareTo( a1_copy ) != 0 ) {
1759                 return false;
1760             }
1761             if ( a1.compareTo( a1_equal ) != 0 ) {
1762                 return false;
1763             }
1764             if ( a1.compareTo( a2 ) != 0 ) {
1765                 return false;
1766             }
1767             if ( a1.compareTo( a3 ) == 0 ) {
1768                 return false;
1769             }
1770         }
1771         catch ( final Exception e ) {
1772             e.printStackTrace( System.out );
1773             return false;
1774         }
1775         return true;
1776     }
1777
1778     private static boolean testBasicNodeMethods() {
1779         try {
1780             if ( PhylogenyNode.getNodeCount() != 0 ) {
1781                 return false;
1782             }
1783             final PhylogenyNode n1 = new PhylogenyNode();
1784             final PhylogenyNode n2 = PhylogenyNode
1785                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1786             final PhylogenyNode n3 = PhylogenyNode
1787                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1788             final PhylogenyNode n4 = PhylogenyNode
1789                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1790             if ( n1.isHasAssignedEvent() ) {
1791                 return false;
1792             }
1793             if ( PhylogenyNode.getNodeCount() != 4 ) {
1794                 return false;
1795             }
1796             if ( n3.getIndicator() != 0 ) {
1797                 return false;
1798             }
1799             if ( n3.getNumberOfExternalNodes() != 1 ) {
1800                 return false;
1801             }
1802             if ( !n3.isExternal() ) {
1803                 return false;
1804             }
1805             if ( !n3.isRoot() ) {
1806                 return false;
1807             }
1808             if ( !n4.getName().equals( "n4" ) ) {
1809                 return false;
1810             }
1811         }
1812         catch ( final Exception e ) {
1813             e.printStackTrace( System.out );
1814             return false;
1815         }
1816         return true;
1817     }
1818     
1819     private static boolean testUTF8ParsingFromFile() {
1820         try {
1821             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1822             final Phylogeny[] phylogenies_xml = ParserBasedPhylogenyFactory.getInstance().create( new File( Test.PATH_TO_TEST_DATA + "chars.xml" ),
1823                                                               xml_parser );
1824             if ( xml_parser.getErrorCount() > 0 ) {
1825                 System.out.println( xml_parser.getErrorMessages().toString() );
1826                 return false;
1827             }
1828             if ( phylogenies_xml.length != 1 ) {
1829                 return false;
1830             }
1831          
1832             final Phylogeny[] phylogenies_xml2 = ParserBasedPhylogenyFactory.getInstance().create( new StringBuffer( phylogenies_xml[0].toPhyloXML( 0 )),
1833                                                                                                    xml_parser );
1834             
1835             final Phylogeny[] phylogenies_nh = ParserBasedPhylogenyFactory.getInstance().create( new File( Test.PATH_TO_TEST_DATA + "chars.nh" ), new NHXParser() );
1836             if ( phylogenies_nh.length != 1 ) {
1837                 return false;
1838             }
1839            
1840             final Phylogeny[] phylogenies_nex = ParserBasedPhylogenyFactory.getInstance().create( new File( Test.PATH_TO_TEST_DATA + "chars.nex" ), new NexusPhylogeniesParser() );
1841             if ( phylogenies_nex.length != 1 ) {
1842                 return false;
1843             }
1844           
1845             final String[] xml_n = phylogenies_xml[0].getAllExternalNodeNames();
1846             final String[] xml_n2 = phylogenies_xml2[0].getAllExternalNodeNames();
1847             final String[] nh_n = phylogenies_nh[0].getAllExternalNodeNames();
1848             final String[] nex_n = phylogenies_nex[0].getAllExternalNodeNames();
1849             final String n0 = "AQ~!@#$%^&*()_+-=\\{}|;:\"<>?,./";
1850             final String n1 = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ";
1851             final String n2 = "漢字ひらがなカタカナ";
1852             final String n3 = "อักษรไทย";
1853             final String n4 = "繁體字";
1854             final String n5 = "한글";
1855             final String n6 = "देवनागरी";
1856             
1857             final String n7 = "chữ Quốc ngữ";
1858             final String n8 = "ру́сский язы́к";
1859             final String n9 = "អក្សរខ្មែរ";
1860             
1861             if ( !xml_n[0].equals( n0 ) ) {
1862                 System.out.println( xml_n[0] );
1863                 System.out.println( n0 );
1864                 return false;
1865             }
1866             if ( !xml_n2[0].equals( n0 ) ) {
1867                 System.out.println( xml_n2[0] );
1868                 System.out.println( n0 );
1869                 return false;
1870             }
1871             if ( !nh_n[0].equals( n0 ) ) {
1872                 System.out.println( nh_n[0] );
1873                 System.out.println( n0 );
1874                 return false;
1875             }
1876             if ( !nex_n[0].equals( n0 ) ) {
1877                 System.out.println( nex_n[0] );
1878                 System.out.println( n0 );
1879                 return false;
1880             }
1881             
1882             if ( !xml_n[1].equals( n1 ) ) {
1883                 System.out.println( xml_n[1] );
1884                 System.out.println( n1 );
1885                 return false;
1886             }
1887             if ( !xml_n2[1].equals( n1 ) ) {
1888                 System.out.println( xml_n2[1] );
1889                 System.out.println( n1 );
1890                 return false;
1891             }
1892             if ( !nh_n[1].equals( n1 ) ) {
1893                 System.out.println( nh_n[1] );
1894                 System.out.println( n1 );
1895                 return false;
1896             }
1897             if ( !nex_n[1].equals( n1 ) ) {
1898                 System.out.println( nex_n[1] );
1899                 System.out.println( n1 );
1900                 return false;
1901             }
1902             
1903             if ( !xml_n[2].equals( n2 ) ) {
1904                 System.out.println( xml_n[2] );
1905                 System.out.println( n2 );
1906                 return false;
1907             }
1908             if ( !xml_n2[2].equals( n2 ) ) {
1909                 System.out.println( xml_n2[2] );
1910                 System.out.println( n2 );
1911                 return false;
1912             }
1913             if ( !nh_n[2].equals( n2 ) ) {
1914                 System.out.println( nh_n[2] );
1915                 System.out.println( n2 );
1916                 return false;
1917             }
1918             if ( !nex_n[2].equals( n2 ) ) {
1919                 System.out.println( nex_n[2] );
1920                 System.out.println( n2 );
1921                 return false;
1922             }
1923             //
1924             if ( !xml_n[3].equals( n3 ) ) {
1925                 System.out.println( xml_n[3] );
1926                 System.out.println( n3 );
1927                 return false;
1928             }
1929             if ( !xml_n2[3].equals( n3 ) ) {
1930                 System.out.println( xml_n2[3] );
1931                 System.out.println( n3 );
1932                 return false;
1933             }
1934             if ( !nh_n[3].equals( n3 ) ) {
1935                 System.out.println( nh_n[3] );
1936                 System.out.println( n3 );
1937                 return false;
1938             }
1939             if ( !nex_n[3].equals( n3 ) ) {
1940                 System.out.println( nex_n[3] );
1941                 System.out.println( n3 );
1942                 return false;
1943             }
1944             //
1945             if ( !xml_n[4].equals( n4 ) ) {
1946                 System.out.println( xml_n[4] );
1947                 System.out.println( n4 );
1948                 return false;
1949             }
1950             if ( !nh_n[4].equals( n4 ) ) {
1951                 System.out.println( nh_n[4] );
1952                 System.out.println( n4 );
1953                 return false;
1954             }
1955             if ( !nex_n[4].equals( n4 ) ) {
1956                 System.out.println( nex_n[4] );
1957                 System.out.println( n4 );
1958                 return false;
1959             }
1960             //
1961             if ( !xml_n[5].equals( n5 ) ) {
1962                 System.out.println( xml_n[5] );
1963                 System.out.println( n5 );
1964                 return false;
1965             }
1966             if ( !nh_n[5].equals( n5 ) ) {
1967                 System.out.println( nh_n[5] );
1968                 System.out.println( n5 );
1969                 return false;
1970             }
1971             if ( !nex_n[5].equals( n5 ) ) {
1972                 System.out.println( nex_n[5] );
1973                 System.out.println( n5 );
1974                 return false;
1975             }
1976             //
1977             if ( !xml_n[6].equals( n6 ) ) {
1978                 System.out.println( xml_n[6] );
1979                 System.out.println( n6 );
1980                 return false;
1981             }
1982             if ( !nh_n[6].equals( n6 ) ) {
1983                 System.out.println( nh_n[6] );
1984                 System.out.println( n6 );
1985                 return false;
1986             }
1987             if ( !nex_n[6].equals( n6 ) ) {
1988                 System.out.println( nex_n[6] );
1989                 System.out.println( n6 );
1990                 return false;
1991             }
1992             //
1993             if ( !xml_n[7].equals( n7 ) ) {
1994                 System.out.println( xml_n[7] );
1995                 System.out.println( n7 );
1996                 return false;
1997             }
1998             if ( !nh_n[7].equals( n7 ) ) {
1999                 System.out.println( nh_n[7] );
2000                 System.out.println( n7 );
2001                 return false;
2002             }
2003             if ( !nex_n[7].equals( n7 ) ) {
2004                 System.out.println( nex_n[7] );
2005                 System.out.println( n7 );
2006                 return false;
2007             }
2008             if ( !xml_n[8].equals( n8 ) ) {
2009                 System.out.println( xml_n[8] );
2010                 System.out.println( n8 );
2011                 return false;
2012             }
2013             if ( !nh_n[8].equals( n8 ) ) {
2014                 System.out.println( nh_n[8] );
2015                 System.out.println( n8 );
2016                 return false;
2017             }
2018             if ( !nex_n[8].equals( n8 ) ) {
2019                 System.out.println( nex_n[8] );
2020                 System.out.println( n8 );
2021                 return false;
2022             }
2023             if ( !xml_n[9].equals( n9 ) ) {
2024                 System.out.println( xml_n[9] );
2025                 System.out.println( n9 );
2026                 return false;
2027             }
2028             if ( !xml_n2[9].equals( n9 ) ) {
2029                 System.out.println( xml_n2[9] );
2030                 System.out.println( n9 );
2031                 return false;
2032             }
2033             if ( !nh_n[9].equals( n9 ) ) {
2034                 System.out.println( nh_n[9] );
2035                 System.out.println( n9 );
2036                 return false;
2037             }
2038             if ( !nex_n[9].equals( n9 ) ) {
2039                 System.out.println( nex_n[9] );
2040                 System.out.println( n9 );
2041                 return false;
2042             }
2043             if (!phylogenies_xml[0].toNewHampshire().equals( 
2044                                                             phylogenies_nh[0].toNewHampshire() ) ) {
2045                 System.out.println( phylogenies_xml[0].toNewHampshire() );
2046                 System.out.println( phylogenies_nh[0].toNewHampshire() );
2047                 return false;
2048             }
2049             if (!phylogenies_xml[0].toNewHampshire().equals( 
2050                                                             phylogenies_nex[0].toNewHampshire() ) ) {
2051                 System.out.println( phylogenies_xml[0].toNewHampshire() );
2052                 System.out.println( phylogenies_nex[0].toNewHampshire() );
2053                 return false;
2054             }
2055         }
2056         catch ( final Exception e ) {
2057             e.printStackTrace( System.out );
2058             return false;
2059         }
2060         return true;
2061     }
2062     
2063     
2064
2065     private static boolean testBasicPhyloXMLparsing() {
2066         try {
2067             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2068             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2069             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ),
2070                                                               xml_parser );
2071             if ( xml_parser.getErrorCount() > 0 ) {
2072                 System.out.println( xml_parser.getErrorMessages().toString() );
2073                 return false;
2074             }
2075             if ( phylogenies_0.length != 4 ) {
2076                 return false;
2077             }
2078             final Phylogeny t1 = phylogenies_0[ 0 ];
2079             final Phylogeny t2 = phylogenies_0[ 1 ];
2080             final Phylogeny t3 = phylogenies_0[ 2 ];
2081             final Phylogeny t4 = phylogenies_0[ 3 ];
2082             if ( t1.getNumberOfExternalNodes() != 1 ) {
2083                 return false;
2084             }
2085             if ( !t1.isRooted() ) {
2086                 return false;
2087             }
2088             if ( t1.isRerootable() ) {
2089                 return false;
2090             }
2091             if ( !t1.getType().equals( "gene_tree" ) ) {
2092                 return false;
2093             }
2094             if ( t2.getNumberOfExternalNodes() != 2 ) {
2095                 return false;
2096             }
2097             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
2098                 return false;
2099             }
2100             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
2101                 return false;
2102             }
2103             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2104                 return false;
2105             }
2106             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2107                 return false;
2108             }
2109             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2110                 return false;
2111             }
2112             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2113                 return false;
2114             }
2115             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2116                     .startsWith( "actgtgggggt" ) ) {
2117                 return false;
2118             }
2119             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2120                     .startsWith( "ctgtgatgcat" ) ) {
2121                 return false;
2122             }
2123             if ( t3.getNumberOfExternalNodes() != 4 ) {
2124                 return false;
2125             }
2126             if ( !t1.getName().equals( "t1" ) ) {
2127                 return false;
2128             }
2129             if ( !t2.getName().equals( "t2" ) ) {
2130                 return false;
2131             }
2132             if ( !t3.getName().equals( "t3" ) ) {
2133                 return false;
2134             }
2135             if ( !t4.getName().equals( "t4" ) ) {
2136                 return false;
2137             }
2138             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
2139                 return false;
2140             }
2141             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
2142                 return false;
2143             }
2144             if ( !t3.getNode( "root node" ).isDuplication() ) {
2145                 return false;
2146             }
2147             if ( !t3.getNode( "node a" ).isDuplication() ) {
2148                 return false;
2149             }
2150             if ( t3.getNode( "node a" ).isSpeciation() ) {
2151                 return false;
2152             }
2153             if ( t3.getNode( "node bc" ).isDuplication() ) {
2154                 return false;
2155             }
2156             if ( !t3.getNode( "node bc" ).isSpeciation() ) {
2157                 return false;
2158             }
2159             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2160                 return false;
2161             }
2162             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
2163                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2164                 return false;
2165             }
2166             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2167                 return false;
2168             }
2169             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2170                 return false;
2171             }
2172             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
2173                 return false;
2174             }
2175             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2176                     .equals( "apoptosis" ) ) {
2177                 return false;
2178             }
2179             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2180                     .equals( "GO:0006915" ) ) {
2181                 return false;
2182             }
2183             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2184                     .equals( "UniProtKB" ) ) {
2185                 return false;
2186             }
2187             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2188                     .equals( "experimental" ) ) {
2189                 return false;
2190             }
2191             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2192                     .equals( "function" ) ) {
2193                 return false;
2194             }
2195             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2196                     .getValue() != 1 ) {
2197                 return false;
2198             }
2199             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2200                     .getType().equals( "ml" ) ) {
2201                 return false;
2202             }
2203             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2204                     .equals( "apoptosis" ) ) {
2205                 return false;
2206             }
2207             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2208                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2209                 return false;
2210             }
2211             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2212                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2213                 return false;
2214             }
2215             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2216                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2217                 return false;
2218             }
2219             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2220                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2221                 return false;
2222             }
2223             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2224                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2225                 return false;
2226             }
2227             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2228                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2229                 return false;
2230             }
2231             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2232                     .equals( "GO:0005829" ) ) {
2233                 return false;
2234             }
2235             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2236                     .equals( "intracellular organelle" ) ) {
2237                 return false;
2238             }
2239             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2240                 return false;
2241             }
2242             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2243                     .equals( "UniProt link" ) ) ) {
2244                 return false;
2245             }
2246             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2247                 return false;
2248             }
2249             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
2250             if ( x.size() != 4 ) {
2251                 return false;
2252             }
2253             int c = 0;
2254             for( final Accession acc : x ) {
2255                 if ( c == 0 ) {
2256                     if ( !acc.getSource().equals( "KEGG" ) ) {
2257                         return false;
2258                     }
2259                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2260                         return false;
2261                     }
2262                 }
2263                 c++;
2264             }
2265         }
2266         catch ( final Exception e ) {
2267             e.printStackTrace( System.out );
2268             return false;
2269         }
2270         return true;
2271     }
2272
2273     private static boolean testBasicPhyloXMLparsingRoundtrip() {
2274         try {
2275             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2276             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2277             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2278                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2279             }
2280             else {
2281                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2282             }
2283             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ),
2284                                                               xml_parser );
2285             if ( xml_parser.getErrorCount() > 0 ) {
2286                 System.out.println( xml_parser.getErrorMessages().toString() );
2287                 return false;
2288             }
2289             if ( phylogenies_0.length != 4 ) {
2290                 return false;
2291             }
2292             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
2293             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
2294             if ( phylogenies_t1.length != 1 ) {
2295                 return false;
2296             }
2297             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
2298             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
2299                 return false;
2300             }
2301             if ( !t1_rt.isRooted() ) {
2302                 return false;
2303             }
2304             if ( t1_rt.isRerootable() ) {
2305                 return false;
2306             }
2307             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
2308                 return false;
2309             }
2310             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
2311             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
2312             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
2313             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2314                 return false;
2315             }
2316             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2317                 return false;
2318             }
2319             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2320                 return false;
2321             }
2322             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2323                 return false;
2324             }
2325             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2326                     .startsWith( "actgtgggggt" ) ) {
2327                 return false;
2328             }
2329             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2330                     .startsWith( "ctgtgatgcat" ) ) {
2331                 return false;
2332             }
2333             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
2334             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
2335             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
2336             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
2337             if ( phylogenies_1.length != 1 ) {
2338                 return false;
2339             }
2340             final Phylogeny t3_rt = phylogenies_1[ 0 ];
2341             if ( !t3_rt.getName().equals( "t3" ) ) {
2342                 return false;
2343             }
2344             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
2345                 return false;
2346             }
2347             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
2348                 return false;
2349             }
2350             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
2351                 return false;
2352             }
2353             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2354                 return false;
2355             }
2356             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
2357                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2358                 return false;
2359             }
2360             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2361                 return false;
2362             }
2363             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2364                 return false;
2365             }
2366             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2367                     .equals( "UniProtKB" ) ) {
2368                 return false;
2369             }
2370             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2371                     .equals( "apoptosis" ) ) {
2372                 return false;
2373             }
2374             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2375                     .equals( "GO:0006915" ) ) {
2376                 return false;
2377             }
2378             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2379                     .equals( "UniProtKB" ) ) {
2380                 return false;
2381             }
2382             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2383                     .equals( "experimental" ) ) {
2384                 return false;
2385             }
2386             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2387                     .equals( "function" ) ) {
2388                 return false;
2389             }
2390             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2391                     .getValue() != 1 ) {
2392                 return false;
2393             }
2394             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2395                     .getType().equals( "ml" ) ) {
2396                 return false;
2397             }
2398             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2399                     .equals( "apoptosis" ) ) {
2400                 return false;
2401             }
2402             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2403                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2404                 return false;
2405             }
2406             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2407                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2408                 return false;
2409             }
2410             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2411                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2412                 return false;
2413             }
2414             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2415                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2416                 return false;
2417             }
2418             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2419                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2420                 return false;
2421             }
2422             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2423                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2424                 return false;
2425             }
2426             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2427                     .equals( "GO:0005829" ) ) {
2428                 return false;
2429             }
2430             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2431                     .equals( "intracellular organelle" ) ) {
2432                 return false;
2433             }
2434             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2435                 return false;
2436             }
2437             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2438                     .equals( "UniProt link" ) ) ) {
2439                 return false;
2440             }
2441             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2442                 return false;
2443             }
2444             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
2445                 return false;
2446             }
2447             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2448                     .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." ) ) ) {
2449                 System.out.println( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription() );
2450                 return false;
2451             }
2452             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2453                 return false;
2454             }
2455             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2456                 return false;
2457             }
2458             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
2459                 return false;
2460             }
2461             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2462                 return false;
2463             }
2464             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2465                     .equals( "ncbi" ) ) {
2466                 return false;
2467             }
2468             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2469                 return false;
2470             }
2471             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2472                     .getName().equals( "B" ) ) {
2473                 return false;
2474             }
2475             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2476                     .getFrom() != 21 ) {
2477                 return false;
2478             }
2479             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2480                 return false;
2481             }
2482             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2483                     .getLength() != 24 ) {
2484                 return false;
2485             }
2486             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2487                     .getConfidence() != 0 ) {
2488                 return false;
2489             }
2490             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2491                     .equals( "pfam" ) ) {
2492                 return false;
2493             }
2494             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2495                 return false;
2496             }
2497             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2498                 return false;
2499             }
2500             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2501                 return false;
2502             }
2503             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2504                 return false;
2505             }
2506             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2507             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2508                 return false;
2509             }
2510             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2511                 return false;
2512             }
2513             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2514                 return false;
2515             }
2516             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2517                 return false;
2518             }
2519             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2520                 return false;
2521             }
2522             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2523                 return false;
2524             }
2525             if ( taxbb.getSynonyms().size() != 2 ) {
2526                 return false;
2527             }
2528             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2529                 return false;
2530             }
2531             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2532                 return false;
2533             }
2534             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2535                 return false;
2536             }
2537             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2538                 return false;
2539             }
2540             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2541                 return false;
2542             }
2543             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2544                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2545                 return false;
2546             }
2547             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2548                 return false;
2549             }
2550             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2551                 return false;
2552             }
2553             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2554                 return false;
2555             }
2556             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2557                 return false;
2558             }
2559             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2560                 return false;
2561             }
2562             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2563                 return false;
2564             }
2565             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2566                 return false;
2567             }
2568             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2569                 return false;
2570             }
2571             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2572                     .equalsIgnoreCase( "435" ) ) {
2573                 return false;
2574             }
2575             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2576                 return false;
2577             }
2578             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2579                     .equalsIgnoreCase( "443.7" ) ) {
2580                 return false;
2581             }
2582             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2583                 return false;
2584             }
2585             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2586                 return false;
2587             }
2588             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2589                     .equalsIgnoreCase( "433" ) ) {
2590                 return false;
2591             }
2592             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2593                     .getCrossReferences();
2594             if ( x.size() != 4 ) {
2595                 return false;
2596             }
2597             int c = 0;
2598             for( final Accession acc : x ) {
2599                 if ( c == 0 ) {
2600                     if ( !acc.getSource().equals( "KEGG" ) ) {
2601                         return false;
2602                     }
2603                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2604                         return false;
2605                     }
2606                 }
2607                 c++;
2608             }
2609         }
2610         catch ( final Exception e ) {
2611             e.printStackTrace( System.out );
2612             return false;
2613         }
2614         return true;
2615     }
2616
2617     private static boolean testBasicPhyloXMLparsingValidating() {
2618         try {
2619             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2620             PhyloXmlParser xml_parser = null;
2621             try {
2622                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2623             }
2624             catch ( final Exception e ) {
2625                 // Do nothing -- means were not running from jar.
2626             }
2627             if ( xml_parser == null ) {
2628                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2629                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2630                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2631                 }
2632                 else {
2633                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2634                 }
2635             }
2636             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ),
2637                                                               xml_parser );
2638             if ( xml_parser.getErrorCount() > 0 ) {
2639                 System.out.println( xml_parser.getErrorMessages().toString() );
2640                 return false;
2641             }
2642             if ( phylogenies_0.length != 4 ) {
2643                 return false;
2644             }
2645             final Phylogeny t1 = phylogenies_0[ 0 ];
2646             final Phylogeny t2 = phylogenies_0[ 1 ];
2647             final Phylogeny t3 = phylogenies_0[ 2 ];
2648             final Phylogeny t4 = phylogenies_0[ 3 ];
2649             if ( !t1.getName().equals( "t1" ) ) {
2650                 return false;
2651             }
2652             if ( !t2.getName().equals( "t2" ) ) {
2653                 return false;
2654             }
2655             if ( !t3.getName().equals( "t3" ) ) {
2656                 return false;
2657             }
2658             if ( !t4.getName().equals( "t4" ) ) {
2659                 return false;
2660             }
2661             if ( t1.getNumberOfExternalNodes() != 1 ) {
2662                 return false;
2663             }
2664             if ( t2.getNumberOfExternalNodes() != 2 ) {
2665                 return false;
2666             }
2667             if ( t3.getNumberOfExternalNodes() != 4 ) {
2668                 return false;
2669             }
2670             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2671             final Phylogeny[] phylogenies_1 = factory.create( new File( x2 ), xml_parser );
2672             if ( xml_parser.getErrorCount() > 0 ) {
2673                 System.out.println( "errors:" );
2674                 System.out.println( xml_parser.getErrorMessages().toString() );
2675                 return false;
2676             }
2677             if ( phylogenies_1.length != 4 ) {
2678                 return false;
2679             }
2680             final Phylogeny[] phylogenies_2 = factory.create( new File(Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml" ),
2681                                                               xml_parser );
2682             if ( xml_parser.getErrorCount() > 0 ) {
2683                 System.out.println( "errors:" );
2684                 System.out.println( xml_parser.getErrorMessages().toString() );
2685                 return false;
2686             }
2687             if ( phylogenies_2.length != 1 ) {
2688                 return false;
2689             }
2690             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2691                 return false;
2692             }
2693             final Phylogeny[] phylogenies_3 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml" ),
2694                                                               xml_parser );
2695             if ( xml_parser.getErrorCount() > 0 ) {
2696                 System.out.println( xml_parser.getErrorMessages().toString() );
2697                 return false;
2698             }
2699             if ( phylogenies_3.length != 2 ) {
2700                 return false;
2701             }
2702             final Phylogeny a = phylogenies_3[ 0 ];
2703             if ( !a.getName().equals( "tree 4" ) ) {
2704                 return false;
2705             }
2706             if ( a.getNumberOfExternalNodes() != 3 ) {
2707                 return false;
2708             }
2709             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2710                 return false;
2711             }
2712             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2713                 return false;
2714             }
2715             final Phylogeny[] phylogenies_4 = factory.create( new File( Test.PATH_TO_TEST_DATA + "special_characters.xml") ,
2716                                                               xml_parser );
2717             if ( xml_parser.getErrorCount() > 0 ) {
2718                 System.out.println( xml_parser.getErrorMessages().toString() );
2719                 return false;
2720             }
2721             if ( phylogenies_4.length != 1 ) {
2722                 return false;
2723             }
2724             final Phylogeny s = phylogenies_4[ 0 ];
2725             if ( s.getNumberOfExternalNodes() != 6 ) {
2726                 return false;
2727             }
2728             s.getNode( "first" );
2729             s.getNode( "<>" );
2730             s.getNode( "\"<a'b&c'd\">\"" );
2731             s.getNode( "'''\"" );
2732             s.getNode( "\"\"\"" );
2733             s.getNode( "dick & doof" );
2734         }
2735         catch ( final Exception e ) {
2736             e.printStackTrace( System.out );
2737             return false;
2738         }
2739         return true;
2740     }
2741
2742     private static boolean testBasicProtein() {
2743         try {
2744             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2745             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2746             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2747             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2748             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2749             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2750             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2751             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2752             p0.addProteinDomain( y );
2753             p0.addProteinDomain( e );
2754             p0.addProteinDomain( b );
2755             p0.addProteinDomain( c );
2756             p0.addProteinDomain( d );
2757             p0.addProteinDomain( a );
2758             p0.addProteinDomain( x );
2759             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2760                 return false;
2761             }
2762             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2763                 return false;
2764             }
2765             //
2766             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2767             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2768             aa0.addProteinDomain( a1 );
2769             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2770                 return false;
2771             }
2772             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2773                 return false;
2774             }
2775             //
2776             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2777             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2778             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2779             aa1.addProteinDomain( a11 );
2780             aa1.addProteinDomain( a12 );
2781             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2782                 return false;
2783             }
2784             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2785                 return false;
2786             }
2787             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2788             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2789                 return false;
2790             }
2791             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2792                 return false;
2793             }
2794             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2795                 return false;
2796             }
2797             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2798             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2799                 return false;
2800             }
2801             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2802                 return false;
2803             }
2804             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2805                 return false;
2806             }
2807             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2808                 return false;
2809             }
2810             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2811             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2812                 return false;
2813             }
2814             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2815                 return false;
2816             }
2817             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2818                 return false;
2819             }
2820             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2821                 return false;
2822             }
2823             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2824             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2825                 return false;
2826             }
2827             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2828                 return false;
2829             }
2830             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2831                 return false;
2832             }
2833             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2834                 return false;
2835             }
2836             //
2837             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2838             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2839             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2840             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2841             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2842             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2843             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2844             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2845             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2846             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2847             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2848             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2849             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2850             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2851             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2852             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2853             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2854             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2855             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2856             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2857             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2858             p00.addProteinDomain( y0 );
2859             p00.addProteinDomain( e0 );
2860             p00.addProteinDomain( b0 );
2861             p00.addProteinDomain( c0 );
2862             p00.addProteinDomain( d0 );
2863             p00.addProteinDomain( a0 );
2864             p00.addProteinDomain( x0 );
2865             p00.addProteinDomain( y1 );
2866             p00.addProteinDomain( y2 );
2867             p00.addProteinDomain( y3 );
2868             p00.addProteinDomain( e1 );
2869             p00.addProteinDomain( e2 );
2870             p00.addProteinDomain( e3 );
2871             p00.addProteinDomain( e4 );
2872             p00.addProteinDomain( e5 );
2873             p00.addProteinDomain( z0 );
2874             p00.addProteinDomain( z1 );
2875             p00.addProteinDomain( z2 );
2876             p00.addProteinDomain( zz0 );
2877             p00.addProteinDomain( zz1 );
2878             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2879                 return false;
2880             }
2881             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2882                 return false;
2883             }
2884             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2885                 return false;
2886             }
2887             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2888                 return false;
2889             }
2890             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" ) ) {
2891                 return false;
2892             }
2893             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2894             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2895             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2896             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2897             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2898             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2899             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2900             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2901             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2902             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2903             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2904             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2905             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2906             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2907             p.addProteinDomain( B15 );
2908             p.addProteinDomain( C50 );
2909             p.addProteinDomain( A60 );
2910             p.addProteinDomain( A30 );
2911             p.addProteinDomain( C70 );
2912             p.addProteinDomain( B35 );
2913             p.addProteinDomain( B40 );
2914             p.addProteinDomain( A0 );
2915             p.addProteinDomain( A10 );
2916             p.addProteinDomain( A20 );
2917             p.addProteinDomain( B25 );
2918             p.addProteinDomain( D80 );
2919             List<String> domains_ids = new ArrayList<String>();
2920             domains_ids.add( "A" );
2921             domains_ids.add( "B" );
2922             domains_ids.add( "C" );
2923             if ( !p.contains( domains_ids, false ) ) {
2924                 return false;
2925             }
2926             if ( !p.contains( domains_ids, true ) ) {
2927                 return false;
2928             }
2929             domains_ids.add( "X" );
2930             if ( p.contains( domains_ids, false ) ) {
2931                 return false;
2932             }
2933             if ( p.contains( domains_ids, true ) ) {
2934                 return false;
2935             }
2936             domains_ids = new ArrayList<String>();
2937             domains_ids.add( "A" );
2938             domains_ids.add( "C" );
2939             domains_ids.add( "D" );
2940             if ( !p.contains( domains_ids, false ) ) {
2941                 return false;
2942             }
2943             if ( !p.contains( domains_ids, true ) ) {
2944                 return false;
2945             }
2946             domains_ids = new ArrayList<String>();
2947             domains_ids.add( "A" );
2948             domains_ids.add( "D" );
2949             domains_ids.add( "C" );
2950             if ( !p.contains( domains_ids, false ) ) {
2951                 return false;
2952             }
2953             if ( p.contains( domains_ids, true ) ) {
2954                 return false;
2955             }
2956             domains_ids = new ArrayList<String>();
2957             domains_ids.add( "A" );
2958             domains_ids.add( "A" );
2959             domains_ids.add( "B" );
2960             if ( !p.contains( domains_ids, false ) ) {
2961                 return false;
2962             }
2963             if ( !p.contains( domains_ids, true ) ) {
2964                 return false;
2965             }
2966             domains_ids = new ArrayList<String>();
2967             domains_ids.add( "A" );
2968             domains_ids.add( "A" );
2969             domains_ids.add( "A" );
2970             domains_ids.add( "B" );
2971             domains_ids.add( "B" );
2972             if ( !p.contains( domains_ids, false ) ) {
2973                 return false;
2974             }
2975             if ( !p.contains( domains_ids, true ) ) {
2976                 return false;
2977             }
2978             domains_ids = new ArrayList<String>();
2979             domains_ids.add( "A" );
2980             domains_ids.add( "A" );
2981             domains_ids.add( "B" );
2982             domains_ids.add( "A" );
2983             domains_ids.add( "B" );
2984             domains_ids.add( "B" );
2985             domains_ids.add( "A" );
2986             domains_ids.add( "B" );
2987             domains_ids.add( "C" );
2988             domains_ids.add( "A" );
2989             domains_ids.add( "C" );
2990             domains_ids.add( "D" );
2991             if ( !p.contains( domains_ids, false ) ) {
2992                 return false;
2993             }
2994             if ( p.contains( domains_ids, true ) ) {
2995                 return false;
2996             }
2997         }
2998         catch ( final Exception e ) {
2999             e.printStackTrace( System.out );
3000             return false;
3001         }
3002         return true;
3003     }
3004
3005     private static boolean testBasicTable() {
3006         try {
3007             final BasicTable<String> t0 = new BasicTable<String>();
3008             if ( t0.getNumberOfColumns() != 0 ) {
3009                 return false;
3010             }
3011             if ( t0.getNumberOfRows() != 0 ) {
3012                 return false;
3013             }
3014             t0.setValue( 3, 2, "23" );
3015             t0.setValue( 10, 1, "error" );
3016             t0.setValue( 10, 1, "110" );
3017             t0.setValue( 9, 1, "19" );
3018             t0.setValue( 1, 10, "101" );
3019             t0.setValue( 10, 10, "1010" );
3020             t0.setValue( 100, 10, "10100" );
3021             t0.setValue( 0, 0, "00" );
3022             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3023                 return false;
3024             }
3025             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3026                 return false;
3027             }
3028             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3029                 return false;
3030             }
3031             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3032                 return false;
3033             }
3034             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3035                 return false;
3036             }
3037             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3038                 return false;
3039             }
3040             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3041                 return false;
3042             }
3043             if ( t0.getNumberOfColumns() != 101 ) {
3044                 return false;
3045             }
3046             if ( t0.getNumberOfRows() != 11 ) {
3047                 return false;
3048             }
3049             if ( t0.getValueAsString( 49, 4 ) != null ) {
3050                 return false;
3051             }
3052             final String l = ForesterUtil.getLineSeparator();
3053             final StringBuffer source = new StringBuffer();
3054             source.append( "" + l );
3055             source.append( "# 1 1 1 1 1 1 1 1" + l );
3056             source.append( " 00 01 02 03" + l );
3057             source.append( "   10 11 12 13  " + l );
3058             source.append( "20 21 22 23 " + l );
3059             source.append( "    30  31    32 33" + l );
3060             source.append( "40 41 42 43" + l );
3061             source.append( "  # 1 1 1 1 1 " + l );
3062             source.append( "50 51 52 53 54" + l );
3063             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
3064             if ( t1.getNumberOfColumns() != 5 ) {
3065                 return false;
3066             }
3067             if ( t1.getNumberOfRows() != 6 ) {
3068                 return false;
3069             }
3070             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
3071                 return false;
3072             }
3073             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
3074                 return false;
3075             }
3076             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
3077                 return false;
3078             }
3079             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
3080                 return false;
3081             }
3082             final StringBuffer source1 = new StringBuffer();
3083             source1.append( "" + l );
3084             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3085             source1.append( " 00; 01 ;02;03" + l );
3086             source1.append( "   10; 11; 12; 13  " + l );
3087             source1.append( "20; 21; 22; 23 " + l );
3088             source1.append( "    30;  31;    32; 33" + l );
3089             source1.append( "40;41;42;43" + l );
3090             source1.append( "  # 1 1 1 1 1 " + l );
3091             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
3092             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
3093             if ( t2.getNumberOfColumns() != 5 ) {
3094                 return false;
3095             }
3096             if ( t2.getNumberOfRows() != 6 ) {
3097                 return false;
3098             }
3099             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
3100                 return false;
3101             }
3102             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
3103                 return false;
3104             }
3105             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
3106                 return false;
3107             }
3108             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
3109                 return false;
3110             }
3111             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
3112                 return false;
3113             }
3114             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
3115                 return false;
3116             }
3117             final StringBuffer source2 = new StringBuffer();
3118             source2.append( "" + l );
3119             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3120             source2.append( " 00; 01 ;02;03" + l );
3121             source2.append( "   10; 11; 12; 13  " + l );
3122             source2.append( "20; 21; 22; 23 " + l );
3123             source2.append( "                     " + l );
3124             source2.append( "    30;  31;    32; 33" + l );
3125             source2.append( "40;41;42;43" + l );
3126             source2.append( "  comment: 1 1 1 1 1 " + l );
3127             source2.append( ";;;50  ;   52; 53;;54   " + l );
3128             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
3129                                                                         ';',
3130                                                                         false,
3131                                                                         false,
3132                                                                         "comment:",
3133                                                                         false );
3134             if ( tl.size() != 2 ) {
3135                 return false;
3136             }
3137             final BasicTable<String> t3 = tl.get( 0 );
3138             final BasicTable<String> t4 = tl.get( 1 );
3139             if ( t3.getNumberOfColumns() != 4 ) {
3140                 return false;
3141             }
3142             if ( t3.getNumberOfRows() != 3 ) {
3143                 return false;
3144             }
3145             if ( t4.getNumberOfColumns() != 4 ) {
3146                 return false;
3147             }
3148             if ( t4.getNumberOfRows() != 3 ) {
3149                 return false;
3150             }
3151             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
3152                 return false;
3153             }
3154             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
3155                 return false;
3156             }
3157         }
3158         catch ( final Exception e ) {
3159             e.printStackTrace( System.out );
3160             return false;
3161         }
3162         return true;
3163     }
3164
3165     private static boolean testBasicTolXMLparsing() {
3166         try {
3167             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3168             final TolParser parser = new TolParser();
3169             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
3170             if ( parser.getErrorCount() > 0 ) {
3171                 System.out.println( parser.getErrorMessages().toString() );
3172                 return false;
3173             }
3174             if ( phylogenies_0.length != 1 ) {
3175                 return false;
3176             }
3177             final Phylogeny t1 = phylogenies_0[ 0 ];
3178             if ( t1.getNumberOfExternalNodes() != 5 ) {
3179                 return false;
3180             }
3181             if ( !t1.isRooted() ) {
3182                 return false;
3183             }
3184             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
3185                 return false;
3186             }
3187             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
3188                 return false;
3189             }
3190             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
3191                 return false;
3192             }
3193             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
3194                 return false;
3195             }
3196             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
3197             if ( parser.getErrorCount() > 0 ) {
3198                 System.out.println( parser.getErrorMessages().toString() );
3199                 return false;
3200             }
3201             if ( phylogenies_1.length != 1 ) {
3202                 return false;
3203             }
3204             final Phylogeny t2 = phylogenies_1[ 0 ];
3205             if ( t2.getNumberOfExternalNodes() != 664 ) {
3206                 return false;
3207             }
3208             if ( !t2.isRooted() ) {
3209                 return false;
3210             }
3211             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
3212                 return false;
3213             }
3214             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
3215                 return false;
3216             }
3217             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3218                 return false;
3219             }
3220             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3221                 return false;
3222             }
3223             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
3224                 return false;
3225             }
3226             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3227                     .equals( "Aquifex" ) ) {
3228                 return false;
3229             }
3230             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
3231             if ( parser.getErrorCount() > 0 ) {
3232                 System.out.println( parser.getErrorMessages().toString() );
3233                 return false;
3234             }
3235             if ( phylogenies_2.length != 1 ) {
3236                 return false;
3237             }
3238             final Phylogeny t3 = phylogenies_2[ 0 ];
3239             if ( t3.getNumberOfExternalNodes() != 184 ) {
3240                 return false;
3241             }
3242             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
3243                 return false;
3244             }
3245             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
3246                 return false;
3247             }
3248             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
3249                 return false;
3250             }
3251             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
3252             if ( parser.getErrorCount() > 0 ) {
3253                 System.out.println( parser.getErrorMessages().toString() );
3254                 return false;
3255             }
3256             if ( phylogenies_3.length != 1 ) {
3257                 return false;
3258             }
3259             final Phylogeny t4 = phylogenies_3[ 0 ];
3260             if ( t4.getNumberOfExternalNodes() != 1 ) {
3261                 return false;
3262             }
3263             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
3264                 return false;
3265             }
3266             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
3267                 return false;
3268             }
3269             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
3270                 return false;
3271             }
3272             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
3273             if ( parser.getErrorCount() > 0 ) {
3274                 System.out.println( parser.getErrorMessages().toString() );
3275                 return false;
3276             }
3277             if ( phylogenies_4.length != 1 ) {
3278                 return false;
3279             }
3280             final Phylogeny t5 = phylogenies_4[ 0 ];
3281             if ( t5.getNumberOfExternalNodes() != 13 ) {
3282                 return false;
3283             }
3284             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
3285                 return false;
3286             }
3287             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
3288                 return false;
3289             }
3290             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
3291                 return false;
3292             }
3293         }
3294         catch ( final Exception e ) {
3295             e.printStackTrace( System.out );
3296             return false;
3297         }
3298         return true;
3299     }
3300
3301     private static boolean testBasicTreeMethods() {
3302         try {
3303             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3304             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
3305             if ( t2.getNumberOfExternalNodes() != 4 ) {
3306                 return false;
3307             }
3308             if ( t2.getHeight() != 8.5 ) {
3309                 return false;
3310             }
3311             if ( !t2.isCompletelyBinary() ) {
3312                 return false;
3313             }
3314             if ( t2.isEmpty() ) {
3315                 return false;
3316             }
3317             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
3318             if ( t3.getNumberOfExternalNodes() != 5 ) {
3319                 return false;
3320             }
3321             if ( t3.getHeight() != 11 ) {
3322                 return false;
3323             }
3324             if ( t3.isCompletelyBinary() ) {
3325                 return false;
3326             }
3327             final PhylogenyNode n = t3.getNode( "ABC" );
3328             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 ];
3329             if ( t4.getNumberOfExternalNodes() != 9 ) {
3330                 return false;
3331             }
3332             if ( t4.getHeight() != 11 ) {
3333                 return false;
3334             }
3335             if ( t4.isCompletelyBinary() ) {
3336                 return false;
3337             }
3338             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)" );
3339             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
3340             if ( t5.getNumberOfExternalNodes() != 8 ) {
3341                 return false;
3342             }
3343             if ( t5.getHeight() != 15 ) {
3344                 return false;
3345             }
3346             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)" );
3347             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
3348             if ( t6.getHeight() != 15 ) {
3349                 return false;
3350             }
3351             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)" );
3352             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
3353             if ( t7.getHeight() != 15 ) {
3354                 return false;
3355             }
3356             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)" );
3357             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
3358             if ( t8.getNumberOfExternalNodes() != 10 ) {
3359                 return false;
3360             }
3361             if ( t8.getHeight() != 15 ) {
3362                 return false;
3363             }
3364             final char[] a9 = new char[] { 'a' };
3365             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
3366             if ( t9.getHeight() != 0 ) {
3367                 return false;
3368             }
3369             final char[] a10 = new char[] { 'a', ':', '6' };
3370             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
3371             if ( t10.getHeight() != 6 ) {
3372                 return false;
3373             }
3374         }
3375         catch ( final Exception e ) {
3376             e.printStackTrace( System.out );
3377             return false;
3378         }
3379         return true;
3380     }
3381
3382     private static boolean testConfidenceAssessor() {
3383         try {
3384             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3385             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3386             final Phylogeny[] ev0 = factory
3387                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3388                              new NHXParser() );
3389             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3390             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3391                 return false;
3392             }
3393             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3394                 return false;
3395             }
3396             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3397             final Phylogeny[] ev1 = factory
3398                     .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)));",
3399                              new NHXParser() );
3400             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3401             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3402                 return false;
3403             }
3404             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3405                 return false;
3406             }
3407             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3408             final Phylogeny[] ev_b = factory
3409                     .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",
3410                              new NHXParser() );
3411             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3412             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3413                 return false;
3414             }
3415             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3416                 return false;
3417             }
3418             //
3419             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3420             final Phylogeny[] ev1x = factory
3421                     .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)));",
3422                              new NHXParser() );
3423             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3424             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3425                 return false;
3426             }
3427             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3428                 return false;
3429             }
3430             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3431             final Phylogeny[] ev_bx = factory
3432                     .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",
3433                              new NHXParser() );
3434             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3435             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3436                 return false;
3437             }
3438             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3439                 return false;
3440             }
3441             final Phylogeny[] t2 = factory
3442                     .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);",
3443                              new NHXParser() );
3444             final Phylogeny[] ev2 = factory
3445                     .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);",
3446                              new NHXParser() );
3447             for( final Phylogeny target : t2 ) {
3448                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3449             }
3450             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3451                                                  new NHXParser() )[ 0 ];
3452             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3453             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3454             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3455                 return false;
3456             }
3457             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3458                 return false;
3459             }
3460             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3461                 return false;
3462             }
3463         }
3464         catch ( final Exception e ) {
3465             e.printStackTrace();
3466             return false;
3467         }
3468         return true;
3469     }
3470
3471     private static boolean testCopyOfNodeData() {
3472         try {
3473             final PhylogenyNode n1 = PhylogenyNode
3474                     .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]" );
3475             final PhylogenyNode n2 = n1.copyNodeData();
3476             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3477                 return false;
3478             }
3479         }
3480         catch ( final Exception e ) {
3481             e.printStackTrace();
3482             return false;
3483         }
3484         return true;
3485     }
3486
3487     private static boolean testCreateBalancedPhylogeny() {
3488         try {
3489             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3490             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3491                 return false;
3492             }
3493             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3494                 return false;
3495             }
3496             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3497             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3498                 return false;
3499             }
3500             if ( p1.getNumberOfExternalNodes() != 100 ) {
3501                 return false;
3502             }
3503         }
3504         catch ( final Exception e ) {
3505             e.printStackTrace();
3506             return false;
3507         }
3508         return true;
3509     }
3510
3511     private static boolean testCreateUriForSeqWeb() {
3512         try {
3513             final PhylogenyNode n = new PhylogenyNode();
3514             n.setName( "tr|B3RJ64" );
3515             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3516                 return false;
3517             }
3518             n.setName( "B0LM41_HUMAN" );
3519             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3520                 return false;
3521             }
3522             n.setName( "NP_001025424" );
3523             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3524                 return false;
3525             }
3526             n.setName( "_NM_001030253-" );
3527             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3528                 return false;
3529             }
3530             n.setName( "XM_002122186" );
3531             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3532                 return false;
3533             }
3534             n.setName( "dgh_AAA34956_gdg" );
3535             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3536                 return false;
3537             }
3538             n.setName( "AAA34956" );
3539             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3540                 return false;
3541             }
3542             n.setName( "GI:394892" );
3543             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3544                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3545                 return false;
3546             }
3547             n.setName( "gi_394892" );
3548             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3549                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3550                 return false;
3551             }
3552             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3553             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3554                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3555                 return false;
3556             }
3557             n.setName( "P12345" );
3558             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3559                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3560                 return false;
3561             }
3562             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3563             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3564                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3565                 return false;
3566             }
3567         }
3568         catch ( final Exception e ) {
3569             e.printStackTrace( System.out );
3570             return false;
3571         }
3572         return true;
3573     }
3574
3575     private static boolean testDataObjects() {
3576         try {
3577             final Confidence s0 = new Confidence();
3578             final Confidence s1 = new Confidence();
3579             if ( !s0.isEqual( s1 ) ) {
3580                 return false;
3581             }
3582             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3583             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3584             if ( s2.isEqual( s1 ) ) {
3585                 return false;
3586             }
3587             if ( !s2.isEqual( s3 ) ) {
3588                 return false;
3589             }
3590             final Confidence s4 = ( Confidence ) s3.copy();
3591             if ( !s4.isEqual( s3 ) ) {
3592                 return false;
3593             }
3594             s3.asSimpleText();
3595             s3.asText();
3596             // Taxonomy
3597             // ----------
3598             final Taxonomy t1 = new Taxonomy();
3599             final Taxonomy t2 = new Taxonomy();
3600             final Taxonomy t3 = new Taxonomy();
3601             final Taxonomy t4 = new Taxonomy();
3602             final Taxonomy t5 = new Taxonomy();
3603             t1.setIdentifier( new Identifier( "ecoli" ) );
3604             t1.setTaxonomyCode( "ECOLI" );
3605             t1.setScientificName( "E. coli" );
3606             t1.setCommonName( "coli" );
3607             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3608             if ( !t1.isEqual( t0 ) ) {
3609                 return false;
3610             }
3611             t2.setIdentifier( new Identifier( "ecoli" ) );
3612             t2.setTaxonomyCode( "OTHER" );
3613             t2.setScientificName( "what" );
3614             t2.setCommonName( "something" );
3615             if ( !t1.isEqual( t2 ) ) {
3616                 return false;
3617             }
3618             t2.setIdentifier( new Identifier( "nemve" ) );
3619             if ( t1.isEqual( t2 ) ) {
3620                 return false;
3621             }
3622             t1.setIdentifier( null );
3623             t3.setTaxonomyCode( "ECOLI" );
3624             t3.setScientificName( "what" );
3625             t3.setCommonName( "something" );
3626             if ( !t1.isEqual( t3 ) ) {
3627                 return false;
3628             }
3629             t1.setIdentifier( null );
3630             t1.setTaxonomyCode( "" );
3631             t4.setScientificName( "E. ColI" );
3632             t4.setCommonName( "something" );
3633             if ( !t1.isEqual( t4 ) ) {
3634                 return false;
3635             }
3636             t4.setScientificName( "B. subtilis" );
3637             t4.setCommonName( "something" );
3638             if ( t1.isEqual( t4 ) ) {
3639                 return false;
3640             }
3641             t1.setIdentifier( null );
3642             t1.setTaxonomyCode( "" );
3643             t1.setScientificName( "" );
3644             t5.setCommonName( "COLI" );
3645             if ( !t1.isEqual( t5 ) ) {
3646                 return false;
3647             }
3648             t5.setCommonName( "vibrio" );
3649             if ( t1.isEqual( t5 ) ) {
3650                 return false;
3651             }
3652             // Identifier
3653             // ----------
3654             final Identifier id0 = new Identifier( "123", "pfam" );
3655             final Identifier id1 = ( Identifier ) id0.copy();
3656             if ( !id1.isEqual( id1 ) ) {
3657                 return false;
3658             }
3659             if ( !id1.isEqual( id0 ) ) {
3660                 return false;
3661             }
3662             if ( !id0.isEqual( id1 ) ) {
3663                 return false;
3664             }
3665             id1.asSimpleText();
3666             id1.asText();
3667             // ProteinDomain
3668             // ---------------
3669             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3670             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3671             if ( !pd1.isEqual( pd1 ) ) {
3672                 return false;
3673             }
3674             if ( !pd1.isEqual( pd0 ) ) {
3675                 return false;
3676             }
3677             pd1.asSimpleText();
3678             pd1.asText();
3679             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3680             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3681             if ( !pd3.isEqual( pd3 ) ) {
3682                 return false;
3683             }
3684             if ( !pd2.isEqual( pd3 ) ) {
3685                 return false;
3686             }
3687             if ( !pd0.isEqual( pd3 ) ) {
3688                 return false;
3689             }
3690             pd3.asSimpleText();
3691             pd3.asText();
3692             // DomainArchitecture
3693             // ------------------
3694             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3695             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3696             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3697             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3698             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3699             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3700             domains0.add( d2 );
3701             domains0.add( d0 );
3702             domains0.add( d3 );
3703             domains0.add( d1 );
3704             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3705             if ( ds0.getNumberOfDomains() != 4 ) {
3706                 return false;
3707             }
3708             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3709             if ( !ds0.isEqual( ds0 ) ) {
3710                 return false;
3711             }
3712             if ( !ds0.isEqual( ds1 ) ) {
3713                 return false;
3714             }
3715             if ( ds1.getNumberOfDomains() != 4 ) {
3716                 return false;
3717             }
3718             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3719             domains1.add( d1 );
3720             domains1.add( d2 );
3721             domains1.add( d4 );
3722             domains1.add( d0 );
3723             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3724             if ( ds0.isEqual( ds2 ) ) {
3725                 return false;
3726             }
3727             ds1.asSimpleText();
3728             ds1.asText();
3729             ds1.toNHX();
3730             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3731             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3732                 System.out.println( ds3.toNHX() );
3733                 return false;
3734             }
3735             if ( ds3.getNumberOfDomains() != 3 ) {
3736                 return false;
3737             }
3738             // Event
3739             // -----
3740             final Event e1 = new Event( Event.EventType.fusion );
3741             if ( e1.isDuplication() ) {
3742                 return false;
3743             }
3744             if ( !e1.isFusion() ) {
3745                 return false;
3746             }
3747             if ( !e1.asText().toString().equals( "fusion" ) ) {
3748                 return false;
3749             }
3750             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3751                 return false;
3752             }
3753             final Event e11 = new Event( Event.EventType.fusion );
3754             if ( !e11.isEqual( e1 ) ) {
3755                 return false;
3756             }
3757             if ( !e11.toNHX().toString().equals( "" ) ) {
3758                 return false;
3759             }
3760             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3761             if ( e2.isDuplication() ) {
3762                 return false;
3763             }
3764             if ( !e2.isSpeciationOrDuplication() ) {
3765                 return false;
3766             }
3767             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3768                 return false;
3769             }
3770             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3771                 return false;
3772             }
3773             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3774                 return false;
3775             }
3776             if ( e11.isEqual( e2 ) ) {
3777                 return false;
3778             }
3779             final Event e2c = ( Event ) e2.copy();
3780             if ( !e2c.isEqual( e2 ) ) {
3781                 return false;
3782             }
3783             Event e3 = new Event( 1, 2, 3 );
3784             if ( e3.isDuplication() ) {
3785                 return false;
3786             }
3787             if ( e3.isSpeciation() ) {
3788                 return false;
3789             }
3790             if ( e3.isGeneLoss() ) {
3791                 return false;
3792             }
3793             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3794                 return false;
3795             }
3796             final Event e3c = ( Event ) e3.copy();
3797             final Event e3cc = ( Event ) e3c.copy();
3798             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3799                 return false;
3800             }
3801             e3 = null;
3802             if ( !e3c.isEqual( e3cc ) ) {
3803                 return false;
3804             }
3805             Event e4 = new Event( 1, 2, 3 );
3806             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3807                 return false;
3808             }
3809             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3810                 return false;
3811             }
3812             final Event e4c = ( Event ) e4.copy();
3813             e4 = null;
3814             final Event e4cc = ( Event ) e4c.copy();
3815             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3816                 return false;
3817             }
3818             if ( !e4c.isEqual( e4cc ) ) {
3819                 return false;
3820             }
3821             final Event e5 = new Event();
3822             if ( !e5.isUnassigned() ) {
3823                 return false;
3824             }
3825             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3826                 return false;
3827             }
3828             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3829                 return false;
3830             }
3831             final Event e6 = new Event( 1, 0, 0 );
3832             if ( !e6.asText().toString().equals( "duplication" ) ) {
3833                 return false;
3834             }
3835             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3836                 return false;
3837             }
3838             final Event e7 = new Event( 0, 1, 0 );
3839             if ( !e7.asText().toString().equals( "speciation" ) ) {
3840                 return false;
3841             }
3842             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3843                 return false;
3844             }
3845             final Event e8 = new Event( 0, 0, 1 );
3846             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3847                 return false;
3848             }
3849             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3850                 return false;
3851             }
3852         }
3853         catch ( final Exception e ) {
3854             e.printStackTrace( System.out );
3855             return false;
3856         }
3857         return true;
3858     }
3859
3860     private static boolean testDeletionOfExternalNodes() {
3861         try {
3862             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3863             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3864             final PhylogenyWriter w = new PhylogenyWriter();
3865             if ( t0.isEmpty() ) {
3866                 return false;
3867             }
3868             if ( t0.getNumberOfExternalNodes() != 1 ) {
3869                 return false;
3870             }
3871             t0.deleteSubtree( t0.getNode( "A" ), false );
3872             if ( t0.getNumberOfExternalNodes() != 0 ) {
3873                 return false;
3874             }
3875             if ( !t0.isEmpty() ) {
3876                 return false;
3877             }
3878             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3879             if ( t1.getNumberOfExternalNodes() != 2 ) {
3880                 return false;
3881             }
3882             t1.deleteSubtree( t1.getNode( "A" ), false );
3883             if ( t1.getNumberOfExternalNodes() != 1 ) {
3884                 return false;
3885             }
3886             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3887                 return false;
3888             }
3889             t1.deleteSubtree( t1.getNode( "B" ), false );
3890             if ( t1.getNumberOfExternalNodes() != 1 ) {
3891                 return false;
3892             }
3893             t1.deleteSubtree( t1.getNode( "r" ), false );
3894             if ( !t1.isEmpty() ) {
3895                 return false;
3896             }
3897             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3898             if ( t2.getNumberOfExternalNodes() != 3 ) {
3899                 return false;
3900             }
3901             t2.deleteSubtree( t2.getNode( "B" ), false );
3902             if ( t2.getNumberOfExternalNodes() != 2 ) {
3903                 return false;
3904             }
3905             t2.toNewHampshireX();
3906             PhylogenyNode n = t2.getNode( "A" );
3907             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3908                 return false;
3909             }
3910             t2.deleteSubtree( t2.getNode( "A" ), false );
3911             if ( t2.getNumberOfExternalNodes() != 2 ) {
3912                 return false;
3913             }
3914             t2.deleteSubtree( t2.getNode( "C" ), true );
3915             if ( t2.getNumberOfExternalNodes() != 1 ) {
3916                 return false;
3917             }
3918             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3919             if ( t3.getNumberOfExternalNodes() != 4 ) {
3920                 return false;
3921             }
3922             t3.deleteSubtree( t3.getNode( "B" ), true );
3923             if ( t3.getNumberOfExternalNodes() != 3 ) {
3924                 return false;
3925             }
3926             n = t3.getNode( "A" );
3927             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3928                 return false;
3929             }
3930             n = n.getNextExternalNode();
3931             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3932                 return false;
3933             }
3934             t3.deleteSubtree( t3.getNode( "A" ), true );
3935             if ( t3.getNumberOfExternalNodes() != 2 ) {
3936                 return false;
3937             }
3938             n = t3.getNode( "C" );
3939             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3940                 return false;
3941             }
3942             t3.deleteSubtree( t3.getNode( "C" ), true );
3943             if ( t3.getNumberOfExternalNodes() != 1 ) {
3944                 return false;
3945             }
3946             t3.deleteSubtree( t3.getNode( "D" ), true );
3947             if ( t3.getNumberOfExternalNodes() != 0 ) {
3948                 return false;
3949             }
3950             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3951             if ( t4.getNumberOfExternalNodes() != 6 ) {
3952                 return false;
3953             }
3954             t4.deleteSubtree( t4.getNode( "B2" ), true );
3955             if ( t4.getNumberOfExternalNodes() != 5 ) {
3956                 return false;
3957             }
3958             String s = w.toNewHampshire( t4, true ).toString();
3959             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3960                 return false;
3961             }
3962             t4.deleteSubtree( t4.getNode( "B11" ), true );
3963             if ( t4.getNumberOfExternalNodes() != 4 ) {
3964                 return false;
3965             }
3966             t4.deleteSubtree( t4.getNode( "C" ), true );
3967             if ( t4.getNumberOfExternalNodes() != 3 ) {
3968                 return false;
3969             }
3970             n = t4.getNode( "A" );
3971             n = n.getNextExternalNode();
3972             if ( !n.getName().equals( "B12" ) ) {
3973                 return false;
3974             }
3975             n = n.getNextExternalNode();
3976             if ( !n.getName().equals( "D" ) ) {
3977                 return false;
3978             }
3979             s = w.toNewHampshire( t4, true ).toString();
3980             if ( !s.equals( "((A,B12),D);" ) ) {
3981                 return false;
3982             }
3983             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3984             t5.deleteSubtree( t5.getNode( "A" ), true );
3985             if ( t5.getNumberOfExternalNodes() != 5 ) {
3986                 return false;
3987             }
3988             s = w.toNewHampshire( t5, true ).toString();
3989             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3990                 return false;
3991             }
3992             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3993             t6.deleteSubtree( t6.getNode( "B11" ), true );
3994             if ( t6.getNumberOfExternalNodes() != 5 ) {
3995                 return false;
3996             }
3997             s = w.toNewHampshire( t6, false ).toString();
3998             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3999                 return false;
4000             }
4001             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4002             t7.deleteSubtree( t7.getNode( "B12" ), true );
4003             if ( t7.getNumberOfExternalNodes() != 5 ) {
4004                 return false;
4005             }
4006             s = w.toNewHampshire( t7, true ).toString();
4007             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
4008                 return false;
4009             }
4010             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4011             t8.deleteSubtree( t8.getNode( "B2" ), true );
4012             if ( t8.getNumberOfExternalNodes() != 5 ) {
4013                 return false;
4014             }
4015             s = w.toNewHampshire( t8, false ).toString();
4016             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
4017                 return false;
4018             }
4019             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4020             t9.deleteSubtree( t9.getNode( "C" ), true );
4021             if ( t9.getNumberOfExternalNodes() != 5 ) {
4022                 return false;
4023             }
4024             s = w.toNewHampshire( t9, true ).toString();
4025             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
4026                 return false;
4027             }
4028             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4029             t10.deleteSubtree( t10.getNode( "D" ), true );
4030             if ( t10.getNumberOfExternalNodes() != 5 ) {
4031                 return false;
4032             }
4033             s = w.toNewHampshire( t10, true ).toString();
4034             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
4035                 return false;
4036             }
4037             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
4038             t11.deleteSubtree( t11.getNode( "A" ), true );
4039             if ( t11.getNumberOfExternalNodes() != 2 ) {
4040                 return false;
4041             }
4042             s = w.toNewHampshire( t11, true ).toString();
4043             if ( !s.equals( "(B,C);" ) ) {
4044                 return false;
4045             }
4046             t11.deleteSubtree( t11.getNode( "C" ), true );
4047             if ( t11.getNumberOfExternalNodes() != 1 ) {
4048                 return false;
4049             }
4050             s = w.toNewHampshire( t11, false ).toString();
4051             if ( !s.equals( "B;" ) ) {
4052                 return false;
4053             }
4054             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
4055             t12.deleteSubtree( t12.getNode( "B2" ), true );
4056             if ( t12.getNumberOfExternalNodes() != 8 ) {
4057                 return false;
4058             }
4059             s = w.toNewHampshire( t12, true ).toString();
4060             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
4061                 return false;
4062             }
4063             t12.deleteSubtree( t12.getNode( "B3" ), true );
4064             if ( t12.getNumberOfExternalNodes() != 7 ) {
4065                 return false;
4066             }
4067             s = w.toNewHampshire( t12, true ).toString();
4068             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
4069                 return false;
4070             }
4071             t12.deleteSubtree( t12.getNode( "C3" ), true );
4072             if ( t12.getNumberOfExternalNodes() != 6 ) {
4073                 return false;
4074             }
4075             s = w.toNewHampshire( t12, true ).toString();
4076             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
4077                 return false;
4078             }
4079             t12.deleteSubtree( t12.getNode( "A1" ), true );
4080             if ( t12.getNumberOfExternalNodes() != 5 ) {
4081                 return false;
4082             }
4083             s = w.toNewHampshire( t12, true ).toString();
4084             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
4085                 return false;
4086             }
4087             t12.deleteSubtree( t12.getNode( "B1" ), true );
4088             if ( t12.getNumberOfExternalNodes() != 4 ) {
4089                 return false;
4090             }
4091             s = w.toNewHampshire( t12, true ).toString();
4092             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
4093                 return false;
4094             }
4095             t12.deleteSubtree( t12.getNode( "A3" ), true );
4096             if ( t12.getNumberOfExternalNodes() != 3 ) {
4097                 return false;
4098             }
4099             s = w.toNewHampshire( t12, true ).toString();
4100             if ( !s.equals( "(A2,(C1,C2));" ) ) {
4101                 return false;
4102             }
4103             t12.deleteSubtree( t12.getNode( "A2" ), true );
4104             if ( t12.getNumberOfExternalNodes() != 2 ) {
4105                 return false;
4106             }
4107             s = w.toNewHampshire( t12, true ).toString();
4108             if ( !s.equals( "(C1,C2);" ) ) {
4109                 return false;
4110             }
4111             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
4112             t13.deleteSubtree( t13.getNode( "D" ), true );
4113             if ( t13.getNumberOfExternalNodes() != 4 ) {
4114                 return false;
4115             }
4116             s = w.toNewHampshire( t13, true ).toString();
4117             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
4118                 return false;
4119             }
4120             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
4121             t14.deleteSubtree( t14.getNode( "E" ), true );
4122             if ( t14.getNumberOfExternalNodes() != 5 ) {
4123                 return false;
4124             }
4125             s = w.toNewHampshire( t14, true ).toString();
4126             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
4127                 return false;
4128             }
4129             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
4130             t15.deleteSubtree( t15.getNode( "B2" ), true );
4131             if ( t15.getNumberOfExternalNodes() != 11 ) {
4132                 return false;
4133             }
4134             t15.deleteSubtree( t15.getNode( "B1" ), true );
4135             if ( t15.getNumberOfExternalNodes() != 10 ) {
4136                 return false;
4137             }
4138             t15.deleteSubtree( t15.getNode( "B3" ), true );
4139             if ( t15.getNumberOfExternalNodes() != 9 ) {
4140                 return false;
4141             }
4142             t15.deleteSubtree( t15.getNode( "B4" ), true );
4143             if ( t15.getNumberOfExternalNodes() != 8 ) {
4144                 return false;
4145             }
4146             t15.deleteSubtree( t15.getNode( "A1" ), true );
4147             if ( t15.getNumberOfExternalNodes() != 7 ) {
4148                 return false;
4149             }
4150             t15.deleteSubtree( t15.getNode( "C4" ), true );
4151             if ( t15.getNumberOfExternalNodes() != 6 ) {
4152                 return false;
4153             }
4154         }
4155         catch ( final Exception e ) {
4156             e.printStackTrace( System.out );
4157             return false;
4158         }
4159         return true;
4160     }
4161
4162     private static boolean testDescriptiveStatistics() {
4163         try {
4164             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
4165             dss1.addValue( 82 );
4166             dss1.addValue( 78 );
4167             dss1.addValue( 70 );
4168             dss1.addValue( 58 );
4169             dss1.addValue( 42 );
4170             if ( dss1.getN() != 5 ) {
4171                 return false;
4172             }
4173             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
4174                 return false;
4175             }
4176             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
4177                 return false;
4178             }
4179             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
4180                 return false;
4181             }
4182             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
4183                 return false;
4184             }
4185             if ( !Test.isEqual( dss1.median(), 70 ) ) {
4186                 return false;
4187             }
4188             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
4189                 return false;
4190             }
4191             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
4192                 return false;
4193             }
4194             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
4195                 return false;
4196             }
4197             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
4198                 return false;
4199             }
4200             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
4201                 return false;
4202             }
4203             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
4204                 return false;
4205             }
4206             dss1.addValue( 123 );
4207             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
4208                 return false;
4209             }
4210             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
4211                 return false;
4212             }
4213             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
4214                 return false;
4215             }
4216             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
4217             dss2.addValue( -1.85 );
4218             dss2.addValue( 57.5 );
4219             dss2.addValue( 92.78 );
4220             dss2.addValue( 57.78 );
4221             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
4222                 return false;
4223             }
4224             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
4225                 return false;
4226             }
4227             final double[] a = dss2.getDataAsDoubleArray();
4228             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
4229                 return false;
4230             }
4231             dss2.addValue( -100 );
4232             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
4233                 return false;
4234             }
4235             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
4236                 return false;
4237             }
4238             final double[] ds = new double[ 14 ];
4239             ds[ 0 ] = 34;
4240             ds[ 1 ] = 23;
4241             ds[ 2 ] = 1;
4242             ds[ 3 ] = 32;
4243             ds[ 4 ] = 11;
4244             ds[ 5 ] = 2;
4245             ds[ 6 ] = 12;
4246             ds[ 7 ] = 33;
4247             ds[ 8 ] = 13;
4248             ds[ 9 ] = 22;
4249             ds[ 10 ] = 21;
4250             ds[ 11 ] = 35;
4251             ds[ 12 ] = 24;
4252             ds[ 13 ] = 31;
4253             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
4254             if ( bins.length != 4 ) {
4255                 return false;
4256             }
4257             if ( bins[ 0 ] != 2 ) {
4258                 return false;
4259             }
4260             if ( bins[ 1 ] != 3 ) {
4261                 return false;
4262             }
4263             if ( bins[ 2 ] != 4 ) {
4264                 return false;
4265             }
4266             if ( bins[ 3 ] != 5 ) {
4267                 return false;
4268             }
4269             final double[] ds1 = new double[ 9 ];
4270             ds1[ 0 ] = 10.0;
4271             ds1[ 1 ] = 19.0;
4272             ds1[ 2 ] = 9.999;
4273             ds1[ 3 ] = 0.0;
4274             ds1[ 4 ] = 39.9;
4275             ds1[ 5 ] = 39.999;
4276             ds1[ 6 ] = 30.0;
4277             ds1[ 7 ] = 19.999;
4278             ds1[ 8 ] = 30.1;
4279             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
4280             if ( bins1.length != 4 ) {
4281                 return false;
4282             }
4283             if ( bins1[ 0 ] != 2 ) {
4284                 return false;
4285             }
4286             if ( bins1[ 1 ] != 3 ) {
4287                 return false;
4288             }
4289             if ( bins1[ 2 ] != 0 ) {
4290                 return false;
4291             }
4292             if ( bins1[ 3 ] != 4 ) {
4293                 return false;
4294             }
4295             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
4296             if ( bins1_1.length != 3 ) {
4297                 return false;
4298             }
4299             if ( bins1_1[ 0 ] != 3 ) {
4300                 return false;
4301             }
4302             if ( bins1_1[ 1 ] != 2 ) {
4303                 return false;
4304             }
4305             if ( bins1_1[ 2 ] != 4 ) {
4306                 return false;
4307             }
4308             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
4309             if ( bins1_2.length != 3 ) {
4310                 return false;
4311             }
4312             if ( bins1_2[ 0 ] != 2 ) {
4313                 return false;
4314             }
4315             if ( bins1_2[ 1 ] != 2 ) {
4316                 return false;
4317             }
4318             if ( bins1_2[ 2 ] != 2 ) {
4319                 return false;
4320             }
4321             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
4322             dss3.addValue( 1 );
4323             dss3.addValue( 1 );
4324             dss3.addValue( 1 );
4325             dss3.addValue( 2 );
4326             dss3.addValue( 3 );
4327             dss3.addValue( 4 );
4328             dss3.addValue( 5 );
4329             dss3.addValue( 5 );
4330             dss3.addValue( 5 );
4331             dss3.addValue( 6 );
4332             dss3.addValue( 7 );
4333             dss3.addValue( 8 );
4334             dss3.addValue( 9 );
4335             dss3.addValue( 10 );
4336             dss3.addValue( 10 );
4337             dss3.addValue( 10 );
4338             final AsciiHistogram histo = new AsciiHistogram( dss3 );
4339             histo.toStringBuffer( 10, '=', 40, 5 );
4340             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
4341         }
4342         catch ( final Exception e ) {
4343             e.printStackTrace( System.out );
4344             return false;
4345         }
4346         return true;
4347     }
4348
4349     private static boolean testDir( final String file ) {
4350         try {
4351             final File f = new File( file );
4352             if ( !f.exists() ) {
4353                 return false;
4354             }
4355             if ( !f.isDirectory() ) {
4356                 return false;
4357             }
4358             if ( !f.canRead() ) {
4359                 return false;
4360             }
4361         }
4362         catch ( final Exception e ) {
4363             return false;
4364         }
4365         return true;
4366     }
4367
4368     private static boolean testEbiEntryRetrieval() {
4369         try {
4370             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
4371             if ( !entry.getAccession().equals( "AAK41263" ) ) {
4372                 System.out.println( entry.getAccession() );
4373                 return false;
4374             }
4375             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
4376                 System.out.println( entry.getTaxonomyScientificName() );
4377                 return false;
4378             }
4379             if ( !entry.getSequenceName()
4380                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4381                 System.out.println( entry.getSequenceName() );
4382                 return false;
4383             }
4384             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4385                 System.out.println( entry.getGeneName() );
4386                 return false;
4387             }
4388             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4389                 System.out.println( entry.getTaxonomyIdentifier() );
4390                 return false;
4391             }
4392             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4393                 System.out.println( entry.getAnnotations().first().getRefValue() );
4394                 return false;
4395             }
4396             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4397                 System.out.println( entry.getAnnotations().first().getRefSource() );
4398                 return false;
4399             }
4400             if ( entry.getCrossReferences().size() < 1 ) {
4401                 return false;
4402             }
4403             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4404             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4405                 return false;
4406             }
4407             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4408                 System.out.println( entry1.getTaxonomyScientificName() );
4409                 return false;
4410             }
4411             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4412                 System.out.println( entry1.getSequenceName() );
4413                 return false;
4414             }
4415             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4416                 System.out.println( entry1.getTaxonomyIdentifier() );
4417                 return false;
4418             }
4419             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4420                 System.out.println( entry1.getGeneName() );
4421                 return false;
4422             }
4423             if ( entry1.getCrossReferences().size() < 1 ) {
4424                 return false;
4425             }
4426             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4427             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4428                 return false;
4429             }
4430             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4431                 System.out.println( entry2.getTaxonomyScientificName() );
4432                 return false;
4433             }
4434             if ( !entry2.getSequenceName()
4435                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4436                 System.out.println( entry2.getSequenceName() );
4437                 return false;
4438             }
4439             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4440                 System.out.println( entry2.getTaxonomyIdentifier() );
4441                 return false;
4442             }
4443             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4444                 System.out.println( entry2.getGeneName() );
4445                 return false;
4446             }
4447             if ( entry2.getCrossReferences().size() < 1 ) {
4448                 return false;
4449             }
4450             if ( !entry2.getChromosome().equals( "20" ) ) {
4451                 return false;
4452             }
4453             if ( !entry2.getMap().equals( "20q11.22" ) ) {
4454                 return false;
4455             }
4456             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4457             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4458                 return false;
4459             }
4460             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4461                 System.out.println( entry3.getTaxonomyScientificName() );
4462                 return false;
4463             }
4464             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4465                 System.out.println( entry3.getSequenceName() );
4466                 return false;
4467             }
4468             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4469                 System.out.println( entry3.getTaxonomyIdentifier() );
4470                 return false;
4471             }
4472             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4473                 System.out.println( entry3.getSequenceSymbol() );
4474                 return false;
4475             }
4476             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4477                 return false;
4478             }
4479             if ( entry3.getCrossReferences().size() < 1 ) {
4480                 return false;
4481             }
4482             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4483             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4484                 return false;
4485             }
4486             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4487                 System.out.println( entry4.getTaxonomyScientificName() );
4488                 return false;
4489             }
4490             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4491                 System.out.println( entry4.getSequenceName() );
4492                 return false;
4493             }
4494             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4495                 System.out.println( entry4.getTaxonomyIdentifier() );
4496                 return false;
4497             }
4498             if ( !entry4.getGeneName().equals( "ras" ) ) {
4499                 System.out.println( entry4.getGeneName() );
4500                 return false;
4501             }
4502             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4503             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4504                 return false;
4505             }
4506             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4507                 System.out.println( entry5.getTaxonomyScientificName() );
4508                 return false;
4509             }
4510             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4511                 System.out.println( entry5.getSequenceName() );
4512                 return false;
4513             }
4514             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4515                 System.out.println( entry5.getTaxonomyIdentifier() );
4516                 return false;
4517             }
4518             final SequenceDatabaseEntry entry6 = SequenceDbWsTools.obtainEntry( "M30539" );
4519             if ( !entry6.getAccession().equals( "M30539" ) ) {
4520                 return false;
4521             }
4522             if ( !entry6.getGeneName().equals( "ras" ) ) {
4523                 return false;
4524             }
4525             if ( !entry6.getSequenceName().equals( "Human SK2 c-Ha-ras-1 oncogene-encoded protein gene, exon 1" ) ) {
4526                 return false;
4527             }
4528             if ( !entry6.getTaxonomyIdentifier().equals( "9606" ) ) {
4529                 return false;
4530             }
4531             if ( !entry6.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4532                 return false;
4533             }
4534             if ( entry6.getCrossReferences().size() < 1 ) {
4535                 return false;
4536             }
4537         }
4538         catch ( final IOException e ) {
4539             System.out.println();
4540             System.out.println( "the following might be due to absence internet connection:" );
4541             e.printStackTrace( System.out );
4542             return true;
4543         }
4544         catch ( final Exception e ) {
4545             e.printStackTrace();
4546             return false;
4547         }
4548         return true;
4549     }
4550
4551     private static boolean testExternalNodeRelatedMethods() {
4552         try {
4553             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4554             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4555             PhylogenyNode n = t1.getNode( "A" );
4556             n = n.getNextExternalNode();
4557             if ( !n.getName().equals( "B" ) ) {
4558                 return false;
4559             }
4560             n = n.getNextExternalNode();
4561             if ( !n.getName().equals( "C" ) ) {
4562                 return false;
4563             }
4564             n = n.getNextExternalNode();
4565             if ( !n.getName().equals( "D" ) ) {
4566                 return false;
4567             }
4568             n = t1.getNode( "B" );
4569             while ( !n.isLastExternalNode() ) {
4570                 n = n.getNextExternalNode();
4571             }
4572             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4573             n = t2.getNode( "A" );
4574             n = n.getNextExternalNode();
4575             if ( !n.getName().equals( "B" ) ) {
4576                 return false;
4577             }
4578             n = n.getNextExternalNode();
4579             if ( !n.getName().equals( "C" ) ) {
4580                 return false;
4581             }
4582             n = n.getNextExternalNode();
4583             if ( !n.getName().equals( "D" ) ) {
4584                 return false;
4585             }
4586             n = t2.getNode( "B" );
4587             while ( !n.isLastExternalNode() ) {
4588                 n = n.getNextExternalNode();
4589             }
4590             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4591             n = t3.getNode( "A" );
4592             n = n.getNextExternalNode();
4593             if ( !n.getName().equals( "B" ) ) {
4594                 return false;
4595             }
4596             n = n.getNextExternalNode();
4597             if ( !n.getName().equals( "C" ) ) {
4598                 return false;
4599             }
4600             n = n.getNextExternalNode();
4601             if ( !n.getName().equals( "D" ) ) {
4602                 return false;
4603             }
4604             n = n.getNextExternalNode();
4605             if ( !n.getName().equals( "E" ) ) {
4606                 return false;
4607             }
4608             n = n.getNextExternalNode();
4609             if ( !n.getName().equals( "F" ) ) {
4610                 return false;
4611             }
4612             n = n.getNextExternalNode();
4613             if ( !n.getName().equals( "G" ) ) {
4614                 return false;
4615             }
4616             n = n.getNextExternalNode();
4617             if ( !n.getName().equals( "H" ) ) {
4618                 return false;
4619             }
4620             n = t3.getNode( "B" );
4621             while ( !n.isLastExternalNode() ) {
4622                 n = n.getNextExternalNode();
4623             }
4624             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4625             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4626                 final PhylogenyNode node = iter.next();
4627             }
4628             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4629             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4630                 final PhylogenyNode node = iter.next();
4631             }
4632             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4633             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4634             if ( !iter.next().getName().equals( "A" ) ) {
4635                 return false;
4636             }
4637             if ( !iter.next().getName().equals( "B" ) ) {
4638                 return false;
4639             }
4640             if ( !iter.next().getName().equals( "C" ) ) {
4641                 return false;
4642             }
4643             if ( !iter.next().getName().equals( "D" ) ) {
4644                 return false;
4645             }
4646             if ( !iter.next().getName().equals( "E" ) ) {
4647                 return false;
4648             }
4649             if ( !iter.next().getName().equals( "F" ) ) {
4650                 return false;
4651             }
4652             if ( iter.hasNext() ) {
4653                 return false;
4654             }
4655         }
4656         catch ( final Exception e ) {
4657             e.printStackTrace( System.out );
4658             return false;
4659         }
4660         return true;
4661     }
4662
4663     private static boolean testExtractSNFromNodeName() {
4664         try {
4665             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4666                 return false;
4667             }
4668             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4669                 return false;
4670             }
4671             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4672                 return false;
4673             }
4674             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4675                     .equals( "Mus musculus musculus" ) ) {
4676                 return false;
4677             }
4678             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4679                     .equals( "Mus musculus musculus" ) ) {
4680                 return false;
4681             }
4682             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4683                     .equals( "Mus musculus musculus" ) ) {
4684                 return false;
4685             }
4686             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4687                     .equals( "Mus musculus musculus" ) ) {
4688                 return false;
4689             }
4690             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4691                 return false;
4692             }
4693             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4694                     .equals( "Mus musculus musculus" ) ) {
4695                 return false;
4696             }
4697             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4698                     .equals( "Mus musculus musculus" ) ) {
4699                 return false;
4700             }
4701             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4702                 return false;
4703             }
4704             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4705                 return false;
4706             }
4707             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4708                 return false;
4709             }
4710             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4711                 return false;
4712             }
4713             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4714                     .equals( "Mus musculus musculus" ) ) {
4715                 return false;
4716             }
4717             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4718                 return false;
4719             }
4720             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4721                 return false;
4722             }
4723             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4724                 return false;
4725             }
4726             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4727                 return false;
4728             }
4729             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4730                 return false;
4731             }
4732             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4733                 return false;
4734             }
4735             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4736                 return false;
4737             }
4738             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4739                 return false;
4740             }
4741             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4742                     .equals( "Mus musculus" ) ) {
4743                 return false;
4744             }
4745             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4746                     .equals( "Mus musculus" ) ) {
4747                 return false;
4748             }
4749             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4750                 return false;
4751             }
4752             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4753                     .equals( "Mus musculus musculus" ) ) {
4754                 return false;
4755             }
4756             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4757                     .equals( "Mus musculus musculus" ) ) {
4758                 return false;
4759             }
4760             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4761                     .equals( "Mus musculus musculus" ) ) {
4762                 return false;
4763             }
4764             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4765                 return false;
4766             }
4767             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4768                     .equals( "Pilostyles mexicana" ) ) {
4769                 return false;
4770             }
4771             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4772                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4773                 return false;
4774             }
4775             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4776                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4777                 return false;
4778             }
4779             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4780                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4781                 return false;
4782             }
4783             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4784                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4785                 return false;
4786             }
4787             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4788                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4789                 return false;
4790             }
4791             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4792                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4793                 return false;
4794             }
4795             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4796                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4797                 return false;
4798             }
4799             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4800                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4801                 return false;
4802             }
4803             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4804                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4805                 return false;
4806             }
4807             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4808                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4809                 return false;
4810             }
4811             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4812                     .equals( "Escherichia coli (strain K12)" ) ) {
4813                 return false;
4814             }
4815             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4816                     .equals( "Escherichia coli (strain K12)" ) ) {
4817                 return false;
4818             }
4819             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4820                     .equals( "Escherichia coli (str. K12)" ) ) {
4821                 return false;
4822             }
4823             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4824                     .equals( "Escherichia coli (str. K12)" ) ) {
4825                 return false;
4826             }
4827             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4828                     .equals( "Escherichia coli (str. K12)" ) ) {
4829                 return false;
4830             }
4831             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4832                     .equals( "Escherichia coli (var. K12)" ) ) {
4833                 return false;
4834             }
4835             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4836                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4837                 return false;
4838             }
4839             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4840                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4841                 return false;
4842             }
4843             if ( !ParserUtils
4844                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4845                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4846                 return false;
4847             }
4848             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4849                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4850                 return false;
4851             }
4852             if ( !ParserUtils
4853                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4854                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4855                 return false;
4856             }
4857             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4858                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4859                 return false;
4860             }
4861             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4862                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4863                 return false;
4864             }
4865             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4866                 return false;
4867             }
4868             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4869                 return false;
4870             }
4871             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4872                 return false;
4873             }
4874             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4875                     .equals( "Macrocera sp." ) ) {
4876                 return false;
4877             }
4878             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4879                 return false;
4880             }
4881             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4882                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4883                 return false;
4884             }
4885             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4886                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4887                 return false;
4888             }
4889             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4890                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4891                 return false;
4892             }
4893             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4894                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4895                 return false;
4896             }
4897         }
4898         catch ( final Exception e ) {
4899             e.printStackTrace( System.out );
4900             return false;
4901         }
4902         return true;
4903     }
4904
4905     private static boolean testExtractTaxonomyDataFromNodeName() {
4906         try {
4907             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
4908             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4909                 return false;
4910             }
4911             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
4912             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4913                 return false;
4914             }
4915             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
4916             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4917                 return false;
4918             }
4919             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
4920             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4921                 return false;
4922             }
4923             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
4924             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4925                 return false;
4926             }
4927             n = new PhylogenyNode( "HNRPR_HUMAN" );
4928             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4929                 return false;
4930             }
4931             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
4932             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4933                 return false;
4934             }
4935         }
4936         catch ( final Exception e ) {
4937             e.printStackTrace( System.out );
4938             return false;
4939         }
4940         return true;
4941     }
4942
4943     private static boolean testExtractTaxonomyCodeFromNodeName() {
4944         try {
4945             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4946                 return false;
4947             }
4948             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4949                     .equals( "SOYBN" ) ) {
4950                 return false;
4951             }
4952             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4953                     .equals( "ARATH" ) ) {
4954                 return false;
4955             }
4956             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4957                     .equals( "ARATH" ) ) {
4958                 return false;
4959             }
4960             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4961                 return false;
4962             }
4963             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4964                 return false;
4965             }
4966             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4967                 return false;
4968             }
4969             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4970                     .equals( "SOYBN" ) ) {
4971                 return false;
4972             }
4973             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4974                     .equals( "SOYBN" ) ) {
4975                 return false;
4976             }
4977             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4978                     .equals( "SOYBN" ) ) {
4979                 return false;
4980             }
4981             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4982                     .equals( "SOYBN" ) ) {
4983                 return false;
4984             }
4985             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4986                     .equals( "SOYBN" ) ) {
4987                 return false;
4988             }
4989             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4990                     .equals( "SOYBN" ) ) {
4991                 return false;
4992             }
4993             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4994                     .equals( "SOYBN" ) ) {
4995                 return false;
4996             }
4997             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4998                     .equals( "SOYBN" ) ) {
4999                 return false;
5000             }
5001             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
5002                 return false;
5003             }
5004             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
5005                     .equals( "SOYBN" ) ) {
5006                 return false;
5007             }
5008             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
5009                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
5010                 return false;
5011             }
5012             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
5013                     .equals( "9YX45" ) ) {
5014                 return false;
5015             }
5016             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
5017                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5018                                                                .equals( "MOUSE" ) ) {
5019                 return false;
5020             }
5021             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
5022                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5023                                                                .equals( "MOUSE" ) ) {
5024                 return false;
5025             }
5026             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
5027                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5028                                                                .equals( "MOUSE" ) ) {
5029                 return false;
5030             }
5031             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
5032                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5033                 return false;
5034             }
5035             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
5036                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5037                 return false;
5038             }
5039             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5040                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
5041                 return false;
5042             }
5043             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5044                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
5045                 return false;
5046             }
5047             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
5048                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
5049                 return false;
5050             }
5051             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
5052                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5053                 return false;
5054             }
5055             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
5056                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5057                 return false;
5058             }
5059             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5060                     .equals( "RAT" ) ) {
5061                 return false;
5062             }
5063             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5064                     .equals( "PIG" ) ) {
5065                 return false;
5066             }
5067             if ( !ParserUtils
5068                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5069                     .equals( "MOUSE" ) ) {
5070                 return false;
5071             }
5072             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5073                     .equals( "MOUSE" ) ) {
5074                 return false;
5075             }
5076             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5077                 return false;
5078             }
5079         }
5080         catch ( final Exception e ) {
5081             e.printStackTrace( System.out );
5082             return false;
5083         }
5084         return true;
5085     }
5086
5087     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
5088         try {
5089             PhylogenyNode n = new PhylogenyNode();
5090             n.setName( "tr|B3RJ64" );
5091             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5092                 return false;
5093             }
5094             n.setName( "tr.B3RJ64" );
5095             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5096                 return false;
5097             }
5098             n.setName( "tr=B3RJ64" );
5099             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5100                 return false;
5101             }
5102             n.setName( "tr-B3RJ64" );
5103             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5104                 return false;
5105             }
5106             n.setName( "tr/B3RJ64" );
5107             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5108                 return false;
5109             }
5110             n.setName( "tr\\B3RJ64" );
5111             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5112                 return false;
5113             }
5114             n.setName( "tr_B3RJ64" );
5115             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5116                 return false;
5117             }
5118             n.setName( " tr|B3RJ64 " );
5119             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5120                 return false;
5121             }
5122             n.setName( "-tr|B3RJ64-" );
5123             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5124                 return false;
5125             }
5126             n.setName( "-tr=B3RJ64-" );
5127             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5128                 return false;
5129             }
5130             n.setName( "_tr=B3RJ64_" );
5131             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5132                 return false;
5133             }
5134             n.setName( " tr_tr|B3RJ64_sp|123 " );
5135             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5136                 return false;
5137             }
5138             n.setName( "B3RJ64" );
5139             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5140                 return false;
5141             }
5142             n.setName( "sp|B3RJ64" );
5143             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5144                 return false;
5145             }
5146             n.setName( "sp|B3RJ64C" );
5147             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5148                 return false;
5149             }
5150             n.setName( "sp B3RJ64" );
5151             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5152                 return false;
5153             }
5154             n.setName( "sp|B3RJ6X" );
5155             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5156                 return false;
5157             }
5158             n.setName( "sp|B3RJ6" );
5159             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5160                 return false;
5161             }
5162             n.setName( "K1PYK7_CRAGI" );
5163             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5164                 return false;
5165             }
5166             n.setName( "K1PYK7_PEA" );
5167             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
5168                 return false;
5169             }
5170             n.setName( "K1PYK7_RAT" );
5171             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
5172                 return false;
5173             }
5174             n.setName( "K1PYK7_PIG" );
5175             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5176                 return false;
5177             }
5178             n.setName( "~K1PYK7_PIG~" );
5179             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5180                 return false;
5181             }
5182             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
5183             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5184                 return false;
5185             }
5186             n.setName( "K1PYKX_CRAGI" );
5187             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5188                 return false;
5189             }
5190             n.setName( "XXXXX_CRAGI" );
5191             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
5192                 return false;
5193             }
5194             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
5195             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
5196                 return false;
5197             }
5198             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
5199             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5200                 return false;
5201             }
5202             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
5203             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
5204                 return false;
5205             }
5206             n = new PhylogenyNode();
5207             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
5208             seq.setSymbol( "K1PYK7_CRAGI" );
5209             n.getNodeData().addSequence( seq );
5210             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5211                 return false;
5212             }
5213             seq.setSymbol( "tr|B3RJ64" );
5214             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5215                 return false;
5216             }
5217             n = new PhylogenyNode();
5218             seq = new org.forester.phylogeny.data.Sequence();
5219             seq.setName( "K1PYK7_CRAGI" );
5220             n.getNodeData().addSequence( seq );
5221             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5222                 return false;
5223             }
5224             seq.setName( "tr|B3RJ64" );
5225             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5226                 return false;
5227             }
5228             n = new PhylogenyNode();
5229             seq = new org.forester.phylogeny.data.Sequence();
5230             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
5231             n.getNodeData().addSequence( seq );
5232             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
5233                 return false;
5234             }
5235             n = new PhylogenyNode();
5236             seq = new org.forester.phylogeny.data.Sequence();
5237             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
5238             n.getNodeData().addSequence( seq );
5239             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5240                 return false;
5241             }
5242             //
5243             n = new PhylogenyNode();
5244             n.setName( "ACP19736" );
5245             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5246                 return false;
5247             }
5248             n = new PhylogenyNode();
5249             n.setName( "|ACP19736|" );
5250             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5251                 return false;
5252             }
5253         }
5254         catch ( final Exception e ) {
5255             e.printStackTrace( System.out );
5256             return false;
5257         }
5258         return true;
5259     }
5260
5261     private static boolean testFastaParser() {
5262         try {
5263             FileInputStream fis1 = new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" );
5264             if ( !FastaParser.isLikelyFasta( fis1 ) ) {
5265                 fis1.close();
5266                 return false;
5267             }
5268             else {
5269                 fis1.close();
5270             }
5271             FileInputStream fis2 = new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" );
5272             if ( FastaParser.isLikelyFasta( fis2 ) ) {
5273                 fis2.close();
5274                 return false;
5275             }
5276             else {
5277                 fis2.close();
5278             }
5279             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
5280             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
5281                 return false;
5282             }
5283             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
5284                 return false;
5285             }
5286             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
5287                 return false;
5288             }
5289             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
5290                 return false;
5291             }
5292             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
5293                 return false;
5294             }
5295             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
5296                 return false;
5297             }
5298         }
5299         catch ( final Exception e ) {
5300             e.printStackTrace();
5301             return false;
5302         }
5303         return true;
5304     }
5305
5306     private static boolean testGenbankAccessorParsing() {
5307         //The format for GenBank Accession numbers are:
5308         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
5309         //Protein:    3 letters + 5 numerals
5310         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
5311         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
5312             return false;
5313         }
5314         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
5315             return false;
5316         }
5317         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
5318             return false;
5319         }
5320         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
5321             return false;
5322         }
5323         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
5324             return false;
5325         }
5326         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
5327             return false;
5328         }
5329         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
5330             return false;
5331         }
5332         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
5333             return false;
5334         }
5335         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
5336             return false;
5337         }
5338         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
5339             return false;
5340         }
5341         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
5342             return false;
5343         }
5344         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
5345             return false;
5346         }
5347         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
5348             return false;
5349         }
5350         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
5351             return false;
5352         }
5353         return true;
5354     }
5355
5356     private static boolean testGeneralMsaParser() {
5357         try {
5358             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
5359             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
5360             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
5361             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
5362             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
5363             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
5364             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
5365             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
5366             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5367                 return false;
5368             }
5369             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5370                 return false;
5371             }
5372             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5373                 return false;
5374             }
5375             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5376                 return false;
5377             }
5378             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5379                 return false;
5380             }
5381             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5382                 return false;
5383             }
5384             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5385                 return false;
5386             }
5387             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5388                 return false;
5389             }
5390             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5391                 return false;
5392             }
5393             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5394                 return false;
5395             }
5396             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5397                 return false;
5398             }
5399             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5400                 return false;
5401             }
5402             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5403             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5404                 return false;
5405             }
5406             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5407                 return false;
5408             }
5409             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5410                 return false;
5411             }
5412             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5413             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5414                 return false;
5415             }
5416             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5417                 return false;
5418             }
5419             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5420                 return false;
5421             }
5422             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5423             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5424                 return false;
5425             }
5426             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5427                 return false;
5428             }
5429             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5430                 return false;
5431             }
5432         }
5433         catch ( final Exception e ) {
5434             e.printStackTrace();
5435             return false;
5436         }
5437         return true;
5438     }
5439
5440     private static boolean testGeneralTable() {
5441         try {
5442             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5443             t0.setValue( 3, 2, "23" );
5444             t0.setValue( 10, 1, "error" );
5445             t0.setValue( 10, 1, "110" );
5446             t0.setValue( 9, 1, "19" );
5447             t0.setValue( 1, 10, "101" );
5448             t0.setValue( 10, 10, "1010" );
5449             t0.setValue( 100, 10, "10100" );
5450             t0.setValue( 0, 0, "00" );
5451             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5452                 return false;
5453             }
5454             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5455                 return false;
5456             }
5457             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5458                 return false;
5459             }
5460             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5461                 return false;
5462             }
5463             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5464                 return false;
5465             }
5466             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5467                 return false;
5468             }
5469             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5470                 return false;
5471             }
5472             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5473                 return false;
5474             }
5475             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5476                 return false;
5477             }
5478             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5479             t1.setValue( "3", "2", "23" );
5480             t1.setValue( "10", "1", "error" );
5481             t1.setValue( "10", "1", "110" );
5482             t1.setValue( "9", "1", "19" );
5483             t1.setValue( "1", "10", "101" );
5484             t1.setValue( "10", "10", "1010" );
5485             t1.setValue( "100", "10", "10100" );
5486             t1.setValue( "0", "0", "00" );
5487             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5488             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5489                 return false;
5490             }
5491             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5492                 return false;
5493             }
5494             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5495                 return false;
5496             }
5497             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5498                 return false;
5499             }
5500             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5501                 return false;
5502             }
5503             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5504                 return false;
5505             }
5506             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5507                 return false;
5508             }
5509             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5510                 return false;
5511             }
5512             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5513                 return false;
5514             }
5515             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5516                 return false;
5517             }
5518         }
5519         catch ( final Exception e ) {
5520             e.printStackTrace( System.out );
5521             return false;
5522         }
5523         return true;
5524     }
5525
5526     private static boolean testGetDistance() {
5527         try {
5528             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5529             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",
5530                                                  new NHXParser() )[ 0 ];
5531             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5532                 return false;
5533             }
5534             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5535                 return false;
5536             }
5537             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5538                 return false;
5539             }
5540             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5541                 return false;
5542             }
5543             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5544                 return false;
5545             }
5546             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5547                 return false;
5548             }
5549             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5550                 return false;
5551             }
5552             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5553                 return false;
5554             }
5555             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5556                 return false;
5557             }
5558             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5559                 return false;
5560             }
5561             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5562                 return false;
5563             }
5564             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5565                 return false;
5566             }
5567             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5568                 return false;
5569             }
5570             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5571                 return false;
5572             }
5573             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5574                 return false;
5575             }
5576             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5577                 return false;
5578             }
5579             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5580                 return false;
5581             }
5582             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5583                 return false;
5584             }
5585             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5586                 return false;
5587             }
5588             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5589                 return false;
5590             }
5591             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5592                 return false;
5593             }
5594             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5595                 return false;
5596             }
5597             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5598                 return false;
5599             }
5600             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5601                 return false;
5602             }
5603             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5604                 return false;
5605             }
5606             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5607                 return false;
5608             }
5609             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5610                 return false;
5611             }
5612             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5613                 return false;
5614             }
5615             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5616                 return false;
5617             }
5618             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5619                 return false;
5620             }
5621             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5622                 return false;
5623             }
5624             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",
5625                                                  new NHXParser() )[ 0 ];
5626             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5627                 return false;
5628             }
5629             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5630                 return false;
5631             }
5632             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5633                 return false;
5634             }
5635             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5636                 return false;
5637             }
5638             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5639                 return false;
5640             }
5641             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5642                 return false;
5643             }
5644             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5645                 return false;
5646             }
5647             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5648                 return false;
5649             }
5650             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5651                 return false;
5652             }
5653             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5654                 return false;
5655             }
5656             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5657                 return false;
5658             }
5659         }
5660         catch ( final Exception e ) {
5661             e.printStackTrace( System.out );
5662             return false;
5663         }
5664         return true;
5665     }
5666
5667     private static boolean testGetLCA() {
5668         try {
5669             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5670             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5671                                                  new NHXParser() )[ 0 ];
5672             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5673             if ( !A.getName().equals( "A" ) ) {
5674                 return false;
5675             }
5676             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5677             if ( !gh.getName().equals( "gh" ) ) {
5678                 return false;
5679             }
5680             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5681             if ( !ab.getName().equals( "ab" ) ) {
5682                 return false;
5683             }
5684             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5685             if ( !ab2.getName().equals( "ab" ) ) {
5686                 return false;
5687             }
5688             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5689             if ( !gh2.getName().equals( "gh" ) ) {
5690                 return false;
5691             }
5692             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5693             if ( !gh3.getName().equals( "gh" ) ) {
5694                 return false;
5695             }
5696             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5697             if ( !abc.getName().equals( "abc" ) ) {
5698                 return false;
5699             }
5700             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5701             if ( !abc2.getName().equals( "abc" ) ) {
5702                 return false;
5703             }
5704             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5705             if ( !abcd.getName().equals( "abcd" ) ) {
5706                 return false;
5707             }
5708             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5709             if ( !abcd2.getName().equals( "abcd" ) ) {
5710                 return false;
5711             }
5712             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5713             if ( !abcdef.getName().equals( "abcdef" ) ) {
5714                 return false;
5715             }
5716             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5717             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5718                 return false;
5719             }
5720             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5721             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5722                 return false;
5723             }
5724             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5725             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5726                 return false;
5727             }
5728             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5729             if ( !abcde.getName().equals( "abcde" ) ) {
5730                 return false;
5731             }
5732             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5733             if ( !abcde2.getName().equals( "abcde" ) ) {
5734                 return false;
5735             }
5736             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5737             if ( !r.getName().equals( "abcdefgh" ) ) {
5738                 return false;
5739             }
5740             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5741             if ( !r2.getName().equals( "abcdefgh" ) ) {
5742                 return false;
5743             }
5744             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5745             if ( !r3.getName().equals( "abcdefgh" ) ) {
5746                 return false;
5747             }
5748             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5749             if ( !abcde3.getName().equals( "abcde" ) ) {
5750                 return false;
5751             }
5752             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5753             if ( !abcde4.getName().equals( "abcde" ) ) {
5754                 return false;
5755             }
5756             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5757             if ( !ab3.getName().equals( "ab" ) ) {
5758                 return false;
5759             }
5760             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5761             if ( !ab4.getName().equals( "ab" ) ) {
5762                 return false;
5763             }
5764             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5765             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5766             if ( !cd.getName().equals( "cd" ) ) {
5767                 return false;
5768             }
5769             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5770             if ( !cd2.getName().equals( "cd" ) ) {
5771                 return false;
5772             }
5773             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5774             if ( !cde.getName().equals( "cde" ) ) {
5775                 return false;
5776             }
5777             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5778             if ( !cde2.getName().equals( "cde" ) ) {
5779                 return false;
5780             }
5781             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5782             if ( !cdef.getName().equals( "cdef" ) ) {
5783                 return false;
5784             }
5785             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5786             if ( !cdef2.getName().equals( "cdef" ) ) {
5787                 return false;
5788             }
5789             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5790             if ( !cdef3.getName().equals( "cdef" ) ) {
5791                 return false;
5792             }
5793             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5794             if ( !rt.getName().equals( "r" ) ) {
5795                 return false;
5796             }
5797             final Phylogeny p3 = factory
5798                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5799                              new NHXParser() )[ 0 ];
5800             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5801             if ( !bc_3.getName().equals( "bc" ) ) {
5802                 return false;
5803             }
5804             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5805             if ( !ac_3.getName().equals( "abc" ) ) {
5806                 return false;
5807             }
5808             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5809             if ( !ad_3.getName().equals( "abcde" ) ) {
5810                 return false;
5811             }
5812             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5813             if ( !af_3.getName().equals( "abcdef" ) ) {
5814                 return false;
5815             }
5816             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5817             if ( !ag_3.getName().equals( "" ) ) {
5818                 return false;
5819             }
5820             if ( !ag_3.isRoot() ) {
5821                 return false;
5822             }
5823             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5824             if ( !al_3.getName().equals( "" ) ) {
5825                 return false;
5826             }
5827             if ( !al_3.isRoot() ) {
5828                 return false;
5829             }
5830             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5831             if ( !kl_3.getName().equals( "" ) ) {
5832                 return false;
5833             }
5834             if ( !kl_3.isRoot() ) {
5835                 return false;
5836             }
5837             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5838             if ( !fl_3.getName().equals( "" ) ) {
5839                 return false;
5840             }
5841             if ( !fl_3.isRoot() ) {
5842                 return false;
5843             }
5844             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5845             if ( !gk_3.getName().equals( "ghijk" ) ) {
5846                 return false;
5847             }
5848             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5849             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5850             if ( !r_4.getName().equals( "r" ) ) {
5851                 return false;
5852             }
5853             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5854             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5855             if ( !r_5.getName().equals( "root" ) ) {
5856                 return false;
5857             }
5858             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5859             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5860             if ( !r_6.getName().equals( "rot" ) ) {
5861                 return false;
5862             }
5863             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5864             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5865             if ( !r_7.getName().equals( "rott" ) ) {
5866                 return false;
5867             }
5868         }
5869         catch ( final Exception e ) {
5870             e.printStackTrace( System.out );
5871             return false;
5872         }
5873         return true;
5874     }
5875
5876     private static boolean testGetLCA2() {
5877         try {
5878             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5879             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5880             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5881             PhylogenyMethods.preOrderReId( p_a );
5882             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5883                                                                                               p_a.getNode( "a" ) );
5884             if ( !p_a_1.getName().equals( "a" ) ) {
5885                 return false;
5886             }
5887             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5888             PhylogenyMethods.preOrderReId( p_b );
5889             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5890                                                                                               p_b.getNode( "a" ) );
5891             if ( !p_b_1.getName().equals( "b" ) ) {
5892                 return false;
5893             }
5894             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5895                                                                                               p_b.getNode( "b" ) );
5896             if ( !p_b_2.getName().equals( "b" ) ) {
5897                 return false;
5898             }
5899             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5900             PhylogenyMethods.preOrderReId( p_c );
5901             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5902                                                                                               p_c.getNode( "a" ) );
5903             if ( !p_c_1.getName().equals( "b" ) ) {
5904                 return false;
5905             }
5906             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5907                                                                                               p_c.getNode( "c" ) );
5908             if ( !p_c_2.getName().equals( "c" ) ) {
5909                 System.out.println( p_c_2.getName() );
5910                 System.exit( -1 );
5911                 return false;
5912             }
5913             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5914                                                                                               p_c.getNode( "b" ) );
5915             if ( !p_c_3.getName().equals( "b" ) ) {
5916                 return false;
5917             }
5918             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5919                                                                                               p_c.getNode( "a" ) );
5920             if ( !p_c_4.getName().equals( "c" ) ) {
5921                 return false;
5922             }
5923             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5924                                                  new NHXParser() )[ 0 ];
5925             PhylogenyMethods.preOrderReId( p1 );
5926             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5927                                                                                           p1.getNode( "A" ) );
5928             if ( !A.getName().equals( "A" ) ) {
5929                 return false;
5930             }
5931             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5932                                                                                            p1.getNode( "gh" ) );
5933             if ( !gh.getName().equals( "gh" ) ) {
5934                 return false;
5935             }
5936             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5937                                                                                            p1.getNode( "B" ) );
5938             if ( !ab.getName().equals( "ab" ) ) {
5939                 return false;
5940             }
5941             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5942                                                                                             p1.getNode( "A" ) );
5943             if ( !ab2.getName().equals( "ab" ) ) {
5944                 return false;
5945             }
5946             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5947                                                                                             p1.getNode( "G" ) );
5948             if ( !gh2.getName().equals( "gh" ) ) {
5949                 return false;
5950             }
5951             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5952                                                                                             p1.getNode( "H" ) );
5953             if ( !gh3.getName().equals( "gh" ) ) {
5954                 return false;
5955             }
5956             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5957                                                                                             p1.getNode( "A" ) );
5958             if ( !abc.getName().equals( "abc" ) ) {
5959                 return false;
5960             }
5961             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5962                                                                                              p1.getNode( "C" ) );
5963             if ( !abc2.getName().equals( "abc" ) ) {
5964                 return false;
5965             }
5966             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5967                                                                                              p1.getNode( "D" ) );
5968             if ( !abcd.getName().equals( "abcd" ) ) {
5969                 return false;
5970             }
5971             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5972                                                                                               p1.getNode( "A" ) );
5973             if ( !abcd2.getName().equals( "abcd" ) ) {
5974                 return false;
5975             }
5976             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5977                                                                                                p1.getNode( "F" ) );
5978             if ( !abcdef.getName().equals( "abcdef" ) ) {
5979                 return false;
5980             }
5981             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5982                                                                                                 p1.getNode( "A" ) );
5983             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5984                 return false;
5985             }
5986             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5987                                                                                                 p1.getNode( "F" ) );
5988             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5989                 return false;
5990             }
5991             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5992                                                                                                 p1.getNode( "ab" ) );
5993             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5994                 return false;
5995             }
5996             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5997                                                                                               p1.getNode( "E" ) );
5998             if ( !abcde.getName().equals( "abcde" ) ) {
5999                 return false;
6000             }
6001             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6002                                                                                                p1.getNode( "A" ) );
6003             if ( !abcde2.getName().equals( "abcde" ) ) {
6004                 return false;
6005             }
6006             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
6007                                                                                           p1.getNode( "abcdefgh" ) );
6008             if ( !r.getName().equals( "abcdefgh" ) ) {
6009                 return false;
6010             }
6011             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6012                                                                                            p1.getNode( "H" ) );
6013             if ( !r2.getName().equals( "abcdefgh" ) ) {
6014                 return false;
6015             }
6016             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
6017                                                                                            p1.getNode( "A" ) );
6018             if ( !r3.getName().equals( "abcdefgh" ) ) {
6019                 return false;
6020             }
6021             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6022                                                                                                p1.getNode( "abcde" ) );
6023             if ( !abcde3.getName().equals( "abcde" ) ) {
6024                 return false;
6025             }
6026             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
6027                                                                                                p1.getNode( "E" ) );
6028             if ( !abcde4.getName().equals( "abcde" ) ) {
6029                 return false;
6030             }
6031             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
6032                                                                                             p1.getNode( "B" ) );
6033             if ( !ab3.getName().equals( "ab" ) ) {
6034                 return false;
6035             }
6036             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
6037                                                                                             p1.getNode( "ab" ) );
6038             if ( !ab4.getName().equals( "ab" ) ) {
6039                 return false;
6040             }
6041             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
6042             PhylogenyMethods.preOrderReId( p2 );
6043             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6044                                                                                            p2.getNode( "d" ) );
6045             if ( !cd.getName().equals( "cd" ) ) {
6046                 return false;
6047             }
6048             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6049                                                                                             p2.getNode( "c" ) );
6050             if ( !cd2.getName().equals( "cd" ) ) {
6051                 return false;
6052             }
6053             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6054                                                                                             p2.getNode( "e" ) );
6055             if ( !cde.getName().equals( "cde" ) ) {
6056                 return false;
6057             }
6058             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
6059                                                                                              p2.getNode( "c" ) );
6060             if ( !cde2.getName().equals( "cde" ) ) {
6061                 return false;
6062             }
6063             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6064                                                                                              p2.getNode( "f" ) );
6065             if ( !cdef.getName().equals( "cdef" ) ) {
6066                 return false;
6067             }
6068             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6069                                                                                               p2.getNode( "f" ) );
6070             if ( !cdef2.getName().equals( "cdef" ) ) {
6071                 return false;
6072             }
6073             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
6074                                                                                               p2.getNode( "d" ) );
6075             if ( !cdef3.getName().equals( "cdef" ) ) {
6076                 return false;
6077             }
6078             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6079                                                                                            p2.getNode( "a" ) );
6080             if ( !rt.getName().equals( "r" ) ) {
6081                 return false;
6082             }
6083             final Phylogeny p3 = factory
6084                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
6085                              new NHXParser() )[ 0 ];
6086             PhylogenyMethods.preOrderReId( p3 );
6087             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
6088                                                                                              p3.getNode( "c" ) );
6089             if ( !bc_3.getName().equals( "bc" ) ) {
6090                 return false;
6091             }
6092             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6093                                                                                              p3.getNode( "c" ) );
6094             if ( !ac_3.getName().equals( "abc" ) ) {
6095                 return false;
6096             }
6097             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6098                                                                                              p3.getNode( "d" ) );
6099             if ( !ad_3.getName().equals( "abcde" ) ) {
6100                 return false;
6101             }
6102             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6103                                                                                              p3.getNode( "f" ) );
6104             if ( !af_3.getName().equals( "abcdef" ) ) {
6105                 return false;
6106             }
6107             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6108                                                                                              p3.getNode( "g" ) );
6109             if ( !ag_3.getName().equals( "" ) ) {
6110                 return false;
6111             }
6112             if ( !ag_3.isRoot() ) {
6113                 return false;
6114             }
6115             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6116                                                                                              p3.getNode( "l" ) );
6117             if ( !al_3.getName().equals( "" ) ) {
6118                 return false;
6119             }
6120             if ( !al_3.isRoot() ) {
6121                 return false;
6122             }
6123             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
6124                                                                                              p3.getNode( "l" ) );
6125             if ( !kl_3.getName().equals( "" ) ) {
6126                 return false;
6127             }
6128             if ( !kl_3.isRoot() ) {
6129                 return false;
6130             }
6131             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
6132                                                                                              p3.getNode( "l" ) );
6133             if ( !fl_3.getName().equals( "" ) ) {
6134                 return false;
6135             }
6136             if ( !fl_3.isRoot() ) {
6137                 return false;
6138             }
6139             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
6140                                                                                              p3.getNode( "k" ) );
6141             if ( !gk_3.getName().equals( "ghijk" ) ) {
6142                 return false;
6143             }
6144             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
6145             PhylogenyMethods.preOrderReId( p4 );
6146             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
6147                                                                                             p4.getNode( "c" ) );
6148             if ( !r_4.getName().equals( "r" ) ) {
6149                 return false;
6150             }
6151             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
6152             PhylogenyMethods.preOrderReId( p5 );
6153             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
6154                                                                                             p5.getNode( "c" ) );
6155             if ( !r_5.getName().equals( "root" ) ) {
6156                 return false;
6157             }
6158             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
6159             PhylogenyMethods.preOrderReId( p6 );
6160             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
6161                                                                                             p6.getNode( "a" ) );
6162             if ( !r_6.getName().equals( "rot" ) ) {
6163                 return false;
6164             }
6165             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
6166             PhylogenyMethods.preOrderReId( p7 );
6167             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
6168                                                                                             p7.getNode( "e" ) );
6169             if ( !r_7.getName().equals( "rott" ) ) {
6170                 return false;
6171             }
6172             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6173                                                                                              p7.getNode( "a" ) );
6174             if ( !r_71.getName().equals( "rott" ) ) {
6175                 return false;
6176             }
6177             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6178                                                                                              p7.getNode( "rott" ) );
6179             if ( !r_72.getName().equals( "rott" ) ) {
6180                 return false;
6181             }
6182             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6183                                                                                              p7.getNode( "a" ) );
6184             if ( !r_73.getName().equals( "rott" ) ) {
6185                 return false;
6186             }
6187             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6188                                                                                              p7.getNode( "rott" ) );
6189             if ( !r_74.getName().equals( "rott" ) ) {
6190                 return false;
6191             }
6192             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6193                                                                                              p7.getNode( "e" ) );
6194             if ( !r_75.getName().equals( "e" ) ) {
6195                 return false;
6196             }
6197         }
6198         catch ( final Exception e ) {
6199             e.printStackTrace( System.out );
6200             return false;
6201         }
6202         return true;
6203     }
6204
6205     private static boolean testHmmscanOutputParser() {
6206         final String test_dir = Test.PATH_TO_TEST_DATA;
6207         try {
6208             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
6209                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
6210             parser1.parse();
6211             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
6212                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
6213             final List<Protein> proteins = parser2.parse();
6214             if ( parser2.getProteinsEncountered() != 4 ) {
6215                 return false;
6216             }
6217             if ( proteins.size() != 4 ) {
6218                 return false;
6219             }
6220             if ( parser2.getDomainsEncountered() != 69 ) {
6221                 return false;
6222             }
6223             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
6224                 return false;
6225             }
6226             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
6227                 return false;
6228             }
6229             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
6230                 return false;
6231             }
6232             final Protein p1 = proteins.get( 0 );
6233             if ( p1.getNumberOfProteinDomains() != 15 ) {
6234                 return false;
6235             }
6236             if ( p1.getLength() != 850 ) {
6237                 return false;
6238             }
6239             final Protein p2 = proteins.get( 1 );
6240             if ( p2.getNumberOfProteinDomains() != 51 ) {
6241                 return false;
6242             }
6243             if ( p2.getLength() != 1291 ) {
6244                 return false;
6245             }
6246             final Protein p3 = proteins.get( 2 );
6247             if ( p3.getNumberOfProteinDomains() != 2 ) {
6248                 return false;
6249             }
6250             final Protein p4 = proteins.get( 3 );
6251             if ( p4.getNumberOfProteinDomains() != 1 ) {
6252                 return false;
6253             }
6254             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
6255                 return false;
6256             }
6257             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
6258                 return false;
6259             }
6260             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
6261                 return false;
6262             }
6263             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
6264                 return false;
6265             }
6266             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
6267                 return false;
6268             }
6269             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
6270                 return false;
6271             }
6272             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
6273                 return false;
6274             }
6275         }
6276         catch ( final Exception e ) {
6277             e.printStackTrace( System.out );
6278             return false;
6279         }
6280         return true;
6281     }
6282
6283     private static boolean testLastExternalNodeMethods() {
6284         try {
6285             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6286             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
6287             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
6288             final PhylogenyNode n1 = t0.getNode( "A" );
6289             if ( n1.isLastExternalNode() ) {
6290                 return false;
6291             }
6292             final PhylogenyNode n2 = t0.getNode( "B" );
6293             if ( n2.isLastExternalNode() ) {
6294                 return false;
6295             }
6296             final PhylogenyNode n3 = t0.getNode( "C" );
6297             if ( n3.isLastExternalNode() ) {
6298                 return false;
6299             }
6300             final PhylogenyNode n4 = t0.getNode( "D" );
6301             if ( !n4.isLastExternalNode() ) {
6302                 return false;
6303             }
6304         }
6305         catch ( final Exception e ) {
6306             e.printStackTrace( System.out );
6307             return false;
6308         }
6309         return true;
6310     }
6311
6312     private static boolean testLevelOrderIterator() {
6313         try {
6314             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6315             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
6316             PhylogenyNodeIterator it0;
6317             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
6318                 it0.next();
6319             }
6320             for( it0.reset(); it0.hasNext(); ) {
6321                 it0.next();
6322             }
6323             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
6324             if ( !it.next().getName().equals( "r" ) ) {
6325                 return false;
6326             }
6327             if ( !it.next().getName().equals( "ab" ) ) {
6328                 return false;
6329             }
6330             if ( !it.next().getName().equals( "cd" ) ) {
6331                 return false;
6332             }
6333             if ( !it.next().getName().equals( "A" ) ) {
6334                 return false;
6335             }
6336             if ( !it.next().getName().equals( "B" ) ) {
6337                 return false;
6338             }
6339             if ( !it.next().getName().equals( "C" ) ) {
6340                 return false;
6341             }
6342             if ( !it.next().getName().equals( "D" ) ) {
6343                 return false;
6344             }
6345             if ( it.hasNext() ) {
6346                 return false;
6347             }
6348             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",
6349                                                  new NHXParser() )[ 0 ];
6350             PhylogenyNodeIterator it2;
6351             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
6352                 it2.next();
6353             }
6354             for( it2.reset(); it2.hasNext(); ) {
6355                 it2.next();
6356             }
6357             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
6358             if ( !it3.next().getName().equals( "r" ) ) {
6359                 return false;
6360             }
6361             if ( !it3.next().getName().equals( "abc" ) ) {
6362                 return false;
6363             }
6364             if ( !it3.next().getName().equals( "defg" ) ) {
6365                 return false;
6366             }
6367             if ( !it3.next().getName().equals( "A" ) ) {
6368                 return false;
6369             }
6370             if ( !it3.next().getName().equals( "B" ) ) {
6371                 return false;
6372             }
6373             if ( !it3.next().getName().equals( "C" ) ) {
6374                 return false;
6375             }
6376             if ( !it3.next().getName().equals( "D" ) ) {
6377                 return false;
6378             }
6379             if ( !it3.next().getName().equals( "E" ) ) {
6380                 return false;
6381             }
6382             if ( !it3.next().getName().equals( "F" ) ) {
6383                 return false;
6384             }
6385             if ( !it3.next().getName().equals( "G" ) ) {
6386                 return false;
6387             }
6388             if ( !it3.next().getName().equals( "1" ) ) {
6389                 return false;
6390             }
6391             if ( !it3.next().getName().equals( "2" ) ) {
6392                 return false;
6393             }
6394             if ( !it3.next().getName().equals( "3" ) ) {
6395                 return false;
6396             }
6397             if ( !it3.next().getName().equals( "4" ) ) {
6398                 return false;
6399             }
6400             if ( !it3.next().getName().equals( "5" ) ) {
6401                 return false;
6402             }
6403             if ( !it3.next().getName().equals( "6" ) ) {
6404                 return false;
6405             }
6406             if ( !it3.next().getName().equals( "f1" ) ) {
6407                 return false;
6408             }
6409             if ( !it3.next().getName().equals( "f2" ) ) {
6410                 return false;
6411             }
6412             if ( !it3.next().getName().equals( "f3" ) ) {
6413                 return false;
6414             }
6415             if ( !it3.next().getName().equals( "a" ) ) {
6416                 return false;
6417             }
6418             if ( !it3.next().getName().equals( "b" ) ) {
6419                 return false;
6420             }
6421             if ( !it3.next().getName().equals( "f21" ) ) {
6422                 return false;
6423             }
6424             if ( !it3.next().getName().equals( "X" ) ) {
6425                 return false;
6426             }
6427             if ( !it3.next().getName().equals( "Y" ) ) {
6428                 return false;
6429             }
6430             if ( !it3.next().getName().equals( "Z" ) ) {
6431                 return false;
6432             }
6433             if ( it3.hasNext() ) {
6434                 return false;
6435             }
6436             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6437             PhylogenyNodeIterator it4;
6438             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6439                 it4.next();
6440             }
6441             for( it4.reset(); it4.hasNext(); ) {
6442                 it4.next();
6443             }
6444             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6445             if ( !it5.next().getName().equals( "r" ) ) {
6446                 return false;
6447             }
6448             if ( !it5.next().getName().equals( "A" ) ) {
6449                 return false;
6450             }
6451             if ( !it5.next().getName().equals( "B" ) ) {
6452                 return false;
6453             }
6454             if ( !it5.next().getName().equals( "C" ) ) {
6455                 return false;
6456             }
6457             if ( !it5.next().getName().equals( "D" ) ) {
6458                 return false;
6459             }
6460             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6461             PhylogenyNodeIterator it6;
6462             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6463                 it6.next();
6464             }
6465             for( it6.reset(); it6.hasNext(); ) {
6466                 it6.next();
6467             }
6468             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6469             if ( !it7.next().getName().equals( "A" ) ) {
6470                 return false;
6471             }
6472             if ( it.hasNext() ) {
6473                 return false;
6474             }
6475         }
6476         catch ( final Exception e ) {
6477             e.printStackTrace( System.out );
6478             return false;
6479         }
6480         return true;
6481     }
6482
6483     private static boolean testMafft( final String path ) {
6484         try {
6485             final List<String> opts = new ArrayList<String>();
6486             opts.add( "--maxiterate" );
6487             opts.add( "1000" );
6488             opts.add( "--localpair" );
6489             opts.add( "--quiet" );
6490             Msa msa = null;
6491             final MsaInferrer mafft = Mafft.createInstance( path );
6492             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6493             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6494                 return false;
6495             }
6496             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6497                 return false;
6498             }
6499         }
6500         catch ( final Exception e ) {
6501             e.printStackTrace( System.out );
6502             return false;
6503         }
6504         return true;
6505     }
6506
6507     private static boolean testMidpointrooting() {
6508         try {
6509             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6510             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6511             PhylogenyMethods.midpointRoot( t0 );
6512             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6513                 return false;
6514             }
6515             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6516                 return false;
6517             }
6518             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6519                            1 ) ) {
6520                 return false;
6521             }
6522             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",
6523                                                  new NHXParser() )[ 0 ];
6524             if ( !t1.isRooted() ) {
6525                 return false;
6526             }
6527             PhylogenyMethods.midpointRoot( t1 );
6528             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6529                 return false;
6530             }
6531             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6532                 return false;
6533             }
6534             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6535                 return false;
6536             }
6537             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6538                 return false;
6539             }
6540             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6541                 return false;
6542             }
6543             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6544                 return false;
6545             }
6546             t1.reRoot( t1.getNode( "A" ) );
6547             PhylogenyMethods.midpointRoot( t1 );
6548             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6549                 return false;
6550             }
6551             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6552                 return false;
6553             }
6554             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6555                 return false;
6556             }
6557             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6558                 return false;
6559             }
6560             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6561                 System.exit( -1 );
6562                 return false;
6563             }
6564             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6565                 return false;
6566             }
6567         }
6568         catch ( final Exception e ) {
6569             e.printStackTrace( System.out );
6570             return false;
6571         }
6572         return true;
6573     }
6574
6575     private static boolean testMsaQualityMethod() {
6576         try {
6577             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6578             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6579             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6580             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6581             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6582             l.add( s0 );
6583             l.add( s1 );
6584             l.add( s2 );
6585             l.add( s3 );
6586             final Msa msa = BasicMsa.createInstance( l );
6587             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6588                 return false;
6589             }
6590             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6591                 return false;
6592             }
6593             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6594                 return false;
6595             }
6596             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6597                 return false;
6598             }
6599             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6600                 return false;
6601             }
6602             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6603                 return false;
6604             }
6605             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6606                 return false;
6607             }
6608         }
6609         catch ( final Exception e ) {
6610             e.printStackTrace( System.out );
6611             return false;
6612         }
6613         return true;
6614     }
6615
6616     private static boolean testMsaEntropy() {
6617         try {
6618             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6619             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6620             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6621             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6622             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6623             l.add( s0 );
6624             l.add( s1 );
6625             l.add( s2 );
6626             l.add( s3 );
6627             final Msa msa = BasicMsa.createInstance( l );
6628             //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6629             //FIXME
6630             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6631             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6632             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6633             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6634             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6635             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6636             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6637             //            System.out.println();
6638             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6639             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6640             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6641             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6642             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6643             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6644             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6645             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6646             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6647             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6648             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6649             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6650             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6651             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6652             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6653             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6654             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6655             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6656             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6657             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6658             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6659             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6660             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6661             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6662             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6663             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6664             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6665             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6666             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6667             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6668             final Msa msa2 = BasicMsa.createInstance( l2 );
6669             //            System.out.println();
6670             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6671             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6672             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6673         }
6674         catch ( final Exception e ) {
6675             e.printStackTrace( System.out );
6676             return false;
6677         }
6678         return true;
6679     }
6680
6681     private static boolean testDeleteableMsa() {
6682         try {
6683             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6684             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6685             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6686             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6687             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6688             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6689             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6690             l0.add( s0 );
6691             l0.add( s1 );
6692             l0.add( s2 );
6693             l0.add( s3 );
6694             l0.add( s4 );
6695             l0.add( s5 );
6696             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6697             dmsa0.deleteRow( "b", false );
6698             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6699                 return false;
6700             }
6701             dmsa0.deleteRow( "e", false );
6702             dmsa0.deleteRow( "a", false );
6703             dmsa0.deleteRow( "f", false );
6704             if ( dmsa0.getLength() != 4 ) {
6705                 return false;
6706             }
6707             if ( dmsa0.getNumberOfSequences() != 2 ) {
6708                 return false;
6709             }
6710             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6711                 return false;
6712             }
6713             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6714                 return false;
6715             }
6716             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6717                 return false;
6718             }
6719             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6720                 return false;
6721             }
6722             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6723                 return false;
6724             }
6725             dmsa0.deleteRow( "c", false );
6726             dmsa0.deleteRow( "d", false );
6727             if ( dmsa0.getNumberOfSequences() != 0 ) {
6728                 return false;
6729             }
6730             //
6731             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6732             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6733             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6734             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6735             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6736             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6737             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6738             l1.add( s_0 );
6739             l1.add( s_1 );
6740             l1.add( s_2 );
6741             l1.add( s_3 );
6742             l1.add( s_4 );
6743             l1.add( s_5 );
6744             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6745             dmsa1.deleteGapOnlyColumns();
6746             dmsa1.deleteRow( "a", false );
6747             dmsa1.deleteRow( "f", false );
6748             dmsa1.deleteRow( "d", false );
6749             dmsa1.deleteGapOnlyColumns();
6750             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6751                 return false;
6752             }
6753             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6754                 return false;
6755             }
6756             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6757                 return false;
6758             }
6759             dmsa1.deleteRow( "c", false );
6760             dmsa1.deleteGapOnlyColumns();
6761             final Writer w0 = new StringWriter();
6762             dmsa1.write( w0, MSA_FORMAT.FASTA );
6763             final Writer w1 = new StringWriter();
6764             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6765             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6766                 return false;
6767             }
6768             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6769                 return false;
6770             }
6771             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6772             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6773             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6774             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6775             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6776             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6777             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6778             l2.add( s__0 );
6779             l2.add( s__1 );
6780             l2.add( s__2 );
6781             l2.add( s__3 );
6782             l2.add( s__4 );
6783             l2.add( s__5 );
6784             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6785             dmsa2.deleteGapColumns( 0.5 );
6786             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6787                 return false;
6788             }
6789             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6790                 return false;
6791             }
6792             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6793                 return false;
6794             }
6795             dmsa2.deleteGapColumns( 0.2 );
6796             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6797                 return false;
6798             }
6799             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6800                 return false;
6801             }
6802             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6803                 return false;
6804             }
6805             dmsa2.deleteGapColumns( 0 );
6806             dmsa2.deleteRow( "a", false );
6807             dmsa2.deleteRow( "b", false );
6808             dmsa2.deleteRow( "f", false );
6809             dmsa2.deleteRow( "e", false );
6810             dmsa2.setIdentifier( 0, "new_c" );
6811             dmsa2.setIdentifier( 1, "new_d" );
6812             dmsa2.setResidueAt( 0, 0, 'x' );
6813             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6814             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6815                 return false;
6816             }
6817             final Writer w = new StringWriter();
6818             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6819             final String phylip = w.toString();
6820             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6821                 System.out.println( phylip );
6822                 return false;
6823             }
6824             final Writer w2 = new StringWriter();
6825             dmsa2.write( w2, MSA_FORMAT.FASTA );
6826             final String fasta = w2.toString();
6827             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6828                 System.out.println( fasta );
6829                 return false;
6830             }
6831         }
6832         catch ( final Exception e ) {
6833             e.printStackTrace( System.out );
6834             return false;
6835         }
6836         return true;
6837     }
6838
6839     private static boolean testNextNodeWithCollapsing() {
6840         try {
6841             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6842             PhylogenyNode n;
6843             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6844             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6845             final Phylogeny t0 = factory.create( sb0.toString(), new NHXParser() )[ 0 ];
6846             t0.getNode( "cd" ).setCollapse( true );
6847             t0.getNode( "cde" ).setCollapse( true );
6848             n = t0.getFirstExternalNode();
6849             while ( n != null ) {
6850                 ext.add( n );
6851                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6852             }
6853             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6854                 return false;
6855             }
6856             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6857                 return false;
6858             }
6859             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6860                 return false;
6861             }
6862             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6863                 return false;
6864             }
6865             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6866                 return false;
6867             }
6868             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6869                 return false;
6870             }
6871             ext.clear();
6872             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6873             final Phylogeny t1 = factory.create( sb1.toString(), new NHXParser() )[ 0 ];
6874             t1.getNode( "ab" ).setCollapse( true );
6875             t1.getNode( "cd" ).setCollapse( true );
6876             t1.getNode( "cde" ).setCollapse( true );
6877             n = t1.getNode( "ab" );
6878             ext = new ArrayList<PhylogenyNode>();
6879             while ( n != null ) {
6880                 ext.add( n );
6881                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6882             }
6883             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6884                 return false;
6885             }
6886             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6887                 return false;
6888             }
6889             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6890                 return false;
6891             }
6892             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6893                 return false;
6894             }
6895             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6896                 return false;
6897             }
6898             ext.clear();
6899             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6900             final Phylogeny t2 = factory.create( sb2.toString(), new NHXParser() )[ 0 ];
6901             t2.getNode( "ab" ).setCollapse( true );
6902             t2.getNode( "cd" ).setCollapse( true );
6903             t2.getNode( "cde" ).setCollapse( true );
6904             t2.getNode( "c" ).setCollapse( true );
6905             t2.getNode( "d" ).setCollapse( true );
6906             t2.getNode( "e" ).setCollapse( true );
6907             t2.getNode( "gh" ).setCollapse( true );
6908             n = t2.getNode( "ab" );
6909             ext = new ArrayList<PhylogenyNode>();
6910             while ( n != null ) {
6911                 ext.add( n );
6912                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6913             }
6914             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6915                 return false;
6916             }
6917             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6918                 return false;
6919             }
6920             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6921                 return false;
6922             }
6923             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6924                 return false;
6925             }
6926             ext.clear();
6927             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6928             final Phylogeny t3 = factory.create( sb3.toString(), new NHXParser() )[ 0 ];
6929             t3.getNode( "ab" ).setCollapse( true );
6930             t3.getNode( "cd" ).setCollapse( true );
6931             t3.getNode( "cde" ).setCollapse( true );
6932             t3.getNode( "c" ).setCollapse( true );
6933             t3.getNode( "d" ).setCollapse( true );
6934             t3.getNode( "e" ).setCollapse( true );
6935             t3.getNode( "gh" ).setCollapse( true );
6936             t3.getNode( "fgh" ).setCollapse( true );
6937             n = t3.getNode( "ab" );
6938             ext = new ArrayList<PhylogenyNode>();
6939             while ( n != null ) {
6940                 ext.add( n );
6941                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6942             }
6943             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6944                 return false;
6945             }
6946             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6947                 return false;
6948             }
6949             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6950                 return false;
6951             }
6952             ext.clear();
6953             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6954             final Phylogeny t4 = factory.create( sb4.toString(), new NHXParser() )[ 0 ];
6955             t4.getNode( "ab" ).setCollapse( true );
6956             t4.getNode( "cd" ).setCollapse( true );
6957             t4.getNode( "cde" ).setCollapse( true );
6958             t4.getNode( "c" ).setCollapse( true );
6959             t4.getNode( "d" ).setCollapse( true );
6960             t4.getNode( "e" ).setCollapse( true );
6961             t4.getNode( "gh" ).setCollapse( true );
6962             t4.getNode( "fgh" ).setCollapse( true );
6963             t4.getNode( "abcdefgh" ).setCollapse( true );
6964             n = t4.getNode( "abcdefgh" );
6965             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6966                 return false;
6967             }
6968             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6969             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
6970             ext.clear();
6971             n = t5.getFirstExternalNode();
6972             while ( n != null ) {
6973                 ext.add( n );
6974                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6975             }
6976             if ( ext.size() != 8 ) {
6977                 return false;
6978             }
6979             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6980                 return false;
6981             }
6982             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6983                 return false;
6984             }
6985             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6986                 return false;
6987             }
6988             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6989                 return false;
6990             }
6991             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6992                 return false;
6993             }
6994             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6995                 return false;
6996             }
6997             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6998                 return false;
6999             }
7000             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
7001                 return false;
7002             }
7003             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7004             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
7005             ext.clear();
7006             t6.getNode( "ab" ).setCollapse( true );
7007             n = t6.getNode( "ab" );
7008             while ( n != null ) {
7009                 ext.add( n );
7010                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7011             }
7012             if ( ext.size() != 7 ) {
7013                 return false;
7014             }
7015             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7016                 return false;
7017             }
7018             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7019                 return false;
7020             }
7021             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7022                 return false;
7023             }
7024             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7025                 return false;
7026             }
7027             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7028                 return false;
7029             }
7030             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7031                 return false;
7032             }
7033             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7034                 return false;
7035             }
7036             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7037             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
7038             ext.clear();
7039             t7.getNode( "cd" ).setCollapse( true );
7040             n = t7.getNode( "a" );
7041             while ( n != null ) {
7042                 ext.add( n );
7043                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7044             }
7045             if ( ext.size() != 7 ) {
7046                 return false;
7047             }
7048             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7049                 return false;
7050             }
7051             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7052                 return false;
7053             }
7054             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7055                 return false;
7056             }
7057             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7058                 return false;
7059             }
7060             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7061                 return false;
7062             }
7063             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7064                 return false;
7065             }
7066             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7067                 return false;
7068             }
7069             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7070             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
7071             ext.clear();
7072             t8.getNode( "cd" ).setCollapse( true );
7073             t8.getNode( "c" ).setCollapse( true );
7074             t8.getNode( "d" ).setCollapse( true );
7075             n = t8.getNode( "a" );
7076             while ( n != null ) {
7077                 ext.add( n );
7078                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7079             }
7080             if ( ext.size() != 7 ) {
7081                 return false;
7082             }
7083             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7084                 return false;
7085             }
7086             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7087                 return false;
7088             }
7089             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7090                 System.out.println( "2 fail" );
7091                 return false;
7092             }
7093             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7094                 return false;
7095             }
7096             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7097                 return false;
7098             }
7099             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7100                 return false;
7101             }
7102             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7103                 return false;
7104             }
7105             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7106             final Phylogeny t9 = factory.create( sb9.toString(), new NHXParser() )[ 0 ];
7107             ext.clear();
7108             t9.getNode( "gh" ).setCollapse( true );
7109             n = t9.getNode( "a" );
7110             while ( n != null ) {
7111                 ext.add( n );
7112                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7113             }
7114             if ( ext.size() != 7 ) {
7115                 return false;
7116             }
7117             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7118                 return false;
7119             }
7120             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7121                 return false;
7122             }
7123             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7124                 return false;
7125             }
7126             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7127                 return false;
7128             }
7129             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7130                 return false;
7131             }
7132             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7133                 return false;
7134             }
7135             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7136                 return false;
7137             }
7138             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7139             final Phylogeny t10 = factory.create( sb10.toString(), new NHXParser() )[ 0 ];
7140             ext.clear();
7141             t10.getNode( "gh" ).setCollapse( true );
7142             t10.getNode( "g" ).setCollapse( true );
7143             t10.getNode( "h" ).setCollapse( true );
7144             n = t10.getNode( "a" );
7145             while ( n != null ) {
7146                 ext.add( n );
7147                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7148             }
7149             if ( ext.size() != 7 ) {
7150                 return false;
7151             }
7152             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7153                 return false;
7154             }
7155             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7156                 return false;
7157             }
7158             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7159                 return false;
7160             }
7161             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7162                 return false;
7163             }
7164             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7165                 return false;
7166             }
7167             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7168                 return false;
7169             }
7170             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7171                 return false;
7172             }
7173             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7174             final Phylogeny t11 = factory.create( sb11.toString(), new NHXParser() )[ 0 ];
7175             ext.clear();
7176             t11.getNode( "gh" ).setCollapse( true );
7177             t11.getNode( "fgh" ).setCollapse( true );
7178             n = t11.getNode( "a" );
7179             while ( n != null ) {
7180                 ext.add( n );
7181                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7182             }
7183             if ( ext.size() != 6 ) {
7184                 return false;
7185             }
7186             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7187                 return false;
7188             }
7189             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7190                 return false;
7191             }
7192             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7193                 return false;
7194             }
7195             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7196                 return false;
7197             }
7198             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7199                 return false;
7200             }
7201             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7202                 return false;
7203             }
7204             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7205             final Phylogeny t12 = factory.create( sb12.toString(), new NHXParser() )[ 0 ];
7206             ext.clear();
7207             t12.getNode( "gh" ).setCollapse( true );
7208             t12.getNode( "fgh" ).setCollapse( true );
7209             t12.getNode( "g" ).setCollapse( true );
7210             t12.getNode( "h" ).setCollapse( true );
7211             t12.getNode( "f" ).setCollapse( true );
7212             n = t12.getNode( "a" );
7213             while ( n != null ) {
7214                 ext.add( n );
7215                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7216             }
7217             if ( ext.size() != 6 ) {
7218                 return false;
7219             }
7220             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7221                 return false;
7222             }
7223             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7224                 return false;
7225             }
7226             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7227                 return false;
7228             }
7229             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7230                 return false;
7231             }
7232             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7233                 return false;
7234             }
7235             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7236                 return false;
7237             }
7238             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7239             final Phylogeny t13 = factory.create( sb13.toString(), new NHXParser() )[ 0 ];
7240             ext.clear();
7241             t13.getNode( "ab" ).setCollapse( true );
7242             t13.getNode( "b" ).setCollapse( true );
7243             t13.getNode( "fgh" ).setCollapse( true );
7244             t13.getNode( "gh" ).setCollapse( true );
7245             n = t13.getNode( "ab" );
7246             while ( n != null ) {
7247                 ext.add( n );
7248                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7249             }
7250             if ( ext.size() != 5 ) {
7251                 return false;
7252             }
7253             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7254                 return false;
7255             }
7256             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7257                 return false;
7258             }
7259             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7260                 return false;
7261             }
7262             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7263                 return false;
7264             }
7265             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7266                 return false;
7267             }
7268             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
7269             final Phylogeny t14 = factory.create( sb14.toString(), new NHXParser() )[ 0 ];
7270             ext.clear();
7271             t14.getNode( "ab" ).setCollapse( true );
7272             t14.getNode( "a" ).setCollapse( true );
7273             t14.getNode( "fgh" ).setCollapse( true );
7274             t14.getNode( "gh" ).setCollapse( true );
7275             n = t14.getNode( "ab" );
7276             while ( n != null ) {
7277                 ext.add( n );
7278                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7279             }
7280             if ( ext.size() != 5 ) {
7281                 return false;
7282             }
7283             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7284                 return false;
7285             }
7286             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7287                 return false;
7288             }
7289             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7290                 return false;
7291             }
7292             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7293                 return false;
7294             }
7295             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7296                 return false;
7297             }
7298             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" );
7299             final Phylogeny t15 = factory.create( sb15.toString(), new NHXParser() )[ 0 ];
7300             ext.clear();
7301             t15.getNode( "ab" ).setCollapse( true );
7302             t15.getNode( "a" ).setCollapse( true );
7303             t15.getNode( "fgh" ).setCollapse( true );
7304             t15.getNode( "gh" ).setCollapse( true );
7305             n = t15.getNode( "ab" );
7306             while ( n != null ) {
7307                 ext.add( n );
7308                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7309             }
7310             if ( ext.size() != 6 ) {
7311                 return false;
7312             }
7313             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7314                 return false;
7315             }
7316             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7317                 return false;
7318             }
7319             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7320                 return false;
7321             }
7322             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7323                 return false;
7324             }
7325             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
7326                 return false;
7327             }
7328             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7329                 return false;
7330             }
7331             //
7332             //
7333             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" );
7334             final Phylogeny t16 = factory.create( sb16.toString(), new NHXParser() )[ 0 ];
7335             ext.clear();
7336             t16.getNode( "ab" ).setCollapse( true );
7337             t16.getNode( "a" ).setCollapse( true );
7338             t16.getNode( "fgh" ).setCollapse( true );
7339             t16.getNode( "gh" ).setCollapse( true );
7340             t16.getNode( "cd" ).setCollapse( true );
7341             t16.getNode( "cde" ).setCollapse( true );
7342             t16.getNode( "d" ).setCollapse( true );
7343             t16.getNode( "x" ).setCollapse( true );
7344             n = t16.getNode( "ab" );
7345             while ( n != null ) {
7346                 ext.add( n );
7347                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7348             }
7349             if ( ext.size() != 4 ) {
7350                 return false;
7351             }
7352             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7353                 return false;
7354             }
7355             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7356                 return false;
7357             }
7358             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
7359                 return false;
7360             }
7361             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
7362                 return false;
7363             }
7364         }
7365         catch ( final Exception e ) {
7366             e.printStackTrace( System.out );
7367             return false;
7368         }
7369         return true;
7370     }
7371
7372     private static boolean testNexusCharactersParsing() {
7373         try {
7374             final NexusCharactersParser parser = new NexusCharactersParser();
7375             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
7376             parser.parse();
7377             String[] labels = parser.getCharStateLabels();
7378             if ( labels.length != 7 ) {
7379                 return false;
7380             }
7381             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7382                 return false;
7383             }
7384             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7385                 return false;
7386             }
7387             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7388                 return false;
7389             }
7390             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7391                 return false;
7392             }
7393             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7394                 return false;
7395             }
7396             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7397                 return false;
7398             }
7399             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7400                 return false;
7401             }
7402             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7403             parser.parse();
7404             labels = parser.getCharStateLabels();
7405             if ( labels.length != 7 ) {
7406                 return false;
7407             }
7408             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7409                 return false;
7410             }
7411             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7412                 return false;
7413             }
7414             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7415                 return false;
7416             }
7417             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7418                 return false;
7419             }
7420             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7421                 return false;
7422             }
7423             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7424                 return false;
7425             }
7426             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7427                 return false;
7428             }
7429         }
7430         catch ( final Exception e ) {
7431             e.printStackTrace( System.out );
7432             return false;
7433         }
7434         return true;
7435     }
7436
7437     private static boolean testNexusMatrixParsing() {
7438         try {
7439             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7440             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7441             parser.parse();
7442             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7443             if ( m.getNumberOfCharacters() != 9 ) {
7444                 return false;
7445             }
7446             if ( m.getNumberOfIdentifiers() != 5 ) {
7447                 return false;
7448             }
7449             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7450                 return false;
7451             }
7452             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7453                 return false;
7454             }
7455             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7456                 return false;
7457             }
7458             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7459                 return false;
7460             }
7461             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7462                 return false;
7463             }
7464             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7465                 return false;
7466             }
7467             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7468                 return false;
7469             }
7470             //            if ( labels.length != 7 ) {
7471             //                return false;
7472             //            }
7473             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7474             //                return false;
7475             //            }
7476             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7477             //                return false;
7478             //            }
7479             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7480             //                return false;
7481             //            }
7482             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7483             //                return false;
7484             //            }
7485             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7486             //                return false;
7487             //            }
7488             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7489             //                return false;
7490             //            }
7491             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7492             //                return false;
7493             //            }
7494             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7495             //            parser.parse();
7496             //            labels = parser.getCharStateLabels();
7497             //            if ( labels.length != 7 ) {
7498             //                return false;
7499             //            }
7500             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7501             //                return false;
7502             //            }
7503             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7504             //                return false;
7505             //            }
7506             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7507             //                return false;
7508             //            }
7509             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7510             //                return false;
7511             //            }
7512             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7513             //                return false;
7514             //            }
7515             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7516             //                return false;
7517             //            }
7518             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7519             //                return false;
7520             //            }
7521         }
7522         catch ( final Exception e ) {
7523             e.printStackTrace( System.out );
7524             return false;
7525         }
7526         return true;
7527     }
7528
7529     private static boolean testNexusTreeParsing() {
7530         try {
7531             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7532             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7533             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7534             if ( phylogenies.length != 1 ) {
7535                 return false;
7536             }
7537             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7538                 return false;
7539             }
7540             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7541                 return false;
7542             }
7543             phylogenies = null;
7544             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7545             if ( phylogenies.length != 1 ) {
7546                 return false;
7547             }
7548             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7549                 return false;
7550             }
7551             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7552                 return false;
7553             }
7554             phylogenies = null;
7555             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7556             if ( phylogenies.length != 1 ) {
7557                 return false;
7558             }
7559             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7560                 return false;
7561             }
7562             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7563                 return false;
7564             }
7565             if ( phylogenies[ 0 ].isRooted() ) {
7566                 return false;
7567             }
7568             phylogenies = null;
7569             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7570             if ( phylogenies.length != 18 ) {
7571                 return false;
7572             }
7573             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7574                 return false;
7575             }
7576             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7577                 return false;
7578             }
7579             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7580                 return false;
7581             }
7582             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7583                 return false;
7584             }
7585             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7586                 return false;
7587             }
7588             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7589                 return false;
7590             }
7591             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7592                 return false;
7593             }
7594             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7595                 return false;
7596             }
7597             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7598                 return false;
7599             }
7600             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7601                 return false;
7602             }
7603             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7604                 return false;
7605             }
7606             if ( phylogenies[ 8 ].isRooted() ) {
7607                 return false;
7608             }
7609             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7610                 return false;
7611             }
7612             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7613                 return false;
7614             }
7615             if ( !phylogenies[ 9 ].isRooted() ) {
7616                 return false;
7617             }
7618             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7619                 return false;
7620             }
7621             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7622                 return false;
7623             }
7624             if ( !phylogenies[ 10 ].isRooted() ) {
7625                 return false;
7626             }
7627             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7628                 return false;
7629             }
7630             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7631                 return false;
7632             }
7633             if ( phylogenies[ 11 ].isRooted() ) {
7634                 return false;
7635             }
7636             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7637                 return false;
7638             }
7639             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7640                 return false;
7641             }
7642             if ( !phylogenies[ 12 ].isRooted() ) {
7643                 return false;
7644             }
7645             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7646                 return false;
7647             }
7648             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7649                 return false;
7650             }
7651             if ( !phylogenies[ 13 ].isRooted() ) {
7652                 return false;
7653             }
7654             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7655                 return false;
7656             }
7657             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7658                 return false;
7659             }
7660             if ( !phylogenies[ 14 ].isRooted() ) {
7661                 return false;
7662             }
7663             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7664                 return false;
7665             }
7666             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7667                 return false;
7668             }
7669             if ( phylogenies[ 15 ].isRooted() ) {
7670                 return false;
7671             }
7672             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7673                 return false;
7674             }
7675             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7676                 return false;
7677             }
7678             if ( !phylogenies[ 16 ].isRooted() ) {
7679                 return false;
7680             }
7681             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7682                 return false;
7683             }
7684             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7685                 return false;
7686             }
7687             if ( phylogenies[ 17 ].isRooted() ) {
7688                 return false;
7689             }
7690             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7691                 return false;
7692             }
7693             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7694             phylogenies = null;
7695             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7696             if ( phylogenies.length != 9 ) {
7697                 return false;
7698             }
7699             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7700                            .getDistanceToParent() ) ) {
7701                 return false;
7702             }
7703             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7704                            .getDistanceToParent() ) ) {
7705                 return false;
7706             }
7707             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7708                 return false;
7709             }
7710             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7711                 return false;
7712             }
7713             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7714                 return false;
7715             }
7716             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7717                 return false;
7718             }
7719             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7720                 return false;
7721             }
7722         }
7723         catch ( final Exception e ) {
7724             e.printStackTrace( System.out );
7725             return false;
7726         }
7727         return true;
7728     }
7729
7730     private static boolean testNexusTreeParsingIterating() {
7731         try {
7732             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7733             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7734             if ( !p.hasNext() ) {
7735                 return false;
7736             }
7737             Phylogeny phy = p.next();
7738             if ( phy == null ) {
7739                 return false;
7740             }
7741             if ( phy.getNumberOfExternalNodes() != 25 ) {
7742                 return false;
7743             }
7744             if ( !phy.getName().equals( "" ) ) {
7745                 return false;
7746             }
7747             if ( p.hasNext() ) {
7748                 return false;
7749             }
7750             phy = p.next();
7751             if ( phy != null ) {
7752                 return false;
7753             }
7754             p.reset();
7755             if ( !p.hasNext() ) {
7756                 return false;
7757             }
7758             phy = p.next();
7759             if ( phy == null ) {
7760                 return false;
7761             }
7762             if ( phy.getNumberOfExternalNodes() != 25 ) {
7763                 return false;
7764             }
7765             if ( !phy.getName().equals( "" ) ) {
7766                 return false;
7767             }
7768             if ( p.hasNext() ) {
7769                 return false;
7770             }
7771             phy = p.next();
7772             if ( phy != null ) {
7773                 return false;
7774             }
7775             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7776             if ( !p.hasNext() ) {
7777                 return false;
7778             }
7779             phy = p.next();
7780             if ( phy == null ) {
7781                 return false;
7782             }
7783             if ( phy.getNumberOfExternalNodes() != 10 ) {
7784                 return false;
7785             }
7786             if ( !phy.getName().equals( "name" ) ) {
7787                 return false;
7788             }
7789             if ( p.hasNext() ) {
7790                 return false;
7791             }
7792             phy = p.next();
7793             if ( phy != null ) {
7794                 return false;
7795             }
7796             p.reset();
7797             if ( !p.hasNext() ) {
7798                 return false;
7799             }
7800             phy = p.next();
7801             if ( phy == null ) {
7802                 return false;
7803             }
7804             if ( phy.getNumberOfExternalNodes() != 10 ) {
7805                 return false;
7806             }
7807             if ( !phy.getName().equals( "name" ) ) {
7808                 return false;
7809             }
7810             if ( p.hasNext() ) {
7811                 return false;
7812             }
7813             phy = p.next();
7814             if ( phy != null ) {
7815                 return false;
7816             }
7817             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7818             if ( !p.hasNext() ) {
7819                 return false;
7820             }
7821             phy = p.next();
7822             if ( phy == null ) {
7823                 return false;
7824             }
7825             if ( phy.getNumberOfExternalNodes() != 3 ) {
7826                 return false;
7827             }
7828             if ( !phy.getName().equals( "" ) ) {
7829                 return false;
7830             }
7831             if ( phy.isRooted() ) {
7832                 return false;
7833             }
7834             if ( p.hasNext() ) {
7835                 return false;
7836             }
7837             phy = p.next();
7838             if ( phy != null ) {
7839                 return false;
7840             }
7841             //
7842             p.reset();
7843             if ( !p.hasNext() ) {
7844                 return false;
7845             }
7846             phy = p.next();
7847             if ( phy == null ) {
7848                 return false;
7849             }
7850             if ( phy.getNumberOfExternalNodes() != 3 ) {
7851                 return false;
7852             }
7853             if ( !phy.getName().equals( "" ) ) {
7854                 return false;
7855             }
7856             if ( p.hasNext() ) {
7857                 return false;
7858             }
7859             phy = p.next();
7860             if ( phy != null ) {
7861                 return false;
7862             }
7863             //
7864             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7865             if ( !p.hasNext() ) {
7866                 return false;
7867             }
7868             //0
7869             phy = p.next();
7870             if ( phy == null ) {
7871                 return false;
7872             }
7873             if ( phy.getNumberOfExternalNodes() != 10 ) {
7874                 return false;
7875             }
7876             if ( !phy.getName().equals( "tree 0" ) ) {
7877                 return false;
7878             }
7879             //1
7880             if ( !p.hasNext() ) {
7881                 return false;
7882             }
7883             phy = p.next();
7884             if ( phy == null ) {
7885                 return false;
7886             }
7887             if ( phy.getNumberOfExternalNodes() != 10 ) {
7888                 return false;
7889             }
7890             if ( !phy.getName().equals( "tree 1" ) ) {
7891                 return false;
7892             }
7893             //2
7894             if ( !p.hasNext() ) {
7895                 return false;
7896             }
7897             phy = p.next();
7898             if ( phy == null ) {
7899                 return false;
7900             }
7901             if ( phy.getNumberOfExternalNodes() != 3 ) {
7902                 System.out.println( phy.toString() );
7903                 return false;
7904             }
7905             if ( !phy.getName().equals( "" ) ) {
7906                 return false;
7907             }
7908             if ( phy.isRooted() ) {
7909                 return false;
7910             }
7911             //3
7912             if ( !p.hasNext() ) {
7913                 return false;
7914             }
7915             phy = p.next();
7916             if ( phy == null ) {
7917                 return false;
7918             }
7919             if ( phy.getNumberOfExternalNodes() != 4 ) {
7920                 return false;
7921             }
7922             if ( !phy.getName().equals( "" ) ) {
7923                 return false;
7924             }
7925             if ( !phy.isRooted() ) {
7926                 return false;
7927             }
7928             //4
7929             if ( !p.hasNext() ) {
7930                 return false;
7931             }
7932             phy = p.next();
7933             if ( phy == null ) {
7934                 return false;
7935             }
7936             if ( phy.getNumberOfExternalNodes() != 5 ) {
7937                 System.out.println( phy.getNumberOfExternalNodes() );
7938                 return false;
7939             }
7940             if ( !phy.getName().equals( "" ) ) {
7941                 return false;
7942             }
7943             if ( !phy.isRooted() ) {
7944                 return false;
7945             }
7946             //5
7947             if ( !p.hasNext() ) {
7948                 return false;
7949             }
7950             phy = p.next();
7951             if ( phy == null ) {
7952                 return false;
7953             }
7954             if ( phy.getNumberOfExternalNodes() != 3 ) {
7955                 return false;
7956             }
7957             if ( !phy.getName().equals( "" ) ) {
7958                 return false;
7959             }
7960             if ( phy.isRooted() ) {
7961                 return false;
7962             }
7963             //6
7964             if ( !p.hasNext() ) {
7965                 return false;
7966             }
7967             phy = p.next();
7968             if ( phy == null ) {
7969                 return false;
7970             }
7971             if ( phy.getNumberOfExternalNodes() != 2 ) {
7972                 return false;
7973             }
7974             if ( !phy.getName().equals( "" ) ) {
7975                 return false;
7976             }
7977             if ( !phy.isRooted() ) {
7978                 return false;
7979             }
7980             //7
7981             if ( !p.hasNext() ) {
7982                 return false;
7983             }
7984             phy = p.next();
7985             if ( phy.getNumberOfExternalNodes() != 3 ) {
7986                 return false;
7987             }
7988             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7989                 return false;
7990             }
7991             if ( !phy.isRooted() ) {
7992                 return false;
7993             }
7994             //8
7995             if ( !p.hasNext() ) {
7996                 return false;
7997             }
7998             phy = p.next();
7999             if ( phy.getNumberOfExternalNodes() != 3 ) {
8000                 return false;
8001             }
8002             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
8003                 return false;
8004             }
8005             if ( !phy.getName().equals( "tree 8" ) ) {
8006                 return false;
8007             }
8008             //9
8009             if ( !p.hasNext() ) {
8010                 return false;
8011             }
8012             phy = p.next();
8013             if ( phy.getNumberOfExternalNodes() != 3 ) {
8014                 return false;
8015             }
8016             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
8017                 return false;
8018             }
8019             if ( !phy.getName().equals( "tree 9" ) ) {
8020                 return false;
8021             }
8022             //10
8023             if ( !p.hasNext() ) {
8024                 return false;
8025             }
8026             phy = p.next();
8027             if ( phy.getNumberOfExternalNodes() != 3 ) {
8028                 return false;
8029             }
8030             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8031                 return false;
8032             }
8033             if ( !phy.getName().equals( "tree 10" ) ) {
8034                 return false;
8035             }
8036             if ( !phy.isRooted() ) {
8037                 return false;
8038             }
8039             //11
8040             if ( !p.hasNext() ) {
8041                 return false;
8042             }
8043             phy = p.next();
8044             if ( phy.getNumberOfExternalNodes() != 3 ) {
8045                 return false;
8046             }
8047             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
8048                 return false;
8049             }
8050             if ( !phy.getName().equals( "tree 11" ) ) {
8051                 return false;
8052             }
8053             if ( phy.isRooted() ) {
8054                 return false;
8055             }
8056             //12
8057             if ( !p.hasNext() ) {
8058                 return false;
8059             }
8060             phy = p.next();
8061             if ( phy.getNumberOfExternalNodes() != 3 ) {
8062                 return false;
8063             }
8064             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
8065                 return false;
8066             }
8067             if ( !phy.getName().equals( "tree 12" ) ) {
8068                 return false;
8069             }
8070             if ( !phy.isRooted() ) {
8071                 return false;
8072             }
8073             //13
8074             if ( !p.hasNext() ) {
8075                 return false;
8076             }
8077             phy = p.next();
8078             if ( phy.getNumberOfExternalNodes() != 3 ) {
8079                 return false;
8080             }
8081             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8082                 return false;
8083             }
8084             if ( !phy.getName().equals( "tree 13" ) ) {
8085                 return false;
8086             }
8087             if ( !phy.isRooted() ) {
8088                 return false;
8089             }
8090             //14
8091             if ( !p.hasNext() ) {
8092                 return false;
8093             }
8094             phy = p.next();
8095             if ( phy.getNumberOfExternalNodes() != 10 ) {
8096                 System.out.println( phy.getNumberOfExternalNodes() );
8097                 return false;
8098             }
8099             if ( !phy
8100                     .toNewHampshire()
8101                     .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;" ) ) {
8102                 System.out.println( phy.toNewHampshire() );
8103                 return false;
8104             }
8105             if ( !phy.getName().equals( "tree 14" ) ) {
8106                 return false;
8107             }
8108             if ( !phy.isRooted() ) {
8109                 return false;
8110             }
8111             //15
8112             if ( !p.hasNext() ) {
8113                 return false;
8114             }
8115             phy = p.next();
8116             if ( phy.getNumberOfExternalNodes() != 10 ) {
8117                 System.out.println( phy.getNumberOfExternalNodes() );
8118                 return false;
8119             }
8120             if ( !phy
8121                     .toNewHampshire()
8122                     .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;" ) ) {
8123                 System.out.println( phy.toNewHampshire() );
8124                 return false;
8125             }
8126             if ( !phy.getName().equals( "tree 15" ) ) {
8127                 return false;
8128             }
8129             if ( phy.isRooted() ) {
8130                 return false;
8131             }
8132             //16
8133             if ( !p.hasNext() ) {
8134                 return false;
8135             }
8136             phy = p.next();
8137             if ( phy.getNumberOfExternalNodes() != 10 ) {
8138                 System.out.println( phy.getNumberOfExternalNodes() );
8139                 return false;
8140             }
8141             if ( !phy
8142                     .toNewHampshire()
8143                     .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;" ) ) {
8144                 System.out.println( phy.toNewHampshire() );
8145                 return false;
8146             }
8147             if ( !phy.getName().equals( "tree 16" ) ) {
8148                 return false;
8149             }
8150             if ( !phy.isRooted() ) {
8151                 return false;
8152             }
8153             //17
8154             if ( !p.hasNext() ) {
8155                 return false;
8156             }
8157             phy = p.next();
8158             if ( phy.getNumberOfExternalNodes() != 10 ) {
8159                 System.out.println( phy.getNumberOfExternalNodes() );
8160                 return false;
8161             }
8162             if ( !phy
8163                     .toNewHampshire()
8164                     .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;" ) ) {
8165                 System.out.println( phy.toNewHampshire() );
8166                 return false;
8167             }
8168             if ( !phy.getName().equals( "tree 17" ) ) {
8169                 return false;
8170             }
8171             if ( phy.isRooted() ) {
8172                 return false;
8173             }
8174             //
8175             if ( p.hasNext() ) {
8176                 return false;
8177             }
8178             phy = p.next();
8179             if ( phy != null ) {
8180                 return false;
8181             }
8182             p.reset();
8183             //0
8184             if ( !p.hasNext() ) {
8185                 return false;
8186             }
8187             phy = p.next();
8188             if ( phy == null ) {
8189                 return false;
8190             }
8191             if ( phy.getNumberOfExternalNodes() != 10 ) {
8192                 return false;
8193             }
8194             if ( !phy.getName().equals( "tree 0" ) ) {
8195                 return false;
8196             }
8197             //1
8198             if ( !p.hasNext() ) {
8199                 return false;
8200             }
8201             phy = p.next();
8202             if ( phy == null ) {
8203                 return false;
8204             }
8205             if ( phy.getNumberOfExternalNodes() != 10 ) {
8206                 return false;
8207             }
8208             if ( !phy.getName().equals( "tree 1" ) ) {
8209                 return false;
8210             }
8211             //2
8212             if ( !p.hasNext() ) {
8213                 return false;
8214             }
8215             phy = p.next();
8216             if ( phy == null ) {
8217                 return false;
8218             }
8219             if ( phy.getNumberOfExternalNodes() != 3 ) {
8220                 return false;
8221             }
8222             if ( !phy.getName().equals( "" ) ) {
8223                 return false;
8224             }
8225             if ( phy.isRooted() ) {
8226                 return false;
8227             }
8228             //3
8229             if ( !p.hasNext() ) {
8230                 return false;
8231             }
8232             phy = p.next();
8233             if ( phy == null ) {
8234                 return false;
8235             }
8236             if ( phy.getNumberOfExternalNodes() != 4 ) {
8237                 return false;
8238             }
8239             if ( !phy.getName().equals( "" ) ) {
8240                 return false;
8241             }
8242             if ( !phy.isRooted() ) {
8243                 return false;
8244             }
8245             //4
8246             if ( !p.hasNext() ) {
8247                 return false;
8248             }
8249             phy = p.next();
8250             if ( phy == null ) {
8251                 return false;
8252             }
8253             if ( phy.getNumberOfExternalNodes() != 5 ) {
8254                 System.out.println( phy.getNumberOfExternalNodes() );
8255                 return false;
8256             }
8257             if ( !phy.getName().equals( "" ) ) {
8258                 return false;
8259             }
8260             if ( !phy.isRooted() ) {
8261                 return false;
8262             }
8263             //5
8264             if ( !p.hasNext() ) {
8265                 return false;
8266             }
8267             phy = p.next();
8268             if ( phy == null ) {
8269                 return false;
8270             }
8271             if ( phy.getNumberOfExternalNodes() != 3 ) {
8272                 return false;
8273             }
8274             if ( !phy.getName().equals( "" ) ) {
8275                 return false;
8276             }
8277             if ( phy.isRooted() ) {
8278                 return false;
8279             }
8280             //
8281             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
8282             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
8283             // 0
8284             if ( !p2.hasNext() ) {
8285                 return false;
8286             }
8287             phy = p2.next();
8288             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8289                 return false;
8290             }
8291             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8292                 return false;
8293             }
8294             // 1
8295             if ( !p2.hasNext() ) {
8296                 return false;
8297             }
8298             phy = p2.next();
8299             // 2
8300             if ( !p2.hasNext() ) {
8301                 return false;
8302             }
8303             phy = p2.next();
8304             // 3
8305             if ( !p2.hasNext() ) {
8306                 return false;
8307             }
8308             phy = p2.next();
8309             // 4
8310             if ( !p2.hasNext() ) {
8311                 return false;
8312             }
8313             phy = p2.next();
8314             // 5
8315             if ( !p2.hasNext() ) {
8316                 return false;
8317             }
8318             phy = p2.next();
8319             // 6
8320             if ( !p2.hasNext() ) {
8321                 return false;
8322             }
8323             phy = p2.next();
8324             // 7
8325             if ( !p2.hasNext() ) {
8326                 return false;
8327             }
8328             phy = p2.next();
8329             // 8
8330             if ( !p2.hasNext() ) {
8331                 return false;
8332             }
8333             phy = p2.next();
8334             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
8335                 return false;
8336             }
8337             if ( p2.hasNext() ) {
8338                 return false;
8339             }
8340             phy = p2.next();
8341             if ( phy != null ) {
8342                 return false;
8343             }
8344             // 0
8345             p2.reset();
8346             if ( !p2.hasNext() ) {
8347                 return false;
8348             }
8349             phy = p2.next();
8350             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8351                 return false;
8352             }
8353             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8354                 return false;
8355             }
8356         }
8357         catch ( final Exception e ) {
8358             e.printStackTrace( System.out );
8359             return false;
8360         }
8361         return true;
8362     }
8363
8364     private static boolean testNexusTreeParsingTranslating() {
8365         try {
8366             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8367             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
8368             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
8369             if ( phylogenies.length != 1 ) {
8370                 return false;
8371             }
8372             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8373                 return false;
8374             }
8375             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8376                 return false;
8377             }
8378             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8379                 return false;
8380             }
8381             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8382                 return false;
8383             }
8384             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8385                     .equals( "Aranaeus" ) ) {
8386                 return false;
8387             }
8388             phylogenies = null;
8389             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
8390             if ( phylogenies.length != 3 ) {
8391                 return false;
8392             }
8393             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8394                 return false;
8395             }
8396             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8397                 return false;
8398             }
8399             if ( phylogenies[ 0 ].isRooted() ) {
8400                 return false;
8401             }
8402             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8403                 return false;
8404             }
8405             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8406                 return false;
8407             }
8408             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8409                     .equals( "Aranaeus" ) ) {
8410                 return false;
8411             }
8412             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8413                 return false;
8414             }
8415             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8416                 return false;
8417             }
8418             if ( phylogenies[ 1 ].isRooted() ) {
8419                 return false;
8420             }
8421             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8422                 return false;
8423             }
8424             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8425                 return false;
8426             }
8427             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8428                     .equals( "Aranaeus" ) ) {
8429                 return false;
8430             }
8431             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8432                 return false;
8433             }
8434             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8435                 return false;
8436             }
8437             if ( !phylogenies[ 2 ].isRooted() ) {
8438                 return false;
8439             }
8440             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8441                 return false;
8442             }
8443             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8444                 return false;
8445             }
8446             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8447                     .equals( "Aranaeus" ) ) {
8448                 return false;
8449             }
8450             phylogenies = null;
8451             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8452             if ( phylogenies.length != 3 ) {
8453                 return false;
8454             }
8455             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8456                 return false;
8457             }
8458             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8459                 return false;
8460             }
8461             if ( phylogenies[ 0 ].isRooted() ) {
8462                 return false;
8463             }
8464             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8465                 return false;
8466             }
8467             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8468                 return false;
8469             }
8470             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8471                     .equals( "Aranaeus" ) ) {
8472                 return false;
8473             }
8474             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8475                 return false;
8476             }
8477             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8478                 return false;
8479             }
8480             if ( phylogenies[ 1 ].isRooted() ) {
8481                 return false;
8482             }
8483             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8484                 return false;
8485             }
8486             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8487                 return false;
8488             }
8489             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8490                     .equals( "Aranaeus" ) ) {
8491                 return false;
8492             }
8493             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8494                 return false;
8495             }
8496             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8497                 return false;
8498             }
8499             if ( !phylogenies[ 2 ].isRooted() ) {
8500                 return false;
8501             }
8502             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8503                 return false;
8504             }
8505             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8506                 return false;
8507             }
8508             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8509                     .equals( "Aranaeus" ) ) {
8510                 return false;
8511             }
8512             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8513             if ( phylogenies.length != 3 ) {
8514                 return false;
8515             }
8516             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8517                            0.00100049 ) ) {
8518                 return false;
8519             }
8520         }
8521         catch ( final Exception e ) {
8522             e.printStackTrace( System.out );
8523             return false;
8524         }
8525         return true;
8526     }
8527
8528     private static boolean testNHParsing() {
8529         try {
8530             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8531             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8532             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8533                 return false;
8534             }
8535             final NHXParser nhxp = new NHXParser();
8536             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8537             nhxp.setReplaceUnderscores( true );
8538             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8539             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8540                 return false;
8541             }
8542             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8543                 return false;
8544             }
8545             final Phylogeny p1b = factory
8546                     .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 ",
8547                              new NHXParser() )[ 0 ];
8548             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8549                 return false;
8550             }
8551             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8552                 return false;
8553             }
8554             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ).toString(), new NHXParser() )[ 0 ];
8555             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8556             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8557             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ).toString(), new NHXParser() )[ 0 ];
8558             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8559             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8560             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8561             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8562             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8563             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8564             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8565                     + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8566                     + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8567                     new NHXParser() );
8568             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8569                 return false;
8570             }
8571             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8572                 return false;
8573             }
8574             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8575                 return false;
8576             }
8577             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8578                 return false;
8579             }
8580             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8581             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8582             final String p16_S = "((A,B),C)";
8583             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8584             if ( p16.length != 1 ) {
8585                 return false;
8586             }
8587             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8588                 return false;
8589             }
8590             final String p17_S = "(C,(A,B))";
8591             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8592             if ( p17.length != 1 ) {
8593                 return false;
8594             }
8595             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8596                 return false;
8597             }
8598             final String p18_S = "((A,B),(C,D))";
8599             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8600             if ( p18.length != 1 ) {
8601                 return false;
8602             }
8603             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8604                 return false;
8605             }
8606             final String p19_S = "(((A,B),C),D)";
8607             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8608             if ( p19.length != 1 ) {
8609                 return false;
8610             }
8611             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8612                 return false;
8613             }
8614             final String p20_S = "(A,(B,(C,D)))";
8615             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8616             if ( p20.length != 1 ) {
8617                 return false;
8618             }
8619             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8620                 return false;
8621             }
8622             final String p21_S = "(A,(B,(C,(D,E))))";
8623             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8624             if ( p21.length != 1 ) {
8625                 return false;
8626             }
8627             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8628                 return false;
8629             }
8630             final String p22_S = "((((A,B),C),D),E)";
8631             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8632             if ( p22.length != 1 ) {
8633                 return false;
8634             }
8635             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8636                 return false;
8637             }
8638             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8639             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8640             if ( p23.length != 1 ) {
8641                 System.out.println( "xl=" + p23.length );
8642                 System.exit( -1 );
8643                 return false;
8644             }
8645             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8646                 return false;
8647             }
8648             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8649             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8650             if ( p24.length != 1 ) {
8651                 return false;
8652             }
8653             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8654                 return false;
8655             }
8656             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8657             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8658             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8659             if ( p241.length != 2 ) {
8660                 return false;
8661             }
8662             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8663                 return false;
8664             }
8665             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8666                 return false;
8667             }
8668             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8669                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8670                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8671                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8672                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8673                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8674                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8675                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8676             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8677             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8678                 return false;
8679             }
8680             final String p26_S = "(A,B)ab";
8681             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8682             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8683                 return false;
8684             }
8685             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8686             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8687             if ( p27s.length != 1 ) {
8688                 System.out.println( "xxl=" + p27s.length );
8689                 System.exit( -1 );
8690                 return false;
8691             }
8692             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8693                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8694                 System.exit( -1 );
8695                 return false;
8696             }
8697             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8698                                                     new NHXParser() );
8699             if ( p27.length != 1 ) {
8700                 System.out.println( "yl=" + p27.length );
8701                 System.exit( -1 );
8702                 return false;
8703             }
8704             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8705                 System.out.println( p27[ 0 ].toNewHampshireX() );
8706                 System.exit( -1 );
8707                 return false;
8708             }
8709             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8710             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8711             final String p28_S3 = "(A,B)ab";
8712             final String p28_S4 = "((((A,B),C),D),;E;)";
8713             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8714                                                     new NHXParser() );
8715             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8716                 return false;
8717             }
8718             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8719                 return false;
8720             }
8721             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8722                 return false;
8723             }
8724             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8725                 return false;
8726             }
8727             if ( p28.length != 4 ) {
8728                 return false;
8729             }
8730             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";
8731             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8732             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8733                 return false;
8734             }
8735             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";
8736             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8737             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8738                 return false;
8739             }
8740             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8741             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8742             if ( ( p32.length != 0 ) ) {
8743                 return false;
8744             }
8745             final String p33_S = "A";
8746             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8747             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8748                 return false;
8749             }
8750             final String p34_S = "B;";
8751             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8752             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8753                 return false;
8754             }
8755             final String p35_S = "B:0.2";
8756             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8757             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8758                 return false;
8759             }
8760             final String p36_S = "(A)";
8761             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8762             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8763                 return false;
8764             }
8765             final String p37_S = "((A))";
8766             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8767             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8768                 return false;
8769             }
8770             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8771             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8772             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8773                 return false;
8774             }
8775             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8776             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8777             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8778                 return false;
8779             }
8780             final String p40_S = "(A,B,C)";
8781             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8782             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8783                 return false;
8784             }
8785             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8786             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8787             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8788                 return false;
8789             }
8790             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8791             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8792             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8793                 return false;
8794             }
8795             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)";
8796             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8797             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8798                 return false;
8799             }
8800             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)))";
8801             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8802             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8803                 return false;
8804             }
8805             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8806             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8807             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8808                 return false;
8809             }
8810             final String p46_S = "";
8811             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8812             if ( p46.length != 0 ) {
8813                 return false;
8814             }
8815             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ).toString(), new NHXParser() )[ 0 ];
8816             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8817                 return false;
8818             }
8819             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8820             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8821                 return false;
8822             }
8823             final Phylogeny p49 = factory
8824                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ).toString(),
8825                              new NHXParser() )[ 0 ];
8826             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8827                 return false;
8828             }
8829             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8830             if ( p50.getNode( "A" ) == null ) {
8831                 return false;
8832             }
8833             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8834                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8835                 return false;
8836             }
8837             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8838                 return false;
8839             }
8840             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8841                     .equals( "((A,B)88:2.0,C);" ) ) {
8842                 return false;
8843             }
8844             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8845             if ( p51.getNode( "A(A" ) == null ) {
8846                 return false;
8847             }
8848             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8849             if ( p52.getNode( "A(A" ) == null ) {
8850                 return false;
8851             }
8852             final Phylogeny p53 = factory
8853                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ).toString(),
8854                              new NHXParser() )[ 0 ];
8855             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8856                 return false;
8857             }
8858             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ).toString(), new NHXParser() )[ 0 ];
8859             if ( p54.getNode( "A" ) == null ) {
8860                 return false;
8861             }
8862             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8863                 return false;
8864             }
8865             final Phylogeny p55 = factory
8866                     .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(),
8867                              new NHXParser() )[ 0 ];
8868             if ( !p55
8869                     .toNewHampshire()
8870                     .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);" ) ) {
8871                 System.out.println( p55.toNewHampshire() );
8872                 return false;
8873             }
8874             final Phylogeny p56 = factory
8875                     .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(),
8876                              new NHXParser() )[ 0 ];
8877             if ( !p56
8878                     .toNewHampshire()
8879                     .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);" ) ) {
8880                 System.out.println( p56.toNewHampshire() );
8881                 return false;
8882             }
8883             final Phylogeny p57 = factory
8884                     .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(),
8885                              new NHXParser() )[ 0 ];
8886             if ( !p57
8887                     .toNewHampshire()
8888                     .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);" ) ) {
8889                 System.out.println( p56.toNewHampshire() );
8890                 return false;
8891             }
8892             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8893             final Phylogeny p58 = factory.create( s58, new NHXParser() )[ 0 ];
8894             if ( !p58.toNewHampshire().equals( s58 ) ) {
8895                 System.out.println( p58.toNewHampshire() );
8896                 return false;
8897             }
8898             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8899             final Phylogeny p59 = factory.create( s59 , new NHXParser() )[ 0 ];
8900             if ( !p59.toNewHampshire().equals( s59 ) ) {
8901                 System.out.println( p59.toNewHampshire() );
8902                 return false;
8903             }
8904             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8905             final Phylogeny p60 = factory.create( s60, new NHXParser() )[ 0 ];
8906             if ( !p60.toNewHampshire().equals( s60 ) ) {
8907                 System.out.println( p60.toNewHampshire() );
8908                 return false;
8909             }
8910             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8911             final Phylogeny p61 = factory.create( s61, new NHXParser() )[ 0 ];
8912             if ( !p61.toNewHampshire()
8913                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8914                 System.out.println( p61.toNewHampshire() );
8915                 return false;
8916             }
8917         }
8918         catch ( final Exception e ) {
8919             e.printStackTrace( System.out );
8920             return false;
8921         }
8922         return true;
8923     }
8924     
8925     private static boolean testNHParsingSpecialChars() {
8926         try {
8927             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();   
8928             final String i0 = "(A!+=~QWERTY!@#$%^&*-,€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ)";
8929             final Phylogeny p0 = factory.create( i0, new NHXParser() )[ 0 ];
8930             if ( !p0.toNewHampshireX().equals( i0 ) ) {
8931                 System.out.println();
8932                 System.out.println( p0.toNewHampshireX() );
8933                 System.out.println( i0 );
8934                 return false;
8935             }
8936             final String i1 = "(हिंदी,한글,ไทย,'Tiếng Việt',ひらがなカタカナ漢字,繁體字,русский)";
8937             final Phylogeny p1 = factory.create( i1, new NHXParser() )[ 0 ];
8938             if ( !p1.toNewHampshireX().equals( i1 ) ) {
8939                 System.out.println();
8940                 System.out.println( p1.toNewHampshireX() );
8941                 System.out.println( i1 );
8942                 return false;
8943             }
8944         }
8945         catch ( final Exception e ) {
8946             e.printStackTrace( System.out );
8947             return false;
8948         }
8949         return true;
8950     }
8951     
8952     
8953     
8954     private static boolean testNHParsingIter() {
8955         try {
8956             final String p0_str = "(A,B);";
8957             final NHXParser p = new NHXParser();
8958             p.setSource( p0_str );
8959             if ( !p.hasNext() ) {
8960                 return false;
8961             }
8962             final Phylogeny p0 = p.next();
8963             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8964                 System.out.println( p0.toNewHampshire() );
8965                 return false;
8966             }
8967             if ( p.hasNext() ) {
8968                 return false;
8969             }
8970             if ( p.next() != null ) {
8971                 return false;
8972             }
8973             //
8974             final String p00_str = "(A,B)root;";
8975             p.setSource( p00_str );
8976             final Phylogeny p00 = p.next();
8977             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8978                 System.out.println( p00.toNewHampshire() );
8979                 return false;
8980             }
8981             //
8982             final String p000_str = "A;";
8983             p.setSource( p000_str );
8984             final Phylogeny p000 = p.next();
8985             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8986                 System.out.println( p000.toNewHampshire() );
8987                 return false;
8988             }
8989             //
8990             final String p0000_str = "A";
8991             p.setSource( p0000_str );
8992             final Phylogeny p0000 = p.next();
8993             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8994                 System.out.println( p0000.toNewHampshire() );
8995                 return false;
8996             }
8997             //
8998             p.setSource( "(A)" );
8999             final Phylogeny p00000 = p.next();
9000             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
9001                 System.out.println( p00000.toNewHampshire() );
9002                 return false;
9003             }
9004             //
9005             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
9006             p.setSource( p1_str );
9007             if ( !p.hasNext() ) {
9008                 return false;
9009             }
9010             final Phylogeny p1_0 = p.next();
9011             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
9012                 System.out.println( p1_0.toNewHampshire() );
9013                 return false;
9014             }
9015             if ( !p.hasNext() ) {
9016                 return false;
9017             }
9018             final Phylogeny p1_1 = p.next();
9019             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
9020                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
9021                 return false;
9022             }
9023             if ( !p.hasNext() ) {
9024                 return false;
9025             }
9026             final Phylogeny p1_2 = p.next();
9027             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
9028                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
9029                 return false;
9030             }
9031             if ( !p.hasNext() ) {
9032                 return false;
9033             }
9034             final Phylogeny p1_3 = p.next();
9035             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
9036                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
9037                 return false;
9038             }
9039             if ( p.hasNext() ) {
9040                 return false;
9041             }
9042             if ( p.next() != null ) {
9043                 return false;
9044             }
9045             //
9046             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
9047             p.setSource( p2_str );
9048             if ( !p.hasNext() ) {
9049                 return false;
9050             }
9051             Phylogeny p2_0 = p.next();
9052             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9053                 System.out.println( p2_0.toNewHampshire() );
9054                 return false;
9055             }
9056             if ( !p.hasNext() ) {
9057                 return false;
9058             }
9059             Phylogeny p2_1 = p.next();
9060             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9061                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9062                 return false;
9063             }
9064             if ( !p.hasNext() ) {
9065                 return false;
9066             }
9067             Phylogeny p2_2 = p.next();
9068             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9069                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9070                 return false;
9071             }
9072             if ( !p.hasNext() ) {
9073                 return false;
9074             }
9075             Phylogeny p2_3 = p.next();
9076             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9077                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9078                 return false;
9079             }
9080             if ( !p.hasNext() ) {
9081                 return false;
9082             }
9083             Phylogeny p2_4 = p.next();
9084             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9085                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9086                 return false;
9087             }
9088             if ( p.hasNext() ) {
9089                 return false;
9090             }
9091             if ( p.next() != null ) {
9092                 return false;
9093             }
9094             ////
9095             p.reset();
9096             if ( !p.hasNext() ) {
9097                 return false;
9098             }
9099             p2_0 = p.next();
9100             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9101                 System.out.println( p2_0.toNewHampshire() );
9102                 return false;
9103             }
9104             if ( !p.hasNext() ) {
9105                 return false;
9106             }
9107             p2_1 = p.next();
9108             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9109                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9110                 return false;
9111             }
9112             if ( !p.hasNext() ) {
9113                 return false;
9114             }
9115             p2_2 = p.next();
9116             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9117                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9118                 return false;
9119             }
9120             if ( !p.hasNext() ) {
9121                 return false;
9122             }
9123             p2_3 = p.next();
9124             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9125                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9126                 return false;
9127             }
9128             if ( !p.hasNext() ) {
9129                 return false;
9130             }
9131             p2_4 = p.next();
9132             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9133                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9134                 return false;
9135             }
9136             if ( p.hasNext() ) {
9137                 return false;
9138             }
9139             if ( p.next() != null ) {
9140                 return false;
9141             }
9142             //
9143             final String p3_str = "((A,B),C)abc";
9144             p.setSource( p3_str );
9145             if ( !p.hasNext() ) {
9146                 return false;
9147             }
9148             final Phylogeny p3_0 = p.next();
9149             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
9150                 return false;
9151             }
9152             if ( p.hasNext() ) {
9153                 return false;
9154             }
9155             if ( p.next() != null ) {
9156                 return false;
9157             }
9158             //
9159             final String p4_str = "((A,B)ab,C)abc";
9160             p.setSource( p4_str );
9161             if ( !p.hasNext() ) {
9162                 return false;
9163             }
9164             final Phylogeny p4_0 = p.next();
9165             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
9166                 return false;
9167             }
9168             if ( p.hasNext() ) {
9169                 return false;
9170             }
9171             if ( p.next() != null ) {
9172                 return false;
9173             }
9174             //
9175             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
9176             p.setSource( p5_str );
9177             if ( !p.hasNext() ) {
9178                 return false;
9179             }
9180             final Phylogeny p5_0 = p.next();
9181             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
9182                 return false;
9183             }
9184             if ( p.hasNext() ) {
9185                 return false;
9186             }
9187             if ( p.next() != null ) {
9188                 return false;
9189             }
9190             //
9191             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
9192             p.setSource( p6_str );
9193             if ( !p.hasNext() ) {
9194                 return false;
9195             }
9196             Phylogeny p6_0 = p.next();
9197             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9198                 return false;
9199             }
9200             if ( p.hasNext() ) {
9201                 return false;
9202             }
9203             if ( p.next() != null ) {
9204                 return false;
9205             }
9206             p.reset();
9207             if ( !p.hasNext() ) {
9208                 return false;
9209             }
9210             p6_0 = p.next();
9211             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9212                 return false;
9213             }
9214             if ( p.hasNext() ) {
9215                 return false;
9216             }
9217             if ( p.next() != null ) {
9218                 return false;
9219             }
9220             //
9221             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
9222             p.setSource( p7_str );
9223             if ( !p.hasNext() ) {
9224                 return false;
9225             }
9226             Phylogeny p7_0 = p.next();
9227             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9228                 return false;
9229             }
9230             if ( p.hasNext() ) {
9231                 return false;
9232             }
9233             if ( p.next() != null ) {
9234                 return false;
9235             }
9236             p.reset();
9237             if ( !p.hasNext() ) {
9238                 return false;
9239             }
9240             p7_0 = p.next();
9241             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9242                 return false;
9243             }
9244             if ( p.hasNext() ) {
9245                 return false;
9246             }
9247             if ( p.next() != null ) {
9248                 return false;
9249             }
9250             //
9251             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
9252             p.setSource( p8_str );
9253             if ( !p.hasNext() ) {
9254                 return false;
9255             }
9256             Phylogeny p8_0 = p.next();
9257             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9258                 return false;
9259             }
9260             if ( !p.hasNext() ) {
9261                 return false;
9262             }
9263             if ( !p.hasNext() ) {
9264                 return false;
9265             }
9266             Phylogeny p8_1 = p.next();
9267             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9268                 return false;
9269             }
9270             if ( p.hasNext() ) {
9271                 return false;
9272             }
9273             if ( p.next() != null ) {
9274                 return false;
9275             }
9276             p.reset();
9277             if ( !p.hasNext() ) {
9278                 return false;
9279             }
9280             p8_0 = p.next();
9281             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9282                 return false;
9283             }
9284             if ( !p.hasNext() ) {
9285                 return false;
9286             }
9287             p8_1 = p.next();
9288             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9289                 return false;
9290             }
9291             if ( p.hasNext() ) {
9292                 return false;
9293             }
9294             if ( p.next() != null ) {
9295                 return false;
9296             }
9297             p.reset();
9298             //
9299             p.setSource( "" );
9300             if ( p.hasNext() ) {
9301                 return false;
9302             }
9303             //
9304             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
9305             if ( !p.hasNext() ) {
9306                 return false;
9307             }
9308             Phylogeny p_27 = p.next();
9309             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9310                 System.out.println( p_27.toNewHampshireX() );
9311                 System.exit( -1 );
9312                 return false;
9313             }
9314             if ( p.hasNext() ) {
9315                 return false;
9316             }
9317             if ( p.next() != null ) {
9318                 return false;
9319             }
9320             p.reset();
9321             if ( !p.hasNext() ) {
9322                 return false;
9323             }
9324             p_27 = p.next();
9325             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9326                 System.out.println( p_27.toNewHampshireX() );
9327                 System.exit( -1 );
9328                 return false;
9329             }
9330             if ( p.hasNext() ) {
9331                 return false;
9332             }
9333             if ( p.next() != null ) {
9334                 return false;
9335             }
9336             //
9337             final String p30_str = "(A,B);(C,D)";
9338             final NHXParser p30 = new NHXParser();
9339             p30.setSource( p30_str );
9340             if ( !p30.hasNext() ) {
9341                 return false;
9342             }
9343             Phylogeny phy30 = p30.next();
9344             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9345                 System.out.println( phy30.toNewHampshire() );
9346                 return false;
9347             }
9348             if ( !p30.hasNext() ) {
9349                 return false;
9350             }
9351             Phylogeny phy301 = p30.next();
9352             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9353                 System.out.println( phy301.toNewHampshire() );
9354                 return false;
9355             }
9356             if ( p30.hasNext() ) {
9357                 return false;
9358             }
9359             if ( p30.hasNext() ) {
9360                 return false;
9361             }
9362             if ( p30.next() != null ) {
9363                 return false;
9364             }
9365             if ( p30.next() != null ) {
9366                 return false;
9367             }
9368             p30.reset();
9369             if ( !p30.hasNext() ) {
9370                 return false;
9371             }
9372             phy30 = p30.next();
9373             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9374                 System.out.println( phy30.toNewHampshire() );
9375                 return false;
9376             }
9377             if ( !p30.hasNext() ) {
9378                 return false;
9379             }
9380             phy301 = p30.next();
9381             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9382                 System.out.println( phy301.toNewHampshire() );
9383                 return false;
9384             }
9385             if ( p30.hasNext() ) {
9386                 return false;
9387             }
9388             if ( p30.hasNext() ) {
9389                 return false;
9390             }
9391             if ( p30.next() != null ) {
9392                 return false;
9393             }
9394             if ( p30.next() != null ) {
9395                 return false;
9396             }
9397         }
9398         catch ( final Exception e ) {
9399             e.printStackTrace( System.out );
9400             return false;
9401         }
9402         return true;
9403     }
9404
9405     private static boolean testNHXconversion() {
9406         try {
9407             final PhylogenyNode n1 = new PhylogenyNode();
9408             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9409             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9410             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9411             final PhylogenyNode n5 = PhylogenyNode
9412                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
9413             final PhylogenyNode n6 = PhylogenyNode
9414                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
9415             if ( !n1.toNewHampshireX().equals( "" ) ) {
9416                 return false;
9417             }
9418             if ( !n2.toNewHampshireX().equals( "" ) ) {
9419                 return false;
9420             }
9421             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
9422                 return false;
9423             }
9424             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
9425                 return false;
9426             }
9427             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
9428                 return false;
9429             }
9430             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9431                 System.out.println( n6.toNewHampshireX() );
9432                 return false;
9433             }
9434             final PhylogenyNode n7 = new PhylogenyNode();
9435             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9436             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9437                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9438                 System.out.println( n7
9439                                     .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9440                 return false;
9441             }
9442         }
9443         catch ( final Exception e ) {
9444             e.printStackTrace( System.out );
9445             return false;
9446         }
9447         return true;
9448     }
9449
9450     private static boolean testNHXNodeParsing() {
9451         try {
9452             final PhylogenyNode n1 = new PhylogenyNode();
9453             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9454             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9455             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9456             final PhylogenyNode n5 = PhylogenyNode
9457                     .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]" );
9458             if ( !n3.getName().equals( "n3" ) ) {
9459                 return false;
9460             }
9461             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9462                 return false;
9463             }
9464             if ( n3.isDuplication() ) {
9465                 return false;
9466             }
9467             if ( n3.isHasAssignedEvent() ) {
9468                 return false;
9469             }
9470             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9471                 return false;
9472             }
9473             if ( !n4.getName().equals( "n4" ) ) {
9474                 return false;
9475             }
9476             if ( n4.getDistanceToParent() != 0.01 ) {
9477                 return false;
9478             }
9479             if ( !n5.getName().equals( "n5" ) ) {
9480                 return false;
9481             }
9482             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9483                 return false;
9484             }
9485             if ( n5.getDistanceToParent() != 0.1 ) {
9486                 return false;
9487             }
9488             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9489                 return false;
9490             }
9491             if ( !n5.isDuplication() ) {
9492                 return false;
9493             }
9494             if ( !n5.isHasAssignedEvent() ) {
9495                 return false;
9496             }
9497             final PhylogenyNode n8 = PhylogenyNode
9498                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9499                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9500             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9501                 return false;
9502             }
9503             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9504                 return false;
9505             }
9506             final PhylogenyNode n9 = PhylogenyNode
9507                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9508                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9509             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9510                 return false;
9511             }
9512             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9513                 return false;
9514             }
9515             final PhylogenyNode n10 = PhylogenyNode
9516                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9517             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9518                 return false;
9519             }
9520             final PhylogenyNode n20 = PhylogenyNode
9521                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9522             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9523                 return false;
9524             }
9525             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9526                 return false;
9527             }
9528             final PhylogenyNode n20x = PhylogenyNode
9529                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9530             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9531                 return false;
9532             }
9533             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9534                 return false;
9535             }
9536             final PhylogenyNode n20xx = PhylogenyNode
9537                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9538             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9539                 return false;
9540             }
9541             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9542                 return false;
9543             }
9544             final PhylogenyNode n20xxx = PhylogenyNode
9545                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9546             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9547                 return false;
9548             }
9549             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9550                 return false;
9551             }
9552             final PhylogenyNode n20xxxx = PhylogenyNode
9553                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9554             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9555                 return false;
9556             }
9557             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9558                 return false;
9559             }
9560             final PhylogenyNode n21 = PhylogenyNode
9561                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9562             if ( !n21.getName().equals( "N21_PIG" ) ) {
9563                 return false;
9564             }
9565             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9566                 return false;
9567             }
9568             final PhylogenyNode n21x = PhylogenyNode
9569                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9570             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9571                 return false;
9572             }
9573             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9574                 return false;
9575             }
9576             final PhylogenyNode n22 = PhylogenyNode
9577                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9578             if ( !n22.getName().equals( "n22/PIG" ) ) {
9579                 return false;
9580             }
9581             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9582                 return false;
9583             }
9584             final PhylogenyNode n23 = PhylogenyNode
9585                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9586             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9587                 return false;
9588             }
9589             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9590                 return false;
9591             }
9592             final PhylogenyNode a = PhylogenyNode
9593                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9594             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9595                 return false;
9596             }
9597             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9598                 return false;
9599             }
9600             final PhylogenyNode c1 = PhylogenyNode
9601                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9602                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9603             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9604                 return false;
9605             }
9606             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9607                 return false;
9608             }
9609             final PhylogenyNode c2 = PhylogenyNode
9610                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9611                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9612             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9613                 return false;
9614             }
9615             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9616                 return false;
9617             }
9618             final PhylogenyNode e3 = PhylogenyNode
9619                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9620             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9621                 return false;
9622             }
9623             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9624                 return false;
9625             }
9626             final PhylogenyNode n11 = PhylogenyNode
9627                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9628                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9629             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9630                 return false;
9631             }
9632             if ( n11.getDistanceToParent() != 0.4 ) {
9633                 return false;
9634             }
9635             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9636                 return false;
9637             }
9638             final PhylogenyNode n12 = PhylogenyNode
9639                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9640                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9641             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9642                 return false;
9643             }
9644             if ( n12.getDistanceToParent() != 0.4 ) {
9645                 return false;
9646             }
9647             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9648                 return false;
9649             }
9650             final PhylogenyNode o = PhylogenyNode
9651                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9652             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9653                 return false;
9654             }
9655             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9656                 return false;
9657             }
9658             if ( n1.getName().compareTo( "" ) != 0 ) {
9659                 return false;
9660             }
9661             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9662                 return false;
9663             }
9664             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9665                 return false;
9666             }
9667             if ( n2.getName().compareTo( "" ) != 0 ) {
9668                 return false;
9669             }
9670             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9671                 return false;
9672             }
9673             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9674                 return false;
9675             }
9676             final PhylogenyNode n00 = PhylogenyNode
9677                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9678             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9679                 return false;
9680             }
9681             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9682                 return false;
9683             }
9684             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9685             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9686                 return false;
9687             }
9688             final PhylogenyNode n13 = PhylogenyNode
9689                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9690             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9691                 return false;
9692             }
9693             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9694                 return false;
9695             }
9696             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9697                 return false;
9698             }
9699             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9700                 return false;
9701             }
9702             final PhylogenyNode n14 = PhylogenyNode
9703                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9704             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9705                 return false;
9706             }
9707             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9708                 return false;
9709             }
9710             final PhylogenyNode n15 = PhylogenyNode
9711                     .createInstanceFromNhxString( "something_wicked[123]",
9712                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9713             if ( !n15.getName().equals( "something_wicked" ) ) {
9714                 return false;
9715             }
9716             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9717                 return false;
9718             }
9719             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9720                 return false;
9721             }
9722             final PhylogenyNode n16 = PhylogenyNode
9723                     .createInstanceFromNhxString( "something_wicked2[9]",
9724                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9725             if ( !n16.getName().equals( "something_wicked2" ) ) {
9726                 return false;
9727             }
9728             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9729                 return false;
9730             }
9731             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9732                 return false;
9733             }
9734             final PhylogenyNode n17 = PhylogenyNode
9735                     .createInstanceFromNhxString( "something_wicked3[a]",
9736                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9737             if ( !n17.getName().equals( "something_wicked3" ) ) {
9738                 return false;
9739             }
9740             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9741                 return false;
9742             }
9743             final PhylogenyNode n18 = PhylogenyNode
9744                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9745             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9746                 return false;
9747             }
9748             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9749                 return false;
9750             }
9751             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9752                 return false;
9753             }
9754             final PhylogenyNode n19 = PhylogenyNode
9755                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9756             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9757                 return false;
9758             }
9759             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9760                 return false;
9761             }
9762             final PhylogenyNode n30 = PhylogenyNode
9763                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9764                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9765             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9766                 return false;
9767             }
9768             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9769                 return false;
9770             }
9771             final PhylogenyNode n31 = PhylogenyNode
9772                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9773                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9774             if ( n31.getNodeData().isHasTaxonomy() ) {
9775                 return false;
9776             }
9777             final PhylogenyNode n32 = PhylogenyNode
9778                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9779             if ( n32.getNodeData().isHasTaxonomy() ) {
9780                 return false;
9781             }
9782             final PhylogenyNode n40 = PhylogenyNode
9783                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9784             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9785                 return false;
9786             }
9787             final PhylogenyNode n41 = PhylogenyNode
9788                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9789             if ( n41.getNodeData().isHasTaxonomy() ) {
9790                 return false;
9791             }
9792             final PhylogenyNode n42 = PhylogenyNode
9793                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9794             if ( n42.getNodeData().isHasTaxonomy() ) {
9795                 return false;
9796             }
9797             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9798                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9799             if ( n43.getNodeData().isHasTaxonomy() ) {
9800                 return false;
9801             }
9802             final PhylogenyNode n44 = PhylogenyNode
9803                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9804             if ( n44.getNodeData().isHasTaxonomy() ) {
9805                 return false;
9806             }
9807         }
9808         catch ( final Exception e ) {
9809             e.printStackTrace( System.out );
9810             return false;
9811         }
9812         return true;
9813     }
9814
9815     private static boolean testNHXParsing() {
9816         try {
9817             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9818             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9819             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9820                 return false;
9821             }
9822             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]";
9823             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9824             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9825                 return false;
9826             }
9827             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]";
9828             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9829             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9830                 return false;
9831             }
9832             final Phylogeny[] p3 = factory
9833                     .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]",
9834                              new NHXParser() );
9835             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9836                 return false;
9837             }
9838             final Phylogeny[] p4 = factory
9839                     .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(]",
9840                              new NHXParser() );
9841             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9842                 return false;
9843             }
9844             final Phylogeny[] p5 = factory
9845                     .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(((]",
9846                              new NHXParser() );
9847             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9848                 return false;
9849             }
9850             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)";
9851             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)";
9852             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9853             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9854                 return false;
9855             }
9856             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)))";
9857             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)))";
9858             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9859             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9860                 return false;
9861             }
9862             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])   ))[,,, ])))))))";
9863             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9864             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9865             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9866                 return false;
9867             }
9868             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9869             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9870                 return false;
9871             }
9872             final Phylogeny p10 = factory
9873                     .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]",
9874                              new NHXParser() )[ 0 ];
9875             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9876                 return false;
9877             }
9878             final Phylogeny p11 = factory
9879                     .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]",
9880                              new NHXParser() )[ 0 ];
9881             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9882                 return false;
9883             }
9884             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]",
9885                                                   new NHXParser() )[ 0 ];
9886             if ( !p12.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9887                 return false;
9888             }
9889         }
9890         catch ( final Exception e ) {
9891             e.printStackTrace( System.out );
9892             return false;
9893         }
9894         return true;
9895     }
9896
9897     private static boolean testNHXParsingMB() {
9898         try {
9899             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9900             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9901                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9902                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9903                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9904                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9905                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9906                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9907                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9908                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9909             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9910                 return false;
9911             }
9912             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9913                 return false;
9914             }
9915             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9916                            0.1100000000000000e+00 ) ) {
9917                 return false;
9918             }
9919             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9920                 return false;
9921             }
9922             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9923                 return false;
9924             }
9925             final Phylogeny p2 = factory
9926                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9927                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9928                             + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9929                             + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9930                             + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9931                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9932                             + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9933                             + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9934                             + "7.369400000000000e-02}])",
9935                             new NHXParser() )[ 0 ];
9936             if ( p2.getNode( "1" ) == null ) {
9937                 return false;
9938             }
9939             if ( p2.getNode( "2" ) == null ) {
9940                 return false;
9941             }
9942         }
9943         catch ( final Exception e ) {
9944             e.printStackTrace( System.out );
9945             System.exit( -1 );
9946             return false;
9947         }
9948         return true;
9949     }
9950
9951     private static boolean testNHXParsingQuotes() {
9952         try {
9953             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9954             final NHXParser p = new NHXParser();
9955             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9956             if ( phylogenies_0.length != 5 ) {
9957                 return false;
9958             }
9959             final Phylogeny phy = phylogenies_0[ 4 ];
9960             if ( phy.getNumberOfExternalNodes() != 7 ) {
9961                 return false;
9962             }
9963             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9964                 return false;
9965             }
9966             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9967                 return false;
9968             }
9969             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9970                     .getScientificName().equals( "hsapiens" ) ) {
9971                 return false;
9972             }
9973             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9974                 return false;
9975             }
9976             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9977                 return false;
9978             }
9979             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9980                 return false;
9981             }
9982             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9983                 return false;
9984             }
9985             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9986                 return false;
9987             }
9988             final NHXParser p1p = new NHXParser();
9989             p1p.setIgnoreQuotes( true );
9990             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9991             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9992                 return false;
9993             }
9994             final NHXParser p2p = new NHXParser();
9995             p1p.setIgnoreQuotes( false );
9996             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9997             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9998                 return false;
9999             }
10000             final NHXParser p3p = new NHXParser();
10001             p3p.setIgnoreQuotes( false );
10002             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
10003             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
10004                 return false;
10005             }
10006             final NHXParser p4p = new NHXParser();
10007             p4p.setIgnoreQuotes( false );
10008             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
10009             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
10010                 return false;
10011             }
10012             final Phylogeny p10 = factory
10013                     .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]",
10014                              new NHXParser() )[ 0 ];
10015             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]";
10016             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
10017                 return false;
10018             }
10019             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
10020             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
10021                 return false;
10022             }
10023             final Phylogeny p12 = factory
10024                     .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]",
10025                              new NHXParser() )[ 0 ];
10026             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]";
10027             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
10028                 return false;
10029             }
10030             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
10031             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
10032                 return false;
10033             }
10034             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;";
10035             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
10036                 return false;
10037             }
10038             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
10039             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
10040                 return false;
10041             }
10042         }
10043         catch ( final Exception e ) {
10044             e.printStackTrace( System.out );
10045             return false;
10046         }
10047         return true;
10048     }
10049
10050     private static boolean testNodeRemoval() {
10051         try {
10052             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10053             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
10054             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
10055             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
10056                 return false;
10057             }
10058             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
10059             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
10060             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
10061                 return false;
10062             }
10063             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
10064             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
10065             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
10066                 return false;
10067             }
10068         }
10069         catch ( final Exception e ) {
10070             e.printStackTrace( System.out );
10071             return false;
10072         }
10073         return true;
10074     }
10075
10076     private static boolean testPhylogenyBranch() {
10077         try {
10078             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
10079             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
10080             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
10081             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
10082             if ( !a1b1.equals( a1b1 ) ) {
10083                 return false;
10084             }
10085             if ( !a1b1.equals( b1a1 ) ) {
10086                 return false;
10087             }
10088             if ( !b1a1.equals( a1b1 ) ) {
10089                 return false;
10090             }
10091             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
10092             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
10093             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
10094             if ( a1_b1.equals( b1_a1 ) ) {
10095                 return false;
10096             }
10097             if ( a1_b1.equals( a1_b1_ ) ) {
10098                 return false;
10099             }
10100             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
10101             if ( !a1_b1.equals( b1_a1_ ) ) {
10102                 return false;
10103             }
10104             if ( a1_b1_.equals( b1_a1_ ) ) {
10105                 return false;
10106             }
10107             if ( !a1_b1_.equals( b1_a1 ) ) {
10108                 return false;
10109             }
10110         }
10111         catch ( final Exception e ) {
10112             e.printStackTrace( System.out );
10113             return false;
10114         }
10115         return true;
10116     }
10117
10118     private static boolean testPhyloXMLparsingOfDistributionElement() {
10119         try {
10120             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10121             PhyloXmlParser xml_parser = null;
10122             try {
10123                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
10124             }
10125             catch ( final Exception e ) {
10126                 // Do nothing -- means were not running from jar.
10127             }
10128             if ( xml_parser == null ) {
10129                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
10130                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
10131                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
10132                 }
10133                 else {
10134                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
10135                 }
10136             }
10137             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml" ),
10138                                                               xml_parser );
10139             if ( xml_parser.getErrorCount() > 0 ) {
10140                 System.out.println( xml_parser.getErrorMessages().toString() );
10141                 return false;
10142             }
10143             if ( phylogenies_0.length != 1 ) {
10144                 return false;
10145             }
10146             final Phylogeny t1 = phylogenies_0[ 0 ];
10147             PhylogenyNode n = null;
10148             Distribution d = null;
10149             n = t1.getNode( "root node" );
10150             if ( !n.getNodeData().isHasDistribution() ) {
10151                 return false;
10152             }
10153             if ( n.getNodeData().getDistributions().size() != 1 ) {
10154                 return false;
10155             }
10156             d = n.getNodeData().getDistribution();
10157             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10158                 return false;
10159             }
10160             if ( d.getPoints().size() != 1 ) {
10161                 return false;
10162             }
10163             if ( d.getPolygons() != null ) {
10164                 return false;
10165             }
10166             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10167                 return false;
10168             }
10169             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10170                 return false;
10171             }
10172             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10173                 return false;
10174             }
10175             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10176                 return false;
10177             }
10178             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10179                 return false;
10180             }
10181             n = t1.getNode( "node a" );
10182             if ( !n.getNodeData().isHasDistribution() ) {
10183                 return false;
10184             }
10185             if ( n.getNodeData().getDistributions().size() != 2 ) {
10186                 return false;
10187             }
10188             d = n.getNodeData().getDistribution( 1 );
10189             if ( !d.getDesc().equals( "San Diego" ) ) {
10190                 return false;
10191             }
10192             if ( d.getPoints().size() != 1 ) {
10193                 return false;
10194             }
10195             if ( d.getPolygons() != null ) {
10196                 return false;
10197             }
10198             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10199                 return false;
10200             }
10201             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10202                 return false;
10203             }
10204             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10205                 return false;
10206             }
10207             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10208                 return false;
10209             }
10210             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10211                 return false;
10212             }
10213             n = t1.getNode( "node bb" );
10214             if ( !n.getNodeData().isHasDistribution() ) {
10215                 return false;
10216             }
10217             if ( n.getNodeData().getDistributions().size() != 1 ) {
10218                 return false;
10219             }
10220             d = n.getNodeData().getDistribution( 0 );
10221             if ( d.getPoints().size() != 3 ) {
10222                 return false;
10223             }
10224             if ( d.getPolygons().size() != 2 ) {
10225                 return false;
10226             }
10227             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10228                 return false;
10229             }
10230             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10231                 return false;
10232             }
10233             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10234                 return false;
10235             }
10236             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10237                 return false;
10238             }
10239             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10240                 return false;
10241             }
10242             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10243                 return false;
10244             }
10245             Polygon p = d.getPolygons().get( 0 );
10246             if ( p.getPoints().size() != 3 ) {
10247                 return false;
10248             }
10249             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10250                 return false;
10251             }
10252             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10253                 return false;
10254             }
10255             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10256                 return false;
10257             }
10258             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10259                 return false;
10260             }
10261             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10262                 return false;
10263             }
10264             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10265                 return false;
10266             }
10267             p = d.getPolygons().get( 1 );
10268             if ( p.getPoints().size() != 3 ) {
10269                 return false;
10270             }
10271             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10272                 return false;
10273             }
10274             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10275                 return false;
10276             }
10277             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10278                 return false;
10279             }
10280             // Roundtrip:
10281             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
10282             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
10283             if ( rt.length != 1 ) {
10284                 return false;
10285             }
10286             final Phylogeny t1_rt = rt[ 0 ];
10287             n = t1_rt.getNode( "root node" );
10288             if ( !n.getNodeData().isHasDistribution() ) {
10289                 return false;
10290             }
10291             if ( n.getNodeData().getDistributions().size() != 1 ) {
10292                 return false;
10293             }
10294             d = n.getNodeData().getDistribution();
10295             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10296                 return false;
10297             }
10298             if ( d.getPoints().size() != 1 ) {
10299                 return false;
10300             }
10301             if ( d.getPolygons() != null ) {
10302                 return false;
10303             }
10304             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10305                 return false;
10306             }
10307             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10308                 return false;
10309             }
10310             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10311                 return false;
10312             }
10313             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10314                 return false;
10315             }
10316             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10317                 return false;
10318             }
10319             n = t1_rt.getNode( "node a" );
10320             if ( !n.getNodeData().isHasDistribution() ) {
10321                 return false;
10322             }
10323             if ( n.getNodeData().getDistributions().size() != 2 ) {
10324                 return false;
10325             }
10326             d = n.getNodeData().getDistribution( 1 );
10327             if ( !d.getDesc().equals( "San Diego" ) ) {
10328                 return false;
10329             }
10330             if ( d.getPoints().size() != 1 ) {
10331                 return false;
10332             }
10333             if ( d.getPolygons() != null ) {
10334                 return false;
10335             }
10336             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10337                 return false;
10338             }
10339             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10340                 return false;
10341             }
10342             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10343                 return false;
10344             }
10345             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10346                 return false;
10347             }
10348             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10349                 return false;
10350             }
10351             n = t1_rt.getNode( "node bb" );
10352             if ( !n.getNodeData().isHasDistribution() ) {
10353                 return false;
10354             }
10355             if ( n.getNodeData().getDistributions().size() != 1 ) {
10356                 return false;
10357             }
10358             d = n.getNodeData().getDistribution( 0 );
10359             if ( d.getPoints().size() != 3 ) {
10360                 return false;
10361             }
10362             if ( d.getPolygons().size() != 2 ) {
10363                 return false;
10364             }
10365             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10366                 return false;
10367             }
10368             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10369                 return false;
10370             }
10371             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10372                 return false;
10373             }
10374             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10375                 return false;
10376             }
10377             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10378                 return false;
10379             }
10380             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10381                 return false;
10382             }
10383             p = d.getPolygons().get( 0 );
10384             if ( p.getPoints().size() != 3 ) {
10385                 return false;
10386             }
10387             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10388                 return false;
10389             }
10390             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10391                 return false;
10392             }
10393             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10394                 return false;
10395             }
10396             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10397                 return false;
10398             }
10399             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10400                 return false;
10401             }
10402             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10403                 return false;
10404             }
10405             p = d.getPolygons().get( 1 );
10406             if ( p.getPoints().size() != 3 ) {
10407                 return false;
10408             }
10409             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10410                 return false;
10411             }
10412             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10413                 return false;
10414             }
10415             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10416                 return false;
10417             }
10418         }
10419         catch ( final Exception e ) {
10420             e.printStackTrace( System.out );
10421             return false;
10422         }
10423         return true;
10424     }
10425
10426     private static boolean testPostOrderIterator() {
10427         try {
10428             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10429             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10430             PhylogenyNodeIterator it0;
10431             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
10432                 it0.next();
10433             }
10434             for( it0.reset(); it0.hasNext(); ) {
10435                 it0.next();
10436             }
10437             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10438             final PhylogenyNodeIterator it = t1.iteratorPostorder();
10439             if ( !it.next().getName().equals( "A" ) ) {
10440                 return false;
10441             }
10442             if ( !it.next().getName().equals( "B" ) ) {
10443                 return false;
10444             }
10445             if ( !it.next().getName().equals( "ab" ) ) {
10446                 return false;
10447             }
10448             if ( !it.next().getName().equals( "C" ) ) {
10449                 return false;
10450             }
10451             if ( !it.next().getName().equals( "D" ) ) {
10452                 return false;
10453             }
10454             if ( !it.next().getName().equals( "cd" ) ) {
10455                 return false;
10456             }
10457             if ( !it.next().getName().equals( "abcd" ) ) {
10458                 return false;
10459             }
10460             if ( !it.next().getName().equals( "E" ) ) {
10461                 return false;
10462             }
10463             if ( !it.next().getName().equals( "F" ) ) {
10464                 return false;
10465             }
10466             if ( !it.next().getName().equals( "ef" ) ) {
10467                 return false;
10468             }
10469             if ( !it.next().getName().equals( "G" ) ) {
10470                 return false;
10471             }
10472             if ( !it.next().getName().equals( "H" ) ) {
10473                 return false;
10474             }
10475             if ( !it.next().getName().equals( "gh" ) ) {
10476                 return false;
10477             }
10478             if ( !it.next().getName().equals( "efgh" ) ) {
10479                 return false;
10480             }
10481             if ( !it.next().getName().equals( "r" ) ) {
10482                 return false;
10483             }
10484             if ( it.hasNext() ) {
10485                 return false;
10486             }
10487         }
10488         catch ( final Exception e ) {
10489             e.printStackTrace( System.out );
10490             return false;
10491         }
10492         return true;
10493     }
10494
10495     private static boolean testPreOrderIterator() {
10496         try {
10497             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10498             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10499             PhylogenyNodeIterator it0;
10500             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10501                 it0.next();
10502             }
10503             for( it0.reset(); it0.hasNext(); ) {
10504                 it0.next();
10505             }
10506             PhylogenyNodeIterator it = t0.iteratorPreorder();
10507             if ( !it.next().getName().equals( "r" ) ) {
10508                 return false;
10509             }
10510             if ( !it.next().getName().equals( "ab" ) ) {
10511                 return false;
10512             }
10513             if ( !it.next().getName().equals( "A" ) ) {
10514                 return false;
10515             }
10516             if ( !it.next().getName().equals( "B" ) ) {
10517                 return false;
10518             }
10519             if ( !it.next().getName().equals( "cd" ) ) {
10520                 return false;
10521             }
10522             if ( !it.next().getName().equals( "C" ) ) {
10523                 return false;
10524             }
10525             if ( !it.next().getName().equals( "D" ) ) {
10526                 return false;
10527             }
10528             if ( it.hasNext() ) {
10529                 return false;
10530             }
10531             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10532             it = t1.iteratorPreorder();
10533             if ( !it.next().getName().equals( "r" ) ) {
10534                 return false;
10535             }
10536             if ( !it.next().getName().equals( "abcd" ) ) {
10537                 return false;
10538             }
10539             if ( !it.next().getName().equals( "ab" ) ) {
10540                 return false;
10541             }
10542             if ( !it.next().getName().equals( "A" ) ) {
10543                 return false;
10544             }
10545             if ( !it.next().getName().equals( "B" ) ) {
10546                 return false;
10547             }
10548             if ( !it.next().getName().equals( "cd" ) ) {
10549                 return false;
10550             }
10551             if ( !it.next().getName().equals( "C" ) ) {
10552                 return false;
10553             }
10554             if ( !it.next().getName().equals( "D" ) ) {
10555                 return false;
10556             }
10557             if ( !it.next().getName().equals( "efgh" ) ) {
10558                 return false;
10559             }
10560             if ( !it.next().getName().equals( "ef" ) ) {
10561                 return false;
10562             }
10563             if ( !it.next().getName().equals( "E" ) ) {
10564                 return false;
10565             }
10566             if ( !it.next().getName().equals( "F" ) ) {
10567                 return false;
10568             }
10569             if ( !it.next().getName().equals( "gh" ) ) {
10570                 return false;
10571             }
10572             if ( !it.next().getName().equals( "G" ) ) {
10573                 return false;
10574             }
10575             if ( !it.next().getName().equals( "H" ) ) {
10576                 return false;
10577             }
10578             if ( it.hasNext() ) {
10579                 return false;
10580             }
10581         }
10582         catch ( final Exception e ) {
10583             e.printStackTrace( System.out );
10584             return false;
10585         }
10586         return true;
10587     }
10588
10589     private static boolean testPropertiesMap() {
10590         try {
10591             final PropertiesMap pm = new PropertiesMap();
10592             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10593             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10594             final Property p2 = new Property( "something:else",
10595                                               "?",
10596                                               "improbable:research",
10597                                               "xsd:decimal",
10598                                               AppliesTo.NODE );
10599             pm.addProperty( p0 );
10600             pm.addProperty( p1 );
10601             pm.addProperty( p2 );
10602             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10603                 return false;
10604             }
10605             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10606                 return false;
10607             }
10608             if ( pm.getProperties().size() != 3 ) {
10609                 return false;
10610             }
10611             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10612                 return false;
10613             }
10614             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10615                 return false;
10616             }
10617             if ( pm.getProperties().size() != 3 ) {
10618                 return false;
10619             }
10620             pm.removeProperty( "dimensions:diameter" );
10621             if ( pm.getProperties().size() != 2 ) {
10622                 return false;
10623             }
10624             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10625                 return false;
10626             }
10627             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10628                 return false;
10629             }
10630         }
10631         catch ( final Exception e ) {
10632             e.printStackTrace( System.out );
10633             return false;
10634         }
10635         return true;
10636     }
10637
10638     private static boolean testProteinId() {
10639         try {
10640             final ProteinId id1 = new ProteinId( "a" );
10641             final ProteinId id2 = new ProteinId( "a" );
10642             final ProteinId id3 = new ProteinId( "A" );
10643             final ProteinId id4 = new ProteinId( "b" );
10644             if ( !id1.equals( id1 ) ) {
10645                 return false;
10646             }
10647             if ( id1.getId().equals( "x" ) ) {
10648                 return false;
10649             }
10650             if ( id1.getId().equals( null ) ) {
10651                 return false;
10652             }
10653             if ( !id1.equals( id2 ) ) {
10654                 return false;
10655             }
10656             if ( id1.equals( id3 ) ) {
10657                 return false;
10658             }
10659             if ( id1.hashCode() != id1.hashCode() ) {
10660                 return false;
10661             }
10662             if ( id1.hashCode() != id2.hashCode() ) {
10663                 return false;
10664             }
10665             if ( id1.hashCode() == id3.hashCode() ) {
10666                 return false;
10667             }
10668             if ( id1.compareTo( id1 ) != 0 ) {
10669                 return false;
10670             }
10671             if ( id1.compareTo( id2 ) != 0 ) {
10672                 return false;
10673             }
10674             if ( id1.compareTo( id3 ) != 0 ) {
10675                 return false;
10676             }
10677             if ( id1.compareTo( id4 ) >= 0 ) {
10678                 return false;
10679             }
10680             if ( id4.compareTo( id1 ) <= 0 ) {
10681                 return false;
10682             }
10683             if ( !id4.getId().equals( "b" ) ) {
10684                 return false;
10685             }
10686             final ProteinId id5 = new ProteinId( " C " );
10687             if ( !id5.getId().equals( "C" ) ) {
10688                 return false;
10689             }
10690             if ( id5.equals( id1 ) ) {
10691                 return false;
10692             }
10693         }
10694         catch ( final Exception e ) {
10695             e.printStackTrace( System.out );
10696             return false;
10697         }
10698         return true;
10699     }
10700
10701     private static boolean testReIdMethods() {
10702         try {
10703             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10704             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10705             final long count = PhylogenyNode.getNodeCount();
10706             p.levelOrderReID();
10707             if ( p.getNode( "r" ).getId() != count ) {
10708                 return false;
10709             }
10710             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10711                 return false;
10712             }
10713             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10714                 return false;
10715             }
10716             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10717                 return false;
10718             }
10719             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10720                 return false;
10721             }
10722             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10723                 return false;
10724             }
10725             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10726                 return false;
10727             }
10728             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10729                 return false;
10730             }
10731             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10732                 return false;
10733             }
10734             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10735                 return false;
10736             }
10737             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10738                 return false;
10739             }
10740             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10741                 return false;
10742             }
10743             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10744                 return false;
10745             }
10746             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10747                 return false;
10748             }
10749             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10750                 return false;
10751             }
10752         }
10753         catch ( final Exception e ) {
10754             e.printStackTrace( System.out );
10755             return false;
10756         }
10757         return true;
10758     }
10759
10760     private static boolean testRerooting() {
10761         try {
10762             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10763             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",
10764                                                  new NHXParser() )[ 0 ];
10765             if ( !t1.isRooted() ) {
10766                 return false;
10767             }
10768             t1.reRoot( t1.getNode( "D" ) );
10769             t1.reRoot( t1.getNode( "CD" ) );
10770             t1.reRoot( t1.getNode( "A" ) );
10771             t1.reRoot( t1.getNode( "B" ) );
10772             t1.reRoot( t1.getNode( "AB" ) );
10773             t1.reRoot( t1.getNode( "D" ) );
10774             t1.reRoot( t1.getNode( "C" ) );
10775             t1.reRoot( t1.getNode( "CD" ) );
10776             t1.reRoot( t1.getNode( "A" ) );
10777             t1.reRoot( t1.getNode( "B" ) );
10778             t1.reRoot( t1.getNode( "AB" ) );
10779             t1.reRoot( t1.getNode( "D" ) );
10780             t1.reRoot( t1.getNode( "D" ) );
10781             t1.reRoot( t1.getNode( "C" ) );
10782             t1.reRoot( t1.getNode( "A" ) );
10783             t1.reRoot( t1.getNode( "B" ) );
10784             t1.reRoot( t1.getNode( "AB" ) );
10785             t1.reRoot( t1.getNode( "C" ) );
10786             t1.reRoot( t1.getNode( "D" ) );
10787             t1.reRoot( t1.getNode( "CD" ) );
10788             t1.reRoot( t1.getNode( "D" ) );
10789             t1.reRoot( t1.getNode( "A" ) );
10790             t1.reRoot( t1.getNode( "B" ) );
10791             t1.reRoot( t1.getNode( "AB" ) );
10792             t1.reRoot( t1.getNode( "C" ) );
10793             t1.reRoot( t1.getNode( "D" ) );
10794             t1.reRoot( t1.getNode( "CD" ) );
10795             t1.reRoot( t1.getNode( "D" ) );
10796             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10797                 return false;
10798             }
10799             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10800                 return false;
10801             }
10802             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10803                 return false;
10804             }
10805             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10806                 return false;
10807             }
10808             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10809                 return false;
10810             }
10811             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10812                 return false;
10813             }
10814             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",
10815                                                  new NHXParser() )[ 0 ];
10816             t2.reRoot( t2.getNode( "A" ) );
10817             t2.reRoot( t2.getNode( "D" ) );
10818             t2.reRoot( t2.getNode( "ABC" ) );
10819             t2.reRoot( t2.getNode( "A" ) );
10820             t2.reRoot( t2.getNode( "B" ) );
10821             t2.reRoot( t2.getNode( "D" ) );
10822             t2.reRoot( t2.getNode( "C" ) );
10823             t2.reRoot( t2.getNode( "ABC" ) );
10824             t2.reRoot( t2.getNode( "A" ) );
10825             t2.reRoot( t2.getNode( "B" ) );
10826             t2.reRoot( t2.getNode( "AB" ) );
10827             t2.reRoot( t2.getNode( "AB" ) );
10828             t2.reRoot( t2.getNode( "D" ) );
10829             t2.reRoot( t2.getNode( "C" ) );
10830             t2.reRoot( t2.getNode( "B" ) );
10831             t2.reRoot( t2.getNode( "AB" ) );
10832             t2.reRoot( t2.getNode( "D" ) );
10833             t2.reRoot( t2.getNode( "D" ) );
10834             t2.reRoot( t2.getNode( "ABC" ) );
10835             t2.reRoot( t2.getNode( "A" ) );
10836             t2.reRoot( t2.getNode( "B" ) );
10837             t2.reRoot( t2.getNode( "AB" ) );
10838             t2.reRoot( t2.getNode( "D" ) );
10839             t2.reRoot( t2.getNode( "C" ) );
10840             t2.reRoot( t2.getNode( "ABC" ) );
10841             t2.reRoot( t2.getNode( "A" ) );
10842             t2.reRoot( t2.getNode( "B" ) );
10843             t2.reRoot( t2.getNode( "AB" ) );
10844             t2.reRoot( t2.getNode( "D" ) );
10845             t2.reRoot( t2.getNode( "D" ) );
10846             t2.reRoot( t2.getNode( "C" ) );
10847             t2.reRoot( t2.getNode( "A" ) );
10848             t2.reRoot( t2.getNode( "B" ) );
10849             t2.reRoot( t2.getNode( "AB" ) );
10850             t2.reRoot( t2.getNode( "C" ) );
10851             t2.reRoot( t2.getNode( "D" ) );
10852             t2.reRoot( t2.getNode( "ABC" ) );
10853             t2.reRoot( t2.getNode( "D" ) );
10854             t2.reRoot( t2.getNode( "A" ) );
10855             t2.reRoot( t2.getNode( "B" ) );
10856             t2.reRoot( t2.getNode( "AB" ) );
10857             t2.reRoot( t2.getNode( "C" ) );
10858             t2.reRoot( t2.getNode( "D" ) );
10859             t2.reRoot( t2.getNode( "ABC" ) );
10860             t2.reRoot( t2.getNode( "D" ) );
10861             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10862                 return false;
10863             }
10864             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10865                 return false;
10866             }
10867             t2.reRoot( t2.getNode( "ABC" ) );
10868             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10869                 return false;
10870             }
10871             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10872                 return false;
10873             }
10874             t2.reRoot( t2.getNode( "AB" ) );
10875             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10876                 return false;
10877             }
10878             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10879                 return false;
10880             }
10881             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10882                 return false;
10883             }
10884             t2.reRoot( t2.getNode( "AB" ) );
10885             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10886                 return false;
10887             }
10888             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10889                 return false;
10890             }
10891             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10892                 return false;
10893             }
10894             t2.reRoot( t2.getNode( "D" ) );
10895             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10896                 return false;
10897             }
10898             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10899                 return false;
10900             }
10901             t2.reRoot( t2.getNode( "ABC" ) );
10902             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10903                 return false;
10904             }
10905             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10906                 return false;
10907             }
10908             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10909                                                  new NHXParser() )[ 0 ];
10910             t3.reRoot( t3.getNode( "B" ) );
10911             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10912                 return false;
10913             }
10914             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10915                 return false;
10916             }
10917             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10918                 return false;
10919             }
10920             t3.reRoot( t3.getNode( "B" ) );
10921             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10922                 return false;
10923             }
10924             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10925                 return false;
10926             }
10927             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10928                 return false;
10929             }
10930             t3.reRoot( t3.getRoot() );
10931             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10932                 return false;
10933             }
10934             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10935                 return false;
10936             }
10937             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10938                 return false;
10939             }
10940         }
10941         catch ( final Exception e ) {
10942             e.printStackTrace( System.out );
10943             return false;
10944         }
10945         return true;
10946     }
10947
10948     private static boolean testSDIse() {
10949         try {
10950             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10951             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10952             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10953             gene1.setRooted( true );
10954             species1.setRooted( true );
10955             final SDI sdi = new SDI( gene1, species1 );
10956             if ( !gene1.getRoot().isDuplication() ) {
10957                 return false;
10958             }
10959             final Phylogeny species2 = factory
10960                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10961                              new NHXParser() )[ 0 ];
10962             final Phylogeny gene2 = factory
10963                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10964                              new NHXParser() )[ 0 ];
10965             species2.setRooted( true );
10966             gene2.setRooted( true );
10967             final SDI sdi2 = new SDI( gene2, species2 );
10968             if ( sdi2.getDuplicationsSum() != 0 ) {
10969                 return false;
10970             }
10971             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10972                 return false;
10973             }
10974             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10975                 return false;
10976             }
10977             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10978                 return false;
10979             }
10980             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10981                 return false;
10982             }
10983             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10984                 return false;
10985             }
10986             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10987                 return false;
10988             }
10989             final Phylogeny species3 = factory
10990                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10991                              new NHXParser() )[ 0 ];
10992             final Phylogeny gene3 = factory
10993                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10994                              new NHXParser() )[ 0 ];
10995             species3.setRooted( true );
10996             gene3.setRooted( true );
10997             final SDI sdi3 = new SDI( gene3, species3 );
10998             if ( sdi3.getDuplicationsSum() != 1 ) {
10999                 return false;
11000             }
11001             if ( !gene3.getNode( "aa" ).isDuplication() ) {
11002                 return false;
11003             }
11004             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
11005                 return false;
11006             }
11007             final Phylogeny species4 = factory
11008                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11009                              new NHXParser() )[ 0 ];
11010             final Phylogeny gene4 = factory
11011                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11012                              new NHXParser() )[ 0 ];
11013             species4.setRooted( true );
11014             gene4.setRooted( true );
11015             final SDI sdi4 = new SDI( gene4, species4 );
11016             if ( sdi4.getDuplicationsSum() != 1 ) {
11017                 return false;
11018             }
11019             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
11020                 return false;
11021             }
11022             if ( !gene4.getNode( "abc" ).isDuplication() ) {
11023                 return false;
11024             }
11025             if ( gene4.getNode( "abcd" ).isDuplication() ) {
11026                 return false;
11027             }
11028             if ( species4.getNumberOfExternalNodes() != 6 ) {
11029                 return false;
11030             }
11031             if ( gene4.getNumberOfExternalNodes() != 6 ) {
11032                 return false;
11033             }
11034             final Phylogeny species5 = factory
11035                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11036                              new NHXParser() )[ 0 ];
11037             final Phylogeny gene5 = factory
11038                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11039                              new NHXParser() )[ 0 ];
11040             species5.setRooted( true );
11041             gene5.setRooted( true );
11042             final SDI sdi5 = new SDI( gene5, species5 );
11043             if ( sdi5.getDuplicationsSum() != 2 ) {
11044                 return false;
11045             }
11046             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
11047                 return false;
11048             }
11049             if ( !gene5.getNode( "adc" ).isDuplication() ) {
11050                 return false;
11051             }
11052             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
11053                 return false;
11054             }
11055             if ( species5.getNumberOfExternalNodes() != 6 ) {
11056                 return false;
11057             }
11058             if ( gene5.getNumberOfExternalNodes() != 6 ) {
11059                 return false;
11060             }
11061             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
11062             // Conjecture for Comparing Molecular Phylogenies"
11063             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
11064             final Phylogeny species6 = factory
11065                     .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,"
11066                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11067                             new NHXParser() )[ 0 ];
11068             final Phylogeny gene6 = factory
11069                     .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,"
11070                             + "((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,"
11071                             + "(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;",
11072                             new NHXParser() )[ 0 ];
11073             species6.setRooted( true );
11074             gene6.setRooted( true );
11075             final SDI sdi6 = new SDI( gene6, species6 );
11076             if ( sdi6.getDuplicationsSum() != 3 ) {
11077                 return false;
11078             }
11079             if ( !gene6.getNode( "r" ).isDuplication() ) {
11080                 return false;
11081             }
11082             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
11083                 return false;
11084             }
11085             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
11086                 return false;
11087             }
11088             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
11089                 return false;
11090             }
11091             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
11092                 return false;
11093             }
11094             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
11095                 return false;
11096             }
11097             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
11098                 return false;
11099             }
11100             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
11101                 return false;
11102             }
11103             sdi6.computeMappingCostL();
11104             if ( sdi6.computeMappingCostL() != 17 ) {
11105                 return false;
11106             }
11107             if ( species6.getNumberOfExternalNodes() != 9 ) {
11108                 return false;
11109             }
11110             if ( gene6.getNumberOfExternalNodes() != 9 ) {
11111                 return false;
11112             }
11113             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
11114                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
11115                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
11116                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
11117                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
11118             species7.setRooted( true );
11119             final Phylogeny gene7_1 = Test
11120                     .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])" );
11121             gene7_1.setRooted( true );
11122             final SDI sdi7 = new SDI( gene7_1, species7 );
11123             if ( sdi7.getDuplicationsSum() != 0 ) {
11124                 return false;
11125             }
11126             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
11127                 return false;
11128             }
11129             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
11130                 return false;
11131             }
11132             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
11133                 return false;
11134             }
11135             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
11136                 return false;
11137             }
11138             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
11139                 return false;
11140             }
11141             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
11142                 return false;
11143             }
11144             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
11145                 return false;
11146             }
11147             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
11148                 return false;
11149             }
11150             final Phylogeny gene7_2 = Test
11151                     .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])" );
11152             gene7_2.setRooted( true );
11153             final SDI sdi7_2 = new SDI( gene7_2, species7 );
11154             if ( sdi7_2.getDuplicationsSum() != 1 ) {
11155                 return false;
11156             }
11157             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
11158                 return false;
11159             }
11160             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
11161                 return false;
11162             }
11163             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
11164                 return false;
11165             }
11166             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
11167                 return false;
11168             }
11169             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
11170                 return false;
11171             }
11172             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
11173                 return false;
11174             }
11175             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
11176                 return false;
11177             }
11178             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
11179                 return false;
11180             }
11181             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
11182                 return false;
11183             }
11184         }
11185         catch ( final Exception e ) {
11186             return false;
11187         }
11188         return true;
11189     }
11190
11191     private static boolean testSDIunrooted() {
11192         try {
11193             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11194             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
11195             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
11196             final Iterator<PhylogenyBranch> iter = l.iterator();
11197             PhylogenyBranch br = iter.next();
11198             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
11199                 return false;
11200             }
11201             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
11202                 return false;
11203             }
11204             br = iter.next();
11205             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11206                 return false;
11207             }
11208             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11209                 return false;
11210             }
11211             br = iter.next();
11212             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
11213                 return false;
11214             }
11215             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
11216                 return false;
11217             }
11218             br = iter.next();
11219             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11220                 return false;
11221             }
11222             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11223                 return false;
11224             }
11225             br = iter.next();
11226             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11227                 return false;
11228             }
11229             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11230                 return false;
11231             }
11232             br = iter.next();
11233             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11234                 return false;
11235             }
11236             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11237                 return false;
11238             }
11239             br = iter.next();
11240             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11241                 return false;
11242             }
11243             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11244                 return false;
11245             }
11246             br = iter.next();
11247             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11248                 return false;
11249             }
11250             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11251                 return false;
11252             }
11253             br = iter.next();
11254             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11255                 return false;
11256             }
11257             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11258                 return false;
11259             }
11260             br = iter.next();
11261             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11262                 return false;
11263             }
11264             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11265                 return false;
11266             }
11267             br = iter.next();
11268             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11269                 return false;
11270             }
11271             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11272                 return false;
11273             }
11274             br = iter.next();
11275             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
11276                 return false;
11277             }
11278             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
11279                 return false;
11280             }
11281             br = iter.next();
11282             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11283                 return false;
11284             }
11285             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11286                 return false;
11287             }
11288             br = iter.next();
11289             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
11290                 return false;
11291             }
11292             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
11293                 return false;
11294             }
11295             br = iter.next();
11296             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
11297                 return false;
11298             }
11299             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
11300                 return false;
11301             }
11302             if ( iter.hasNext() ) {
11303                 return false;
11304             }
11305             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
11306             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
11307             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
11308             br = iter1.next();
11309             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11310                 return false;
11311             }
11312             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11313                 return false;
11314             }
11315             br = iter1.next();
11316             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11317                 return false;
11318             }
11319             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11320                 return false;
11321             }
11322             br = iter1.next();
11323             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11324                 return false;
11325             }
11326             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11327                 return false;
11328             }
11329             if ( iter1.hasNext() ) {
11330                 return false;
11331             }
11332             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
11333             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
11334             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
11335             br = iter2.next();
11336             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11337                 return false;
11338             }
11339             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11340                 return false;
11341             }
11342             br = iter2.next();
11343             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11344                 return false;
11345             }
11346             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11347                 return false;
11348             }
11349             br = iter2.next();
11350             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11351                 return false;
11352             }
11353             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11354                 return false;
11355             }
11356             if ( iter2.hasNext() ) {
11357                 return false;
11358             }
11359             final Phylogeny species0 = factory
11360                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11361                              new NHXParser() )[ 0 ];
11362             final Phylogeny gene1 = factory
11363                     .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])",
11364                              new NHXParser() )[ 0 ];
11365             species0.setRooted( true );
11366             gene1.setRooted( true );
11367             final SDIR sdi_unrooted = new SDIR();
11368             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
11369             if ( sdi_unrooted.getCount() != 1 ) {
11370                 return false;
11371             }
11372             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
11373                 return false;
11374             }
11375             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
11376                 return false;
11377             }
11378             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
11379                 return false;
11380             }
11381             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11382                 return false;
11383             }
11384             final Phylogeny gene2 = factory
11385                     .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])",
11386                              new NHXParser() )[ 0 ];
11387             gene2.setRooted( true );
11388             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
11389             if ( sdi_unrooted.getCount() != 1 ) {
11390                 return false;
11391             }
11392             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11393                 return false;
11394             }
11395             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11396                 return false;
11397             }
11398             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
11399                 return false;
11400             }
11401             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11402                 return false;
11403             }
11404             final Phylogeny species6 = factory
11405                     .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,"
11406                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11407                             new NHXParser() )[ 0 ];
11408             final Phylogeny gene6 = factory
11409                     .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],"
11410                             + "(((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],"
11411                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11412                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11413                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11414                             new NHXParser() )[ 0 ];
11415             species6.setRooted( true );
11416             gene6.setRooted( true );
11417             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
11418             if ( sdi_unrooted.getCount() != 1 ) {
11419                 return false;
11420             }
11421             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11422                 return false;
11423             }
11424             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11425                 return false;
11426             }
11427             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11428                 return false;
11429             }
11430             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11431                 return false;
11432             }
11433             if ( !p6[ 0 ].getRoot().isDuplication() ) {
11434                 return false;
11435             }
11436             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11437                 return false;
11438             }
11439             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11440                 return false;
11441             }
11442             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11443                 return false;
11444             }
11445             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11446                 return false;
11447             }
11448             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11449                 return false;
11450             }
11451             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11452                 return false;
11453             }
11454             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11455                 return false;
11456             }
11457             p6 = null;
11458             final Phylogeny species7 = factory
11459                     .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,"
11460                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11461                             new NHXParser() )[ 0 ];
11462             final Phylogeny gene7 = factory
11463                     .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],"
11464                             + "(((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],"
11465                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11466                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11467                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11468                             new NHXParser() )[ 0 ];
11469             species7.setRooted( true );
11470             gene7.setRooted( true );
11471             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11472             if ( sdi_unrooted.getCount() != 1 ) {
11473                 return false;
11474             }
11475             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11476                 return false;
11477             }
11478             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11479                 return false;
11480             }
11481             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11482                 return false;
11483             }
11484             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11485                 return false;
11486             }
11487             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11488                 return false;
11489             }
11490             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11491                 return false;
11492             }
11493             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11494                 return false;
11495             }
11496             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11497                 return false;
11498             }
11499             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11500                 return false;
11501             }
11502             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11503                 return false;
11504             }
11505             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11506                 return false;
11507             }
11508             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11509                 return false;
11510             }
11511             p7 = null;
11512             final Phylogeny species8 = factory
11513                     .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,"
11514                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11515                             new NHXParser() )[ 0 ];
11516             final Phylogeny gene8 = factory
11517                     .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],"
11518                             + "(((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],"
11519                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11520                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11521                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11522                             new NHXParser() )[ 0 ];
11523             species8.setRooted( true );
11524             gene8.setRooted( true );
11525             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11526             if ( sdi_unrooted.getCount() != 1 ) {
11527                 return false;
11528             }
11529             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11530                 return false;
11531             }
11532             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11533                 return false;
11534             }
11535             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11536                 return false;
11537             }
11538             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11539                 return false;
11540             }
11541             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11542                 return false;
11543             }
11544             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11545                 return false;
11546             }
11547             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11548                 return false;
11549             }
11550             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11551                 return false;
11552             }
11553             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11554                 return false;
11555             }
11556             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11557                 return false;
11558             }
11559             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11560                 return false;
11561             }
11562             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11563                 return false;
11564             }
11565             p8 = null;
11566         }
11567         catch ( final Exception e ) {
11568             e.printStackTrace( System.out );
11569             return false;
11570         }
11571         return true;
11572     }
11573
11574     private static boolean testSequenceDbWsTools1() {
11575         try {
11576             final PhylogenyNode n = new PhylogenyNode();
11577             n.setName( "NP_001025424" );
11578             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11579             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11580                     || !acc.getValue().equals( "NP_001025424" ) ) {
11581                 return false;
11582             }
11583             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11584             acc = SequenceDbWsTools.obtainSeqAccession( n );
11585             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11586                     || !acc.getValue().equals( "NP_001025424" ) ) {
11587                 return false;
11588             }
11589             n.setName( "NP_001025424.1" );
11590             acc = SequenceDbWsTools.obtainSeqAccession( n );
11591             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11592                     || !acc.getValue().equals( "NP_001025424" ) ) {
11593                 return false;
11594             }
11595             n.setName( "NM_001030253" );
11596             acc = SequenceDbWsTools.obtainSeqAccession( n );
11597             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11598                     || !acc.getValue().equals( "NM_001030253" ) ) {
11599                 return false;
11600             }
11601             n.setName( "BCL2_HUMAN" );
11602             acc = SequenceDbWsTools.obtainSeqAccession( n );
11603             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11604                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11605                 System.out.println( acc.toString() );
11606                 return false;
11607             }
11608             n.setName( "P10415" );
11609             acc = SequenceDbWsTools.obtainSeqAccession( n );
11610             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11611                     || !acc.getValue().equals( "P10415" ) ) {
11612                 System.out.println( acc.toString() );
11613                 return false;
11614             }
11615             n.setName( " P10415 " );
11616             acc = SequenceDbWsTools.obtainSeqAccession( n );
11617             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11618                     || !acc.getValue().equals( "P10415" ) ) {
11619                 System.out.println( acc.toString() );
11620                 return false;
11621             }
11622             n.setName( "_P10415|" );
11623             acc = SequenceDbWsTools.obtainSeqAccession( n );
11624             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11625                     || !acc.getValue().equals( "P10415" ) ) {
11626                 System.out.println( acc.toString() );
11627                 return false;
11628             }
11629             n.setName( "AY695820" );
11630             acc = SequenceDbWsTools.obtainSeqAccession( n );
11631             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11632                     || !acc.getValue().equals( "AY695820" ) ) {
11633                 System.out.println( acc.toString() );
11634                 return false;
11635             }
11636             n.setName( "_AY695820_" );
11637             acc = SequenceDbWsTools.obtainSeqAccession( n );
11638             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11639                     || !acc.getValue().equals( "AY695820" ) ) {
11640                 System.out.println( acc.toString() );
11641                 return false;
11642             }
11643             n.setName( "AAA59452" );
11644             acc = SequenceDbWsTools.obtainSeqAccession( n );
11645             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11646                     || !acc.getValue().equals( "AAA59452" ) ) {
11647                 System.out.println( acc.toString() );
11648                 return false;
11649             }
11650             n.setName( "_AAA59452_" );
11651             acc = SequenceDbWsTools.obtainSeqAccession( n );
11652             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11653                     || !acc.getValue().equals( "AAA59452" ) ) {
11654                 System.out.println( acc.toString() );
11655                 return false;
11656             }
11657             n.setName( "AAA59452.1" );
11658             acc = SequenceDbWsTools.obtainSeqAccession( n );
11659             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11660                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11661                 System.out.println( acc.toString() );
11662                 return false;
11663             }
11664             n.setName( "_AAA59452.1_" );
11665             acc = SequenceDbWsTools.obtainSeqAccession( n );
11666             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11667                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11668                 System.out.println( acc.toString() );
11669                 return false;
11670             }
11671             n.setName( "GI:94894583" );
11672             acc = SequenceDbWsTools.obtainSeqAccession( n );
11673             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11674                     || !acc.getValue().equals( "94894583" ) ) {
11675                 System.out.println( acc.toString() );
11676                 return false;
11677             }
11678             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11679             acc = SequenceDbWsTools.obtainSeqAccession( n );
11680             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11681                     || !acc.getValue().equals( "71845847" ) ) {
11682                 System.out.println( acc.toString() );
11683                 return false;
11684             }
11685             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11686             acc = SequenceDbWsTools.obtainSeqAccession( n );
11687             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11688                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11689                 System.out.println( acc.toString() );
11690                 return false;
11691             }
11692         }
11693         catch ( final Exception e ) {
11694             return false;
11695         }
11696         return true;
11697     }
11698
11699     private static boolean testSequenceDbWsTools2() {
11700         try {
11701             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11702             SequenceDbWsTools.obtainSeqInformation( n1 );
11703             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11704                 return false;
11705             }
11706             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11707                 return false;
11708             }
11709             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11710                 return false;
11711             }
11712             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11713                 return false;
11714             }
11715             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11716             SequenceDbWsTools.obtainSeqInformation( n2 );
11717             if ( !n2.getNodeData().getSequence().getName().equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
11718                 return false;
11719             }
11720             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11721                 return false;
11722             }
11723             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11724                 return false;
11725             }
11726             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11727                 return false;
11728             }
11729             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11730             SequenceDbWsTools.obtainSeqInformation( n3 );
11731             if ( !n3.getNodeData().getSequence().getName()
11732                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11733                 return false;
11734             }
11735             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11736                 return false;
11737             }
11738             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11739                 return false;
11740             }
11741             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11742                 return false;
11743             }
11744         }
11745         catch ( final IOException e ) {
11746             System.out.println();
11747             System.out.println( "the following might be due to absence internet connection:" );
11748             e.printStackTrace( System.out );
11749             return true;
11750         }
11751         catch ( final Exception e ) {
11752             e.printStackTrace();
11753             return false;
11754         }
11755         return true;
11756     }
11757
11758     private static boolean testSequenceIdParsing() {
11759         try {
11760             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11761             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11762                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11763                 if ( id != null ) {
11764                     System.out.println( "value   =" + id.getValue() );
11765                     System.out.println( "provider=" + id.getSource() );
11766                 }
11767                 return false;
11768             }
11769             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11770             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11771                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11772                 if ( id != null ) {
11773                     System.out.println( "value   =" + id.getValue() );
11774                     System.out.println( "provider=" + id.getSource() );
11775                 }
11776                 return false;
11777             }
11778             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11779             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11780                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11781                 if ( id != null ) {
11782                     System.out.println( "value   =" + id.getValue() );
11783                     System.out.println( "provider=" + id.getSource() );
11784                 }
11785                 return false;
11786             }
11787             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11788             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11789                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11790                 if ( id != null ) {
11791                     System.out.println( "value   =" + id.getValue() );
11792                     System.out.println( "provider=" + id.getSource() );
11793                 }
11794                 return false;
11795             }
11796             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11797             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11798                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11799                 if ( id != null ) {
11800                     System.out.println( "value   =" + id.getValue() );
11801                     System.out.println( "provider=" + id.getSource() );
11802                 }
11803                 return false;
11804             }
11805             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11806             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11807                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11808                 if ( id != null ) {
11809                     System.out.println( "value   =" + id.getValue() );
11810                     System.out.println( "provider=" + id.getSource() );
11811                 }
11812                 return false;
11813             }
11814             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11815             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11816                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11817                 if ( id != null ) {
11818                     System.out.println( "value   =" + id.getValue() );
11819                     System.out.println( "provider=" + id.getSource() );
11820                 }
11821                 return false;
11822             }
11823             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11824             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11825                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11826                 if ( id != null ) {
11827                     System.out.println( "value   =" + id.getValue() );
11828                     System.out.println( "provider=" + id.getSource() );
11829                 }
11830                 return false;
11831             }
11832             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11833             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11834                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11835                 if ( id != null ) {
11836                     System.out.println( "value   =" + id.getValue() );
11837                     System.out.println( "provider=" + id.getSource() );
11838                 }
11839                 return false;
11840             }
11841             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11842             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11843                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11844                 if ( id != null ) {
11845                     System.out.println( "value   =" + id.getValue() );
11846                     System.out.println( "provider=" + id.getSource() );
11847                 }
11848                 return false;
11849             }
11850             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11851             if ( id != null ) {
11852                 System.out.println( "value   =" + id.getValue() );
11853                 System.out.println( "provider=" + id.getSource() );
11854                 return false;
11855             }
11856             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
11857             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11858                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
11859                 if ( id != null ) {
11860                     System.out.println( "value   =" + id.getValue() );
11861                     System.out.println( "provider=" + id.getSource() );
11862                 }
11863                 return false;
11864             }
11865             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
11866             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11867                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11868                 if ( id != null ) {
11869                     System.out.println( "value   =" + id.getValue() );
11870                     System.out.println( "provider=" + id.getSource() );
11871                 }
11872                 return false;
11873             }
11874             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
11875             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11876                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11877                 if ( id != null ) {
11878                     System.out.println( "value   =" + id.getValue() );
11879                     System.out.println( "provider=" + id.getSource() );
11880                 }
11881                 return false;
11882             }
11883             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
11884             if ( id != null ) {
11885                 System.out.println( "value   =" + id.getValue() );
11886                 System.out.println( "provider=" + id.getSource() );
11887                 return false;
11888             }
11889         }
11890         catch ( final Exception e ) {
11891             e.printStackTrace( System.out );
11892             return false;
11893         }
11894         return true;
11895     }
11896
11897     private static boolean testSequenceWriter() {
11898         try {
11899             final String n = ForesterUtil.LINE_SEPARATOR;
11900             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11901                 return false;
11902             }
11903             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11904                 return false;
11905             }
11906             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11907                 return false;
11908             }
11909             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11910                 return false;
11911             }
11912             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11913                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11914                 return false;
11915             }
11916             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11917                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11918                 return false;
11919             }
11920         }
11921         catch ( final Exception e ) {
11922             e.printStackTrace();
11923             return false;
11924         }
11925         return true;
11926     }
11927
11928     private static boolean testSpecies() {
11929         try {
11930             final Species s1 = new BasicSpecies( "a" );
11931             final Species s2 = new BasicSpecies( "a" );
11932             final Species s3 = new BasicSpecies( "A" );
11933             final Species s4 = new BasicSpecies( "b" );
11934             if ( !s1.equals( s1 ) ) {
11935                 return false;
11936             }
11937             if ( s1.getSpeciesId().equals( "x" ) ) {
11938                 return false;
11939             }
11940             if ( s1.getSpeciesId().equals( null ) ) {
11941                 return false;
11942             }
11943             if ( !s1.equals( s2 ) ) {
11944                 return false;
11945             }
11946             if ( s1.equals( s3 ) ) {
11947                 return false;
11948             }
11949             if ( s1.hashCode() != s1.hashCode() ) {
11950                 return false;
11951             }
11952             if ( s1.hashCode() != s2.hashCode() ) {
11953                 return false;
11954             }
11955             if ( s1.hashCode() == s3.hashCode() ) {
11956                 return false;
11957             }
11958             if ( s1.compareTo( s1 ) != 0 ) {
11959                 return false;
11960             }
11961             if ( s1.compareTo( s2 ) != 0 ) {
11962                 return false;
11963             }
11964             if ( s1.compareTo( s3 ) != 0 ) {
11965                 return false;
11966             }
11967             if ( s1.compareTo( s4 ) >= 0 ) {
11968                 return false;
11969             }
11970             if ( s4.compareTo( s1 ) <= 0 ) {
11971                 return false;
11972             }
11973             if ( !s4.getSpeciesId().equals( "b" ) ) {
11974                 return false;
11975             }
11976             final Species s5 = new BasicSpecies( " C " );
11977             if ( !s5.getSpeciesId().equals( "C" ) ) {
11978                 return false;
11979             }
11980             if ( s5.equals( s1 ) ) {
11981                 return false;
11982             }
11983         }
11984         catch ( final Exception e ) {
11985             e.printStackTrace( System.out );
11986             return false;
11987         }
11988         return true;
11989     }
11990
11991     private static boolean testSplit() {
11992         try {
11993             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11994             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11995             //Archaeopteryx.createApplication( p0 );
11996             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11997             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11998             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11999             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12000             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12001             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12002             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12003             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12004             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12005             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12006             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
12007             // System.out.println( s0.toString() );
12008             //
12009             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12010             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12011             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12012             if ( s0.match( query_nodes ) ) {
12013                 return false;
12014             }
12015             query_nodes = new HashSet<PhylogenyNode>();
12016             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12017             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12018             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12019             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12020             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12023             if ( !s0.match( query_nodes ) ) {
12024                 return false;
12025             }
12026             //
12027             query_nodes = new HashSet<PhylogenyNode>();
12028             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12029             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12030             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12031             if ( !s0.match( query_nodes ) ) {
12032                 return false;
12033             }
12034             //
12035             query_nodes = new HashSet<PhylogenyNode>();
12036             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12037             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12040             if ( !s0.match( query_nodes ) ) {
12041                 return false;
12042             }
12043             //
12044             query_nodes = new HashSet<PhylogenyNode>();
12045             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12046             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12048             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12049             if ( !s0.match( query_nodes ) ) {
12050                 return false;
12051             }
12052             //
12053             query_nodes = new HashSet<PhylogenyNode>();
12054             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12055             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12056             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12057             if ( !s0.match( query_nodes ) ) {
12058                 return false;
12059             }
12060             query_nodes = new HashSet<PhylogenyNode>();
12061             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12062             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12063             if ( !s0.match( query_nodes ) ) {
12064                 return false;
12065             }
12066             query_nodes = new HashSet<PhylogenyNode>();
12067             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12068             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12069             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12070             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12071             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12072             if ( !s0.match( query_nodes ) ) {
12073                 return false;
12074             }
12075             query_nodes = new HashSet<PhylogenyNode>();
12076             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12077             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12078             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12079             if ( !s0.match( query_nodes ) ) {
12080                 return false;
12081             }
12082             query_nodes = new HashSet<PhylogenyNode>();
12083             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12084             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12085             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12086             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12087             if ( !s0.match( query_nodes ) ) {
12088                 return false;
12089             }
12090             query_nodes = new HashSet<PhylogenyNode>();
12091             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12092             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12093             if ( s0.match( query_nodes ) ) {
12094                 return false;
12095             }
12096             query_nodes = new HashSet<PhylogenyNode>();
12097             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12098             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12099             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12100             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12101             if ( s0.match( query_nodes ) ) {
12102                 return false;
12103             }
12104             query_nodes = new HashSet<PhylogenyNode>();
12105             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12106             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12107             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12108             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12109             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12110             if ( s0.match( query_nodes ) ) {
12111                 return false;
12112             }
12113             query_nodes = new HashSet<PhylogenyNode>();
12114             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12115             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12116             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12117             if ( s0.match( query_nodes ) ) {
12118                 return false;
12119             }
12120             query_nodes = new HashSet<PhylogenyNode>();
12121             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12122             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12123             if ( s0.match( query_nodes ) ) {
12124                 return false;
12125             }
12126             query_nodes = new HashSet<PhylogenyNode>();
12127             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12128             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12129             if ( s0.match( query_nodes ) ) {
12130                 return false;
12131             }
12132             query_nodes = new HashSet<PhylogenyNode>();
12133             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12134             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12135             if ( s0.match( query_nodes ) ) {
12136                 return false;
12137             }
12138             query_nodes = new HashSet<PhylogenyNode>();
12139             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12140             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12141             if ( s0.match( query_nodes ) ) {
12142                 return false;
12143             }
12144             query_nodes = new HashSet<PhylogenyNode>();
12145             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12146             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12147             if ( s0.match( query_nodes ) ) {
12148                 return false;
12149             }
12150             query_nodes = new HashSet<PhylogenyNode>();
12151             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12152             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12153             if ( s0.match( query_nodes ) ) {
12154                 return false;
12155             }
12156             query_nodes = new HashSet<PhylogenyNode>();
12157             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12158             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12159             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12160             if ( s0.match( query_nodes ) ) {
12161                 return false;
12162             }
12163             query_nodes = new HashSet<PhylogenyNode>();
12164             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12165             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12166             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12167             if ( s0.match( query_nodes ) ) {
12168                 return false;
12169             }
12170             query_nodes = new HashSet<PhylogenyNode>();
12171             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12172             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12173             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12174             if ( s0.match( query_nodes ) ) {
12175                 return false;
12176             }
12177             query_nodes = new HashSet<PhylogenyNode>();
12178             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12179             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12180             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12181             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12182             if ( s0.match( query_nodes ) ) {
12183                 return false;
12184             }
12185             /////////
12186             //            query_nodes = new HashSet<PhylogenyNode>();
12187             //            query_nodes.add( new PhylogenyNode( "X" ) );
12188             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12189             //            query_nodes.add( new PhylogenyNode( "A" ) );
12190             //            query_nodes.add( new PhylogenyNode( "B" ) );
12191             //            query_nodes.add( new PhylogenyNode( "C" ) );
12192             //            query_nodes.add( new PhylogenyNode( "D" ) );
12193             //            query_nodes.add( new PhylogenyNode( "E" ) );
12194             //            query_nodes.add( new PhylogenyNode( "F" ) );
12195             //            query_nodes.add( new PhylogenyNode( "G" ) );
12196             //            if ( !s0.match( query_nodes ) ) {
12197             //                return false;
12198             //            }
12199             //            query_nodes = new HashSet<PhylogenyNode>();
12200             //            query_nodes.add( new PhylogenyNode( "X" ) );
12201             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12202             //            query_nodes.add( new PhylogenyNode( "A" ) );
12203             //            query_nodes.add( new PhylogenyNode( "B" ) );
12204             //            query_nodes.add( new PhylogenyNode( "C" ) );
12205             //            if ( !s0.match( query_nodes ) ) {
12206             //                return false;
12207             //            }
12208             //            //
12209             //            query_nodes = new HashSet<PhylogenyNode>();
12210             //            query_nodes.add( new PhylogenyNode( "X" ) );
12211             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12212             //            query_nodes.add( new PhylogenyNode( "D" ) );
12213             //            query_nodes.add( new PhylogenyNode( "E" ) );
12214             //            query_nodes.add( new PhylogenyNode( "F" ) );
12215             //            query_nodes.add( new PhylogenyNode( "G" ) );
12216             //            if ( !s0.match( query_nodes ) ) {
12217             //                return false;
12218             //            }
12219             //            //
12220             //            query_nodes = new HashSet<PhylogenyNode>();
12221             //            query_nodes.add( new PhylogenyNode( "X" ) );
12222             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12223             //            query_nodes.add( new PhylogenyNode( "A" ) );
12224             //            query_nodes.add( new PhylogenyNode( "B" ) );
12225             //            query_nodes.add( new PhylogenyNode( "C" ) );
12226             //            query_nodes.add( new PhylogenyNode( "D" ) );
12227             //            if ( !s0.match( query_nodes ) ) {
12228             //                return false;
12229             //            }
12230             //            //
12231             //            query_nodes = new HashSet<PhylogenyNode>();
12232             //            query_nodes.add( new PhylogenyNode( "X" ) );
12233             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12234             //            query_nodes.add( new PhylogenyNode( "E" ) );
12235             //            query_nodes.add( new PhylogenyNode( "F" ) );
12236             //            query_nodes.add( new PhylogenyNode( "G" ) );
12237             //            if ( !s0.match( query_nodes ) ) {
12238             //                return false;
12239             //            }
12240             //            //
12241             //            query_nodes = new HashSet<PhylogenyNode>();
12242             //            query_nodes.add( new PhylogenyNode( "X" ) );
12243             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12244             //            query_nodes.add( new PhylogenyNode( "F" ) );
12245             //            query_nodes.add( new PhylogenyNode( "G" ) );
12246             //            if ( !s0.match( query_nodes ) ) {
12247             //                return false;
12248             //            }
12249             //
12250             query_nodes = new HashSet<PhylogenyNode>();
12251             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12252             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12253             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12254             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12255             if ( s0.match( query_nodes ) ) {
12256                 return false;
12257             }
12258             //
12259             query_nodes = new HashSet<PhylogenyNode>();
12260             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12261             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12262             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12263             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12264             if ( s0.match( query_nodes ) ) {
12265                 return false;
12266             }
12267             ///////////////////////////
12268             //
12269             query_nodes = new HashSet<PhylogenyNode>();
12270             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12271             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12272             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12273             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12274             if ( s0.match( query_nodes ) ) {
12275                 return false;
12276             }
12277             //
12278             query_nodes = new HashSet<PhylogenyNode>();
12279             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12280             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12281             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12282             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12283             if ( s0.match( query_nodes ) ) {
12284                 return false;
12285             }
12286             //
12287             query_nodes = new HashSet<PhylogenyNode>();
12288             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12289             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12290             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12291             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12292             if ( s0.match( query_nodes ) ) {
12293                 return false;
12294             }
12295             //
12296             query_nodes = new HashSet<PhylogenyNode>();
12297             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12298             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12299             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12300             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12301             if ( s0.match( query_nodes ) ) {
12302                 return false;
12303             }
12304             //
12305             query_nodes = new HashSet<PhylogenyNode>();
12306             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12307             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12308             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12309             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12310             if ( s0.match( query_nodes ) ) {
12311                 return false;
12312             }
12313             //
12314             query_nodes = new HashSet<PhylogenyNode>();
12315             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12316             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12317             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12318             if ( s0.match( query_nodes ) ) {
12319                 return false;
12320             }
12321             //
12322             query_nodes = new HashSet<PhylogenyNode>();
12323             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12324             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12325             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12326             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12327             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12328             if ( s0.match( query_nodes ) ) {
12329                 return false;
12330             }
12331             //
12332             query_nodes = new HashSet<PhylogenyNode>();
12333             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12334             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12335             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12336             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12337             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12338             if ( s0.match( query_nodes ) ) {
12339                 return false;
12340             }
12341             //
12342             query_nodes = new HashSet<PhylogenyNode>();
12343             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12344             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12345             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12346             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12347             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12348             if ( s0.match( query_nodes ) ) {
12349                 return false;
12350             }
12351             //
12352             query_nodes = new HashSet<PhylogenyNode>();
12353             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12354             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12355             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12356             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12357             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12358             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12359             if ( s0.match( query_nodes ) ) {
12360                 return false;
12361             }
12362         }
12363         catch ( final Exception e ) {
12364             e.printStackTrace();
12365             return false;
12366         }
12367         return true;
12368     }
12369
12370     private static boolean testSplitStrict() {
12371         try {
12372             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12373             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12374             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
12375             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12376             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12377             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12378             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12379             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12380             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12381             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12382             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
12383             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12384             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12385             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12386             if ( s0.match( query_nodes ) ) {
12387                 return false;
12388             }
12389             query_nodes = new HashSet<PhylogenyNode>();
12390             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12391             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12392             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12393             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12394             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12395             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12396             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12397             if ( !s0.match( query_nodes ) ) {
12398                 return false;
12399             }
12400             //
12401             query_nodes = new HashSet<PhylogenyNode>();
12402             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12403             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12404             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12405             if ( !s0.match( query_nodes ) ) {
12406                 return false;
12407             }
12408             //
12409             query_nodes = new HashSet<PhylogenyNode>();
12410             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12411             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12412             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12413             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12414             if ( !s0.match( query_nodes ) ) {
12415                 return false;
12416             }
12417             //
12418             query_nodes = new HashSet<PhylogenyNode>();
12419             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12420             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12421             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12422             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12423             if ( !s0.match( query_nodes ) ) {
12424                 return false;
12425             }
12426             //
12427             query_nodes = new HashSet<PhylogenyNode>();
12428             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12429             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12430             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12431             if ( !s0.match( query_nodes ) ) {
12432                 return false;
12433             }
12434             //
12435             query_nodes = new HashSet<PhylogenyNode>();
12436             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12437             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12438             if ( !s0.match( query_nodes ) ) {
12439                 return false;
12440             }
12441             //
12442             query_nodes = new HashSet<PhylogenyNode>();
12443             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12444             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12445             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12446             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12447             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12448             if ( !s0.match( query_nodes ) ) {
12449                 return false;
12450             }
12451             //
12452             query_nodes = new HashSet<PhylogenyNode>();
12453             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12454             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12455             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12456             if ( !s0.match( query_nodes ) ) {
12457                 return false;
12458             }
12459             //
12460             query_nodes = new HashSet<PhylogenyNode>();
12461             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12462             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12463             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12464             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12465             if ( !s0.match( query_nodes ) ) {
12466                 return false;
12467             }
12468             //
12469             query_nodes = new HashSet<PhylogenyNode>();
12470             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12471             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12472             if ( s0.match( query_nodes ) ) {
12473                 return false;
12474             }
12475             //
12476             query_nodes = new HashSet<PhylogenyNode>();
12477             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12478             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12479             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12480             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12481             if ( s0.match( query_nodes ) ) {
12482                 return false;
12483             }
12484             //
12485             query_nodes = new HashSet<PhylogenyNode>();
12486             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12487             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12488             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12489             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12490             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12491             if ( s0.match( query_nodes ) ) {
12492                 return false;
12493             }
12494             //
12495             query_nodes = new HashSet<PhylogenyNode>();
12496             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12497             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12498             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12499             if ( s0.match( query_nodes ) ) {
12500                 return false;
12501             }
12502             //
12503             query_nodes = new HashSet<PhylogenyNode>();
12504             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12505             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12506             if ( s0.match( query_nodes ) ) {
12507                 return false;
12508             }
12509             //
12510             query_nodes = new HashSet<PhylogenyNode>();
12511             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12512             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12513             if ( s0.match( query_nodes ) ) {
12514                 return false;
12515             }
12516             //
12517             query_nodes = new HashSet<PhylogenyNode>();
12518             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12519             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12520             if ( s0.match( query_nodes ) ) {
12521                 return false;
12522             }
12523             //
12524             query_nodes = new HashSet<PhylogenyNode>();
12525             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12526             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12527             if ( s0.match( query_nodes ) ) {
12528                 return false;
12529             }
12530             //
12531             query_nodes = new HashSet<PhylogenyNode>();
12532             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12533             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12534             if ( s0.match( query_nodes ) ) {
12535                 return false;
12536             }
12537             //
12538             query_nodes = new HashSet<PhylogenyNode>();
12539             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12540             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12541             if ( s0.match( query_nodes ) ) {
12542                 return false;
12543             }
12544             //
12545             query_nodes = new HashSet<PhylogenyNode>();
12546             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12547             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12548             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12549             if ( s0.match( query_nodes ) ) {
12550                 return false;
12551             }
12552             //
12553             query_nodes = new HashSet<PhylogenyNode>();
12554             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12555             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12556             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12557             if ( s0.match( query_nodes ) ) {
12558                 return false;
12559             }
12560             //
12561             query_nodes = new HashSet<PhylogenyNode>();
12562             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12563             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12564             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12565             if ( s0.match( query_nodes ) ) {
12566                 return false;
12567             }
12568             //
12569             query_nodes = new HashSet<PhylogenyNode>();
12570             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12571             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12572             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12573             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12574             if ( s0.match( query_nodes ) ) {
12575                 return false;
12576             }
12577         }
12578         catch ( final Exception e ) {
12579             e.printStackTrace();
12580             return false;
12581         }
12582         return true;
12583     }
12584
12585     private static boolean testSubtreeDeletion() {
12586         try {
12587             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12588             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12589             t1.deleteSubtree( t1.getNode( "A" ), false );
12590             if ( t1.getNumberOfExternalNodes() != 5 ) {
12591                 return false;
12592             }
12593             t1.toNewHampshireX();
12594             t1.deleteSubtree( t1.getNode( "E" ), false );
12595             if ( t1.getNumberOfExternalNodes() != 4 ) {
12596                 return false;
12597             }
12598             t1.toNewHampshireX();
12599             t1.deleteSubtree( t1.getNode( "F" ), false );
12600             if ( t1.getNumberOfExternalNodes() != 3 ) {
12601                 return false;
12602             }
12603             t1.toNewHampshireX();
12604             t1.deleteSubtree( t1.getNode( "D" ), false );
12605             t1.toNewHampshireX();
12606             if ( t1.getNumberOfExternalNodes() != 3 ) {
12607                 return false;
12608             }
12609             t1.deleteSubtree( t1.getNode( "def" ), false );
12610             t1.toNewHampshireX();
12611             if ( t1.getNumberOfExternalNodes() != 2 ) {
12612                 return false;
12613             }
12614             t1.deleteSubtree( t1.getNode( "B" ), false );
12615             t1.toNewHampshireX();
12616             if ( t1.getNumberOfExternalNodes() != 1 ) {
12617                 return false;
12618             }
12619             t1.deleteSubtree( t1.getNode( "C" ), false );
12620             t1.toNewHampshireX();
12621             if ( t1.getNumberOfExternalNodes() != 1 ) {
12622                 return false;
12623             }
12624             t1.deleteSubtree( t1.getNode( "abc" ), false );
12625             t1.toNewHampshireX();
12626             if ( t1.getNumberOfExternalNodes() != 1 ) {
12627                 return false;
12628             }
12629             t1.deleteSubtree( t1.getNode( "r" ), false );
12630             if ( t1.getNumberOfExternalNodes() != 0 ) {
12631                 return false;
12632             }
12633             if ( !t1.isEmpty() ) {
12634                 return false;
12635             }
12636             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12637             t2.deleteSubtree( t2.getNode( "A" ), false );
12638             t2.toNewHampshireX();
12639             if ( t2.getNumberOfExternalNodes() != 5 ) {
12640                 return false;
12641             }
12642             t2.deleteSubtree( t2.getNode( "abc" ), false );
12643             t2.toNewHampshireX();
12644             if ( t2.getNumberOfExternalNodes() != 3 ) {
12645                 return false;
12646             }
12647             t2.deleteSubtree( t2.getNode( "def" ), false );
12648             t2.toNewHampshireX();
12649             if ( t2.getNumberOfExternalNodes() != 1 ) {
12650                 return false;
12651             }
12652         }
12653         catch ( final Exception e ) {
12654             e.printStackTrace( System.out );
12655             return false;
12656         }
12657         return true;
12658     }
12659
12660     private static boolean testSupportCount() {
12661         try {
12662             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12663             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12664             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12665                     + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12666                     + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12667                     + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12668                     + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12669                     new NHXParser() );
12670             SupportCount.count( t0_1, phylogenies_1, true, false );
12671             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12672             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12673                     + "(((((A,B),C),D),E),((F,G),X))"
12674                     + "(((((A,Y),B),C),D),((F,G),E))"
12675                     + "(((((A,B),C),D),E),(F,G))"
12676                     + "(((((A,B),C),D),E),(F,G))"
12677                     + "(((((A,B),C),D),E),(F,G))"
12678                     + "(((((A,B),C),D),E),(F,G),Z)"
12679                     + "(((((A,B),C),D),E),(F,G))"
12680                     + "((((((A,B),C),D),E),F),G)"
12681                     + "(((((X,Y),F,G),E),((A,B),C)),D)",
12682                     new NHXParser() );
12683             SupportCount.count( t0_2, phylogenies_2, true, false );
12684             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12685             while ( it.hasNext() ) {
12686                 final PhylogenyNode n = it.next();
12687                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12688                     return false;
12689                 }
12690             }
12691             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12692             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12693                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12694             SupportCount.count( t0_3, phylogenies_3, true, false );
12695             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12696             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12697                 return false;
12698             }
12699             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12700                 return false;
12701             }
12702             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12703                 return false;
12704             }
12705             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12706                 return false;
12707             }
12708             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12709                 return false;
12710             }
12711             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12712                 return false;
12713             }
12714             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12715                 return false;
12716             }
12717             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12718                 return false;
12719             }
12720             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12721                 return false;
12722             }
12723             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12724                 return false;
12725             }
12726             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12727             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12728                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12729             SupportCount.count( t0_4, phylogenies_4, true, false );
12730             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12731             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12732                 return false;
12733             }
12734             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12735                 return false;
12736             }
12737             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12738                 return false;
12739             }
12740             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12741                 return false;
12742             }
12743             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12744                 return false;
12745             }
12746             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12747                 return false;
12748             }
12749             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12750                 return false;
12751             }
12752             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12753                 return false;
12754             }
12755             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12756                 return false;
12757             }
12758             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12759                 return false;
12760             }
12761             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12762             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12763             double d = SupportCount.compare( b1, a, true, true, true );
12764             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12765                 return false;
12766             }
12767             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12768             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12769             d = SupportCount.compare( b2, a, true, true, true );
12770             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12771                 return false;
12772             }
12773             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12774             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12775             d = SupportCount.compare( b3, a, true, true, true );
12776             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12777                 return false;
12778             }
12779             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12780             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12781             d = SupportCount.compare( b4, a, true, true, false );
12782             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12783                 return false;
12784             }
12785         }
12786         catch ( final Exception e ) {
12787             e.printStackTrace( System.out );
12788             return false;
12789         }
12790         return true;
12791     }
12792
12793     private static boolean testSupportTransfer() {
12794         try {
12795             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12796             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)",
12797                                                  new NHXParser() )[ 0 ];
12798             final Phylogeny p2 = factory
12799                     .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 ];
12800             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12801                 return false;
12802             }
12803             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12804                 return false;
12805             }
12806             support_transfer.moveBranchLengthsToBootstrap( p1 );
12807             support_transfer.transferSupportValues( p1, p2 );
12808             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12809                 return false;
12810             }
12811             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12812                 return false;
12813             }
12814             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12815                 return false;
12816             }
12817             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12818                 return false;
12819             }
12820             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12821                 return false;
12822             }
12823             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12824                 return false;
12825             }
12826             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12827                 return false;
12828             }
12829             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12830                 return false;
12831             }
12832         }
12833         catch ( final Exception e ) {
12834             e.printStackTrace( System.out );
12835             return false;
12836         }
12837         return true;
12838     }
12839
12840     private static boolean testTaxonomyExtraction() {
12841         try {
12842             final PhylogenyNode n0 = PhylogenyNode
12843                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12844             if ( n0.getNodeData().isHasTaxonomy() ) {
12845                 return false;
12846             }
12847             final PhylogenyNode n1 = PhylogenyNode
12848                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12849             if ( n1.getNodeData().isHasTaxonomy() ) {
12850                 System.out.println( n1.toString() );
12851                 return false;
12852             }
12853             final PhylogenyNode n2x = PhylogenyNode
12854                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12855             if ( n2x.getNodeData().isHasTaxonomy() ) {
12856                 return false;
12857             }
12858             final PhylogenyNode n3 = PhylogenyNode
12859                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12860             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12861                 System.out.println( n3.toString() );
12862                 return false;
12863             }
12864             final PhylogenyNode n4 = PhylogenyNode
12865                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12866             if ( n4.getNodeData().isHasTaxonomy() ) {
12867                 System.out.println( n4.toString() );
12868                 return false;
12869             }
12870             final PhylogenyNode n5 = PhylogenyNode
12871                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12872             if ( n5.getNodeData().isHasTaxonomy() ) {
12873                 System.out.println( n5.toString() );
12874                 return false;
12875             }
12876             final PhylogenyNode n6 = PhylogenyNode
12877                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12878             if ( n6.getNodeData().isHasTaxonomy() ) {
12879                 System.out.println( n6.toString() );
12880                 return false;
12881             }
12882             final PhylogenyNode n7 = PhylogenyNode
12883                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12884             if ( n7.getNodeData().isHasTaxonomy() ) {
12885                 System.out.println( n7.toString() );
12886                 return false;
12887             }
12888             final PhylogenyNode n8 = PhylogenyNode
12889                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12890             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12891                 System.out.println( n8.toString() );
12892                 return false;
12893             }
12894             final PhylogenyNode n9 = PhylogenyNode
12895                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12896             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12897                 System.out.println( n9.toString() );
12898                 return false;
12899             }
12900             final PhylogenyNode n10x = PhylogenyNode
12901                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12902             if ( n10x.getNodeData().isHasTaxonomy() ) {
12903                 System.out.println( n10x.toString() );
12904                 return false;
12905             }
12906             final PhylogenyNode n10xx = PhylogenyNode
12907                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12908             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12909                 System.out.println( n10xx.toString() );
12910                 return false;
12911             }
12912             final PhylogenyNode n10 = PhylogenyNode
12913                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12914             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12915                 System.out.println( n10.toString() );
12916                 return false;
12917             }
12918             final PhylogenyNode n11 = PhylogenyNode
12919                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12920             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12921                 System.out.println( n11.toString() );
12922                 return false;
12923             }
12924             final PhylogenyNode n12 = PhylogenyNode
12925                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12926                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12927             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12928                 System.out.println( n12.toString() );
12929                 return false;
12930             }
12931             final PhylogenyNode n13 = PhylogenyNode
12932                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12933             if ( n13.getNodeData().isHasTaxonomy() ) {
12934                 System.out.println( n13.toString() );
12935                 return false;
12936             }
12937             final PhylogenyNode n14 = PhylogenyNode
12938                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12939             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12940                 System.out.println( n14.toString() );
12941                 return false;
12942             }
12943             final PhylogenyNode n15 = PhylogenyNode
12944                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12945             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12946                 System.out.println( n15.toString() );
12947                 return false;
12948             }
12949             final PhylogenyNode n16 = PhylogenyNode
12950                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12951             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12952                 System.out.println( n16.toString() );
12953                 return false;
12954             }
12955             final PhylogenyNode n17 = PhylogenyNode
12956                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12957             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12958                 System.out.println( n17.toString() );
12959                 return false;
12960             }
12961             final PhylogenyNode n18 = PhylogenyNode
12962                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12963             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12964                 System.out.println( n18.toString() );
12965                 return false;
12966             }
12967             final PhylogenyNode n19 = PhylogenyNode
12968                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12969                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12970             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12971                 System.out.println( n19.toString() );
12972                 return false;
12973             }
12974             final PhylogenyNode n20 = PhylogenyNode
12975                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12976             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12977                 System.out.println( n20.toString() );
12978                 return false;
12979             }
12980             final PhylogenyNode n21 = PhylogenyNode
12981                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12982                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12983             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12984                 System.out.println( n21.toString() );
12985                 return false;
12986             }
12987             final PhylogenyNode n23 = PhylogenyNode
12988                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12989                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12990             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12991                 System.out.println( n23.toString() );
12992                 return false;
12993             }
12994             final PhylogenyNode n24 = PhylogenyNode
12995                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12996             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12997                 System.out.println( n24.toString() );
12998                 return false;
12999             }
13000             //
13001             final PhylogenyNode n25 = PhylogenyNode
13002                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
13003                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13004             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
13005                 System.out.println( n25.toString() );
13006                 return false;
13007             }
13008             final PhylogenyNode n26 = PhylogenyNode
13009                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
13010                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13011             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13012                 System.out.println( n26.toString() );
13013                 return false;
13014             }
13015             final PhylogenyNode n27 = PhylogenyNode
13016                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13017             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13018                 System.out.println( n27.toString() );
13019                 return false;
13020             }
13021         }
13022         catch ( final Exception e ) {
13023             e.printStackTrace( System.out );
13024             return false;
13025         }
13026         return true;
13027     }
13028
13029     private static boolean testTreeCopy() {
13030         try {
13031             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
13032             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
13033             final Phylogeny t1 = t0.copy();
13034             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
13035                 return false;
13036             }
13037             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13038                 return false;
13039             }
13040             t0.deleteSubtree( t0.getNode( "c" ), true );
13041             t0.deleteSubtree( t0.getNode( "a" ), true );
13042             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
13043             t0.getNode( "b" ).setName( "Bee" );
13044             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
13045                 return false;
13046             }
13047             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13048                 return false;
13049             }
13050             t0.deleteSubtree( t0.getNode( "e" ), true );
13051             t0.deleteSubtree( t0.getNode( "Bee" ), true );
13052             t0.deleteSubtree( t0.getNode( "d" ), true );
13053             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13054                 return false;
13055             }
13056         }
13057         catch ( final Exception e ) {
13058             e.printStackTrace();
13059             return false;
13060         }
13061         return true;
13062     }
13063
13064     private static boolean testTreeMethods() {
13065         try {
13066             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13067             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
13068             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
13069             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
13070                 System.out.println( t0.toNewHampshireX() );
13071                 return false;
13072             }
13073             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
13074             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
13075             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
13076                 return false;
13077             }
13078             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
13079                 return false;
13080             }
13081             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
13082                 return false;
13083             }
13084         }
13085         catch ( final Exception e ) {
13086             e.printStackTrace( System.out );
13087             return false;
13088         }
13089         return true;
13090     }
13091
13092     private static boolean testUniprotEntryRetrieval() {
13093         try {
13094             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 5000 );
13095             if ( !entry.getAccession().equals( "P12345" ) ) {
13096                 return false;
13097             }
13098             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
13099                 return false;
13100             }
13101             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
13102                 return false;
13103             }
13104             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
13105                 return false;
13106             }
13107             if ( !entry.getGeneName().equals( "GOT2" ) ) {
13108                 return false;
13109             }
13110             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
13111                 return false;
13112             }
13113             if ( entry.getMolecularSequence() == null ) {
13114                 return false;
13115             }
13116             if ( !entry
13117                     .getMolecularSequence()
13118                     .getMolecularSequenceAsString()
13119                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
13120                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
13121                 System.out.println( "got: " + entry.getMolecularSequence().getMolecularSequenceAsString() );
13122                 System.out.println( "expected something else." );
13123                 return false;
13124             }
13125         }
13126         catch ( final IOException e ) {
13127             System.out.println();
13128             System.out.println( "the following might be due to absence internet connection:" );
13129             e.printStackTrace( System.out );
13130             return true;
13131         }
13132         catch ( final NullPointerException f ) {
13133             f.printStackTrace( System.out );
13134             return false;
13135         }
13136         catch ( final Exception e ) {
13137             return false;
13138         }
13139         return true;
13140     }
13141
13142     private static boolean testUniprotTaxonomySearch() {
13143         try {
13144             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
13145                                                                                                  10 );
13146             if ( results.size() != 1 ) {
13147                 return false;
13148             }
13149             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13150                 return false;
13151             }
13152             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13153                 return false;
13154             }
13155             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13156                 return false;
13157             }
13158             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13159                 return false;
13160             }
13161             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13162                 return false;
13163             }
13164             results = null;
13165             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
13166             if ( results.size() != 1 ) {
13167                 return false;
13168             }
13169             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13170                 return false;
13171             }
13172             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13173                 return false;
13174             }
13175             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13176                 return false;
13177             }
13178             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13179                 return false;
13180             }
13181             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13182                 return false;
13183             }
13184             results = null;
13185             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
13186             if ( results.size() != 1 ) {
13187                 return false;
13188             }
13189             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13190                 return false;
13191             }
13192             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13193                 return false;
13194             }
13195             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13196                 return false;
13197             }
13198             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13199                 return false;
13200             }
13201             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13202                 return false;
13203             }
13204             results = null;
13205             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
13206             if ( results.size() != 1 ) {
13207                 return false;
13208             }
13209             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13210                 return false;
13211             }
13212             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13213                 return false;
13214             }
13215             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13216                 return false;
13217             }
13218             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13219                 return false;
13220             }
13221             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13222                 return false;
13223             }
13224             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
13225                 return false;
13226             }
13227             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
13228                 return false;
13229             }
13230             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13231                     .equals( "Nematostella vectensis" ) ) {
13232                 System.out.println( results.get( 0 ).getLineage() );
13233                 return false;
13234             }
13235             //
13236             results = null;
13237             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
13238             if ( results.size() != 1 ) {
13239                 return false;
13240             }
13241             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13242                 return false;
13243             }
13244             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13245                 return false;
13246             }
13247             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13248                 return false;
13249             }
13250             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13251                 return false;
13252             }
13253             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13254                 return false;
13255             }
13256             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13257                     .equals( "Xenopus tropicalis" ) ) {
13258                 System.out.println( results.get( 0 ).getLineage() );
13259                 return false;
13260             }
13261             //
13262             results = null;
13263             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
13264             if ( results.size() != 1 ) {
13265                 return false;
13266             }
13267             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13268                 return false;
13269             }
13270             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13271                 return false;
13272             }
13273             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13274                 return false;
13275             }
13276             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13277                 return false;
13278             }
13279             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13280                 return false;
13281             }
13282             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13283                     .equals( "Xenopus tropicalis" ) ) {
13284                 System.out.println( results.get( 0 ).getLineage() );
13285                 return false;
13286             }
13287             //
13288             results = null;
13289             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
13290             if ( results.size() != 1 ) {
13291                 return false;
13292             }
13293             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13294                 return false;
13295             }
13296             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13297                 return false;
13298             }
13299             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13300                 return false;
13301             }
13302             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13303                 return false;
13304             }
13305             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13306                 return false;
13307             }
13308             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13309                     .equals( "Xenopus tropicalis" ) ) {
13310                 System.out.println( results.get( 0 ).getLineage() );
13311                 return false;
13312             }
13313         }
13314         catch ( final IOException e ) {
13315             System.out.println();
13316             System.out.println( "the following might be due to absence internet connection:" );
13317             e.printStackTrace( System.out );
13318             return true;
13319         }
13320         catch ( final Exception e ) {
13321             return false;
13322         }
13323         return true;
13324     }
13325     
13326     
13327 }