f7146862a752ea9236fde0384abd74318fa32575
[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         }
1478         catch ( final Exception e ) {
1479             e.printStackTrace();
1480             return false;
1481         }
1482         return true;
1483     }
1484
1485     private static final boolean testPhyloXMLparsingFromURL() {
1486         try {
1487             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1488             final URL u = new URL( s );
1489             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1490             
1491             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1492                 return false;
1493             }
1494             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1495             
1496             if ( ( phys2 == null ) || ( phys2.length != 2 ) ) {
1497                 return false;
1498             }
1499         }
1500         catch ( final Exception e ) {
1501             e.printStackTrace();
1502             return false;
1503         }
1504         return true;
1505     }
1506
1507     private static final boolean testToLReading() {
1508         try {
1509             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1510             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, new TolParser() );
1511             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1512                 return false;
1513             }
1514             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1515                 return false;
1516             }
1517             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1518                 return false;
1519             }
1520             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1521                 return false;
1522             }
1523             //
1524             final URL u2 = new URL( WebserviceUtil.TOL_URL_BASE + "17706" );
1525             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, new TolParser() );
1526             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
1527                 return false;
1528             }
1529             if ( !phys2[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "17706" ) ) {
1530                 return false;
1531             }
1532             if ( phys2[ 0 ].getNumberOfExternalNodes() < 5 ) {
1533                 return false;
1534             }
1535         }
1536         catch ( final Exception e ) {
1537             e.printStackTrace();
1538             return false;
1539         }
1540         return true;
1541     }
1542
1543     private static final boolean testTreeBaseReading() {
1544         try {
1545             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "72557?format=nexus" );  
1546             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1547             parser.setReplaceUnderscores( true );
1548             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1549             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1550                 return false;
1551             }
1552             final URL u_1 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2406?format=nexus" );  
1553             final NexusPhylogeniesParser parser_1 = new NexusPhylogeniesParser();
1554             final Phylogeny[] phys_1 = ForesterUtil.readPhylogeniesFromUrl( u_1, parser_1 );
1555             if ( ( phys_1 == null ) || ( phys_1.length != 1 ) ) {
1556                 return false;
1557             }
1558             final URL u_2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "422?format=nexus" );  
1559             final NexusPhylogeniesParser parser_2 = new NexusPhylogeniesParser();
1560             final Phylogeny[] phys_2 = ForesterUtil.readPhylogeniesFromUrl( u_2, parser_2 );
1561             if ( ( phys_2 == null ) || ( phys_2.length != 1 ) ) {
1562                 return false;
1563             }
1564             final URL u_3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2654?format=nexus" );  
1565             final NexusPhylogeniesParser parser_3 = new NexusPhylogeniesParser();
1566             final Phylogeny[] phys_3 = ForesterUtil.readPhylogeniesFromUrl( u_3, parser_3 );
1567              if ( ( phys_3 == null ) || ( phys_3.length != 1 ) ) {
1568                 return false;
1569             }
1570             final URL u_4 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );  
1571             final NexusPhylogeniesParser parser_4 = new NexusPhylogeniesParser();
1572             final Phylogeny[] phys_4 = ForesterUtil.readPhylogeniesFromUrl( u_4, parser_4 );
1573              if ( ( phys_4 == null ) || ( phys_4.length != 1 ) ) {
1574                 return false;
1575             }
1576             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1577             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1578             parser2.setReplaceUnderscores( true );
1579             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, parser2 );
1580             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1581                 return false;
1582             }
1583             final URL u3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14909?format=nexus" );
1584             final NexusPhylogeniesParser parser3 = new NexusPhylogeniesParser();
1585             final Phylogeny[] phys3 = ForesterUtil.readPhylogeniesFromUrl( u3, parser3 );
1586             if ( ( phys3 == null ) || ( phys3.length != 2 ) ) {
1587                 return false;
1588             }
1589             final Phylogeny[] phys4 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14525?format=nexus" ),
1590                     new NexusPhylogeniesParser() );
1591             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1592                 return false;
1593             }
1594             final Phylogeny[] phys5 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15632?format=nexus" ) ,
1595                     new NexusPhylogeniesParser() );
1596             if ( ( phys5 == null ) || ( phys5.length != 1 ) ) {
1597                 return false;
1598             }
1599             final Phylogeny[] phys6 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "10190?format=nexus" ) ,
1600                     new NexusPhylogeniesParser() );
1601             if ( ( phys6 == null ) || ( phys6.length != 1 ) ) {
1602                 return false;
1603             }
1604             final Phylogeny[] phys7 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "13246?format=nexus" ) ,
1605                     new NexusPhylogeniesParser() );
1606             if ( ( phys7 == null ) || ( phys7.length != 2 ) ) {
1607                 return false;
1608             }
1609             final Phylogeny[] phys8 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "11662?format=nexus" ) ,
1610                     new NexusPhylogeniesParser() );
1611             if ( ( phys8 == null ) || ( phys8.length != 2 ) ) {
1612                 return false;
1613             }
1614             final Phylogeny[] phys9 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "562?format=nexus" ) ,
1615                     new NexusPhylogeniesParser() );
1616             if ( ( phys9 == null ) || ( phys9.length != 4 ) ) {
1617                 return false;
1618             }
1619             final Phylogeny[] phys16424 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "16424?format=nexus" ) ,
1620                     new NexusPhylogeniesParser() );
1621             if ( ( phys16424 == null ) || ( phys16424.length != 1 ) ) {
1622                 return false;
1623             }
1624             final Phylogeny[] phys17878 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "17878?format=nexus" ) ,
1625                     new NexusPhylogeniesParser() );
1626             if ( ( phys17878 == null ) || ( phys17878.length != 17 ) ) {
1627                 return false;
1628             }
1629             final Phylogeny[] phys18804 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "18804?format=nexus" ) ,
1630                     new NexusPhylogeniesParser() );
1631             if ( ( phys18804 == null ) || ( phys18804.length != 2 ) ) {
1632                 return false;
1633             }
1634             final Phylogeny[] phys346 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "346?format=nexus" ) ,
1635                     new NexusPhylogeniesParser() );
1636             if ( ( phys346 == null ) || ( phys346.length != 1 ) ) {
1637                 return false;
1638             }
1639         }
1640         catch ( final Exception e ) {
1641             e.printStackTrace();
1642             return false;
1643         }
1644         return true;
1645     }
1646
1647     private static final boolean testTreeFamReading() {
1648         try {
1649             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1650             final NHXParser parser = new NHXParser();
1651             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1652             parser.setReplaceUnderscores( false );
1653             parser.setGuessRootedness( true );
1654             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1655             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1656                 return false;
1657             }
1658             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1659                 return false;
1660             }
1661         }
1662         catch ( final Exception e ) {
1663             e.printStackTrace();
1664             return false;
1665         }
1666         return true;
1667     }
1668
1669     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1670         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1671         return p;
1672     }
1673
1674     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1675         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1676     }
1677
1678     private static boolean testAminoAcidSequence() {
1679         try {
1680             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1681             if ( aa1.getLength() != 13 ) {
1682                 return false;
1683             }
1684             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1685                 return false;
1686             }
1687             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1688                 return false;
1689             }
1690             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1691                 return false;
1692             }
1693             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1694             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1695                 return false;
1696             }
1697             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1698             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1699                 return false;
1700             }
1701             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1702             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1703                 return false;
1704             }
1705         }
1706         catch ( final Exception e ) {
1707             e.printStackTrace();
1708             return false;
1709         }
1710         return true;
1711     }
1712
1713     private static boolean testBasicDomain() {
1714         try {
1715             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1716             if ( !pd.getDomainId().equals( "id" ) ) {
1717                 return false;
1718             }
1719             if ( pd.getNumber() != 1 ) {
1720                 return false;
1721             }
1722             if ( pd.getTotalCount() != 4 ) {
1723                 return false;
1724             }
1725             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1726                 return false;
1727             }
1728             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1729             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1730             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1731             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1732             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1733             if ( !a1.equals( a1 ) ) {
1734                 return false;
1735             }
1736             if ( !a1.equals( a1_copy ) ) {
1737                 return false;
1738             }
1739             if ( !a1.equals( a1_equal ) ) {
1740                 return false;
1741             }
1742             if ( !a1.equals( a2 ) ) {
1743                 return false;
1744             }
1745             if ( a1.equals( a3 ) ) {
1746                 return false;
1747             }
1748             if ( a1.compareTo( a1 ) != 0 ) {
1749                 return false;
1750             }
1751             if ( a1.compareTo( a1_copy ) != 0 ) {
1752                 return false;
1753             }
1754             if ( a1.compareTo( a1_equal ) != 0 ) {
1755                 return false;
1756             }
1757             if ( a1.compareTo( a2 ) != 0 ) {
1758                 return false;
1759             }
1760             if ( a1.compareTo( a3 ) == 0 ) {
1761                 return false;
1762             }
1763         }
1764         catch ( final Exception e ) {
1765             e.printStackTrace( System.out );
1766             return false;
1767         }
1768         return true;
1769     }
1770
1771     private static boolean testBasicNodeMethods() {
1772         try {
1773             if ( PhylogenyNode.getNodeCount() != 0 ) {
1774                 return false;
1775             }
1776             final PhylogenyNode n1 = new PhylogenyNode();
1777             final PhylogenyNode n2 = PhylogenyNode
1778                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1779             final PhylogenyNode n3 = PhylogenyNode
1780                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1781             final PhylogenyNode n4 = PhylogenyNode
1782                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1783             if ( n1.isHasAssignedEvent() ) {
1784                 return false;
1785             }
1786             if ( PhylogenyNode.getNodeCount() != 4 ) {
1787                 return false;
1788             }
1789             if ( n3.getIndicator() != 0 ) {
1790                 return false;
1791             }
1792             if ( n3.getNumberOfExternalNodes() != 1 ) {
1793                 return false;
1794             }
1795             if ( !n3.isExternal() ) {
1796                 return false;
1797             }
1798             if ( !n3.isRoot() ) {
1799                 return false;
1800             }
1801             if ( !n4.getName().equals( "n4" ) ) {
1802                 return false;
1803             }
1804         }
1805         catch ( final Exception e ) {
1806             e.printStackTrace( System.out );
1807             return false;
1808         }
1809         return true;
1810     }
1811     
1812     private static boolean testUTF8ParsingFromFile() {
1813         try {
1814             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1815             final Phylogeny[] phylogenies_xml = ParserBasedPhylogenyFactory.getInstance().create( new File( Test.PATH_TO_TEST_DATA + "chars.xml" ),
1816                                                               xml_parser );
1817             if ( xml_parser.getErrorCount() > 0 ) {
1818                 System.out.println( xml_parser.getErrorMessages().toString() );
1819                 return false;
1820             }
1821             if ( phylogenies_xml.length != 1 ) {
1822                 return false;
1823             }
1824          
1825             final Phylogeny[] phylogenies_xml2 = ParserBasedPhylogenyFactory.getInstance().create( new StringBuffer( phylogenies_xml[0].toPhyloXML( 0 )),
1826                                                                                                    xml_parser );
1827             
1828             final Phylogeny[] phylogenies_nh = ParserBasedPhylogenyFactory.getInstance().create( new File( Test.PATH_TO_TEST_DATA + "chars.nh" ), new NHXParser() );
1829             if ( phylogenies_nh.length != 1 ) {
1830                 return false;
1831             }
1832            
1833             final Phylogeny[] phylogenies_nex = ParserBasedPhylogenyFactory.getInstance().create( new File( Test.PATH_TO_TEST_DATA + "chars.nex" ), new NexusPhylogeniesParser() );
1834             if ( phylogenies_nex.length != 1 ) {
1835                 return false;
1836             }
1837           
1838             final String[] xml_n = phylogenies_xml[0].getAllExternalNodeNames();
1839             final String[] xml_n2 = phylogenies_xml2[0].getAllExternalNodeNames();
1840             final String[] nh_n = phylogenies_nh[0].getAllExternalNodeNames();
1841             final String[] nex_n = phylogenies_nex[0].getAllExternalNodeNames();
1842             final String n0 = "AQ~!@#$%^&*()_+-=\\{}|;:\"<>?,./";
1843             final String n1 = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ";
1844             final String n2 = "漢字ひらがなカタカナ";
1845             final String n3 = "อักษรไทย";
1846             final String n4 = "繁體字";
1847             final String n5 = "한글";
1848             final String n6 = "देवनागरी";
1849             
1850             final String n7 = "chữ Quốc ngữ";
1851             final String n8 = "ру́сский язы́к";
1852             final String n9 = "អក្សរខ្មែរ";
1853             
1854             if ( !xml_n[0].equals( n0 ) ) {
1855                 System.out.println( xml_n[0] );
1856                 System.out.println( n0 );
1857                 return false;
1858             }
1859             if ( !xml_n2[0].equals( n0 ) ) {
1860                 System.out.println( xml_n2[0] );
1861                 System.out.println( n0 );
1862                 return false;
1863             }
1864             if ( !nh_n[0].equals( n0 ) ) {
1865                 System.out.println( nh_n[0] );
1866                 System.out.println( n0 );
1867                 return false;
1868             }
1869             if ( !nex_n[0].equals( n0 ) ) {
1870                 System.out.println( nex_n[0] );
1871                 System.out.println( n0 );
1872                 return false;
1873             }
1874             
1875             if ( !xml_n[1].equals( n1 ) ) {
1876                 System.out.println( xml_n[1] );
1877                 System.out.println( n1 );
1878                 return false;
1879             }
1880             if ( !xml_n2[1].equals( n1 ) ) {
1881                 System.out.println( xml_n2[1] );
1882                 System.out.println( n1 );
1883                 return false;
1884             }
1885             if ( !nh_n[1].equals( n1 ) ) {
1886                 System.out.println( nh_n[1] );
1887                 System.out.println( n1 );
1888                 return false;
1889             }
1890             if ( !nex_n[1].equals( n1 ) ) {
1891                 System.out.println( nex_n[1] );
1892                 System.out.println( n1 );
1893                 return false;
1894             }
1895             
1896             if ( !xml_n[2].equals( n2 ) ) {
1897                 System.out.println( xml_n[2] );
1898                 System.out.println( n2 );
1899                 return false;
1900             }
1901             if ( !xml_n2[2].equals( n2 ) ) {
1902                 System.out.println( xml_n2[2] );
1903                 System.out.println( n2 );
1904                 return false;
1905             }
1906             if ( !nh_n[2].equals( n2 ) ) {
1907                 System.out.println( nh_n[2] );
1908                 System.out.println( n2 );
1909                 return false;
1910             }
1911             if ( !nex_n[2].equals( n2 ) ) {
1912                 System.out.println( nex_n[2] );
1913                 System.out.println( n2 );
1914                 return false;
1915             }
1916             //
1917             if ( !xml_n[3].equals( n3 ) ) {
1918                 System.out.println( xml_n[3] );
1919                 System.out.println( n3 );
1920                 return false;
1921             }
1922             if ( !xml_n2[3].equals( n3 ) ) {
1923                 System.out.println( xml_n2[3] );
1924                 System.out.println( n3 );
1925                 return false;
1926             }
1927             if ( !nh_n[3].equals( n3 ) ) {
1928                 System.out.println( nh_n[3] );
1929                 System.out.println( n3 );
1930                 return false;
1931             }
1932             if ( !nex_n[3].equals( n3 ) ) {
1933                 System.out.println( nex_n[3] );
1934                 System.out.println( n3 );
1935                 return false;
1936             }
1937             //
1938             if ( !xml_n[4].equals( n4 ) ) {
1939                 System.out.println( xml_n[4] );
1940                 System.out.println( n4 );
1941                 return false;
1942             }
1943             if ( !nh_n[4].equals( n4 ) ) {
1944                 System.out.println( nh_n[4] );
1945                 System.out.println( n4 );
1946                 return false;
1947             }
1948             if ( !nex_n[4].equals( n4 ) ) {
1949                 System.out.println( nex_n[4] );
1950                 System.out.println( n4 );
1951                 return false;
1952             }
1953             //
1954             if ( !xml_n[5].equals( n5 ) ) {
1955                 System.out.println( xml_n[5] );
1956                 System.out.println( n5 );
1957                 return false;
1958             }
1959             if ( !nh_n[5].equals( n5 ) ) {
1960                 System.out.println( nh_n[5] );
1961                 System.out.println( n5 );
1962                 return false;
1963             }
1964             if ( !nex_n[5].equals( n5 ) ) {
1965                 System.out.println( nex_n[5] );
1966                 System.out.println( n5 );
1967                 return false;
1968             }
1969             //
1970             if ( !xml_n[6].equals( n6 ) ) {
1971                 System.out.println( xml_n[6] );
1972                 System.out.println( n6 );
1973                 return false;
1974             }
1975             if ( !nh_n[6].equals( n6 ) ) {
1976                 System.out.println( nh_n[6] );
1977                 System.out.println( n6 );
1978                 return false;
1979             }
1980             if ( !nex_n[6].equals( n6 ) ) {
1981                 System.out.println( nex_n[6] );
1982                 System.out.println( n6 );
1983                 return false;
1984             }
1985             //
1986             if ( !xml_n[7].equals( n7 ) ) {
1987                 System.out.println( xml_n[7] );
1988                 System.out.println( n7 );
1989                 return false;
1990             }
1991             if ( !nh_n[7].equals( n7 ) ) {
1992                 System.out.println( nh_n[7] );
1993                 System.out.println( n7 );
1994                 return false;
1995             }
1996             if ( !nex_n[7].equals( n7 ) ) {
1997                 System.out.println( nex_n[7] );
1998                 System.out.println( n7 );
1999                 return false;
2000             }
2001             if ( !xml_n[8].equals( n8 ) ) {
2002                 System.out.println( xml_n[8] );
2003                 System.out.println( n8 );
2004                 return false;
2005             }
2006             if ( !nh_n[8].equals( n8 ) ) {
2007                 System.out.println( nh_n[8] );
2008                 System.out.println( n8 );
2009                 return false;
2010             }
2011             if ( !nex_n[8].equals( n8 ) ) {
2012                 System.out.println( nex_n[8] );
2013                 System.out.println( n8 );
2014                 return false;
2015             }
2016             if ( !xml_n[9].equals( n9 ) ) {
2017                 System.out.println( xml_n[9] );
2018                 System.out.println( n9 );
2019                 return false;
2020             }
2021             if ( !xml_n2[9].equals( n9 ) ) {
2022                 System.out.println( xml_n2[9] );
2023                 System.out.println( n9 );
2024                 return false;
2025             }
2026             if ( !nh_n[9].equals( n9 ) ) {
2027                 System.out.println( nh_n[9] );
2028                 System.out.println( n9 );
2029                 return false;
2030             }
2031             if ( !nex_n[9].equals( n9 ) ) {
2032                 System.out.println( nex_n[9] );
2033                 System.out.println( n9 );
2034                 return false;
2035             }
2036             if (!phylogenies_xml[0].toNewHampshire().equals( 
2037                                                             phylogenies_nh[0].toNewHampshire() ) ) {
2038                 System.out.println( phylogenies_xml[0].toNewHampshire() );
2039                 System.out.println( phylogenies_nh[0].toNewHampshire() );
2040                 return false;
2041             }
2042             if (!phylogenies_xml[0].toNewHampshire().equals( 
2043                                                             phylogenies_nex[0].toNewHampshire() ) ) {
2044                 System.out.println( phylogenies_xml[0].toNewHampshire() );
2045                 System.out.println( phylogenies_nex[0].toNewHampshire() );
2046                 return false;
2047             }
2048         }
2049         catch ( final Exception e ) {
2050             e.printStackTrace( System.out );
2051             return false;
2052         }
2053         return true;
2054     }
2055     
2056     
2057
2058     private static boolean testBasicPhyloXMLparsing() {
2059         try {
2060             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2061             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2062             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ),
2063                                                               xml_parser );
2064             if ( xml_parser.getErrorCount() > 0 ) {
2065                 System.out.println( xml_parser.getErrorMessages().toString() );
2066                 return false;
2067             }
2068             if ( phylogenies_0.length != 4 ) {
2069                 return false;
2070             }
2071             final Phylogeny t1 = phylogenies_0[ 0 ];
2072             final Phylogeny t2 = phylogenies_0[ 1 ];
2073             final Phylogeny t3 = phylogenies_0[ 2 ];
2074             final Phylogeny t4 = phylogenies_0[ 3 ];
2075             if ( t1.getNumberOfExternalNodes() != 1 ) {
2076                 return false;
2077             }
2078             if ( !t1.isRooted() ) {
2079                 return false;
2080             }
2081             if ( t1.isRerootable() ) {
2082                 return false;
2083             }
2084             if ( !t1.getType().equals( "gene_tree" ) ) {
2085                 return false;
2086             }
2087             if ( t2.getNumberOfExternalNodes() != 2 ) {
2088                 return false;
2089             }
2090             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
2091                 return false;
2092             }
2093             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
2094                 return false;
2095             }
2096             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2097                 return false;
2098             }
2099             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2100                 return false;
2101             }
2102             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2103                 return false;
2104             }
2105             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2106                 return false;
2107             }
2108             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2109                     .startsWith( "actgtgggggt" ) ) {
2110                 return false;
2111             }
2112             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2113                     .startsWith( "ctgtgatgcat" ) ) {
2114                 return false;
2115             }
2116             if ( t3.getNumberOfExternalNodes() != 4 ) {
2117                 return false;
2118             }
2119             if ( !t1.getName().equals( "t1" ) ) {
2120                 return false;
2121             }
2122             if ( !t2.getName().equals( "t2" ) ) {
2123                 return false;
2124             }
2125             if ( !t3.getName().equals( "t3" ) ) {
2126                 return false;
2127             }
2128             if ( !t4.getName().equals( "t4" ) ) {
2129                 return false;
2130             }
2131             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
2132                 return false;
2133             }
2134             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
2135                 return false;
2136             }
2137             if ( !t3.getNode( "root node" ).isDuplication() ) {
2138                 return false;
2139             }
2140             if ( !t3.getNode( "node a" ).isDuplication() ) {
2141                 return false;
2142             }
2143             if ( t3.getNode( "node a" ).isSpeciation() ) {
2144                 return false;
2145             }
2146             if ( t3.getNode( "node bc" ).isDuplication() ) {
2147                 return false;
2148             }
2149             if ( !t3.getNode( "node bc" ).isSpeciation() ) {
2150                 return false;
2151             }
2152             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2153                 return false;
2154             }
2155             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
2156                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2157                 return false;
2158             }
2159             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2160                 return false;
2161             }
2162             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2163                 return false;
2164             }
2165             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
2166                 return false;
2167             }
2168             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2169                     .equals( "apoptosis" ) ) {
2170                 return false;
2171             }
2172             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2173                     .equals( "GO:0006915" ) ) {
2174                 return false;
2175             }
2176             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2177                     .equals( "UniProtKB" ) ) {
2178                 return false;
2179             }
2180             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2181                     .equals( "experimental" ) ) {
2182                 return false;
2183             }
2184             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2185                     .equals( "function" ) ) {
2186                 return false;
2187             }
2188             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2189                     .getValue() != 1 ) {
2190                 return false;
2191             }
2192             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2193                     .getType().equals( "ml" ) ) {
2194                 return false;
2195             }
2196             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2197                     .equals( "apoptosis" ) ) {
2198                 return false;
2199             }
2200             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2201                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2202                 return false;
2203             }
2204             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2205                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2206                 return false;
2207             }
2208             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2209                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2210                 return false;
2211             }
2212             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2213                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2214                 return false;
2215             }
2216             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2217                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2218                 return false;
2219             }
2220             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2221                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2222                 return false;
2223             }
2224             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2225                     .equals( "GO:0005829" ) ) {
2226                 return false;
2227             }
2228             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2229                     .equals( "intracellular organelle" ) ) {
2230                 return false;
2231             }
2232             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2233                 return false;
2234             }
2235             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2236                     .equals( "UniProt link" ) ) ) {
2237                 return false;
2238             }
2239             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2240                 return false;
2241             }
2242             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
2243             if ( x.size() != 4 ) {
2244                 return false;
2245             }
2246             int c = 0;
2247             for( final Accession acc : x ) {
2248                 if ( c == 0 ) {
2249                     if ( !acc.getSource().equals( "KEGG" ) ) {
2250                         return false;
2251                     }
2252                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2253                         return false;
2254                     }
2255                 }
2256                 c++;
2257             }
2258         }
2259         catch ( final Exception e ) {
2260             e.printStackTrace( System.out );
2261             return false;
2262         }
2263         return true;
2264     }
2265
2266     private static boolean testBasicPhyloXMLparsingRoundtrip() {
2267         try {
2268             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2269             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2270             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2271                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2272             }
2273             else {
2274                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2275             }
2276             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ),
2277                                                               xml_parser );
2278             if ( xml_parser.getErrorCount() > 0 ) {
2279                 System.out.println( xml_parser.getErrorMessages().toString() );
2280                 return false;
2281             }
2282             if ( phylogenies_0.length != 4 ) {
2283                 return false;
2284             }
2285             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
2286             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
2287             if ( phylogenies_t1.length != 1 ) {
2288                 return false;
2289             }
2290             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
2291             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
2292                 return false;
2293             }
2294             if ( !t1_rt.isRooted() ) {
2295                 return false;
2296             }
2297             if ( t1_rt.isRerootable() ) {
2298                 return false;
2299             }
2300             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
2301                 return false;
2302             }
2303             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
2304             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
2305             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
2306             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2307                 return false;
2308             }
2309             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2310                 return false;
2311             }
2312             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2313                 return false;
2314             }
2315             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2316                 return false;
2317             }
2318             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2319                     .startsWith( "actgtgggggt" ) ) {
2320                 return false;
2321             }
2322             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2323                     .startsWith( "ctgtgatgcat" ) ) {
2324                 return false;
2325             }
2326             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
2327             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
2328             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
2329             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
2330             if ( phylogenies_1.length != 1 ) {
2331                 return false;
2332             }
2333             final Phylogeny t3_rt = phylogenies_1[ 0 ];
2334             if ( !t3_rt.getName().equals( "t3" ) ) {
2335                 return false;
2336             }
2337             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
2338                 return false;
2339             }
2340             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
2341                 return false;
2342             }
2343             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
2344                 return false;
2345             }
2346             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2347                 return false;
2348             }
2349             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
2350                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2351                 return false;
2352             }
2353             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2354                 return false;
2355             }
2356             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2357                 return false;
2358             }
2359             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2360                     .equals( "UniProtKB" ) ) {
2361                 return false;
2362             }
2363             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2364                     .equals( "apoptosis" ) ) {
2365                 return false;
2366             }
2367             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2368                     .equals( "GO:0006915" ) ) {
2369                 return false;
2370             }
2371             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2372                     .equals( "UniProtKB" ) ) {
2373                 return false;
2374             }
2375             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2376                     .equals( "experimental" ) ) {
2377                 return false;
2378             }
2379             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2380                     .equals( "function" ) ) {
2381                 return false;
2382             }
2383             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2384                     .getValue() != 1 ) {
2385                 return false;
2386             }
2387             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2388                     .getType().equals( "ml" ) ) {
2389                 return false;
2390             }
2391             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2392                     .equals( "apoptosis" ) ) {
2393                 return false;
2394             }
2395             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2396                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2397                 return false;
2398             }
2399             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2400                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2401                 return false;
2402             }
2403             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2404                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2405                 return false;
2406             }
2407             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2408                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2409                 return false;
2410             }
2411             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2412                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2413                 return false;
2414             }
2415             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2416                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2417                 return false;
2418             }
2419             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2420                     .equals( "GO:0005829" ) ) {
2421                 return false;
2422             }
2423             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2424                     .equals( "intracellular organelle" ) ) {
2425                 return false;
2426             }
2427             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2428                 return false;
2429             }
2430             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2431                     .equals( "UniProt link" ) ) ) {
2432                 return false;
2433             }
2434             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2435                 return false;
2436             }
2437             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
2438                 return false;
2439             }
2440             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2441                     .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." ) ) ) {
2442                 System.out.println( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription() );
2443                 return false;
2444             }
2445             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2446                 return false;
2447             }
2448             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2449                 return false;
2450             }
2451             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
2452                 return false;
2453             }
2454             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2455                 return false;
2456             }
2457             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2458                     .equals( "ncbi" ) ) {
2459                 return false;
2460             }
2461             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2462                 return false;
2463             }
2464             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2465                     .getName().equals( "B" ) ) {
2466                 return false;
2467             }
2468             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2469                     .getFrom() != 21 ) {
2470                 return false;
2471             }
2472             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2473                 return false;
2474             }
2475             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2476                     .getLength() != 24 ) {
2477                 return false;
2478             }
2479             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2480                     .getConfidence() != 0 ) {
2481                 return false;
2482             }
2483             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2484                     .equals( "pfam" ) ) {
2485                 return false;
2486             }
2487             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2488                 return false;
2489             }
2490             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2491                 return false;
2492             }
2493             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2494                 return false;
2495             }
2496             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2497                 return false;
2498             }
2499             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2500             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2501                 return false;
2502             }
2503             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2504                 return false;
2505             }
2506             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2507                 return false;
2508             }
2509             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2510                 return false;
2511             }
2512             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2513                 return false;
2514             }
2515             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2516                 return false;
2517             }
2518             if ( taxbb.getSynonyms().size() != 2 ) {
2519                 return false;
2520             }
2521             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2522                 return false;
2523             }
2524             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2525                 return false;
2526             }
2527             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2528                 return false;
2529             }
2530             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2531                 return false;
2532             }
2533             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2534                 return false;
2535             }
2536             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2537                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2538                 return false;
2539             }
2540             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2541                 return false;
2542             }
2543             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2544                 return false;
2545             }
2546             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2547                 return false;
2548             }
2549             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2550                 return false;
2551             }
2552             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2553                 return false;
2554             }
2555             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2556                 return false;
2557             }
2558             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2559                 return false;
2560             }
2561             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2562                 return false;
2563             }
2564             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2565                     .equalsIgnoreCase( "435" ) ) {
2566                 return false;
2567             }
2568             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2569                 return false;
2570             }
2571             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2572                     .equalsIgnoreCase( "443.7" ) ) {
2573                 return false;
2574             }
2575             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2576                 return false;
2577             }
2578             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2579                 return false;
2580             }
2581             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2582                     .equalsIgnoreCase( "433" ) ) {
2583                 return false;
2584             }
2585             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2586                     .getCrossReferences();
2587             if ( x.size() != 4 ) {
2588                 return false;
2589             }
2590             int c = 0;
2591             for( final Accession acc : x ) {
2592                 if ( c == 0 ) {
2593                     if ( !acc.getSource().equals( "KEGG" ) ) {
2594                         return false;
2595                     }
2596                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2597                         return false;
2598                     }
2599                 }
2600                 c++;
2601             }
2602         }
2603         catch ( final Exception e ) {
2604             e.printStackTrace( System.out );
2605             return false;
2606         }
2607         return true;
2608     }
2609
2610     private static boolean testBasicPhyloXMLparsingValidating() {
2611         try {
2612             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2613             PhyloXmlParser xml_parser = null;
2614             try {
2615                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2616             }
2617             catch ( final Exception e ) {
2618                 // Do nothing -- means were not running from jar.
2619             }
2620             if ( xml_parser == null ) {
2621                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2622                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2623                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2624                 }
2625                 else {
2626                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2627                 }
2628             }
2629             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ),
2630                                                               xml_parser );
2631             if ( xml_parser.getErrorCount() > 0 ) {
2632                 System.out.println( xml_parser.getErrorMessages().toString() );
2633                 return false;
2634             }
2635             if ( phylogenies_0.length != 4 ) {
2636                 return false;
2637             }
2638             final Phylogeny t1 = phylogenies_0[ 0 ];
2639             final Phylogeny t2 = phylogenies_0[ 1 ];
2640             final Phylogeny t3 = phylogenies_0[ 2 ];
2641             final Phylogeny t4 = phylogenies_0[ 3 ];
2642             if ( !t1.getName().equals( "t1" ) ) {
2643                 return false;
2644             }
2645             if ( !t2.getName().equals( "t2" ) ) {
2646                 return false;
2647             }
2648             if ( !t3.getName().equals( "t3" ) ) {
2649                 return false;
2650             }
2651             if ( !t4.getName().equals( "t4" ) ) {
2652                 return false;
2653             }
2654             if ( t1.getNumberOfExternalNodes() != 1 ) {
2655                 return false;
2656             }
2657             if ( t2.getNumberOfExternalNodes() != 2 ) {
2658                 return false;
2659             }
2660             if ( t3.getNumberOfExternalNodes() != 4 ) {
2661                 return false;
2662             }
2663             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2664             final Phylogeny[] phylogenies_1 = factory.create( new File( x2 ), xml_parser );
2665             if ( xml_parser.getErrorCount() > 0 ) {
2666                 System.out.println( "errors:" );
2667                 System.out.println( xml_parser.getErrorMessages().toString() );
2668                 return false;
2669             }
2670             if ( phylogenies_1.length != 4 ) {
2671                 return false;
2672             }
2673             final Phylogeny[] phylogenies_2 = factory.create( new File(Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml" ),
2674                                                               xml_parser );
2675             if ( xml_parser.getErrorCount() > 0 ) {
2676                 System.out.println( "errors:" );
2677                 System.out.println( xml_parser.getErrorMessages().toString() );
2678                 return false;
2679             }
2680             if ( phylogenies_2.length != 1 ) {
2681                 return false;
2682             }
2683             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2684                 return false;
2685             }
2686             final Phylogeny[] phylogenies_3 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml" ),
2687                                                               xml_parser );
2688             if ( xml_parser.getErrorCount() > 0 ) {
2689                 System.out.println( xml_parser.getErrorMessages().toString() );
2690                 return false;
2691             }
2692             if ( phylogenies_3.length != 2 ) {
2693                 return false;
2694             }
2695             final Phylogeny a = phylogenies_3[ 0 ];
2696             if ( !a.getName().equals( "tree 4" ) ) {
2697                 return false;
2698             }
2699             if ( a.getNumberOfExternalNodes() != 3 ) {
2700                 return false;
2701             }
2702             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2703                 return false;
2704             }
2705             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2706                 return false;
2707             }
2708             final Phylogeny[] phylogenies_4 = factory.create( new File( Test.PATH_TO_TEST_DATA + "special_characters.xml") ,
2709                                                               xml_parser );
2710             if ( xml_parser.getErrorCount() > 0 ) {
2711                 System.out.println( xml_parser.getErrorMessages().toString() );
2712                 return false;
2713             }
2714             if ( phylogenies_4.length != 1 ) {
2715                 return false;
2716             }
2717             final Phylogeny s = phylogenies_4[ 0 ];
2718             if ( s.getNumberOfExternalNodes() != 6 ) {
2719                 return false;
2720             }
2721             s.getNode( "first" );
2722             s.getNode( "<>" );
2723             s.getNode( "\"<a'b&c'd\">\"" );
2724             s.getNode( "'''\"" );
2725             s.getNode( "\"\"\"" );
2726             s.getNode( "dick & doof" );
2727         }
2728         catch ( final Exception e ) {
2729             e.printStackTrace( System.out );
2730             return false;
2731         }
2732         return true;
2733     }
2734
2735     private static boolean testBasicProtein() {
2736         try {
2737             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2738             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2739             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2740             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2741             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2742             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2743             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2744             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2745             p0.addProteinDomain( y );
2746             p0.addProteinDomain( e );
2747             p0.addProteinDomain( b );
2748             p0.addProteinDomain( c );
2749             p0.addProteinDomain( d );
2750             p0.addProteinDomain( a );
2751             p0.addProteinDomain( x );
2752             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2753                 return false;
2754             }
2755             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2756                 return false;
2757             }
2758             //
2759             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2760             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2761             aa0.addProteinDomain( a1 );
2762             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2763                 return false;
2764             }
2765             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2766                 return false;
2767             }
2768             //
2769             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2770             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2771             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2772             aa1.addProteinDomain( a11 );
2773             aa1.addProteinDomain( a12 );
2774             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2775                 return false;
2776             }
2777             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2778                 return false;
2779             }
2780             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2781             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2782                 return false;
2783             }
2784             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2785                 return false;
2786             }
2787             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2788                 return false;
2789             }
2790             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2791             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2792                 return false;
2793             }
2794             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2795                 return false;
2796             }
2797             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2798                 return false;
2799             }
2800             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2801                 return false;
2802             }
2803             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2804             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2805                 return false;
2806             }
2807             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2808                 return false;
2809             }
2810             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2811                 return false;
2812             }
2813             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2814                 return false;
2815             }
2816             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2817             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2818                 return false;
2819             }
2820             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2821                 return false;
2822             }
2823             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2824                 return false;
2825             }
2826             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2827                 return false;
2828             }
2829             //
2830             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2831             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2832             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2833             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2834             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2835             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2836             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2837             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2838             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2839             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2840             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2841             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2842             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2843             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2844             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2845             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2846             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2847             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2848             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2849             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2850             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2851             p00.addProteinDomain( y0 );
2852             p00.addProteinDomain( e0 );
2853             p00.addProteinDomain( b0 );
2854             p00.addProteinDomain( c0 );
2855             p00.addProteinDomain( d0 );
2856             p00.addProteinDomain( a0 );
2857             p00.addProteinDomain( x0 );
2858             p00.addProteinDomain( y1 );
2859             p00.addProteinDomain( y2 );
2860             p00.addProteinDomain( y3 );
2861             p00.addProteinDomain( e1 );
2862             p00.addProteinDomain( e2 );
2863             p00.addProteinDomain( e3 );
2864             p00.addProteinDomain( e4 );
2865             p00.addProteinDomain( e5 );
2866             p00.addProteinDomain( z0 );
2867             p00.addProteinDomain( z1 );
2868             p00.addProteinDomain( z2 );
2869             p00.addProteinDomain( zz0 );
2870             p00.addProteinDomain( zz1 );
2871             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2872                 return false;
2873             }
2874             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2875                 return false;
2876             }
2877             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2878                 return false;
2879             }
2880             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2881                 return false;
2882             }
2883             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" ) ) {
2884                 return false;
2885             }
2886             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2887             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2888             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2889             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2890             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2891             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2892             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2893             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2894             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2895             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2896             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2897             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2898             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2899             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2900             p.addProteinDomain( B15 );
2901             p.addProteinDomain( C50 );
2902             p.addProteinDomain( A60 );
2903             p.addProteinDomain( A30 );
2904             p.addProteinDomain( C70 );
2905             p.addProteinDomain( B35 );
2906             p.addProteinDomain( B40 );
2907             p.addProteinDomain( A0 );
2908             p.addProteinDomain( A10 );
2909             p.addProteinDomain( A20 );
2910             p.addProteinDomain( B25 );
2911             p.addProteinDomain( D80 );
2912             List<String> domains_ids = new ArrayList<String>();
2913             domains_ids.add( "A" );
2914             domains_ids.add( "B" );
2915             domains_ids.add( "C" );
2916             if ( !p.contains( domains_ids, false ) ) {
2917                 return false;
2918             }
2919             if ( !p.contains( domains_ids, true ) ) {
2920                 return false;
2921             }
2922             domains_ids.add( "X" );
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 = new ArrayList<String>();
2930             domains_ids.add( "A" );
2931             domains_ids.add( "C" );
2932             domains_ids.add( "D" );
2933             if ( !p.contains( domains_ids, false ) ) {
2934                 return false;
2935             }
2936             if ( !p.contains( domains_ids, true ) ) {
2937                 return false;
2938             }
2939             domains_ids = new ArrayList<String>();
2940             domains_ids.add( "A" );
2941             domains_ids.add( "D" );
2942             domains_ids.add( "C" );
2943             if ( !p.contains( domains_ids, false ) ) {
2944                 return false;
2945             }
2946             if ( p.contains( domains_ids, true ) ) {
2947                 return false;
2948             }
2949             domains_ids = new ArrayList<String>();
2950             domains_ids.add( "A" );
2951             domains_ids.add( "A" );
2952             domains_ids.add( "B" );
2953             if ( !p.contains( domains_ids, false ) ) {
2954                 return false;
2955             }
2956             if ( !p.contains( domains_ids, true ) ) {
2957                 return false;
2958             }
2959             domains_ids = new ArrayList<String>();
2960             domains_ids.add( "A" );
2961             domains_ids.add( "A" );
2962             domains_ids.add( "A" );
2963             domains_ids.add( "B" );
2964             domains_ids.add( "B" );
2965             if ( !p.contains( domains_ids, false ) ) {
2966                 return false;
2967             }
2968             if ( !p.contains( domains_ids, true ) ) {
2969                 return false;
2970             }
2971             domains_ids = new ArrayList<String>();
2972             domains_ids.add( "A" );
2973             domains_ids.add( "A" );
2974             domains_ids.add( "B" );
2975             domains_ids.add( "A" );
2976             domains_ids.add( "B" );
2977             domains_ids.add( "B" );
2978             domains_ids.add( "A" );
2979             domains_ids.add( "B" );
2980             domains_ids.add( "C" );
2981             domains_ids.add( "A" );
2982             domains_ids.add( "C" );
2983             domains_ids.add( "D" );
2984             if ( !p.contains( domains_ids, false ) ) {
2985                 return false;
2986             }
2987             if ( p.contains( domains_ids, true ) ) {
2988                 return false;
2989             }
2990         }
2991         catch ( final Exception e ) {
2992             e.printStackTrace( System.out );
2993             return false;
2994         }
2995         return true;
2996     }
2997
2998     private static boolean testBasicTable() {
2999         try {
3000             final BasicTable<String> t0 = new BasicTable<String>();
3001             if ( t0.getNumberOfColumns() != 0 ) {
3002                 return false;
3003             }
3004             if ( t0.getNumberOfRows() != 0 ) {
3005                 return false;
3006             }
3007             t0.setValue( 3, 2, "23" );
3008             t0.setValue( 10, 1, "error" );
3009             t0.setValue( 10, 1, "110" );
3010             t0.setValue( 9, 1, "19" );
3011             t0.setValue( 1, 10, "101" );
3012             t0.setValue( 10, 10, "1010" );
3013             t0.setValue( 100, 10, "10100" );
3014             t0.setValue( 0, 0, "00" );
3015             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3016                 return false;
3017             }
3018             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3019                 return false;
3020             }
3021             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3022                 return false;
3023             }
3024             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3025                 return false;
3026             }
3027             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3028                 return false;
3029             }
3030             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3031                 return false;
3032             }
3033             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3034                 return false;
3035             }
3036             if ( t0.getNumberOfColumns() != 101 ) {
3037                 return false;
3038             }
3039             if ( t0.getNumberOfRows() != 11 ) {
3040                 return false;
3041             }
3042             if ( t0.getValueAsString( 49, 4 ) != null ) {
3043                 return false;
3044             }
3045             final String l = ForesterUtil.getLineSeparator();
3046             final StringBuffer source = new StringBuffer();
3047             source.append( "" + l );
3048             source.append( "# 1 1 1 1 1 1 1 1" + l );
3049             source.append( " 00 01 02 03" + l );
3050             source.append( "   10 11 12 13  " + l );
3051             source.append( "20 21 22 23 " + l );
3052             source.append( "    30  31    32 33" + l );
3053             source.append( "40 41 42 43" + l );
3054             source.append( "  # 1 1 1 1 1 " + l );
3055             source.append( "50 51 52 53 54" + l );
3056             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
3057             if ( t1.getNumberOfColumns() != 5 ) {
3058                 return false;
3059             }
3060             if ( t1.getNumberOfRows() != 6 ) {
3061                 return false;
3062             }
3063             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
3064                 return false;
3065             }
3066             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
3067                 return false;
3068             }
3069             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
3070                 return false;
3071             }
3072             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
3073                 return false;
3074             }
3075             final StringBuffer source1 = new StringBuffer();
3076             source1.append( "" + l );
3077             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3078             source1.append( " 00; 01 ;02;03" + l );
3079             source1.append( "   10; 11; 12; 13  " + l );
3080             source1.append( "20; 21; 22; 23 " + l );
3081             source1.append( "    30;  31;    32; 33" + l );
3082             source1.append( "40;41;42;43" + l );
3083             source1.append( "  # 1 1 1 1 1 " + l );
3084             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
3085             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
3086             if ( t2.getNumberOfColumns() != 5 ) {
3087                 return false;
3088             }
3089             if ( t2.getNumberOfRows() != 6 ) {
3090                 return false;
3091             }
3092             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
3093                 return false;
3094             }
3095             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
3096                 return false;
3097             }
3098             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
3099                 return false;
3100             }
3101             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
3102                 return false;
3103             }
3104             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
3105                 return false;
3106             }
3107             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
3108                 return false;
3109             }
3110             final StringBuffer source2 = new StringBuffer();
3111             source2.append( "" + l );
3112             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3113             source2.append( " 00; 01 ;02;03" + l );
3114             source2.append( "   10; 11; 12; 13  " + l );
3115             source2.append( "20; 21; 22; 23 " + l );
3116             source2.append( "                     " + l );
3117             source2.append( "    30;  31;    32; 33" + l );
3118             source2.append( "40;41;42;43" + l );
3119             source2.append( "  comment: 1 1 1 1 1 " + l );
3120             source2.append( ";;;50  ;   52; 53;;54   " + l );
3121             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
3122                                                                         ';',
3123                                                                         false,
3124                                                                         false,
3125                                                                         "comment:",
3126                                                                         false );
3127             if ( tl.size() != 2 ) {
3128                 return false;
3129             }
3130             final BasicTable<String> t3 = tl.get( 0 );
3131             final BasicTable<String> t4 = tl.get( 1 );
3132             if ( t3.getNumberOfColumns() != 4 ) {
3133                 return false;
3134             }
3135             if ( t3.getNumberOfRows() != 3 ) {
3136                 return false;
3137             }
3138             if ( t4.getNumberOfColumns() != 4 ) {
3139                 return false;
3140             }
3141             if ( t4.getNumberOfRows() != 3 ) {
3142                 return false;
3143             }
3144             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
3145                 return false;
3146             }
3147             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
3148                 return false;
3149             }
3150         }
3151         catch ( final Exception e ) {
3152             e.printStackTrace( System.out );
3153             return false;
3154         }
3155         return true;
3156     }
3157
3158     private static boolean testBasicTolXMLparsing() {
3159         try {
3160             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3161             final TolParser parser = new TolParser();
3162             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
3163             if ( parser.getErrorCount() > 0 ) {
3164                 System.out.println( parser.getErrorMessages().toString() );
3165                 return false;
3166             }
3167             if ( phylogenies_0.length != 1 ) {
3168                 return false;
3169             }
3170             final Phylogeny t1 = phylogenies_0[ 0 ];
3171             if ( t1.getNumberOfExternalNodes() != 5 ) {
3172                 return false;
3173             }
3174             if ( !t1.isRooted() ) {
3175                 return false;
3176             }
3177             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
3178                 return false;
3179             }
3180             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
3181                 return false;
3182             }
3183             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
3184                 return false;
3185             }
3186             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
3187                 return false;
3188             }
3189             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
3190             if ( parser.getErrorCount() > 0 ) {
3191                 System.out.println( parser.getErrorMessages().toString() );
3192                 return false;
3193             }
3194             if ( phylogenies_1.length != 1 ) {
3195                 return false;
3196             }
3197             final Phylogeny t2 = phylogenies_1[ 0 ];
3198             if ( t2.getNumberOfExternalNodes() != 664 ) {
3199                 return false;
3200             }
3201             if ( !t2.isRooted() ) {
3202                 return false;
3203             }
3204             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
3205                 return false;
3206             }
3207             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
3208                 return false;
3209             }
3210             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3211                 return false;
3212             }
3213             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3214                 return false;
3215             }
3216             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
3217                 return false;
3218             }
3219             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3220                     .equals( "Aquifex" ) ) {
3221                 return false;
3222             }
3223             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
3224             if ( parser.getErrorCount() > 0 ) {
3225                 System.out.println( parser.getErrorMessages().toString() );
3226                 return false;
3227             }
3228             if ( phylogenies_2.length != 1 ) {
3229                 return false;
3230             }
3231             final Phylogeny t3 = phylogenies_2[ 0 ];
3232             if ( t3.getNumberOfExternalNodes() != 184 ) {
3233                 return false;
3234             }
3235             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
3236                 return false;
3237             }
3238             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
3239                 return false;
3240             }
3241             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
3242                 return false;
3243             }
3244             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
3245             if ( parser.getErrorCount() > 0 ) {
3246                 System.out.println( parser.getErrorMessages().toString() );
3247                 return false;
3248             }
3249             if ( phylogenies_3.length != 1 ) {
3250                 return false;
3251             }
3252             final Phylogeny t4 = phylogenies_3[ 0 ];
3253             if ( t4.getNumberOfExternalNodes() != 1 ) {
3254                 return false;
3255             }
3256             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
3257                 return false;
3258             }
3259             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
3260                 return false;
3261             }
3262             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
3263                 return false;
3264             }
3265             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
3266             if ( parser.getErrorCount() > 0 ) {
3267                 System.out.println( parser.getErrorMessages().toString() );
3268                 return false;
3269             }
3270             if ( phylogenies_4.length != 1 ) {
3271                 return false;
3272             }
3273             final Phylogeny t5 = phylogenies_4[ 0 ];
3274             if ( t5.getNumberOfExternalNodes() != 13 ) {
3275                 return false;
3276             }
3277             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
3278                 return false;
3279             }
3280             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
3281                 return false;
3282             }
3283             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
3284                 return false;
3285             }
3286         }
3287         catch ( final Exception e ) {
3288             e.printStackTrace( System.out );
3289             return false;
3290         }
3291         return true;
3292     }
3293
3294     private static boolean testBasicTreeMethods() {
3295         try {
3296             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3297             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
3298             if ( t2.getNumberOfExternalNodes() != 4 ) {
3299                 return false;
3300             }
3301             if ( t2.getHeight() != 8.5 ) {
3302                 return false;
3303             }
3304             if ( !t2.isCompletelyBinary() ) {
3305                 return false;
3306             }
3307             if ( t2.isEmpty() ) {
3308                 return false;
3309             }
3310             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
3311             if ( t3.getNumberOfExternalNodes() != 5 ) {
3312                 return false;
3313             }
3314             if ( t3.getHeight() != 11 ) {
3315                 return false;
3316             }
3317             if ( t3.isCompletelyBinary() ) {
3318                 return false;
3319             }
3320             final PhylogenyNode n = t3.getNode( "ABC" );
3321             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 ];
3322             if ( t4.getNumberOfExternalNodes() != 9 ) {
3323                 return false;
3324             }
3325             if ( t4.getHeight() != 11 ) {
3326                 return false;
3327             }
3328             if ( t4.isCompletelyBinary() ) {
3329                 return false;
3330             }
3331             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)" );
3332             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
3333             if ( t5.getNumberOfExternalNodes() != 8 ) {
3334                 return false;
3335             }
3336             if ( t5.getHeight() != 15 ) {
3337                 return false;
3338             }
3339             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)" );
3340             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
3341             if ( t6.getHeight() != 15 ) {
3342                 return false;
3343             }
3344             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)" );
3345             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
3346             if ( t7.getHeight() != 15 ) {
3347                 return false;
3348             }
3349             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)" );
3350             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
3351             if ( t8.getNumberOfExternalNodes() != 10 ) {
3352                 return false;
3353             }
3354             if ( t8.getHeight() != 15 ) {
3355                 return false;
3356             }
3357             final char[] a9 = new char[] { 'a' };
3358             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
3359             if ( t9.getHeight() != 0 ) {
3360                 return false;
3361             }
3362             final char[] a10 = new char[] { 'a', ':', '6' };
3363             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
3364             if ( t10.getHeight() != 6 ) {
3365                 return false;
3366             }
3367         }
3368         catch ( final Exception e ) {
3369             e.printStackTrace( System.out );
3370             return false;
3371         }
3372         return true;
3373     }
3374
3375     private static boolean testConfidenceAssessor() {
3376         try {
3377             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3378             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3379             final Phylogeny[] ev0 = factory
3380                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3381                              new NHXParser() );
3382             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3383             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3384                 return false;
3385             }
3386             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3387                 return false;
3388             }
3389             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3390             final Phylogeny[] ev1 = factory
3391                     .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)));",
3392                              new NHXParser() );
3393             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3394             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3395                 return false;
3396             }
3397             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3398                 return false;
3399             }
3400             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3401             final Phylogeny[] ev_b = factory
3402                     .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",
3403                              new NHXParser() );
3404             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3405             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3406                 return false;
3407             }
3408             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3409                 return false;
3410             }
3411             //
3412             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3413             final Phylogeny[] ev1x = factory
3414                     .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)));",
3415                              new NHXParser() );
3416             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3417             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3418                 return false;
3419             }
3420             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3421                 return false;
3422             }
3423             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3424             final Phylogeny[] ev_bx = factory
3425                     .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",
3426                              new NHXParser() );
3427             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3428             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3429                 return false;
3430             }
3431             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3432                 return false;
3433             }
3434             final Phylogeny[] t2 = factory
3435                     .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);",
3436                              new NHXParser() );
3437             final Phylogeny[] ev2 = factory
3438                     .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);",
3439                              new NHXParser() );
3440             for( final Phylogeny target : t2 ) {
3441                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3442             }
3443             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3444                                                  new NHXParser() )[ 0 ];
3445             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3446             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3447             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3448                 return false;
3449             }
3450             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3451                 return false;
3452             }
3453             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3454                 return false;
3455             }
3456         }
3457         catch ( final Exception e ) {
3458             e.printStackTrace();
3459             return false;
3460         }
3461         return true;
3462     }
3463
3464     private static boolean testCopyOfNodeData() {
3465         try {
3466             final PhylogenyNode n1 = PhylogenyNode
3467                     .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]" );
3468             final PhylogenyNode n2 = n1.copyNodeData();
3469             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3470                 return false;
3471             }
3472         }
3473         catch ( final Exception e ) {
3474             e.printStackTrace();
3475             return false;
3476         }
3477         return true;
3478     }
3479
3480     private static boolean testCreateBalancedPhylogeny() {
3481         try {
3482             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3483             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3484                 return false;
3485             }
3486             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3487                 return false;
3488             }
3489             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3490             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3491                 return false;
3492             }
3493             if ( p1.getNumberOfExternalNodes() != 100 ) {
3494                 return false;
3495             }
3496         }
3497         catch ( final Exception e ) {
3498             e.printStackTrace();
3499             return false;
3500         }
3501         return true;
3502     }
3503
3504     private static boolean testCreateUriForSeqWeb() {
3505         try {
3506             final PhylogenyNode n = new PhylogenyNode();
3507             n.setName( "tr|B3RJ64" );
3508             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3509                 return false;
3510             }
3511             n.setName( "B0LM41_HUMAN" );
3512             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3513                 return false;
3514             }
3515             n.setName( "NP_001025424" );
3516             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3517                 return false;
3518             }
3519             n.setName( "_NM_001030253-" );
3520             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3521                 return false;
3522             }
3523             n.setName( "XM_002122186" );
3524             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3525                 return false;
3526             }
3527             n.setName( "dgh_AAA34956_gdg" );
3528             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3529                 return false;
3530             }
3531             n.setName( "AAA34956" );
3532             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3533                 return false;
3534             }
3535             n.setName( "GI:394892" );
3536             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3537                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3538                 return false;
3539             }
3540             n.setName( "gi_394892" );
3541             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3542                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3543                 return false;
3544             }
3545             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3546             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3547                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3548                 return false;
3549             }
3550             n.setName( "P12345" );
3551             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3552                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3553                 return false;
3554             }
3555             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3556             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3557                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3558                 return false;
3559             }
3560         }
3561         catch ( final Exception e ) {
3562             e.printStackTrace( System.out );
3563             return false;
3564         }
3565         return true;
3566     }
3567
3568     private static boolean testDataObjects() {
3569         try {
3570             final Confidence s0 = new Confidence();
3571             final Confidence s1 = new Confidence();
3572             if ( !s0.isEqual( s1 ) ) {
3573                 return false;
3574             }
3575             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3576             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3577             if ( s2.isEqual( s1 ) ) {
3578                 return false;
3579             }
3580             if ( !s2.isEqual( s3 ) ) {
3581                 return false;
3582             }
3583             final Confidence s4 = ( Confidence ) s3.copy();
3584             if ( !s4.isEqual( s3 ) ) {
3585                 return false;
3586             }
3587             s3.asSimpleText();
3588             s3.asText();
3589             // Taxonomy
3590             // ----------
3591             final Taxonomy t1 = new Taxonomy();
3592             final Taxonomy t2 = new Taxonomy();
3593             final Taxonomy t3 = new Taxonomy();
3594             final Taxonomy t4 = new Taxonomy();
3595             final Taxonomy t5 = new Taxonomy();
3596             t1.setIdentifier( new Identifier( "ecoli" ) );
3597             t1.setTaxonomyCode( "ECOLI" );
3598             t1.setScientificName( "E. coli" );
3599             t1.setCommonName( "coli" );
3600             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3601             if ( !t1.isEqual( t0 ) ) {
3602                 return false;
3603             }
3604             t2.setIdentifier( new Identifier( "ecoli" ) );
3605             t2.setTaxonomyCode( "OTHER" );
3606             t2.setScientificName( "what" );
3607             t2.setCommonName( "something" );
3608             if ( !t1.isEqual( t2 ) ) {
3609                 return false;
3610             }
3611             t2.setIdentifier( new Identifier( "nemve" ) );
3612             if ( t1.isEqual( t2 ) ) {
3613                 return false;
3614             }
3615             t1.setIdentifier( null );
3616             t3.setTaxonomyCode( "ECOLI" );
3617             t3.setScientificName( "what" );
3618             t3.setCommonName( "something" );
3619             if ( !t1.isEqual( t3 ) ) {
3620                 return false;
3621             }
3622             t1.setIdentifier( null );
3623             t1.setTaxonomyCode( "" );
3624             t4.setScientificName( "E. ColI" );
3625             t4.setCommonName( "something" );
3626             if ( !t1.isEqual( t4 ) ) {
3627                 return false;
3628             }
3629             t4.setScientificName( "B. subtilis" );
3630             t4.setCommonName( "something" );
3631             if ( t1.isEqual( t4 ) ) {
3632                 return false;
3633             }
3634             t1.setIdentifier( null );
3635             t1.setTaxonomyCode( "" );
3636             t1.setScientificName( "" );
3637             t5.setCommonName( "COLI" );
3638             if ( !t1.isEqual( t5 ) ) {
3639                 return false;
3640             }
3641             t5.setCommonName( "vibrio" );
3642             if ( t1.isEqual( t5 ) ) {
3643                 return false;
3644             }
3645             // Identifier
3646             // ----------
3647             final Identifier id0 = new Identifier( "123", "pfam" );
3648             final Identifier id1 = ( Identifier ) id0.copy();
3649             if ( !id1.isEqual( id1 ) ) {
3650                 return false;
3651             }
3652             if ( !id1.isEqual( id0 ) ) {
3653                 return false;
3654             }
3655             if ( !id0.isEqual( id1 ) ) {
3656                 return false;
3657             }
3658             id1.asSimpleText();
3659             id1.asText();
3660             // ProteinDomain
3661             // ---------------
3662             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3663             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3664             if ( !pd1.isEqual( pd1 ) ) {
3665                 return false;
3666             }
3667             if ( !pd1.isEqual( pd0 ) ) {
3668                 return false;
3669             }
3670             pd1.asSimpleText();
3671             pd1.asText();
3672             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3673             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3674             if ( !pd3.isEqual( pd3 ) ) {
3675                 return false;
3676             }
3677             if ( !pd2.isEqual( pd3 ) ) {
3678                 return false;
3679             }
3680             if ( !pd0.isEqual( pd3 ) ) {
3681                 return false;
3682             }
3683             pd3.asSimpleText();
3684             pd3.asText();
3685             // DomainArchitecture
3686             // ------------------
3687             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3688             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3689             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3690             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3691             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3692             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3693             domains0.add( d2 );
3694             domains0.add( d0 );
3695             domains0.add( d3 );
3696             domains0.add( d1 );
3697             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3698             if ( ds0.getNumberOfDomains() != 4 ) {
3699                 return false;
3700             }
3701             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3702             if ( !ds0.isEqual( ds0 ) ) {
3703                 return false;
3704             }
3705             if ( !ds0.isEqual( ds1 ) ) {
3706                 return false;
3707             }
3708             if ( ds1.getNumberOfDomains() != 4 ) {
3709                 return false;
3710             }
3711             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3712             domains1.add( d1 );
3713             domains1.add( d2 );
3714             domains1.add( d4 );
3715             domains1.add( d0 );
3716             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3717             if ( ds0.isEqual( ds2 ) ) {
3718                 return false;
3719             }
3720             ds1.asSimpleText();
3721             ds1.asText();
3722             ds1.toNHX();
3723             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3724             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3725                 System.out.println( ds3.toNHX() );
3726                 return false;
3727             }
3728             if ( ds3.getNumberOfDomains() != 3 ) {
3729                 return false;
3730             }
3731             // Event
3732             // -----
3733             final Event e1 = new Event( Event.EventType.fusion );
3734             if ( e1.isDuplication() ) {
3735                 return false;
3736             }
3737             if ( !e1.isFusion() ) {
3738                 return false;
3739             }
3740             if ( !e1.asText().toString().equals( "fusion" ) ) {
3741                 return false;
3742             }
3743             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3744                 return false;
3745             }
3746             final Event e11 = new Event( Event.EventType.fusion );
3747             if ( !e11.isEqual( e1 ) ) {
3748                 return false;
3749             }
3750             if ( !e11.toNHX().toString().equals( "" ) ) {
3751                 return false;
3752             }
3753             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3754             if ( e2.isDuplication() ) {
3755                 return false;
3756             }
3757             if ( !e2.isSpeciationOrDuplication() ) {
3758                 return false;
3759             }
3760             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3761                 return false;
3762             }
3763             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3764                 return false;
3765             }
3766             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3767                 return false;
3768             }
3769             if ( e11.isEqual( e2 ) ) {
3770                 return false;
3771             }
3772             final Event e2c = ( Event ) e2.copy();
3773             if ( !e2c.isEqual( e2 ) ) {
3774                 return false;
3775             }
3776             Event e3 = new Event( 1, 2, 3 );
3777             if ( e3.isDuplication() ) {
3778                 return false;
3779             }
3780             if ( e3.isSpeciation() ) {
3781                 return false;
3782             }
3783             if ( e3.isGeneLoss() ) {
3784                 return false;
3785             }
3786             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3787                 return false;
3788             }
3789             final Event e3c = ( Event ) e3.copy();
3790             final Event e3cc = ( Event ) e3c.copy();
3791             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3792                 return false;
3793             }
3794             e3 = null;
3795             if ( !e3c.isEqual( e3cc ) ) {
3796                 return false;
3797             }
3798             Event e4 = new Event( 1, 2, 3 );
3799             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3800                 return false;
3801             }
3802             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3803                 return false;
3804             }
3805             final Event e4c = ( Event ) e4.copy();
3806             e4 = null;
3807             final Event e4cc = ( Event ) e4c.copy();
3808             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3809                 return false;
3810             }
3811             if ( !e4c.isEqual( e4cc ) ) {
3812                 return false;
3813             }
3814             final Event e5 = new Event();
3815             if ( !e5.isUnassigned() ) {
3816                 return false;
3817             }
3818             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3819                 return false;
3820             }
3821             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3822                 return false;
3823             }
3824             final Event e6 = new Event( 1, 0, 0 );
3825             if ( !e6.asText().toString().equals( "duplication" ) ) {
3826                 return false;
3827             }
3828             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3829                 return false;
3830             }
3831             final Event e7 = new Event( 0, 1, 0 );
3832             if ( !e7.asText().toString().equals( "speciation" ) ) {
3833                 return false;
3834             }
3835             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3836                 return false;
3837             }
3838             final Event e8 = new Event( 0, 0, 1 );
3839             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3840                 return false;
3841             }
3842             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3843                 return false;
3844             }
3845         }
3846         catch ( final Exception e ) {
3847             e.printStackTrace( System.out );
3848             return false;
3849         }
3850         return true;
3851     }
3852
3853     private static boolean testDeletionOfExternalNodes() {
3854         try {
3855             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3856             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3857             final PhylogenyWriter w = new PhylogenyWriter();
3858             if ( t0.isEmpty() ) {
3859                 return false;
3860             }
3861             if ( t0.getNumberOfExternalNodes() != 1 ) {
3862                 return false;
3863             }
3864             t0.deleteSubtree( t0.getNode( "A" ), false );
3865             if ( t0.getNumberOfExternalNodes() != 0 ) {
3866                 return false;
3867             }
3868             if ( !t0.isEmpty() ) {
3869                 return false;
3870             }
3871             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3872             if ( t1.getNumberOfExternalNodes() != 2 ) {
3873                 return false;
3874             }
3875             t1.deleteSubtree( t1.getNode( "A" ), false );
3876             if ( t1.getNumberOfExternalNodes() != 1 ) {
3877                 return false;
3878             }
3879             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3880                 return false;
3881             }
3882             t1.deleteSubtree( t1.getNode( "B" ), false );
3883             if ( t1.getNumberOfExternalNodes() != 1 ) {
3884                 return false;
3885             }
3886             t1.deleteSubtree( t1.getNode( "r" ), false );
3887             if ( !t1.isEmpty() ) {
3888                 return false;
3889             }
3890             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3891             if ( t2.getNumberOfExternalNodes() != 3 ) {
3892                 return false;
3893             }
3894             t2.deleteSubtree( t2.getNode( "B" ), false );
3895             if ( t2.getNumberOfExternalNodes() != 2 ) {
3896                 return false;
3897             }
3898             t2.toNewHampshireX();
3899             PhylogenyNode n = t2.getNode( "A" );
3900             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3901                 return false;
3902             }
3903             t2.deleteSubtree( t2.getNode( "A" ), false );
3904             if ( t2.getNumberOfExternalNodes() != 2 ) {
3905                 return false;
3906             }
3907             t2.deleteSubtree( t2.getNode( "C" ), true );
3908             if ( t2.getNumberOfExternalNodes() != 1 ) {
3909                 return false;
3910             }
3911             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3912             if ( t3.getNumberOfExternalNodes() != 4 ) {
3913                 return false;
3914             }
3915             t3.deleteSubtree( t3.getNode( "B" ), true );
3916             if ( t3.getNumberOfExternalNodes() != 3 ) {
3917                 return false;
3918             }
3919             n = t3.getNode( "A" );
3920             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3921                 return false;
3922             }
3923             n = n.getNextExternalNode();
3924             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3925                 return false;
3926             }
3927             t3.deleteSubtree( t3.getNode( "A" ), true );
3928             if ( t3.getNumberOfExternalNodes() != 2 ) {
3929                 return false;
3930             }
3931             n = t3.getNode( "C" );
3932             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3933                 return false;
3934             }
3935             t3.deleteSubtree( t3.getNode( "C" ), true );
3936             if ( t3.getNumberOfExternalNodes() != 1 ) {
3937                 return false;
3938             }
3939             t3.deleteSubtree( t3.getNode( "D" ), true );
3940             if ( t3.getNumberOfExternalNodes() != 0 ) {
3941                 return false;
3942             }
3943             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3944             if ( t4.getNumberOfExternalNodes() != 6 ) {
3945                 return false;
3946             }
3947             t4.deleteSubtree( t4.getNode( "B2" ), true );
3948             if ( t4.getNumberOfExternalNodes() != 5 ) {
3949                 return false;
3950             }
3951             String s = w.toNewHampshire( t4, true ).toString();
3952             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3953                 return false;
3954             }
3955             t4.deleteSubtree( t4.getNode( "B11" ), true );
3956             if ( t4.getNumberOfExternalNodes() != 4 ) {
3957                 return false;
3958             }
3959             t4.deleteSubtree( t4.getNode( "C" ), true );
3960             if ( t4.getNumberOfExternalNodes() != 3 ) {
3961                 return false;
3962             }
3963             n = t4.getNode( "A" );
3964             n = n.getNextExternalNode();
3965             if ( !n.getName().equals( "B12" ) ) {
3966                 return false;
3967             }
3968             n = n.getNextExternalNode();
3969             if ( !n.getName().equals( "D" ) ) {
3970                 return false;
3971             }
3972             s = w.toNewHampshire( t4, true ).toString();
3973             if ( !s.equals( "((A,B12),D);" ) ) {
3974                 return false;
3975             }
3976             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3977             t5.deleteSubtree( t5.getNode( "A" ), true );
3978             if ( t5.getNumberOfExternalNodes() != 5 ) {
3979                 return false;
3980             }
3981             s = w.toNewHampshire( t5, true ).toString();
3982             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3983                 return false;
3984             }
3985             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3986             t6.deleteSubtree( t6.getNode( "B11" ), true );
3987             if ( t6.getNumberOfExternalNodes() != 5 ) {
3988                 return false;
3989             }
3990             s = w.toNewHampshire( t6, false ).toString();
3991             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3992                 return false;
3993             }
3994             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3995             t7.deleteSubtree( t7.getNode( "B12" ), true );
3996             if ( t7.getNumberOfExternalNodes() != 5 ) {
3997                 return false;
3998             }
3999             s = w.toNewHampshire( t7, true ).toString();
4000             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
4001                 return false;
4002             }
4003             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4004             t8.deleteSubtree( t8.getNode( "B2" ), true );
4005             if ( t8.getNumberOfExternalNodes() != 5 ) {
4006                 return false;
4007             }
4008             s = w.toNewHampshire( t8, false ).toString();
4009             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
4010                 return false;
4011             }
4012             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4013             t9.deleteSubtree( t9.getNode( "C" ), true );
4014             if ( t9.getNumberOfExternalNodes() != 5 ) {
4015                 return false;
4016             }
4017             s = w.toNewHampshire( t9, true ).toString();
4018             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
4019                 return false;
4020             }
4021             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4022             t10.deleteSubtree( t10.getNode( "D" ), true );
4023             if ( t10.getNumberOfExternalNodes() != 5 ) {
4024                 return false;
4025             }
4026             s = w.toNewHampshire( t10, true ).toString();
4027             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
4028                 return false;
4029             }
4030             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
4031             t11.deleteSubtree( t11.getNode( "A" ), true );
4032             if ( t11.getNumberOfExternalNodes() != 2 ) {
4033                 return false;
4034             }
4035             s = w.toNewHampshire( t11, true ).toString();
4036             if ( !s.equals( "(B,C);" ) ) {
4037                 return false;
4038             }
4039             t11.deleteSubtree( t11.getNode( "C" ), true );
4040             if ( t11.getNumberOfExternalNodes() != 1 ) {
4041                 return false;
4042             }
4043             s = w.toNewHampshire( t11, false ).toString();
4044             if ( !s.equals( "B;" ) ) {
4045                 return false;
4046             }
4047             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
4048             t12.deleteSubtree( t12.getNode( "B2" ), true );
4049             if ( t12.getNumberOfExternalNodes() != 8 ) {
4050                 return false;
4051             }
4052             s = w.toNewHampshire( t12, true ).toString();
4053             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
4054                 return false;
4055             }
4056             t12.deleteSubtree( t12.getNode( "B3" ), true );
4057             if ( t12.getNumberOfExternalNodes() != 7 ) {
4058                 return false;
4059             }
4060             s = w.toNewHampshire( t12, true ).toString();
4061             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
4062                 return false;
4063             }
4064             t12.deleteSubtree( t12.getNode( "C3" ), true );
4065             if ( t12.getNumberOfExternalNodes() != 6 ) {
4066                 return false;
4067             }
4068             s = w.toNewHampshire( t12, true ).toString();
4069             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
4070                 return false;
4071             }
4072             t12.deleteSubtree( t12.getNode( "A1" ), true );
4073             if ( t12.getNumberOfExternalNodes() != 5 ) {
4074                 return false;
4075             }
4076             s = w.toNewHampshire( t12, true ).toString();
4077             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
4078                 return false;
4079             }
4080             t12.deleteSubtree( t12.getNode( "B1" ), true );
4081             if ( t12.getNumberOfExternalNodes() != 4 ) {
4082                 return false;
4083             }
4084             s = w.toNewHampshire( t12, true ).toString();
4085             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
4086                 return false;
4087             }
4088             t12.deleteSubtree( t12.getNode( "A3" ), true );
4089             if ( t12.getNumberOfExternalNodes() != 3 ) {
4090                 return false;
4091             }
4092             s = w.toNewHampshire( t12, true ).toString();
4093             if ( !s.equals( "(A2,(C1,C2));" ) ) {
4094                 return false;
4095             }
4096             t12.deleteSubtree( t12.getNode( "A2" ), true );
4097             if ( t12.getNumberOfExternalNodes() != 2 ) {
4098                 return false;
4099             }
4100             s = w.toNewHampshire( t12, true ).toString();
4101             if ( !s.equals( "(C1,C2);" ) ) {
4102                 return false;
4103             }
4104             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
4105             t13.deleteSubtree( t13.getNode( "D" ), true );
4106             if ( t13.getNumberOfExternalNodes() != 4 ) {
4107                 return false;
4108             }
4109             s = w.toNewHampshire( t13, true ).toString();
4110             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
4111                 return false;
4112             }
4113             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
4114             t14.deleteSubtree( t14.getNode( "E" ), true );
4115             if ( t14.getNumberOfExternalNodes() != 5 ) {
4116                 return false;
4117             }
4118             s = w.toNewHampshire( t14, true ).toString();
4119             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
4120                 return false;
4121             }
4122             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
4123             t15.deleteSubtree( t15.getNode( "B2" ), true );
4124             if ( t15.getNumberOfExternalNodes() != 11 ) {
4125                 return false;
4126             }
4127             t15.deleteSubtree( t15.getNode( "B1" ), true );
4128             if ( t15.getNumberOfExternalNodes() != 10 ) {
4129                 return false;
4130             }
4131             t15.deleteSubtree( t15.getNode( "B3" ), true );
4132             if ( t15.getNumberOfExternalNodes() != 9 ) {
4133                 return false;
4134             }
4135             t15.deleteSubtree( t15.getNode( "B4" ), true );
4136             if ( t15.getNumberOfExternalNodes() != 8 ) {
4137                 return false;
4138             }
4139             t15.deleteSubtree( t15.getNode( "A1" ), true );
4140             if ( t15.getNumberOfExternalNodes() != 7 ) {
4141                 return false;
4142             }
4143             t15.deleteSubtree( t15.getNode( "C4" ), true );
4144             if ( t15.getNumberOfExternalNodes() != 6 ) {
4145                 return false;
4146             }
4147         }
4148         catch ( final Exception e ) {
4149             e.printStackTrace( System.out );
4150             return false;
4151         }
4152         return true;
4153     }
4154
4155     private static boolean testDescriptiveStatistics() {
4156         try {
4157             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
4158             dss1.addValue( 82 );
4159             dss1.addValue( 78 );
4160             dss1.addValue( 70 );
4161             dss1.addValue( 58 );
4162             dss1.addValue( 42 );
4163             if ( dss1.getN() != 5 ) {
4164                 return false;
4165             }
4166             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
4167                 return false;
4168             }
4169             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
4170                 return false;
4171             }
4172             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
4173                 return false;
4174             }
4175             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
4176                 return false;
4177             }
4178             if ( !Test.isEqual( dss1.median(), 70 ) ) {
4179                 return false;
4180             }
4181             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
4182                 return false;
4183             }
4184             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
4185                 return false;
4186             }
4187             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
4188                 return false;
4189             }
4190             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
4191                 return false;
4192             }
4193             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
4194                 return false;
4195             }
4196             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
4197                 return false;
4198             }
4199             dss1.addValue( 123 );
4200             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
4201                 return false;
4202             }
4203             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
4204                 return false;
4205             }
4206             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
4207                 return false;
4208             }
4209             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
4210             dss2.addValue( -1.85 );
4211             dss2.addValue( 57.5 );
4212             dss2.addValue( 92.78 );
4213             dss2.addValue( 57.78 );
4214             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
4215                 return false;
4216             }
4217             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
4218                 return false;
4219             }
4220             final double[] a = dss2.getDataAsDoubleArray();
4221             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
4222                 return false;
4223             }
4224             dss2.addValue( -100 );
4225             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
4226                 return false;
4227             }
4228             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
4229                 return false;
4230             }
4231             final double[] ds = new double[ 14 ];
4232             ds[ 0 ] = 34;
4233             ds[ 1 ] = 23;
4234             ds[ 2 ] = 1;
4235             ds[ 3 ] = 32;
4236             ds[ 4 ] = 11;
4237             ds[ 5 ] = 2;
4238             ds[ 6 ] = 12;
4239             ds[ 7 ] = 33;
4240             ds[ 8 ] = 13;
4241             ds[ 9 ] = 22;
4242             ds[ 10 ] = 21;
4243             ds[ 11 ] = 35;
4244             ds[ 12 ] = 24;
4245             ds[ 13 ] = 31;
4246             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
4247             if ( bins.length != 4 ) {
4248                 return false;
4249             }
4250             if ( bins[ 0 ] != 2 ) {
4251                 return false;
4252             }
4253             if ( bins[ 1 ] != 3 ) {
4254                 return false;
4255             }
4256             if ( bins[ 2 ] != 4 ) {
4257                 return false;
4258             }
4259             if ( bins[ 3 ] != 5 ) {
4260                 return false;
4261             }
4262             final double[] ds1 = new double[ 9 ];
4263             ds1[ 0 ] = 10.0;
4264             ds1[ 1 ] = 19.0;
4265             ds1[ 2 ] = 9.999;
4266             ds1[ 3 ] = 0.0;
4267             ds1[ 4 ] = 39.9;
4268             ds1[ 5 ] = 39.999;
4269             ds1[ 6 ] = 30.0;
4270             ds1[ 7 ] = 19.999;
4271             ds1[ 8 ] = 30.1;
4272             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
4273             if ( bins1.length != 4 ) {
4274                 return false;
4275             }
4276             if ( bins1[ 0 ] != 2 ) {
4277                 return false;
4278             }
4279             if ( bins1[ 1 ] != 3 ) {
4280                 return false;
4281             }
4282             if ( bins1[ 2 ] != 0 ) {
4283                 return false;
4284             }
4285             if ( bins1[ 3 ] != 4 ) {
4286                 return false;
4287             }
4288             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
4289             if ( bins1_1.length != 3 ) {
4290                 return false;
4291             }
4292             if ( bins1_1[ 0 ] != 3 ) {
4293                 return false;
4294             }
4295             if ( bins1_1[ 1 ] != 2 ) {
4296                 return false;
4297             }
4298             if ( bins1_1[ 2 ] != 4 ) {
4299                 return false;
4300             }
4301             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
4302             if ( bins1_2.length != 3 ) {
4303                 return false;
4304             }
4305             if ( bins1_2[ 0 ] != 2 ) {
4306                 return false;
4307             }
4308             if ( bins1_2[ 1 ] != 2 ) {
4309                 return false;
4310             }
4311             if ( bins1_2[ 2 ] != 2 ) {
4312                 return false;
4313             }
4314             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
4315             dss3.addValue( 1 );
4316             dss3.addValue( 1 );
4317             dss3.addValue( 1 );
4318             dss3.addValue( 2 );
4319             dss3.addValue( 3 );
4320             dss3.addValue( 4 );
4321             dss3.addValue( 5 );
4322             dss3.addValue( 5 );
4323             dss3.addValue( 5 );
4324             dss3.addValue( 6 );
4325             dss3.addValue( 7 );
4326             dss3.addValue( 8 );
4327             dss3.addValue( 9 );
4328             dss3.addValue( 10 );
4329             dss3.addValue( 10 );
4330             dss3.addValue( 10 );
4331             final AsciiHistogram histo = new AsciiHistogram( dss3 );
4332             histo.toStringBuffer( 10, '=', 40, 5 );
4333             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
4334         }
4335         catch ( final Exception e ) {
4336             e.printStackTrace( System.out );
4337             return false;
4338         }
4339         return true;
4340     }
4341
4342     private static boolean testDir( final String file ) {
4343         try {
4344             final File f = new File( file );
4345             if ( !f.exists() ) {
4346                 return false;
4347             }
4348             if ( !f.isDirectory() ) {
4349                 return false;
4350             }
4351             if ( !f.canRead() ) {
4352                 return false;
4353             }
4354         }
4355         catch ( final Exception e ) {
4356             return false;
4357         }
4358         return true;
4359     }
4360
4361     private static boolean testEbiEntryRetrieval() {
4362         try {
4363             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
4364             if ( !entry.getAccession().equals( "AAK41263" ) ) {
4365                 System.out.println( entry.getAccession() );
4366                 return false;
4367             }
4368             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
4369                 System.out.println( entry.getTaxonomyScientificName() );
4370                 return false;
4371             }
4372             if ( !entry.getSequenceName()
4373                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4374                 System.out.println( entry.getSequenceName() );
4375                 return false;
4376             }
4377             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4378                 System.out.println( entry.getGeneName() );
4379                 return false;
4380             }
4381             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4382                 System.out.println( entry.getTaxonomyIdentifier() );
4383                 return false;
4384             }
4385             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4386                 System.out.println( entry.getAnnotations().first().getRefValue() );
4387                 return false;
4388             }
4389             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4390                 System.out.println( entry.getAnnotations().first().getRefSource() );
4391                 return false;
4392             }
4393             if ( entry.getCrossReferences().size() < 1 ) {
4394                 return false;
4395             }
4396             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4397             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4398                 return false;
4399             }
4400             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4401                 System.out.println( entry1.getTaxonomyScientificName() );
4402                 return false;
4403             }
4404             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4405                 System.out.println( entry1.getSequenceName() );
4406                 return false;
4407             }
4408             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4409                 System.out.println( entry1.getTaxonomyIdentifier() );
4410                 return false;
4411             }
4412             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4413                 System.out.println( entry1.getGeneName() );
4414                 return false;
4415             }
4416             if ( entry1.getCrossReferences().size() < 1 ) {
4417                 return false;
4418             }
4419             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4420             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4421                 return false;
4422             }
4423             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4424                 System.out.println( entry2.getTaxonomyScientificName() );
4425                 return false;
4426             }
4427             if ( !entry2.getSequenceName()
4428                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4429                 System.out.println( entry2.getSequenceName() );
4430                 return false;
4431             }
4432             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4433                 System.out.println( entry2.getTaxonomyIdentifier() );
4434                 return false;
4435             }
4436             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4437                 System.out.println( entry2.getGeneName() );
4438                 return false;
4439             }
4440             if ( entry2.getCrossReferences().size() < 1 ) {
4441                 return false;
4442             }
4443             if ( !entry2.getChromosome().equals( "20" ) ) {
4444                 return false;
4445             }
4446             if ( !entry2.getMap().equals( "20q11.22" ) ) {
4447                 return false;
4448             }
4449             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4450             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4451                 return false;
4452             }
4453             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4454                 System.out.println( entry3.getTaxonomyScientificName() );
4455                 return false;
4456             }
4457             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4458                 System.out.println( entry3.getSequenceName() );
4459                 return false;
4460             }
4461             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4462                 System.out.println( entry3.getTaxonomyIdentifier() );
4463                 return false;
4464             }
4465             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4466                 System.out.println( entry3.getSequenceSymbol() );
4467                 return false;
4468             }
4469             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4470                 return false;
4471             }
4472             if ( entry3.getCrossReferences().size() < 1 ) {
4473                 return false;
4474             }
4475             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4476             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4477                 return false;
4478             }
4479             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4480                 System.out.println( entry4.getTaxonomyScientificName() );
4481                 return false;
4482             }
4483             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4484                 System.out.println( entry4.getSequenceName() );
4485                 return false;
4486             }
4487             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4488                 System.out.println( entry4.getTaxonomyIdentifier() );
4489                 return false;
4490             }
4491             if ( !entry4.getGeneName().equals( "ras" ) ) {
4492                 System.out.println( entry4.getGeneName() );
4493                 return false;
4494             }
4495             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4496             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4497                 return false;
4498             }
4499             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4500                 System.out.println( entry5.getTaxonomyScientificName() );
4501                 return false;
4502             }
4503             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4504                 System.out.println( entry5.getSequenceName() );
4505                 return false;
4506             }
4507             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4508                 System.out.println( entry5.getTaxonomyIdentifier() );
4509                 return false;
4510             }
4511             final SequenceDatabaseEntry entry6 = SequenceDbWsTools.obtainEntry( "M30539" );
4512             if ( !entry6.getAccession().equals( "M30539" ) ) {
4513                 return false;
4514             }
4515             if ( !entry6.getGeneName().equals( "ras" ) ) {
4516                 return false;
4517             }
4518             if ( !entry6.getSequenceName().equals( "Human SK2 c-Ha-ras-1 oncogene-encoded protein gene, exon 1" ) ) {
4519                 return false;
4520             }
4521             if ( !entry6.getTaxonomyIdentifier().equals( "9606" ) ) {
4522                 return false;
4523             }
4524             if ( !entry6.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4525                 return false;
4526             }
4527             if ( entry6.getCrossReferences().size() < 1 ) {
4528                 return false;
4529             }
4530         }
4531         catch ( final IOException e ) {
4532             System.out.println();
4533             System.out.println( "the following might be due to absence internet connection:" );
4534             e.printStackTrace( System.out );
4535             return true;
4536         }
4537         catch ( final Exception e ) {
4538             e.printStackTrace();
4539             return false;
4540         }
4541         return true;
4542     }
4543
4544     private static boolean testExternalNodeRelatedMethods() {
4545         try {
4546             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4547             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4548             PhylogenyNode n = t1.getNode( "A" );
4549             n = n.getNextExternalNode();
4550             if ( !n.getName().equals( "B" ) ) {
4551                 return false;
4552             }
4553             n = n.getNextExternalNode();
4554             if ( !n.getName().equals( "C" ) ) {
4555                 return false;
4556             }
4557             n = n.getNextExternalNode();
4558             if ( !n.getName().equals( "D" ) ) {
4559                 return false;
4560             }
4561             n = t1.getNode( "B" );
4562             while ( !n.isLastExternalNode() ) {
4563                 n = n.getNextExternalNode();
4564             }
4565             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4566             n = t2.getNode( "A" );
4567             n = n.getNextExternalNode();
4568             if ( !n.getName().equals( "B" ) ) {
4569                 return false;
4570             }
4571             n = n.getNextExternalNode();
4572             if ( !n.getName().equals( "C" ) ) {
4573                 return false;
4574             }
4575             n = n.getNextExternalNode();
4576             if ( !n.getName().equals( "D" ) ) {
4577                 return false;
4578             }
4579             n = t2.getNode( "B" );
4580             while ( !n.isLastExternalNode() ) {
4581                 n = n.getNextExternalNode();
4582             }
4583             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4584             n = t3.getNode( "A" );
4585             n = n.getNextExternalNode();
4586             if ( !n.getName().equals( "B" ) ) {
4587                 return false;
4588             }
4589             n = n.getNextExternalNode();
4590             if ( !n.getName().equals( "C" ) ) {
4591                 return false;
4592             }
4593             n = n.getNextExternalNode();
4594             if ( !n.getName().equals( "D" ) ) {
4595                 return false;
4596             }
4597             n = n.getNextExternalNode();
4598             if ( !n.getName().equals( "E" ) ) {
4599                 return false;
4600             }
4601             n = n.getNextExternalNode();
4602             if ( !n.getName().equals( "F" ) ) {
4603                 return false;
4604             }
4605             n = n.getNextExternalNode();
4606             if ( !n.getName().equals( "G" ) ) {
4607                 return false;
4608             }
4609             n = n.getNextExternalNode();
4610             if ( !n.getName().equals( "H" ) ) {
4611                 return false;
4612             }
4613             n = t3.getNode( "B" );
4614             while ( !n.isLastExternalNode() ) {
4615                 n = n.getNextExternalNode();
4616             }
4617             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4618             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4619                 final PhylogenyNode node = iter.next();
4620             }
4621             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4622             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4623                 final PhylogenyNode node = iter.next();
4624             }
4625             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4626             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4627             if ( !iter.next().getName().equals( "A" ) ) {
4628                 return false;
4629             }
4630             if ( !iter.next().getName().equals( "B" ) ) {
4631                 return false;
4632             }
4633             if ( !iter.next().getName().equals( "C" ) ) {
4634                 return false;
4635             }
4636             if ( !iter.next().getName().equals( "D" ) ) {
4637                 return false;
4638             }
4639             if ( !iter.next().getName().equals( "E" ) ) {
4640                 return false;
4641             }
4642             if ( !iter.next().getName().equals( "F" ) ) {
4643                 return false;
4644             }
4645             if ( iter.hasNext() ) {
4646                 return false;
4647             }
4648         }
4649         catch ( final Exception e ) {
4650             e.printStackTrace( System.out );
4651             return false;
4652         }
4653         return true;
4654     }
4655
4656     private static boolean testExtractSNFromNodeName() {
4657         try {
4658             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4659                 return false;
4660             }
4661             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4662                 return false;
4663             }
4664             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4665                 return false;
4666             }
4667             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4668                     .equals( "Mus musculus musculus" ) ) {
4669                 return false;
4670             }
4671             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4672                     .equals( "Mus musculus musculus" ) ) {
4673                 return false;
4674             }
4675             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4676                     .equals( "Mus musculus musculus" ) ) {
4677                 return false;
4678             }
4679             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4680                     .equals( "Mus musculus musculus" ) ) {
4681                 return false;
4682             }
4683             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4684                 return false;
4685             }
4686             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4687                     .equals( "Mus musculus musculus" ) ) {
4688                 return false;
4689             }
4690             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4691                     .equals( "Mus musculus musculus" ) ) {
4692                 return false;
4693             }
4694             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4695                 return false;
4696             }
4697             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4698                 return false;
4699             }
4700             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4701                 return false;
4702             }
4703             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4704                 return false;
4705             }
4706             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4707                     .equals( "Mus musculus musculus" ) ) {
4708                 return false;
4709             }
4710             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4711                 return false;
4712             }
4713             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4714                 return false;
4715             }
4716             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4717                 return false;
4718             }
4719             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4720                 return false;
4721             }
4722             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4723                 return false;
4724             }
4725             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4726                 return false;
4727             }
4728             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4729                 return false;
4730             }
4731             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4732                 return false;
4733             }
4734             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4735                     .equals( "Mus musculus" ) ) {
4736                 return false;
4737             }
4738             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4739                     .equals( "Mus musculus" ) ) {
4740                 return false;
4741             }
4742             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4743                 return false;
4744             }
4745             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4746                     .equals( "Mus musculus musculus" ) ) {
4747                 return false;
4748             }
4749             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4750                     .equals( "Mus musculus musculus" ) ) {
4751                 return false;
4752             }
4753             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4754                     .equals( "Mus musculus musculus" ) ) {
4755                 return false;
4756             }
4757             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4758                 return false;
4759             }
4760             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4761                     .equals( "Pilostyles mexicana" ) ) {
4762                 return false;
4763             }
4764             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4765                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4766                 return false;
4767             }
4768             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4769                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4770                 return false;
4771             }
4772             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4773                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4774                 return false;
4775             }
4776             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4777                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4778                 return false;
4779             }
4780             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4781                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4782                 return false;
4783             }
4784             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4785                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4786                 return false;
4787             }
4788             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4789                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4790                 return false;
4791             }
4792             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4793                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4794                 return false;
4795             }
4796             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4797                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4798                 return false;
4799             }
4800             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4801                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4802                 return false;
4803             }
4804             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4805                     .equals( "Escherichia coli (strain K12)" ) ) {
4806                 return false;
4807             }
4808             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4809                     .equals( "Escherichia coli (strain K12)" ) ) {
4810                 return false;
4811             }
4812             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4813                     .equals( "Escherichia coli (str. K12)" ) ) {
4814                 return false;
4815             }
4816             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4817                     .equals( "Escherichia coli (str. K12)" ) ) {
4818                 return false;
4819             }
4820             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4821                     .equals( "Escherichia coli (str. K12)" ) ) {
4822                 return false;
4823             }
4824             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4825                     .equals( "Escherichia coli (var. K12)" ) ) {
4826                 return false;
4827             }
4828             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4829                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4830                 return false;
4831             }
4832             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4833                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4834                 return false;
4835             }
4836             if ( !ParserUtils
4837                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4838                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4839                 return false;
4840             }
4841             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4842                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4843                 return false;
4844             }
4845             if ( !ParserUtils
4846                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4847                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4848                 return false;
4849             }
4850             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4851                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4852                 return false;
4853             }
4854             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4855                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4856                 return false;
4857             }
4858             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4859                 return false;
4860             }
4861             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4862                 return false;
4863             }
4864             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4865                 return false;
4866             }
4867             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4868                     .equals( "Macrocera sp." ) ) {
4869                 return false;
4870             }
4871             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4872                 return false;
4873             }
4874             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4875                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4876                 return false;
4877             }
4878             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4879                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4880                 return false;
4881             }
4882             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4883                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4884                 return false;
4885             }
4886             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4887                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4888                 return false;
4889             }
4890         }
4891         catch ( final Exception e ) {
4892             e.printStackTrace( System.out );
4893             return false;
4894         }
4895         return true;
4896     }
4897
4898     private static boolean testExtractTaxonomyDataFromNodeName() {
4899         try {
4900             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
4901             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4902                 return false;
4903             }
4904             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
4905             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4906                 return false;
4907             }
4908             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
4909             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4910                 return false;
4911             }
4912             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
4913             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4914                 return false;
4915             }
4916             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
4917             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4918                 return false;
4919             }
4920             n = new PhylogenyNode( "HNRPR_HUMAN" );
4921             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4922                 return false;
4923             }
4924             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
4925             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4926                 return false;
4927             }
4928         }
4929         catch ( final Exception e ) {
4930             e.printStackTrace( System.out );
4931             return false;
4932         }
4933         return true;
4934     }
4935
4936     private static boolean testExtractTaxonomyCodeFromNodeName() {
4937         try {
4938             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4939                 return false;
4940             }
4941             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4942                     .equals( "SOYBN" ) ) {
4943                 return false;
4944             }
4945             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4946                     .equals( "ARATH" ) ) {
4947                 return false;
4948             }
4949             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4950                     .equals( "ARATH" ) ) {
4951                 return false;
4952             }
4953             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4954                 return false;
4955             }
4956             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4957                 return false;
4958             }
4959             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4960                 return false;
4961             }
4962             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4963                     .equals( "SOYBN" ) ) {
4964                 return false;
4965             }
4966             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4967                     .equals( "SOYBN" ) ) {
4968                 return false;
4969             }
4970             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4971                     .equals( "SOYBN" ) ) {
4972                 return false;
4973             }
4974             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4975                     .equals( "SOYBN" ) ) {
4976                 return false;
4977             }
4978             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4979                     .equals( "SOYBN" ) ) {
4980                 return false;
4981             }
4982             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4983                     .equals( "SOYBN" ) ) {
4984                 return false;
4985             }
4986             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4987                     .equals( "SOYBN" ) ) {
4988                 return false;
4989             }
4990             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4991                     .equals( "SOYBN" ) ) {
4992                 return false;
4993             }
4994             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4995                 return false;
4996             }
4997             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4998                     .equals( "SOYBN" ) ) {
4999                 return false;
5000             }
5001             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
5002                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
5003                 return false;
5004             }
5005             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
5006                     .equals( "9YX45" ) ) {
5007                 return false;
5008             }
5009             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
5010                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5011                                                                .equals( "MOUSE" ) ) {
5012                 return false;
5013             }
5014             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
5015                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5016                                                                .equals( "MOUSE" ) ) {
5017                 return false;
5018             }
5019             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
5020                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5021                                                                .equals( "MOUSE" ) ) {
5022                 return false;
5023             }
5024             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
5025                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5026                 return false;
5027             }
5028             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
5029                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5030                 return false;
5031             }
5032             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5033                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
5034                 return false;
5035             }
5036             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5037                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
5038                 return false;
5039             }
5040             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
5041                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
5042                 return false;
5043             }
5044             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
5045                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5046                 return false;
5047             }
5048             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
5049                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5050                 return false;
5051             }
5052             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5053                     .equals( "RAT" ) ) {
5054                 return false;
5055             }
5056             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5057                     .equals( "PIG" ) ) {
5058                 return false;
5059             }
5060             if ( !ParserUtils
5061                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5062                     .equals( "MOUSE" ) ) {
5063                 return false;
5064             }
5065             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5066                     .equals( "MOUSE" ) ) {
5067                 return false;
5068             }
5069             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5070                 return false;
5071             }
5072         }
5073         catch ( final Exception e ) {
5074             e.printStackTrace( System.out );
5075             return false;
5076         }
5077         return true;
5078     }
5079
5080     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
5081         try {
5082             PhylogenyNode n = new PhylogenyNode();
5083             n.setName( "tr|B3RJ64" );
5084             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5085                 return false;
5086             }
5087             n.setName( "tr.B3RJ64" );
5088             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5089                 return false;
5090             }
5091             n.setName( "tr=B3RJ64" );
5092             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5093                 return false;
5094             }
5095             n.setName( "tr-B3RJ64" );
5096             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5097                 return false;
5098             }
5099             n.setName( "tr/B3RJ64" );
5100             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5101                 return false;
5102             }
5103             n.setName( "tr\\B3RJ64" );
5104             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5105                 return false;
5106             }
5107             n.setName( "tr_B3RJ64" );
5108             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5109                 return false;
5110             }
5111             n.setName( " tr|B3RJ64 " );
5112             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5113                 return false;
5114             }
5115             n.setName( "-tr|B3RJ64-" );
5116             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5117                 return false;
5118             }
5119             n.setName( "-tr=B3RJ64-" );
5120             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5121                 return false;
5122             }
5123             n.setName( "_tr=B3RJ64_" );
5124             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5125                 return false;
5126             }
5127             n.setName( " tr_tr|B3RJ64_sp|123 " );
5128             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5129                 return false;
5130             }
5131             n.setName( "B3RJ64" );
5132             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5133                 return false;
5134             }
5135             n.setName( "sp|B3RJ64" );
5136             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5137                 return false;
5138             }
5139             n.setName( "sp|B3RJ64C" );
5140             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5141                 return false;
5142             }
5143             n.setName( "sp B3RJ64" );
5144             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5145                 return false;
5146             }
5147             n.setName( "sp|B3RJ6X" );
5148             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5149                 return false;
5150             }
5151             n.setName( "sp|B3RJ6" );
5152             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5153                 return false;
5154             }
5155             n.setName( "K1PYK7_CRAGI" );
5156             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5157                 return false;
5158             }
5159             n.setName( "K1PYK7_PEA" );
5160             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
5161                 return false;
5162             }
5163             n.setName( "K1PYK7_RAT" );
5164             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
5165                 return false;
5166             }
5167             n.setName( "K1PYK7_PIG" );
5168             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5169                 return false;
5170             }
5171             n.setName( "~K1PYK7_PIG~" );
5172             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5173                 return false;
5174             }
5175             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
5176             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5177                 return false;
5178             }
5179             n.setName( "K1PYKX_CRAGI" );
5180             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5181                 return false;
5182             }
5183             n.setName( "XXXXX_CRAGI" );
5184             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
5185                 return false;
5186             }
5187             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
5188             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
5189                 return false;
5190             }
5191             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
5192             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5193                 return false;
5194             }
5195             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
5196             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
5197                 return false;
5198             }
5199             n = new PhylogenyNode();
5200             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
5201             seq.setSymbol( "K1PYK7_CRAGI" );
5202             n.getNodeData().addSequence( seq );
5203             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5204                 return false;
5205             }
5206             seq.setSymbol( "tr|B3RJ64" );
5207             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5208                 return false;
5209             }
5210             n = new PhylogenyNode();
5211             seq = new org.forester.phylogeny.data.Sequence();
5212             seq.setName( "K1PYK7_CRAGI" );
5213             n.getNodeData().addSequence( seq );
5214             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5215                 return false;
5216             }
5217             seq.setName( "tr|B3RJ64" );
5218             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5219                 return false;
5220             }
5221             n = new PhylogenyNode();
5222             seq = new org.forester.phylogeny.data.Sequence();
5223             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
5224             n.getNodeData().addSequence( seq );
5225             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
5226                 return false;
5227             }
5228             n = new PhylogenyNode();
5229             seq = new org.forester.phylogeny.data.Sequence();
5230             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
5231             n.getNodeData().addSequence( seq );
5232             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5233                 return false;
5234             }
5235             //
5236             n = new PhylogenyNode();
5237             n.setName( "ACP19736" );
5238             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5239                 return false;
5240             }
5241             n = new PhylogenyNode();
5242             n.setName( "|ACP19736|" );
5243             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5244                 return false;
5245             }
5246         }
5247         catch ( final Exception e ) {
5248             e.printStackTrace( System.out );
5249             return false;
5250         }
5251         return true;
5252     }
5253
5254     private static boolean testFastaParser() {
5255         try {
5256             FileInputStream fis1 = new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" );
5257             if ( !FastaParser.isLikelyFasta( fis1 ) ) {
5258                 fis1.close();
5259                 return false;
5260             }
5261             else {
5262                 fis1.close();
5263             }
5264             FileInputStream fis2 = new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" );
5265             if ( FastaParser.isLikelyFasta( fis2 ) ) {
5266                 fis2.close();
5267                 return false;
5268             }
5269             else {
5270                 fis2.close();
5271             }
5272             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
5273             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
5274                 return false;
5275             }
5276             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
5277                 return false;
5278             }
5279             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
5280                 return false;
5281             }
5282             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
5283                 return false;
5284             }
5285             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
5286                 return false;
5287             }
5288             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
5289                 return false;
5290             }
5291         }
5292         catch ( final Exception e ) {
5293             e.printStackTrace();
5294             return false;
5295         }
5296         return true;
5297     }
5298
5299     private static boolean testGenbankAccessorParsing() {
5300         //The format for GenBank Accession numbers are:
5301         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
5302         //Protein:    3 letters + 5 numerals
5303         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
5304         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
5305             return false;
5306         }
5307         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
5308             return false;
5309         }
5310         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
5311             return false;
5312         }
5313         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
5314             return false;
5315         }
5316         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
5317             return false;
5318         }
5319         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
5320             return false;
5321         }
5322         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
5323             return false;
5324         }
5325         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
5326             return false;
5327         }
5328         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
5329             return false;
5330         }
5331         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
5332             return false;
5333         }
5334         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
5335             return false;
5336         }
5337         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
5338             return false;
5339         }
5340         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
5341             return false;
5342         }
5343         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
5344             return false;
5345         }
5346         return true;
5347     }
5348
5349     private static boolean testGeneralMsaParser() {
5350         try {
5351             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
5352             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
5353             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
5354             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
5355             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
5356             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
5357             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
5358             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
5359             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5360                 return false;
5361             }
5362             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5363                 return false;
5364             }
5365             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5366                 return false;
5367             }
5368             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5369                 return false;
5370             }
5371             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5372                 return false;
5373             }
5374             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5375                 return false;
5376             }
5377             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5378                 return false;
5379             }
5380             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5381                 return false;
5382             }
5383             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5384                 return false;
5385             }
5386             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5387                 return false;
5388             }
5389             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5390                 return false;
5391             }
5392             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5393                 return false;
5394             }
5395             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5396             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5397                 return false;
5398             }
5399             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5400                 return false;
5401             }
5402             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5403                 return false;
5404             }
5405             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5406             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5407                 return false;
5408             }
5409             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5410                 return false;
5411             }
5412             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5413                 return false;
5414             }
5415             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5416             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5417                 return false;
5418             }
5419             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5420                 return false;
5421             }
5422             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5423                 return false;
5424             }
5425         }
5426         catch ( final Exception e ) {
5427             e.printStackTrace();
5428             return false;
5429         }
5430         return true;
5431     }
5432
5433     private static boolean testGeneralTable() {
5434         try {
5435             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5436             t0.setValue( 3, 2, "23" );
5437             t0.setValue( 10, 1, "error" );
5438             t0.setValue( 10, 1, "110" );
5439             t0.setValue( 9, 1, "19" );
5440             t0.setValue( 1, 10, "101" );
5441             t0.setValue( 10, 10, "1010" );
5442             t0.setValue( 100, 10, "10100" );
5443             t0.setValue( 0, 0, "00" );
5444             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5445                 return false;
5446             }
5447             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5448                 return false;
5449             }
5450             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5451                 return false;
5452             }
5453             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5454                 return false;
5455             }
5456             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5457                 return false;
5458             }
5459             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5460                 return false;
5461             }
5462             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5463                 return false;
5464             }
5465             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5466                 return false;
5467             }
5468             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5469                 return false;
5470             }
5471             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5472             t1.setValue( "3", "2", "23" );
5473             t1.setValue( "10", "1", "error" );
5474             t1.setValue( "10", "1", "110" );
5475             t1.setValue( "9", "1", "19" );
5476             t1.setValue( "1", "10", "101" );
5477             t1.setValue( "10", "10", "1010" );
5478             t1.setValue( "100", "10", "10100" );
5479             t1.setValue( "0", "0", "00" );
5480             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5481             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5482                 return false;
5483             }
5484             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5485                 return false;
5486             }
5487             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5488                 return false;
5489             }
5490             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5491                 return false;
5492             }
5493             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5494                 return false;
5495             }
5496             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5497                 return false;
5498             }
5499             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5500                 return false;
5501             }
5502             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5503                 return false;
5504             }
5505             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5506                 return false;
5507             }
5508             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5509                 return false;
5510             }
5511         }
5512         catch ( final Exception e ) {
5513             e.printStackTrace( System.out );
5514             return false;
5515         }
5516         return true;
5517     }
5518
5519     private static boolean testGetDistance() {
5520         try {
5521             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5522             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",
5523                                                  new NHXParser() )[ 0 ];
5524             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5525                 return false;
5526             }
5527             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5528                 return false;
5529             }
5530             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5531                 return false;
5532             }
5533             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5534                 return false;
5535             }
5536             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5537                 return false;
5538             }
5539             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5540                 return false;
5541             }
5542             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5543                 return false;
5544             }
5545             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5546                 return false;
5547             }
5548             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5549                 return false;
5550             }
5551             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5552                 return false;
5553             }
5554             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5555                 return false;
5556             }
5557             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5558                 return false;
5559             }
5560             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5561                 return false;
5562             }
5563             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5564                 return false;
5565             }
5566             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5567                 return false;
5568             }
5569             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5570                 return false;
5571             }
5572             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5573                 return false;
5574             }
5575             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5576                 return false;
5577             }
5578             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5579                 return false;
5580             }
5581             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5582                 return false;
5583             }
5584             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5585                 return false;
5586             }
5587             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5588                 return false;
5589             }
5590             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5591                 return false;
5592             }
5593             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5594                 return false;
5595             }
5596             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5597                 return false;
5598             }
5599             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5600                 return false;
5601             }
5602             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5603                 return false;
5604             }
5605             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5606                 return false;
5607             }
5608             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5609                 return false;
5610             }
5611             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5612                 return false;
5613             }
5614             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5615                 return false;
5616             }
5617             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",
5618                                                  new NHXParser() )[ 0 ];
5619             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5620                 return false;
5621             }
5622             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5623                 return false;
5624             }
5625             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5626                 return false;
5627             }
5628             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5629                 return false;
5630             }
5631             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5632                 return false;
5633             }
5634             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5635                 return false;
5636             }
5637             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5638                 return false;
5639             }
5640             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5641                 return false;
5642             }
5643             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5644                 return false;
5645             }
5646             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5647                 return false;
5648             }
5649             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5650                 return false;
5651             }
5652         }
5653         catch ( final Exception e ) {
5654             e.printStackTrace( System.out );
5655             return false;
5656         }
5657         return true;
5658     }
5659
5660     private static boolean testGetLCA() {
5661         try {
5662             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5663             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5664                                                  new NHXParser() )[ 0 ];
5665             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5666             if ( !A.getName().equals( "A" ) ) {
5667                 return false;
5668             }
5669             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5670             if ( !gh.getName().equals( "gh" ) ) {
5671                 return false;
5672             }
5673             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5674             if ( !ab.getName().equals( "ab" ) ) {
5675                 return false;
5676             }
5677             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5678             if ( !ab2.getName().equals( "ab" ) ) {
5679                 return false;
5680             }
5681             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5682             if ( !gh2.getName().equals( "gh" ) ) {
5683                 return false;
5684             }
5685             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5686             if ( !gh3.getName().equals( "gh" ) ) {
5687                 return false;
5688             }
5689             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5690             if ( !abc.getName().equals( "abc" ) ) {
5691                 return false;
5692             }
5693             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5694             if ( !abc2.getName().equals( "abc" ) ) {
5695                 return false;
5696             }
5697             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5698             if ( !abcd.getName().equals( "abcd" ) ) {
5699                 return false;
5700             }
5701             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5702             if ( !abcd2.getName().equals( "abcd" ) ) {
5703                 return false;
5704             }
5705             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5706             if ( !abcdef.getName().equals( "abcdef" ) ) {
5707                 return false;
5708             }
5709             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5710             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5711                 return false;
5712             }
5713             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5714             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5715                 return false;
5716             }
5717             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5718             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5719                 return false;
5720             }
5721             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5722             if ( !abcde.getName().equals( "abcde" ) ) {
5723                 return false;
5724             }
5725             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5726             if ( !abcde2.getName().equals( "abcde" ) ) {
5727                 return false;
5728             }
5729             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5730             if ( !r.getName().equals( "abcdefgh" ) ) {
5731                 return false;
5732             }
5733             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5734             if ( !r2.getName().equals( "abcdefgh" ) ) {
5735                 return false;
5736             }
5737             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5738             if ( !r3.getName().equals( "abcdefgh" ) ) {
5739                 return false;
5740             }
5741             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5742             if ( !abcde3.getName().equals( "abcde" ) ) {
5743                 return false;
5744             }
5745             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5746             if ( !abcde4.getName().equals( "abcde" ) ) {
5747                 return false;
5748             }
5749             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5750             if ( !ab3.getName().equals( "ab" ) ) {
5751                 return false;
5752             }
5753             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5754             if ( !ab4.getName().equals( "ab" ) ) {
5755                 return false;
5756             }
5757             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5758             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5759             if ( !cd.getName().equals( "cd" ) ) {
5760                 return false;
5761             }
5762             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5763             if ( !cd2.getName().equals( "cd" ) ) {
5764                 return false;
5765             }
5766             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5767             if ( !cde.getName().equals( "cde" ) ) {
5768                 return false;
5769             }
5770             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5771             if ( !cde2.getName().equals( "cde" ) ) {
5772                 return false;
5773             }
5774             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5775             if ( !cdef.getName().equals( "cdef" ) ) {
5776                 return false;
5777             }
5778             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5779             if ( !cdef2.getName().equals( "cdef" ) ) {
5780                 return false;
5781             }
5782             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5783             if ( !cdef3.getName().equals( "cdef" ) ) {
5784                 return false;
5785             }
5786             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5787             if ( !rt.getName().equals( "r" ) ) {
5788                 return false;
5789             }
5790             final Phylogeny p3 = factory
5791                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5792                              new NHXParser() )[ 0 ];
5793             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5794             if ( !bc_3.getName().equals( "bc" ) ) {
5795                 return false;
5796             }
5797             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5798             if ( !ac_3.getName().equals( "abc" ) ) {
5799                 return false;
5800             }
5801             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5802             if ( !ad_3.getName().equals( "abcde" ) ) {
5803                 return false;
5804             }
5805             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5806             if ( !af_3.getName().equals( "abcdef" ) ) {
5807                 return false;
5808             }
5809             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5810             if ( !ag_3.getName().equals( "" ) ) {
5811                 return false;
5812             }
5813             if ( !ag_3.isRoot() ) {
5814                 return false;
5815             }
5816             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5817             if ( !al_3.getName().equals( "" ) ) {
5818                 return false;
5819             }
5820             if ( !al_3.isRoot() ) {
5821                 return false;
5822             }
5823             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5824             if ( !kl_3.getName().equals( "" ) ) {
5825                 return false;
5826             }
5827             if ( !kl_3.isRoot() ) {
5828                 return false;
5829             }
5830             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5831             if ( !fl_3.getName().equals( "" ) ) {
5832                 return false;
5833             }
5834             if ( !fl_3.isRoot() ) {
5835                 return false;
5836             }
5837             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5838             if ( !gk_3.getName().equals( "ghijk" ) ) {
5839                 return false;
5840             }
5841             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5842             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5843             if ( !r_4.getName().equals( "r" ) ) {
5844                 return false;
5845             }
5846             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5847             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5848             if ( !r_5.getName().equals( "root" ) ) {
5849                 return false;
5850             }
5851             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5852             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5853             if ( !r_6.getName().equals( "rot" ) ) {
5854                 return false;
5855             }
5856             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5857             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5858             if ( !r_7.getName().equals( "rott" ) ) {
5859                 return false;
5860             }
5861         }
5862         catch ( final Exception e ) {
5863             e.printStackTrace( System.out );
5864             return false;
5865         }
5866         return true;
5867     }
5868
5869     private static boolean testGetLCA2() {
5870         try {
5871             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5872             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5873             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5874             PhylogenyMethods.preOrderReId( p_a );
5875             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5876                                                                                               p_a.getNode( "a" ) );
5877             if ( !p_a_1.getName().equals( "a" ) ) {
5878                 return false;
5879             }
5880             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5881             PhylogenyMethods.preOrderReId( p_b );
5882             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5883                                                                                               p_b.getNode( "a" ) );
5884             if ( !p_b_1.getName().equals( "b" ) ) {
5885                 return false;
5886             }
5887             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5888                                                                                               p_b.getNode( "b" ) );
5889             if ( !p_b_2.getName().equals( "b" ) ) {
5890                 return false;
5891             }
5892             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5893             PhylogenyMethods.preOrderReId( p_c );
5894             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5895                                                                                               p_c.getNode( "a" ) );
5896             if ( !p_c_1.getName().equals( "b" ) ) {
5897                 return false;
5898             }
5899             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5900                                                                                               p_c.getNode( "c" ) );
5901             if ( !p_c_2.getName().equals( "c" ) ) {
5902                 System.out.println( p_c_2.getName() );
5903                 System.exit( -1 );
5904                 return false;
5905             }
5906             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5907                                                                                               p_c.getNode( "b" ) );
5908             if ( !p_c_3.getName().equals( "b" ) ) {
5909                 return false;
5910             }
5911             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5912                                                                                               p_c.getNode( "a" ) );
5913             if ( !p_c_4.getName().equals( "c" ) ) {
5914                 return false;
5915             }
5916             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5917                                                  new NHXParser() )[ 0 ];
5918             PhylogenyMethods.preOrderReId( p1 );
5919             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5920                                                                                           p1.getNode( "A" ) );
5921             if ( !A.getName().equals( "A" ) ) {
5922                 return false;
5923             }
5924             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5925                                                                                            p1.getNode( "gh" ) );
5926             if ( !gh.getName().equals( "gh" ) ) {
5927                 return false;
5928             }
5929             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5930                                                                                            p1.getNode( "B" ) );
5931             if ( !ab.getName().equals( "ab" ) ) {
5932                 return false;
5933             }
5934             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5935                                                                                             p1.getNode( "A" ) );
5936             if ( !ab2.getName().equals( "ab" ) ) {
5937                 return false;
5938             }
5939             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5940                                                                                             p1.getNode( "G" ) );
5941             if ( !gh2.getName().equals( "gh" ) ) {
5942                 return false;
5943             }
5944             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5945                                                                                             p1.getNode( "H" ) );
5946             if ( !gh3.getName().equals( "gh" ) ) {
5947                 return false;
5948             }
5949             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5950                                                                                             p1.getNode( "A" ) );
5951             if ( !abc.getName().equals( "abc" ) ) {
5952                 return false;
5953             }
5954             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5955                                                                                              p1.getNode( "C" ) );
5956             if ( !abc2.getName().equals( "abc" ) ) {
5957                 return false;
5958             }
5959             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5960                                                                                              p1.getNode( "D" ) );
5961             if ( !abcd.getName().equals( "abcd" ) ) {
5962                 return false;
5963             }
5964             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5965                                                                                               p1.getNode( "A" ) );
5966             if ( !abcd2.getName().equals( "abcd" ) ) {
5967                 return false;
5968             }
5969             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5970                                                                                                p1.getNode( "F" ) );
5971             if ( !abcdef.getName().equals( "abcdef" ) ) {
5972                 return false;
5973             }
5974             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5975                                                                                                 p1.getNode( "A" ) );
5976             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5977                 return false;
5978             }
5979             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5980                                                                                                 p1.getNode( "F" ) );
5981             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5982                 return false;
5983             }
5984             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5985                                                                                                 p1.getNode( "ab" ) );
5986             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5987                 return false;
5988             }
5989             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5990                                                                                               p1.getNode( "E" ) );
5991             if ( !abcde.getName().equals( "abcde" ) ) {
5992                 return false;
5993             }
5994             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5995                                                                                                p1.getNode( "A" ) );
5996             if ( !abcde2.getName().equals( "abcde" ) ) {
5997                 return false;
5998             }
5999             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
6000                                                                                           p1.getNode( "abcdefgh" ) );
6001             if ( !r.getName().equals( "abcdefgh" ) ) {
6002                 return false;
6003             }
6004             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6005                                                                                            p1.getNode( "H" ) );
6006             if ( !r2.getName().equals( "abcdefgh" ) ) {
6007                 return false;
6008             }
6009             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
6010                                                                                            p1.getNode( "A" ) );
6011             if ( !r3.getName().equals( "abcdefgh" ) ) {
6012                 return false;
6013             }
6014             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6015                                                                                                p1.getNode( "abcde" ) );
6016             if ( !abcde3.getName().equals( "abcde" ) ) {
6017                 return false;
6018             }
6019             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
6020                                                                                                p1.getNode( "E" ) );
6021             if ( !abcde4.getName().equals( "abcde" ) ) {
6022                 return false;
6023             }
6024             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
6025                                                                                             p1.getNode( "B" ) );
6026             if ( !ab3.getName().equals( "ab" ) ) {
6027                 return false;
6028             }
6029             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
6030                                                                                             p1.getNode( "ab" ) );
6031             if ( !ab4.getName().equals( "ab" ) ) {
6032                 return false;
6033             }
6034             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
6035             PhylogenyMethods.preOrderReId( p2 );
6036             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6037                                                                                            p2.getNode( "d" ) );
6038             if ( !cd.getName().equals( "cd" ) ) {
6039                 return false;
6040             }
6041             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6042                                                                                             p2.getNode( "c" ) );
6043             if ( !cd2.getName().equals( "cd" ) ) {
6044                 return false;
6045             }
6046             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6047                                                                                             p2.getNode( "e" ) );
6048             if ( !cde.getName().equals( "cde" ) ) {
6049                 return false;
6050             }
6051             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
6052                                                                                              p2.getNode( "c" ) );
6053             if ( !cde2.getName().equals( "cde" ) ) {
6054                 return false;
6055             }
6056             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6057                                                                                              p2.getNode( "f" ) );
6058             if ( !cdef.getName().equals( "cdef" ) ) {
6059                 return false;
6060             }
6061             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6062                                                                                               p2.getNode( "f" ) );
6063             if ( !cdef2.getName().equals( "cdef" ) ) {
6064                 return false;
6065             }
6066             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
6067                                                                                               p2.getNode( "d" ) );
6068             if ( !cdef3.getName().equals( "cdef" ) ) {
6069                 return false;
6070             }
6071             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6072                                                                                            p2.getNode( "a" ) );
6073             if ( !rt.getName().equals( "r" ) ) {
6074                 return false;
6075             }
6076             final Phylogeny p3 = factory
6077                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
6078                              new NHXParser() )[ 0 ];
6079             PhylogenyMethods.preOrderReId( p3 );
6080             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
6081                                                                                              p3.getNode( "c" ) );
6082             if ( !bc_3.getName().equals( "bc" ) ) {
6083                 return false;
6084             }
6085             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6086                                                                                              p3.getNode( "c" ) );
6087             if ( !ac_3.getName().equals( "abc" ) ) {
6088                 return false;
6089             }
6090             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6091                                                                                              p3.getNode( "d" ) );
6092             if ( !ad_3.getName().equals( "abcde" ) ) {
6093                 return false;
6094             }
6095             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6096                                                                                              p3.getNode( "f" ) );
6097             if ( !af_3.getName().equals( "abcdef" ) ) {
6098                 return false;
6099             }
6100             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6101                                                                                              p3.getNode( "g" ) );
6102             if ( !ag_3.getName().equals( "" ) ) {
6103                 return false;
6104             }
6105             if ( !ag_3.isRoot() ) {
6106                 return false;
6107             }
6108             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6109                                                                                              p3.getNode( "l" ) );
6110             if ( !al_3.getName().equals( "" ) ) {
6111                 return false;
6112             }
6113             if ( !al_3.isRoot() ) {
6114                 return false;
6115             }
6116             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
6117                                                                                              p3.getNode( "l" ) );
6118             if ( !kl_3.getName().equals( "" ) ) {
6119                 return false;
6120             }
6121             if ( !kl_3.isRoot() ) {
6122                 return false;
6123             }
6124             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
6125                                                                                              p3.getNode( "l" ) );
6126             if ( !fl_3.getName().equals( "" ) ) {
6127                 return false;
6128             }
6129             if ( !fl_3.isRoot() ) {
6130                 return false;
6131             }
6132             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
6133                                                                                              p3.getNode( "k" ) );
6134             if ( !gk_3.getName().equals( "ghijk" ) ) {
6135                 return false;
6136             }
6137             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
6138             PhylogenyMethods.preOrderReId( p4 );
6139             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
6140                                                                                             p4.getNode( "c" ) );
6141             if ( !r_4.getName().equals( "r" ) ) {
6142                 return false;
6143             }
6144             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
6145             PhylogenyMethods.preOrderReId( p5 );
6146             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
6147                                                                                             p5.getNode( "c" ) );
6148             if ( !r_5.getName().equals( "root" ) ) {
6149                 return false;
6150             }
6151             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
6152             PhylogenyMethods.preOrderReId( p6 );
6153             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
6154                                                                                             p6.getNode( "a" ) );
6155             if ( !r_6.getName().equals( "rot" ) ) {
6156                 return false;
6157             }
6158             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
6159             PhylogenyMethods.preOrderReId( p7 );
6160             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
6161                                                                                             p7.getNode( "e" ) );
6162             if ( !r_7.getName().equals( "rott" ) ) {
6163                 return false;
6164             }
6165             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6166                                                                                              p7.getNode( "a" ) );
6167             if ( !r_71.getName().equals( "rott" ) ) {
6168                 return false;
6169             }
6170             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6171                                                                                              p7.getNode( "rott" ) );
6172             if ( !r_72.getName().equals( "rott" ) ) {
6173                 return false;
6174             }
6175             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6176                                                                                              p7.getNode( "a" ) );
6177             if ( !r_73.getName().equals( "rott" ) ) {
6178                 return false;
6179             }
6180             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6181                                                                                              p7.getNode( "rott" ) );
6182             if ( !r_74.getName().equals( "rott" ) ) {
6183                 return false;
6184             }
6185             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6186                                                                                              p7.getNode( "e" ) );
6187             if ( !r_75.getName().equals( "e" ) ) {
6188                 return false;
6189             }
6190         }
6191         catch ( final Exception e ) {
6192             e.printStackTrace( System.out );
6193             return false;
6194         }
6195         return true;
6196     }
6197
6198     private static boolean testHmmscanOutputParser() {
6199         final String test_dir = Test.PATH_TO_TEST_DATA;
6200         try {
6201             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
6202                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
6203             parser1.parse();
6204             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
6205                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
6206             final List<Protein> proteins = parser2.parse();
6207             if ( parser2.getProteinsEncountered() != 4 ) {
6208                 return false;
6209             }
6210             if ( proteins.size() != 4 ) {
6211                 return false;
6212             }
6213             if ( parser2.getDomainsEncountered() != 69 ) {
6214                 return false;
6215             }
6216             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
6217                 return false;
6218             }
6219             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
6220                 return false;
6221             }
6222             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
6223                 return false;
6224             }
6225             final Protein p1 = proteins.get( 0 );
6226             if ( p1.getNumberOfProteinDomains() != 15 ) {
6227                 return false;
6228             }
6229             if ( p1.getLength() != 850 ) {
6230                 return false;
6231             }
6232             final Protein p2 = proteins.get( 1 );
6233             if ( p2.getNumberOfProteinDomains() != 51 ) {
6234                 return false;
6235             }
6236             if ( p2.getLength() != 1291 ) {
6237                 return false;
6238             }
6239             final Protein p3 = proteins.get( 2 );
6240             if ( p3.getNumberOfProteinDomains() != 2 ) {
6241                 return false;
6242             }
6243             final Protein p4 = proteins.get( 3 );
6244             if ( p4.getNumberOfProteinDomains() != 1 ) {
6245                 return false;
6246             }
6247             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
6248                 return false;
6249             }
6250             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
6251                 return false;
6252             }
6253             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
6254                 return false;
6255             }
6256             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
6257                 return false;
6258             }
6259             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
6260                 return false;
6261             }
6262             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
6263                 return false;
6264             }
6265             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
6266                 return false;
6267             }
6268         }
6269         catch ( final Exception e ) {
6270             e.printStackTrace( System.out );
6271             return false;
6272         }
6273         return true;
6274     }
6275
6276     private static boolean testLastExternalNodeMethods() {
6277         try {
6278             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6279             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
6280             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
6281             final PhylogenyNode n1 = t0.getNode( "A" );
6282             if ( n1.isLastExternalNode() ) {
6283                 return false;
6284             }
6285             final PhylogenyNode n2 = t0.getNode( "B" );
6286             if ( n2.isLastExternalNode() ) {
6287                 return false;
6288             }
6289             final PhylogenyNode n3 = t0.getNode( "C" );
6290             if ( n3.isLastExternalNode() ) {
6291                 return false;
6292             }
6293             final PhylogenyNode n4 = t0.getNode( "D" );
6294             if ( !n4.isLastExternalNode() ) {
6295                 return false;
6296             }
6297         }
6298         catch ( final Exception e ) {
6299             e.printStackTrace( System.out );
6300             return false;
6301         }
6302         return true;
6303     }
6304
6305     private static boolean testLevelOrderIterator() {
6306         try {
6307             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6308             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
6309             PhylogenyNodeIterator it0;
6310             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
6311                 it0.next();
6312             }
6313             for( it0.reset(); it0.hasNext(); ) {
6314                 it0.next();
6315             }
6316             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
6317             if ( !it.next().getName().equals( "r" ) ) {
6318                 return false;
6319             }
6320             if ( !it.next().getName().equals( "ab" ) ) {
6321                 return false;
6322             }
6323             if ( !it.next().getName().equals( "cd" ) ) {
6324                 return false;
6325             }
6326             if ( !it.next().getName().equals( "A" ) ) {
6327                 return false;
6328             }
6329             if ( !it.next().getName().equals( "B" ) ) {
6330                 return false;
6331             }
6332             if ( !it.next().getName().equals( "C" ) ) {
6333                 return false;
6334             }
6335             if ( !it.next().getName().equals( "D" ) ) {
6336                 return false;
6337             }
6338             if ( it.hasNext() ) {
6339                 return false;
6340             }
6341             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",
6342                                                  new NHXParser() )[ 0 ];
6343             PhylogenyNodeIterator it2;
6344             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
6345                 it2.next();
6346             }
6347             for( it2.reset(); it2.hasNext(); ) {
6348                 it2.next();
6349             }
6350             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
6351             if ( !it3.next().getName().equals( "r" ) ) {
6352                 return false;
6353             }
6354             if ( !it3.next().getName().equals( "abc" ) ) {
6355                 return false;
6356             }
6357             if ( !it3.next().getName().equals( "defg" ) ) {
6358                 return false;
6359             }
6360             if ( !it3.next().getName().equals( "A" ) ) {
6361                 return false;
6362             }
6363             if ( !it3.next().getName().equals( "B" ) ) {
6364                 return false;
6365             }
6366             if ( !it3.next().getName().equals( "C" ) ) {
6367                 return false;
6368             }
6369             if ( !it3.next().getName().equals( "D" ) ) {
6370                 return false;
6371             }
6372             if ( !it3.next().getName().equals( "E" ) ) {
6373                 return false;
6374             }
6375             if ( !it3.next().getName().equals( "F" ) ) {
6376                 return false;
6377             }
6378             if ( !it3.next().getName().equals( "G" ) ) {
6379                 return false;
6380             }
6381             if ( !it3.next().getName().equals( "1" ) ) {
6382                 return false;
6383             }
6384             if ( !it3.next().getName().equals( "2" ) ) {
6385                 return false;
6386             }
6387             if ( !it3.next().getName().equals( "3" ) ) {
6388                 return false;
6389             }
6390             if ( !it3.next().getName().equals( "4" ) ) {
6391                 return false;
6392             }
6393             if ( !it3.next().getName().equals( "5" ) ) {
6394                 return false;
6395             }
6396             if ( !it3.next().getName().equals( "6" ) ) {
6397                 return false;
6398             }
6399             if ( !it3.next().getName().equals( "f1" ) ) {
6400                 return false;
6401             }
6402             if ( !it3.next().getName().equals( "f2" ) ) {
6403                 return false;
6404             }
6405             if ( !it3.next().getName().equals( "f3" ) ) {
6406                 return false;
6407             }
6408             if ( !it3.next().getName().equals( "a" ) ) {
6409                 return false;
6410             }
6411             if ( !it3.next().getName().equals( "b" ) ) {
6412                 return false;
6413             }
6414             if ( !it3.next().getName().equals( "f21" ) ) {
6415                 return false;
6416             }
6417             if ( !it3.next().getName().equals( "X" ) ) {
6418                 return false;
6419             }
6420             if ( !it3.next().getName().equals( "Y" ) ) {
6421                 return false;
6422             }
6423             if ( !it3.next().getName().equals( "Z" ) ) {
6424                 return false;
6425             }
6426             if ( it3.hasNext() ) {
6427                 return false;
6428             }
6429             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6430             PhylogenyNodeIterator it4;
6431             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6432                 it4.next();
6433             }
6434             for( it4.reset(); it4.hasNext(); ) {
6435                 it4.next();
6436             }
6437             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6438             if ( !it5.next().getName().equals( "r" ) ) {
6439                 return false;
6440             }
6441             if ( !it5.next().getName().equals( "A" ) ) {
6442                 return false;
6443             }
6444             if ( !it5.next().getName().equals( "B" ) ) {
6445                 return false;
6446             }
6447             if ( !it5.next().getName().equals( "C" ) ) {
6448                 return false;
6449             }
6450             if ( !it5.next().getName().equals( "D" ) ) {
6451                 return false;
6452             }
6453             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6454             PhylogenyNodeIterator it6;
6455             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6456                 it6.next();
6457             }
6458             for( it6.reset(); it6.hasNext(); ) {
6459                 it6.next();
6460             }
6461             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6462             if ( !it7.next().getName().equals( "A" ) ) {
6463                 return false;
6464             }
6465             if ( it.hasNext() ) {
6466                 return false;
6467             }
6468         }
6469         catch ( final Exception e ) {
6470             e.printStackTrace( System.out );
6471             return false;
6472         }
6473         return true;
6474     }
6475
6476     private static boolean testMafft( final String path ) {
6477         try {
6478             final List<String> opts = new ArrayList<String>();
6479             opts.add( "--maxiterate" );
6480             opts.add( "1000" );
6481             opts.add( "--localpair" );
6482             opts.add( "--quiet" );
6483             Msa msa = null;
6484             final MsaInferrer mafft = Mafft.createInstance( path );
6485             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6486             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6487                 return false;
6488             }
6489             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6490                 return false;
6491             }
6492         }
6493         catch ( final Exception e ) {
6494             e.printStackTrace( System.out );
6495             return false;
6496         }
6497         return true;
6498     }
6499
6500     private static boolean testMidpointrooting() {
6501         try {
6502             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6503             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6504             PhylogenyMethods.midpointRoot( t0 );
6505             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6506                 return false;
6507             }
6508             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6509                 return false;
6510             }
6511             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6512                            1 ) ) {
6513                 return false;
6514             }
6515             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",
6516                                                  new NHXParser() )[ 0 ];
6517             if ( !t1.isRooted() ) {
6518                 return false;
6519             }
6520             PhylogenyMethods.midpointRoot( t1 );
6521             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6522                 return false;
6523             }
6524             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6525                 return false;
6526             }
6527             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6528                 return false;
6529             }
6530             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6531                 return false;
6532             }
6533             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6534                 return false;
6535             }
6536             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6537                 return false;
6538             }
6539             t1.reRoot( t1.getNode( "A" ) );
6540             PhylogenyMethods.midpointRoot( t1 );
6541             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6542                 return false;
6543             }
6544             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6545                 return false;
6546             }
6547             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6548                 return false;
6549             }
6550             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6551                 return false;
6552             }
6553             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6554                 System.exit( -1 );
6555                 return false;
6556             }
6557             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6558                 return false;
6559             }
6560         }
6561         catch ( final Exception e ) {
6562             e.printStackTrace( System.out );
6563             return false;
6564         }
6565         return true;
6566     }
6567
6568     private static boolean testMsaQualityMethod() {
6569         try {
6570             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6571             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6572             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6573             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6574             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6575             l.add( s0 );
6576             l.add( s1 );
6577             l.add( s2 );
6578             l.add( s3 );
6579             final Msa msa = BasicMsa.createInstance( l );
6580             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6581                 return false;
6582             }
6583             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6584                 return false;
6585             }
6586             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6587                 return false;
6588             }
6589             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6590                 return false;
6591             }
6592             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6593                 return false;
6594             }
6595             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6596                 return false;
6597             }
6598             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6599                 return false;
6600             }
6601         }
6602         catch ( final Exception e ) {
6603             e.printStackTrace( System.out );
6604             return false;
6605         }
6606         return true;
6607     }
6608
6609     private static boolean testMsaEntropy() {
6610         try {
6611             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6612             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6613             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6614             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6615             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6616             l.add( s0 );
6617             l.add( s1 );
6618             l.add( s2 );
6619             l.add( s3 );
6620             final Msa msa = BasicMsa.createInstance( l );
6621             //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6622             //FIXME
6623             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6624             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6625             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6626             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6627             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6628             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6629             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6630             //            System.out.println();
6631             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6632             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6633             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6634             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6635             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6636             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6637             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6638             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6639             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6640             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6641             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6642             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6643             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6644             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6645             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6646             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6647             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6648             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6649             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6650             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6651             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6652             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6653             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6654             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6655             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6656             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6657             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6658             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6659             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6660             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6661             final Msa msa2 = BasicMsa.createInstance( l2 );
6662             //            System.out.println();
6663             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6664             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6665             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6666         }
6667         catch ( final Exception e ) {
6668             e.printStackTrace( System.out );
6669             return false;
6670         }
6671         return true;
6672     }
6673
6674     private static boolean testDeleteableMsa() {
6675         try {
6676             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6677             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6678             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6679             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6680             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6681             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6682             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6683             l0.add( s0 );
6684             l0.add( s1 );
6685             l0.add( s2 );
6686             l0.add( s3 );
6687             l0.add( s4 );
6688             l0.add( s5 );
6689             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6690             dmsa0.deleteRow( "b", false );
6691             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6692                 return false;
6693             }
6694             dmsa0.deleteRow( "e", false );
6695             dmsa0.deleteRow( "a", false );
6696             dmsa0.deleteRow( "f", false );
6697             if ( dmsa0.getLength() != 4 ) {
6698                 return false;
6699             }
6700             if ( dmsa0.getNumberOfSequences() != 2 ) {
6701                 return false;
6702             }
6703             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6704                 return false;
6705             }
6706             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6707                 return false;
6708             }
6709             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6710                 return false;
6711             }
6712             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6713                 return false;
6714             }
6715             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6716                 return false;
6717             }
6718             dmsa0.deleteRow( "c", false );
6719             dmsa0.deleteRow( "d", false );
6720             if ( dmsa0.getNumberOfSequences() != 0 ) {
6721                 return false;
6722             }
6723             //
6724             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6725             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6726             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6727             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6728             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6729             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6730             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6731             l1.add( s_0 );
6732             l1.add( s_1 );
6733             l1.add( s_2 );
6734             l1.add( s_3 );
6735             l1.add( s_4 );
6736             l1.add( s_5 );
6737             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6738             dmsa1.deleteGapOnlyColumns();
6739             dmsa1.deleteRow( "a", false );
6740             dmsa1.deleteRow( "f", false );
6741             dmsa1.deleteRow( "d", false );
6742             dmsa1.deleteGapOnlyColumns();
6743             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6744                 return false;
6745             }
6746             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6747                 return false;
6748             }
6749             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6750                 return false;
6751             }
6752             dmsa1.deleteRow( "c", false );
6753             dmsa1.deleteGapOnlyColumns();
6754             final Writer w0 = new StringWriter();
6755             dmsa1.write( w0, MSA_FORMAT.FASTA );
6756             final Writer w1 = new StringWriter();
6757             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6758             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6759                 return false;
6760             }
6761             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6762                 return false;
6763             }
6764             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6765             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6766             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6767             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6768             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6769             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6770             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6771             l2.add( s__0 );
6772             l2.add( s__1 );
6773             l2.add( s__2 );
6774             l2.add( s__3 );
6775             l2.add( s__4 );
6776             l2.add( s__5 );
6777             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6778             dmsa2.deleteGapColumns( 0.5 );
6779             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6780                 return false;
6781             }
6782             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6783                 return false;
6784             }
6785             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6786                 return false;
6787             }
6788             dmsa2.deleteGapColumns( 0.2 );
6789             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6790                 return false;
6791             }
6792             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6793                 return false;
6794             }
6795             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6796                 return false;
6797             }
6798             dmsa2.deleteGapColumns( 0 );
6799             dmsa2.deleteRow( "a", false );
6800             dmsa2.deleteRow( "b", false );
6801             dmsa2.deleteRow( "f", false );
6802             dmsa2.deleteRow( "e", false );
6803             dmsa2.setIdentifier( 0, "new_c" );
6804             dmsa2.setIdentifier( 1, "new_d" );
6805             dmsa2.setResidueAt( 0, 0, 'x' );
6806             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6807             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6808                 return false;
6809             }
6810             final Writer w = new StringWriter();
6811             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6812             final String phylip = w.toString();
6813             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6814                 System.out.println( phylip );
6815                 return false;
6816             }
6817             final Writer w2 = new StringWriter();
6818             dmsa2.write( w2, MSA_FORMAT.FASTA );
6819             final String fasta = w2.toString();
6820             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6821                 System.out.println( fasta );
6822                 return false;
6823             }
6824         }
6825         catch ( final Exception e ) {
6826             e.printStackTrace( System.out );
6827             return false;
6828         }
6829         return true;
6830     }
6831
6832     private static boolean testNextNodeWithCollapsing() {
6833         try {
6834             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6835             PhylogenyNode n;
6836             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6837             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6838             final Phylogeny t0 = factory.create( sb0.toString(), new NHXParser() )[ 0 ];
6839             t0.getNode( "cd" ).setCollapse( true );
6840             t0.getNode( "cde" ).setCollapse( true );
6841             n = t0.getFirstExternalNode();
6842             while ( n != null ) {
6843                 ext.add( n );
6844                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6845             }
6846             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6847                 return false;
6848             }
6849             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6850                 return false;
6851             }
6852             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6853                 return false;
6854             }
6855             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6856                 return false;
6857             }
6858             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6859                 return false;
6860             }
6861             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6862                 return false;
6863             }
6864             ext.clear();
6865             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6866             final Phylogeny t1 = factory.create( sb1.toString(), new NHXParser() )[ 0 ];
6867             t1.getNode( "ab" ).setCollapse( true );
6868             t1.getNode( "cd" ).setCollapse( true );
6869             t1.getNode( "cde" ).setCollapse( true );
6870             n = t1.getNode( "ab" );
6871             ext = new ArrayList<PhylogenyNode>();
6872             while ( n != null ) {
6873                 ext.add( n );
6874                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6875             }
6876             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6877                 return false;
6878             }
6879             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6880                 return false;
6881             }
6882             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6883                 return false;
6884             }
6885             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6886                 return false;
6887             }
6888             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6889                 return false;
6890             }
6891             ext.clear();
6892             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6893             final Phylogeny t2 = factory.create( sb2.toString(), new NHXParser() )[ 0 ];
6894             t2.getNode( "ab" ).setCollapse( true );
6895             t2.getNode( "cd" ).setCollapse( true );
6896             t2.getNode( "cde" ).setCollapse( true );
6897             t2.getNode( "c" ).setCollapse( true );
6898             t2.getNode( "d" ).setCollapse( true );
6899             t2.getNode( "e" ).setCollapse( true );
6900             t2.getNode( "gh" ).setCollapse( true );
6901             n = t2.getNode( "ab" );
6902             ext = new ArrayList<PhylogenyNode>();
6903             while ( n != null ) {
6904                 ext.add( n );
6905                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6906             }
6907             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6908                 return false;
6909             }
6910             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6911                 return false;
6912             }
6913             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6914                 return false;
6915             }
6916             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6917                 return false;
6918             }
6919             ext.clear();
6920             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6921             final Phylogeny t3 = factory.create( sb3.toString(), new NHXParser() )[ 0 ];
6922             t3.getNode( "ab" ).setCollapse( true );
6923             t3.getNode( "cd" ).setCollapse( true );
6924             t3.getNode( "cde" ).setCollapse( true );
6925             t3.getNode( "c" ).setCollapse( true );
6926             t3.getNode( "d" ).setCollapse( true );
6927             t3.getNode( "e" ).setCollapse( true );
6928             t3.getNode( "gh" ).setCollapse( true );
6929             t3.getNode( "fgh" ).setCollapse( true );
6930             n = t3.getNode( "ab" );
6931             ext = new ArrayList<PhylogenyNode>();
6932             while ( n != null ) {
6933                 ext.add( n );
6934                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6935             }
6936             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6937                 return false;
6938             }
6939             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6940                 return false;
6941             }
6942             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6943                 return false;
6944             }
6945             ext.clear();
6946             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6947             final Phylogeny t4 = factory.create( sb4.toString(), new NHXParser() )[ 0 ];
6948             t4.getNode( "ab" ).setCollapse( true );
6949             t4.getNode( "cd" ).setCollapse( true );
6950             t4.getNode( "cde" ).setCollapse( true );
6951             t4.getNode( "c" ).setCollapse( true );
6952             t4.getNode( "d" ).setCollapse( true );
6953             t4.getNode( "e" ).setCollapse( true );
6954             t4.getNode( "gh" ).setCollapse( true );
6955             t4.getNode( "fgh" ).setCollapse( true );
6956             t4.getNode( "abcdefgh" ).setCollapse( true );
6957             n = t4.getNode( "abcdefgh" );
6958             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6959                 return false;
6960             }
6961             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6962             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
6963             ext.clear();
6964             n = t5.getFirstExternalNode();
6965             while ( n != null ) {
6966                 ext.add( n );
6967                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6968             }
6969             if ( ext.size() != 8 ) {
6970                 return false;
6971             }
6972             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6973                 return false;
6974             }
6975             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6976                 return false;
6977             }
6978             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6979                 return false;
6980             }
6981             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6982                 return false;
6983             }
6984             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6985                 return false;
6986             }
6987             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6988                 return false;
6989             }
6990             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6991                 return false;
6992             }
6993             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6994                 return false;
6995             }
6996             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6997             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
6998             ext.clear();
6999             t6.getNode( "ab" ).setCollapse( true );
7000             n = t6.getNode( "ab" );
7001             while ( n != null ) {
7002                 ext.add( n );
7003                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7004             }
7005             if ( ext.size() != 7 ) {
7006                 return false;
7007             }
7008             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7009                 return false;
7010             }
7011             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7012                 return false;
7013             }
7014             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7015                 return false;
7016             }
7017             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7018                 return false;
7019             }
7020             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7021                 return false;
7022             }
7023             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7024                 return false;
7025             }
7026             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7027                 return false;
7028             }
7029             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7030             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
7031             ext.clear();
7032             t7.getNode( "cd" ).setCollapse( true );
7033             n = t7.getNode( "a" );
7034             while ( n != null ) {
7035                 ext.add( n );
7036                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7037             }
7038             if ( ext.size() != 7 ) {
7039                 return false;
7040             }
7041             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7042                 return false;
7043             }
7044             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7045                 return false;
7046             }
7047             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7048                 return false;
7049             }
7050             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7051                 return false;
7052             }
7053             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7054                 return false;
7055             }
7056             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7057                 return false;
7058             }
7059             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7060                 return false;
7061             }
7062             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7063             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
7064             ext.clear();
7065             t8.getNode( "cd" ).setCollapse( true );
7066             t8.getNode( "c" ).setCollapse( true );
7067             t8.getNode( "d" ).setCollapse( true );
7068             n = t8.getNode( "a" );
7069             while ( n != null ) {
7070                 ext.add( n );
7071                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7072             }
7073             if ( ext.size() != 7 ) {
7074                 return false;
7075             }
7076             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7077                 return false;
7078             }
7079             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7080                 return false;
7081             }
7082             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7083                 System.out.println( "2 fail" );
7084                 return false;
7085             }
7086             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7087                 return false;
7088             }
7089             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7090                 return false;
7091             }
7092             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7093                 return false;
7094             }
7095             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7096                 return false;
7097             }
7098             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7099             final Phylogeny t9 = factory.create( sb9.toString(), new NHXParser() )[ 0 ];
7100             ext.clear();
7101             t9.getNode( "gh" ).setCollapse( true );
7102             n = t9.getNode( "a" );
7103             while ( n != null ) {
7104                 ext.add( n );
7105                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7106             }
7107             if ( ext.size() != 7 ) {
7108                 return false;
7109             }
7110             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7111                 return false;
7112             }
7113             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7114                 return false;
7115             }
7116             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7117                 return false;
7118             }
7119             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7120                 return false;
7121             }
7122             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7123                 return false;
7124             }
7125             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7126                 return false;
7127             }
7128             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7129                 return false;
7130             }
7131             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7132             final Phylogeny t10 = factory.create( sb10.toString(), new NHXParser() )[ 0 ];
7133             ext.clear();
7134             t10.getNode( "gh" ).setCollapse( true );
7135             t10.getNode( "g" ).setCollapse( true );
7136             t10.getNode( "h" ).setCollapse( true );
7137             n = t10.getNode( "a" );
7138             while ( n != null ) {
7139                 ext.add( n );
7140                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7141             }
7142             if ( ext.size() != 7 ) {
7143                 return false;
7144             }
7145             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7146                 return false;
7147             }
7148             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7149                 return false;
7150             }
7151             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7152                 return false;
7153             }
7154             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7155                 return false;
7156             }
7157             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7158                 return false;
7159             }
7160             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7161                 return false;
7162             }
7163             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7164                 return false;
7165             }
7166             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7167             final Phylogeny t11 = factory.create( sb11.toString(), new NHXParser() )[ 0 ];
7168             ext.clear();
7169             t11.getNode( "gh" ).setCollapse( true );
7170             t11.getNode( "fgh" ).setCollapse( true );
7171             n = t11.getNode( "a" );
7172             while ( n != null ) {
7173                 ext.add( n );
7174                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7175             }
7176             if ( ext.size() != 6 ) {
7177                 return false;
7178             }
7179             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7180                 return false;
7181             }
7182             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7183                 return false;
7184             }
7185             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7186                 return false;
7187             }
7188             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7189                 return false;
7190             }
7191             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7192                 return false;
7193             }
7194             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7195                 return false;
7196             }
7197             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7198             final Phylogeny t12 = factory.create( sb12.toString(), new NHXParser() )[ 0 ];
7199             ext.clear();
7200             t12.getNode( "gh" ).setCollapse( true );
7201             t12.getNode( "fgh" ).setCollapse( true );
7202             t12.getNode( "g" ).setCollapse( true );
7203             t12.getNode( "h" ).setCollapse( true );
7204             t12.getNode( "f" ).setCollapse( true );
7205             n = t12.getNode( "a" );
7206             while ( n != null ) {
7207                 ext.add( n );
7208                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7209             }
7210             if ( ext.size() != 6 ) {
7211                 return false;
7212             }
7213             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7214                 return false;
7215             }
7216             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7217                 return false;
7218             }
7219             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7220                 return false;
7221             }
7222             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7223                 return false;
7224             }
7225             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7226                 return false;
7227             }
7228             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7229                 return false;
7230             }
7231             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7232             final Phylogeny t13 = factory.create( sb13.toString(), new NHXParser() )[ 0 ];
7233             ext.clear();
7234             t13.getNode( "ab" ).setCollapse( true );
7235             t13.getNode( "b" ).setCollapse( true );
7236             t13.getNode( "fgh" ).setCollapse( true );
7237             t13.getNode( "gh" ).setCollapse( true );
7238             n = t13.getNode( "ab" );
7239             while ( n != null ) {
7240                 ext.add( n );
7241                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7242             }
7243             if ( ext.size() != 5 ) {
7244                 return false;
7245             }
7246             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7247                 return false;
7248             }
7249             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7250                 return false;
7251             }
7252             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7253                 return false;
7254             }
7255             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7256                 return false;
7257             }
7258             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7259                 return false;
7260             }
7261             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
7262             final Phylogeny t14 = factory.create( sb14.toString(), new NHXParser() )[ 0 ];
7263             ext.clear();
7264             t14.getNode( "ab" ).setCollapse( true );
7265             t14.getNode( "a" ).setCollapse( true );
7266             t14.getNode( "fgh" ).setCollapse( true );
7267             t14.getNode( "gh" ).setCollapse( true );
7268             n = t14.getNode( "ab" );
7269             while ( n != null ) {
7270                 ext.add( n );
7271                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7272             }
7273             if ( ext.size() != 5 ) {
7274                 return false;
7275             }
7276             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7277                 return false;
7278             }
7279             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7280                 return false;
7281             }
7282             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7283                 return false;
7284             }
7285             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7286                 return false;
7287             }
7288             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7289                 return false;
7290             }
7291             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" );
7292             final Phylogeny t15 = factory.create( sb15.toString(), new NHXParser() )[ 0 ];
7293             ext.clear();
7294             t15.getNode( "ab" ).setCollapse( true );
7295             t15.getNode( "a" ).setCollapse( true );
7296             t15.getNode( "fgh" ).setCollapse( true );
7297             t15.getNode( "gh" ).setCollapse( true );
7298             n = t15.getNode( "ab" );
7299             while ( n != null ) {
7300                 ext.add( n );
7301                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7302             }
7303             if ( ext.size() != 6 ) {
7304                 return false;
7305             }
7306             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7307                 return false;
7308             }
7309             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7310                 return false;
7311             }
7312             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7313                 return false;
7314             }
7315             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7316                 return false;
7317             }
7318             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
7319                 return false;
7320             }
7321             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7322                 return false;
7323             }
7324             //
7325             //
7326             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" );
7327             final Phylogeny t16 = factory.create( sb16.toString(), new NHXParser() )[ 0 ];
7328             ext.clear();
7329             t16.getNode( "ab" ).setCollapse( true );
7330             t16.getNode( "a" ).setCollapse( true );
7331             t16.getNode( "fgh" ).setCollapse( true );
7332             t16.getNode( "gh" ).setCollapse( true );
7333             t16.getNode( "cd" ).setCollapse( true );
7334             t16.getNode( "cde" ).setCollapse( true );
7335             t16.getNode( "d" ).setCollapse( true );
7336             t16.getNode( "x" ).setCollapse( true );
7337             n = t16.getNode( "ab" );
7338             while ( n != null ) {
7339                 ext.add( n );
7340                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7341             }
7342             if ( ext.size() != 4 ) {
7343                 return false;
7344             }
7345             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7346                 return false;
7347             }
7348             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7349                 return false;
7350             }
7351             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
7352                 return false;
7353             }
7354             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
7355                 return false;
7356             }
7357         }
7358         catch ( final Exception e ) {
7359             e.printStackTrace( System.out );
7360             return false;
7361         }
7362         return true;
7363     }
7364
7365     private static boolean testNexusCharactersParsing() {
7366         try {
7367             final NexusCharactersParser parser = new NexusCharactersParser();
7368             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
7369             parser.parse();
7370             String[] labels = parser.getCharStateLabels();
7371             if ( labels.length != 7 ) {
7372                 return false;
7373             }
7374             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7375                 return false;
7376             }
7377             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7378                 return false;
7379             }
7380             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7381                 return false;
7382             }
7383             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7384                 return false;
7385             }
7386             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7387                 return false;
7388             }
7389             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7390                 return false;
7391             }
7392             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7393                 return false;
7394             }
7395             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7396             parser.parse();
7397             labels = parser.getCharStateLabels();
7398             if ( labels.length != 7 ) {
7399                 return false;
7400             }
7401             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7402                 return false;
7403             }
7404             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7405                 return false;
7406             }
7407             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7408                 return false;
7409             }
7410             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7411                 return false;
7412             }
7413             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7414                 return false;
7415             }
7416             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7417                 return false;
7418             }
7419             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7420                 return false;
7421             }
7422         }
7423         catch ( final Exception e ) {
7424             e.printStackTrace( System.out );
7425             return false;
7426         }
7427         return true;
7428     }
7429
7430     private static boolean testNexusMatrixParsing() {
7431         try {
7432             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7433             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7434             parser.parse();
7435             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7436             if ( m.getNumberOfCharacters() != 9 ) {
7437                 return false;
7438             }
7439             if ( m.getNumberOfIdentifiers() != 5 ) {
7440                 return false;
7441             }
7442             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7443                 return false;
7444             }
7445             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7446                 return false;
7447             }
7448             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7449                 return false;
7450             }
7451             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7452                 return false;
7453             }
7454             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7455                 return false;
7456             }
7457             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7458                 return false;
7459             }
7460             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7461                 return false;
7462             }
7463             //            if ( labels.length != 7 ) {
7464             //                return false;
7465             //            }
7466             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7467             //                return false;
7468             //            }
7469             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7470             //                return false;
7471             //            }
7472             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7473             //                return false;
7474             //            }
7475             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7476             //                return false;
7477             //            }
7478             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7479             //                return false;
7480             //            }
7481             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7482             //                return false;
7483             //            }
7484             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7485             //                return false;
7486             //            }
7487             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7488             //            parser.parse();
7489             //            labels = parser.getCharStateLabels();
7490             //            if ( labels.length != 7 ) {
7491             //                return false;
7492             //            }
7493             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7494             //                return false;
7495             //            }
7496             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7497             //                return false;
7498             //            }
7499             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7500             //                return false;
7501             //            }
7502             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7503             //                return false;
7504             //            }
7505             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7506             //                return false;
7507             //            }
7508             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7509             //                return false;
7510             //            }
7511             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7512             //                return false;
7513             //            }
7514         }
7515         catch ( final Exception e ) {
7516             e.printStackTrace( System.out );
7517             return false;
7518         }
7519         return true;
7520     }
7521
7522     private static boolean testNexusTreeParsing() {
7523         try {
7524             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7525             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7526             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7527             if ( phylogenies.length != 1 ) {
7528                 return false;
7529             }
7530             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7531                 return false;
7532             }
7533             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7534                 return false;
7535             }
7536             phylogenies = null;
7537             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7538             if ( phylogenies.length != 1 ) {
7539                 return false;
7540             }
7541             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7542                 return false;
7543             }
7544             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7545                 return false;
7546             }
7547             phylogenies = null;
7548             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7549             if ( phylogenies.length != 1 ) {
7550                 return false;
7551             }
7552             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7553                 return false;
7554             }
7555             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7556                 return false;
7557             }
7558             if ( phylogenies[ 0 ].isRooted() ) {
7559                 return false;
7560             }
7561             phylogenies = null;
7562             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7563             if ( phylogenies.length != 18 ) {
7564                 return false;
7565             }
7566             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7567                 return false;
7568             }
7569             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7570                 return false;
7571             }
7572             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7573                 return false;
7574             }
7575             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7576                 return false;
7577             }
7578             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7579                 return false;
7580             }
7581             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7582                 return false;
7583             }
7584             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7585                 return false;
7586             }
7587             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7588                 return false;
7589             }
7590             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7591                 return false;
7592             }
7593             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7594                 return false;
7595             }
7596             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7597                 return false;
7598             }
7599             if ( phylogenies[ 8 ].isRooted() ) {
7600                 return false;
7601             }
7602             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7603                 return false;
7604             }
7605             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7606                 return false;
7607             }
7608             if ( !phylogenies[ 9 ].isRooted() ) {
7609                 return false;
7610             }
7611             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7612                 return false;
7613             }
7614             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7615                 return false;
7616             }
7617             if ( !phylogenies[ 10 ].isRooted() ) {
7618                 return false;
7619             }
7620             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7621                 return false;
7622             }
7623             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7624                 return false;
7625             }
7626             if ( phylogenies[ 11 ].isRooted() ) {
7627                 return false;
7628             }
7629             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7630                 return false;
7631             }
7632             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7633                 return false;
7634             }
7635             if ( !phylogenies[ 12 ].isRooted() ) {
7636                 return false;
7637             }
7638             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7639                 return false;
7640             }
7641             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7642                 return false;
7643             }
7644             if ( !phylogenies[ 13 ].isRooted() ) {
7645                 return false;
7646             }
7647             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7648                 return false;
7649             }
7650             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7651                 return false;
7652             }
7653             if ( !phylogenies[ 14 ].isRooted() ) {
7654                 return false;
7655             }
7656             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7657                 return false;
7658             }
7659             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7660                 return false;
7661             }
7662             if ( phylogenies[ 15 ].isRooted() ) {
7663                 return false;
7664             }
7665             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7666                 return false;
7667             }
7668             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7669                 return false;
7670             }
7671             if ( !phylogenies[ 16 ].isRooted() ) {
7672                 return false;
7673             }
7674             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7675                 return false;
7676             }
7677             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7678                 return false;
7679             }
7680             if ( phylogenies[ 17 ].isRooted() ) {
7681                 return false;
7682             }
7683             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7684                 return false;
7685             }
7686             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7687             phylogenies = null;
7688             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7689             if ( phylogenies.length != 9 ) {
7690                 return false;
7691             }
7692             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7693                            .getDistanceToParent() ) ) {
7694                 return false;
7695             }
7696             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7697                            .getDistanceToParent() ) ) {
7698                 return false;
7699             }
7700             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7701                 return false;
7702             }
7703             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7704                 return false;
7705             }
7706             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7707                 return false;
7708             }
7709             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7710                 return false;
7711             }
7712             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7713                 return false;
7714             }
7715         }
7716         catch ( final Exception e ) {
7717             e.printStackTrace( System.out );
7718             return false;
7719         }
7720         return true;
7721     }
7722
7723     private static boolean testNexusTreeParsingIterating() {
7724         try {
7725             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7726             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7727             if ( !p.hasNext() ) {
7728                 return false;
7729             }
7730             Phylogeny phy = p.next();
7731             if ( phy == null ) {
7732                 return false;
7733             }
7734             if ( phy.getNumberOfExternalNodes() != 25 ) {
7735                 return false;
7736             }
7737             if ( !phy.getName().equals( "" ) ) {
7738                 return false;
7739             }
7740             if ( p.hasNext() ) {
7741                 return false;
7742             }
7743             phy = p.next();
7744             if ( phy != null ) {
7745                 return false;
7746             }
7747             p.reset();
7748             if ( !p.hasNext() ) {
7749                 return false;
7750             }
7751             phy = p.next();
7752             if ( phy == null ) {
7753                 return false;
7754             }
7755             if ( phy.getNumberOfExternalNodes() != 25 ) {
7756                 return false;
7757             }
7758             if ( !phy.getName().equals( "" ) ) {
7759                 return false;
7760             }
7761             if ( p.hasNext() ) {
7762                 return false;
7763             }
7764             phy = p.next();
7765             if ( phy != null ) {
7766                 return false;
7767             }
7768             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7769             if ( !p.hasNext() ) {
7770                 return false;
7771             }
7772             phy = p.next();
7773             if ( phy == null ) {
7774                 return false;
7775             }
7776             if ( phy.getNumberOfExternalNodes() != 10 ) {
7777                 return false;
7778             }
7779             if ( !phy.getName().equals( "name" ) ) {
7780                 return false;
7781             }
7782             if ( p.hasNext() ) {
7783                 return false;
7784             }
7785             phy = p.next();
7786             if ( phy != null ) {
7787                 return false;
7788             }
7789             p.reset();
7790             if ( !p.hasNext() ) {
7791                 return false;
7792             }
7793             phy = p.next();
7794             if ( phy == null ) {
7795                 return false;
7796             }
7797             if ( phy.getNumberOfExternalNodes() != 10 ) {
7798                 return false;
7799             }
7800             if ( !phy.getName().equals( "name" ) ) {
7801                 return false;
7802             }
7803             if ( p.hasNext() ) {
7804                 return false;
7805             }
7806             phy = p.next();
7807             if ( phy != null ) {
7808                 return false;
7809             }
7810             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7811             if ( !p.hasNext() ) {
7812                 return false;
7813             }
7814             phy = p.next();
7815             if ( phy == null ) {
7816                 return false;
7817             }
7818             if ( phy.getNumberOfExternalNodes() != 3 ) {
7819                 return false;
7820             }
7821             if ( !phy.getName().equals( "" ) ) {
7822                 return false;
7823             }
7824             if ( phy.isRooted() ) {
7825                 return false;
7826             }
7827             if ( p.hasNext() ) {
7828                 return false;
7829             }
7830             phy = p.next();
7831             if ( phy != null ) {
7832                 return false;
7833             }
7834             //
7835             p.reset();
7836             if ( !p.hasNext() ) {
7837                 return false;
7838             }
7839             phy = p.next();
7840             if ( phy == null ) {
7841                 return false;
7842             }
7843             if ( phy.getNumberOfExternalNodes() != 3 ) {
7844                 return false;
7845             }
7846             if ( !phy.getName().equals( "" ) ) {
7847                 return false;
7848             }
7849             if ( p.hasNext() ) {
7850                 return false;
7851             }
7852             phy = p.next();
7853             if ( phy != null ) {
7854                 return false;
7855             }
7856             //
7857             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7858             if ( !p.hasNext() ) {
7859                 return false;
7860             }
7861             //0
7862             phy = p.next();
7863             if ( phy == null ) {
7864                 return false;
7865             }
7866             if ( phy.getNumberOfExternalNodes() != 10 ) {
7867                 return false;
7868             }
7869             if ( !phy.getName().equals( "tree 0" ) ) {
7870                 return false;
7871             }
7872             //1
7873             if ( !p.hasNext() ) {
7874                 return false;
7875             }
7876             phy = p.next();
7877             if ( phy == null ) {
7878                 return false;
7879             }
7880             if ( phy.getNumberOfExternalNodes() != 10 ) {
7881                 return false;
7882             }
7883             if ( !phy.getName().equals( "tree 1" ) ) {
7884                 return false;
7885             }
7886             //2
7887             if ( !p.hasNext() ) {
7888                 return false;
7889             }
7890             phy = p.next();
7891             if ( phy == null ) {
7892                 return false;
7893             }
7894             if ( phy.getNumberOfExternalNodes() != 3 ) {
7895                 System.out.println( phy.toString() );
7896                 return false;
7897             }
7898             if ( !phy.getName().equals( "" ) ) {
7899                 return false;
7900             }
7901             if ( phy.isRooted() ) {
7902                 return false;
7903             }
7904             //3
7905             if ( !p.hasNext() ) {
7906                 return false;
7907             }
7908             phy = p.next();
7909             if ( phy == null ) {
7910                 return false;
7911             }
7912             if ( phy.getNumberOfExternalNodes() != 4 ) {
7913                 return false;
7914             }
7915             if ( !phy.getName().equals( "" ) ) {
7916                 return false;
7917             }
7918             if ( !phy.isRooted() ) {
7919                 return false;
7920             }
7921             //4
7922             if ( !p.hasNext() ) {
7923                 return false;
7924             }
7925             phy = p.next();
7926             if ( phy == null ) {
7927                 return false;
7928             }
7929             if ( phy.getNumberOfExternalNodes() != 5 ) {
7930                 System.out.println( phy.getNumberOfExternalNodes() );
7931                 return false;
7932             }
7933             if ( !phy.getName().equals( "" ) ) {
7934                 return false;
7935             }
7936             if ( !phy.isRooted() ) {
7937                 return false;
7938             }
7939             //5
7940             if ( !p.hasNext() ) {
7941                 return false;
7942             }
7943             phy = p.next();
7944             if ( phy == null ) {
7945                 return false;
7946             }
7947             if ( phy.getNumberOfExternalNodes() != 3 ) {
7948                 return false;
7949             }
7950             if ( !phy.getName().equals( "" ) ) {
7951                 return false;
7952             }
7953             if ( phy.isRooted() ) {
7954                 return false;
7955             }
7956             //6
7957             if ( !p.hasNext() ) {
7958                 return false;
7959             }
7960             phy = p.next();
7961             if ( phy == null ) {
7962                 return false;
7963             }
7964             if ( phy.getNumberOfExternalNodes() != 2 ) {
7965                 return false;
7966             }
7967             if ( !phy.getName().equals( "" ) ) {
7968                 return false;
7969             }
7970             if ( !phy.isRooted() ) {
7971                 return false;
7972             }
7973             //7
7974             if ( !p.hasNext() ) {
7975                 return false;
7976             }
7977             phy = p.next();
7978             if ( phy.getNumberOfExternalNodes() != 3 ) {
7979                 return false;
7980             }
7981             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7982                 return false;
7983             }
7984             if ( !phy.isRooted() ) {
7985                 return false;
7986             }
7987             //8
7988             if ( !p.hasNext() ) {
7989                 return false;
7990             }
7991             phy = p.next();
7992             if ( phy.getNumberOfExternalNodes() != 3 ) {
7993                 return false;
7994             }
7995             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7996                 return false;
7997             }
7998             if ( !phy.getName().equals( "tree 8" ) ) {
7999                 return false;
8000             }
8001             //9
8002             if ( !p.hasNext() ) {
8003                 return false;
8004             }
8005             phy = p.next();
8006             if ( phy.getNumberOfExternalNodes() != 3 ) {
8007                 return false;
8008             }
8009             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
8010                 return false;
8011             }
8012             if ( !phy.getName().equals( "tree 9" ) ) {
8013                 return false;
8014             }
8015             //10
8016             if ( !p.hasNext() ) {
8017                 return false;
8018             }
8019             phy = p.next();
8020             if ( phy.getNumberOfExternalNodes() != 3 ) {
8021                 return false;
8022             }
8023             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8024                 return false;
8025             }
8026             if ( !phy.getName().equals( "tree 10" ) ) {
8027                 return false;
8028             }
8029             if ( !phy.isRooted() ) {
8030                 return false;
8031             }
8032             //11
8033             if ( !p.hasNext() ) {
8034                 return false;
8035             }
8036             phy = p.next();
8037             if ( phy.getNumberOfExternalNodes() != 3 ) {
8038                 return false;
8039             }
8040             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
8041                 return false;
8042             }
8043             if ( !phy.getName().equals( "tree 11" ) ) {
8044                 return false;
8045             }
8046             if ( phy.isRooted() ) {
8047                 return false;
8048             }
8049             //12
8050             if ( !p.hasNext() ) {
8051                 return false;
8052             }
8053             phy = p.next();
8054             if ( phy.getNumberOfExternalNodes() != 3 ) {
8055                 return false;
8056             }
8057             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
8058                 return false;
8059             }
8060             if ( !phy.getName().equals( "tree 12" ) ) {
8061                 return false;
8062             }
8063             if ( !phy.isRooted() ) {
8064                 return false;
8065             }
8066             //13
8067             if ( !p.hasNext() ) {
8068                 return false;
8069             }
8070             phy = p.next();
8071             if ( phy.getNumberOfExternalNodes() != 3 ) {
8072                 return false;
8073             }
8074             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8075                 return false;
8076             }
8077             if ( !phy.getName().equals( "tree 13" ) ) {
8078                 return false;
8079             }
8080             if ( !phy.isRooted() ) {
8081                 return false;
8082             }
8083             //14
8084             if ( !p.hasNext() ) {
8085                 return false;
8086             }
8087             phy = p.next();
8088             if ( phy.getNumberOfExternalNodes() != 10 ) {
8089                 System.out.println( phy.getNumberOfExternalNodes() );
8090                 return false;
8091             }
8092             if ( !phy
8093                     .toNewHampshire()
8094                     .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;" ) ) {
8095                 System.out.println( phy.toNewHampshire() );
8096                 return false;
8097             }
8098             if ( !phy.getName().equals( "tree 14" ) ) {
8099                 return false;
8100             }
8101             if ( !phy.isRooted() ) {
8102                 return false;
8103             }
8104             //15
8105             if ( !p.hasNext() ) {
8106                 return false;
8107             }
8108             phy = p.next();
8109             if ( phy.getNumberOfExternalNodes() != 10 ) {
8110                 System.out.println( phy.getNumberOfExternalNodes() );
8111                 return false;
8112             }
8113             if ( !phy
8114                     .toNewHampshire()
8115                     .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;" ) ) {
8116                 System.out.println( phy.toNewHampshire() );
8117                 return false;
8118             }
8119             if ( !phy.getName().equals( "tree 15" ) ) {
8120                 return false;
8121             }
8122             if ( phy.isRooted() ) {
8123                 return false;
8124             }
8125             //16
8126             if ( !p.hasNext() ) {
8127                 return false;
8128             }
8129             phy = p.next();
8130             if ( phy.getNumberOfExternalNodes() != 10 ) {
8131                 System.out.println( phy.getNumberOfExternalNodes() );
8132                 return false;
8133             }
8134             if ( !phy
8135                     .toNewHampshire()
8136                     .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;" ) ) {
8137                 System.out.println( phy.toNewHampshire() );
8138                 return false;
8139             }
8140             if ( !phy.getName().equals( "tree 16" ) ) {
8141                 return false;
8142             }
8143             if ( !phy.isRooted() ) {
8144                 return false;
8145             }
8146             //17
8147             if ( !p.hasNext() ) {
8148                 return false;
8149             }
8150             phy = p.next();
8151             if ( phy.getNumberOfExternalNodes() != 10 ) {
8152                 System.out.println( phy.getNumberOfExternalNodes() );
8153                 return false;
8154             }
8155             if ( !phy
8156                     .toNewHampshire()
8157                     .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;" ) ) {
8158                 System.out.println( phy.toNewHampshire() );
8159                 return false;
8160             }
8161             if ( !phy.getName().equals( "tree 17" ) ) {
8162                 return false;
8163             }
8164             if ( phy.isRooted() ) {
8165                 return false;
8166             }
8167             //
8168             if ( p.hasNext() ) {
8169                 return false;
8170             }
8171             phy = p.next();
8172             if ( phy != null ) {
8173                 return false;
8174             }
8175             p.reset();
8176             //0
8177             if ( !p.hasNext() ) {
8178                 return false;
8179             }
8180             phy = p.next();
8181             if ( phy == null ) {
8182                 return false;
8183             }
8184             if ( phy.getNumberOfExternalNodes() != 10 ) {
8185                 return false;
8186             }
8187             if ( !phy.getName().equals( "tree 0" ) ) {
8188                 return false;
8189             }
8190             //1
8191             if ( !p.hasNext() ) {
8192                 return false;
8193             }
8194             phy = p.next();
8195             if ( phy == null ) {
8196                 return false;
8197             }
8198             if ( phy.getNumberOfExternalNodes() != 10 ) {
8199                 return false;
8200             }
8201             if ( !phy.getName().equals( "tree 1" ) ) {
8202                 return false;
8203             }
8204             //2
8205             if ( !p.hasNext() ) {
8206                 return false;
8207             }
8208             phy = p.next();
8209             if ( phy == null ) {
8210                 return false;
8211             }
8212             if ( phy.getNumberOfExternalNodes() != 3 ) {
8213                 return false;
8214             }
8215             if ( !phy.getName().equals( "" ) ) {
8216                 return false;
8217             }
8218             if ( phy.isRooted() ) {
8219                 return false;
8220             }
8221             //3
8222             if ( !p.hasNext() ) {
8223                 return false;
8224             }
8225             phy = p.next();
8226             if ( phy == null ) {
8227                 return false;
8228             }
8229             if ( phy.getNumberOfExternalNodes() != 4 ) {
8230                 return false;
8231             }
8232             if ( !phy.getName().equals( "" ) ) {
8233                 return false;
8234             }
8235             if ( !phy.isRooted() ) {
8236                 return false;
8237             }
8238             //4
8239             if ( !p.hasNext() ) {
8240                 return false;
8241             }
8242             phy = p.next();
8243             if ( phy == null ) {
8244                 return false;
8245             }
8246             if ( phy.getNumberOfExternalNodes() != 5 ) {
8247                 System.out.println( phy.getNumberOfExternalNodes() );
8248                 return false;
8249             }
8250             if ( !phy.getName().equals( "" ) ) {
8251                 return false;
8252             }
8253             if ( !phy.isRooted() ) {
8254                 return false;
8255             }
8256             //5
8257             if ( !p.hasNext() ) {
8258                 return false;
8259             }
8260             phy = p.next();
8261             if ( phy == null ) {
8262                 return false;
8263             }
8264             if ( phy.getNumberOfExternalNodes() != 3 ) {
8265                 return false;
8266             }
8267             if ( !phy.getName().equals( "" ) ) {
8268                 return false;
8269             }
8270             if ( phy.isRooted() ) {
8271                 return false;
8272             }
8273             //
8274             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
8275             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
8276             // 0
8277             if ( !p2.hasNext() ) {
8278                 return false;
8279             }
8280             phy = p2.next();
8281             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8282                 return false;
8283             }
8284             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8285                 return false;
8286             }
8287             // 1
8288             if ( !p2.hasNext() ) {
8289                 return false;
8290             }
8291             phy = p2.next();
8292             // 2
8293             if ( !p2.hasNext() ) {
8294                 return false;
8295             }
8296             phy = p2.next();
8297             // 3
8298             if ( !p2.hasNext() ) {
8299                 return false;
8300             }
8301             phy = p2.next();
8302             // 4
8303             if ( !p2.hasNext() ) {
8304                 return false;
8305             }
8306             phy = p2.next();
8307             // 5
8308             if ( !p2.hasNext() ) {
8309                 return false;
8310             }
8311             phy = p2.next();
8312             // 6
8313             if ( !p2.hasNext() ) {
8314                 return false;
8315             }
8316             phy = p2.next();
8317             // 7
8318             if ( !p2.hasNext() ) {
8319                 return false;
8320             }
8321             phy = p2.next();
8322             // 8
8323             if ( !p2.hasNext() ) {
8324                 return false;
8325             }
8326             phy = p2.next();
8327             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
8328                 return false;
8329             }
8330             if ( p2.hasNext() ) {
8331                 return false;
8332             }
8333             phy = p2.next();
8334             if ( phy != null ) {
8335                 return false;
8336             }
8337             // 0
8338             p2.reset();
8339             if ( !p2.hasNext() ) {
8340                 return false;
8341             }
8342             phy = p2.next();
8343             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8344                 return false;
8345             }
8346             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8347                 return false;
8348             }
8349         }
8350         catch ( final Exception e ) {
8351             e.printStackTrace( System.out );
8352             return false;
8353         }
8354         return true;
8355     }
8356
8357     private static boolean testNexusTreeParsingTranslating() {
8358         try {
8359             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8360             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
8361             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
8362             if ( phylogenies.length != 1 ) {
8363                 return false;
8364             }
8365             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8366                 return false;
8367             }
8368             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8369                 return false;
8370             }
8371             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8372                 return false;
8373             }
8374             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8375                 return false;
8376             }
8377             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8378                     .equals( "Aranaeus" ) ) {
8379                 return false;
8380             }
8381             phylogenies = null;
8382             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
8383             if ( phylogenies.length != 3 ) {
8384                 return false;
8385             }
8386             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8387                 return false;
8388             }
8389             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8390                 return false;
8391             }
8392             if ( phylogenies[ 0 ].isRooted() ) {
8393                 return false;
8394             }
8395             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8396                 return false;
8397             }
8398             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8399                 return false;
8400             }
8401             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8402                     .equals( "Aranaeus" ) ) {
8403                 return false;
8404             }
8405             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8406                 return false;
8407             }
8408             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8409                 return false;
8410             }
8411             if ( phylogenies[ 1 ].isRooted() ) {
8412                 return false;
8413             }
8414             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8415                 return false;
8416             }
8417             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8418                 return false;
8419             }
8420             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8421                     .equals( "Aranaeus" ) ) {
8422                 return false;
8423             }
8424             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8425                 return false;
8426             }
8427             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8428                 return false;
8429             }
8430             if ( !phylogenies[ 2 ].isRooted() ) {
8431                 return false;
8432             }
8433             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8434                 return false;
8435             }
8436             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8437                 return false;
8438             }
8439             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8440                     .equals( "Aranaeus" ) ) {
8441                 return false;
8442             }
8443             phylogenies = null;
8444             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8445             if ( phylogenies.length != 3 ) {
8446                 return false;
8447             }
8448             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8449                 return false;
8450             }
8451             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8452                 return false;
8453             }
8454             if ( phylogenies[ 0 ].isRooted() ) {
8455                 return false;
8456             }
8457             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8458                 return false;
8459             }
8460             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8461                 return false;
8462             }
8463             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8464                     .equals( "Aranaeus" ) ) {
8465                 return false;
8466             }
8467             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8468                 return false;
8469             }
8470             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8471                 return false;
8472             }
8473             if ( phylogenies[ 1 ].isRooted() ) {
8474                 return false;
8475             }
8476             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8477                 return false;
8478             }
8479             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8480                 return false;
8481             }
8482             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8483                     .equals( "Aranaeus" ) ) {
8484                 return false;
8485             }
8486             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8487                 return false;
8488             }
8489             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8490                 return false;
8491             }
8492             if ( !phylogenies[ 2 ].isRooted() ) {
8493                 return false;
8494             }
8495             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8496                 return false;
8497             }
8498             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8499                 return false;
8500             }
8501             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8502                     .equals( "Aranaeus" ) ) {
8503                 return false;
8504             }
8505             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8506             if ( phylogenies.length != 3 ) {
8507                 return false;
8508             }
8509             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8510                            0.00100049 ) ) {
8511                 return false;
8512             }
8513         }
8514         catch ( final Exception e ) {
8515             e.printStackTrace( System.out );
8516             return false;
8517         }
8518         return true;
8519     }
8520
8521     private static boolean testNHParsing() {
8522         try {
8523             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8524             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8525             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8526                 return false;
8527             }
8528             final NHXParser nhxp = new NHXParser();
8529             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8530             nhxp.setReplaceUnderscores( true );
8531             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8532             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8533                 return false;
8534             }
8535             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8536                 return false;
8537             }
8538             final Phylogeny p1b = factory
8539                     .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 ",
8540                              new NHXParser() )[ 0 ];
8541             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8542                 return false;
8543             }
8544             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8545                 return false;
8546             }
8547             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ).toString(), new NHXParser() )[ 0 ];
8548             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8549             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8550             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ).toString(), new NHXParser() )[ 0 ];
8551             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8552             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8553             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8554             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8555             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8556             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8557             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8558                     + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8559                     + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8560                     new NHXParser() );
8561             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8562                 return false;
8563             }
8564             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8565                 return false;
8566             }
8567             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8568                 return false;
8569             }
8570             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8571                 return false;
8572             }
8573             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8574             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8575             final String p16_S = "((A,B),C)";
8576             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8577             if ( p16.length != 1 ) {
8578                 return false;
8579             }
8580             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8581                 return false;
8582             }
8583             final String p17_S = "(C,(A,B))";
8584             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8585             if ( p17.length != 1 ) {
8586                 return false;
8587             }
8588             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8589                 return false;
8590             }
8591             final String p18_S = "((A,B),(C,D))";
8592             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8593             if ( p18.length != 1 ) {
8594                 return false;
8595             }
8596             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8597                 return false;
8598             }
8599             final String p19_S = "(((A,B),C),D)";
8600             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8601             if ( p19.length != 1 ) {
8602                 return false;
8603             }
8604             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8605                 return false;
8606             }
8607             final String p20_S = "(A,(B,(C,D)))";
8608             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8609             if ( p20.length != 1 ) {
8610                 return false;
8611             }
8612             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8613                 return false;
8614             }
8615             final String p21_S = "(A,(B,(C,(D,E))))";
8616             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8617             if ( p21.length != 1 ) {
8618                 return false;
8619             }
8620             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8621                 return false;
8622             }
8623             final String p22_S = "((((A,B),C),D),E)";
8624             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8625             if ( p22.length != 1 ) {
8626                 return false;
8627             }
8628             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8629                 return false;
8630             }
8631             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8632             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8633             if ( p23.length != 1 ) {
8634                 System.out.println( "xl=" + p23.length );
8635                 System.exit( -1 );
8636                 return false;
8637             }
8638             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8639                 return false;
8640             }
8641             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8642             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8643             if ( p24.length != 1 ) {
8644                 return false;
8645             }
8646             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8647                 return false;
8648             }
8649             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8650             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8651             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8652             if ( p241.length != 2 ) {
8653                 return false;
8654             }
8655             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8656                 return false;
8657             }
8658             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8659                 return false;
8660             }
8661             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8662                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8663                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8664                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8665                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8666                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8667                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8668                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8669             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8670             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8671                 return false;
8672             }
8673             final String p26_S = "(A,B)ab";
8674             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8675             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8676                 return false;
8677             }
8678             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8679             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8680             if ( p27s.length != 1 ) {
8681                 System.out.println( "xxl=" + p27s.length );
8682                 System.exit( -1 );
8683                 return false;
8684             }
8685             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8686                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8687                 System.exit( -1 );
8688                 return false;
8689             }
8690             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8691                                                     new NHXParser() );
8692             if ( p27.length != 1 ) {
8693                 System.out.println( "yl=" + p27.length );
8694                 System.exit( -1 );
8695                 return false;
8696             }
8697             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8698                 System.out.println( p27[ 0 ].toNewHampshireX() );
8699                 System.exit( -1 );
8700                 return false;
8701             }
8702             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8703             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8704             final String p28_S3 = "(A,B)ab";
8705             final String p28_S4 = "((((A,B),C),D),;E;)";
8706             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8707                                                     new NHXParser() );
8708             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8709                 return false;
8710             }
8711             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8712                 return false;
8713             }
8714             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8715                 return false;
8716             }
8717             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8718                 return false;
8719             }
8720             if ( p28.length != 4 ) {
8721                 return false;
8722             }
8723             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";
8724             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8725             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8726                 return false;
8727             }
8728             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";
8729             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8730             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8731                 return false;
8732             }
8733             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8734             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8735             if ( ( p32.length != 0 ) ) {
8736                 return false;
8737             }
8738             final String p33_S = "A";
8739             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8740             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8741                 return false;
8742             }
8743             final String p34_S = "B;";
8744             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8745             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8746                 return false;
8747             }
8748             final String p35_S = "B:0.2";
8749             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8750             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8751                 return false;
8752             }
8753             final String p36_S = "(A)";
8754             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8755             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8756                 return false;
8757             }
8758             final String p37_S = "((A))";
8759             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8760             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8761                 return false;
8762             }
8763             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8764             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8765             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8766                 return false;
8767             }
8768             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8769             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8770             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8771                 return false;
8772             }
8773             final String p40_S = "(A,B,C)";
8774             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8775             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8776                 return false;
8777             }
8778             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8779             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8780             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8781                 return false;
8782             }
8783             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8784             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8785             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8786                 return false;
8787             }
8788             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)";
8789             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8790             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8791                 return false;
8792             }
8793             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)))";
8794             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8795             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8796                 return false;
8797             }
8798             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8799             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8800             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8801                 return false;
8802             }
8803             final String p46_S = "";
8804             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8805             if ( p46.length != 0 ) {
8806                 return false;
8807             }
8808             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ).toString(), new NHXParser() )[ 0 ];
8809             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8810                 return false;
8811             }
8812             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8813             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8814                 return false;
8815             }
8816             final Phylogeny p49 = factory
8817                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ).toString(),
8818                              new NHXParser() )[ 0 ];
8819             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8820                 return false;
8821             }
8822             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8823             if ( p50.getNode( "A" ) == null ) {
8824                 return false;
8825             }
8826             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8827                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8828                 return false;
8829             }
8830             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8831                 return false;
8832             }
8833             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8834                     .equals( "((A,B)88:2.0,C);" ) ) {
8835                 return false;
8836             }
8837             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8838             if ( p51.getNode( "A(A" ) == null ) {
8839                 return false;
8840             }
8841             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8842             if ( p52.getNode( "A(A" ) == null ) {
8843                 return false;
8844             }
8845             final Phylogeny p53 = factory
8846                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ).toString(),
8847                              new NHXParser() )[ 0 ];
8848             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8849                 return false;
8850             }
8851             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ).toString(), new NHXParser() )[ 0 ];
8852             if ( p54.getNode( "A" ) == null ) {
8853                 return false;
8854             }
8855             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8856                 return false;
8857             }
8858             final Phylogeny p55 = factory
8859                     .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(),
8860                              new NHXParser() )[ 0 ];
8861             if ( !p55
8862                     .toNewHampshire()
8863                     .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);" ) ) {
8864                 System.out.println( p55.toNewHampshire() );
8865                 return false;
8866             }
8867             final Phylogeny p56 = factory
8868                     .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(),
8869                              new NHXParser() )[ 0 ];
8870             if ( !p56
8871                     .toNewHampshire()
8872                     .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);" ) ) {
8873                 System.out.println( p56.toNewHampshire() );
8874                 return false;
8875             }
8876             final Phylogeny p57 = factory
8877                     .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(),
8878                              new NHXParser() )[ 0 ];
8879             if ( !p57
8880                     .toNewHampshire()
8881                     .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);" ) ) {
8882                 System.out.println( p56.toNewHampshire() );
8883                 return false;
8884             }
8885             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8886             final Phylogeny p58 = factory.create( s58, new NHXParser() )[ 0 ];
8887             if ( !p58.toNewHampshire().equals( s58 ) ) {
8888                 System.out.println( p58.toNewHampshire() );
8889                 return false;
8890             }
8891             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8892             final Phylogeny p59 = factory.create( s59 , new NHXParser() )[ 0 ];
8893             if ( !p59.toNewHampshire().equals( s59 ) ) {
8894                 System.out.println( p59.toNewHampshire() );
8895                 return false;
8896             }
8897             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8898             final Phylogeny p60 = factory.create( s60, new NHXParser() )[ 0 ];
8899             if ( !p60.toNewHampshire().equals( s60 ) ) {
8900                 System.out.println( p60.toNewHampshire() );
8901                 return false;
8902             }
8903             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8904             final Phylogeny p61 = factory.create( s61, new NHXParser() )[ 0 ];
8905             if ( !p61.toNewHampshire()
8906                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8907                 System.out.println( p61.toNewHampshire() );
8908                 return false;
8909             }
8910         }
8911         catch ( final Exception e ) {
8912             e.printStackTrace( System.out );
8913             return false;
8914         }
8915         return true;
8916     }
8917     
8918     private static boolean testNHParsingSpecialChars() {
8919         try {
8920             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();   
8921             final String i0 = "(A!+=~QWERTY!@#$%^&*-,€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ)";
8922             final Phylogeny p0 = factory.create( i0, new NHXParser() )[ 0 ];
8923             if ( !p0.toNewHampshireX().equals( i0 ) ) {
8924                 System.out.println();
8925                 System.out.println( p0.toNewHampshireX() );
8926                 System.out.println( i0 );
8927                 return false;
8928             }
8929             final String i1 = "(हिंदी,한글,ไทย,'Tiếng Việt',ひらがなカタカナ漢字,繁體字,русский)";
8930             final Phylogeny p1 = factory.create( i1, new NHXParser() )[ 0 ];
8931             if ( !p1.toNewHampshireX().equals( i1 ) ) {
8932                 System.out.println();
8933                 System.out.println( p1.toNewHampshireX() );
8934                 System.out.println( i1 );
8935                 return false;
8936             }
8937         }
8938         catch ( final Exception e ) {
8939             e.printStackTrace( System.out );
8940             return false;
8941         }
8942         return true;
8943     }
8944     
8945     
8946     
8947     private static boolean testNHParsingIter() {
8948         try {
8949             final String p0_str = "(A,B);";
8950             final NHXParser p = new NHXParser();
8951             p.setSource( p0_str );
8952             if ( !p.hasNext() ) {
8953                 return false;
8954             }
8955             final Phylogeny p0 = p.next();
8956             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8957                 System.out.println( p0.toNewHampshire() );
8958                 return false;
8959             }
8960             if ( p.hasNext() ) {
8961                 return false;
8962             }
8963             if ( p.next() != null ) {
8964                 return false;
8965             }
8966             //
8967             final String p00_str = "(A,B)root;";
8968             p.setSource( p00_str );
8969             final Phylogeny p00 = p.next();
8970             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8971                 System.out.println( p00.toNewHampshire() );
8972                 return false;
8973             }
8974             //
8975             final String p000_str = "A;";
8976             p.setSource( p000_str );
8977             final Phylogeny p000 = p.next();
8978             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8979                 System.out.println( p000.toNewHampshire() );
8980                 return false;
8981             }
8982             //
8983             final String p0000_str = "A";
8984             p.setSource( p0000_str );
8985             final Phylogeny p0000 = p.next();
8986             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8987                 System.out.println( p0000.toNewHampshire() );
8988                 return false;
8989             }
8990             //
8991             p.setSource( "(A)" );
8992             final Phylogeny p00000 = p.next();
8993             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8994                 System.out.println( p00000.toNewHampshire() );
8995                 return false;
8996             }
8997             //
8998             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8999             p.setSource( p1_str );
9000             if ( !p.hasNext() ) {
9001                 return false;
9002             }
9003             final Phylogeny p1_0 = p.next();
9004             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
9005                 System.out.println( p1_0.toNewHampshire() );
9006                 return false;
9007             }
9008             if ( !p.hasNext() ) {
9009                 return false;
9010             }
9011             final Phylogeny p1_1 = p.next();
9012             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
9013                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
9014                 return false;
9015             }
9016             if ( !p.hasNext() ) {
9017                 return false;
9018             }
9019             final Phylogeny p1_2 = p.next();
9020             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
9021                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
9022                 return false;
9023             }
9024             if ( !p.hasNext() ) {
9025                 return false;
9026             }
9027             final Phylogeny p1_3 = p.next();
9028             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
9029                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
9030                 return false;
9031             }
9032             if ( p.hasNext() ) {
9033                 return false;
9034             }
9035             if ( p.next() != null ) {
9036                 return false;
9037             }
9038             //
9039             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
9040             p.setSource( p2_str );
9041             if ( !p.hasNext() ) {
9042                 return false;
9043             }
9044             Phylogeny p2_0 = p.next();
9045             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9046                 System.out.println( p2_0.toNewHampshire() );
9047                 return false;
9048             }
9049             if ( !p.hasNext() ) {
9050                 return false;
9051             }
9052             Phylogeny p2_1 = p.next();
9053             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9054                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9055                 return false;
9056             }
9057             if ( !p.hasNext() ) {
9058                 return false;
9059             }
9060             Phylogeny p2_2 = p.next();
9061             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9062                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9063                 return false;
9064             }
9065             if ( !p.hasNext() ) {
9066                 return false;
9067             }
9068             Phylogeny p2_3 = p.next();
9069             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9070                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9071                 return false;
9072             }
9073             if ( !p.hasNext() ) {
9074                 return false;
9075             }
9076             Phylogeny p2_4 = p.next();
9077             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9078                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9079                 return false;
9080             }
9081             if ( p.hasNext() ) {
9082                 return false;
9083             }
9084             if ( p.next() != null ) {
9085                 return false;
9086             }
9087             ////
9088             p.reset();
9089             if ( !p.hasNext() ) {
9090                 return false;
9091             }
9092             p2_0 = p.next();
9093             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9094                 System.out.println( p2_0.toNewHampshire() );
9095                 return false;
9096             }
9097             if ( !p.hasNext() ) {
9098                 return false;
9099             }
9100             p2_1 = p.next();
9101             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9102                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9103                 return false;
9104             }
9105             if ( !p.hasNext() ) {
9106                 return false;
9107             }
9108             p2_2 = p.next();
9109             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9110                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9111                 return false;
9112             }
9113             if ( !p.hasNext() ) {
9114                 return false;
9115             }
9116             p2_3 = p.next();
9117             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9118                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9119                 return false;
9120             }
9121             if ( !p.hasNext() ) {
9122                 return false;
9123             }
9124             p2_4 = p.next();
9125             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9126                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9127                 return false;
9128             }
9129             if ( p.hasNext() ) {
9130                 return false;
9131             }
9132             if ( p.next() != null ) {
9133                 return false;
9134             }
9135             //
9136             final String p3_str = "((A,B),C)abc";
9137             p.setSource( p3_str );
9138             if ( !p.hasNext() ) {
9139                 return false;
9140             }
9141             final Phylogeny p3_0 = p.next();
9142             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
9143                 return false;
9144             }
9145             if ( p.hasNext() ) {
9146                 return false;
9147             }
9148             if ( p.next() != null ) {
9149                 return false;
9150             }
9151             //
9152             final String p4_str = "((A,B)ab,C)abc";
9153             p.setSource( p4_str );
9154             if ( !p.hasNext() ) {
9155                 return false;
9156             }
9157             final Phylogeny p4_0 = p.next();
9158             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
9159                 return false;
9160             }
9161             if ( p.hasNext() ) {
9162                 return false;
9163             }
9164             if ( p.next() != null ) {
9165                 return false;
9166             }
9167             //
9168             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
9169             p.setSource( p5_str );
9170             if ( !p.hasNext() ) {
9171                 return false;
9172             }
9173             final Phylogeny p5_0 = p.next();
9174             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
9175                 return false;
9176             }
9177             if ( p.hasNext() ) {
9178                 return false;
9179             }
9180             if ( p.next() != null ) {
9181                 return false;
9182             }
9183             //
9184             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
9185             p.setSource( p6_str );
9186             if ( !p.hasNext() ) {
9187                 return false;
9188             }
9189             Phylogeny p6_0 = p.next();
9190             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9191                 return false;
9192             }
9193             if ( p.hasNext() ) {
9194                 return false;
9195             }
9196             if ( p.next() != null ) {
9197                 return false;
9198             }
9199             p.reset();
9200             if ( !p.hasNext() ) {
9201                 return false;
9202             }
9203             p6_0 = p.next();
9204             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9205                 return false;
9206             }
9207             if ( p.hasNext() ) {
9208                 return false;
9209             }
9210             if ( p.next() != null ) {
9211                 return false;
9212             }
9213             //
9214             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
9215             p.setSource( p7_str );
9216             if ( !p.hasNext() ) {
9217                 return false;
9218             }
9219             Phylogeny p7_0 = p.next();
9220             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9221                 return false;
9222             }
9223             if ( p.hasNext() ) {
9224                 return false;
9225             }
9226             if ( p.next() != null ) {
9227                 return false;
9228             }
9229             p.reset();
9230             if ( !p.hasNext() ) {
9231                 return false;
9232             }
9233             p7_0 = p.next();
9234             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9235                 return false;
9236             }
9237             if ( p.hasNext() ) {
9238                 return false;
9239             }
9240             if ( p.next() != null ) {
9241                 return false;
9242             }
9243             //
9244             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
9245             p.setSource( p8_str );
9246             if ( !p.hasNext() ) {
9247                 return false;
9248             }
9249             Phylogeny p8_0 = p.next();
9250             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9251                 return false;
9252             }
9253             if ( !p.hasNext() ) {
9254                 return false;
9255             }
9256             if ( !p.hasNext() ) {
9257                 return false;
9258             }
9259             Phylogeny p8_1 = p.next();
9260             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9261                 return false;
9262             }
9263             if ( p.hasNext() ) {
9264                 return false;
9265             }
9266             if ( p.next() != null ) {
9267                 return false;
9268             }
9269             p.reset();
9270             if ( !p.hasNext() ) {
9271                 return false;
9272             }
9273             p8_0 = p.next();
9274             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9275                 return false;
9276             }
9277             if ( !p.hasNext() ) {
9278                 return false;
9279             }
9280             p8_1 = p.next();
9281             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9282                 return false;
9283             }
9284             if ( p.hasNext() ) {
9285                 return false;
9286             }
9287             if ( p.next() != null ) {
9288                 return false;
9289             }
9290             p.reset();
9291             //
9292             p.setSource( "" );
9293             if ( p.hasNext() ) {
9294                 return false;
9295             }
9296             //
9297             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
9298             if ( !p.hasNext() ) {
9299                 return false;
9300             }
9301             Phylogeny p_27 = p.next();
9302             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9303                 System.out.println( p_27.toNewHampshireX() );
9304                 System.exit( -1 );
9305                 return false;
9306             }
9307             if ( p.hasNext() ) {
9308                 return false;
9309             }
9310             if ( p.next() != null ) {
9311                 return false;
9312             }
9313             p.reset();
9314             if ( !p.hasNext() ) {
9315                 return false;
9316             }
9317             p_27 = p.next();
9318             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9319                 System.out.println( p_27.toNewHampshireX() );
9320                 System.exit( -1 );
9321                 return false;
9322             }
9323             if ( p.hasNext() ) {
9324                 return false;
9325             }
9326             if ( p.next() != null ) {
9327                 return false;
9328             }
9329             //
9330             final String p30_str = "(A,B);(C,D)";
9331             final NHXParser p30 = new NHXParser();
9332             p30.setSource( p30_str );
9333             if ( !p30.hasNext() ) {
9334                 return false;
9335             }
9336             Phylogeny phy30 = p30.next();
9337             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9338                 System.out.println( phy30.toNewHampshire() );
9339                 return false;
9340             }
9341             if ( !p30.hasNext() ) {
9342                 return false;
9343             }
9344             Phylogeny phy301 = p30.next();
9345             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9346                 System.out.println( phy301.toNewHampshire() );
9347                 return false;
9348             }
9349             if ( p30.hasNext() ) {
9350                 return false;
9351             }
9352             if ( p30.hasNext() ) {
9353                 return false;
9354             }
9355             if ( p30.next() != null ) {
9356                 return false;
9357             }
9358             if ( p30.next() != null ) {
9359                 return false;
9360             }
9361             p30.reset();
9362             if ( !p30.hasNext() ) {
9363                 return false;
9364             }
9365             phy30 = p30.next();
9366             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9367                 System.out.println( phy30.toNewHampshire() );
9368                 return false;
9369             }
9370             if ( !p30.hasNext() ) {
9371                 return false;
9372             }
9373             phy301 = p30.next();
9374             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9375                 System.out.println( phy301.toNewHampshire() );
9376                 return false;
9377             }
9378             if ( p30.hasNext() ) {
9379                 return false;
9380             }
9381             if ( p30.hasNext() ) {
9382                 return false;
9383             }
9384             if ( p30.next() != null ) {
9385                 return false;
9386             }
9387             if ( p30.next() != null ) {
9388                 return false;
9389             }
9390         }
9391         catch ( final Exception e ) {
9392             e.printStackTrace( System.out );
9393             return false;
9394         }
9395         return true;
9396     }
9397
9398     private static boolean testNHXconversion() {
9399         try {
9400             final PhylogenyNode n1 = new PhylogenyNode();
9401             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9402             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9403             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9404             final PhylogenyNode n5 = PhylogenyNode
9405                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
9406             final PhylogenyNode n6 = PhylogenyNode
9407                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
9408             if ( !n1.toNewHampshireX().equals( "" ) ) {
9409                 return false;
9410             }
9411             if ( !n2.toNewHampshireX().equals( "" ) ) {
9412                 return false;
9413             }
9414             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
9415                 return false;
9416             }
9417             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
9418                 return false;
9419             }
9420             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
9421                 return false;
9422             }
9423             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9424                 System.out.println( n6.toNewHampshireX() );
9425                 return false;
9426             }
9427             final PhylogenyNode n7 = new PhylogenyNode();
9428             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9429             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9430                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9431                 System.out.println( n7
9432                                     .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9433                 return false;
9434             }
9435         }
9436         catch ( final Exception e ) {
9437             e.printStackTrace( System.out );
9438             return false;
9439         }
9440         return true;
9441     }
9442
9443     private static boolean testNHXNodeParsing() {
9444         try {
9445             final PhylogenyNode n1 = new PhylogenyNode();
9446             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9447             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9448             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9449             final PhylogenyNode n5 = PhylogenyNode
9450                     .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]" );
9451             if ( !n3.getName().equals( "n3" ) ) {
9452                 return false;
9453             }
9454             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9455                 return false;
9456             }
9457             if ( n3.isDuplication() ) {
9458                 return false;
9459             }
9460             if ( n3.isHasAssignedEvent() ) {
9461                 return false;
9462             }
9463             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9464                 return false;
9465             }
9466             if ( !n4.getName().equals( "n4" ) ) {
9467                 return false;
9468             }
9469             if ( n4.getDistanceToParent() != 0.01 ) {
9470                 return false;
9471             }
9472             if ( !n5.getName().equals( "n5" ) ) {
9473                 return false;
9474             }
9475             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9476                 return false;
9477             }
9478             if ( n5.getDistanceToParent() != 0.1 ) {
9479                 return false;
9480             }
9481             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9482                 return false;
9483             }
9484             if ( !n5.isDuplication() ) {
9485                 return false;
9486             }
9487             if ( !n5.isHasAssignedEvent() ) {
9488                 return false;
9489             }
9490             final PhylogenyNode n8 = PhylogenyNode
9491                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9492                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9493             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9494                 return false;
9495             }
9496             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9497                 return false;
9498             }
9499             final PhylogenyNode n9 = PhylogenyNode
9500                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9501                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9502             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9503                 return false;
9504             }
9505             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9506                 return false;
9507             }
9508             final PhylogenyNode n10 = PhylogenyNode
9509                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9510             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9511                 return false;
9512             }
9513             final PhylogenyNode n20 = PhylogenyNode
9514                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9515             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9516                 return false;
9517             }
9518             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9519                 return false;
9520             }
9521             final PhylogenyNode n20x = PhylogenyNode
9522                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9523             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9524                 return false;
9525             }
9526             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9527                 return false;
9528             }
9529             final PhylogenyNode n20xx = PhylogenyNode
9530                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9531             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9532                 return false;
9533             }
9534             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9535                 return false;
9536             }
9537             final PhylogenyNode n20xxx = PhylogenyNode
9538                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9539             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9540                 return false;
9541             }
9542             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9543                 return false;
9544             }
9545             final PhylogenyNode n20xxxx = PhylogenyNode
9546                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9547             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9548                 return false;
9549             }
9550             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9551                 return false;
9552             }
9553             final PhylogenyNode n21 = PhylogenyNode
9554                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9555             if ( !n21.getName().equals( "N21_PIG" ) ) {
9556                 return false;
9557             }
9558             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9559                 return false;
9560             }
9561             final PhylogenyNode n21x = PhylogenyNode
9562                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9563             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9564                 return false;
9565             }
9566             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9567                 return false;
9568             }
9569             final PhylogenyNode n22 = PhylogenyNode
9570                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9571             if ( !n22.getName().equals( "n22/PIG" ) ) {
9572                 return false;
9573             }
9574             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9575                 return false;
9576             }
9577             final PhylogenyNode n23 = PhylogenyNode
9578                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9579             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9580                 return false;
9581             }
9582             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9583                 return false;
9584             }
9585             final PhylogenyNode a = PhylogenyNode
9586                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9587             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9588                 return false;
9589             }
9590             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9591                 return false;
9592             }
9593             final PhylogenyNode c1 = PhylogenyNode
9594                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9595                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9596             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9597                 return false;
9598             }
9599             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9600                 return false;
9601             }
9602             final PhylogenyNode c2 = PhylogenyNode
9603                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9604                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9605             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9606                 return false;
9607             }
9608             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9609                 return false;
9610             }
9611             final PhylogenyNode e3 = PhylogenyNode
9612                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9613             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9614                 return false;
9615             }
9616             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9617                 return false;
9618             }
9619             final PhylogenyNode n11 = PhylogenyNode
9620                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9621                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9622             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9623                 return false;
9624             }
9625             if ( n11.getDistanceToParent() != 0.4 ) {
9626                 return false;
9627             }
9628             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9629                 return false;
9630             }
9631             final PhylogenyNode n12 = PhylogenyNode
9632                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9633                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9634             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9635                 return false;
9636             }
9637             if ( n12.getDistanceToParent() != 0.4 ) {
9638                 return false;
9639             }
9640             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9641                 return false;
9642             }
9643             final PhylogenyNode o = PhylogenyNode
9644                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9645             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9646                 return false;
9647             }
9648             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9649                 return false;
9650             }
9651             if ( n1.getName().compareTo( "" ) != 0 ) {
9652                 return false;
9653             }
9654             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9655                 return false;
9656             }
9657             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9658                 return false;
9659             }
9660             if ( n2.getName().compareTo( "" ) != 0 ) {
9661                 return false;
9662             }
9663             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9664                 return false;
9665             }
9666             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9667                 return false;
9668             }
9669             final PhylogenyNode n00 = PhylogenyNode
9670                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9671             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9672                 return false;
9673             }
9674             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9675                 return false;
9676             }
9677             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9678             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9679                 return false;
9680             }
9681             final PhylogenyNode n13 = PhylogenyNode
9682                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9683             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9684                 return false;
9685             }
9686             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9687                 return false;
9688             }
9689             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9690                 return false;
9691             }
9692             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9693                 return false;
9694             }
9695             final PhylogenyNode n14 = PhylogenyNode
9696                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9697             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9698                 return false;
9699             }
9700             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9701                 return false;
9702             }
9703             final PhylogenyNode n15 = PhylogenyNode
9704                     .createInstanceFromNhxString( "something_wicked[123]",
9705                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9706             if ( !n15.getName().equals( "something_wicked" ) ) {
9707                 return false;
9708             }
9709             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9710                 return false;
9711             }
9712             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9713                 return false;
9714             }
9715             final PhylogenyNode n16 = PhylogenyNode
9716                     .createInstanceFromNhxString( "something_wicked2[9]",
9717                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9718             if ( !n16.getName().equals( "something_wicked2" ) ) {
9719                 return false;
9720             }
9721             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9722                 return false;
9723             }
9724             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9725                 return false;
9726             }
9727             final PhylogenyNode n17 = PhylogenyNode
9728                     .createInstanceFromNhxString( "something_wicked3[a]",
9729                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9730             if ( !n17.getName().equals( "something_wicked3" ) ) {
9731                 return false;
9732             }
9733             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9734                 return false;
9735             }
9736             final PhylogenyNode n18 = PhylogenyNode
9737                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9738             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9739                 return false;
9740             }
9741             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9742                 return false;
9743             }
9744             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9745                 return false;
9746             }
9747             final PhylogenyNode n19 = PhylogenyNode
9748                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9749             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9750                 return false;
9751             }
9752             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9753                 return false;
9754             }
9755             final PhylogenyNode n30 = PhylogenyNode
9756                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9757                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9758             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9759                 return false;
9760             }
9761             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9762                 return false;
9763             }
9764             final PhylogenyNode n31 = PhylogenyNode
9765                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9766                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9767             if ( n31.getNodeData().isHasTaxonomy() ) {
9768                 return false;
9769             }
9770             final PhylogenyNode n32 = PhylogenyNode
9771                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9772             if ( n32.getNodeData().isHasTaxonomy() ) {
9773                 return false;
9774             }
9775             final PhylogenyNode n40 = PhylogenyNode
9776                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9777             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9778                 return false;
9779             }
9780             final PhylogenyNode n41 = PhylogenyNode
9781                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9782             if ( n41.getNodeData().isHasTaxonomy() ) {
9783                 return false;
9784             }
9785             final PhylogenyNode n42 = PhylogenyNode
9786                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9787             if ( n42.getNodeData().isHasTaxonomy() ) {
9788                 return false;
9789             }
9790             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9791                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9792             if ( n43.getNodeData().isHasTaxonomy() ) {
9793                 return false;
9794             }
9795             final PhylogenyNode n44 = PhylogenyNode
9796                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9797             if ( n44.getNodeData().isHasTaxonomy() ) {
9798                 return false;
9799             }
9800         }
9801         catch ( final Exception e ) {
9802             e.printStackTrace( System.out );
9803             return false;
9804         }
9805         return true;
9806     }
9807
9808     private static boolean testNHXParsing() {
9809         try {
9810             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9811             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9812             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9813                 return false;
9814             }
9815             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]";
9816             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9817             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9818                 return false;
9819             }
9820             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]";
9821             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9822             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9823                 return false;
9824             }
9825             final Phylogeny[] p3 = factory
9826                     .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]",
9827                              new NHXParser() );
9828             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9829                 return false;
9830             }
9831             final Phylogeny[] p4 = factory
9832                     .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(]",
9833                              new NHXParser() );
9834             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9835                 return false;
9836             }
9837             final Phylogeny[] p5 = factory
9838                     .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(((]",
9839                              new NHXParser() );
9840             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9841                 return false;
9842             }
9843             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)";
9844             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)";
9845             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9846             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9847                 return false;
9848             }
9849             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)))";
9850             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)))";
9851             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9852             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9853                 return false;
9854             }
9855             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])   ))[,,, ])))))))";
9856             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9857             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9858             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9859                 return false;
9860             }
9861             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9862             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9863                 return false;
9864             }
9865             final Phylogeny p10 = factory
9866                     .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]",
9867                              new NHXParser() )[ 0 ];
9868             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9869                 return false;
9870             }
9871             final Phylogeny p11 = factory
9872                     .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]",
9873                              new NHXParser() )[ 0 ];
9874             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9875                 return false;
9876             }
9877             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]",
9878                                                   new NHXParser() )[ 0 ];
9879             if ( !p12.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9880                 return false;
9881             }
9882         }
9883         catch ( final Exception e ) {
9884             e.printStackTrace( System.out );
9885             return false;
9886         }
9887         return true;
9888     }
9889
9890     private static boolean testNHXParsingMB() {
9891         try {
9892             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9893             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9894                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9895                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9896                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9897                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9898                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9899                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9900                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9901                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9902             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9903                 return false;
9904             }
9905             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9906                 return false;
9907             }
9908             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9909                            0.1100000000000000e+00 ) ) {
9910                 return false;
9911             }
9912             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9913                 return false;
9914             }
9915             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9916                 return false;
9917             }
9918             final Phylogeny p2 = factory
9919                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9920                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9921                             + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9922                             + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9923                             + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9924                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9925                             + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9926                             + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9927                             + "7.369400000000000e-02}])",
9928                             new NHXParser() )[ 0 ];
9929             if ( p2.getNode( "1" ) == null ) {
9930                 return false;
9931             }
9932             if ( p2.getNode( "2" ) == null ) {
9933                 return false;
9934             }
9935         }
9936         catch ( final Exception e ) {
9937             e.printStackTrace( System.out );
9938             System.exit( -1 );
9939             return false;
9940         }
9941         return true;
9942     }
9943
9944     private static boolean testNHXParsingQuotes() {
9945         try {
9946             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9947             final NHXParser p = new NHXParser();
9948             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9949             if ( phylogenies_0.length != 5 ) {
9950                 return false;
9951             }
9952             final Phylogeny phy = phylogenies_0[ 4 ];
9953             if ( phy.getNumberOfExternalNodes() != 7 ) {
9954                 return false;
9955             }
9956             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9957                 return false;
9958             }
9959             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9960                 return false;
9961             }
9962             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9963                     .getScientificName().equals( "hsapiens" ) ) {
9964                 return false;
9965             }
9966             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9967                 return false;
9968             }
9969             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9970                 return false;
9971             }
9972             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9973                 return false;
9974             }
9975             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9976                 return false;
9977             }
9978             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9979                 return false;
9980             }
9981             final NHXParser p1p = new NHXParser();
9982             p1p.setIgnoreQuotes( true );
9983             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9984             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9985                 return false;
9986             }
9987             final NHXParser p2p = new NHXParser();
9988             p1p.setIgnoreQuotes( false );
9989             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9990             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9991                 return false;
9992             }
9993             final NHXParser p3p = new NHXParser();
9994             p3p.setIgnoreQuotes( false );
9995             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9996             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9997                 return false;
9998             }
9999             final NHXParser p4p = new NHXParser();
10000             p4p.setIgnoreQuotes( false );
10001             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
10002             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
10003                 return false;
10004             }
10005             final Phylogeny p10 = factory
10006                     .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]",
10007                              new NHXParser() )[ 0 ];
10008             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]";
10009             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
10010                 return false;
10011             }
10012             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
10013             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
10014                 return false;
10015             }
10016             final Phylogeny p12 = factory
10017                     .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]",
10018                              new NHXParser() )[ 0 ];
10019             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]";
10020             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
10021                 return false;
10022             }
10023             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
10024             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
10025                 return false;
10026             }
10027             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;";
10028             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
10029                 return false;
10030             }
10031             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
10032             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
10033                 return false;
10034             }
10035         }
10036         catch ( final Exception e ) {
10037             e.printStackTrace( System.out );
10038             return false;
10039         }
10040         return true;
10041     }
10042
10043     private static boolean testNodeRemoval() {
10044         try {
10045             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10046             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
10047             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
10048             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
10049                 return false;
10050             }
10051             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
10052             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
10053             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
10054                 return false;
10055             }
10056             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
10057             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
10058             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
10059                 return false;
10060             }
10061         }
10062         catch ( final Exception e ) {
10063             e.printStackTrace( System.out );
10064             return false;
10065         }
10066         return true;
10067     }
10068
10069     private static boolean testPhylogenyBranch() {
10070         try {
10071             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
10072             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
10073             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
10074             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
10075             if ( !a1b1.equals( a1b1 ) ) {
10076                 return false;
10077             }
10078             if ( !a1b1.equals( b1a1 ) ) {
10079                 return false;
10080             }
10081             if ( !b1a1.equals( a1b1 ) ) {
10082                 return false;
10083             }
10084             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
10085             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
10086             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
10087             if ( a1_b1.equals( b1_a1 ) ) {
10088                 return false;
10089             }
10090             if ( a1_b1.equals( a1_b1_ ) ) {
10091                 return false;
10092             }
10093             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
10094             if ( !a1_b1.equals( b1_a1_ ) ) {
10095                 return false;
10096             }
10097             if ( a1_b1_.equals( b1_a1_ ) ) {
10098                 return false;
10099             }
10100             if ( !a1_b1_.equals( b1_a1 ) ) {
10101                 return false;
10102             }
10103         }
10104         catch ( final Exception e ) {
10105             e.printStackTrace( System.out );
10106             return false;
10107         }
10108         return true;
10109     }
10110
10111     private static boolean testPhyloXMLparsingOfDistributionElement() {
10112         try {
10113             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10114             PhyloXmlParser xml_parser = null;
10115             try {
10116                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
10117             }
10118             catch ( final Exception e ) {
10119                 // Do nothing -- means were not running from jar.
10120             }
10121             if ( xml_parser == null ) {
10122                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
10123                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
10124                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
10125                 }
10126                 else {
10127                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
10128                 }
10129             }
10130             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml" ),
10131                                                               xml_parser );
10132             if ( xml_parser.getErrorCount() > 0 ) {
10133                 System.out.println( xml_parser.getErrorMessages().toString() );
10134                 return false;
10135             }
10136             if ( phylogenies_0.length != 1 ) {
10137                 return false;
10138             }
10139             final Phylogeny t1 = phylogenies_0[ 0 ];
10140             PhylogenyNode n = null;
10141             Distribution d = null;
10142             n = t1.getNode( "root node" );
10143             if ( !n.getNodeData().isHasDistribution() ) {
10144                 return false;
10145             }
10146             if ( n.getNodeData().getDistributions().size() != 1 ) {
10147                 return false;
10148             }
10149             d = n.getNodeData().getDistribution();
10150             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10151                 return false;
10152             }
10153             if ( d.getPoints().size() != 1 ) {
10154                 return false;
10155             }
10156             if ( d.getPolygons() != null ) {
10157                 return false;
10158             }
10159             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10160                 return false;
10161             }
10162             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10163                 return false;
10164             }
10165             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10166                 return false;
10167             }
10168             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10169                 return false;
10170             }
10171             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10172                 return false;
10173             }
10174             n = t1.getNode( "node a" );
10175             if ( !n.getNodeData().isHasDistribution() ) {
10176                 return false;
10177             }
10178             if ( n.getNodeData().getDistributions().size() != 2 ) {
10179                 return false;
10180             }
10181             d = n.getNodeData().getDistribution( 1 );
10182             if ( !d.getDesc().equals( "San Diego" ) ) {
10183                 return false;
10184             }
10185             if ( d.getPoints().size() != 1 ) {
10186                 return false;
10187             }
10188             if ( d.getPolygons() != null ) {
10189                 return false;
10190             }
10191             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10192                 return false;
10193             }
10194             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10195                 return false;
10196             }
10197             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10198                 return false;
10199             }
10200             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10201                 return false;
10202             }
10203             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10204                 return false;
10205             }
10206             n = t1.getNode( "node bb" );
10207             if ( !n.getNodeData().isHasDistribution() ) {
10208                 return false;
10209             }
10210             if ( n.getNodeData().getDistributions().size() != 1 ) {
10211                 return false;
10212             }
10213             d = n.getNodeData().getDistribution( 0 );
10214             if ( d.getPoints().size() != 3 ) {
10215                 return false;
10216             }
10217             if ( d.getPolygons().size() != 2 ) {
10218                 return false;
10219             }
10220             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10221                 return false;
10222             }
10223             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10224                 return false;
10225             }
10226             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10227                 return false;
10228             }
10229             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10230                 return false;
10231             }
10232             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10233                 return false;
10234             }
10235             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10236                 return false;
10237             }
10238             Polygon p = d.getPolygons().get( 0 );
10239             if ( p.getPoints().size() != 3 ) {
10240                 return false;
10241             }
10242             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10243                 return false;
10244             }
10245             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10246                 return false;
10247             }
10248             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10249                 return false;
10250             }
10251             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10252                 return false;
10253             }
10254             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10255                 return false;
10256             }
10257             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10258                 return false;
10259             }
10260             p = d.getPolygons().get( 1 );
10261             if ( p.getPoints().size() != 3 ) {
10262                 return false;
10263             }
10264             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10265                 return false;
10266             }
10267             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10268                 return false;
10269             }
10270             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10271                 return false;
10272             }
10273             // Roundtrip:
10274             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
10275             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
10276             if ( rt.length != 1 ) {
10277                 return false;
10278             }
10279             final Phylogeny t1_rt = rt[ 0 ];
10280             n = t1_rt.getNode( "root node" );
10281             if ( !n.getNodeData().isHasDistribution() ) {
10282                 return false;
10283             }
10284             if ( n.getNodeData().getDistributions().size() != 1 ) {
10285                 return false;
10286             }
10287             d = n.getNodeData().getDistribution();
10288             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10289                 return false;
10290             }
10291             if ( d.getPoints().size() != 1 ) {
10292                 return false;
10293             }
10294             if ( d.getPolygons() != null ) {
10295                 return false;
10296             }
10297             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10298                 return false;
10299             }
10300             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10301                 return false;
10302             }
10303             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10304                 return false;
10305             }
10306             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10307                 return false;
10308             }
10309             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10310                 return false;
10311             }
10312             n = t1_rt.getNode( "node a" );
10313             if ( !n.getNodeData().isHasDistribution() ) {
10314                 return false;
10315             }
10316             if ( n.getNodeData().getDistributions().size() != 2 ) {
10317                 return false;
10318             }
10319             d = n.getNodeData().getDistribution( 1 );
10320             if ( !d.getDesc().equals( "San Diego" ) ) {
10321                 return false;
10322             }
10323             if ( d.getPoints().size() != 1 ) {
10324                 return false;
10325             }
10326             if ( d.getPolygons() != null ) {
10327                 return false;
10328             }
10329             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10330                 return false;
10331             }
10332             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10333                 return false;
10334             }
10335             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10336                 return false;
10337             }
10338             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10339                 return false;
10340             }
10341             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10342                 return false;
10343             }
10344             n = t1_rt.getNode( "node bb" );
10345             if ( !n.getNodeData().isHasDistribution() ) {
10346                 return false;
10347             }
10348             if ( n.getNodeData().getDistributions().size() != 1 ) {
10349                 return false;
10350             }
10351             d = n.getNodeData().getDistribution( 0 );
10352             if ( d.getPoints().size() != 3 ) {
10353                 return false;
10354             }
10355             if ( d.getPolygons().size() != 2 ) {
10356                 return false;
10357             }
10358             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10359                 return false;
10360             }
10361             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10362                 return false;
10363             }
10364             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10365                 return false;
10366             }
10367             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10368                 return false;
10369             }
10370             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10371                 return false;
10372             }
10373             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10374                 return false;
10375             }
10376             p = d.getPolygons().get( 0 );
10377             if ( p.getPoints().size() != 3 ) {
10378                 return false;
10379             }
10380             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10381                 return false;
10382             }
10383             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10384                 return false;
10385             }
10386             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10387                 return false;
10388             }
10389             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10390                 return false;
10391             }
10392             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10393                 return false;
10394             }
10395             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10396                 return false;
10397             }
10398             p = d.getPolygons().get( 1 );
10399             if ( p.getPoints().size() != 3 ) {
10400                 return false;
10401             }
10402             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10403                 return false;
10404             }
10405             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10406                 return false;
10407             }
10408             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10409                 return false;
10410             }
10411         }
10412         catch ( final Exception e ) {
10413             e.printStackTrace( System.out );
10414             return false;
10415         }
10416         return true;
10417     }
10418
10419     private static boolean testPostOrderIterator() {
10420         try {
10421             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10422             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10423             PhylogenyNodeIterator it0;
10424             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
10425                 it0.next();
10426             }
10427             for( it0.reset(); it0.hasNext(); ) {
10428                 it0.next();
10429             }
10430             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10431             final PhylogenyNodeIterator it = t1.iteratorPostorder();
10432             if ( !it.next().getName().equals( "A" ) ) {
10433                 return false;
10434             }
10435             if ( !it.next().getName().equals( "B" ) ) {
10436                 return false;
10437             }
10438             if ( !it.next().getName().equals( "ab" ) ) {
10439                 return false;
10440             }
10441             if ( !it.next().getName().equals( "C" ) ) {
10442                 return false;
10443             }
10444             if ( !it.next().getName().equals( "D" ) ) {
10445                 return false;
10446             }
10447             if ( !it.next().getName().equals( "cd" ) ) {
10448                 return false;
10449             }
10450             if ( !it.next().getName().equals( "abcd" ) ) {
10451                 return false;
10452             }
10453             if ( !it.next().getName().equals( "E" ) ) {
10454                 return false;
10455             }
10456             if ( !it.next().getName().equals( "F" ) ) {
10457                 return false;
10458             }
10459             if ( !it.next().getName().equals( "ef" ) ) {
10460                 return false;
10461             }
10462             if ( !it.next().getName().equals( "G" ) ) {
10463                 return false;
10464             }
10465             if ( !it.next().getName().equals( "H" ) ) {
10466                 return false;
10467             }
10468             if ( !it.next().getName().equals( "gh" ) ) {
10469                 return false;
10470             }
10471             if ( !it.next().getName().equals( "efgh" ) ) {
10472                 return false;
10473             }
10474             if ( !it.next().getName().equals( "r" ) ) {
10475                 return false;
10476             }
10477             if ( it.hasNext() ) {
10478                 return false;
10479             }
10480         }
10481         catch ( final Exception e ) {
10482             e.printStackTrace( System.out );
10483             return false;
10484         }
10485         return true;
10486     }
10487
10488     private static boolean testPreOrderIterator() {
10489         try {
10490             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10491             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10492             PhylogenyNodeIterator it0;
10493             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10494                 it0.next();
10495             }
10496             for( it0.reset(); it0.hasNext(); ) {
10497                 it0.next();
10498             }
10499             PhylogenyNodeIterator it = t0.iteratorPreorder();
10500             if ( !it.next().getName().equals( "r" ) ) {
10501                 return false;
10502             }
10503             if ( !it.next().getName().equals( "ab" ) ) {
10504                 return false;
10505             }
10506             if ( !it.next().getName().equals( "A" ) ) {
10507                 return false;
10508             }
10509             if ( !it.next().getName().equals( "B" ) ) {
10510                 return false;
10511             }
10512             if ( !it.next().getName().equals( "cd" ) ) {
10513                 return false;
10514             }
10515             if ( !it.next().getName().equals( "C" ) ) {
10516                 return false;
10517             }
10518             if ( !it.next().getName().equals( "D" ) ) {
10519                 return false;
10520             }
10521             if ( it.hasNext() ) {
10522                 return false;
10523             }
10524             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10525             it = t1.iteratorPreorder();
10526             if ( !it.next().getName().equals( "r" ) ) {
10527                 return false;
10528             }
10529             if ( !it.next().getName().equals( "abcd" ) ) {
10530                 return false;
10531             }
10532             if ( !it.next().getName().equals( "ab" ) ) {
10533                 return false;
10534             }
10535             if ( !it.next().getName().equals( "A" ) ) {
10536                 return false;
10537             }
10538             if ( !it.next().getName().equals( "B" ) ) {
10539                 return false;
10540             }
10541             if ( !it.next().getName().equals( "cd" ) ) {
10542                 return false;
10543             }
10544             if ( !it.next().getName().equals( "C" ) ) {
10545                 return false;
10546             }
10547             if ( !it.next().getName().equals( "D" ) ) {
10548                 return false;
10549             }
10550             if ( !it.next().getName().equals( "efgh" ) ) {
10551                 return false;
10552             }
10553             if ( !it.next().getName().equals( "ef" ) ) {
10554                 return false;
10555             }
10556             if ( !it.next().getName().equals( "E" ) ) {
10557                 return false;
10558             }
10559             if ( !it.next().getName().equals( "F" ) ) {
10560                 return false;
10561             }
10562             if ( !it.next().getName().equals( "gh" ) ) {
10563                 return false;
10564             }
10565             if ( !it.next().getName().equals( "G" ) ) {
10566                 return false;
10567             }
10568             if ( !it.next().getName().equals( "H" ) ) {
10569                 return false;
10570             }
10571             if ( it.hasNext() ) {
10572                 return false;
10573             }
10574         }
10575         catch ( final Exception e ) {
10576             e.printStackTrace( System.out );
10577             return false;
10578         }
10579         return true;
10580     }
10581
10582     private static boolean testPropertiesMap() {
10583         try {
10584             final PropertiesMap pm = new PropertiesMap();
10585             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10586             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10587             final Property p2 = new Property( "something:else",
10588                                               "?",
10589                                               "improbable:research",
10590                                               "xsd:decimal",
10591                                               AppliesTo.NODE );
10592             pm.addProperty( p0 );
10593             pm.addProperty( p1 );
10594             pm.addProperty( p2 );
10595             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10596                 return false;
10597             }
10598             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10599                 return false;
10600             }
10601             if ( pm.getProperties().size() != 3 ) {
10602                 return false;
10603             }
10604             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10605                 return false;
10606             }
10607             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10608                 return false;
10609             }
10610             if ( pm.getProperties().size() != 3 ) {
10611                 return false;
10612             }
10613             pm.removeProperty( "dimensions:diameter" );
10614             if ( pm.getProperties().size() != 2 ) {
10615                 return false;
10616             }
10617             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10618                 return false;
10619             }
10620             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10621                 return false;
10622             }
10623         }
10624         catch ( final Exception e ) {
10625             e.printStackTrace( System.out );
10626             return false;
10627         }
10628         return true;
10629     }
10630
10631     private static boolean testProteinId() {
10632         try {
10633             final ProteinId id1 = new ProteinId( "a" );
10634             final ProteinId id2 = new ProteinId( "a" );
10635             final ProteinId id3 = new ProteinId( "A" );
10636             final ProteinId id4 = new ProteinId( "b" );
10637             if ( !id1.equals( id1 ) ) {
10638                 return false;
10639             }
10640             if ( id1.getId().equals( "x" ) ) {
10641                 return false;
10642             }
10643             if ( id1.getId().equals( null ) ) {
10644                 return false;
10645             }
10646             if ( !id1.equals( id2 ) ) {
10647                 return false;
10648             }
10649             if ( id1.equals( id3 ) ) {
10650                 return false;
10651             }
10652             if ( id1.hashCode() != id1.hashCode() ) {
10653                 return false;
10654             }
10655             if ( id1.hashCode() != id2.hashCode() ) {
10656                 return false;
10657             }
10658             if ( id1.hashCode() == id3.hashCode() ) {
10659                 return false;
10660             }
10661             if ( id1.compareTo( id1 ) != 0 ) {
10662                 return false;
10663             }
10664             if ( id1.compareTo( id2 ) != 0 ) {
10665                 return false;
10666             }
10667             if ( id1.compareTo( id3 ) != 0 ) {
10668                 return false;
10669             }
10670             if ( id1.compareTo( id4 ) >= 0 ) {
10671                 return false;
10672             }
10673             if ( id4.compareTo( id1 ) <= 0 ) {
10674                 return false;
10675             }
10676             if ( !id4.getId().equals( "b" ) ) {
10677                 return false;
10678             }
10679             final ProteinId id5 = new ProteinId( " C " );
10680             if ( !id5.getId().equals( "C" ) ) {
10681                 return false;
10682             }
10683             if ( id5.equals( id1 ) ) {
10684                 return false;
10685             }
10686         }
10687         catch ( final Exception e ) {
10688             e.printStackTrace( System.out );
10689             return false;
10690         }
10691         return true;
10692     }
10693
10694     private static boolean testReIdMethods() {
10695         try {
10696             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10697             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10698             final long count = PhylogenyNode.getNodeCount();
10699             p.levelOrderReID();
10700             if ( p.getNode( "r" ).getId() != count ) {
10701                 return false;
10702             }
10703             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10704                 return false;
10705             }
10706             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10707                 return false;
10708             }
10709             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10710                 return false;
10711             }
10712             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10713                 return false;
10714             }
10715             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10716                 return false;
10717             }
10718             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10719                 return false;
10720             }
10721             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10722                 return false;
10723             }
10724             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10725                 return false;
10726             }
10727             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10728                 return false;
10729             }
10730             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10731                 return false;
10732             }
10733             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10734                 return false;
10735             }
10736             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10737                 return false;
10738             }
10739             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10740                 return false;
10741             }
10742             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10743                 return false;
10744             }
10745         }
10746         catch ( final Exception e ) {
10747             e.printStackTrace( System.out );
10748             return false;
10749         }
10750         return true;
10751     }
10752
10753     private static boolean testRerooting() {
10754         try {
10755             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10756             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",
10757                                                  new NHXParser() )[ 0 ];
10758             if ( !t1.isRooted() ) {
10759                 return false;
10760             }
10761             t1.reRoot( t1.getNode( "D" ) );
10762             t1.reRoot( t1.getNode( "CD" ) );
10763             t1.reRoot( t1.getNode( "A" ) );
10764             t1.reRoot( t1.getNode( "B" ) );
10765             t1.reRoot( t1.getNode( "AB" ) );
10766             t1.reRoot( t1.getNode( "D" ) );
10767             t1.reRoot( t1.getNode( "C" ) );
10768             t1.reRoot( t1.getNode( "CD" ) );
10769             t1.reRoot( t1.getNode( "A" ) );
10770             t1.reRoot( t1.getNode( "B" ) );
10771             t1.reRoot( t1.getNode( "AB" ) );
10772             t1.reRoot( t1.getNode( "D" ) );
10773             t1.reRoot( t1.getNode( "D" ) );
10774             t1.reRoot( t1.getNode( "C" ) );
10775             t1.reRoot( t1.getNode( "A" ) );
10776             t1.reRoot( t1.getNode( "B" ) );
10777             t1.reRoot( t1.getNode( "AB" ) );
10778             t1.reRoot( t1.getNode( "C" ) );
10779             t1.reRoot( t1.getNode( "D" ) );
10780             t1.reRoot( t1.getNode( "CD" ) );
10781             t1.reRoot( t1.getNode( "D" ) );
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             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10790                 return false;
10791             }
10792             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10793                 return false;
10794             }
10795             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10796                 return false;
10797             }
10798             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10799                 return false;
10800             }
10801             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10802                 return false;
10803             }
10804             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10805                 return false;
10806             }
10807             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",
10808                                                  new NHXParser() )[ 0 ];
10809             t2.reRoot( t2.getNode( "A" ) );
10810             t2.reRoot( t2.getNode( "D" ) );
10811             t2.reRoot( t2.getNode( "ABC" ) );
10812             t2.reRoot( t2.getNode( "A" ) );
10813             t2.reRoot( t2.getNode( "B" ) );
10814             t2.reRoot( t2.getNode( "D" ) );
10815             t2.reRoot( t2.getNode( "C" ) );
10816             t2.reRoot( t2.getNode( "ABC" ) );
10817             t2.reRoot( t2.getNode( "A" ) );
10818             t2.reRoot( t2.getNode( "B" ) );
10819             t2.reRoot( t2.getNode( "AB" ) );
10820             t2.reRoot( t2.getNode( "AB" ) );
10821             t2.reRoot( t2.getNode( "D" ) );
10822             t2.reRoot( t2.getNode( "C" ) );
10823             t2.reRoot( t2.getNode( "B" ) );
10824             t2.reRoot( t2.getNode( "AB" ) );
10825             t2.reRoot( t2.getNode( "D" ) );
10826             t2.reRoot( t2.getNode( "D" ) );
10827             t2.reRoot( t2.getNode( "ABC" ) );
10828             t2.reRoot( t2.getNode( "A" ) );
10829             t2.reRoot( t2.getNode( "B" ) );
10830             t2.reRoot( t2.getNode( "AB" ) );
10831             t2.reRoot( t2.getNode( "D" ) );
10832             t2.reRoot( t2.getNode( "C" ) );
10833             t2.reRoot( t2.getNode( "ABC" ) );
10834             t2.reRoot( t2.getNode( "A" ) );
10835             t2.reRoot( t2.getNode( "B" ) );
10836             t2.reRoot( t2.getNode( "AB" ) );
10837             t2.reRoot( t2.getNode( "D" ) );
10838             t2.reRoot( t2.getNode( "D" ) );
10839             t2.reRoot( t2.getNode( "C" ) );
10840             t2.reRoot( t2.getNode( "A" ) );
10841             t2.reRoot( t2.getNode( "B" ) );
10842             t2.reRoot( t2.getNode( "AB" ) );
10843             t2.reRoot( t2.getNode( "C" ) );
10844             t2.reRoot( t2.getNode( "D" ) );
10845             t2.reRoot( t2.getNode( "ABC" ) );
10846             t2.reRoot( t2.getNode( "D" ) );
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             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10855                 return false;
10856             }
10857             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10858                 return false;
10859             }
10860             t2.reRoot( t2.getNode( "ABC" ) );
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( "AB" ) );
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(), 55 ) ) {
10872                 return false;
10873             }
10874             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10875                 return false;
10876             }
10877             t2.reRoot( t2.getNode( "AB" ) );
10878             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10879                 return false;
10880             }
10881             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10882                 return false;
10883             }
10884             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10885                 return false;
10886             }
10887             t2.reRoot( t2.getNode( "D" ) );
10888             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10889                 return false;
10890             }
10891             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10892                 return false;
10893             }
10894             t2.reRoot( t2.getNode( "ABC" ) );
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             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10902                                                  new NHXParser() )[ 0 ];
10903             t3.reRoot( t3.getNode( "B" ) );
10904             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10905                 return false;
10906             }
10907             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10908                 return false;
10909             }
10910             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10911                 return false;
10912             }
10913             t3.reRoot( t3.getNode( "B" ) );
10914             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10915                 return false;
10916             }
10917             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10918                 return false;
10919             }
10920             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10921                 return false;
10922             }
10923             t3.reRoot( t3.getRoot() );
10924             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10925                 return false;
10926             }
10927             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10928                 return false;
10929             }
10930             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10931                 return false;
10932             }
10933         }
10934         catch ( final Exception e ) {
10935             e.printStackTrace( System.out );
10936             return false;
10937         }
10938         return true;
10939     }
10940
10941     private static boolean testSDIse() {
10942         try {
10943             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10944             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10945             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10946             gene1.setRooted( true );
10947             species1.setRooted( true );
10948             final SDI sdi = new SDI( gene1, species1 );
10949             if ( !gene1.getRoot().isDuplication() ) {
10950                 return false;
10951             }
10952             final Phylogeny species2 = factory
10953                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10954                              new NHXParser() )[ 0 ];
10955             final Phylogeny gene2 = factory
10956                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10957                              new NHXParser() )[ 0 ];
10958             species2.setRooted( true );
10959             gene2.setRooted( true );
10960             final SDI sdi2 = new SDI( gene2, species2 );
10961             if ( sdi2.getDuplicationsSum() != 0 ) {
10962                 return false;
10963             }
10964             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10965                 return false;
10966             }
10967             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10968                 return false;
10969             }
10970             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10971                 return false;
10972             }
10973             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10974                 return false;
10975             }
10976             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10977                 return false;
10978             }
10979             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10980                 return false;
10981             }
10982             final Phylogeny species3 = factory
10983                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10984                              new NHXParser() )[ 0 ];
10985             final Phylogeny gene3 = factory
10986                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10987                              new NHXParser() )[ 0 ];
10988             species3.setRooted( true );
10989             gene3.setRooted( true );
10990             final SDI sdi3 = new SDI( gene3, species3 );
10991             if ( sdi3.getDuplicationsSum() != 1 ) {
10992                 return false;
10993             }
10994             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10995                 return false;
10996             }
10997             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10998                 return false;
10999             }
11000             final Phylogeny species4 = factory
11001                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11002                              new NHXParser() )[ 0 ];
11003             final Phylogeny gene4 = factory
11004                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11005                              new NHXParser() )[ 0 ];
11006             species4.setRooted( true );
11007             gene4.setRooted( true );
11008             final SDI sdi4 = new SDI( gene4, species4 );
11009             if ( sdi4.getDuplicationsSum() != 1 ) {
11010                 return false;
11011             }
11012             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
11013                 return false;
11014             }
11015             if ( !gene4.getNode( "abc" ).isDuplication() ) {
11016                 return false;
11017             }
11018             if ( gene4.getNode( "abcd" ).isDuplication() ) {
11019                 return false;
11020             }
11021             if ( species4.getNumberOfExternalNodes() != 6 ) {
11022                 return false;
11023             }
11024             if ( gene4.getNumberOfExternalNodes() != 6 ) {
11025                 return false;
11026             }
11027             final Phylogeny species5 = factory
11028                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11029                              new NHXParser() )[ 0 ];
11030             final Phylogeny gene5 = factory
11031                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11032                              new NHXParser() )[ 0 ];
11033             species5.setRooted( true );
11034             gene5.setRooted( true );
11035             final SDI sdi5 = new SDI( gene5, species5 );
11036             if ( sdi5.getDuplicationsSum() != 2 ) {
11037                 return false;
11038             }
11039             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
11040                 return false;
11041             }
11042             if ( !gene5.getNode( "adc" ).isDuplication() ) {
11043                 return false;
11044             }
11045             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
11046                 return false;
11047             }
11048             if ( species5.getNumberOfExternalNodes() != 6 ) {
11049                 return false;
11050             }
11051             if ( gene5.getNumberOfExternalNodes() != 6 ) {
11052                 return false;
11053             }
11054             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
11055             // Conjecture for Comparing Molecular Phylogenies"
11056             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
11057             final Phylogeny species6 = factory
11058                     .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,"
11059                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11060                             new NHXParser() )[ 0 ];
11061             final Phylogeny gene6 = factory
11062                     .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,"
11063                             + "((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,"
11064                             + "(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;",
11065                             new NHXParser() )[ 0 ];
11066             species6.setRooted( true );
11067             gene6.setRooted( true );
11068             final SDI sdi6 = new SDI( gene6, species6 );
11069             if ( sdi6.getDuplicationsSum() != 3 ) {
11070                 return false;
11071             }
11072             if ( !gene6.getNode( "r" ).isDuplication() ) {
11073                 return false;
11074             }
11075             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
11076                 return false;
11077             }
11078             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
11079                 return false;
11080             }
11081             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
11082                 return false;
11083             }
11084             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
11085                 return false;
11086             }
11087             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
11088                 return false;
11089             }
11090             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
11091                 return false;
11092             }
11093             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
11094                 return false;
11095             }
11096             sdi6.computeMappingCostL();
11097             if ( sdi6.computeMappingCostL() != 17 ) {
11098                 return false;
11099             }
11100             if ( species6.getNumberOfExternalNodes() != 9 ) {
11101                 return false;
11102             }
11103             if ( gene6.getNumberOfExternalNodes() != 9 ) {
11104                 return false;
11105             }
11106             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
11107                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
11108                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
11109                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
11110                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
11111             species7.setRooted( true );
11112             final Phylogeny gene7_1 = Test
11113                     .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])" );
11114             gene7_1.setRooted( true );
11115             final SDI sdi7 = new SDI( gene7_1, species7 );
11116             if ( sdi7.getDuplicationsSum() != 0 ) {
11117                 return false;
11118             }
11119             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
11120                 return false;
11121             }
11122             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
11123                 return false;
11124             }
11125             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
11126                 return false;
11127             }
11128             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
11129                 return false;
11130             }
11131             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
11132                 return false;
11133             }
11134             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
11135                 return false;
11136             }
11137             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
11138                 return false;
11139             }
11140             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
11141                 return false;
11142             }
11143             final Phylogeny gene7_2 = Test
11144                     .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])" );
11145             gene7_2.setRooted( true );
11146             final SDI sdi7_2 = new SDI( gene7_2, species7 );
11147             if ( sdi7_2.getDuplicationsSum() != 1 ) {
11148                 return false;
11149             }
11150             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
11151                 return false;
11152             }
11153             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
11154                 return false;
11155             }
11156             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
11157                 return false;
11158             }
11159             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
11160                 return false;
11161             }
11162             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
11163                 return false;
11164             }
11165             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
11166                 return false;
11167             }
11168             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
11169                 return false;
11170             }
11171             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
11172                 return false;
11173             }
11174             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
11175                 return false;
11176             }
11177         }
11178         catch ( final Exception e ) {
11179             return false;
11180         }
11181         return true;
11182     }
11183
11184     private static boolean testSDIunrooted() {
11185         try {
11186             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11187             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
11188             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
11189             final Iterator<PhylogenyBranch> iter = l.iterator();
11190             PhylogenyBranch br = iter.next();
11191             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
11192                 return false;
11193             }
11194             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
11195                 return false;
11196             }
11197             br = iter.next();
11198             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11199                 return false;
11200             }
11201             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11202                 return false;
11203             }
11204             br = iter.next();
11205             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
11206                 return false;
11207             }
11208             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
11209                 return false;
11210             }
11211             br = iter.next();
11212             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11213                 return false;
11214             }
11215             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11216                 return false;
11217             }
11218             br = iter.next();
11219             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11220                 return false;
11221             }
11222             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11223                 return false;
11224             }
11225             br = iter.next();
11226             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11227                 return false;
11228             }
11229             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11230                 return false;
11231             }
11232             br = iter.next();
11233             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11234                 return false;
11235             }
11236             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11237                 return false;
11238             }
11239             br = iter.next();
11240             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11241                 return false;
11242             }
11243             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11244                 return false;
11245             }
11246             br = iter.next();
11247             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11248                 return false;
11249             }
11250             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11251                 return false;
11252             }
11253             br = iter.next();
11254             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11255                 return false;
11256             }
11257             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11258                 return false;
11259             }
11260             br = iter.next();
11261             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11262                 return false;
11263             }
11264             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11265                 return false;
11266             }
11267             br = iter.next();
11268             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
11269                 return false;
11270             }
11271             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
11272                 return false;
11273             }
11274             br = iter.next();
11275             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11276                 return false;
11277             }
11278             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11279                 return false;
11280             }
11281             br = iter.next();
11282             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
11283                 return false;
11284             }
11285             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
11286                 return false;
11287             }
11288             br = iter.next();
11289             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
11290                 return false;
11291             }
11292             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
11293                 return false;
11294             }
11295             if ( iter.hasNext() ) {
11296                 return false;
11297             }
11298             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
11299             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
11300             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
11301             br = iter1.next();
11302             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11303                 return false;
11304             }
11305             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11306                 return false;
11307             }
11308             br = iter1.next();
11309             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11310                 return false;
11311             }
11312             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11313                 return false;
11314             }
11315             br = iter1.next();
11316             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11317                 return false;
11318             }
11319             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11320                 return false;
11321             }
11322             if ( iter1.hasNext() ) {
11323                 return false;
11324             }
11325             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
11326             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
11327             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
11328             br = iter2.next();
11329             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11330                 return false;
11331             }
11332             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11333                 return false;
11334             }
11335             br = iter2.next();
11336             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11337                 return false;
11338             }
11339             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11340                 return false;
11341             }
11342             br = iter2.next();
11343             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11344                 return false;
11345             }
11346             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11347                 return false;
11348             }
11349             if ( iter2.hasNext() ) {
11350                 return false;
11351             }
11352             final Phylogeny species0 = factory
11353                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11354                              new NHXParser() )[ 0 ];
11355             final Phylogeny gene1 = factory
11356                     .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])",
11357                              new NHXParser() )[ 0 ];
11358             species0.setRooted( true );
11359             gene1.setRooted( true );
11360             final SDIR sdi_unrooted = new SDIR();
11361             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
11362             if ( sdi_unrooted.getCount() != 1 ) {
11363                 return false;
11364             }
11365             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
11366                 return false;
11367             }
11368             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
11369                 return false;
11370             }
11371             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
11372                 return false;
11373             }
11374             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11375                 return false;
11376             }
11377             final Phylogeny gene2 = factory
11378                     .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])",
11379                              new NHXParser() )[ 0 ];
11380             gene2.setRooted( true );
11381             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
11382             if ( sdi_unrooted.getCount() != 1 ) {
11383                 return false;
11384             }
11385             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11386                 return false;
11387             }
11388             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11389                 return false;
11390             }
11391             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
11392                 return false;
11393             }
11394             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11395                 return false;
11396             }
11397             final Phylogeny species6 = factory
11398                     .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,"
11399                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11400                             new NHXParser() )[ 0 ];
11401             final Phylogeny gene6 = factory
11402                     .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],"
11403                             + "(((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],"
11404                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11405                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11406                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11407                             new NHXParser() )[ 0 ];
11408             species6.setRooted( true );
11409             gene6.setRooted( true );
11410             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
11411             if ( sdi_unrooted.getCount() != 1 ) {
11412                 return false;
11413             }
11414             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11415                 return false;
11416             }
11417             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11418                 return false;
11419             }
11420             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11421                 return false;
11422             }
11423             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11424                 return false;
11425             }
11426             if ( !p6[ 0 ].getRoot().isDuplication() ) {
11427                 return false;
11428             }
11429             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11430                 return false;
11431             }
11432             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11433                 return false;
11434             }
11435             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11436                 return false;
11437             }
11438             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11439                 return false;
11440             }
11441             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11442                 return false;
11443             }
11444             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11445                 return false;
11446             }
11447             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11448                 return false;
11449             }
11450             p6 = null;
11451             final Phylogeny species7 = factory
11452                     .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,"
11453                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11454                             new NHXParser() )[ 0 ];
11455             final Phylogeny gene7 = factory
11456                     .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],"
11457                             + "(((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],"
11458                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11459                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11460                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11461                             new NHXParser() )[ 0 ];
11462             species7.setRooted( true );
11463             gene7.setRooted( true );
11464             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11465             if ( sdi_unrooted.getCount() != 1 ) {
11466                 return false;
11467             }
11468             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11469                 return false;
11470             }
11471             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11472                 return false;
11473             }
11474             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11475                 return false;
11476             }
11477             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11478                 return false;
11479             }
11480             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11481                 return false;
11482             }
11483             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11484                 return false;
11485             }
11486             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11487                 return false;
11488             }
11489             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11490                 return false;
11491             }
11492             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11493                 return false;
11494             }
11495             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11496                 return false;
11497             }
11498             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11499                 return false;
11500             }
11501             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11502                 return false;
11503             }
11504             p7 = null;
11505             final Phylogeny species8 = factory
11506                     .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,"
11507                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11508                             new NHXParser() )[ 0 ];
11509             final Phylogeny gene8 = factory
11510                     .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],"
11511                             + "(((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],"
11512                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11513                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11514                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11515                             new NHXParser() )[ 0 ];
11516             species8.setRooted( true );
11517             gene8.setRooted( true );
11518             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11519             if ( sdi_unrooted.getCount() != 1 ) {
11520                 return false;
11521             }
11522             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11523                 return false;
11524             }
11525             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11526                 return false;
11527             }
11528             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11529                 return false;
11530             }
11531             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11532                 return false;
11533             }
11534             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11535                 return false;
11536             }
11537             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11538                 return false;
11539             }
11540             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11541                 return false;
11542             }
11543             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11544                 return false;
11545             }
11546             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11547                 return false;
11548             }
11549             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11550                 return false;
11551             }
11552             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11553                 return false;
11554             }
11555             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11556                 return false;
11557             }
11558             p8 = null;
11559         }
11560         catch ( final Exception e ) {
11561             e.printStackTrace( System.out );
11562             return false;
11563         }
11564         return true;
11565     }
11566
11567     private static boolean testSequenceDbWsTools1() {
11568         try {
11569             final PhylogenyNode n = new PhylogenyNode();
11570             n.setName( "NP_001025424" );
11571             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11572             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11573                     || !acc.getValue().equals( "NP_001025424" ) ) {
11574                 return false;
11575             }
11576             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11577             acc = SequenceDbWsTools.obtainSeqAccession( n );
11578             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11579                     || !acc.getValue().equals( "NP_001025424" ) ) {
11580                 return false;
11581             }
11582             n.setName( "NP_001025424.1" );
11583             acc = SequenceDbWsTools.obtainSeqAccession( n );
11584             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11585                     || !acc.getValue().equals( "NP_001025424" ) ) {
11586                 return false;
11587             }
11588             n.setName( "NM_001030253" );
11589             acc = SequenceDbWsTools.obtainSeqAccession( n );
11590             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11591                     || !acc.getValue().equals( "NM_001030253" ) ) {
11592                 return false;
11593             }
11594             n.setName( "BCL2_HUMAN" );
11595             acc = SequenceDbWsTools.obtainSeqAccession( n );
11596             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11597                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11598                 System.out.println( acc.toString() );
11599                 return false;
11600             }
11601             n.setName( "P10415" );
11602             acc = SequenceDbWsTools.obtainSeqAccession( n );
11603             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11604                     || !acc.getValue().equals( "P10415" ) ) {
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( "AY695820" );
11623             acc = SequenceDbWsTools.obtainSeqAccession( n );
11624             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11625                     || !acc.getValue().equals( "AY695820" ) ) {
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( "AAA59452" );
11637             acc = SequenceDbWsTools.obtainSeqAccession( n );
11638             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11639                     || !acc.getValue().equals( "AAA59452" ) ) {
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.1" );
11651             acc = SequenceDbWsTools.obtainSeqAccession( n );
11652             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11653                     || !acc.getValue().equals( "AAA59452.1" ) ) {
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( "GI:94894583" );
11665             acc = SequenceDbWsTools.obtainSeqAccession( n );
11666             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11667                     || !acc.getValue().equals( "94894583" ) ) {
11668                 System.out.println( acc.toString() );
11669                 return false;
11670             }
11671             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11672             acc = SequenceDbWsTools.obtainSeqAccession( n );
11673             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11674                     || !acc.getValue().equals( "71845847" ) ) {
11675                 System.out.println( acc.toString() );
11676                 return false;
11677             }
11678             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11679             acc = SequenceDbWsTools.obtainSeqAccession( n );
11680             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11681                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11682                 System.out.println( acc.toString() );
11683                 return false;
11684             }
11685         }
11686         catch ( final Exception e ) {
11687             return false;
11688         }
11689         return true;
11690     }
11691
11692     private static boolean testSequenceDbWsTools2() {
11693         try {
11694             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11695             SequenceDbWsTools.obtainSeqInformation( n1 );
11696             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11697                 return false;
11698             }
11699             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11700                 return false;
11701             }
11702             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11703                 return false;
11704             }
11705             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11706                 return false;
11707             }
11708             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11709             SequenceDbWsTools.obtainSeqInformation( n2 );
11710             if ( !n2.getNodeData().getSequence().getName().equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
11711                 return false;
11712             }
11713             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11714                 return false;
11715             }
11716             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11717                 return false;
11718             }
11719             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11720                 return false;
11721             }
11722             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11723             SequenceDbWsTools.obtainSeqInformation( n3 );
11724             if ( !n3.getNodeData().getSequence().getName()
11725                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11726                 return false;
11727             }
11728             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11729                 return false;
11730             }
11731             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11732                 return false;
11733             }
11734             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11735                 return false;
11736             }
11737         }
11738         catch ( final IOException e ) {
11739             System.out.println();
11740             System.out.println( "the following might be due to absence internet connection:" );
11741             e.printStackTrace( System.out );
11742             return true;
11743         }
11744         catch ( final Exception e ) {
11745             e.printStackTrace();
11746             return false;
11747         }
11748         return true;
11749     }
11750
11751     private static boolean testSequenceIdParsing() {
11752         try {
11753             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11754             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11755                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11756                 if ( id != null ) {
11757                     System.out.println( "value   =" + id.getValue() );
11758                     System.out.println( "provider=" + id.getSource() );
11759                 }
11760                 return false;
11761             }
11762             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11763             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11764                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11765                 if ( id != null ) {
11766                     System.out.println( "value   =" + id.getValue() );
11767                     System.out.println( "provider=" + id.getSource() );
11768                 }
11769                 return false;
11770             }
11771             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11772             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11773                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11774                 if ( id != null ) {
11775                     System.out.println( "value   =" + id.getValue() );
11776                     System.out.println( "provider=" + id.getSource() );
11777                 }
11778                 return false;
11779             }
11780             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11781             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11782                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11783                 if ( id != null ) {
11784                     System.out.println( "value   =" + id.getValue() );
11785                     System.out.println( "provider=" + id.getSource() );
11786                 }
11787                 return false;
11788             }
11789             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11790             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11791                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11792                 if ( id != null ) {
11793                     System.out.println( "value   =" + id.getValue() );
11794                     System.out.println( "provider=" + id.getSource() );
11795                 }
11796                 return false;
11797             }
11798             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11799             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11800                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11801                 if ( id != null ) {
11802                     System.out.println( "value   =" + id.getValue() );
11803                     System.out.println( "provider=" + id.getSource() );
11804                 }
11805                 return false;
11806             }
11807             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11808             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11809                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11810                 if ( id != null ) {
11811                     System.out.println( "value   =" + id.getValue() );
11812                     System.out.println( "provider=" + id.getSource() );
11813                 }
11814                 return false;
11815             }
11816             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11817             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11818                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11819                 if ( id != null ) {
11820                     System.out.println( "value   =" + id.getValue() );
11821                     System.out.println( "provider=" + id.getSource() );
11822                 }
11823                 return false;
11824             }
11825             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11826             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11827                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11828                 if ( id != null ) {
11829                     System.out.println( "value   =" + id.getValue() );
11830                     System.out.println( "provider=" + id.getSource() );
11831                 }
11832                 return false;
11833             }
11834             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11835             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11836                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11837                 if ( id != null ) {
11838                     System.out.println( "value   =" + id.getValue() );
11839                     System.out.println( "provider=" + id.getSource() );
11840                 }
11841                 return false;
11842             }
11843             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11844             if ( id != null ) {
11845                 System.out.println( "value   =" + id.getValue() );
11846                 System.out.println( "provider=" + id.getSource() );
11847                 return false;
11848             }
11849             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
11850             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11851                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
11852                 if ( id != null ) {
11853                     System.out.println( "value   =" + id.getValue() );
11854                     System.out.println( "provider=" + id.getSource() );
11855                 }
11856                 return false;
11857             }
11858             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
11859             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11860                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11861                 if ( id != null ) {
11862                     System.out.println( "value   =" + id.getValue() );
11863                     System.out.println( "provider=" + id.getSource() );
11864                 }
11865                 return false;
11866             }
11867             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
11868             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11869                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11870                 if ( id != null ) {
11871                     System.out.println( "value   =" + id.getValue() );
11872                     System.out.println( "provider=" + id.getSource() );
11873                 }
11874                 return false;
11875             }
11876             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
11877             if ( id != null ) {
11878                 System.out.println( "value   =" + id.getValue() );
11879                 System.out.println( "provider=" + id.getSource() );
11880                 return false;
11881             }
11882         }
11883         catch ( final Exception e ) {
11884             e.printStackTrace( System.out );
11885             return false;
11886         }
11887         return true;
11888     }
11889
11890     private static boolean testSequenceWriter() {
11891         try {
11892             final String n = ForesterUtil.LINE_SEPARATOR;
11893             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11894                 return false;
11895             }
11896             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11897                 return false;
11898             }
11899             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11900                 return false;
11901             }
11902             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11903                 return false;
11904             }
11905             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11906                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11907                 return false;
11908             }
11909             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11910                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11911                 return false;
11912             }
11913         }
11914         catch ( final Exception e ) {
11915             e.printStackTrace();
11916             return false;
11917         }
11918         return true;
11919     }
11920
11921     private static boolean testSpecies() {
11922         try {
11923             final Species s1 = new BasicSpecies( "a" );
11924             final Species s2 = new BasicSpecies( "a" );
11925             final Species s3 = new BasicSpecies( "A" );
11926             final Species s4 = new BasicSpecies( "b" );
11927             if ( !s1.equals( s1 ) ) {
11928                 return false;
11929             }
11930             if ( s1.getSpeciesId().equals( "x" ) ) {
11931                 return false;
11932             }
11933             if ( s1.getSpeciesId().equals( null ) ) {
11934                 return false;
11935             }
11936             if ( !s1.equals( s2 ) ) {
11937                 return false;
11938             }
11939             if ( s1.equals( s3 ) ) {
11940                 return false;
11941             }
11942             if ( s1.hashCode() != s1.hashCode() ) {
11943                 return false;
11944             }
11945             if ( s1.hashCode() != s2.hashCode() ) {
11946                 return false;
11947             }
11948             if ( s1.hashCode() == s3.hashCode() ) {
11949                 return false;
11950             }
11951             if ( s1.compareTo( s1 ) != 0 ) {
11952                 return false;
11953             }
11954             if ( s1.compareTo( s2 ) != 0 ) {
11955                 return false;
11956             }
11957             if ( s1.compareTo( s3 ) != 0 ) {
11958                 return false;
11959             }
11960             if ( s1.compareTo( s4 ) >= 0 ) {
11961                 return false;
11962             }
11963             if ( s4.compareTo( s1 ) <= 0 ) {
11964                 return false;
11965             }
11966             if ( !s4.getSpeciesId().equals( "b" ) ) {
11967                 return false;
11968             }
11969             final Species s5 = new BasicSpecies( " C " );
11970             if ( !s5.getSpeciesId().equals( "C" ) ) {
11971                 return false;
11972             }
11973             if ( s5.equals( s1 ) ) {
11974                 return false;
11975             }
11976         }
11977         catch ( final Exception e ) {
11978             e.printStackTrace( System.out );
11979             return false;
11980         }
11981         return true;
11982     }
11983
11984     private static boolean testSplit() {
11985         try {
11986             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11987             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11988             //Archaeopteryx.createApplication( p0 );
11989             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11990             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11991             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11992             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11993             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11994             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11995             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11996             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11997             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11998             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11999             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
12000             // System.out.println( s0.toString() );
12001             //
12002             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12003             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12004             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12005             if ( s0.match( query_nodes ) ) {
12006                 return false;
12007             }
12008             query_nodes = new HashSet<PhylogenyNode>();
12009             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12010             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12011             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12012             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12013             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12014             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12015             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12016             if ( !s0.match( query_nodes ) ) {
12017                 return false;
12018             }
12019             //
12020             query_nodes = new HashSet<PhylogenyNode>();
12021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12023             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12024             if ( !s0.match( query_nodes ) ) {
12025                 return false;
12026             }
12027             //
12028             query_nodes = new HashSet<PhylogenyNode>();
12029             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12030             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12032             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12033             if ( !s0.match( query_nodes ) ) {
12034                 return false;
12035             }
12036             //
12037             query_nodes = new HashSet<PhylogenyNode>();
12038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12040             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12041             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12042             if ( !s0.match( query_nodes ) ) {
12043                 return false;
12044             }
12045             //
12046             query_nodes = new HashSet<PhylogenyNode>();
12047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12048             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12049             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12050             if ( !s0.match( query_nodes ) ) {
12051                 return false;
12052             }
12053             query_nodes = new HashSet<PhylogenyNode>();
12054             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12055             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12056             if ( !s0.match( query_nodes ) ) {
12057                 return false;
12058             }
12059             query_nodes = new HashSet<PhylogenyNode>();
12060             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12061             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12062             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12063             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12064             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12065             if ( !s0.match( query_nodes ) ) {
12066                 return false;
12067             }
12068             query_nodes = new HashSet<PhylogenyNode>();
12069             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12070             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12071             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
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             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12080             if ( !s0.match( query_nodes ) ) {
12081                 return false;
12082             }
12083             query_nodes = new HashSet<PhylogenyNode>();
12084             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12085             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12086             if ( s0.match( query_nodes ) ) {
12087                 return false;
12088             }
12089             query_nodes = new HashSet<PhylogenyNode>();
12090             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12091             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12092             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12093             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12094             if ( s0.match( query_nodes ) ) {
12095                 return false;
12096             }
12097             query_nodes = new HashSet<PhylogenyNode>();
12098             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12099             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12100             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12101             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12102             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12103             if ( s0.match( query_nodes ) ) {
12104                 return false;
12105             }
12106             query_nodes = new HashSet<PhylogenyNode>();
12107             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12108             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12109             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
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( "D" ) );
12116             if ( s0.match( query_nodes ) ) {
12117                 return false;
12118             }
12119             query_nodes = new HashSet<PhylogenyNode>();
12120             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12121             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12122             if ( s0.match( query_nodes ) ) {
12123                 return false;
12124             }
12125             query_nodes = new HashSet<PhylogenyNode>();
12126             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12127             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12128             if ( s0.match( query_nodes ) ) {
12129                 return false;
12130             }
12131             query_nodes = new HashSet<PhylogenyNode>();
12132             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12133             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12134             if ( s0.match( query_nodes ) ) {
12135                 return false;
12136             }
12137             query_nodes = new HashSet<PhylogenyNode>();
12138             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12139             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12140             if ( s0.match( query_nodes ) ) {
12141                 return false;
12142             }
12143             query_nodes = new HashSet<PhylogenyNode>();
12144             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12145             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12146             if ( s0.match( query_nodes ) ) {
12147                 return false;
12148             }
12149             query_nodes = new HashSet<PhylogenyNode>();
12150             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12151             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
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( "B" ) );
12159             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12160             if ( s0.match( query_nodes ) ) {
12161                 return false;
12162             }
12163             query_nodes = new HashSet<PhylogenyNode>();
12164             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12165             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12166             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
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             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12175             if ( s0.match( query_nodes ) ) {
12176                 return false;
12177             }
12178             /////////
12179             //            query_nodes = new HashSet<PhylogenyNode>();
12180             //            query_nodes.add( new PhylogenyNode( "X" ) );
12181             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12182             //            query_nodes.add( new PhylogenyNode( "A" ) );
12183             //            query_nodes.add( new PhylogenyNode( "B" ) );
12184             //            query_nodes.add( new PhylogenyNode( "C" ) );
12185             //            query_nodes.add( new PhylogenyNode( "D" ) );
12186             //            query_nodes.add( new PhylogenyNode( "E" ) );
12187             //            query_nodes.add( new PhylogenyNode( "F" ) );
12188             //            query_nodes.add( new PhylogenyNode( "G" ) );
12189             //            if ( !s0.match( query_nodes ) ) {
12190             //                return false;
12191             //            }
12192             //            query_nodes = new HashSet<PhylogenyNode>();
12193             //            query_nodes.add( new PhylogenyNode( "X" ) );
12194             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12195             //            query_nodes.add( new PhylogenyNode( "A" ) );
12196             //            query_nodes.add( new PhylogenyNode( "B" ) );
12197             //            query_nodes.add( new PhylogenyNode( "C" ) );
12198             //            if ( !s0.match( query_nodes ) ) {
12199             //                return false;
12200             //            }
12201             //            //
12202             //            query_nodes = new HashSet<PhylogenyNode>();
12203             //            query_nodes.add( new PhylogenyNode( "X" ) );
12204             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12205             //            query_nodes.add( new PhylogenyNode( "D" ) );
12206             //            query_nodes.add( new PhylogenyNode( "E" ) );
12207             //            query_nodes.add( new PhylogenyNode( "F" ) );
12208             //            query_nodes.add( new PhylogenyNode( "G" ) );
12209             //            if ( !s0.match( query_nodes ) ) {
12210             //                return false;
12211             //            }
12212             //            //
12213             //            query_nodes = new HashSet<PhylogenyNode>();
12214             //            query_nodes.add( new PhylogenyNode( "X" ) );
12215             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12216             //            query_nodes.add( new PhylogenyNode( "A" ) );
12217             //            query_nodes.add( new PhylogenyNode( "B" ) );
12218             //            query_nodes.add( new PhylogenyNode( "C" ) );
12219             //            query_nodes.add( new PhylogenyNode( "D" ) );
12220             //            if ( !s0.match( query_nodes ) ) {
12221             //                return false;
12222             //            }
12223             //            //
12224             //            query_nodes = new HashSet<PhylogenyNode>();
12225             //            query_nodes.add( new PhylogenyNode( "X" ) );
12226             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12227             //            query_nodes.add( new PhylogenyNode( "E" ) );
12228             //            query_nodes.add( new PhylogenyNode( "F" ) );
12229             //            query_nodes.add( new PhylogenyNode( "G" ) );
12230             //            if ( !s0.match( query_nodes ) ) {
12231             //                return false;
12232             //            }
12233             //            //
12234             //            query_nodes = new HashSet<PhylogenyNode>();
12235             //            query_nodes.add( new PhylogenyNode( "X" ) );
12236             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12237             //            query_nodes.add( new PhylogenyNode( "F" ) );
12238             //            query_nodes.add( new PhylogenyNode( "G" ) );
12239             //            if ( !s0.match( query_nodes ) ) {
12240             //                return false;
12241             //            }
12242             //
12243             query_nodes = new HashSet<PhylogenyNode>();
12244             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12245             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12246             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12247             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12248             if ( s0.match( query_nodes ) ) {
12249                 return false;
12250             }
12251             //
12252             query_nodes = new HashSet<PhylogenyNode>();
12253             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12254             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12255             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12256             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12257             if ( s0.match( query_nodes ) ) {
12258                 return false;
12259             }
12260             ///////////////////////////
12261             //
12262             query_nodes = new HashSet<PhylogenyNode>();
12263             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12264             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12265             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12266             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12267             if ( s0.match( query_nodes ) ) {
12268                 return false;
12269             }
12270             //
12271             query_nodes = new HashSet<PhylogenyNode>();
12272             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12273             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12274             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12275             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12276             if ( s0.match( query_nodes ) ) {
12277                 return false;
12278             }
12279             //
12280             query_nodes = new HashSet<PhylogenyNode>();
12281             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12282             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12283             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12284             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12285             if ( s0.match( query_nodes ) ) {
12286                 return false;
12287             }
12288             //
12289             query_nodes = new HashSet<PhylogenyNode>();
12290             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12291             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12292             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12293             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12294             if ( s0.match( query_nodes ) ) {
12295                 return false;
12296             }
12297             //
12298             query_nodes = new HashSet<PhylogenyNode>();
12299             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12300             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12301             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12302             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12303             if ( s0.match( query_nodes ) ) {
12304                 return false;
12305             }
12306             //
12307             query_nodes = new HashSet<PhylogenyNode>();
12308             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12309             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12310             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12311             if ( s0.match( query_nodes ) ) {
12312                 return false;
12313             }
12314             //
12315             query_nodes = new HashSet<PhylogenyNode>();
12316             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12317             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12318             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12319             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12320             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12321             if ( s0.match( query_nodes ) ) {
12322                 return false;
12323             }
12324             //
12325             query_nodes = new HashSet<PhylogenyNode>();
12326             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12327             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12328             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12329             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12330             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12331             if ( s0.match( query_nodes ) ) {
12332                 return false;
12333             }
12334             //
12335             query_nodes = new HashSet<PhylogenyNode>();
12336             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12337             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12338             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12339             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12340             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12341             if ( s0.match( query_nodes ) ) {
12342                 return false;
12343             }
12344             //
12345             query_nodes = new HashSet<PhylogenyNode>();
12346             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12347             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12348             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12349             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12350             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12351             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12352             if ( s0.match( query_nodes ) ) {
12353                 return false;
12354             }
12355         }
12356         catch ( final Exception e ) {
12357             e.printStackTrace();
12358             return false;
12359         }
12360         return true;
12361     }
12362
12363     private static boolean testSplitStrict() {
12364         try {
12365             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12366             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12367             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
12368             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12369             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12370             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12371             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12372             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12373             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12374             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12375             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
12376             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12377             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12378             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12379             if ( s0.match( query_nodes ) ) {
12380                 return false;
12381             }
12382             query_nodes = new HashSet<PhylogenyNode>();
12383             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12384             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12385             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12386             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12387             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12388             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12389             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12390             if ( !s0.match( query_nodes ) ) {
12391                 return false;
12392             }
12393             //
12394             query_nodes = new HashSet<PhylogenyNode>();
12395             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12396             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12397             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12398             if ( !s0.match( query_nodes ) ) {
12399                 return false;
12400             }
12401             //
12402             query_nodes = new HashSet<PhylogenyNode>();
12403             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12404             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12405             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12406             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12407             if ( !s0.match( query_nodes ) ) {
12408                 return false;
12409             }
12410             //
12411             query_nodes = new HashSet<PhylogenyNode>();
12412             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12413             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12414             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12415             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12416             if ( !s0.match( query_nodes ) ) {
12417                 return false;
12418             }
12419             //
12420             query_nodes = new HashSet<PhylogenyNode>();
12421             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12422             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12423             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12424             if ( !s0.match( query_nodes ) ) {
12425                 return false;
12426             }
12427             //
12428             query_nodes = new HashSet<PhylogenyNode>();
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( "E" ) );
12437             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12438             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12439             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12440             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12441             if ( !s0.match( query_nodes ) ) {
12442                 return false;
12443             }
12444             //
12445             query_nodes = new HashSet<PhylogenyNode>();
12446             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12447             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12448             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12449             if ( !s0.match( query_nodes ) ) {
12450                 return false;
12451             }
12452             //
12453             query_nodes = new HashSet<PhylogenyNode>();
12454             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12455             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12456             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12457             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12458             if ( !s0.match( query_nodes ) ) {
12459                 return false;
12460             }
12461             //
12462             query_nodes = new HashSet<PhylogenyNode>();
12463             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12464             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12465             if ( s0.match( query_nodes ) ) {
12466                 return false;
12467             }
12468             //
12469             query_nodes = new HashSet<PhylogenyNode>();
12470             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12471             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12472             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12473             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12474             if ( s0.match( query_nodes ) ) {
12475                 return false;
12476             }
12477             //
12478             query_nodes = new HashSet<PhylogenyNode>();
12479             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12480             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12481             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12482             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12483             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12484             if ( s0.match( query_nodes ) ) {
12485                 return false;
12486             }
12487             //
12488             query_nodes = new HashSet<PhylogenyNode>();
12489             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12490             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12491             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12492             if ( s0.match( query_nodes ) ) {
12493                 return false;
12494             }
12495             //
12496             query_nodes = new HashSet<PhylogenyNode>();
12497             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
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( "B" ) );
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( "C" ) );
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( "E" ) );
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( "F" ) );
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( "G" ) );
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( "F" ) );
12541             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12542             if ( s0.match( query_nodes ) ) {
12543                 return false;
12544             }
12545             //
12546             query_nodes = new HashSet<PhylogenyNode>();
12547             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12548             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12549             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12550             if ( s0.match( query_nodes ) ) {
12551                 return false;
12552             }
12553             //
12554             query_nodes = new HashSet<PhylogenyNode>();
12555             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12556             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12557             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12558             if ( s0.match( query_nodes ) ) {
12559                 return false;
12560             }
12561             //
12562             query_nodes = new HashSet<PhylogenyNode>();
12563             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12564             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12565             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12566             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12567             if ( s0.match( query_nodes ) ) {
12568                 return false;
12569             }
12570         }
12571         catch ( final Exception e ) {
12572             e.printStackTrace();
12573             return false;
12574         }
12575         return true;
12576     }
12577
12578     private static boolean testSubtreeDeletion() {
12579         try {
12580             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12581             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12582             t1.deleteSubtree( t1.getNode( "A" ), false );
12583             if ( t1.getNumberOfExternalNodes() != 5 ) {
12584                 return false;
12585             }
12586             t1.toNewHampshireX();
12587             t1.deleteSubtree( t1.getNode( "E" ), false );
12588             if ( t1.getNumberOfExternalNodes() != 4 ) {
12589                 return false;
12590             }
12591             t1.toNewHampshireX();
12592             t1.deleteSubtree( t1.getNode( "F" ), false );
12593             if ( t1.getNumberOfExternalNodes() != 3 ) {
12594                 return false;
12595             }
12596             t1.toNewHampshireX();
12597             t1.deleteSubtree( t1.getNode( "D" ), false );
12598             t1.toNewHampshireX();
12599             if ( t1.getNumberOfExternalNodes() != 3 ) {
12600                 return false;
12601             }
12602             t1.deleteSubtree( t1.getNode( "def" ), false );
12603             t1.toNewHampshireX();
12604             if ( t1.getNumberOfExternalNodes() != 2 ) {
12605                 return false;
12606             }
12607             t1.deleteSubtree( t1.getNode( "B" ), false );
12608             t1.toNewHampshireX();
12609             if ( t1.getNumberOfExternalNodes() != 1 ) {
12610                 return false;
12611             }
12612             t1.deleteSubtree( t1.getNode( "C" ), false );
12613             t1.toNewHampshireX();
12614             if ( t1.getNumberOfExternalNodes() != 1 ) {
12615                 return false;
12616             }
12617             t1.deleteSubtree( t1.getNode( "abc" ), false );
12618             t1.toNewHampshireX();
12619             if ( t1.getNumberOfExternalNodes() != 1 ) {
12620                 return false;
12621             }
12622             t1.deleteSubtree( t1.getNode( "r" ), false );
12623             if ( t1.getNumberOfExternalNodes() != 0 ) {
12624                 return false;
12625             }
12626             if ( !t1.isEmpty() ) {
12627                 return false;
12628             }
12629             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12630             t2.deleteSubtree( t2.getNode( "A" ), false );
12631             t2.toNewHampshireX();
12632             if ( t2.getNumberOfExternalNodes() != 5 ) {
12633                 return false;
12634             }
12635             t2.deleteSubtree( t2.getNode( "abc" ), false );
12636             t2.toNewHampshireX();
12637             if ( t2.getNumberOfExternalNodes() != 3 ) {
12638                 return false;
12639             }
12640             t2.deleteSubtree( t2.getNode( "def" ), false );
12641             t2.toNewHampshireX();
12642             if ( t2.getNumberOfExternalNodes() != 1 ) {
12643                 return false;
12644             }
12645         }
12646         catch ( final Exception e ) {
12647             e.printStackTrace( System.out );
12648             return false;
12649         }
12650         return true;
12651     }
12652
12653     private static boolean testSupportCount() {
12654         try {
12655             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12656             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12657             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12658                     + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12659                     + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12660                     + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12661                     + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12662                     new NHXParser() );
12663             SupportCount.count( t0_1, phylogenies_1, true, false );
12664             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12665             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12666                     + "(((((A,B),C),D),E),((F,G),X))"
12667                     + "(((((A,Y),B),C),D),((F,G),E))"
12668                     + "(((((A,B),C),D),E),(F,G))"
12669                     + "(((((A,B),C),D),E),(F,G))"
12670                     + "(((((A,B),C),D),E),(F,G))"
12671                     + "(((((A,B),C),D),E),(F,G),Z)"
12672                     + "(((((A,B),C),D),E),(F,G))"
12673                     + "((((((A,B),C),D),E),F),G)"
12674                     + "(((((X,Y),F,G),E),((A,B),C)),D)",
12675                     new NHXParser() );
12676             SupportCount.count( t0_2, phylogenies_2, true, false );
12677             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12678             while ( it.hasNext() ) {
12679                 final PhylogenyNode n = it.next();
12680                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12681                     return false;
12682                 }
12683             }
12684             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12685             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12686                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12687             SupportCount.count( t0_3, phylogenies_3, true, false );
12688             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12689             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12690                 return false;
12691             }
12692             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12693                 return false;
12694             }
12695             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12696                 return false;
12697             }
12698             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12699                 return false;
12700             }
12701             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12702                 return false;
12703             }
12704             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12705                 return false;
12706             }
12707             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12708                 return false;
12709             }
12710             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12711                 return false;
12712             }
12713             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12714                 return false;
12715             }
12716             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12717                 return false;
12718             }
12719             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12720             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12721                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12722             SupportCount.count( t0_4, phylogenies_4, true, false );
12723             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12724             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12725                 return false;
12726             }
12727             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12728                 return false;
12729             }
12730             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12731                 return false;
12732             }
12733             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12734                 return false;
12735             }
12736             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12737                 return false;
12738             }
12739             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12740                 return false;
12741             }
12742             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12743                 return false;
12744             }
12745             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12746                 return false;
12747             }
12748             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12749                 return false;
12750             }
12751             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12752                 return false;
12753             }
12754             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12755             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12756             double d = SupportCount.compare( b1, a, true, true, true );
12757             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12758                 return false;
12759             }
12760             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12761             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12762             d = SupportCount.compare( b2, a, true, true, true );
12763             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12764                 return false;
12765             }
12766             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12767             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12768             d = SupportCount.compare( b3, a, true, true, true );
12769             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12770                 return false;
12771             }
12772             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12773             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12774             d = SupportCount.compare( b4, a, true, true, false );
12775             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12776                 return false;
12777             }
12778         }
12779         catch ( final Exception e ) {
12780             e.printStackTrace( System.out );
12781             return false;
12782         }
12783         return true;
12784     }
12785
12786     private static boolean testSupportTransfer() {
12787         try {
12788             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12789             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)",
12790                                                  new NHXParser() )[ 0 ];
12791             final Phylogeny p2 = factory
12792                     .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 ];
12793             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12794                 return false;
12795             }
12796             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12797                 return false;
12798             }
12799             support_transfer.moveBranchLengthsToBootstrap( p1 );
12800             support_transfer.transferSupportValues( p1, p2 );
12801             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12802                 return false;
12803             }
12804             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12805                 return false;
12806             }
12807             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12808                 return false;
12809             }
12810             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12811                 return false;
12812             }
12813             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12814                 return false;
12815             }
12816             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12817                 return false;
12818             }
12819             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12820                 return false;
12821             }
12822             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12823                 return false;
12824             }
12825         }
12826         catch ( final Exception e ) {
12827             e.printStackTrace( System.out );
12828             return false;
12829         }
12830         return true;
12831     }
12832
12833     private static boolean testTaxonomyExtraction() {
12834         try {
12835             final PhylogenyNode n0 = PhylogenyNode
12836                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12837             if ( n0.getNodeData().isHasTaxonomy() ) {
12838                 return false;
12839             }
12840             final PhylogenyNode n1 = PhylogenyNode
12841                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12842             if ( n1.getNodeData().isHasTaxonomy() ) {
12843                 System.out.println( n1.toString() );
12844                 return false;
12845             }
12846             final PhylogenyNode n2x = PhylogenyNode
12847                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12848             if ( n2x.getNodeData().isHasTaxonomy() ) {
12849                 return false;
12850             }
12851             final PhylogenyNode n3 = PhylogenyNode
12852                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12853             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12854                 System.out.println( n3.toString() );
12855                 return false;
12856             }
12857             final PhylogenyNode n4 = PhylogenyNode
12858                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12859             if ( n4.getNodeData().isHasTaxonomy() ) {
12860                 System.out.println( n4.toString() );
12861                 return false;
12862             }
12863             final PhylogenyNode n5 = PhylogenyNode
12864                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12865             if ( n5.getNodeData().isHasTaxonomy() ) {
12866                 System.out.println( n5.toString() );
12867                 return false;
12868             }
12869             final PhylogenyNode n6 = PhylogenyNode
12870                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12871             if ( n6.getNodeData().isHasTaxonomy() ) {
12872                 System.out.println( n6.toString() );
12873                 return false;
12874             }
12875             final PhylogenyNode n7 = PhylogenyNode
12876                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12877             if ( n7.getNodeData().isHasTaxonomy() ) {
12878                 System.out.println( n7.toString() );
12879                 return false;
12880             }
12881             final PhylogenyNode n8 = PhylogenyNode
12882                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12883             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12884                 System.out.println( n8.toString() );
12885                 return false;
12886             }
12887             final PhylogenyNode n9 = PhylogenyNode
12888                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12889             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12890                 System.out.println( n9.toString() );
12891                 return false;
12892             }
12893             final PhylogenyNode n10x = PhylogenyNode
12894                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12895             if ( n10x.getNodeData().isHasTaxonomy() ) {
12896                 System.out.println( n10x.toString() );
12897                 return false;
12898             }
12899             final PhylogenyNode n10xx = PhylogenyNode
12900                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12901             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12902                 System.out.println( n10xx.toString() );
12903                 return false;
12904             }
12905             final PhylogenyNode n10 = PhylogenyNode
12906                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12907             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12908                 System.out.println( n10.toString() );
12909                 return false;
12910             }
12911             final PhylogenyNode n11 = PhylogenyNode
12912                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12913             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12914                 System.out.println( n11.toString() );
12915                 return false;
12916             }
12917             final PhylogenyNode n12 = PhylogenyNode
12918                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12919                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12920             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12921                 System.out.println( n12.toString() );
12922                 return false;
12923             }
12924             final PhylogenyNode n13 = PhylogenyNode
12925                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12926             if ( n13.getNodeData().isHasTaxonomy() ) {
12927                 System.out.println( n13.toString() );
12928                 return false;
12929             }
12930             final PhylogenyNode n14 = PhylogenyNode
12931                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12932             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12933                 System.out.println( n14.toString() );
12934                 return false;
12935             }
12936             final PhylogenyNode n15 = PhylogenyNode
12937                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12938             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12939                 System.out.println( n15.toString() );
12940                 return false;
12941             }
12942             final PhylogenyNode n16 = PhylogenyNode
12943                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12944             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12945                 System.out.println( n16.toString() );
12946                 return false;
12947             }
12948             final PhylogenyNode n17 = PhylogenyNode
12949                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12950             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12951                 System.out.println( n17.toString() );
12952                 return false;
12953             }
12954             final PhylogenyNode n18 = PhylogenyNode
12955                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12956             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12957                 System.out.println( n18.toString() );
12958                 return false;
12959             }
12960             final PhylogenyNode n19 = PhylogenyNode
12961                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12962                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12963             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12964                 System.out.println( n19.toString() );
12965                 return false;
12966             }
12967             final PhylogenyNode n20 = PhylogenyNode
12968                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12969             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12970                 System.out.println( n20.toString() );
12971                 return false;
12972             }
12973             final PhylogenyNode n21 = PhylogenyNode
12974                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12975                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12976             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12977                 System.out.println( n21.toString() );
12978                 return false;
12979             }
12980             final PhylogenyNode n23 = PhylogenyNode
12981                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12982                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12983             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12984                 System.out.println( n23.toString() );
12985                 return false;
12986             }
12987             final PhylogenyNode n24 = PhylogenyNode
12988                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12989             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12990                 System.out.println( n24.toString() );
12991                 return false;
12992             }
12993             //
12994             final PhylogenyNode n25 = PhylogenyNode
12995                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12996                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12997             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12998                 System.out.println( n25.toString() );
12999                 return false;
13000             }
13001             final PhylogenyNode n26 = PhylogenyNode
13002                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
13003                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13004             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13005                 System.out.println( n26.toString() );
13006                 return false;
13007             }
13008             final PhylogenyNode n27 = PhylogenyNode
13009                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13010             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13011                 System.out.println( n27.toString() );
13012                 return false;
13013             }
13014         }
13015         catch ( final Exception e ) {
13016             e.printStackTrace( System.out );
13017             return false;
13018         }
13019         return true;
13020     }
13021
13022     private static boolean testTreeCopy() {
13023         try {
13024             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
13025             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
13026             final Phylogeny t1 = t0.copy();
13027             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
13028                 return false;
13029             }
13030             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13031                 return false;
13032             }
13033             t0.deleteSubtree( t0.getNode( "c" ), true );
13034             t0.deleteSubtree( t0.getNode( "a" ), true );
13035             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
13036             t0.getNode( "b" ).setName( "Bee" );
13037             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
13038                 return false;
13039             }
13040             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13041                 return false;
13042             }
13043             t0.deleteSubtree( t0.getNode( "e" ), true );
13044             t0.deleteSubtree( t0.getNode( "Bee" ), true );
13045             t0.deleteSubtree( t0.getNode( "d" ), true );
13046             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13047                 return false;
13048             }
13049         }
13050         catch ( final Exception e ) {
13051             e.printStackTrace();
13052             return false;
13053         }
13054         return true;
13055     }
13056
13057     private static boolean testTreeMethods() {
13058         try {
13059             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13060             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
13061             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
13062             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
13063                 System.out.println( t0.toNewHampshireX() );
13064                 return false;
13065             }
13066             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
13067             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
13068             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
13069                 return false;
13070             }
13071             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
13072                 return false;
13073             }
13074             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
13075                 return false;
13076             }
13077         }
13078         catch ( final Exception e ) {
13079             e.printStackTrace( System.out );
13080             return false;
13081         }
13082         return true;
13083     }
13084
13085     private static boolean testUniprotEntryRetrieval() {
13086         try {
13087             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 5000 );
13088             if ( !entry.getAccession().equals( "P12345" ) ) {
13089                 return false;
13090             }
13091             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
13092                 return false;
13093             }
13094             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
13095                 return false;
13096             }
13097             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
13098                 return false;
13099             }
13100             if ( !entry.getGeneName().equals( "GOT2" ) ) {
13101                 return false;
13102             }
13103             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
13104                 return false;
13105             }
13106             if ( entry.getMolecularSequence() == null ) {
13107                 return false;
13108             }
13109             if ( !entry
13110                     .getMolecularSequence()
13111                     .getMolecularSequenceAsString()
13112                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
13113                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
13114                 System.out.println( "got: " + entry.getMolecularSequence().getMolecularSequenceAsString() );
13115                 System.out.println( "expected something else." );
13116                 return false;
13117             }
13118         }
13119         catch ( final IOException e ) {
13120             System.out.println();
13121             System.out.println( "the following might be due to absence internet connection:" );
13122             e.printStackTrace( System.out );
13123             return true;
13124         }
13125         catch ( final NullPointerException f ) {
13126             f.printStackTrace( System.out );
13127             return false;
13128         }
13129         catch ( final Exception e ) {
13130             return false;
13131         }
13132         return true;
13133     }
13134
13135     private static boolean testUniprotTaxonomySearch() {
13136         try {
13137             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
13138                                                                                                  10 );
13139             if ( results.size() != 1 ) {
13140                 return false;
13141             }
13142             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13143                 return false;
13144             }
13145             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13146                 return false;
13147             }
13148             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13149                 return false;
13150             }
13151             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13152                 return false;
13153             }
13154             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13155                 return false;
13156             }
13157             results = null;
13158             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
13159             if ( results.size() != 1 ) {
13160                 return false;
13161             }
13162             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13163                 return false;
13164             }
13165             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13166                 return false;
13167             }
13168             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13169                 return false;
13170             }
13171             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13172                 return false;
13173             }
13174             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13175                 return false;
13176             }
13177             results = null;
13178             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
13179             if ( results.size() != 1 ) {
13180                 return false;
13181             }
13182             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13183                 return false;
13184             }
13185             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13186                 return false;
13187             }
13188             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13189                 return false;
13190             }
13191             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13192                 return false;
13193             }
13194             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13195                 return false;
13196             }
13197             results = null;
13198             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
13199             if ( results.size() != 1 ) {
13200                 return false;
13201             }
13202             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13203                 return false;
13204             }
13205             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13206                 return false;
13207             }
13208             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13209                 return false;
13210             }
13211             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13212                 return false;
13213             }
13214             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13215                 return false;
13216             }
13217             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
13218                 return false;
13219             }
13220             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
13221                 return false;
13222             }
13223             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13224                     .equals( "Nematostella vectensis" ) ) {
13225                 System.out.println( results.get( 0 ).getLineage() );
13226                 return false;
13227             }
13228             //
13229             results = null;
13230             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
13231             if ( results.size() != 1 ) {
13232                 return false;
13233             }
13234             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13235                 return false;
13236             }
13237             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13238                 return false;
13239             }
13240             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13241                 return false;
13242             }
13243             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13244                 return false;
13245             }
13246             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13247                 return false;
13248             }
13249             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13250                     .equals( "Xenopus tropicalis" ) ) {
13251                 System.out.println( results.get( 0 ).getLineage() );
13252                 return false;
13253             }
13254             //
13255             results = null;
13256             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
13257             if ( results.size() != 1 ) {
13258                 return false;
13259             }
13260             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13261                 return false;
13262             }
13263             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13264                 return false;
13265             }
13266             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13267                 return false;
13268             }
13269             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13270                 return false;
13271             }
13272             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13273                 return false;
13274             }
13275             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13276                     .equals( "Xenopus tropicalis" ) ) {
13277                 System.out.println( results.get( 0 ).getLineage() );
13278                 return false;
13279             }
13280             //
13281             results = null;
13282             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
13283             if ( results.size() != 1 ) {
13284                 return false;
13285             }
13286             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13287                 return false;
13288             }
13289             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13290                 return false;
13291             }
13292             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13293                 return false;
13294             }
13295             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13296                 return false;
13297             }
13298             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13299                 return false;
13300             }
13301             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13302                     .equals( "Xenopus tropicalis" ) ) {
13303                 System.out.println( results.get( 0 ).getLineage() );
13304                 return false;
13305             }
13306         }
13307         catch ( final IOException e ) {
13308             System.out.println();
13309             System.out.println( "the following might be due to absence internet connection:" );
13310             e.printStackTrace( System.out );
13311             return true;
13312         }
13313         catch ( final Exception e ) {
13314             return false;
13315         }
13316         return true;
13317     }
13318     
13319     
13320 }