in progress
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24
25 package org.forester.test;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.StringWriter;
32 import java.io.Writer;
33 import java.net.URL;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.HashSet;
37 import java.util.Iterator;
38 import java.util.List;
39 import java.util.Locale;
40 import java.util.Set;
41 import java.util.SortedSet;
42
43 import javax.net.ssl.HttpsURLConnection;
44 import javax.net.ssl.SSLContext;
45
46 import org.forester.application.support_transfer;
47 import org.forester.archaeopteryx.AptxUtil;
48 import org.forester.archaeopteryx.TreePanelUtil;
49 import org.forester.archaeopteryx.webservices.WebserviceUtil;
50 import org.forester.development.DevelopmentTools;
51 import org.forester.evoinference.TestPhylogenyReconstruction;
52 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
53 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
54 import org.forester.go.TestGo;
55 import org.forester.io.parsers.FastaParser;
56 import org.forester.io.parsers.GeneralMsaParser;
57 import org.forester.io.parsers.HmmscanPerDomainTableParser;
58 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
59 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
60 import org.forester.io.parsers.nexus.NexusCharactersParser;
61 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
62 import org.forester.io.parsers.nhx.NHXParser;
63 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
64 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
65 import org.forester.io.parsers.tol.TolParser;
66 import org.forester.io.parsers.util.ParserUtils;
67 import org.forester.io.writers.PhylogenyWriter;
68 import org.forester.io.writers.SequenceWriter;
69 import org.forester.msa.BasicMsa;
70 import org.forester.msa.DeleteableMsa;
71 import org.forester.msa.Mafft;
72 import org.forester.msa.Msa;
73 import org.forester.msa.Msa.MSA_FORMAT;
74 import org.forester.msa.MsaInferrer;
75 import org.forester.msa.MsaMethods;
76 import org.forester.pccx.TestPccx;
77 import org.forester.phylogeny.Phylogeny;
78 import org.forester.phylogeny.PhylogenyBranch;
79 import org.forester.phylogeny.PhylogenyMethods;
80 import org.forester.phylogeny.PhylogenyNode;
81 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
82 import org.forester.phylogeny.data.Accession;
83 import org.forester.phylogeny.data.Accession.Source;
84 import org.forester.phylogeny.data.BinaryCharacters;
85 import org.forester.phylogeny.data.BranchWidth;
86 import org.forester.phylogeny.data.Confidence;
87 import org.forester.phylogeny.data.Distribution;
88 import org.forester.phylogeny.data.DomainArchitecture;
89 import org.forester.phylogeny.data.Event;
90 import org.forester.phylogeny.data.Identifier;
91 import org.forester.phylogeny.data.PhylogenyData;
92 import org.forester.phylogeny.data.PhylogenyDataUtil;
93 import org.forester.phylogeny.data.Polygon;
94 import org.forester.phylogeny.data.PropertiesMap;
95 import org.forester.phylogeny.data.Property;
96 import org.forester.phylogeny.data.Property.AppliesTo;
97 import org.forester.phylogeny.data.ProteinDomain;
98 import org.forester.phylogeny.data.Taxonomy;
99 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
100 import org.forester.phylogeny.factories.PhylogenyFactory;
101 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
102 import org.forester.protein.BasicDomain;
103 import org.forester.protein.BasicProtein;
104 import org.forester.protein.Domain;
105 import org.forester.protein.Protein;
106 import org.forester.protein.ProteinId;
107 import org.forester.rio.TestRIO;
108 import org.forester.sdi.SDI;
109 import org.forester.sdi.SDIR;
110 import org.forester.sdi.TestGSDI;
111 import org.forester.sequence.BasicSequence;
112 import org.forester.sequence.MolecularSequence;
113 import org.forester.species.BasicSpecies;
114 import org.forester.species.Species;
115 import org.forester.surfacing.TestSurfacing;
116 import org.forester.tools.ConfidenceAssessor;
117 import org.forester.tools.SupportCount;
118 import org.forester.tools.TreeSplitMatrix;
119 import org.forester.util.AsciiHistogram;
120 import org.forester.util.BasicDescriptiveStatistics;
121 import org.forester.util.BasicTable;
122 import org.forester.util.BasicTableParser;
123 import org.forester.util.DescriptiveStatistics;
124 import org.forester.util.ForesterConstants;
125 import org.forester.util.ForesterUtil;
126 import org.forester.util.GeneralTable;
127 import org.forester.util.SequenceAccessionTools;
128 import org.forester.ws.seqdb.SequenceDatabaseEntry;
129 import org.forester.ws.seqdb.SequenceDbWsTools;
130 import org.forester.ws.seqdb.UniProtTaxonomy;
131
132
133 @SuppressWarnings( "unused")
134 public final class Test {
135
136     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
137             + ForesterUtil.getFileSeparator() + "resources"
138             + ForesterUtil.getFileSeparator();
139     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
140             + ForesterUtil.getFileSeparator() + "test_data"
141             + ForesterUtil.getFileSeparator();
142     private final static boolean PERFORM_DB_TESTS          = true;
143     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
144     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
145             + ForesterConstants.PHYLO_XML_VERSION + "/"
146             + ForesterConstants.PHYLO_XML_XSD;
147     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
148             + ForesterConstants.PHYLO_XML_VERSION + "/"
149             + ForesterConstants.PHYLO_XML_XSD;
150     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
151     private final static double  ZERO_DIFF                 = 1.0E-9;
152
153     private static boolean isEqual( final double a, final double b ) {
154         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
155     }
156
157     public static void main( final String[] args ) {
158         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
159         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
160                             + "]" );
161         Locale.setDefault( Locale.US );
162         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
163         int failed = 0;
164         int succeeded = 0;
165         System.out.print( "[Test if directory with files for testing exists/is readable: " );
166         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
167             System.out.println( "OK.]" );
168         }
169         else {
170             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
171             System.out.println( "Testing aborted." );
172             System.exit( -1 );
173         }
174         System.out.print( "[Test if resources directory exists/is readable: " );
175         if ( testDir( PATH_TO_RESOURCES ) ) {
176             System.out.println( "OK.]" );
177         }
178         else {
179             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
180             System.out.println( "Testing aborted." );
181             System.exit( -1 );
182         }
183         final long start_time = new Date().getTime();
184         
185         System.out.print( "Basic node methods: " );
186         if ( Test.testBasicNodeMethods() ) {
187             System.out.println( "OK." );
188             succeeded++;
189         }
190         else {
191             System.out.println( "failed." );
192             failed++;
193         }
194         System.out.print( "Protein id: " );
195         if ( !testProteinId() ) {
196             System.out.println( "failed." );
197             failed++;
198         }
199         else {
200             succeeded++;
201         }
202         System.out.println( "OK." );
203         System.out.print( "Species: " );
204         if ( !testSpecies() ) {
205             System.out.println( "failed." );
206             failed++;
207         }
208         else {
209             succeeded++;
210         }
211         System.out.println( "OK." );
212         System.out.print( "Basic domain: " );
213         if ( !testBasicDomain() ) {
214             System.out.println( "failed." );
215             failed++;
216         }
217         else {
218             succeeded++;
219         }
220         System.out.println( "OK." );
221         System.out.print( "Basic protein: " );
222         if ( !testBasicProtein() ) {
223             System.out.println( "failed." );
224             failed++;
225         }
226         else {
227             succeeded++;
228         }
229         System.out.println( "OK." );
230         System.out.print( "Sequence writer: " );
231         if ( testSequenceWriter() ) {
232             System.out.println( "OK." );
233             succeeded++;
234         }
235         else {
236             System.out.println( "failed." );
237             failed++;
238         }
239         System.out.print( "Sequence id parsing: " );
240         if ( testSequenceIdParsing() ) {
241             System.out.println( "OK." );
242             succeeded++;
243         }
244         else {
245             System.out.println( "failed." );
246             failed++;
247         }
248         System.out.print( "UniProtKB id extraction: " );
249         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
250             System.out.println( "OK." );
251             succeeded++;
252         }
253         else {
254             System.out.println( "failed." );
255             failed++;
256         }
257         System.out.print( "Sequence DB tools 1: " );
258         if ( testSequenceDbWsTools1() ) {
259             System.out.println( "OK." );
260             succeeded++;
261         }
262         else {
263             System.out.println( "failed." );
264             failed++;
265         }
266         System.out.print( "Hmmscan output parser: " );
267         if ( testHmmscanOutputParser() ) {
268             System.out.println( "OK." );
269             succeeded++;
270         }
271         else {
272             System.out.println( "failed." );
273             failed++;
274         }
275         System.out.print( "Overlap removal: " );
276         if ( !org.forester.test.Test.testOverlapRemoval() ) {
277             System.out.println( "failed." );
278             failed++;
279         }
280         else {
281             succeeded++;
282         }
283         System.out.println( "OK." );
284         System.out.print( "Engulfing overlap removal: " );
285         if ( !Test.testEngulfingOverlapRemoval() ) {
286             System.out.println( "failed." );
287             failed++;
288         }
289         else {
290             succeeded++;
291         }
292         System.out.println( "OK." );
293         System.out.print( "Taxonomy data extraction: " );
294         if ( Test.testExtractTaxonomyDataFromNodeName() ) {
295             System.out.println( "OK." );
296             succeeded++;
297         }
298         else {
299             System.out.println( "failed." );
300             failed++;
301         }
302         System.out.print( "Taxonomy code extraction: " );
303         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
304             System.out.println( "OK." );
305             succeeded++;
306         }
307         else {
308             System.out.println( "failed." );
309             failed++;
310         }
311         System.out.print( "SN extraction: " );
312         if ( Test.testExtractSNFromNodeName() ) {
313             System.out.println( "OK." );
314             succeeded++;
315         }
316         else {
317             System.out.println( "failed." );
318             failed++;
319         }
320         System.out.print( "Taxonomy extraction (general): " );
321         if ( Test.testTaxonomyExtraction() ) {
322             System.out.println( "OK." );
323             succeeded++;
324         }
325         else {
326             System.out.println( "failed." );
327             failed++;
328         }
329         System.out.print( "Uri for Aptx web sequence accession: " );
330         if ( Test.testCreateUriForSeqWeb() ) {
331             System.out.println( "OK." );
332             succeeded++;
333         }
334         else {
335             System.out.println( "failed." );
336             failed++;
337         }
338         System.out.print( "Basic node construction and parsing of NHX (node level): " );
339         if ( Test.testNHXNodeParsing() ) {
340             System.out.println( "OK." );
341             succeeded++;
342         }
343         else {
344             System.out.println( "failed." );
345             failed++;
346         }
347         System.out.print( "Node construction and parsing of NHX (node level): " );
348         if ( Test.testNHXNodeParsing2() ) {
349             System.out.println( "OK." );
350             succeeded++;
351         }
352         else {
353             System.out.println( "failed." );
354             failed++;
355         }
356         System.out.print( "NHX parsing iterating: " );
357         if ( Test.testNHParsingIter() ) {
358             System.out.println( "OK." );
359             succeeded++;
360         }
361         else {
362             System.out.println( "failed." );
363             failed++;
364         }
365         System.out.print( "NH parsing: " );
366         if ( Test.testNHParsing() ) {
367             System.out.println( "OK." );
368             succeeded++;
369         }
370         else {
371             System.out.println( "failed." );
372             failed++;
373         }
374         System.out.print( "NH parsing - special chars: " );
375         if ( Test.testNHParsingSpecialChars() ) {
376             System.out.println( "OK." );
377             succeeded++;
378         }
379         else {
380             System.out.println( "failed." );
381             failed++;
382         }
383         System.out.print( "Conversion to NHX (node level): " );
384         if ( Test.testNHXconversion() ) {
385             System.out.println( "OK." );
386             succeeded++;
387         }
388         else {
389             System.out.println( "failed." );
390             failed++;
391         }
392         System.out.print( "NHX parsing: " );
393         if ( Test.testNHXParsing() ) {
394             System.out.println( "OK." );
395             succeeded++;
396         }
397         else {
398             System.out.println( "failed." );
399             failed++;
400         }
401         System.out.print( "NHX parsing with quotes: " );
402         if ( Test.testNHXParsingQuotes() ) {
403             System.out.println( "OK." );
404             succeeded++;
405         }
406         else {
407             System.out.println( "failed." );
408             failed++;
409         }
410         System.out.print( "NHX parsing (MrBayes): " );
411         if ( Test.testNHXParsingMB() ) {
412             System.out.println( "OK." );
413             succeeded++;
414         }
415         else {
416             System.out.println( "failed." );
417             failed++;
418         }
419         System.out.print( "Nexus characters parsing: " );
420         if ( Test.testNexusCharactersParsing() ) {
421             System.out.println( "OK." );
422             succeeded++;
423         }
424         else {
425             System.out.println( "failed." );
426             failed++;
427         }
428         System.out.print( "Nexus tree parsing iterating: " );
429         if ( Test.testNexusTreeParsingIterating() ) {
430             System.out.println( "OK." );
431             succeeded++;
432         }
433         else {
434             System.out.println( "failed." );
435             failed++;
436         }
437         System.out.print( "Nexus tree parsing: " );
438         if ( Test.testNexusTreeParsing() ) {
439             System.out.println( "OK." );
440             succeeded++;
441         }
442         else {
443             System.out.println( "failed." );
444             failed++;
445         }
446         System.out.print( "Nexus tree parsing (translating): " );
447         if ( Test.testNexusTreeParsingTranslating() ) {
448             System.out.println( "OK." );
449             succeeded++;
450         }
451         else {
452             System.out.println( "failed." );
453             failed++;
454         }
455         System.out.print( "Nexus matrix parsing: " );
456         if ( Test.testNexusMatrixParsing() ) {
457             System.out.println( "OK." );
458             succeeded++;
459         }
460         else {
461             System.out.println( "failed." );
462             failed++;
463         }
464         System.out.print( "Basic phyloXML parsing: " );
465         if ( Test.testBasicPhyloXMLparsing() ) {
466             System.out.println( "OK." );
467             succeeded++;
468         }
469         else {
470             System.out.println( "failed." );
471             failed++;
472         }
473         System.out.print( "Basic phyloXML parsing (validating against schema): " );
474         if ( testBasicPhyloXMLparsingValidating() ) {
475             System.out.println( "OK." );
476             succeeded++;
477         }
478         else {
479             System.out.println( "failed." );
480             failed++;
481         }
482         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
483         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
484             System.out.println( "OK." );
485             succeeded++;
486         }
487         else {
488             System.out.println( "failed." );
489             failed++;
490         }
491         System.out.print( "phyloXML Distribution Element: " );
492         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
493             System.out.println( "OK." );
494             succeeded++;
495         }
496         else {
497             System.out.println( "failed." );
498             failed++;
499         }
500         System.out.print( "Tol XML parsing: " );
501         if ( Test.testBasicTolXMLparsing() ) {
502             System.out.println( "OK." );
503             succeeded++;
504         }
505         else {
506             System.out.println( "failed." );
507             failed++;
508         }
509         System.out.print( "UTF-8 parsing from file: " );
510         if ( Test.testUTF8ParsingFromFile() ) {
511             System.out.println( "OK." );
512             succeeded++;
513         }
514         else {
515             System.out.println( "failed." );
516             failed++;
517         }
518         System.out.print( "Copying of node data: " );
519         if ( Test.testCopyOfNodeData() ) {
520             System.out.println( "OK." );
521             succeeded++;
522         }
523         else {
524             System.out.println( "failed." );
525             failed++;
526         }
527         System.out.print( "Tree copy: " );
528         if ( Test.testTreeCopy() ) {
529             System.out.println( "OK." );
530             succeeded++;
531         }
532         else {
533             System.out.println( "failed." );
534             failed++;
535         }
536         System.out.print( "Basic tree methods: " );
537         if ( Test.testBasicTreeMethods() ) {
538             System.out.println( "OK." );
539             succeeded++;
540         }
541         else {
542             System.out.println( "failed." );
543             failed++;
544         }
545         System.out.print( "Tree methods: " );
546         if ( Test.testTreeMethods() ) {
547             System.out.println( "OK." );
548             succeeded++;
549         }
550         else {
551             System.out.println( "failed." );
552             failed++;
553         }
554         System.out.print( "Postorder Iterator: " );
555         if ( Test.testPostOrderIterator() ) {
556             System.out.println( "OK." );
557             succeeded++;
558         }
559         else {
560             System.out.println( "failed." );
561             failed++;
562         }
563         System.out.print( "Preorder Iterator: " );
564         if ( Test.testPreOrderIterator() ) {
565             System.out.println( "OK." );
566             succeeded++;
567         }
568         else {
569             System.out.println( "failed." );
570             failed++;
571         }
572         System.out.print( "Levelorder Iterator: " );
573         if ( Test.testLevelOrderIterator() ) {
574             System.out.println( "OK." );
575             succeeded++;
576         }
577         else {
578             System.out.println( "failed." );
579             failed++;
580         }
581         System.out.print( "Re-id methods: " );
582         if ( Test.testReIdMethods() ) {
583             System.out.println( "OK." );
584             succeeded++;
585         }
586         else {
587             System.out.println( "failed." );
588             failed++;
589         }
590         System.out.print( "Methods on last external nodes: " );
591         if ( Test.testLastExternalNodeMethods() ) {
592             System.out.println( "OK." );
593             succeeded++;
594         }
595         else {
596             System.out.println( "failed." );
597             failed++;
598         }
599         System.out.print( "Methods on external nodes: " );
600         if ( Test.testExternalNodeRelatedMethods() ) {
601             System.out.println( "OK." );
602             succeeded++;
603         }
604         else {
605             System.out.println( "failed." );
606             failed++;
607         }
608         System.out.print( "Deletion of external nodes: " );
609         if ( Test.testDeletionOfExternalNodes() ) {
610             System.out.println( "OK." );
611             succeeded++;
612         }
613         else {
614             System.out.println( "failed." );
615             failed++;
616         }
617         System.out.print( "Subtree deletion: " );
618         if ( Test.testSubtreeDeletion() ) {
619             System.out.println( "OK." );
620             succeeded++;
621         }
622         else {
623             System.out.println( "failed." );
624             failed++;
625         }
626         System.out.print( "Phylogeny branch: " );
627         if ( Test.testPhylogenyBranch() ) {
628             System.out.println( "OK." );
629             succeeded++;
630         }
631         else {
632             System.out.println( "failed." );
633             failed++;
634         }
635         System.out.print( "Rerooting: " );
636         if ( Test.testRerooting() ) {
637             System.out.println( "OK." );
638             succeeded++;
639         }
640         else {
641             System.out.println( "failed." );
642             failed++;
643         }
644         System.out.print( "Mipoint rooting: " );
645         if ( Test.testMidpointrooting() ) {
646             System.out.println( "OK." );
647             succeeded++;
648         }
649         else {
650             System.out.println( "failed." );
651             failed++;
652         }
653         System.out.print( "Node removal: " );
654         if ( Test.testNodeRemoval() ) {
655             System.out.println( "OK." );
656             succeeded++;
657         }
658         else {
659             System.out.println( "failed." );
660             failed++;
661         }
662         System.out.print( "Support count: " );
663         if ( Test.testSupportCount() ) {
664             System.out.println( "OK." );
665             succeeded++;
666         }
667         else {
668             System.out.println( "failed." );
669             failed++;
670         }
671         System.out.print( "Support transfer: " );
672         if ( Test.testSupportTransfer() ) {
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: " );
681         if ( Test.testGetLCA() ) {
682             System.out.println( "OK." );
683             succeeded++;
684         }
685         else {
686             System.out.println( "failed." );
687             failed++;
688         }
689         System.out.print( "Finding of LCA 2: " );
690         if ( Test.testGetLCA2() ) {
691             System.out.println( "OK." );
692             succeeded++;
693         }
694         else {
695             System.out.println( "failed." );
696             failed++;
697         }
698         System.out.print( "Calculation of distance between nodes: " );
699         if ( Test.testGetDistance() ) {
700             System.out.println( "OK." );
701             succeeded++;
702         }
703         else {
704             System.out.println( "failed." );
705             failed++;
706         }
707         System.out.print( "Descriptive statistics: " );
708         if ( Test.testDescriptiveStatistics() ) {
709             System.out.println( "OK." );
710             succeeded++;
711         }
712         else {
713             System.out.println( "failed." );
714             failed++;
715         }
716         System.out.print( "Data objects and methods: " );
717         if ( Test.testDataObjects() ) {
718             System.out.println( "OK." );
719             succeeded++;
720         }
721         else {
722             System.out.println( "failed." );
723             failed++;
724         }
725         System.out.print( "Properties map: " );
726         if ( Test.testPropertiesMap() ) {
727             System.out.println( "OK." );
728             succeeded++;
729         }
730         else {
731             System.out.println( "failed." );
732             failed++;
733         }
734         System.out.print( "SDIse: " );
735         if ( Test.testSDIse() ) {
736             System.out.println( "OK." );
737             succeeded++;
738         }
739         else {
740             System.out.println( "failed." );
741             failed++;
742         }
743         System.out.print( "SDIunrooted: " );
744         if ( Test.testSDIunrooted() ) {
745             System.out.println( "OK." );
746             succeeded++;
747         }
748         else {
749             System.out.println( "failed." );
750             failed++;
751         }
752         System.out.print( "GSDI: " );
753         if ( TestGSDI.test() ) {
754             System.out.println( "OK." );
755             succeeded++;
756         }
757         else {
758             System.out.println( "failed." );
759             failed++;
760         }
761         System.out.print( "RIO: " );
762         if ( TestRIO.test() ) {
763             System.out.println( "OK." );
764             succeeded++;
765         }
766         else {
767             System.out.println( "failed." );
768             failed++;
769         }
770         System.out.print( "Phylogeny reconstruction:" );
771         System.out.println();
772         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
773             System.out.println( "OK." );
774             succeeded++;
775         }
776         else {
777             System.out.println( "failed." );
778             failed++;
779         }
780         System.out.print( "Analysis of domain architectures: " );
781         System.out.println();
782         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
783             System.out.println( "OK." );
784             succeeded++;
785         }
786         else {
787             System.out.println( "failed." );
788             failed++;
789         }
790         System.out.print( "GO: " );
791         System.out.println();
792         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
793             System.out.println( "OK." );
794             succeeded++;
795         }
796         else {
797             System.out.println( "failed." );
798             failed++;
799         }
800         System.out.print( "Modeling tools: " );
801         if ( TestPccx.test() ) {
802             System.out.println( "OK." );
803             succeeded++;
804         }
805         else {
806             System.out.println( "failed." );
807             failed++;
808         }
809         System.out.print( "Split Matrix strict: " );
810         if ( Test.testSplitStrict() ) {
811             System.out.println( "OK." );
812             succeeded++;
813         }
814         else {
815             System.out.println( "failed." );
816             failed++;
817         }
818         System.out.print( "Split Matrix: " );
819         if ( Test.testSplit() ) {
820             System.out.println( "OK." );
821             succeeded++;
822         }
823         else {
824             System.out.println( "failed." );
825             failed++;
826         }
827         System.out.print( "Confidence Assessor: " );
828         if ( Test.testConfidenceAssessor() ) {
829             System.out.println( "OK." );
830             succeeded++;
831         }
832         else {
833             System.out.println( "failed." );
834             failed++;
835         }
836         System.out.print( "Basic table: " );
837         if ( Test.testBasicTable() ) {
838             System.out.println( "OK." );
839             succeeded++;
840         }
841         else {
842             System.out.println( "failed." );
843             failed++;
844         }
845         System.out.print( "General table: " );
846         if ( Test.testGeneralTable() ) {
847             System.out.println( "OK." );
848             succeeded++;
849         }
850         else {
851             System.out.println( "failed." );
852             failed++;
853         }
854         System.out.print( "Amino acid sequence: " );
855         if ( Test.testAminoAcidSequence() ) {
856             System.out.println( "OK." );
857             succeeded++;
858         }
859         else {
860             System.out.println( "failed." );
861             failed++;
862         }
863         System.out.print( "General MSA parser: " );
864         if ( Test.testGeneralMsaParser() ) {
865             System.out.println( "OK." );
866             succeeded++;
867         }
868         else {
869             System.out.println( "failed." );
870             failed++;
871         }
872         System.out.print( "Fasta parser for msa: " );
873         if ( Test.testFastaParser() ) {
874             System.out.println( "OK." );
875             succeeded++;
876         }
877         else {
878             System.out.println( "failed." );
879             failed++;
880         }
881         System.out.print( "Creation of balanced phylogeny: " );
882         if ( Test.testCreateBalancedPhylogeny() ) {
883             System.out.println( "OK." );
884             succeeded++;
885         }
886         else {
887             System.out.println( "failed." );
888             failed++;
889         }
890         System.out.print( "Genbank accessor parsing: " );
891         if ( Test.testGenbankAccessorParsing() ) {
892             System.out.println( "OK." );
893             succeeded++;
894         }
895         else {
896             System.out.println( "failed." );
897             failed++;
898         }
899         String path = "";
900         final String os = ForesterUtil.OS_NAME.toLowerCase();
901         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
902             path = "/usr/local/bin/mafft";
903         }
904         else if ( os.indexOf( "win" ) >= 0 ) {
905             path = "C:\\Program Files\\mafft-win\\mafft.bat";
906         }
907         else {
908             path = "mafft";
909             if ( !MsaInferrer.isInstalled( path ) ) {
910                 path = "/usr/bin/mafft";
911             }
912             if ( !MsaInferrer.isInstalled( path ) ) {
913                 path = "/usr/local/bin/mafft";
914             }
915         }
916         if ( MsaInferrer.isInstalled( path ) ) {
917             System.out.print( "MAFFT (external program): " );
918             if ( Test.testMafft( path ) ) {
919                 System.out.println( "OK." );
920                 succeeded++;
921             }
922             else {
923                 System.out.println( "failed [will not count towards failed tests]" );
924             }
925         }
926         System.out.print( "Next nodes with collapsed: " );
927         if ( Test.testNextNodeWithCollapsing() ) {
928             System.out.println( "OK." );
929             succeeded++;
930         }
931         else {
932             System.out.println( "failed." );
933             failed++;
934         }
935         System.out.print( "Simple MSA quality: " );
936         if ( Test.testMsaQualityMethod() ) {
937             System.out.println( "OK." );
938             succeeded++;
939         }
940         else {
941             System.out.println( "failed." );
942             failed++;
943         }
944         System.out.print( "Deleteable MSA: " );
945         if ( Test.testDeleteableMsa() ) {
946             System.out.println( "OK." );
947             succeeded++;
948         }
949         else {
950             System.out.println( "failed." );
951             failed++;
952         }
953         System.out.print( "MSA entropy: " );
954         if ( Test.testMsaEntropy() ) {
955             System.out.println( "OK." );
956             succeeded++;
957         }
958         else {
959             System.out.println( "failed." );
960             failed++;
961         }
962         if ( PERFORM_DB_TESTS ) {
963             System.out.print( "Uniprot Entry Retrieval: " );
964             if ( Test.testUniprotEntryRetrieval() ) {
965                 System.out.println( "OK." );
966                 succeeded++;
967             }
968             else {
969                 System.out.println( "failed." );
970                 failed++;
971             }
972             System.out.print( "Ebi Entry Retrieval: " );
973             if ( Test.testEbiEntryRetrieval() ) {
974                 System.out.println( "OK." );
975                 succeeded++;
976             }
977             else {
978                 System.out.println( "failed." );
979                 failed++;
980             }
981             System.out.print( "Sequence DB tools 2: " );
982             if ( testSequenceDbWsTools2() ) {
983                 System.out.println( "OK." );
984                 succeeded++;
985             }
986             else {
987                 System.out.println( "failed." );
988                 failed++;
989                 System.exit( -1 );
990             }
991             System.out.print( "Uniprot Taxonomy Search: " );
992             if ( Test.testUniprotTaxonomySearch() ) {
993                 System.out.println( "OK." );
994                 succeeded++;
995             }
996             else {
997                 System.out.println( "failed." );
998                 failed++;
999             }
1000         }
1001         if ( PERFORM_WEB_TREE_ACCESS ) {
1002             System.out.print( "TreeBase acccess: " );
1003             if ( Test.testTreeBaseReading() ) {
1004                 System.out.println( "OK." );
1005                 succeeded++;
1006             }
1007             else {
1008                 System.out.println( "failed." );
1009                 failed++;
1010             }
1011             System.out.print( "ToL access: " );
1012             if ( Test.testToLReading() ) {
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: " );
1021             if ( Test.testNHXparsingFromURL() ) {
1022                 System.out.println( "OK." );
1023                 succeeded++;
1024             }
1025             else {
1026                 System.out.println( "failed." );
1027                 failed++;
1028             }
1029             System.out.print( "NHX parsing from URL 2: " );
1030             if ( Test.testNHXparsingFromURL2() ) {
1031                 System.out.println( "OK." );
1032                 succeeded++;
1033             }
1034             else {
1035                 System.out.println( "failed." );
1036                 failed++;
1037             }
1038             System.out.print( "phyloXML parsing from URL: " );
1039             if ( Test.testPhyloXMLparsingFromURL() ) {
1040                 System.out.println( "OK." );
1041                 succeeded++;
1042             }
1043             else {
1044                 System.out.println( "failed." );
1045                 failed++;
1046             }
1047             System.out.print( "TreeFam access: " );
1048             if ( Test.testTreeFamReading() ) {
1049                 System.out.println( "OK." );
1050                 succeeded++;
1051             }
1052             else {
1053                 System.out.println( "failed." );
1054                 failed++;
1055             }
1056             System.out.print( "Pfam tree access: " );
1057             if ( Test.testPfamTreeReading() ) {
1058                 System.out.println( "OK." );
1059                 succeeded++;
1060             }
1061             else {
1062                 System.out.println( "failed." );
1063                 failed++;
1064             }
1065         }
1066         System.out.println();
1067         final Runtime rt = java.lang.Runtime.getRuntime();
1068         final long free_memory = rt.freeMemory() / 1000000;
1069         final long total_memory = rt.totalMemory() / 1000000;
1070         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1071                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1072         System.out.println();
1073         System.out.println( "Successful tests: " + succeeded );
1074         System.out.println( "Failed     tests: " + failed );
1075         System.out.println();
1076         if ( failed < 1 ) {
1077             System.out.println( "OK." );
1078         }
1079         else {
1080             System.out.println( "Not OK." );
1081         }
1082     }
1083
1084     private static boolean testEngulfingOverlapRemoval() {
1085         try {
1086             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1087             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1088             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1089             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1090             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1091             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1092             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1093             final List<Boolean> covered = new ArrayList<Boolean>();
1094             covered.add( true ); // 0
1095             covered.add( false ); // 1
1096             covered.add( true ); // 2
1097             covered.add( false ); // 3
1098             covered.add( true ); // 4
1099             covered.add( true ); // 5
1100             covered.add( false ); // 6
1101             covered.add( true ); // 7
1102             covered.add( true ); // 8
1103             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1104                 return false;
1105             }
1106             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1107                 return false;
1108             }
1109             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1110                 return false;
1111             }
1112             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1113                 return false;
1114             }
1115             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1116                 return false;
1117             }
1118             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1119                 return false;
1120             }
1121             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1122                 return false;
1123             }
1124             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1125             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1126             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1127             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1128             abc.addProteinDomain( a );
1129             abc.addProteinDomain( b );
1130             abc.addProteinDomain( c );
1131             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1132             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1133             if ( abc.getNumberOfProteinDomains() != 3 ) {
1134                 return false;
1135             }
1136             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1137                 return false;
1138             }
1139             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1140                 return false;
1141             }
1142             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1143                 return false;
1144             }
1145             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1146                 return false;
1147             }
1148             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1149             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1150             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1151             final Protein def = new BasicProtein( "def", "nemve", 0 );
1152             def.addProteinDomain( d );
1153             def.addProteinDomain( e );
1154             def.addProteinDomain( f );
1155             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1156             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1157             if ( def.getNumberOfProteinDomains() != 3 ) {
1158                 return false;
1159             }
1160             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1161                 return false;
1162             }
1163             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1164                 return false;
1165             }
1166             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1167                 return false;
1168             }
1169             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1170                 return false;
1171             }
1172             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1173                 return false;
1174             }
1175         }
1176         catch ( final Exception e ) {
1177             e.printStackTrace( System.out );
1178             return false;
1179         }
1180         return true;
1181     }
1182
1183     private static final boolean testNHXparsingFromURL2() {
1184         try {
1185             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1186             final Phylogeny phys[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1187                                                                       false,
1188                                                                       false,
1189                                                                       false,
1190                                                                       TAXONOMY_EXTRACTION.NO,
1191                                                                       false );
1192             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1193                 return false;
1194             }
1195             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1196                 System.out.println( phys[ 0 ].toNewHampshire() );
1197                 return false;
1198             }
1199             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1200                 System.out.println( phys[ 1 ].toNewHampshire() );
1201                 return false;
1202             }
1203             final Phylogeny phys2[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1204                                                                        false,
1205                                                                        false,
1206                                                                        false,
1207                                                                        TAXONOMY_EXTRACTION.NO,
1208                                                                        false );
1209             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1210                 return false;
1211             }
1212             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1213                 System.out.println( phys2[ 0 ].toNewHampshire() );
1214                 return false;
1215             }
1216             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1217                 System.out.println( phys2[ 1 ].toNewHampshire() );
1218                 return false;
1219             }
1220             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1221                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1222             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1223                 return false;
1224             }
1225             if ( !phys3[ 0 ]
1226                     .toNewHampshire()
1227                     .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))))));" ) ) {
1228                 System.out.println( phys3[ 0 ].toNewHampshire() );
1229                 return false;
1230             }
1231             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1232                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1233             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1234                 return false;
1235             }
1236             if ( !phys4[ 0 ]
1237                     .toNewHampshire()
1238                     .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))))));" ) ) {
1239                 System.out.println( phys4[ 0 ].toNewHampshire() );
1240                 return false;
1241             }
1242         }
1243         catch ( final Exception e ) {
1244             e.printStackTrace();
1245             return false;
1246         }
1247         return true;
1248     }
1249
1250     private static final boolean testNHXparsingFromURL() {
1251         try {
1252             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1253             final URL u = new URL( s );
1254             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1255             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1256             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1257                 return false;
1258             }
1259             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1260                 System.out.println( phys[ 0 ].toNewHampshire() );
1261                 return false;
1262             }
1263             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1264                 System.out.println( phys[ 1 ].toNewHampshire() );
1265                 return false;
1266             }
1267             final URL u2 = new URL( s );
1268             final Phylogeny[] phys2 = factory.create( u2.openStream(), new NHXParser() );
1269             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1270                 return false;
1271             }
1272             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1273                 System.out.println( phys2[ 0 ].toNewHampshire() );
1274                 return false;
1275             }
1276             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1277             final NHXParser p = new NHXParser();
1278             final URL u3 = new URL( s );
1279             p.setSource( u3 );
1280             if ( !p.hasNext() ) {
1281                 return false;
1282             }
1283             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1284                 return false;
1285             }
1286             if ( !p.hasNext() ) {
1287                 return false;
1288             }
1289             p.reset();
1290             if ( !p.hasNext() ) {
1291                 return false;
1292             }
1293             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1294                 return false;
1295             }
1296             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1297                 return false;
1298             }
1299             p.reset();
1300             if ( !p.hasNext() ) {
1301                 return false;
1302             }
1303             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1304                 return false;
1305             }
1306             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1307                 return false;
1308             }
1309         }
1310         catch ( final Exception e ) {
1311             System.out.println( e.toString() );
1312             e.printStackTrace();
1313             return false;
1314         }
1315         return true;
1316     }
1317
1318     private static boolean testOverlapRemoval() {
1319         try {
1320             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1321             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1322             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1323             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1324             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1325             final List<Boolean> covered = new ArrayList<Boolean>();
1326             covered.add( true ); // 0
1327             covered.add( false ); // 1
1328             covered.add( true ); // 2
1329             covered.add( false ); // 3
1330             covered.add( true ); // 4
1331             covered.add( true ); // 5
1332             covered.add( false ); // 6
1333             covered.add( true ); // 7
1334             covered.add( true ); // 8
1335             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1336                 return false;
1337             }
1338             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1339                 return false;
1340             }
1341             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1342                 return false;
1343             }
1344             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1345                 return false;
1346             }
1347             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1348                 return false;
1349             }
1350             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1351             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1352             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1353             ab.addProteinDomain( a );
1354             ab.addProteinDomain( b );
1355             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1356             if ( ab.getNumberOfProteinDomains() != 2 ) {
1357                 return false;
1358             }
1359             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1360                 return false;
1361             }
1362             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1363                 return false;
1364             }
1365             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1366             if ( ab.getNumberOfProteinDomains() != 2 ) {
1367                 return false;
1368             }
1369             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1370                 return false;
1371             }
1372             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1373             final Domain d = new BasicDomain( "d",
1374                                               ( short ) 10000,
1375                                               ( short ) 10500,
1376                                               ( short ) 1,
1377                                               ( short ) 1,
1378                                               0.0000001,
1379                                               1 );
1380             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1381             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1382             cde.addProteinDomain( c );
1383             cde.addProteinDomain( d );
1384             cde.addProteinDomain( e );
1385             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1386             if ( cde.getNumberOfProteinDomains() != 3 ) {
1387                 return false;
1388             }
1389             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1390                 return false;
1391             }
1392             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1393             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1394             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1395             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1396             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1397             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1398             fghi.addProteinDomain( f );
1399             fghi.addProteinDomain( g );
1400             fghi.addProteinDomain( h );
1401             fghi.addProteinDomain( i );
1402             fghi.addProteinDomain( i );
1403             fghi.addProteinDomain( i );
1404             fghi.addProteinDomain( i2 );
1405             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1406             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1407                 return false;
1408             }
1409             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1410                 return false;
1411             }
1412             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1413                 return false;
1414             }
1415             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1416             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1417                 return false;
1418             }
1419             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1420                 return false;
1421             }
1422             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1423             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1424             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1425             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1426             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1427             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1428             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1429             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1430             jklm.addProteinDomain( j );
1431             jklm.addProteinDomain( k );
1432             jklm.addProteinDomain( l );
1433             jklm.addProteinDomain( m );
1434             jklm.addProteinDomain( m0 );
1435             jklm.addProteinDomain( m1 );
1436             jklm.addProteinDomain( m2 );
1437             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1438             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1439                 return false;
1440             }
1441             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1442                 return false;
1443             }
1444             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1445                 return false;
1446             }
1447             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1448             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1449                 return false;
1450             }
1451             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1452                 return false;
1453             }
1454             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1455             final Protein od = new BasicProtein( "od", "varanus", 0 );
1456             od.addProteinDomain( only );
1457             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1458             if ( od.getNumberOfProteinDomains() != 1 ) {
1459                 return false;
1460             }
1461             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1462                 return false;
1463             }
1464         }
1465         catch ( final Exception e ) {
1466             e.printStackTrace( System.out );
1467             return false;
1468         }
1469         return true;
1470     }
1471
1472     private static final boolean testPfamTreeReading() {
1473         try {
1474             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1475             final NHXParser parser = new NHXParser();
1476             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1477             parser.setReplaceUnderscores( false );
1478             parser.setGuessRootedness( true );
1479             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser);
1480             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1481                 return false;
1482             }
1483             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1484                 return false;
1485             }
1486         }
1487         catch ( final Exception e ) {
1488             e.printStackTrace();
1489             return false;
1490         }
1491         return true;
1492     }
1493
1494     private static final boolean testPhyloXMLparsingFromURL() {
1495         try {
1496             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1497             final URL u = new URL( s );
1498             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1499             
1500             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1501                 return false;
1502             }
1503             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1504             
1505             if ( ( phys2 == null ) || ( phys2.length != 2 ) ) {
1506                 return false;
1507             }
1508         }
1509         catch ( final Exception e ) {
1510             e.printStackTrace();
1511             return false;
1512         }
1513         return true;
1514     }
1515
1516     private static final boolean testToLReading() {
1517         try {
1518             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1519             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, new TolParser() );
1520             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1521                 return false;
1522             }
1523             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1524                 return false;
1525             }
1526             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1527                 return false;
1528             }
1529             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1530                 return false;
1531             }
1532             //
1533             final URL u2 = new URL( WebserviceUtil.TOL_URL_BASE + "17706" );
1534             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, new TolParser() );
1535             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
1536                 return false;
1537             }
1538             if ( !phys2[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "17706" ) ) {
1539                 return false;
1540             }
1541             if ( phys2[ 0 ].getNumberOfExternalNodes() < 5 ) {
1542                 return false;
1543             }
1544         }
1545         catch ( final Exception e ) {
1546             e.printStackTrace();
1547             return false;
1548         }
1549         return true;
1550     }
1551
1552     private static final boolean testTreeBaseReading() {
1553         try {
1554             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "72557?format=nexus" );  
1555             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1556             parser.setReplaceUnderscores( true );
1557             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1558             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1559                 return false;
1560             }
1561             final URL u_1 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2406?format=nexus" );  
1562             final NexusPhylogeniesParser parser_1 = new NexusPhylogeniesParser();
1563             final Phylogeny[] phys_1 = ForesterUtil.readPhylogeniesFromUrl( u_1, parser_1 );
1564             if ( ( phys_1 == null ) || ( phys_1.length != 1 ) ) {
1565                 return false;
1566             }
1567             final URL u_2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "422?format=nexus" );  
1568             final NexusPhylogeniesParser parser_2 = new NexusPhylogeniesParser();
1569             final Phylogeny[] phys_2 = ForesterUtil.readPhylogeniesFromUrl( u_2, parser_2 );
1570             if ( ( phys_2 == null ) || ( phys_2.length != 1 ) ) {
1571                 return false;
1572             }
1573             final URL u_3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2654?format=nexus" );  
1574             final NexusPhylogeniesParser parser_3 = new NexusPhylogeniesParser();
1575             final Phylogeny[] phys_3 = ForesterUtil.readPhylogeniesFromUrl( u_3, parser_3 );
1576              if ( ( phys_3 == null ) || ( phys_3.length != 1 ) ) {
1577                 return false;
1578             }
1579             final URL u_4 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );  
1580             final NexusPhylogeniesParser parser_4 = new NexusPhylogeniesParser();
1581             final Phylogeny[] phys_4 = ForesterUtil.readPhylogeniesFromUrl( u_4, parser_4 );
1582              if ( ( phys_4 == null ) || ( phys_4.length != 1 ) ) {
1583                 return false;
1584             }
1585             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1586             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1587             parser2.setReplaceUnderscores( true );
1588             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, parser2 );
1589             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1590                 return false;
1591             }
1592             final URL u3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14909?format=nexus" );
1593             final NexusPhylogeniesParser parser3 = new NexusPhylogeniesParser();
1594             final Phylogeny[] phys3 = ForesterUtil.readPhylogeniesFromUrl( u3, parser3 );
1595             if ( ( phys3 == null ) || ( phys3.length != 2 ) ) {
1596                 return false;
1597             }
1598             final Phylogeny[] phys4 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14525?format=nexus" ),
1599                     new NexusPhylogeniesParser() );
1600             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1601                 return false;
1602             }
1603             final Phylogeny[] phys5 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15632?format=nexus" ) ,
1604                     new NexusPhylogeniesParser() );
1605             if ( ( phys5 == null ) || ( phys5.length != 1 ) ) {
1606                 return false;
1607             }
1608             final Phylogeny[] phys6 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "10190?format=nexus" ) ,
1609                     new NexusPhylogeniesParser() );
1610             if ( ( phys6 == null ) || ( phys6.length != 1 ) ) {
1611                 return false;
1612             }
1613             final Phylogeny[] phys7 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "13246?format=nexus" ) ,
1614                     new NexusPhylogeniesParser() );
1615             if ( ( phys7 == null ) || ( phys7.length != 2 ) ) {
1616                 return false;
1617             }
1618             final Phylogeny[] phys8 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "11662?format=nexus" ) ,
1619                     new NexusPhylogeniesParser() );
1620             if ( ( phys8 == null ) || ( phys8.length != 2 ) ) {
1621                 return false;
1622             }
1623             final Phylogeny[] phys9 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "562?format=nexus" ) ,
1624                     new NexusPhylogeniesParser() );
1625             if ( ( phys9 == null ) || ( phys9.length != 4 ) ) {
1626                 return false;
1627             }
1628             final Phylogeny[] phys16424 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "16424?format=nexus" ) ,
1629                     new NexusPhylogeniesParser() );
1630             if ( ( phys16424 == null ) || ( phys16424.length != 1 ) ) {
1631                 return false;
1632             }
1633             final Phylogeny[] phys17878 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "17878?format=nexus" ) ,
1634                     new NexusPhylogeniesParser() );
1635             if ( ( phys17878 == null ) || ( phys17878.length != 17 ) ) {
1636                 return false;
1637             }
1638             final Phylogeny[] phys18804 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "18804?format=nexus" ) ,
1639                     new NexusPhylogeniesParser() );
1640             if ( ( phys18804 == null ) || ( phys18804.length != 2 ) ) {
1641                 return false;
1642             }
1643             final Phylogeny[] phys346 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "346?format=nexus" ) ,
1644                     new NexusPhylogeniesParser() );
1645             if ( ( phys346 == null ) || ( phys346.length != 1 ) ) {
1646                 return false;
1647             }
1648         }
1649         catch ( final Exception e ) {
1650             e.printStackTrace();
1651             return false;
1652         }
1653         return true;
1654     }
1655
1656     private static final boolean testTreeFamReading() {
1657         try {
1658             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1659             final NHXParser parser = new NHXParser();
1660             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1661             parser.setReplaceUnderscores( false );
1662             parser.setGuessRootedness( true );
1663             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1664             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1665                 return false;
1666             }
1667             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1668                 return false;
1669             }
1670         }
1671         catch ( final Exception e ) {
1672             e.printStackTrace();
1673             return false;
1674         }
1675         return true;
1676     }
1677
1678     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1679         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1680         return p;
1681     }
1682
1683     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1684         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1685     }
1686
1687     private static boolean testAminoAcidSequence() {
1688         try {
1689             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1690             if ( aa1.getLength() != 13 ) {
1691                 return false;
1692             }
1693             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1694                 return false;
1695             }
1696             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1697                 return false;
1698             }
1699             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1700                 return false;
1701             }
1702             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1703             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1704                 return false;
1705             }
1706             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1707             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1708                 return false;
1709             }
1710             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1711             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1712                 return false;
1713             }
1714         }
1715         catch ( final Exception e ) {
1716             e.printStackTrace();
1717             return false;
1718         }
1719         return true;
1720     }
1721
1722     private static boolean testBasicDomain() {
1723         try {
1724             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1725             if ( !pd.getDomainId().equals( "id" ) ) {
1726                 return false;
1727             }
1728             if ( pd.getNumber() != 1 ) {
1729                 return false;
1730             }
1731             if ( pd.getTotalCount() != 4 ) {
1732                 return false;
1733             }
1734             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1735                 return false;
1736             }
1737             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1738             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1739             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1740             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1741             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1742             if ( !a1.equals( a1 ) ) {
1743                 return false;
1744             }
1745             if ( !a1.equals( a1_copy ) ) {
1746                 return false;
1747             }
1748             if ( !a1.equals( a1_equal ) ) {
1749                 return false;
1750             }
1751             if ( !a1.equals( a2 ) ) {
1752                 return false;
1753             }
1754             if ( a1.equals( a3 ) ) {
1755                 return false;
1756             }
1757             if ( a1.compareTo( a1 ) != 0 ) {
1758                 return false;
1759             }
1760             if ( a1.compareTo( a1_copy ) != 0 ) {
1761                 return false;
1762             }
1763             if ( a1.compareTo( a1_equal ) != 0 ) {
1764                 return false;
1765             }
1766             if ( a1.compareTo( a2 ) != 0 ) {
1767                 return false;
1768             }
1769             if ( a1.compareTo( a3 ) == 0 ) {
1770                 return false;
1771             }
1772         }
1773         catch ( final Exception e ) {
1774             e.printStackTrace( System.out );
1775             return false;
1776         }
1777         return true;
1778     }
1779
1780     private static boolean testBasicNodeMethods() {
1781         try {
1782             if ( PhylogenyNode.getNodeCount() != 0 ) {
1783                 return false;
1784             }
1785             final PhylogenyNode n1 = new PhylogenyNode();
1786             final PhylogenyNode n2 = PhylogenyNode
1787                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1788             final PhylogenyNode n3 = PhylogenyNode
1789                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1790             final PhylogenyNode n4 = PhylogenyNode
1791                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1792             if ( n1.isHasAssignedEvent() ) {
1793                 return false;
1794             }
1795             if ( PhylogenyNode.getNodeCount() != 4 ) {
1796                 return false;
1797             }
1798             if ( n3.getIndicator() != 0 ) {
1799                 return false;
1800             }
1801             if ( n3.getNumberOfExternalNodes() != 1 ) {
1802                 return false;
1803             }
1804             if ( !n3.isExternal() ) {
1805                 return false;
1806             }
1807             if ( !n3.isRoot() ) {
1808                 return false;
1809             }
1810             if ( !n4.getName().equals( "n4" ) ) {
1811                 return false;
1812             }
1813         }
1814         catch ( final Exception e ) {
1815             e.printStackTrace( System.out );
1816             return false;
1817         }
1818         return true;
1819     }
1820     
1821     private static boolean testUTF8ParsingFromFile() {
1822         try {
1823             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1824             final Phylogeny[] phylogenies_xml = ParserBasedPhylogenyFactory.getInstance().create( new File( Test.PATH_TO_TEST_DATA + "chars.xml" ),
1825                                                               xml_parser );
1826             if ( xml_parser.getErrorCount() > 0 ) {
1827                 System.out.println( xml_parser.getErrorMessages().toString() );
1828                 return false;
1829             }
1830             if ( phylogenies_xml.length != 1 ) {
1831                 return false;
1832             }
1833          
1834             final Phylogeny[] phylogenies_xml2 = ParserBasedPhylogenyFactory.getInstance().create( new StringBuffer( phylogenies_xml[0].toPhyloXML( 0 )),
1835                                                                                                    xml_parser );
1836             
1837             final Phylogeny[] phylogenies_nh = ParserBasedPhylogenyFactory.getInstance().create( new File( Test.PATH_TO_TEST_DATA + "chars.nh" ), new NHXParser() );
1838             if ( phylogenies_nh.length != 1 ) {
1839                 return false;
1840             }
1841            
1842             final Phylogeny[] phylogenies_nex = ParserBasedPhylogenyFactory.getInstance().create( new File( Test.PATH_TO_TEST_DATA + "chars.nex" ), new NexusPhylogeniesParser() );
1843             if ( phylogenies_nex.length != 1 ) {
1844                 return false;
1845             }
1846           
1847             final String[] xml_n = phylogenies_xml[0].getAllExternalNodeNames();
1848             final String[] xml_n2 = phylogenies_xml2[0].getAllExternalNodeNames();
1849             final String[] nh_n = phylogenies_nh[0].getAllExternalNodeNames();
1850             final String[] nex_n = phylogenies_nex[0].getAllExternalNodeNames();
1851             final String n0 = "AQ~!@#$%^&*()_+-=\\{}|;:\"<>?,./";
1852             final String n1 = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ";
1853             final String n2 = "漢字ひらがなカタカナ";
1854             final String n3 = "อักษรไทย";
1855             final String n4 = "繁體字";
1856             final String n5 = "한글";
1857             final String n6 = "देवनागरी";
1858             
1859             final String n7 = "chữ Quốc ngữ";
1860             final String n8 = "ру́сский язы́к";
1861             final String n9 = "អក្សរខ្មែរ";
1862             
1863             if ( !xml_n[0].equals( n0 ) ) {
1864                 System.out.println( xml_n[0] );
1865                 System.out.println( n0 );
1866                 return false;
1867             }
1868             if ( !xml_n2[0].equals( n0 ) ) {
1869                 System.out.println( xml_n2[0] );
1870                 System.out.println( n0 );
1871                 return false;
1872             }
1873             if ( !nh_n[0].equals( n0 ) ) {
1874                 System.out.println( nh_n[0] );
1875                 System.out.println( n0 );
1876                 return false;
1877             }
1878             if ( !nex_n[0].equals( n0 ) ) {
1879                 System.out.println( nex_n[0] );
1880                 System.out.println( n0 );
1881                 return false;
1882             }
1883             
1884             if ( !xml_n[1].equals( n1 ) ) {
1885                 System.out.println( xml_n[1] );
1886                 System.out.println( n1 );
1887                 return false;
1888             }
1889             if ( !xml_n2[1].equals( n1 ) ) {
1890                 System.out.println( xml_n2[1] );
1891                 System.out.println( n1 );
1892                 return false;
1893             }
1894             if ( !nh_n[1].equals( n1 ) ) {
1895                 System.out.println( nh_n[1] );
1896                 System.out.println( n1 );
1897                 return false;
1898             }
1899             if ( !nex_n[1].equals( n1 ) ) {
1900                 System.out.println( nex_n[1] );
1901                 System.out.println( n1 );
1902                 return false;
1903             }
1904             
1905             if ( !xml_n[2].equals( n2 ) ) {
1906                 System.out.println( xml_n[2] );
1907                 System.out.println( n2 );
1908                 return false;
1909             }
1910             if ( !xml_n2[2].equals( n2 ) ) {
1911                 System.out.println( xml_n2[2] );
1912                 System.out.println( n2 );
1913                 return false;
1914             }
1915             if ( !nh_n[2].equals( n2 ) ) {
1916                 System.out.println( nh_n[2] );
1917                 System.out.println( n2 );
1918                 return false;
1919             }
1920             if ( !nex_n[2].equals( n2 ) ) {
1921                 System.out.println( nex_n[2] );
1922                 System.out.println( n2 );
1923                 return false;
1924             }
1925             //
1926             if ( !xml_n[3].equals( n3 ) ) {
1927                 System.out.println( xml_n[3] );
1928                 System.out.println( n3 );
1929                 return false;
1930             }
1931             if ( !xml_n2[3].equals( n3 ) ) {
1932                 System.out.println( xml_n2[3] );
1933                 System.out.println( n3 );
1934                 return false;
1935             }
1936             if ( !nh_n[3].equals( n3 ) ) {
1937                 System.out.println( nh_n[3] );
1938                 System.out.println( n3 );
1939                 return false;
1940             }
1941             if ( !nex_n[3].equals( n3 ) ) {
1942                 System.out.println( nex_n[3] );
1943                 System.out.println( n3 );
1944                 return false;
1945             }
1946             //
1947             if ( !xml_n[4].equals( n4 ) ) {
1948                 System.out.println( xml_n[4] );
1949                 System.out.println( n4 );
1950                 return false;
1951             }
1952             if ( !nh_n[4].equals( n4 ) ) {
1953                 System.out.println( nh_n[4] );
1954                 System.out.println( n4 );
1955                 return false;
1956             }
1957             if ( !nex_n[4].equals( n4 ) ) {
1958                 System.out.println( nex_n[4] );
1959                 System.out.println( n4 );
1960                 return false;
1961             }
1962             //
1963             if ( !xml_n[5].equals( n5 ) ) {
1964                 System.out.println( xml_n[5] );
1965                 System.out.println( n5 );
1966                 return false;
1967             }
1968             if ( !nh_n[5].equals( n5 ) ) {
1969                 System.out.println( nh_n[5] );
1970                 System.out.println( n5 );
1971                 return false;
1972             }
1973             if ( !nex_n[5].equals( n5 ) ) {
1974                 System.out.println( nex_n[5] );
1975                 System.out.println( n5 );
1976                 return false;
1977             }
1978             //
1979             if ( !xml_n[6].equals( n6 ) ) {
1980                 System.out.println( xml_n[6] );
1981                 System.out.println( n6 );
1982                 return false;
1983             }
1984             if ( !nh_n[6].equals( n6 ) ) {
1985                 System.out.println( nh_n[6] );
1986                 System.out.println( n6 );
1987                 return false;
1988             }
1989             if ( !nex_n[6].equals( n6 ) ) {
1990                 System.out.println( nex_n[6] );
1991                 System.out.println( n6 );
1992                 return false;
1993             }
1994             //
1995             if ( !xml_n[7].equals( n7 ) ) {
1996                 System.out.println( xml_n[7] );
1997                 System.out.println( n7 );
1998                 return false;
1999             }
2000             if ( !nh_n[7].equals( n7 ) ) {
2001                 System.out.println( nh_n[7] );
2002                 System.out.println( n7 );
2003                 return false;
2004             }
2005             if ( !nex_n[7].equals( n7 ) ) {
2006                 System.out.println( nex_n[7] );
2007                 System.out.println( n7 );
2008                 return false;
2009             }
2010             if ( !xml_n[8].equals( n8 ) ) {
2011                 System.out.println( xml_n[8] );
2012                 System.out.println( n8 );
2013                 return false;
2014             }
2015             if ( !nh_n[8].equals( n8 ) ) {
2016                 System.out.println( nh_n[8] );
2017                 System.out.println( n8 );
2018                 return false;
2019             }
2020             if ( !nex_n[8].equals( n8 ) ) {
2021                 System.out.println( nex_n[8] );
2022                 System.out.println( n8 );
2023                 return false;
2024             }
2025             if ( !xml_n[9].equals( n9 ) ) {
2026                 System.out.println( xml_n[9] );
2027                 System.out.println( n9 );
2028                 return false;
2029             }
2030             if ( !xml_n2[9].equals( n9 ) ) {
2031                 System.out.println( xml_n2[9] );
2032                 System.out.println( n9 );
2033                 return false;
2034             }
2035             if ( !nh_n[9].equals( n9 ) ) {
2036                 System.out.println( nh_n[9] );
2037                 System.out.println( n9 );
2038                 return false;
2039             }
2040             if ( !nex_n[9].equals( n9 ) ) {
2041                 System.out.println( nex_n[9] );
2042                 System.out.println( n9 );
2043                 return false;
2044             }
2045             if (!phylogenies_xml[0].toNewHampshire().equals( 
2046                                                             phylogenies_nh[0].toNewHampshire() ) ) {
2047                 System.out.println( phylogenies_xml[0].toNewHampshire() );
2048                 System.out.println( phylogenies_nh[0].toNewHampshire() );
2049                 return false;
2050             }
2051             if (!phylogenies_xml[0].toNewHampshire().equals( 
2052                                                             phylogenies_nex[0].toNewHampshire() ) ) {
2053                 System.out.println( phylogenies_xml[0].toNewHampshire() );
2054                 System.out.println( phylogenies_nex[0].toNewHampshire() );
2055                 return false;
2056             }
2057         }
2058         catch ( final Exception e ) {
2059             e.printStackTrace( System.out );
2060             return false;
2061         }
2062         return true;
2063     }
2064     
2065     
2066
2067     private static boolean testBasicPhyloXMLparsing() {
2068         try {
2069             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2070             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2071             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ),
2072                                                               xml_parser );
2073             if ( xml_parser.getErrorCount() > 0 ) {
2074                 System.out.println( xml_parser.getErrorMessages().toString() );
2075                 return false;
2076             }
2077             if ( phylogenies_0.length != 4 ) {
2078                 return false;
2079             }
2080             final Phylogeny t1 = phylogenies_0[ 0 ];
2081             final Phylogeny t2 = phylogenies_0[ 1 ];
2082             final Phylogeny t3 = phylogenies_0[ 2 ];
2083             final Phylogeny t4 = phylogenies_0[ 3 ];
2084             if ( t1.getNumberOfExternalNodes() != 1 ) {
2085                 return false;
2086             }
2087             if ( !t1.isRooted() ) {
2088                 return false;
2089             }
2090             if ( t1.isRerootable() ) {
2091                 return false;
2092             }
2093             if ( !t1.getType().equals( "gene_tree" ) ) {
2094                 return false;
2095             }
2096             if ( t2.getNumberOfExternalNodes() != 2 ) {
2097                 return false;
2098             }
2099             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
2100                 return false;
2101             }
2102             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
2103                 return false;
2104             }
2105             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2106                 return false;
2107             }
2108             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2109                 return false;
2110             }
2111             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2112                 return false;
2113             }
2114             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2115                 return false;
2116             }
2117             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2118                     .startsWith( "actgtgggggt" ) ) {
2119                 return false;
2120             }
2121             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2122                     .startsWith( "ctgtgatgcat" ) ) {
2123                 return false;
2124             }
2125             if ( t3.getNumberOfExternalNodes() != 4 ) {
2126                 return false;
2127             }
2128             if ( !t1.getName().equals( "t1" ) ) {
2129                 return false;
2130             }
2131             if ( !t2.getName().equals( "t2" ) ) {
2132                 return false;
2133             }
2134             if ( !t3.getName().equals( "t3" ) ) {
2135                 return false;
2136             }
2137             if ( !t4.getName().equals( "t4" ) ) {
2138                 return false;
2139             }
2140             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
2141                 return false;
2142             }
2143             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
2144                 return false;
2145             }
2146             if ( !t3.getNode( "root node" ).isDuplication() ) {
2147                 return false;
2148             }
2149             if ( !t3.getNode( "node a" ).isDuplication() ) {
2150                 return false;
2151             }
2152             if ( t3.getNode( "node a" ).isSpeciation() ) {
2153                 return false;
2154             }
2155             if ( t3.getNode( "node bc" ).isDuplication() ) {
2156                 return false;
2157             }
2158             if ( !t3.getNode( "node bc" ).isSpeciation() ) {
2159                 return false;
2160             }
2161             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2162                 return false;
2163             }
2164             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
2165                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2166                 return false;
2167             }
2168             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2169                 return false;
2170             }
2171             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2172                 return false;
2173             }
2174             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
2175                 return false;
2176             }
2177             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2178                     .equals( "apoptosis" ) ) {
2179                 return false;
2180             }
2181             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2182                     .equals( "GO:0006915" ) ) {
2183                 return false;
2184             }
2185             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2186                     .equals( "UniProtKB" ) ) {
2187                 return false;
2188             }
2189             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2190                     .equals( "experimental" ) ) {
2191                 return false;
2192             }
2193             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2194                     .equals( "function" ) ) {
2195                 return false;
2196             }
2197             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2198                     .getValue() != 1 ) {
2199                 return false;
2200             }
2201             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2202                     .getType().equals( "ml" ) ) {
2203                 return false;
2204             }
2205             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2206                     .equals( "apoptosis" ) ) {
2207                 return false;
2208             }
2209             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2210                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2211                 return false;
2212             }
2213             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2214                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2215                 return false;
2216             }
2217             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2218                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2219                 return false;
2220             }
2221             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2222                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2223                 return false;
2224             }
2225             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2226                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2227                 return false;
2228             }
2229             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2230                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2231                 return false;
2232             }
2233             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2234                     .equals( "GO:0005829" ) ) {
2235                 return false;
2236             }
2237             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2238                     .equals( "intracellular organelle" ) ) {
2239                 return false;
2240             }
2241             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2242                 return false;
2243             }
2244             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2245                     .equals( "UniProt link" ) ) ) {
2246                 return false;
2247             }
2248             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2249                 return false;
2250             }
2251             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
2252             if ( x.size() != 4 ) {
2253                 return false;
2254             }
2255             int c = 0;
2256             for( final Accession acc : x ) {
2257                 if ( c == 0 ) {
2258                     if ( !acc.getSource().equals( "KEGG" ) ) {
2259                         return false;
2260                     }
2261                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2262                         return false;
2263                     }
2264                 }
2265                 c++;
2266             }
2267         }
2268         catch ( final Exception e ) {
2269             e.printStackTrace( System.out );
2270             return false;
2271         }
2272         return true;
2273     }
2274
2275     private static boolean testBasicPhyloXMLparsingRoundtrip() {
2276         try {
2277             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2278             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2279             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2280                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2281             }
2282             else {
2283                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2284             }
2285             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ),
2286                                                               xml_parser );
2287             if ( xml_parser.getErrorCount() > 0 ) {
2288                 System.out.println( xml_parser.getErrorMessages().toString() );
2289                 return false;
2290             }
2291             if ( phylogenies_0.length != 4 ) {
2292                 return false;
2293             }
2294             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
2295             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
2296             if ( phylogenies_t1.length != 1 ) {
2297                 return false;
2298             }
2299             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
2300             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
2301                 return false;
2302             }
2303             if ( !t1_rt.isRooted() ) {
2304                 return false;
2305             }
2306             if ( t1_rt.isRerootable() ) {
2307                 return false;
2308             }
2309             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
2310                 return false;
2311             }
2312             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
2313             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
2314             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
2315             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2316                 return false;
2317             }
2318             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2319                 return false;
2320             }
2321             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2322                 return false;
2323             }
2324             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2325                 return false;
2326             }
2327             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2328                     .startsWith( "actgtgggggt" ) ) {
2329                 return false;
2330             }
2331             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2332                     .startsWith( "ctgtgatgcat" ) ) {
2333                 return false;
2334             }
2335             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
2336             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
2337             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
2338             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
2339             if ( phylogenies_1.length != 1 ) {
2340                 return false;
2341             }
2342             final Phylogeny t3_rt = phylogenies_1[ 0 ];
2343             if ( !t3_rt.getName().equals( "t3" ) ) {
2344                 return false;
2345             }
2346             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
2347                 return false;
2348             }
2349             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
2350                 return false;
2351             }
2352             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
2353                 return false;
2354             }
2355             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2356                 return false;
2357             }
2358             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
2359                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2360                 return false;
2361             }
2362             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2363                 return false;
2364             }
2365             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2366                 return false;
2367             }
2368             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2369                     .equals( "UniProtKB" ) ) {
2370                 return false;
2371             }
2372             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2373                     .equals( "apoptosis" ) ) {
2374                 return false;
2375             }
2376             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2377                     .equals( "GO:0006915" ) ) {
2378                 return false;
2379             }
2380             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2381                     .equals( "UniProtKB" ) ) {
2382                 return false;
2383             }
2384             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2385                     .equals( "experimental" ) ) {
2386                 return false;
2387             }
2388             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2389                     .equals( "function" ) ) {
2390                 return false;
2391             }
2392             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2393                     .getValue() != 1 ) {
2394                 return false;
2395             }
2396             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2397                     .getType().equals( "ml" ) ) {
2398                 return false;
2399             }
2400             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2401                     .equals( "apoptosis" ) ) {
2402                 return false;
2403             }
2404             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2405                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2406                 return false;
2407             }
2408             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2409                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2410                 return false;
2411             }
2412             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2413                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2414                 return false;
2415             }
2416             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2417                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2418                 return false;
2419             }
2420             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2421                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2422                 return false;
2423             }
2424             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2425                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2426                 return false;
2427             }
2428             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2429                     .equals( "GO:0005829" ) ) {
2430                 return false;
2431             }
2432             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2433                     .equals( "intracellular organelle" ) ) {
2434                 return false;
2435             }
2436             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2437                 return false;
2438             }
2439             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2440                     .equals( "UniProt link" ) ) ) {
2441                 return false;
2442             }
2443             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2444                 return false;
2445             }
2446             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
2447                 return false;
2448             }
2449             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2450                     .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." ) ) ) {
2451                 System.out.println( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription() );
2452                 return false;
2453             }
2454             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2455                 return false;
2456             }
2457             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2458                 return false;
2459             }
2460             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
2461                 return false;
2462             }
2463             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2464                 return false;
2465             }
2466             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2467                     .equals( "ncbi" ) ) {
2468                 return false;
2469             }
2470             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2471                 return false;
2472             }
2473             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2474                     .getName().equals( "B" ) ) {
2475                 return false;
2476             }
2477             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2478                     .getFrom() != 21 ) {
2479                 return false;
2480             }
2481             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2482                 return false;
2483             }
2484             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2485                     .getLength() != 24 ) {
2486                 return false;
2487             }
2488             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2489                     .getConfidence() != 0 ) {
2490                 return false;
2491             }
2492             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2493                     .equals( "pfam" ) ) {
2494                 return false;
2495             }
2496             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2497                 return false;
2498             }
2499             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2500                 return false;
2501             }
2502             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2503                 return false;
2504             }
2505             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2506                 return false;
2507             }
2508             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2509             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2510                 return false;
2511             }
2512             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2513                 return false;
2514             }
2515             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2516                 return false;
2517             }
2518             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2519                 return false;
2520             }
2521             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2522                 return false;
2523             }
2524             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2525                 return false;
2526             }
2527             if ( taxbb.getSynonyms().size() != 2 ) {
2528                 return false;
2529             }
2530             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2531                 return false;
2532             }
2533             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2534                 return false;
2535             }
2536             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2537                 return false;
2538             }
2539             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2540                 return false;
2541             }
2542             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2543                 return false;
2544             }
2545             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2546                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2547                 return false;
2548             }
2549             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2550                 return false;
2551             }
2552             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2553                 return false;
2554             }
2555             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2556                 return false;
2557             }
2558             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2559                 return false;
2560             }
2561             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2562                 return false;
2563             }
2564             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2565                 return false;
2566             }
2567             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2568                 return false;
2569             }
2570             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2571                 return false;
2572             }
2573             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2574                     .equalsIgnoreCase( "435" ) ) {
2575                 return false;
2576             }
2577             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2578                 return false;
2579             }
2580             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2581                     .equalsIgnoreCase( "443.7" ) ) {
2582                 return false;
2583             }
2584             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2585                 return false;
2586             }
2587             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2588                 return false;
2589             }
2590             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2591                     .equalsIgnoreCase( "433" ) ) {
2592                 return false;
2593             }
2594             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2595                     .getCrossReferences();
2596             if ( x.size() != 4 ) {
2597                 return false;
2598             }
2599             int c = 0;
2600             for( final Accession acc : x ) {
2601                 if ( c == 0 ) {
2602                     if ( !acc.getSource().equals( "KEGG" ) ) {
2603                         return false;
2604                     }
2605                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2606                         return false;
2607                     }
2608                 }
2609                 c++;
2610             }
2611         }
2612         catch ( final Exception e ) {
2613             e.printStackTrace( System.out );
2614             return false;
2615         }
2616         return true;
2617     }
2618
2619     private static boolean testBasicPhyloXMLparsingValidating() {
2620         try {
2621             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2622             PhyloXmlParser xml_parser = null;
2623             try {
2624                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2625             }
2626             catch ( final Exception e ) {
2627                 // Do nothing -- means were not running from jar.
2628             }
2629             if ( xml_parser == null ) {
2630                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2631                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2632                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2633                 }
2634                 else {
2635                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2636                 }
2637             }
2638             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ),
2639                                                               xml_parser );
2640             if ( xml_parser.getErrorCount() > 0 ) {
2641                 System.out.println( xml_parser.getErrorMessages().toString() );
2642                 return false;
2643             }
2644             if ( phylogenies_0.length != 4 ) {
2645                 return false;
2646             }
2647             final Phylogeny t1 = phylogenies_0[ 0 ];
2648             final Phylogeny t2 = phylogenies_0[ 1 ];
2649             final Phylogeny t3 = phylogenies_0[ 2 ];
2650             final Phylogeny t4 = phylogenies_0[ 3 ];
2651             if ( !t1.getName().equals( "t1" ) ) {
2652                 return false;
2653             }
2654             if ( !t2.getName().equals( "t2" ) ) {
2655                 return false;
2656             }
2657             if ( !t3.getName().equals( "t3" ) ) {
2658                 return false;
2659             }
2660             if ( !t4.getName().equals( "t4" ) ) {
2661                 return false;
2662             }
2663             if ( t1.getNumberOfExternalNodes() != 1 ) {
2664                 return false;
2665             }
2666             if ( t2.getNumberOfExternalNodes() != 2 ) {
2667                 return false;
2668             }
2669             if ( t3.getNumberOfExternalNodes() != 4 ) {
2670                 return false;
2671             }
2672             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2673             final Phylogeny[] phylogenies_1 = factory.create( new File( x2 ), xml_parser );
2674             if ( xml_parser.getErrorCount() > 0 ) {
2675                 System.out.println( "errors:" );
2676                 System.out.println( xml_parser.getErrorMessages().toString() );
2677                 return false;
2678             }
2679             if ( phylogenies_1.length != 4 ) {
2680                 return false;
2681             }
2682             final Phylogeny[] phylogenies_2 = factory.create( new File(Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml" ),
2683                                                               xml_parser );
2684             if ( xml_parser.getErrorCount() > 0 ) {
2685                 System.out.println( "errors:" );
2686                 System.out.println( xml_parser.getErrorMessages().toString() );
2687                 return false;
2688             }
2689             if ( phylogenies_2.length != 1 ) {
2690                 return false;
2691             }
2692             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2693                 return false;
2694             }
2695             final Phylogeny[] phylogenies_3 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml" ),
2696                                                               xml_parser );
2697             if ( xml_parser.getErrorCount() > 0 ) {
2698                 System.out.println( xml_parser.getErrorMessages().toString() );
2699                 return false;
2700             }
2701             if ( phylogenies_3.length != 2 ) {
2702                 return false;
2703             }
2704             final Phylogeny a = phylogenies_3[ 0 ];
2705             if ( !a.getName().equals( "tree 4" ) ) {
2706                 return false;
2707             }
2708             if ( a.getNumberOfExternalNodes() != 3 ) {
2709                 return false;
2710             }
2711             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2712                 return false;
2713             }
2714             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2715                 return false;
2716             }
2717             final Phylogeny[] phylogenies_4 = factory.create( new File( Test.PATH_TO_TEST_DATA + "special_characters.xml") ,
2718                                                               xml_parser );
2719             if ( xml_parser.getErrorCount() > 0 ) {
2720                 System.out.println( xml_parser.getErrorMessages().toString() );
2721                 return false;
2722             }
2723             if ( phylogenies_4.length != 1 ) {
2724                 return false;
2725             }
2726             final Phylogeny s = phylogenies_4[ 0 ];
2727             if ( s.getNumberOfExternalNodes() != 6 ) {
2728                 return false;
2729             }
2730             s.getNode( "first" );
2731             s.getNode( "<>" );
2732             s.getNode( "\"<a'b&c'd\">\"" );
2733             s.getNode( "'''\"" );
2734             s.getNode( "\"\"\"" );
2735             s.getNode( "dick & doof" );
2736         }
2737         catch ( final Exception e ) {
2738             e.printStackTrace( System.out );
2739             return false;
2740         }
2741         return true;
2742     }
2743
2744     private static boolean testBasicProtein() {
2745         try {
2746             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2747             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2748             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2749             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2750             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2751             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2752             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2753             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2754             p0.addProteinDomain( y );
2755             p0.addProteinDomain( e );
2756             p0.addProteinDomain( b );
2757             p0.addProteinDomain( c );
2758             p0.addProteinDomain( d );
2759             p0.addProteinDomain( a );
2760             p0.addProteinDomain( x );
2761             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2762                 return false;
2763             }
2764             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2765                 return false;
2766             }
2767             //
2768             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2769             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2770             aa0.addProteinDomain( a1 );
2771             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2772                 return false;
2773             }
2774             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2775                 return false;
2776             }
2777             //
2778             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2779             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2780             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2781             aa1.addProteinDomain( a11 );
2782             aa1.addProteinDomain( a12 );
2783             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2784                 return false;
2785             }
2786             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2787                 return false;
2788             }
2789             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2790             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2791                 return false;
2792             }
2793             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2794                 return false;
2795             }
2796             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2797                 return false;
2798             }
2799             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2800             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2801                 return false;
2802             }
2803             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2804                 return false;
2805             }
2806             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2807                 return false;
2808             }
2809             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2810                 return false;
2811             }
2812             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2813             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2814                 return false;
2815             }
2816             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2817                 return false;
2818             }
2819             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2820                 return false;
2821             }
2822             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2823                 return false;
2824             }
2825             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2826             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2827                 return false;
2828             }
2829             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2830                 return false;
2831             }
2832             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2833                 return false;
2834             }
2835             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2836                 return false;
2837             }
2838             //
2839             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2840             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2841             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2842             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2843             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2844             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2845             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2846             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2847             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2848             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2849             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2850             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2851             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2852             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2853             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2854             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2855             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2856             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2857             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2858             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2859             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2860             p00.addProteinDomain( y0 );
2861             p00.addProteinDomain( e0 );
2862             p00.addProteinDomain( b0 );
2863             p00.addProteinDomain( c0 );
2864             p00.addProteinDomain( d0 );
2865             p00.addProteinDomain( a0 );
2866             p00.addProteinDomain( x0 );
2867             p00.addProteinDomain( y1 );
2868             p00.addProteinDomain( y2 );
2869             p00.addProteinDomain( y3 );
2870             p00.addProteinDomain( e1 );
2871             p00.addProteinDomain( e2 );
2872             p00.addProteinDomain( e3 );
2873             p00.addProteinDomain( e4 );
2874             p00.addProteinDomain( e5 );
2875             p00.addProteinDomain( z0 );
2876             p00.addProteinDomain( z1 );
2877             p00.addProteinDomain( z2 );
2878             p00.addProteinDomain( zz0 );
2879             p00.addProteinDomain( zz1 );
2880             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2881                 return false;
2882             }
2883             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2884                 return false;
2885             }
2886             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2887                 return false;
2888             }
2889             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2890                 return false;
2891             }
2892             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" ) ) {
2893                 return false;
2894             }
2895             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2896             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2897             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2898             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2899             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2900             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2901             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2902             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2903             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2904             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2905             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2906             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2907             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2908             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2909             p.addProteinDomain( B15 );
2910             p.addProteinDomain( C50 );
2911             p.addProteinDomain( A60 );
2912             p.addProteinDomain( A30 );
2913             p.addProteinDomain( C70 );
2914             p.addProteinDomain( B35 );
2915             p.addProteinDomain( B40 );
2916             p.addProteinDomain( A0 );
2917             p.addProteinDomain( A10 );
2918             p.addProteinDomain( A20 );
2919             p.addProteinDomain( B25 );
2920             p.addProteinDomain( D80 );
2921             List<String> domains_ids = new ArrayList<String>();
2922             domains_ids.add( "A" );
2923             domains_ids.add( "B" );
2924             domains_ids.add( "C" );
2925             if ( !p.contains( domains_ids, false ) ) {
2926                 return false;
2927             }
2928             if ( !p.contains( domains_ids, true ) ) {
2929                 return false;
2930             }
2931             domains_ids.add( "X" );
2932             if ( p.contains( domains_ids, false ) ) {
2933                 return false;
2934             }
2935             if ( p.contains( domains_ids, true ) ) {
2936                 return false;
2937             }
2938             domains_ids = new ArrayList<String>();
2939             domains_ids.add( "A" );
2940             domains_ids.add( "C" );
2941             domains_ids.add( "D" );
2942             if ( !p.contains( domains_ids, false ) ) {
2943                 return false;
2944             }
2945             if ( !p.contains( domains_ids, true ) ) {
2946                 return false;
2947             }
2948             domains_ids = new ArrayList<String>();
2949             domains_ids.add( "A" );
2950             domains_ids.add( "D" );
2951             domains_ids.add( "C" );
2952             if ( !p.contains( domains_ids, false ) ) {
2953                 return false;
2954             }
2955             if ( p.contains( domains_ids, true ) ) {
2956                 return false;
2957             }
2958             domains_ids = new ArrayList<String>();
2959             domains_ids.add( "A" );
2960             domains_ids.add( "A" );
2961             domains_ids.add( "B" );
2962             if ( !p.contains( domains_ids, false ) ) {
2963                 return false;
2964             }
2965             if ( !p.contains( domains_ids, true ) ) {
2966                 return false;
2967             }
2968             domains_ids = new ArrayList<String>();
2969             domains_ids.add( "A" );
2970             domains_ids.add( "A" );
2971             domains_ids.add( "A" );
2972             domains_ids.add( "B" );
2973             domains_ids.add( "B" );
2974             if ( !p.contains( domains_ids, false ) ) {
2975                 return false;
2976             }
2977             if ( !p.contains( domains_ids, true ) ) {
2978                 return false;
2979             }
2980             domains_ids = new ArrayList<String>();
2981             domains_ids.add( "A" );
2982             domains_ids.add( "A" );
2983             domains_ids.add( "B" );
2984             domains_ids.add( "A" );
2985             domains_ids.add( "B" );
2986             domains_ids.add( "B" );
2987             domains_ids.add( "A" );
2988             domains_ids.add( "B" );
2989             domains_ids.add( "C" );
2990             domains_ids.add( "A" );
2991             domains_ids.add( "C" );
2992             domains_ids.add( "D" );
2993             if ( !p.contains( domains_ids, false ) ) {
2994                 return false;
2995             }
2996             if ( p.contains( domains_ids, true ) ) {
2997                 return false;
2998             }
2999         }
3000         catch ( final Exception e ) {
3001             e.printStackTrace( System.out );
3002             return false;
3003         }
3004         return true;
3005     }
3006
3007     private static boolean testBasicTable() {
3008         try {
3009             final BasicTable<String> t0 = new BasicTable<String>();
3010             if ( t0.getNumberOfColumns() != 0 ) {
3011                 return false;
3012             }
3013             if ( t0.getNumberOfRows() != 0 ) {
3014                 return false;
3015             }
3016             t0.setValue( 3, 2, "23" );
3017             t0.setValue( 10, 1, "error" );
3018             t0.setValue( 10, 1, "110" );
3019             t0.setValue( 9, 1, "19" );
3020             t0.setValue( 1, 10, "101" );
3021             t0.setValue( 10, 10, "1010" );
3022             t0.setValue( 100, 10, "10100" );
3023             t0.setValue( 0, 0, "00" );
3024             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3025                 return false;
3026             }
3027             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3028                 return false;
3029             }
3030             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3031                 return false;
3032             }
3033             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3034                 return false;
3035             }
3036             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3037                 return false;
3038             }
3039             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3040                 return false;
3041             }
3042             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3043                 return false;
3044             }
3045             if ( t0.getNumberOfColumns() != 101 ) {
3046                 return false;
3047             }
3048             if ( t0.getNumberOfRows() != 11 ) {
3049                 return false;
3050             }
3051             if ( t0.getValueAsString( 49, 4 ) != null ) {
3052                 return false;
3053             }
3054             final String l = ForesterUtil.getLineSeparator();
3055             final StringBuffer source = new StringBuffer();
3056             source.append( "" + l );
3057             source.append( "# 1 1 1 1 1 1 1 1" + l );
3058             source.append( " 00 01 02 03" + l );
3059             source.append( "   10 11 12 13  " + l );
3060             source.append( "20 21 22 23 " + l );
3061             source.append( "    30  31    32 33" + l );
3062             source.append( "40 41 42 43" + l );
3063             source.append( "  # 1 1 1 1 1 " + l );
3064             source.append( "50 51 52 53 54" + l );
3065             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
3066             if ( t1.getNumberOfColumns() != 5 ) {
3067                 return false;
3068             }
3069             if ( t1.getNumberOfRows() != 6 ) {
3070                 return false;
3071             }
3072             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
3073                 return false;
3074             }
3075             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
3076                 return false;
3077             }
3078             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
3079                 return false;
3080             }
3081             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
3082                 return false;
3083             }
3084             final StringBuffer source1 = new StringBuffer();
3085             source1.append( "" + l );
3086             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3087             source1.append( " 00; 01 ;02;03" + l );
3088             source1.append( "   10; 11; 12; 13  " + l );
3089             source1.append( "20; 21; 22; 23 " + l );
3090             source1.append( "    30;  31;    32; 33" + l );
3091             source1.append( "40;41;42;43" + l );
3092             source1.append( "  # 1 1 1 1 1 " + l );
3093             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
3094             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
3095             if ( t2.getNumberOfColumns() != 5 ) {
3096                 return false;
3097             }
3098             if ( t2.getNumberOfRows() != 6 ) {
3099                 return false;
3100             }
3101             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
3102                 return false;
3103             }
3104             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
3105                 return false;
3106             }
3107             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
3108                 return false;
3109             }
3110             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
3111                 return false;
3112             }
3113             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
3114                 return false;
3115             }
3116             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
3117                 return false;
3118             }
3119             final StringBuffer source2 = new StringBuffer();
3120             source2.append( "" + l );
3121             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3122             source2.append( " 00; 01 ;02;03" + l );
3123             source2.append( "   10; 11; 12; 13  " + l );
3124             source2.append( "20; 21; 22; 23 " + l );
3125             source2.append( "                     " + l );
3126             source2.append( "    30;  31;    32; 33" + l );
3127             source2.append( "40;41;42;43" + l );
3128             source2.append( "  comment: 1 1 1 1 1 " + l );
3129             source2.append( ";;;50  ;   52; 53;;54   " + l );
3130             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
3131                                                                         ';',
3132                                                                         false,
3133                                                                         false,
3134                                                                         "comment:",
3135                                                                         false );
3136             if ( tl.size() != 2 ) {
3137                 return false;
3138             }
3139             final BasicTable<String> t3 = tl.get( 0 );
3140             final BasicTable<String> t4 = tl.get( 1 );
3141             if ( t3.getNumberOfColumns() != 4 ) {
3142                 return false;
3143             }
3144             if ( t3.getNumberOfRows() != 3 ) {
3145                 return false;
3146             }
3147             if ( t4.getNumberOfColumns() != 4 ) {
3148                 return false;
3149             }
3150             if ( t4.getNumberOfRows() != 3 ) {
3151                 return false;
3152             }
3153             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
3154                 return false;
3155             }
3156             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
3157                 return false;
3158             }
3159         }
3160         catch ( final Exception e ) {
3161             e.printStackTrace( System.out );
3162             return false;
3163         }
3164         return true;
3165     }
3166
3167     private static boolean testBasicTolXMLparsing() {
3168         try {
3169             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3170             final TolParser parser = new TolParser();
3171             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
3172             if ( parser.getErrorCount() > 0 ) {
3173                 System.out.println( parser.getErrorMessages().toString() );
3174                 return false;
3175             }
3176             if ( phylogenies_0.length != 1 ) {
3177                 return false;
3178             }
3179             final Phylogeny t1 = phylogenies_0[ 0 ];
3180             if ( t1.getNumberOfExternalNodes() != 5 ) {
3181                 return false;
3182             }
3183             if ( !t1.isRooted() ) {
3184                 return false;
3185             }
3186             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
3187                 return false;
3188             }
3189             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
3190                 return false;
3191             }
3192             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
3193                 return false;
3194             }
3195             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
3196                 return false;
3197             }
3198             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
3199             if ( parser.getErrorCount() > 0 ) {
3200                 System.out.println( parser.getErrorMessages().toString() );
3201                 return false;
3202             }
3203             if ( phylogenies_1.length != 1 ) {
3204                 return false;
3205             }
3206             final Phylogeny t2 = phylogenies_1[ 0 ];
3207             if ( t2.getNumberOfExternalNodes() != 664 ) {
3208                 return false;
3209             }
3210             if ( !t2.isRooted() ) {
3211                 return false;
3212             }
3213             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
3214                 return false;
3215             }
3216             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
3217                 return false;
3218             }
3219             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3220                 return false;
3221             }
3222             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3223                 return false;
3224             }
3225             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
3226                 return false;
3227             }
3228             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3229                     .equals( "Aquifex" ) ) {
3230                 return false;
3231             }
3232             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
3233             if ( parser.getErrorCount() > 0 ) {
3234                 System.out.println( parser.getErrorMessages().toString() );
3235                 return false;
3236             }
3237             if ( phylogenies_2.length != 1 ) {
3238                 return false;
3239             }
3240             final Phylogeny t3 = phylogenies_2[ 0 ];
3241             if ( t3.getNumberOfExternalNodes() != 184 ) {
3242                 return false;
3243             }
3244             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
3245                 return false;
3246             }
3247             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
3248                 return false;
3249             }
3250             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
3251                 return false;
3252             }
3253             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
3254             if ( parser.getErrorCount() > 0 ) {
3255                 System.out.println( parser.getErrorMessages().toString() );
3256                 return false;
3257             }
3258             if ( phylogenies_3.length != 1 ) {
3259                 return false;
3260             }
3261             final Phylogeny t4 = phylogenies_3[ 0 ];
3262             if ( t4.getNumberOfExternalNodes() != 1 ) {
3263                 return false;
3264             }
3265             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
3266                 return false;
3267             }
3268             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
3269                 return false;
3270             }
3271             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
3272                 return false;
3273             }
3274             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
3275             if ( parser.getErrorCount() > 0 ) {
3276                 System.out.println( parser.getErrorMessages().toString() );
3277                 return false;
3278             }
3279             if ( phylogenies_4.length != 1 ) {
3280                 return false;
3281             }
3282             final Phylogeny t5 = phylogenies_4[ 0 ];
3283             if ( t5.getNumberOfExternalNodes() != 13 ) {
3284                 return false;
3285             }
3286             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
3287                 return false;
3288             }
3289             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
3290                 return false;
3291             }
3292             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
3293                 return false;
3294             }
3295         }
3296         catch ( final Exception e ) {
3297             e.printStackTrace( System.out );
3298             return false;
3299         }
3300         return true;
3301     }
3302
3303     private static boolean testBasicTreeMethods() {
3304         try {
3305             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3306             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
3307             if ( t2.getNumberOfExternalNodes() != 4 ) {
3308                 return false;
3309             }
3310             if ( t2.getHeight() != 8.5 ) {
3311                 return false;
3312             }
3313             if ( !t2.isCompletelyBinary() ) {
3314                 return false;
3315             }
3316             if ( t2.isEmpty() ) {
3317                 return false;
3318             }
3319             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
3320             if ( t3.getNumberOfExternalNodes() != 5 ) {
3321                 return false;
3322             }
3323             if ( t3.getHeight() != 11 ) {
3324                 return false;
3325             }
3326             if ( t3.isCompletelyBinary() ) {
3327                 return false;
3328             }
3329             final PhylogenyNode n = t3.getNode( "ABC" );
3330             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 ];
3331             if ( t4.getNumberOfExternalNodes() != 9 ) {
3332                 return false;
3333             }
3334             if ( t4.getHeight() != 11 ) {
3335                 return false;
3336             }
3337             if ( t4.isCompletelyBinary() ) {
3338                 return false;
3339             }
3340             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)" );
3341             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
3342             if ( t5.getNumberOfExternalNodes() != 8 ) {
3343                 return false;
3344             }
3345             if ( t5.getHeight() != 15 ) {
3346                 return false;
3347             }
3348             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)" );
3349             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
3350             if ( t6.getHeight() != 15 ) {
3351                 return false;
3352             }
3353             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)" );
3354             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
3355             if ( t7.getHeight() != 15 ) {
3356                 return false;
3357             }
3358             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)" );
3359             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
3360             if ( t8.getNumberOfExternalNodes() != 10 ) {
3361                 return false;
3362             }
3363             if ( t8.getHeight() != 15 ) {
3364                 return false;
3365             }
3366             final char[] a9 = new char[] { 'a' };
3367             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
3368             if ( t9.getHeight() != 0 ) {
3369                 return false;
3370             }
3371             final char[] a10 = new char[] { 'a', ':', '6' };
3372             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
3373             if ( t10.getHeight() != 6 ) {
3374                 return false;
3375             }
3376         }
3377         catch ( final Exception e ) {
3378             e.printStackTrace( System.out );
3379             return false;
3380         }
3381         return true;
3382     }
3383
3384     private static boolean testConfidenceAssessor() {
3385         try {
3386             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3387             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3388             final Phylogeny[] ev0 = factory
3389                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3390                              new NHXParser() );
3391             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3392             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3393                 return false;
3394             }
3395             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3396                 return false;
3397             }
3398             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3399             final Phylogeny[] ev1 = factory
3400                     .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)));",
3401                              new NHXParser() );
3402             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3403             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3404                 return false;
3405             }
3406             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3407                 return false;
3408             }
3409             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3410             final Phylogeny[] ev_b = factory
3411                     .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",
3412                              new NHXParser() );
3413             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3414             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3415                 return false;
3416             }
3417             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3418                 return false;
3419             }
3420             //
3421             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3422             final Phylogeny[] ev1x = factory
3423                     .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)));",
3424                              new NHXParser() );
3425             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3426             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3427                 return false;
3428             }
3429             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3430                 return false;
3431             }
3432             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3433             final Phylogeny[] ev_bx = factory
3434                     .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",
3435                              new NHXParser() );
3436             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3437             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3438                 return false;
3439             }
3440             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3441                 return false;
3442             }
3443             final Phylogeny[] t2 = factory
3444                     .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);",
3445                              new NHXParser() );
3446             final Phylogeny[] ev2 = factory
3447                     .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);",
3448                              new NHXParser() );
3449             for( final Phylogeny target : t2 ) {
3450                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3451             }
3452             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3453                                                  new NHXParser() )[ 0 ];
3454             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3455             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3456             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3457                 return false;
3458             }
3459             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3460                 return false;
3461             }
3462             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3463                 return false;
3464             }
3465         }
3466         catch ( final Exception e ) {
3467             e.printStackTrace();
3468             return false;
3469         }
3470         return true;
3471     }
3472
3473     private static boolean testCopyOfNodeData() {
3474         try {
3475             final PhylogenyNode n1 = PhylogenyNode
3476                     .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]" );
3477             final PhylogenyNode n2 = n1.copyNodeData();
3478             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3479                 return false;
3480             }
3481         }
3482         catch ( final Exception e ) {
3483             e.printStackTrace();
3484             return false;
3485         }
3486         return true;
3487     }
3488
3489     private static boolean testCreateBalancedPhylogeny() {
3490         try {
3491             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3492             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3493                 return false;
3494             }
3495             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3496                 return false;
3497             }
3498             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3499             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3500                 return false;
3501             }
3502             if ( p1.getNumberOfExternalNodes() != 100 ) {
3503                 return false;
3504             }
3505         }
3506         catch ( final Exception e ) {
3507             e.printStackTrace();
3508             return false;
3509         }
3510         return true;
3511     }
3512
3513     private static boolean testCreateUriForSeqWeb() {
3514         try {
3515             final PhylogenyNode n = new PhylogenyNode();
3516             n.setName( "tr|B3RJ64" );
3517             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3518                 return false;
3519             }
3520             n.setName( "B0LM41_HUMAN" );
3521             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3522                 return false;
3523             }
3524             n.setName( "NP_001025424" );
3525             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3526                 return false;
3527             }
3528             n.setName( "_NM_001030253-" );
3529             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3530                 return false;
3531             }
3532             n.setName( "XM_002122186" );
3533             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3534                 return false;
3535             }
3536             n.setName( "dgh_AAA34956_gdg" );
3537             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3538                 return false;
3539             }
3540             n.setName( "AAA34956" );
3541             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3542                 return false;
3543             }
3544             n.setName( "GI:394892" );
3545             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3546                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3547                 return false;
3548             }
3549             n.setName( "gi_394892" );
3550             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3551                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3552                 return false;
3553             }
3554             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3555             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3556                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3557                 return false;
3558             }
3559             n.setName( "P12345" );
3560             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3561                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3562                 return false;
3563             }
3564             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3565             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3566                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3567                 return false;
3568             }
3569         }
3570         catch ( final Exception e ) {
3571             e.printStackTrace( System.out );
3572             return false;
3573         }
3574         return true;
3575     }
3576
3577     private static boolean testDataObjects() {
3578         try {
3579             final Confidence s0 = new Confidence();
3580             final Confidence s1 = new Confidence();
3581             if ( !s0.isEqual( s1 ) ) {
3582                 return false;
3583             }
3584             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3585             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3586             if ( s2.isEqual( s1 ) ) {
3587                 return false;
3588             }
3589             if ( !s2.isEqual( s3 ) ) {
3590                 return false;
3591             }
3592             final Confidence s4 = ( Confidence ) s3.copy();
3593             if ( !s4.isEqual( s3 ) ) {
3594                 return false;
3595             }
3596             s3.asSimpleText();
3597             s3.asText();
3598             // Taxonomy
3599             // ----------
3600             final Taxonomy t1 = new Taxonomy();
3601             final Taxonomy t2 = new Taxonomy();
3602             final Taxonomy t3 = new Taxonomy();
3603             final Taxonomy t4 = new Taxonomy();
3604             final Taxonomy t5 = new Taxonomy();
3605             t1.setIdentifier( new Identifier( "ecoli" ) );
3606             t1.setTaxonomyCode( "ECOLI" );
3607             t1.setScientificName( "E. coli" );
3608             t1.setCommonName( "coli" );
3609             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3610             if ( !t1.isEqual( t0 ) ) {
3611                 return false;
3612             }
3613             t2.setIdentifier( new Identifier( "ecoli" ) );
3614             t2.setTaxonomyCode( "OTHER" );
3615             t2.setScientificName( "what" );
3616             t2.setCommonName( "something" );
3617             if ( !t1.isEqual( t2 ) ) {
3618                 return false;
3619             }
3620             t2.setIdentifier( new Identifier( "nemve" ) );
3621             if ( t1.isEqual( t2 ) ) {
3622                 return false;
3623             }
3624             t1.setIdentifier( null );
3625             t3.setTaxonomyCode( "ECOLI" );
3626             t3.setScientificName( "what" );
3627             t3.setCommonName( "something" );
3628             if ( !t1.isEqual( t3 ) ) {
3629                 return false;
3630             }
3631             t1.setIdentifier( null );
3632             t1.setTaxonomyCode( "" );
3633             t4.setScientificName( "E. ColI" );
3634             t4.setCommonName( "something" );
3635             if ( !t1.isEqual( t4 ) ) {
3636                 return false;
3637             }
3638             t4.setScientificName( "B. subtilis" );
3639             t4.setCommonName( "something" );
3640             if ( t1.isEqual( t4 ) ) {
3641                 return false;
3642             }
3643             t1.setIdentifier( null );
3644             t1.setTaxonomyCode( "" );
3645             t1.setScientificName( "" );
3646             t5.setCommonName( "COLI" );
3647             if ( !t1.isEqual( t5 ) ) {
3648                 return false;
3649             }
3650             t5.setCommonName( "vibrio" );
3651             if ( t1.isEqual( t5 ) ) {
3652                 return false;
3653             }
3654             // Identifier
3655             // ----------
3656             final Identifier id0 = new Identifier( "123", "pfam" );
3657             final Identifier id1 = ( Identifier ) id0.copy();
3658             if ( !id1.isEqual( id1 ) ) {
3659                 return false;
3660             }
3661             if ( !id1.isEqual( id0 ) ) {
3662                 return false;
3663             }
3664             if ( !id0.isEqual( id1 ) ) {
3665                 return false;
3666             }
3667             id1.asSimpleText();
3668             id1.asText();
3669             // ProteinDomain
3670             // ---------------
3671             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3672             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3673             if ( !pd1.isEqual( pd1 ) ) {
3674                 return false;
3675             }
3676             if ( !pd1.isEqual( pd0 ) ) {
3677                 return false;
3678             }
3679             pd1.asSimpleText();
3680             pd1.asText();
3681             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3682             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3683             if ( !pd3.isEqual( pd3 ) ) {
3684                 return false;
3685             }
3686             if ( !pd2.isEqual( pd3 ) ) {
3687                 return false;
3688             }
3689             if ( !pd0.isEqual( pd3 ) ) {
3690                 return false;
3691             }
3692             pd3.asSimpleText();
3693             pd3.asText();
3694             // DomainArchitecture
3695             // ------------------
3696             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3697             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3698             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3699             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3700             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3701             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3702             domains0.add( d2 );
3703             domains0.add( d0 );
3704             domains0.add( d3 );
3705             domains0.add( d1 );
3706             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3707             if ( ds0.getNumberOfDomains() != 4 ) {
3708                 return false;
3709             }
3710             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3711             if ( !ds0.isEqual( ds0 ) ) {
3712                 return false;
3713             }
3714             if ( !ds0.isEqual( ds1 ) ) {
3715                 return false;
3716             }
3717             if ( ds1.getNumberOfDomains() != 4 ) {
3718                 return false;
3719             }
3720             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3721             domains1.add( d1 );
3722             domains1.add( d2 );
3723             domains1.add( d4 );
3724             domains1.add( d0 );
3725             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3726             if ( ds0.isEqual( ds2 ) ) {
3727                 return false;
3728             }
3729             ds1.asSimpleText();
3730             ds1.asText();
3731             ds1.toNHX();
3732             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3733             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3734                 System.out.println( ds3.toNHX() );
3735                 return false;
3736             }
3737             if ( ds3.getNumberOfDomains() != 3 ) {
3738                 return false;
3739             }
3740             // Event
3741             // -----
3742             final Event e1 = new Event( Event.EventType.fusion );
3743             if ( e1.isDuplication() ) {
3744                 return false;
3745             }
3746             if ( !e1.isFusion() ) {
3747                 return false;
3748             }
3749             if ( !e1.asText().toString().equals( "fusion" ) ) {
3750                 return false;
3751             }
3752             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3753                 return false;
3754             }
3755             final Event e11 = new Event( Event.EventType.fusion );
3756             if ( !e11.isEqual( e1 ) ) {
3757                 return false;
3758             }
3759             if ( !e11.toNHX().toString().equals( "" ) ) {
3760                 return false;
3761             }
3762             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3763             if ( e2.isDuplication() ) {
3764                 return false;
3765             }
3766             if ( !e2.isSpeciationOrDuplication() ) {
3767                 return false;
3768             }
3769             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3770                 return false;
3771             }
3772             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3773                 return false;
3774             }
3775             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3776                 return false;
3777             }
3778             if ( e11.isEqual( e2 ) ) {
3779                 return false;
3780             }
3781             final Event e2c = ( Event ) e2.copy();
3782             if ( !e2c.isEqual( e2 ) ) {
3783                 return false;
3784             }
3785             Event e3 = new Event( 1, 2, 3 );
3786             if ( e3.isDuplication() ) {
3787                 return false;
3788             }
3789             if ( e3.isSpeciation() ) {
3790                 return false;
3791             }
3792             if ( e3.isGeneLoss() ) {
3793                 return false;
3794             }
3795             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3796                 return false;
3797             }
3798             final Event e3c = ( Event ) e3.copy();
3799             final Event e3cc = ( Event ) e3c.copy();
3800             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3801                 return false;
3802             }
3803             e3 = null;
3804             if ( !e3c.isEqual( e3cc ) ) {
3805                 return false;
3806             }
3807             Event e4 = new Event( 1, 2, 3 );
3808             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3809                 return false;
3810             }
3811             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3812                 return false;
3813             }
3814             final Event e4c = ( Event ) e4.copy();
3815             e4 = null;
3816             final Event e4cc = ( Event ) e4c.copy();
3817             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3818                 return false;
3819             }
3820             if ( !e4c.isEqual( e4cc ) ) {
3821                 return false;
3822             }
3823             final Event e5 = new Event();
3824             if ( !e5.isUnassigned() ) {
3825                 return false;
3826             }
3827             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3828                 return false;
3829             }
3830             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3831                 return false;
3832             }
3833             final Event e6 = new Event( 1, 0, 0 );
3834             if ( !e6.asText().toString().equals( "duplication" ) ) {
3835                 return false;
3836             }
3837             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3838                 return false;
3839             }
3840             final Event e7 = new Event( 0, 1, 0 );
3841             if ( !e7.asText().toString().equals( "speciation" ) ) {
3842                 return false;
3843             }
3844             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3845                 return false;
3846             }
3847             final Event e8 = new Event( 0, 0, 1 );
3848             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3849                 return false;
3850             }
3851             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3852                 return false;
3853             }
3854         }
3855         catch ( final Exception e ) {
3856             e.printStackTrace( System.out );
3857             return false;
3858         }
3859         return true;
3860     }
3861
3862     private static boolean testDeletionOfExternalNodes() {
3863         try {
3864             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3865             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3866             final PhylogenyWriter w = new PhylogenyWriter();
3867             if ( t0.isEmpty() ) {
3868                 return false;
3869             }
3870             if ( t0.getNumberOfExternalNodes() != 1 ) {
3871                 return false;
3872             }
3873             t0.deleteSubtree( t0.getNode( "A" ), false );
3874             if ( t0.getNumberOfExternalNodes() != 0 ) {
3875                 return false;
3876             }
3877             if ( !t0.isEmpty() ) {
3878                 return false;
3879             }
3880             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3881             if ( t1.getNumberOfExternalNodes() != 2 ) {
3882                 return false;
3883             }
3884             t1.deleteSubtree( t1.getNode( "A" ), false );
3885             if ( t1.getNumberOfExternalNodes() != 1 ) {
3886                 return false;
3887             }
3888             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3889                 return false;
3890             }
3891             t1.deleteSubtree( t1.getNode( "B" ), false );
3892             if ( t1.getNumberOfExternalNodes() != 1 ) {
3893                 return false;
3894             }
3895             t1.deleteSubtree( t1.getNode( "r" ), false );
3896             if ( !t1.isEmpty() ) {
3897                 return false;
3898             }
3899             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3900             if ( t2.getNumberOfExternalNodes() != 3 ) {
3901                 return false;
3902             }
3903             t2.deleteSubtree( t2.getNode( "B" ), false );
3904             if ( t2.getNumberOfExternalNodes() != 2 ) {
3905                 return false;
3906             }
3907             t2.toNewHampshireX();
3908             PhylogenyNode n = t2.getNode( "A" );
3909             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3910                 return false;
3911             }
3912             t2.deleteSubtree( t2.getNode( "A" ), false );
3913             if ( t2.getNumberOfExternalNodes() != 2 ) {
3914                 return false;
3915             }
3916             t2.deleteSubtree( t2.getNode( "C" ), true );
3917             if ( t2.getNumberOfExternalNodes() != 1 ) {
3918                 return false;
3919             }
3920             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3921             if ( t3.getNumberOfExternalNodes() != 4 ) {
3922                 return false;
3923             }
3924             t3.deleteSubtree( t3.getNode( "B" ), true );
3925             if ( t3.getNumberOfExternalNodes() != 3 ) {
3926                 return false;
3927             }
3928             n = t3.getNode( "A" );
3929             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3930                 return false;
3931             }
3932             n = n.getNextExternalNode();
3933             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3934                 return false;
3935             }
3936             t3.deleteSubtree( t3.getNode( "A" ), true );
3937             if ( t3.getNumberOfExternalNodes() != 2 ) {
3938                 return false;
3939             }
3940             n = t3.getNode( "C" );
3941             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3942                 return false;
3943             }
3944             t3.deleteSubtree( t3.getNode( "C" ), true );
3945             if ( t3.getNumberOfExternalNodes() != 1 ) {
3946                 return false;
3947             }
3948             t3.deleteSubtree( t3.getNode( "D" ), true );
3949             if ( t3.getNumberOfExternalNodes() != 0 ) {
3950                 return false;
3951             }
3952             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3953             if ( t4.getNumberOfExternalNodes() != 6 ) {
3954                 return false;
3955             }
3956             t4.deleteSubtree( t4.getNode( "B2" ), true );
3957             if ( t4.getNumberOfExternalNodes() != 5 ) {
3958                 return false;
3959             }
3960             String s = w.toNewHampshire( t4, true ).toString();
3961             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3962                 return false;
3963             }
3964             t4.deleteSubtree( t4.getNode( "B11" ), true );
3965             if ( t4.getNumberOfExternalNodes() != 4 ) {
3966                 return false;
3967             }
3968             t4.deleteSubtree( t4.getNode( "C" ), true );
3969             if ( t4.getNumberOfExternalNodes() != 3 ) {
3970                 return false;
3971             }
3972             n = t4.getNode( "A" );
3973             n = n.getNextExternalNode();
3974             if ( !n.getName().equals( "B12" ) ) {
3975                 return false;
3976             }
3977             n = n.getNextExternalNode();
3978             if ( !n.getName().equals( "D" ) ) {
3979                 return false;
3980             }
3981             s = w.toNewHampshire( t4, true ).toString();
3982             if ( !s.equals( "((A,B12),D);" ) ) {
3983                 return false;
3984             }
3985             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3986             t5.deleteSubtree( t5.getNode( "A" ), true );
3987             if ( t5.getNumberOfExternalNodes() != 5 ) {
3988                 return false;
3989             }
3990             s = w.toNewHampshire( t5, true ).toString();
3991             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3992                 return false;
3993             }
3994             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3995             t6.deleteSubtree( t6.getNode( "B11" ), true );
3996             if ( t6.getNumberOfExternalNodes() != 5 ) {
3997                 return false;
3998             }
3999             s = w.toNewHampshire( t6, false ).toString();
4000             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
4001                 return false;
4002             }
4003             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4004             t7.deleteSubtree( t7.getNode( "B12" ), true );
4005             if ( t7.getNumberOfExternalNodes() != 5 ) {
4006                 return false;
4007             }
4008             s = w.toNewHampshire( t7, true ).toString();
4009             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
4010                 return false;
4011             }
4012             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4013             t8.deleteSubtree( t8.getNode( "B2" ), true );
4014             if ( t8.getNumberOfExternalNodes() != 5 ) {
4015                 return false;
4016             }
4017             s = w.toNewHampshire( t8, false ).toString();
4018             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
4019                 return false;
4020             }
4021             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4022             t9.deleteSubtree( t9.getNode( "C" ), true );
4023             if ( t9.getNumberOfExternalNodes() != 5 ) {
4024                 return false;
4025             }
4026             s = w.toNewHampshire( t9, true ).toString();
4027             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
4028                 return false;
4029             }
4030             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4031             t10.deleteSubtree( t10.getNode( "D" ), true );
4032             if ( t10.getNumberOfExternalNodes() != 5 ) {
4033                 return false;
4034             }
4035             s = w.toNewHampshire( t10, true ).toString();
4036             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
4037                 return false;
4038             }
4039             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
4040             t11.deleteSubtree( t11.getNode( "A" ), true );
4041             if ( t11.getNumberOfExternalNodes() != 2 ) {
4042                 return false;
4043             }
4044             s = w.toNewHampshire( t11, true ).toString();
4045             if ( !s.equals( "(B,C);" ) ) {
4046                 return false;
4047             }
4048             t11.deleteSubtree( t11.getNode( "C" ), true );
4049             if ( t11.getNumberOfExternalNodes() != 1 ) {
4050                 return false;
4051             }
4052             s = w.toNewHampshire( t11, false ).toString();
4053             if ( !s.equals( "B;" ) ) {
4054                 return false;
4055             }
4056             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
4057             t12.deleteSubtree( t12.getNode( "B2" ), true );
4058             if ( t12.getNumberOfExternalNodes() != 8 ) {
4059                 return false;
4060             }
4061             s = w.toNewHampshire( t12, true ).toString();
4062             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
4063                 return false;
4064             }
4065             t12.deleteSubtree( t12.getNode( "B3" ), true );
4066             if ( t12.getNumberOfExternalNodes() != 7 ) {
4067                 return false;
4068             }
4069             s = w.toNewHampshire( t12, true ).toString();
4070             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
4071                 return false;
4072             }
4073             t12.deleteSubtree( t12.getNode( "C3" ), true );
4074             if ( t12.getNumberOfExternalNodes() != 6 ) {
4075                 return false;
4076             }
4077             s = w.toNewHampshire( t12, true ).toString();
4078             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
4079                 return false;
4080             }
4081             t12.deleteSubtree( t12.getNode( "A1" ), true );
4082             if ( t12.getNumberOfExternalNodes() != 5 ) {
4083                 return false;
4084             }
4085             s = w.toNewHampshire( t12, true ).toString();
4086             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
4087                 return false;
4088             }
4089             t12.deleteSubtree( t12.getNode( "B1" ), true );
4090             if ( t12.getNumberOfExternalNodes() != 4 ) {
4091                 return false;
4092             }
4093             s = w.toNewHampshire( t12, true ).toString();
4094             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
4095                 return false;
4096             }
4097             t12.deleteSubtree( t12.getNode( "A3" ), true );
4098             if ( t12.getNumberOfExternalNodes() != 3 ) {
4099                 return false;
4100             }
4101             s = w.toNewHampshire( t12, true ).toString();
4102             if ( !s.equals( "(A2,(C1,C2));" ) ) {
4103                 return false;
4104             }
4105             t12.deleteSubtree( t12.getNode( "A2" ), true );
4106             if ( t12.getNumberOfExternalNodes() != 2 ) {
4107                 return false;
4108             }
4109             s = w.toNewHampshire( t12, true ).toString();
4110             if ( !s.equals( "(C1,C2);" ) ) {
4111                 return false;
4112             }
4113             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
4114             t13.deleteSubtree( t13.getNode( "D" ), true );
4115             if ( t13.getNumberOfExternalNodes() != 4 ) {
4116                 return false;
4117             }
4118             s = w.toNewHampshire( t13, true ).toString();
4119             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
4120                 return false;
4121             }
4122             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
4123             t14.deleteSubtree( t14.getNode( "E" ), true );
4124             if ( t14.getNumberOfExternalNodes() != 5 ) {
4125                 return false;
4126             }
4127             s = w.toNewHampshire( t14, true ).toString();
4128             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
4129                 return false;
4130             }
4131             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
4132             t15.deleteSubtree( t15.getNode( "B2" ), true );
4133             if ( t15.getNumberOfExternalNodes() != 11 ) {
4134                 return false;
4135             }
4136             t15.deleteSubtree( t15.getNode( "B1" ), true );
4137             if ( t15.getNumberOfExternalNodes() != 10 ) {
4138                 return false;
4139             }
4140             t15.deleteSubtree( t15.getNode( "B3" ), true );
4141             if ( t15.getNumberOfExternalNodes() != 9 ) {
4142                 return false;
4143             }
4144             t15.deleteSubtree( t15.getNode( "B4" ), true );
4145             if ( t15.getNumberOfExternalNodes() != 8 ) {
4146                 return false;
4147             }
4148             t15.deleteSubtree( t15.getNode( "A1" ), true );
4149             if ( t15.getNumberOfExternalNodes() != 7 ) {
4150                 return false;
4151             }
4152             t15.deleteSubtree( t15.getNode( "C4" ), true );
4153             if ( t15.getNumberOfExternalNodes() != 6 ) {
4154                 return false;
4155             }
4156         }
4157         catch ( final Exception e ) {
4158             e.printStackTrace( System.out );
4159             return false;
4160         }
4161         return true;
4162     }
4163
4164     private static boolean testDescriptiveStatistics() {
4165         try {
4166             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
4167             dss1.addValue( 82 );
4168             dss1.addValue( 78 );
4169             dss1.addValue( 70 );
4170             dss1.addValue( 58 );
4171             dss1.addValue( 42 );
4172             if ( dss1.getN() != 5 ) {
4173                 return false;
4174             }
4175             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
4176                 return false;
4177             }
4178             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
4179                 return false;
4180             }
4181             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
4182                 return false;
4183             }
4184             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
4185                 return false;
4186             }
4187             if ( !Test.isEqual( dss1.median(), 70 ) ) {
4188                 return false;
4189             }
4190             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
4191                 return false;
4192             }
4193             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
4194                 return false;
4195             }
4196             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
4197                 return false;
4198             }
4199             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
4200                 return false;
4201             }
4202             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
4203                 return false;
4204             }
4205             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
4206                 return false;
4207             }
4208             dss1.addValue( 123 );
4209             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
4210                 return false;
4211             }
4212             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
4213                 return false;
4214             }
4215             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
4216                 return false;
4217             }
4218             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
4219             dss2.addValue( -1.85 );
4220             dss2.addValue( 57.5 );
4221             dss2.addValue( 92.78 );
4222             dss2.addValue( 57.78 );
4223             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
4224                 return false;
4225             }
4226             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
4227                 return false;
4228             }
4229             final double[] a = dss2.getDataAsDoubleArray();
4230             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
4231                 return false;
4232             }
4233             dss2.addValue( -100 );
4234             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
4235                 return false;
4236             }
4237             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
4238                 return false;
4239             }
4240             final double[] ds = new double[ 14 ];
4241             ds[ 0 ] = 34;
4242             ds[ 1 ] = 23;
4243             ds[ 2 ] = 1;
4244             ds[ 3 ] = 32;
4245             ds[ 4 ] = 11;
4246             ds[ 5 ] = 2;
4247             ds[ 6 ] = 12;
4248             ds[ 7 ] = 33;
4249             ds[ 8 ] = 13;
4250             ds[ 9 ] = 22;
4251             ds[ 10 ] = 21;
4252             ds[ 11 ] = 35;
4253             ds[ 12 ] = 24;
4254             ds[ 13 ] = 31;
4255             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
4256             if ( bins.length != 4 ) {
4257                 return false;
4258             }
4259             if ( bins[ 0 ] != 2 ) {
4260                 return false;
4261             }
4262             if ( bins[ 1 ] != 3 ) {
4263                 return false;
4264             }
4265             if ( bins[ 2 ] != 4 ) {
4266                 return false;
4267             }
4268             if ( bins[ 3 ] != 5 ) {
4269                 return false;
4270             }
4271             final double[] ds1 = new double[ 9 ];
4272             ds1[ 0 ] = 10.0;
4273             ds1[ 1 ] = 19.0;
4274             ds1[ 2 ] = 9.999;
4275             ds1[ 3 ] = 0.0;
4276             ds1[ 4 ] = 39.9;
4277             ds1[ 5 ] = 39.999;
4278             ds1[ 6 ] = 30.0;
4279             ds1[ 7 ] = 19.999;
4280             ds1[ 8 ] = 30.1;
4281             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
4282             if ( bins1.length != 4 ) {
4283                 return false;
4284             }
4285             if ( bins1[ 0 ] != 2 ) {
4286                 return false;
4287             }
4288             if ( bins1[ 1 ] != 3 ) {
4289                 return false;
4290             }
4291             if ( bins1[ 2 ] != 0 ) {
4292                 return false;
4293             }
4294             if ( bins1[ 3 ] != 4 ) {
4295                 return false;
4296             }
4297             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
4298             if ( bins1_1.length != 3 ) {
4299                 return false;
4300             }
4301             if ( bins1_1[ 0 ] != 3 ) {
4302                 return false;
4303             }
4304             if ( bins1_1[ 1 ] != 2 ) {
4305                 return false;
4306             }
4307             if ( bins1_1[ 2 ] != 4 ) {
4308                 return false;
4309             }
4310             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
4311             if ( bins1_2.length != 3 ) {
4312                 return false;
4313             }
4314             if ( bins1_2[ 0 ] != 2 ) {
4315                 return false;
4316             }
4317             if ( bins1_2[ 1 ] != 2 ) {
4318                 return false;
4319             }
4320             if ( bins1_2[ 2 ] != 2 ) {
4321                 return false;
4322             }
4323             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
4324             dss3.addValue( 1 );
4325             dss3.addValue( 1 );
4326             dss3.addValue( 1 );
4327             dss3.addValue( 2 );
4328             dss3.addValue( 3 );
4329             dss3.addValue( 4 );
4330             dss3.addValue( 5 );
4331             dss3.addValue( 5 );
4332             dss3.addValue( 5 );
4333             dss3.addValue( 6 );
4334             dss3.addValue( 7 );
4335             dss3.addValue( 8 );
4336             dss3.addValue( 9 );
4337             dss3.addValue( 10 );
4338             dss3.addValue( 10 );
4339             dss3.addValue( 10 );
4340             final AsciiHistogram histo = new AsciiHistogram( dss3 );
4341             histo.toStringBuffer( 10, '=', 40, 5 );
4342             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
4343         }
4344         catch ( final Exception e ) {
4345             e.printStackTrace( System.out );
4346             return false;
4347         }
4348         return true;
4349     }
4350
4351     private static boolean testDir( final String file ) {
4352         try {
4353             final File f = new File( file );
4354             if ( !f.exists() ) {
4355                 return false;
4356             }
4357             if ( !f.isDirectory() ) {
4358                 return false;
4359             }
4360             if ( !f.canRead() ) {
4361                 return false;
4362             }
4363         }
4364         catch ( final Exception e ) {
4365             return false;
4366         }
4367         return true;
4368     }
4369
4370     private static boolean testEbiEntryRetrieval() {
4371         try {
4372             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
4373             if ( !entry.getAccession().equals( "AAK41263" ) ) {
4374                 System.out.println( entry.getAccession() );
4375                 return false;
4376             }
4377             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
4378                 System.out.println( entry.getTaxonomyScientificName() );
4379                 return false;
4380             }
4381             if ( !entry.getSequenceName()
4382                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4383                 System.out.println( entry.getSequenceName() );
4384                 return false;
4385             }
4386             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4387                 System.out.println( entry.getGeneName() );
4388                 return false;
4389             }
4390             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4391                 System.out.println( entry.getTaxonomyIdentifier() );
4392                 return false;
4393             }
4394             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4395                 System.out.println( entry.getAnnotations().first().getRefValue() );
4396                 return false;
4397             }
4398             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4399                 System.out.println( entry.getAnnotations().first().getRefSource() );
4400                 return false;
4401             }
4402             if ( entry.getCrossReferences().size() < 1 ) {
4403                 return false;
4404             }
4405             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4406             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4407                 return false;
4408             }
4409             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4410                 System.out.println( entry1.getTaxonomyScientificName() );
4411                 return false;
4412             }
4413             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4414                 System.out.println( entry1.getSequenceName() );
4415                 return false;
4416             }
4417             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4418                 System.out.println( entry1.getTaxonomyIdentifier() );
4419                 return false;
4420             }
4421             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4422                 System.out.println( entry1.getGeneName() );
4423                 return false;
4424             }
4425             if ( entry1.getCrossReferences().size() < 1 ) {
4426                 return false;
4427             }
4428             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4429             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4430                 return false;
4431             }
4432             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4433                 System.out.println( entry2.getTaxonomyScientificName() );
4434                 return false;
4435             }
4436             if ( !entry2.getSequenceName()
4437                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4438                 System.out.println( entry2.getSequenceName() );
4439                 return false;
4440             }
4441             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4442                 System.out.println( entry2.getTaxonomyIdentifier() );
4443                 return false;
4444             }
4445             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4446                 System.out.println( entry2.getGeneName() );
4447                 return false;
4448             }
4449             if ( entry2.getCrossReferences().size() < 1 ) {
4450                 return false;
4451             }
4452             if ( !entry2.getChromosome().equals( "20" ) ) {
4453                 return false;
4454             }
4455             if ( !entry2.getMap().equals( "20q11.22" ) ) {
4456                 return false;
4457             }
4458             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4459             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4460                 return false;
4461             }
4462             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4463                 System.out.println( entry3.getTaxonomyScientificName() );
4464                 return false;
4465             }
4466             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4467                 System.out.println( entry3.getSequenceName() );
4468                 return false;
4469             }
4470             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4471                 System.out.println( entry3.getTaxonomyIdentifier() );
4472                 return false;
4473             }
4474             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4475                 System.out.println( entry3.getSequenceSymbol() );
4476                 return false;
4477             }
4478             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4479                 return false;
4480             }
4481             if ( entry3.getCrossReferences().size() < 1 ) {
4482                 return false;
4483             }
4484             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4485             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4486                 return false;
4487             }
4488             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4489                 System.out.println( entry4.getTaxonomyScientificName() );
4490                 return false;
4491             }
4492             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4493                 System.out.println( entry4.getSequenceName() );
4494                 return false;
4495             }
4496             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4497                 System.out.println( entry4.getTaxonomyIdentifier() );
4498                 return false;
4499             }
4500             if ( !entry4.getGeneName().equals( "ras" ) ) {
4501                 System.out.println( entry4.getGeneName() );
4502                 return false;
4503             }
4504             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4505             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4506                 return false;
4507             }
4508             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4509                 System.out.println( entry5.getTaxonomyScientificName() );
4510                 return false;
4511             }
4512             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4513                 System.out.println( entry5.getSequenceName() );
4514                 return false;
4515             }
4516             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4517                 System.out.println( entry5.getTaxonomyIdentifier() );
4518                 return false;
4519             }
4520             final SequenceDatabaseEntry entry6 = SequenceDbWsTools.obtainEntry( "M30539" );
4521             if ( !entry6.getAccession().equals( "M30539" ) ) {
4522                 return false;
4523             }
4524             if ( !entry6.getGeneName().equals( "ras" ) ) {
4525                 return false;
4526             }
4527             if ( !entry6.getSequenceName().equals( "Human SK2 c-Ha-ras-1 oncogene-encoded protein gene, exon 1" ) ) {
4528                 return false;
4529             }
4530             if ( !entry6.getTaxonomyIdentifier().equals( "9606" ) ) {
4531                 return false;
4532             }
4533             if ( !entry6.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4534                 return false;
4535             }
4536             if ( entry6.getCrossReferences().size() < 1 ) {
4537                 return false;
4538             }
4539         }
4540         catch ( final IOException e ) {
4541             System.out.println();
4542             System.out.println( "the following might be due to absence internet connection:" );
4543             e.printStackTrace( System.out );
4544             return true;
4545         }
4546         catch ( final Exception e ) {
4547             e.printStackTrace();
4548             return false;
4549         }
4550         return true;
4551     }
4552
4553     private static boolean testExternalNodeRelatedMethods() {
4554         try {
4555             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4556             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4557             PhylogenyNode n = t1.getNode( "A" );
4558             n = n.getNextExternalNode();
4559             if ( !n.getName().equals( "B" ) ) {
4560                 return false;
4561             }
4562             n = n.getNextExternalNode();
4563             if ( !n.getName().equals( "C" ) ) {
4564                 return false;
4565             }
4566             n = n.getNextExternalNode();
4567             if ( !n.getName().equals( "D" ) ) {
4568                 return false;
4569             }
4570             n = t1.getNode( "B" );
4571             while ( !n.isLastExternalNode() ) {
4572                 n = n.getNextExternalNode();
4573             }
4574             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4575             n = t2.getNode( "A" );
4576             n = n.getNextExternalNode();
4577             if ( !n.getName().equals( "B" ) ) {
4578                 return false;
4579             }
4580             n = n.getNextExternalNode();
4581             if ( !n.getName().equals( "C" ) ) {
4582                 return false;
4583             }
4584             n = n.getNextExternalNode();
4585             if ( !n.getName().equals( "D" ) ) {
4586                 return false;
4587             }
4588             n = t2.getNode( "B" );
4589             while ( !n.isLastExternalNode() ) {
4590                 n = n.getNextExternalNode();
4591             }
4592             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4593             n = t3.getNode( "A" );
4594             n = n.getNextExternalNode();
4595             if ( !n.getName().equals( "B" ) ) {
4596                 return false;
4597             }
4598             n = n.getNextExternalNode();
4599             if ( !n.getName().equals( "C" ) ) {
4600                 return false;
4601             }
4602             n = n.getNextExternalNode();
4603             if ( !n.getName().equals( "D" ) ) {
4604                 return false;
4605             }
4606             n = n.getNextExternalNode();
4607             if ( !n.getName().equals( "E" ) ) {
4608                 return false;
4609             }
4610             n = n.getNextExternalNode();
4611             if ( !n.getName().equals( "F" ) ) {
4612                 return false;
4613             }
4614             n = n.getNextExternalNode();
4615             if ( !n.getName().equals( "G" ) ) {
4616                 return false;
4617             }
4618             n = n.getNextExternalNode();
4619             if ( !n.getName().equals( "H" ) ) {
4620                 return false;
4621             }
4622             n = t3.getNode( "B" );
4623             while ( !n.isLastExternalNode() ) {
4624                 n = n.getNextExternalNode();
4625             }
4626             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4627             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4628                 final PhylogenyNode node = iter.next();
4629             }
4630             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4631             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4632                 final PhylogenyNode node = iter.next();
4633             }
4634             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4635             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4636             if ( !iter.next().getName().equals( "A" ) ) {
4637                 return false;
4638             }
4639             if ( !iter.next().getName().equals( "B" ) ) {
4640                 return false;
4641             }
4642             if ( !iter.next().getName().equals( "C" ) ) {
4643                 return false;
4644             }
4645             if ( !iter.next().getName().equals( "D" ) ) {
4646                 return false;
4647             }
4648             if ( !iter.next().getName().equals( "E" ) ) {
4649                 return false;
4650             }
4651             if ( !iter.next().getName().equals( "F" ) ) {
4652                 return false;
4653             }
4654             if ( iter.hasNext() ) {
4655                 return false;
4656             }
4657         }
4658         catch ( final Exception e ) {
4659             e.printStackTrace( System.out );
4660             return false;
4661         }
4662         return true;
4663     }
4664
4665     private static boolean testExtractSNFromNodeName() {
4666         try {
4667             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4668                 return false;
4669             }
4670             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4671                 return false;
4672             }
4673             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4674                 return false;
4675             }
4676             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4677                     .equals( "Mus musculus musculus" ) ) {
4678                 return false;
4679             }
4680             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4681                     .equals( "Mus musculus musculus" ) ) {
4682                 return false;
4683             }
4684             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4685                     .equals( "Mus musculus musculus" ) ) {
4686                 return false;
4687             }
4688             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4689                     .equals( "Mus musculus musculus" ) ) {
4690                 return false;
4691             }
4692             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4693                 return false;
4694             }
4695             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4696                     .equals( "Mus musculus musculus" ) ) {
4697                 return false;
4698             }
4699             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4700                     .equals( "Mus musculus musculus" ) ) {
4701                 return false;
4702             }
4703             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4704                 return false;
4705             }
4706             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4707                 return false;
4708             }
4709             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4710                 return false;
4711             }
4712             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4713                 return false;
4714             }
4715             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4716                     .equals( "Mus musculus musculus" ) ) {
4717                 return false;
4718             }
4719             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4720                 return false;
4721             }
4722             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4723                 return false;
4724             }
4725             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4726                 return false;
4727             }
4728             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4729                 return false;
4730             }
4731             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4732                 return false;
4733             }
4734             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4735                 return false;
4736             }
4737             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4738                 return false;
4739             }
4740             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4741                 return false;
4742             }
4743             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4744                     .equals( "Mus musculus" ) ) {
4745                 return false;
4746             }
4747             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4748                     .equals( "Mus musculus" ) ) {
4749                 return false;
4750             }
4751             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4752                 return false;
4753             }
4754             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4755                     .equals( "Mus musculus musculus" ) ) {
4756                 return false;
4757             }
4758             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4759                     .equals( "Mus musculus musculus" ) ) {
4760                 return false;
4761             }
4762             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4763                     .equals( "Mus musculus musculus" ) ) {
4764                 return false;
4765             }
4766             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4767                 return false;
4768             }
4769             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4770                     .equals( "Pilostyles mexicana" ) ) {
4771                 return false;
4772             }
4773             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4774                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4775                 return false;
4776             }
4777             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4778                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4779                 return false;
4780             }
4781             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4782                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4783                 return false;
4784             }
4785             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4786                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4787                 return false;
4788             }
4789             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4790                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4791                 return false;
4792             }
4793             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4794                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4795                 return false;
4796             }
4797             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4798                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4799                 return false;
4800             }
4801             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4802                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4803                 return false;
4804             }
4805             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4806                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4807                 return false;
4808             }
4809             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4810                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4811                 return false;
4812             }
4813             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4814                     .equals( "Escherichia coli (strain K12)" ) ) {
4815                 return false;
4816             }
4817             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4818                     .equals( "Escherichia coli (strain K12)" ) ) {
4819                 return false;
4820             }
4821             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4822                     .equals( "Escherichia coli (str. K12)" ) ) {
4823                 return false;
4824             }
4825             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4826                     .equals( "Escherichia coli (str. K12)" ) ) {
4827                 return false;
4828             }
4829             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4830                     .equals( "Escherichia coli (str. K12)" ) ) {
4831                 return false;
4832             }
4833             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4834                     .equals( "Escherichia coli (var. K12)" ) ) {
4835                 return false;
4836             }
4837             if ( !ParserUtils.extractScientificNameFromNodeName( "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" )
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" )
4847                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4848                 return false;
4849             }
4850             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4851                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4852                 return false;
4853             }
4854             if ( !ParserUtils
4855                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4856                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4857                 return false;
4858             }
4859             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4860                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4861                 return false;
4862             }
4863             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4864                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4865                 return false;
4866             }
4867             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4868                 return false;
4869             }
4870             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4871                 return false;
4872             }
4873             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4874                 return false;
4875             }
4876             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4877                     .equals( "Macrocera sp." ) ) {
4878                 return false;
4879             }
4880             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4881                 return false;
4882             }
4883             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4884                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4885                 return false;
4886             }
4887             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4888                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4889                 return false;
4890             }
4891             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4892                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4893                 return false;
4894             }
4895             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4896                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4897                 return false;
4898             }
4899         }
4900         catch ( final Exception e ) {
4901             e.printStackTrace( System.out );
4902             return false;
4903         }
4904         return true;
4905     }
4906
4907     private static boolean testExtractTaxonomyDataFromNodeName() {
4908         try {
4909             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
4910             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4911                 return false;
4912             }
4913             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
4914             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4915                 return false;
4916             }
4917             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
4918             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4919                 return false;
4920             }
4921             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
4922             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4923                 return false;
4924             }
4925             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
4926             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4927                 return false;
4928             }
4929             n = new PhylogenyNode( "HNRPR_HUMAN" );
4930             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4931                 return false;
4932             }
4933             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
4934             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4935                 return false;
4936             }
4937         }
4938         catch ( final Exception e ) {
4939             e.printStackTrace( System.out );
4940             return false;
4941         }
4942         return true;
4943     }
4944
4945     private static boolean testExtractTaxonomyCodeFromNodeName() {
4946         try {
4947             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4948                 return false;
4949             }
4950             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4951                     .equals( "SOYBN" ) ) {
4952                 return false;
4953             }
4954             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4955                     .equals( "ARATH" ) ) {
4956                 return false;
4957             }
4958             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4959                     .equals( "ARATH" ) ) {
4960                 return false;
4961             }
4962             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4963                 return false;
4964             }
4965             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4966                 return false;
4967             }
4968             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4969                 return false;
4970             }
4971             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4972                     .equals( "SOYBN" ) ) {
4973                 return false;
4974             }
4975             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4976                     .equals( "SOYBN" ) ) {
4977                 return false;
4978             }
4979             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4980                     .equals( "SOYBN" ) ) {
4981                 return false;
4982             }
4983             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4984                     .equals( "SOYBN" ) ) {
4985                 return false;
4986             }
4987             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4988                     .equals( "SOYBN" ) ) {
4989                 return false;
4990             }
4991             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4992                     .equals( "SOYBN" ) ) {
4993                 return false;
4994             }
4995             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4996                     .equals( "SOYBN" ) ) {
4997                 return false;
4998             }
4999             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
5000                     .equals( "SOYBN" ) ) {
5001                 return false;
5002             }
5003             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
5004                 return false;
5005             }
5006             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
5007                     .equals( "SOYBN" ) ) {
5008                 return false;
5009             }
5010             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
5011                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
5012                 return false;
5013             }
5014             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
5015                     .equals( "9YX45" ) ) {
5016                 return false;
5017             }
5018             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
5019                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5020                                                                .equals( "MOUSE" ) ) {
5021                 return false;
5022             }
5023             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
5024                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5025                                                                .equals( "MOUSE" ) ) {
5026                 return false;
5027             }
5028             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
5029                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5030                                                                .equals( "MOUSE" ) ) {
5031                 return false;
5032             }
5033             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
5034                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5035                 return false;
5036             }
5037             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
5038                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5039                 return false;
5040             }
5041             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5042                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
5043                 return false;
5044             }
5045             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5046                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
5047                 return false;
5048             }
5049             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
5050                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
5051                 return false;
5052             }
5053             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
5054                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5055                 return false;
5056             }
5057             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
5058                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5059                 return false;
5060             }
5061             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5062                     .equals( "RAT" ) ) {
5063                 return false;
5064             }
5065             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5066                     .equals( "PIG" ) ) {
5067                 return false;
5068             }
5069             if ( !ParserUtils
5070                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5071                     .equals( "MOUSE" ) ) {
5072                 return false;
5073             }
5074             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5075                     .equals( "MOUSE" ) ) {
5076                 return false;
5077             }
5078             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5079                 return false;
5080             }
5081         }
5082         catch ( final Exception e ) {
5083             e.printStackTrace( System.out );
5084             return false;
5085         }
5086         return true;
5087     }
5088
5089     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
5090         try {
5091             PhylogenyNode n = new PhylogenyNode();
5092             n.setName( "tr|B3RJ64" );
5093             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5094                 return false;
5095             }
5096             n.setName( "tr.B3RJ64" );
5097             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5098                 return false;
5099             }
5100             n.setName( "tr=B3RJ64" );
5101             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5102                 return false;
5103             }
5104             n.setName( "tr-B3RJ64" );
5105             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5106                 return false;
5107             }
5108             n.setName( "tr/B3RJ64" );
5109             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5110                 return false;
5111             }
5112             n.setName( "tr\\B3RJ64" );
5113             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5114                 return false;
5115             }
5116             n.setName( "tr_B3RJ64" );
5117             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5118                 return false;
5119             }
5120             n.setName( " tr|B3RJ64 " );
5121             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5122                 return false;
5123             }
5124             n.setName( "-tr|B3RJ64-" );
5125             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5126                 return false;
5127             }
5128             n.setName( "-tr=B3RJ64-" );
5129             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5130                 return false;
5131             }
5132             n.setName( "_tr=B3RJ64_" );
5133             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5134                 return false;
5135             }
5136             n.setName( " tr_tr|B3RJ64_sp|123 " );
5137             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5138                 return false;
5139             }
5140             n.setName( "B3RJ64" );
5141             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5142                 return false;
5143             }
5144             n.setName( "sp|B3RJ64" );
5145             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5146                 return false;
5147             }
5148             n.setName( "sp|B3RJ64C" );
5149             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5150                 return false;
5151             }
5152             n.setName( "sp B3RJ64" );
5153             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5154                 return false;
5155             }
5156             n.setName( "sp|B3RJ6X" );
5157             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5158                 return false;
5159             }
5160             n.setName( "sp|B3RJ6" );
5161             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5162                 return false;
5163             }
5164             n.setName( "K1PYK7_CRAGI" );
5165             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5166                 return false;
5167             }
5168             n.setName( "K1PYK7_PEA" );
5169             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
5170                 return false;
5171             }
5172             n.setName( "K1PYK7_RAT" );
5173             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
5174                 return false;
5175             }
5176             n.setName( "K1PYK7_PIG" );
5177             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5178                 return false;
5179             }
5180             n.setName( "~K1PYK7_PIG~" );
5181             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5182                 return false;
5183             }
5184             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
5185             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5186                 return false;
5187             }
5188             n.setName( "K1PYKX_CRAGI" );
5189             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5190                 return false;
5191             }
5192             n.setName( "XXXXX_CRAGI" );
5193             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
5194                 return false;
5195             }
5196             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
5197             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
5198                 return false;
5199             }
5200             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
5201             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5202                 return false;
5203             }
5204             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
5205             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
5206                 return false;
5207             }
5208             n = new PhylogenyNode();
5209             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
5210             seq.setSymbol( "K1PYK7_CRAGI" );
5211             n.getNodeData().addSequence( seq );
5212             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5213                 return false;
5214             }
5215             seq.setSymbol( "tr|B3RJ64" );
5216             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5217                 return false;
5218             }
5219             n = new PhylogenyNode();
5220             seq = new org.forester.phylogeny.data.Sequence();
5221             seq.setName( "K1PYK7_CRAGI" );
5222             n.getNodeData().addSequence( seq );
5223             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5224                 return false;
5225             }
5226             seq.setName( "tr|B3RJ64" );
5227             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5228                 return false;
5229             }
5230             n = new PhylogenyNode();
5231             seq = new org.forester.phylogeny.data.Sequence();
5232             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
5233             n.getNodeData().addSequence( seq );
5234             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
5235                 return false;
5236             }
5237             n = new PhylogenyNode();
5238             seq = new org.forester.phylogeny.data.Sequence();
5239             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
5240             n.getNodeData().addSequence( seq );
5241             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5242                 return false;
5243             }
5244             //
5245             n = new PhylogenyNode();
5246             n.setName( "ACP19736" );
5247             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5248                 return false;
5249             }
5250             n = new PhylogenyNode();
5251             n.setName( "|ACP19736|" );
5252             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5253                 return false;
5254             }
5255         }
5256         catch ( final Exception e ) {
5257             e.printStackTrace( System.out );
5258             return false;
5259         }
5260         return true;
5261     }
5262
5263     private static boolean testFastaParser() {
5264         try {
5265             FileInputStream fis1 = new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" );
5266             if ( !FastaParser.isLikelyFasta( fis1 ) ) {
5267                 fis1.close();
5268                 return false;
5269             }
5270             else {
5271                 fis1.close();
5272             }
5273             FileInputStream fis2 = new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" );
5274             if ( FastaParser.isLikelyFasta( fis2 ) ) {
5275                 fis2.close();
5276                 return false;
5277             }
5278             else {
5279                 fis2.close();
5280             }
5281             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
5282             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
5283                 return false;
5284             }
5285             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
5286                 return false;
5287             }
5288             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
5289                 return false;
5290             }
5291             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
5292                 return false;
5293             }
5294             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
5295                 return false;
5296             }
5297             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
5298                 return false;
5299             }
5300         }
5301         catch ( final Exception e ) {
5302             e.printStackTrace();
5303             return false;
5304         }
5305         return true;
5306     }
5307
5308     private static boolean testGenbankAccessorParsing() {
5309         //The format for GenBank Accession numbers are:
5310         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
5311         //Protein:    3 letters + 5 numerals
5312         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
5313         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
5314             return false;
5315         }
5316         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
5317             return false;
5318         }
5319         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
5320             return false;
5321         }
5322         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
5323             return false;
5324         }
5325         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
5326             return false;
5327         }
5328         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
5329             return false;
5330         }
5331         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
5332             return false;
5333         }
5334         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
5335             return false;
5336         }
5337         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
5338             return false;
5339         }
5340         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
5341             return false;
5342         }
5343         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
5344             return false;
5345         }
5346         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
5347             return false;
5348         }
5349         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
5350             return false;
5351         }
5352         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
5353             return false;
5354         }
5355         return true;
5356     }
5357
5358     private static boolean testGeneralMsaParser() {
5359         try {
5360             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
5361             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
5362             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
5363             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
5364             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
5365             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
5366             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
5367             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
5368             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5369                 return false;
5370             }
5371             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5372                 return false;
5373             }
5374             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5375                 return false;
5376             }
5377             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5378                 return false;
5379             }
5380             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5381                 return false;
5382             }
5383             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5384                 return false;
5385             }
5386             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5387                 return false;
5388             }
5389             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5390                 return false;
5391             }
5392             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5393                 return false;
5394             }
5395             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5396                 return false;
5397             }
5398             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5399                 return false;
5400             }
5401             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5402                 return false;
5403             }
5404             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5405             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5406                 return false;
5407             }
5408             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5409                 return false;
5410             }
5411             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5412                 return false;
5413             }
5414             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5415             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5416                 return false;
5417             }
5418             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5419                 return false;
5420             }
5421             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5422                 return false;
5423             }
5424             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5425             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5426                 return false;
5427             }
5428             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5429                 return false;
5430             }
5431             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5432                 return false;
5433             }
5434         }
5435         catch ( final Exception e ) {
5436             e.printStackTrace();
5437             return false;
5438         }
5439         return true;
5440     }
5441
5442     private static boolean testGeneralTable() {
5443         try {
5444             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5445             t0.setValue( 3, 2, "23" );
5446             t0.setValue( 10, 1, "error" );
5447             t0.setValue( 10, 1, "110" );
5448             t0.setValue( 9, 1, "19" );
5449             t0.setValue( 1, 10, "101" );
5450             t0.setValue( 10, 10, "1010" );
5451             t0.setValue( 100, 10, "10100" );
5452             t0.setValue( 0, 0, "00" );
5453             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5454                 return false;
5455             }
5456             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5457                 return false;
5458             }
5459             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5460                 return false;
5461             }
5462             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5463                 return false;
5464             }
5465             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5466                 return false;
5467             }
5468             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5469                 return false;
5470             }
5471             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5472                 return false;
5473             }
5474             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5475                 return false;
5476             }
5477             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5478                 return false;
5479             }
5480             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5481             t1.setValue( "3", "2", "23" );
5482             t1.setValue( "10", "1", "error" );
5483             t1.setValue( "10", "1", "110" );
5484             t1.setValue( "9", "1", "19" );
5485             t1.setValue( "1", "10", "101" );
5486             t1.setValue( "10", "10", "1010" );
5487             t1.setValue( "100", "10", "10100" );
5488             t1.setValue( "0", "0", "00" );
5489             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5490             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5491                 return false;
5492             }
5493             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5494                 return false;
5495             }
5496             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5497                 return false;
5498             }
5499             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5500                 return false;
5501             }
5502             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5503                 return false;
5504             }
5505             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5506                 return false;
5507             }
5508             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5509                 return false;
5510             }
5511             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5512                 return false;
5513             }
5514             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5515                 return false;
5516             }
5517             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5518                 return false;
5519             }
5520         }
5521         catch ( final Exception e ) {
5522             e.printStackTrace( System.out );
5523             return false;
5524         }
5525         return true;
5526     }
5527
5528     private static boolean testGetDistance() {
5529         try {
5530             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5531             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",
5532                                                  new NHXParser() )[ 0 ];
5533             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5534                 return false;
5535             }
5536             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5537                 return false;
5538             }
5539             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5540                 return false;
5541             }
5542             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5543                 return false;
5544             }
5545             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5546                 return false;
5547             }
5548             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5549                 return false;
5550             }
5551             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5552                 return false;
5553             }
5554             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5555                 return false;
5556             }
5557             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5558                 return false;
5559             }
5560             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5561                 return false;
5562             }
5563             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5564                 return false;
5565             }
5566             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5567                 return false;
5568             }
5569             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5570                 return false;
5571             }
5572             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5573                 return false;
5574             }
5575             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5576                 return false;
5577             }
5578             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5579                 return false;
5580             }
5581             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5582                 return false;
5583             }
5584             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5585                 return false;
5586             }
5587             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5588                 return false;
5589             }
5590             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5591                 return false;
5592             }
5593             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5594                 return false;
5595             }
5596             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5597                 return false;
5598             }
5599             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5600                 return false;
5601             }
5602             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5603                 return false;
5604             }
5605             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5606                 return false;
5607             }
5608             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5609                 return false;
5610             }
5611             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5612                 return false;
5613             }
5614             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5615                 return false;
5616             }
5617             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5618                 return false;
5619             }
5620             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5621                 return false;
5622             }
5623             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5624                 return false;
5625             }
5626             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",
5627                                                  new NHXParser() )[ 0 ];
5628             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5629                 return false;
5630             }
5631             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5632                 return false;
5633             }
5634             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5635                 return false;
5636             }
5637             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5638                 return false;
5639             }
5640             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5641                 return false;
5642             }
5643             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5644                 return false;
5645             }
5646             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5647                 return false;
5648             }
5649             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5650                 return false;
5651             }
5652             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5653                 return false;
5654             }
5655             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5656                 return false;
5657             }
5658             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5659                 return false;
5660             }
5661         }
5662         catch ( final Exception e ) {
5663             e.printStackTrace( System.out );
5664             return false;
5665         }
5666         return true;
5667     }
5668
5669     private static boolean testGetLCA() {
5670         try {
5671             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5672             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5673                                                  new NHXParser() )[ 0 ];
5674             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5675             if ( !A.getName().equals( "A" ) ) {
5676                 return false;
5677             }
5678             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5679             if ( !gh.getName().equals( "gh" ) ) {
5680                 return false;
5681             }
5682             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5683             if ( !ab.getName().equals( "ab" ) ) {
5684                 return false;
5685             }
5686             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5687             if ( !ab2.getName().equals( "ab" ) ) {
5688                 return false;
5689             }
5690             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5691             if ( !gh2.getName().equals( "gh" ) ) {
5692                 return false;
5693             }
5694             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5695             if ( !gh3.getName().equals( "gh" ) ) {
5696                 return false;
5697             }
5698             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5699             if ( !abc.getName().equals( "abc" ) ) {
5700                 return false;
5701             }
5702             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5703             if ( !abc2.getName().equals( "abc" ) ) {
5704                 return false;
5705             }
5706             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5707             if ( !abcd.getName().equals( "abcd" ) ) {
5708                 return false;
5709             }
5710             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5711             if ( !abcd2.getName().equals( "abcd" ) ) {
5712                 return false;
5713             }
5714             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5715             if ( !abcdef.getName().equals( "abcdef" ) ) {
5716                 return false;
5717             }
5718             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5719             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5720                 return false;
5721             }
5722             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5723             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5724                 return false;
5725             }
5726             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5727             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5728                 return false;
5729             }
5730             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5731             if ( !abcde.getName().equals( "abcde" ) ) {
5732                 return false;
5733             }
5734             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5735             if ( !abcde2.getName().equals( "abcde" ) ) {
5736                 return false;
5737             }
5738             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5739             if ( !r.getName().equals( "abcdefgh" ) ) {
5740                 return false;
5741             }
5742             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5743             if ( !r2.getName().equals( "abcdefgh" ) ) {
5744                 return false;
5745             }
5746             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5747             if ( !r3.getName().equals( "abcdefgh" ) ) {
5748                 return false;
5749             }
5750             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5751             if ( !abcde3.getName().equals( "abcde" ) ) {
5752                 return false;
5753             }
5754             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5755             if ( !abcde4.getName().equals( "abcde" ) ) {
5756                 return false;
5757             }
5758             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5759             if ( !ab3.getName().equals( "ab" ) ) {
5760                 return false;
5761             }
5762             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5763             if ( !ab4.getName().equals( "ab" ) ) {
5764                 return false;
5765             }
5766             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5767             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5768             if ( !cd.getName().equals( "cd" ) ) {
5769                 return false;
5770             }
5771             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5772             if ( !cd2.getName().equals( "cd" ) ) {
5773                 return false;
5774             }
5775             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5776             if ( !cde.getName().equals( "cde" ) ) {
5777                 return false;
5778             }
5779             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5780             if ( !cde2.getName().equals( "cde" ) ) {
5781                 return false;
5782             }
5783             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5784             if ( !cdef.getName().equals( "cdef" ) ) {
5785                 return false;
5786             }
5787             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5788             if ( !cdef2.getName().equals( "cdef" ) ) {
5789                 return false;
5790             }
5791             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5792             if ( !cdef3.getName().equals( "cdef" ) ) {
5793                 return false;
5794             }
5795             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5796             if ( !rt.getName().equals( "r" ) ) {
5797                 return false;
5798             }
5799             final Phylogeny p3 = factory
5800                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5801                              new NHXParser() )[ 0 ];
5802             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5803             if ( !bc_3.getName().equals( "bc" ) ) {
5804                 return false;
5805             }
5806             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5807             if ( !ac_3.getName().equals( "abc" ) ) {
5808                 return false;
5809             }
5810             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5811             if ( !ad_3.getName().equals( "abcde" ) ) {
5812                 return false;
5813             }
5814             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5815             if ( !af_3.getName().equals( "abcdef" ) ) {
5816                 return false;
5817             }
5818             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5819             if ( !ag_3.getName().equals( "" ) ) {
5820                 return false;
5821             }
5822             if ( !ag_3.isRoot() ) {
5823                 return false;
5824             }
5825             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5826             if ( !al_3.getName().equals( "" ) ) {
5827                 return false;
5828             }
5829             if ( !al_3.isRoot() ) {
5830                 return false;
5831             }
5832             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5833             if ( !kl_3.getName().equals( "" ) ) {
5834                 return false;
5835             }
5836             if ( !kl_3.isRoot() ) {
5837                 return false;
5838             }
5839             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5840             if ( !fl_3.getName().equals( "" ) ) {
5841                 return false;
5842             }
5843             if ( !fl_3.isRoot() ) {
5844                 return false;
5845             }
5846             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5847             if ( !gk_3.getName().equals( "ghijk" ) ) {
5848                 return false;
5849             }
5850             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5851             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5852             if ( !r_4.getName().equals( "r" ) ) {
5853                 return false;
5854             }
5855             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5856             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5857             if ( !r_5.getName().equals( "root" ) ) {
5858                 return false;
5859             }
5860             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5861             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5862             if ( !r_6.getName().equals( "rot" ) ) {
5863                 return false;
5864             }
5865             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5866             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5867             if ( !r_7.getName().equals( "rott" ) ) {
5868                 return false;
5869             }
5870         }
5871         catch ( final Exception e ) {
5872             e.printStackTrace( System.out );
5873             return false;
5874         }
5875         return true;
5876     }
5877
5878     private static boolean testGetLCA2() {
5879         try {
5880             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5881             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5882             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5883             PhylogenyMethods.preOrderReId( p_a );
5884             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5885                                                                                               p_a.getNode( "a" ) );
5886             if ( !p_a_1.getName().equals( "a" ) ) {
5887                 return false;
5888             }
5889             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5890             PhylogenyMethods.preOrderReId( p_b );
5891             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5892                                                                                               p_b.getNode( "a" ) );
5893             if ( !p_b_1.getName().equals( "b" ) ) {
5894                 return false;
5895             }
5896             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5897                                                                                               p_b.getNode( "b" ) );
5898             if ( !p_b_2.getName().equals( "b" ) ) {
5899                 return false;
5900             }
5901             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5902             PhylogenyMethods.preOrderReId( p_c );
5903             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5904                                                                                               p_c.getNode( "a" ) );
5905             if ( !p_c_1.getName().equals( "b" ) ) {
5906                 return false;
5907             }
5908             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5909                                                                                               p_c.getNode( "c" ) );
5910             if ( !p_c_2.getName().equals( "c" ) ) {
5911                 System.out.println( p_c_2.getName() );
5912                 System.exit( -1 );
5913                 return false;
5914             }
5915             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5916                                                                                               p_c.getNode( "b" ) );
5917             if ( !p_c_3.getName().equals( "b" ) ) {
5918                 return false;
5919             }
5920             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5921                                                                                               p_c.getNode( "a" ) );
5922             if ( !p_c_4.getName().equals( "c" ) ) {
5923                 return false;
5924             }
5925             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5926                                                  new NHXParser() )[ 0 ];
5927             PhylogenyMethods.preOrderReId( p1 );
5928             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5929                                                                                           p1.getNode( "A" ) );
5930             if ( !A.getName().equals( "A" ) ) {
5931                 return false;
5932             }
5933             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5934                                                                                            p1.getNode( "gh" ) );
5935             if ( !gh.getName().equals( "gh" ) ) {
5936                 return false;
5937             }
5938             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5939                                                                                            p1.getNode( "B" ) );
5940             if ( !ab.getName().equals( "ab" ) ) {
5941                 return false;
5942             }
5943             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5944                                                                                             p1.getNode( "A" ) );
5945             if ( !ab2.getName().equals( "ab" ) ) {
5946                 return false;
5947             }
5948             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5949                                                                                             p1.getNode( "G" ) );
5950             if ( !gh2.getName().equals( "gh" ) ) {
5951                 return false;
5952             }
5953             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5954                                                                                             p1.getNode( "H" ) );
5955             if ( !gh3.getName().equals( "gh" ) ) {
5956                 return false;
5957             }
5958             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5959                                                                                             p1.getNode( "A" ) );
5960             if ( !abc.getName().equals( "abc" ) ) {
5961                 return false;
5962             }
5963             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5964                                                                                              p1.getNode( "C" ) );
5965             if ( !abc2.getName().equals( "abc" ) ) {
5966                 return false;
5967             }
5968             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5969                                                                                              p1.getNode( "D" ) );
5970             if ( !abcd.getName().equals( "abcd" ) ) {
5971                 return false;
5972             }
5973             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5974                                                                                               p1.getNode( "A" ) );
5975             if ( !abcd2.getName().equals( "abcd" ) ) {
5976                 return false;
5977             }
5978             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5979                                                                                                p1.getNode( "F" ) );
5980             if ( !abcdef.getName().equals( "abcdef" ) ) {
5981                 return false;
5982             }
5983             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5984                                                                                                 p1.getNode( "A" ) );
5985             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5986                 return false;
5987             }
5988             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5989                                                                                                 p1.getNode( "F" ) );
5990             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5991                 return false;
5992             }
5993             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5994                                                                                                 p1.getNode( "ab" ) );
5995             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5996                 return false;
5997             }
5998             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5999                                                                                               p1.getNode( "E" ) );
6000             if ( !abcde.getName().equals( "abcde" ) ) {
6001                 return false;
6002             }
6003             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6004                                                                                                p1.getNode( "A" ) );
6005             if ( !abcde2.getName().equals( "abcde" ) ) {
6006                 return false;
6007             }
6008             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
6009                                                                                           p1.getNode( "abcdefgh" ) );
6010             if ( !r.getName().equals( "abcdefgh" ) ) {
6011                 return false;
6012             }
6013             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6014                                                                                            p1.getNode( "H" ) );
6015             if ( !r2.getName().equals( "abcdefgh" ) ) {
6016                 return false;
6017             }
6018             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
6019                                                                                            p1.getNode( "A" ) );
6020             if ( !r3.getName().equals( "abcdefgh" ) ) {
6021                 return false;
6022             }
6023             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6024                                                                                                p1.getNode( "abcde" ) );
6025             if ( !abcde3.getName().equals( "abcde" ) ) {
6026                 return false;
6027             }
6028             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
6029                                                                                                p1.getNode( "E" ) );
6030             if ( !abcde4.getName().equals( "abcde" ) ) {
6031                 return false;
6032             }
6033             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
6034                                                                                             p1.getNode( "B" ) );
6035             if ( !ab3.getName().equals( "ab" ) ) {
6036                 return false;
6037             }
6038             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
6039                                                                                             p1.getNode( "ab" ) );
6040             if ( !ab4.getName().equals( "ab" ) ) {
6041                 return false;
6042             }
6043             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
6044             PhylogenyMethods.preOrderReId( p2 );
6045             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6046                                                                                            p2.getNode( "d" ) );
6047             if ( !cd.getName().equals( "cd" ) ) {
6048                 return false;
6049             }
6050             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6051                                                                                             p2.getNode( "c" ) );
6052             if ( !cd2.getName().equals( "cd" ) ) {
6053                 return false;
6054             }
6055             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6056                                                                                             p2.getNode( "e" ) );
6057             if ( !cde.getName().equals( "cde" ) ) {
6058                 return false;
6059             }
6060             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
6061                                                                                              p2.getNode( "c" ) );
6062             if ( !cde2.getName().equals( "cde" ) ) {
6063                 return false;
6064             }
6065             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6066                                                                                              p2.getNode( "f" ) );
6067             if ( !cdef.getName().equals( "cdef" ) ) {
6068                 return false;
6069             }
6070             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6071                                                                                               p2.getNode( "f" ) );
6072             if ( !cdef2.getName().equals( "cdef" ) ) {
6073                 return false;
6074             }
6075             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
6076                                                                                               p2.getNode( "d" ) );
6077             if ( !cdef3.getName().equals( "cdef" ) ) {
6078                 return false;
6079             }
6080             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6081                                                                                            p2.getNode( "a" ) );
6082             if ( !rt.getName().equals( "r" ) ) {
6083                 return false;
6084             }
6085             final Phylogeny p3 = factory
6086                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
6087                              new NHXParser() )[ 0 ];
6088             PhylogenyMethods.preOrderReId( p3 );
6089             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
6090                                                                                              p3.getNode( "c" ) );
6091             if ( !bc_3.getName().equals( "bc" ) ) {
6092                 return false;
6093             }
6094             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6095                                                                                              p3.getNode( "c" ) );
6096             if ( !ac_3.getName().equals( "abc" ) ) {
6097                 return false;
6098             }
6099             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6100                                                                                              p3.getNode( "d" ) );
6101             if ( !ad_3.getName().equals( "abcde" ) ) {
6102                 return false;
6103             }
6104             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6105                                                                                              p3.getNode( "f" ) );
6106             if ( !af_3.getName().equals( "abcdef" ) ) {
6107                 return false;
6108             }
6109             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6110                                                                                              p3.getNode( "g" ) );
6111             if ( !ag_3.getName().equals( "" ) ) {
6112                 return false;
6113             }
6114             if ( !ag_3.isRoot() ) {
6115                 return false;
6116             }
6117             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6118                                                                                              p3.getNode( "l" ) );
6119             if ( !al_3.getName().equals( "" ) ) {
6120                 return false;
6121             }
6122             if ( !al_3.isRoot() ) {
6123                 return false;
6124             }
6125             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
6126                                                                                              p3.getNode( "l" ) );
6127             if ( !kl_3.getName().equals( "" ) ) {
6128                 return false;
6129             }
6130             if ( !kl_3.isRoot() ) {
6131                 return false;
6132             }
6133             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
6134                                                                                              p3.getNode( "l" ) );
6135             if ( !fl_3.getName().equals( "" ) ) {
6136                 return false;
6137             }
6138             if ( !fl_3.isRoot() ) {
6139                 return false;
6140             }
6141             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
6142                                                                                              p3.getNode( "k" ) );
6143             if ( !gk_3.getName().equals( "ghijk" ) ) {
6144                 return false;
6145             }
6146             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
6147             PhylogenyMethods.preOrderReId( p4 );
6148             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
6149                                                                                             p4.getNode( "c" ) );
6150             if ( !r_4.getName().equals( "r" ) ) {
6151                 return false;
6152             }
6153             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
6154             PhylogenyMethods.preOrderReId( p5 );
6155             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
6156                                                                                             p5.getNode( "c" ) );
6157             if ( !r_5.getName().equals( "root" ) ) {
6158                 return false;
6159             }
6160             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
6161             PhylogenyMethods.preOrderReId( p6 );
6162             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
6163                                                                                             p6.getNode( "a" ) );
6164             if ( !r_6.getName().equals( "rot" ) ) {
6165                 return false;
6166             }
6167             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
6168             PhylogenyMethods.preOrderReId( p7 );
6169             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
6170                                                                                             p7.getNode( "e" ) );
6171             if ( !r_7.getName().equals( "rott" ) ) {
6172                 return false;
6173             }
6174             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6175                                                                                              p7.getNode( "a" ) );
6176             if ( !r_71.getName().equals( "rott" ) ) {
6177                 return false;
6178             }
6179             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6180                                                                                              p7.getNode( "rott" ) );
6181             if ( !r_72.getName().equals( "rott" ) ) {
6182                 return false;
6183             }
6184             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6185                                                                                              p7.getNode( "a" ) );
6186             if ( !r_73.getName().equals( "rott" ) ) {
6187                 return false;
6188             }
6189             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6190                                                                                              p7.getNode( "rott" ) );
6191             if ( !r_74.getName().equals( "rott" ) ) {
6192                 return false;
6193             }
6194             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6195                                                                                              p7.getNode( "e" ) );
6196             if ( !r_75.getName().equals( "e" ) ) {
6197                 return false;
6198             }
6199         }
6200         catch ( final Exception e ) {
6201             e.printStackTrace( System.out );
6202             return false;
6203         }
6204         return true;
6205     }
6206
6207     private static boolean testHmmscanOutputParser() {
6208         final String test_dir = Test.PATH_TO_TEST_DATA;
6209         try {
6210             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
6211                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
6212             parser1.parse();
6213             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
6214                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
6215             final List<Protein> proteins = parser2.parse();
6216             if ( parser2.getProteinsEncountered() != 4 ) {
6217                 return false;
6218             }
6219             if ( proteins.size() != 4 ) {
6220                 return false;
6221             }
6222             if ( parser2.getDomainsEncountered() != 69 ) {
6223                 return false;
6224             }
6225             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
6226                 return false;
6227             }
6228             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
6229                 return false;
6230             }
6231             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
6232                 return false;
6233             }
6234             final Protein p1 = proteins.get( 0 );
6235             if ( p1.getNumberOfProteinDomains() != 15 ) {
6236                 return false;
6237             }
6238             if ( p1.getLength() != 850 ) {
6239                 return false;
6240             }
6241             final Protein p2 = proteins.get( 1 );
6242             if ( p2.getNumberOfProteinDomains() != 51 ) {
6243                 return false;
6244             }
6245             if ( p2.getLength() != 1291 ) {
6246                 return false;
6247             }
6248             final Protein p3 = proteins.get( 2 );
6249             if ( p3.getNumberOfProteinDomains() != 2 ) {
6250                 return false;
6251             }
6252             final Protein p4 = proteins.get( 3 );
6253             if ( p4.getNumberOfProteinDomains() != 1 ) {
6254                 return false;
6255             }
6256             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
6257                 return false;
6258             }
6259             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
6260                 return false;
6261             }
6262             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
6263                 return false;
6264             }
6265             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
6266                 return false;
6267             }
6268             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
6269                 return false;
6270             }
6271             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
6272                 return false;
6273             }
6274             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
6275                 return false;
6276             }
6277         }
6278         catch ( final Exception e ) {
6279             e.printStackTrace( System.out );
6280             return false;
6281         }
6282         return true;
6283     }
6284
6285     private static boolean testLastExternalNodeMethods() {
6286         try {
6287             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6288             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
6289             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
6290             final PhylogenyNode n1 = t0.getNode( "A" );
6291             if ( n1.isLastExternalNode() ) {
6292                 return false;
6293             }
6294             final PhylogenyNode n2 = t0.getNode( "B" );
6295             if ( n2.isLastExternalNode() ) {
6296                 return false;
6297             }
6298             final PhylogenyNode n3 = t0.getNode( "C" );
6299             if ( n3.isLastExternalNode() ) {
6300                 return false;
6301             }
6302             final PhylogenyNode n4 = t0.getNode( "D" );
6303             if ( !n4.isLastExternalNode() ) {
6304                 return false;
6305             }
6306         }
6307         catch ( final Exception e ) {
6308             e.printStackTrace( System.out );
6309             return false;
6310         }
6311         return true;
6312     }
6313
6314     private static boolean testLevelOrderIterator() {
6315         try {
6316             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6317             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
6318             PhylogenyNodeIterator it0;
6319             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
6320                 it0.next();
6321             }
6322             for( it0.reset(); it0.hasNext(); ) {
6323                 it0.next();
6324             }
6325             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
6326             if ( !it.next().getName().equals( "r" ) ) {
6327                 return false;
6328             }
6329             if ( !it.next().getName().equals( "ab" ) ) {
6330                 return false;
6331             }
6332             if ( !it.next().getName().equals( "cd" ) ) {
6333                 return false;
6334             }
6335             if ( !it.next().getName().equals( "A" ) ) {
6336                 return false;
6337             }
6338             if ( !it.next().getName().equals( "B" ) ) {
6339                 return false;
6340             }
6341             if ( !it.next().getName().equals( "C" ) ) {
6342                 return false;
6343             }
6344             if ( !it.next().getName().equals( "D" ) ) {
6345                 return false;
6346             }
6347             if ( it.hasNext() ) {
6348                 return false;
6349             }
6350             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",
6351                                                  new NHXParser() )[ 0 ];
6352             PhylogenyNodeIterator it2;
6353             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
6354                 it2.next();
6355             }
6356             for( it2.reset(); it2.hasNext(); ) {
6357                 it2.next();
6358             }
6359             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
6360             if ( !it3.next().getName().equals( "r" ) ) {
6361                 return false;
6362             }
6363             if ( !it3.next().getName().equals( "abc" ) ) {
6364                 return false;
6365             }
6366             if ( !it3.next().getName().equals( "defg" ) ) {
6367                 return false;
6368             }
6369             if ( !it3.next().getName().equals( "A" ) ) {
6370                 return false;
6371             }
6372             if ( !it3.next().getName().equals( "B" ) ) {
6373                 return false;
6374             }
6375             if ( !it3.next().getName().equals( "C" ) ) {
6376                 return false;
6377             }
6378             if ( !it3.next().getName().equals( "D" ) ) {
6379                 return false;
6380             }
6381             if ( !it3.next().getName().equals( "E" ) ) {
6382                 return false;
6383             }
6384             if ( !it3.next().getName().equals( "F" ) ) {
6385                 return false;
6386             }
6387             if ( !it3.next().getName().equals( "G" ) ) {
6388                 return false;
6389             }
6390             if ( !it3.next().getName().equals( "1" ) ) {
6391                 return false;
6392             }
6393             if ( !it3.next().getName().equals( "2" ) ) {
6394                 return false;
6395             }
6396             if ( !it3.next().getName().equals( "3" ) ) {
6397                 return false;
6398             }
6399             if ( !it3.next().getName().equals( "4" ) ) {
6400                 return false;
6401             }
6402             if ( !it3.next().getName().equals( "5" ) ) {
6403                 return false;
6404             }
6405             if ( !it3.next().getName().equals( "6" ) ) {
6406                 return false;
6407             }
6408             if ( !it3.next().getName().equals( "f1" ) ) {
6409                 return false;
6410             }
6411             if ( !it3.next().getName().equals( "f2" ) ) {
6412                 return false;
6413             }
6414             if ( !it3.next().getName().equals( "f3" ) ) {
6415                 return false;
6416             }
6417             if ( !it3.next().getName().equals( "a" ) ) {
6418                 return false;
6419             }
6420             if ( !it3.next().getName().equals( "b" ) ) {
6421                 return false;
6422             }
6423             if ( !it3.next().getName().equals( "f21" ) ) {
6424                 return false;
6425             }
6426             if ( !it3.next().getName().equals( "X" ) ) {
6427                 return false;
6428             }
6429             if ( !it3.next().getName().equals( "Y" ) ) {
6430                 return false;
6431             }
6432             if ( !it3.next().getName().equals( "Z" ) ) {
6433                 return false;
6434             }
6435             if ( it3.hasNext() ) {
6436                 return false;
6437             }
6438             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6439             PhylogenyNodeIterator it4;
6440             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6441                 it4.next();
6442             }
6443             for( it4.reset(); it4.hasNext(); ) {
6444                 it4.next();
6445             }
6446             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6447             if ( !it5.next().getName().equals( "r" ) ) {
6448                 return false;
6449             }
6450             if ( !it5.next().getName().equals( "A" ) ) {
6451                 return false;
6452             }
6453             if ( !it5.next().getName().equals( "B" ) ) {
6454                 return false;
6455             }
6456             if ( !it5.next().getName().equals( "C" ) ) {
6457                 return false;
6458             }
6459             if ( !it5.next().getName().equals( "D" ) ) {
6460                 return false;
6461             }
6462             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6463             PhylogenyNodeIterator it6;
6464             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6465                 it6.next();
6466             }
6467             for( it6.reset(); it6.hasNext(); ) {
6468                 it6.next();
6469             }
6470             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6471             if ( !it7.next().getName().equals( "A" ) ) {
6472                 return false;
6473             }
6474             if ( it.hasNext() ) {
6475                 return false;
6476             }
6477         }
6478         catch ( final Exception e ) {
6479             e.printStackTrace( System.out );
6480             return false;
6481         }
6482         return true;
6483     }
6484
6485     private static boolean testMafft( final String path ) {
6486         try {
6487             final List<String> opts = new ArrayList<String>();
6488             opts.add( "--maxiterate" );
6489             opts.add( "1000" );
6490             opts.add( "--localpair" );
6491             opts.add( "--quiet" );
6492             Msa msa = null;
6493             final MsaInferrer mafft = Mafft.createInstance( path );
6494             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6495             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6496                 return false;
6497             }
6498             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6499                 return false;
6500             }
6501         }
6502         catch ( final Exception e ) {
6503             e.printStackTrace( System.out );
6504             return false;
6505         }
6506         return true;
6507     }
6508
6509     private static boolean testMidpointrooting() {
6510         try {
6511             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6512             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6513             PhylogenyMethods.midpointRoot( t0 );
6514             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6515                 return false;
6516             }
6517             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6518                 return false;
6519             }
6520             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6521                            1 ) ) {
6522                 return false;
6523             }
6524             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",
6525                                                  new NHXParser() )[ 0 ];
6526             if ( !t1.isRooted() ) {
6527                 return false;
6528             }
6529             PhylogenyMethods.midpointRoot( t1 );
6530             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6531                 return false;
6532             }
6533             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6534                 return false;
6535             }
6536             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6537                 return false;
6538             }
6539             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6540                 return false;
6541             }
6542             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6543                 return false;
6544             }
6545             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6546                 return false;
6547             }
6548             t1.reRoot( t1.getNode( "A" ) );
6549             PhylogenyMethods.midpointRoot( t1 );
6550             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6551                 return false;
6552             }
6553             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6554                 return false;
6555             }
6556             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6557                 return false;
6558             }
6559             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6560                 return false;
6561             }
6562             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6563                 System.exit( -1 );
6564                 return false;
6565             }
6566             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6567                 return false;
6568             }
6569         }
6570         catch ( final Exception e ) {
6571             e.printStackTrace( System.out );
6572             return false;
6573         }
6574         return true;
6575     }
6576
6577     private static boolean testMsaQualityMethod() {
6578         try {
6579             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6580             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6581             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6582             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6583             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6584             l.add( s0 );
6585             l.add( s1 );
6586             l.add( s2 );
6587             l.add( s3 );
6588             final Msa msa = BasicMsa.createInstance( l );
6589             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6590                 return false;
6591             }
6592             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6593                 return false;
6594             }
6595             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6596                 return false;
6597             }
6598             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6599                 return false;
6600             }
6601             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6602                 return false;
6603             }
6604             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6605                 return false;
6606             }
6607             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6608                 return false;
6609             }
6610         }
6611         catch ( final Exception e ) {
6612             e.printStackTrace( System.out );
6613             return false;
6614         }
6615         return true;
6616     }
6617
6618     private static boolean testMsaEntropy() {
6619         try {
6620             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6621             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6622             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6623             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6624             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6625             l.add( s0 );
6626             l.add( s1 );
6627             l.add( s2 );
6628             l.add( s3 );
6629             final Msa msa = BasicMsa.createInstance( l );
6630             //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6631             //FIXME
6632             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6633             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6634             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6635             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6636             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6637             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6638             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6639             //            System.out.println();
6640             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6641             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6642             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6643             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6644             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6645             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6646             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6647             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6648             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6649             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6650             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6651             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6652             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6653             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6654             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6655             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6656             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6657             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6658             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6659             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6660             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6661             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6662             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6663             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6664             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6665             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6666             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6667             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6668             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6669             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6670             final Msa msa2 = BasicMsa.createInstance( l2 );
6671             //            System.out.println();
6672             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6673             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6674             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6675         }
6676         catch ( final Exception e ) {
6677             e.printStackTrace( System.out );
6678             return false;
6679         }
6680         return true;
6681     }
6682
6683     private static boolean testDeleteableMsa() {
6684         try {
6685             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6686             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6687             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6688             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6689             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6690             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6691             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6692             l0.add( s0 );
6693             l0.add( s1 );
6694             l0.add( s2 );
6695             l0.add( s3 );
6696             l0.add( s4 );
6697             l0.add( s5 );
6698             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6699             dmsa0.deleteRow( "b", false );
6700             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6701                 return false;
6702             }
6703             dmsa0.deleteRow( "e", false );
6704             dmsa0.deleteRow( "a", false );
6705             dmsa0.deleteRow( "f", false );
6706             if ( dmsa0.getLength() != 4 ) {
6707                 return false;
6708             }
6709             if ( dmsa0.getNumberOfSequences() != 2 ) {
6710                 return false;
6711             }
6712             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6713                 return false;
6714             }
6715             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6716                 return false;
6717             }
6718             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6719                 return false;
6720             }
6721             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6722                 return false;
6723             }
6724             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6725                 return false;
6726             }
6727             dmsa0.deleteRow( "c", false );
6728             dmsa0.deleteRow( "d", false );
6729             if ( dmsa0.getNumberOfSequences() != 0 ) {
6730                 return false;
6731             }
6732             //
6733             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6734             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6735             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6736             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6737             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6738             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6739             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6740             l1.add( s_0 );
6741             l1.add( s_1 );
6742             l1.add( s_2 );
6743             l1.add( s_3 );
6744             l1.add( s_4 );
6745             l1.add( s_5 );
6746             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6747             dmsa1.deleteGapOnlyColumns();
6748             dmsa1.deleteRow( "a", false );
6749             dmsa1.deleteRow( "f", false );
6750             dmsa1.deleteRow( "d", false );
6751             dmsa1.deleteGapOnlyColumns();
6752             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6753                 return false;
6754             }
6755             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6756                 return false;
6757             }
6758             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6759                 return false;
6760             }
6761             dmsa1.deleteRow( "c", false );
6762             dmsa1.deleteGapOnlyColumns();
6763             final Writer w0 = new StringWriter();
6764             dmsa1.write( w0, MSA_FORMAT.FASTA );
6765             final Writer w1 = new StringWriter();
6766             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6767             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6768                 return false;
6769             }
6770             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6771                 return false;
6772             }
6773             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6774             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6775             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6776             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6777             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6778             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6779             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6780             l2.add( s__0 );
6781             l2.add( s__1 );
6782             l2.add( s__2 );
6783             l2.add( s__3 );
6784             l2.add( s__4 );
6785             l2.add( s__5 );
6786             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6787             dmsa2.deleteGapColumns( 0.5 );
6788             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6789                 return false;
6790             }
6791             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6792                 return false;
6793             }
6794             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6795                 return false;
6796             }
6797             dmsa2.deleteGapColumns( 0.2 );
6798             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6799                 return false;
6800             }
6801             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6802                 return false;
6803             }
6804             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6805                 return false;
6806             }
6807             dmsa2.deleteGapColumns( 0 );
6808             dmsa2.deleteRow( "a", false );
6809             dmsa2.deleteRow( "b", false );
6810             dmsa2.deleteRow( "f", false );
6811             dmsa2.deleteRow( "e", false );
6812             dmsa2.setIdentifier( 0, "new_c" );
6813             dmsa2.setIdentifier( 1, "new_d" );
6814             dmsa2.setResidueAt( 0, 0, 'x' );
6815             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6816             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6817                 return false;
6818             }
6819             final Writer w = new StringWriter();
6820             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6821             final String phylip = w.toString();
6822             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6823                 System.out.println( phylip );
6824                 return false;
6825             }
6826             final Writer w2 = new StringWriter();
6827             dmsa2.write( w2, MSA_FORMAT.FASTA );
6828             final String fasta = w2.toString();
6829             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6830                 System.out.println( fasta );
6831                 return false;
6832             }
6833         }
6834         catch ( final Exception e ) {
6835             e.printStackTrace( System.out );
6836             return false;
6837         }
6838         return true;
6839     }
6840
6841     private static boolean testNextNodeWithCollapsing() {
6842         try {
6843             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6844             PhylogenyNode n;
6845             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6846             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6847             final Phylogeny t0 = factory.create( sb0.toString(), new NHXParser() )[ 0 ];
6848             t0.getNode( "cd" ).setCollapse( true );
6849             t0.getNode( "cde" ).setCollapse( true );
6850             n = t0.getFirstExternalNode();
6851             while ( n != null ) {
6852                 ext.add( n );
6853                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6854             }
6855             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6856                 return false;
6857             }
6858             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6859                 return false;
6860             }
6861             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6862                 return false;
6863             }
6864             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6865                 return false;
6866             }
6867             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6868                 return false;
6869             }
6870             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6871                 return false;
6872             }
6873             ext.clear();
6874             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6875             final Phylogeny t1 = factory.create( sb1.toString(), new NHXParser() )[ 0 ];
6876             t1.getNode( "ab" ).setCollapse( true );
6877             t1.getNode( "cd" ).setCollapse( true );
6878             t1.getNode( "cde" ).setCollapse( true );
6879             n = t1.getNode( "ab" );
6880             ext = new ArrayList<PhylogenyNode>();
6881             while ( n != null ) {
6882                 ext.add( n );
6883                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6884             }
6885             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6886                 return false;
6887             }
6888             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6889                 return false;
6890             }
6891             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6892                 return false;
6893             }
6894             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6895                 return false;
6896             }
6897             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6898                 return false;
6899             }
6900             ext.clear();
6901             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6902             final Phylogeny t2 = factory.create( sb2.toString(), new NHXParser() )[ 0 ];
6903             t2.getNode( "ab" ).setCollapse( true );
6904             t2.getNode( "cd" ).setCollapse( true );
6905             t2.getNode( "cde" ).setCollapse( true );
6906             t2.getNode( "c" ).setCollapse( true );
6907             t2.getNode( "d" ).setCollapse( true );
6908             t2.getNode( "e" ).setCollapse( true );
6909             t2.getNode( "gh" ).setCollapse( true );
6910             n = t2.getNode( "ab" );
6911             ext = new ArrayList<PhylogenyNode>();
6912             while ( n != null ) {
6913                 ext.add( n );
6914                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6915             }
6916             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6917                 return false;
6918             }
6919             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6920                 return false;
6921             }
6922             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6923                 return false;
6924             }
6925             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6926                 return false;
6927             }
6928             ext.clear();
6929             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6930             final Phylogeny t3 = factory.create( sb3.toString(), new NHXParser() )[ 0 ];
6931             t3.getNode( "ab" ).setCollapse( true );
6932             t3.getNode( "cd" ).setCollapse( true );
6933             t3.getNode( "cde" ).setCollapse( true );
6934             t3.getNode( "c" ).setCollapse( true );
6935             t3.getNode( "d" ).setCollapse( true );
6936             t3.getNode( "e" ).setCollapse( true );
6937             t3.getNode( "gh" ).setCollapse( true );
6938             t3.getNode( "fgh" ).setCollapse( true );
6939             n = t3.getNode( "ab" );
6940             ext = new ArrayList<PhylogenyNode>();
6941             while ( n != null ) {
6942                 ext.add( n );
6943                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6944             }
6945             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6946                 return false;
6947             }
6948             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6949                 return false;
6950             }
6951             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6952                 return false;
6953             }
6954             ext.clear();
6955             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6956             final Phylogeny t4 = factory.create( sb4.toString(), new NHXParser() )[ 0 ];
6957             t4.getNode( "ab" ).setCollapse( true );
6958             t4.getNode( "cd" ).setCollapse( true );
6959             t4.getNode( "cde" ).setCollapse( true );
6960             t4.getNode( "c" ).setCollapse( true );
6961             t4.getNode( "d" ).setCollapse( true );
6962             t4.getNode( "e" ).setCollapse( true );
6963             t4.getNode( "gh" ).setCollapse( true );
6964             t4.getNode( "fgh" ).setCollapse( true );
6965             t4.getNode( "abcdefgh" ).setCollapse( true );
6966             n = t4.getNode( "abcdefgh" );
6967             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6968                 return false;
6969             }
6970             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6971             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
6972             ext.clear();
6973             n = t5.getFirstExternalNode();
6974             while ( n != null ) {
6975                 ext.add( n );
6976                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6977             }
6978             if ( ext.size() != 8 ) {
6979                 return false;
6980             }
6981             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6982                 return false;
6983             }
6984             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6985                 return false;
6986             }
6987             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6988                 return false;
6989             }
6990             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6991                 return false;
6992             }
6993             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6994                 return false;
6995             }
6996             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6997                 return false;
6998             }
6999             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
7000                 return false;
7001             }
7002             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
7003                 return false;
7004             }
7005             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7006             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
7007             ext.clear();
7008             t6.getNode( "ab" ).setCollapse( true );
7009             n = t6.getNode( "ab" );
7010             while ( n != null ) {
7011                 ext.add( n );
7012                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7013             }
7014             if ( ext.size() != 7 ) {
7015                 return false;
7016             }
7017             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7018                 return false;
7019             }
7020             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7021                 return false;
7022             }
7023             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7024                 return false;
7025             }
7026             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7027                 return false;
7028             }
7029             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7030                 return false;
7031             }
7032             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7033                 return false;
7034             }
7035             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7036                 return false;
7037             }
7038             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7039             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
7040             ext.clear();
7041             t7.getNode( "cd" ).setCollapse( true );
7042             n = t7.getNode( "a" );
7043             while ( n != null ) {
7044                 ext.add( n );
7045                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7046             }
7047             if ( ext.size() != 7 ) {
7048                 return false;
7049             }
7050             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7051                 return false;
7052             }
7053             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7054                 return false;
7055             }
7056             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7057                 return false;
7058             }
7059             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7060                 return false;
7061             }
7062             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7063                 return false;
7064             }
7065             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7066                 return false;
7067             }
7068             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7069                 return false;
7070             }
7071             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7072             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
7073             ext.clear();
7074             t8.getNode( "cd" ).setCollapse( true );
7075             t8.getNode( "c" ).setCollapse( true );
7076             t8.getNode( "d" ).setCollapse( true );
7077             n = t8.getNode( "a" );
7078             while ( n != null ) {
7079                 ext.add( n );
7080                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7081             }
7082             if ( ext.size() != 7 ) {
7083                 return false;
7084             }
7085             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7086                 return false;
7087             }
7088             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7089                 return false;
7090             }
7091             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7092                 System.out.println( "2 fail" );
7093                 return false;
7094             }
7095             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7096                 return false;
7097             }
7098             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7099                 return false;
7100             }
7101             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7102                 return false;
7103             }
7104             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7105                 return false;
7106             }
7107             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7108             final Phylogeny t9 = factory.create( sb9.toString(), new NHXParser() )[ 0 ];
7109             ext.clear();
7110             t9.getNode( "gh" ).setCollapse( true );
7111             n = t9.getNode( "a" );
7112             while ( n != null ) {
7113                 ext.add( n );
7114                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7115             }
7116             if ( ext.size() != 7 ) {
7117                 return false;
7118             }
7119             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7120                 return false;
7121             }
7122             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7123                 return false;
7124             }
7125             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7126                 return false;
7127             }
7128             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7129                 return false;
7130             }
7131             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7132                 return false;
7133             }
7134             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7135                 return false;
7136             }
7137             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7138                 return false;
7139             }
7140             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7141             final Phylogeny t10 = factory.create( sb10.toString(), new NHXParser() )[ 0 ];
7142             ext.clear();
7143             t10.getNode( "gh" ).setCollapse( true );
7144             t10.getNode( "g" ).setCollapse( true );
7145             t10.getNode( "h" ).setCollapse( true );
7146             n = t10.getNode( "a" );
7147             while ( n != null ) {
7148                 ext.add( n );
7149                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7150             }
7151             if ( ext.size() != 7 ) {
7152                 return false;
7153             }
7154             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7155                 return false;
7156             }
7157             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7158                 return false;
7159             }
7160             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7161                 return false;
7162             }
7163             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7164                 return false;
7165             }
7166             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7167                 return false;
7168             }
7169             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7170                 return false;
7171             }
7172             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7173                 return false;
7174             }
7175             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7176             final Phylogeny t11 = factory.create( sb11.toString(), new NHXParser() )[ 0 ];
7177             ext.clear();
7178             t11.getNode( "gh" ).setCollapse( true );
7179             t11.getNode( "fgh" ).setCollapse( true );
7180             n = t11.getNode( "a" );
7181             while ( n != null ) {
7182                 ext.add( n );
7183                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7184             }
7185             if ( ext.size() != 6 ) {
7186                 return false;
7187             }
7188             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7189                 return false;
7190             }
7191             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7192                 return false;
7193             }
7194             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7195                 return false;
7196             }
7197             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7198                 return false;
7199             }
7200             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7201                 return false;
7202             }
7203             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7204                 return false;
7205             }
7206             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7207             final Phylogeny t12 = factory.create( sb12.toString(), new NHXParser() )[ 0 ];
7208             ext.clear();
7209             t12.getNode( "gh" ).setCollapse( true );
7210             t12.getNode( "fgh" ).setCollapse( true );
7211             t12.getNode( "g" ).setCollapse( true );
7212             t12.getNode( "h" ).setCollapse( true );
7213             t12.getNode( "f" ).setCollapse( true );
7214             n = t12.getNode( "a" );
7215             while ( n != null ) {
7216                 ext.add( n );
7217                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7218             }
7219             if ( ext.size() != 6 ) {
7220                 return false;
7221             }
7222             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7223                 return false;
7224             }
7225             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7226                 return false;
7227             }
7228             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7229                 return false;
7230             }
7231             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7232                 return false;
7233             }
7234             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7235                 return false;
7236             }
7237             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7238                 return false;
7239             }
7240             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7241             final Phylogeny t13 = factory.create( sb13.toString(), new NHXParser() )[ 0 ];
7242             ext.clear();
7243             t13.getNode( "ab" ).setCollapse( true );
7244             t13.getNode( "b" ).setCollapse( true );
7245             t13.getNode( "fgh" ).setCollapse( true );
7246             t13.getNode( "gh" ).setCollapse( true );
7247             n = t13.getNode( "ab" );
7248             while ( n != null ) {
7249                 ext.add( n );
7250                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7251             }
7252             if ( ext.size() != 5 ) {
7253                 return false;
7254             }
7255             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7256                 return false;
7257             }
7258             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7259                 return false;
7260             }
7261             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7262                 return false;
7263             }
7264             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7265                 return false;
7266             }
7267             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7268                 return false;
7269             }
7270             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
7271             final Phylogeny t14 = factory.create( sb14.toString(), new NHXParser() )[ 0 ];
7272             ext.clear();
7273             t14.getNode( "ab" ).setCollapse( true );
7274             t14.getNode( "a" ).setCollapse( true );
7275             t14.getNode( "fgh" ).setCollapse( true );
7276             t14.getNode( "gh" ).setCollapse( true );
7277             n = t14.getNode( "ab" );
7278             while ( n != null ) {
7279                 ext.add( n );
7280                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7281             }
7282             if ( ext.size() != 5 ) {
7283                 return false;
7284             }
7285             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7286                 return false;
7287             }
7288             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7289                 return false;
7290             }
7291             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7292                 return false;
7293             }
7294             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7295                 return false;
7296             }
7297             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7298                 return false;
7299             }
7300             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" );
7301             final Phylogeny t15 = factory.create( sb15.toString(), new NHXParser() )[ 0 ];
7302             ext.clear();
7303             t15.getNode( "ab" ).setCollapse( true );
7304             t15.getNode( "a" ).setCollapse( true );
7305             t15.getNode( "fgh" ).setCollapse( true );
7306             t15.getNode( "gh" ).setCollapse( true );
7307             n = t15.getNode( "ab" );
7308             while ( n != null ) {
7309                 ext.add( n );
7310                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7311             }
7312             if ( ext.size() != 6 ) {
7313                 return false;
7314             }
7315             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7316                 return false;
7317             }
7318             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7319                 return false;
7320             }
7321             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7322                 return false;
7323             }
7324             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7325                 return false;
7326             }
7327             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
7328                 return false;
7329             }
7330             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7331                 return false;
7332             }
7333             //
7334             //
7335             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" );
7336             final Phylogeny t16 = factory.create( sb16.toString(), new NHXParser() )[ 0 ];
7337             ext.clear();
7338             t16.getNode( "ab" ).setCollapse( true );
7339             t16.getNode( "a" ).setCollapse( true );
7340             t16.getNode( "fgh" ).setCollapse( true );
7341             t16.getNode( "gh" ).setCollapse( true );
7342             t16.getNode( "cd" ).setCollapse( true );
7343             t16.getNode( "cde" ).setCollapse( true );
7344             t16.getNode( "d" ).setCollapse( true );
7345             t16.getNode( "x" ).setCollapse( true );
7346             n = t16.getNode( "ab" );
7347             while ( n != null ) {
7348                 ext.add( n );
7349                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7350             }
7351             if ( ext.size() != 4 ) {
7352                 return false;
7353             }
7354             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7355                 return false;
7356             }
7357             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7358                 return false;
7359             }
7360             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
7361                 return false;
7362             }
7363             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
7364                 return false;
7365             }
7366         }
7367         catch ( final Exception e ) {
7368             e.printStackTrace( System.out );
7369             return false;
7370         }
7371         return true;
7372     }
7373
7374     private static boolean testNexusCharactersParsing() {
7375         try {
7376             final NexusCharactersParser parser = new NexusCharactersParser();
7377             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
7378             parser.parse();
7379             String[] labels = parser.getCharStateLabels();
7380             if ( labels.length != 7 ) {
7381                 return false;
7382             }
7383             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7384                 return false;
7385             }
7386             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7387                 return false;
7388             }
7389             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7390                 return false;
7391             }
7392             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7393                 return false;
7394             }
7395             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7396                 return false;
7397             }
7398             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7399                 return false;
7400             }
7401             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7402                 return false;
7403             }
7404             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7405             parser.parse();
7406             labels = parser.getCharStateLabels();
7407             if ( labels.length != 7 ) {
7408                 return false;
7409             }
7410             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7411                 return false;
7412             }
7413             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7414                 return false;
7415             }
7416             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7417                 return false;
7418             }
7419             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7420                 return false;
7421             }
7422             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7423                 return false;
7424             }
7425             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7426                 return false;
7427             }
7428             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7429                 return false;
7430             }
7431         }
7432         catch ( final Exception e ) {
7433             e.printStackTrace( System.out );
7434             return false;
7435         }
7436         return true;
7437     }
7438
7439     private static boolean testNexusMatrixParsing() {
7440         try {
7441             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7442             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7443             parser.parse();
7444             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7445             if ( m.getNumberOfCharacters() != 9 ) {
7446                 return false;
7447             }
7448             if ( m.getNumberOfIdentifiers() != 5 ) {
7449                 return false;
7450             }
7451             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7452                 return false;
7453             }
7454             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7455                 return false;
7456             }
7457             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7458                 return false;
7459             }
7460             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7461                 return false;
7462             }
7463             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7464                 return false;
7465             }
7466             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7467                 return false;
7468             }
7469             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7470                 return false;
7471             }
7472             //            if ( labels.length != 7 ) {
7473             //                return false;
7474             //            }
7475             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7476             //                return false;
7477             //            }
7478             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7479             //                return false;
7480             //            }
7481             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7482             //                return false;
7483             //            }
7484             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7485             //                return false;
7486             //            }
7487             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7488             //                return false;
7489             //            }
7490             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7491             //                return false;
7492             //            }
7493             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7494             //                return false;
7495             //            }
7496             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7497             //            parser.parse();
7498             //            labels = parser.getCharStateLabels();
7499             //            if ( labels.length != 7 ) {
7500             //                return false;
7501             //            }
7502             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7503             //                return false;
7504             //            }
7505             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7506             //                return false;
7507             //            }
7508             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7509             //                return false;
7510             //            }
7511             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7512             //                return false;
7513             //            }
7514             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7515             //                return false;
7516             //            }
7517             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7518             //                return false;
7519             //            }
7520             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7521             //                return false;
7522             //            }
7523         }
7524         catch ( final Exception e ) {
7525             e.printStackTrace( System.out );
7526             return false;
7527         }
7528         return true;
7529     }
7530
7531     private static boolean testNexusTreeParsing() {
7532         try {
7533             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7534             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7535             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7536             if ( phylogenies.length != 1 ) {
7537                 return false;
7538             }
7539             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7540                 return false;
7541             }
7542             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7543                 return false;
7544             }
7545             phylogenies = null;
7546             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7547             if ( phylogenies.length != 1 ) {
7548                 return false;
7549             }
7550             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7551                 return false;
7552             }
7553             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7554                 return false;
7555             }
7556             phylogenies = null;
7557             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7558             if ( phylogenies.length != 1 ) {
7559                 return false;
7560             }
7561             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7562                 return false;
7563             }
7564             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7565                 return false;
7566             }
7567             if ( phylogenies[ 0 ].isRooted() ) {
7568                 return false;
7569             }
7570             phylogenies = null;
7571             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7572             if ( phylogenies.length != 18 ) {
7573                 return false;
7574             }
7575             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7576                 return false;
7577             }
7578             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7579                 return false;
7580             }
7581             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7582                 return false;
7583             }
7584             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7585                 return false;
7586             }
7587             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7588                 return false;
7589             }
7590             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7591                 return false;
7592             }
7593             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7594                 return false;
7595             }
7596             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7597                 return false;
7598             }
7599             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7600                 return false;
7601             }
7602             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7603                 return false;
7604             }
7605             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7606                 return false;
7607             }
7608             if ( phylogenies[ 8 ].isRooted() ) {
7609                 return false;
7610             }
7611             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7612                 return false;
7613             }
7614             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7615                 return false;
7616             }
7617             if ( !phylogenies[ 9 ].isRooted() ) {
7618                 return false;
7619             }
7620             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7621                 return false;
7622             }
7623             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7624                 return false;
7625             }
7626             if ( !phylogenies[ 10 ].isRooted() ) {
7627                 return false;
7628             }
7629             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7630                 return false;
7631             }
7632             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7633                 return false;
7634             }
7635             if ( phylogenies[ 11 ].isRooted() ) {
7636                 return false;
7637             }
7638             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7639                 return false;
7640             }
7641             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7642                 return false;
7643             }
7644             if ( !phylogenies[ 12 ].isRooted() ) {
7645                 return false;
7646             }
7647             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7648                 return false;
7649             }
7650             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7651                 return false;
7652             }
7653             if ( !phylogenies[ 13 ].isRooted() ) {
7654                 return false;
7655             }
7656             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7657                 return false;
7658             }
7659             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7660                 return false;
7661             }
7662             if ( !phylogenies[ 14 ].isRooted() ) {
7663                 return false;
7664             }
7665             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7666                 return false;
7667             }
7668             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7669                 return false;
7670             }
7671             if ( phylogenies[ 15 ].isRooted() ) {
7672                 return false;
7673             }
7674             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7675                 return false;
7676             }
7677             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7678                 return false;
7679             }
7680             if ( !phylogenies[ 16 ].isRooted() ) {
7681                 return false;
7682             }
7683             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7684                 return false;
7685             }
7686             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7687                 return false;
7688             }
7689             if ( phylogenies[ 17 ].isRooted() ) {
7690                 return false;
7691             }
7692             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7693                 return false;
7694             }
7695             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7696             phylogenies = null;
7697             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7698             if ( phylogenies.length != 9 ) {
7699                 return false;
7700             }
7701             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7702                            .getDistanceToParent() ) ) {
7703                 return false;
7704             }
7705             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7706                            .getDistanceToParent() ) ) {
7707                 return false;
7708             }
7709             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7710                 return false;
7711             }
7712             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7713                 return false;
7714             }
7715             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7716                 return false;
7717             }
7718             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7719                 return false;
7720             }
7721             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7722                 return false;
7723             }
7724         }
7725         catch ( final Exception e ) {
7726             e.printStackTrace( System.out );
7727             return false;
7728         }
7729         return true;
7730     }
7731
7732     private static boolean testNexusTreeParsingIterating() {
7733         try {
7734             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7735             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7736             if ( !p.hasNext() ) {
7737                 return false;
7738             }
7739             Phylogeny phy = p.next();
7740             if ( phy == null ) {
7741                 return false;
7742             }
7743             if ( phy.getNumberOfExternalNodes() != 25 ) {
7744                 return false;
7745             }
7746             if ( !phy.getName().equals( "" ) ) {
7747                 return false;
7748             }
7749             if ( p.hasNext() ) {
7750                 return false;
7751             }
7752             phy = p.next();
7753             if ( phy != null ) {
7754                 return false;
7755             }
7756             p.reset();
7757             if ( !p.hasNext() ) {
7758                 return false;
7759             }
7760             phy = p.next();
7761             if ( phy == null ) {
7762                 return false;
7763             }
7764             if ( phy.getNumberOfExternalNodes() != 25 ) {
7765                 return false;
7766             }
7767             if ( !phy.getName().equals( "" ) ) {
7768                 return false;
7769             }
7770             if ( p.hasNext() ) {
7771                 return false;
7772             }
7773             phy = p.next();
7774             if ( phy != null ) {
7775                 return false;
7776             }
7777             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7778             if ( !p.hasNext() ) {
7779                 return false;
7780             }
7781             phy = p.next();
7782             if ( phy == null ) {
7783                 return false;
7784             }
7785             if ( phy.getNumberOfExternalNodes() != 10 ) {
7786                 return false;
7787             }
7788             if ( !phy.getName().equals( "name" ) ) {
7789                 return false;
7790             }
7791             if ( p.hasNext() ) {
7792                 return false;
7793             }
7794             phy = p.next();
7795             if ( phy != null ) {
7796                 return false;
7797             }
7798             p.reset();
7799             if ( !p.hasNext() ) {
7800                 return false;
7801             }
7802             phy = p.next();
7803             if ( phy == null ) {
7804                 return false;
7805             }
7806             if ( phy.getNumberOfExternalNodes() != 10 ) {
7807                 return false;
7808             }
7809             if ( !phy.getName().equals( "name" ) ) {
7810                 return false;
7811             }
7812             if ( p.hasNext() ) {
7813                 return false;
7814             }
7815             phy = p.next();
7816             if ( phy != null ) {
7817                 return false;
7818             }
7819             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7820             if ( !p.hasNext() ) {
7821                 return false;
7822             }
7823             phy = p.next();
7824             if ( phy == null ) {
7825                 return false;
7826             }
7827             if ( phy.getNumberOfExternalNodes() != 3 ) {
7828                 return false;
7829             }
7830             if ( !phy.getName().equals( "" ) ) {
7831                 return false;
7832             }
7833             if ( phy.isRooted() ) {
7834                 return false;
7835             }
7836             if ( p.hasNext() ) {
7837                 return false;
7838             }
7839             phy = p.next();
7840             if ( phy != null ) {
7841                 return false;
7842             }
7843             //
7844             p.reset();
7845             if ( !p.hasNext() ) {
7846                 return false;
7847             }
7848             phy = p.next();
7849             if ( phy == null ) {
7850                 return false;
7851             }
7852             if ( phy.getNumberOfExternalNodes() != 3 ) {
7853                 return false;
7854             }
7855             if ( !phy.getName().equals( "" ) ) {
7856                 return false;
7857             }
7858             if ( p.hasNext() ) {
7859                 return false;
7860             }
7861             phy = p.next();
7862             if ( phy != null ) {
7863                 return false;
7864             }
7865             //
7866             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7867             if ( !p.hasNext() ) {
7868                 return false;
7869             }
7870             //0
7871             phy = p.next();
7872             if ( phy == null ) {
7873                 return false;
7874             }
7875             if ( phy.getNumberOfExternalNodes() != 10 ) {
7876                 return false;
7877             }
7878             if ( !phy.getName().equals( "tree 0" ) ) {
7879                 return false;
7880             }
7881             //1
7882             if ( !p.hasNext() ) {
7883                 return false;
7884             }
7885             phy = p.next();
7886             if ( phy == null ) {
7887                 return false;
7888             }
7889             if ( phy.getNumberOfExternalNodes() != 10 ) {
7890                 return false;
7891             }
7892             if ( !phy.getName().equals( "tree 1" ) ) {
7893                 return false;
7894             }
7895             //2
7896             if ( !p.hasNext() ) {
7897                 return false;
7898             }
7899             phy = p.next();
7900             if ( phy == null ) {
7901                 return false;
7902             }
7903             if ( phy.getNumberOfExternalNodes() != 3 ) {
7904                 System.out.println( phy.toString() );
7905                 return false;
7906             }
7907             if ( !phy.getName().equals( "" ) ) {
7908                 return false;
7909             }
7910             if ( phy.isRooted() ) {
7911                 return false;
7912             }
7913             //3
7914             if ( !p.hasNext() ) {
7915                 return false;
7916             }
7917             phy = p.next();
7918             if ( phy == null ) {
7919                 return false;
7920             }
7921             if ( phy.getNumberOfExternalNodes() != 4 ) {
7922                 return false;
7923             }
7924             if ( !phy.getName().equals( "" ) ) {
7925                 return false;
7926             }
7927             if ( !phy.isRooted() ) {
7928                 return false;
7929             }
7930             //4
7931             if ( !p.hasNext() ) {
7932                 return false;
7933             }
7934             phy = p.next();
7935             if ( phy == null ) {
7936                 return false;
7937             }
7938             if ( phy.getNumberOfExternalNodes() != 5 ) {
7939                 System.out.println( phy.getNumberOfExternalNodes() );
7940                 return false;
7941             }
7942             if ( !phy.getName().equals( "" ) ) {
7943                 return false;
7944             }
7945             if ( !phy.isRooted() ) {
7946                 return false;
7947             }
7948             //5
7949             if ( !p.hasNext() ) {
7950                 return false;
7951             }
7952             phy = p.next();
7953             if ( phy == null ) {
7954                 return false;
7955             }
7956             if ( phy.getNumberOfExternalNodes() != 3 ) {
7957                 return false;
7958             }
7959             if ( !phy.getName().equals( "" ) ) {
7960                 return false;
7961             }
7962             if ( phy.isRooted() ) {
7963                 return false;
7964             }
7965             //6
7966             if ( !p.hasNext() ) {
7967                 return false;
7968             }
7969             phy = p.next();
7970             if ( phy == null ) {
7971                 return false;
7972             }
7973             if ( phy.getNumberOfExternalNodes() != 2 ) {
7974                 return false;
7975             }
7976             if ( !phy.getName().equals( "" ) ) {
7977                 return false;
7978             }
7979             if ( !phy.isRooted() ) {
7980                 return false;
7981             }
7982             //7
7983             if ( !p.hasNext() ) {
7984                 return false;
7985             }
7986             phy = p.next();
7987             if ( phy.getNumberOfExternalNodes() != 3 ) {
7988                 return false;
7989             }
7990             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7991                 return false;
7992             }
7993             if ( !phy.isRooted() ) {
7994                 return false;
7995             }
7996             //8
7997             if ( !p.hasNext() ) {
7998                 return false;
7999             }
8000             phy = p.next();
8001             if ( phy.getNumberOfExternalNodes() != 3 ) {
8002                 return false;
8003             }
8004             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
8005                 return false;
8006             }
8007             if ( !phy.getName().equals( "tree 8" ) ) {
8008                 return false;
8009             }
8010             //9
8011             if ( !p.hasNext() ) {
8012                 return false;
8013             }
8014             phy = p.next();
8015             if ( phy.getNumberOfExternalNodes() != 3 ) {
8016                 return false;
8017             }
8018             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
8019                 return false;
8020             }
8021             if ( !phy.getName().equals( "tree 9" ) ) {
8022                 return false;
8023             }
8024             //10
8025             if ( !p.hasNext() ) {
8026                 return false;
8027             }
8028             phy = p.next();
8029             if ( phy.getNumberOfExternalNodes() != 3 ) {
8030                 return false;
8031             }
8032             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8033                 return false;
8034             }
8035             if ( !phy.getName().equals( "tree 10" ) ) {
8036                 return false;
8037             }
8038             if ( !phy.isRooted() ) {
8039                 return false;
8040             }
8041             //11
8042             if ( !p.hasNext() ) {
8043                 return false;
8044             }
8045             phy = p.next();
8046             if ( phy.getNumberOfExternalNodes() != 3 ) {
8047                 return false;
8048             }
8049             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
8050                 return false;
8051             }
8052             if ( !phy.getName().equals( "tree 11" ) ) {
8053                 return false;
8054             }
8055             if ( phy.isRooted() ) {
8056                 return false;
8057             }
8058             //12
8059             if ( !p.hasNext() ) {
8060                 return false;
8061             }
8062             phy = p.next();
8063             if ( phy.getNumberOfExternalNodes() != 3 ) {
8064                 return false;
8065             }
8066             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
8067                 return false;
8068             }
8069             if ( !phy.getName().equals( "tree 12" ) ) {
8070                 return false;
8071             }
8072             if ( !phy.isRooted() ) {
8073                 return false;
8074             }
8075             //13
8076             if ( !p.hasNext() ) {
8077                 return false;
8078             }
8079             phy = p.next();
8080             if ( phy.getNumberOfExternalNodes() != 3 ) {
8081                 return false;
8082             }
8083             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8084                 return false;
8085             }
8086             if ( !phy.getName().equals( "tree 13" ) ) {
8087                 return false;
8088             }
8089             if ( !phy.isRooted() ) {
8090                 return false;
8091             }
8092             //14
8093             if ( !p.hasNext() ) {
8094                 return false;
8095             }
8096             phy = p.next();
8097             if ( phy.getNumberOfExternalNodes() != 10 ) {
8098                 System.out.println( phy.getNumberOfExternalNodes() );
8099                 return false;
8100             }
8101             if ( !phy
8102                     .toNewHampshire()
8103                     .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;" ) ) {
8104                 System.out.println( phy.toNewHampshire() );
8105                 return false;
8106             }
8107             if ( !phy.getName().equals( "tree 14" ) ) {
8108                 return false;
8109             }
8110             if ( !phy.isRooted() ) {
8111                 return false;
8112             }
8113             //15
8114             if ( !p.hasNext() ) {
8115                 return false;
8116             }
8117             phy = p.next();
8118             if ( phy.getNumberOfExternalNodes() != 10 ) {
8119                 System.out.println( phy.getNumberOfExternalNodes() );
8120                 return false;
8121             }
8122             if ( !phy
8123                     .toNewHampshire()
8124                     .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;" ) ) {
8125                 System.out.println( phy.toNewHampshire() );
8126                 return false;
8127             }
8128             if ( !phy.getName().equals( "tree 15" ) ) {
8129                 return false;
8130             }
8131             if ( phy.isRooted() ) {
8132                 return false;
8133             }
8134             //16
8135             if ( !p.hasNext() ) {
8136                 return false;
8137             }
8138             phy = p.next();
8139             if ( phy.getNumberOfExternalNodes() != 10 ) {
8140                 System.out.println( phy.getNumberOfExternalNodes() );
8141                 return false;
8142             }
8143             if ( !phy
8144                     .toNewHampshire()
8145                     .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;" ) ) {
8146                 System.out.println( phy.toNewHampshire() );
8147                 return false;
8148             }
8149             if ( !phy.getName().equals( "tree 16" ) ) {
8150                 return false;
8151             }
8152             if ( !phy.isRooted() ) {
8153                 return false;
8154             }
8155             //17
8156             if ( !p.hasNext() ) {
8157                 return false;
8158             }
8159             phy = p.next();
8160             if ( phy.getNumberOfExternalNodes() != 10 ) {
8161                 System.out.println( phy.getNumberOfExternalNodes() );
8162                 return false;
8163             }
8164             if ( !phy
8165                     .toNewHampshire()
8166                     .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;" ) ) {
8167                 System.out.println( phy.toNewHampshire() );
8168                 return false;
8169             }
8170             if ( !phy.getName().equals( "tree 17" ) ) {
8171                 return false;
8172             }
8173             if ( phy.isRooted() ) {
8174                 return false;
8175             }
8176             //
8177             if ( p.hasNext() ) {
8178                 return false;
8179             }
8180             phy = p.next();
8181             if ( phy != null ) {
8182                 return false;
8183             }
8184             p.reset();
8185             //0
8186             if ( !p.hasNext() ) {
8187                 return false;
8188             }
8189             phy = p.next();
8190             if ( phy == null ) {
8191                 return false;
8192             }
8193             if ( phy.getNumberOfExternalNodes() != 10 ) {
8194                 return false;
8195             }
8196             if ( !phy.getName().equals( "tree 0" ) ) {
8197                 return false;
8198             }
8199             //1
8200             if ( !p.hasNext() ) {
8201                 return false;
8202             }
8203             phy = p.next();
8204             if ( phy == null ) {
8205                 return false;
8206             }
8207             if ( phy.getNumberOfExternalNodes() != 10 ) {
8208                 return false;
8209             }
8210             if ( !phy.getName().equals( "tree 1" ) ) {
8211                 return false;
8212             }
8213             //2
8214             if ( !p.hasNext() ) {
8215                 return false;
8216             }
8217             phy = p.next();
8218             if ( phy == null ) {
8219                 return false;
8220             }
8221             if ( phy.getNumberOfExternalNodes() != 3 ) {
8222                 return false;
8223             }
8224             if ( !phy.getName().equals( "" ) ) {
8225                 return false;
8226             }
8227             if ( phy.isRooted() ) {
8228                 return false;
8229             }
8230             //3
8231             if ( !p.hasNext() ) {
8232                 return false;
8233             }
8234             phy = p.next();
8235             if ( phy == null ) {
8236                 return false;
8237             }
8238             if ( phy.getNumberOfExternalNodes() != 4 ) {
8239                 return false;
8240             }
8241             if ( !phy.getName().equals( "" ) ) {
8242                 return false;
8243             }
8244             if ( !phy.isRooted() ) {
8245                 return false;
8246             }
8247             //4
8248             if ( !p.hasNext() ) {
8249                 return false;
8250             }
8251             phy = p.next();
8252             if ( phy == null ) {
8253                 return false;
8254             }
8255             if ( phy.getNumberOfExternalNodes() != 5 ) {
8256                 System.out.println( phy.getNumberOfExternalNodes() );
8257                 return false;
8258             }
8259             if ( !phy.getName().equals( "" ) ) {
8260                 return false;
8261             }
8262             if ( !phy.isRooted() ) {
8263                 return false;
8264             }
8265             //5
8266             if ( !p.hasNext() ) {
8267                 return false;
8268             }
8269             phy = p.next();
8270             if ( phy == null ) {
8271                 return false;
8272             }
8273             if ( phy.getNumberOfExternalNodes() != 3 ) {
8274                 return false;
8275             }
8276             if ( !phy.getName().equals( "" ) ) {
8277                 return false;
8278             }
8279             if ( phy.isRooted() ) {
8280                 return false;
8281             }
8282             //
8283             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
8284             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
8285             // 0
8286             if ( !p2.hasNext() ) {
8287                 return false;
8288             }
8289             phy = p2.next();
8290             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8291                 return false;
8292             }
8293             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8294                 return false;
8295             }
8296             // 1
8297             if ( !p2.hasNext() ) {
8298                 return false;
8299             }
8300             phy = p2.next();
8301             // 2
8302             if ( !p2.hasNext() ) {
8303                 return false;
8304             }
8305             phy = p2.next();
8306             // 3
8307             if ( !p2.hasNext() ) {
8308                 return false;
8309             }
8310             phy = p2.next();
8311             // 4
8312             if ( !p2.hasNext() ) {
8313                 return false;
8314             }
8315             phy = p2.next();
8316             // 5
8317             if ( !p2.hasNext() ) {
8318                 return false;
8319             }
8320             phy = p2.next();
8321             // 6
8322             if ( !p2.hasNext() ) {
8323                 return false;
8324             }
8325             phy = p2.next();
8326             // 7
8327             if ( !p2.hasNext() ) {
8328                 return false;
8329             }
8330             phy = p2.next();
8331             // 8
8332             if ( !p2.hasNext() ) {
8333                 return false;
8334             }
8335             phy = p2.next();
8336             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
8337                 return false;
8338             }
8339             if ( p2.hasNext() ) {
8340                 return false;
8341             }
8342             phy = p2.next();
8343             if ( phy != null ) {
8344                 return false;
8345             }
8346             // 0
8347             p2.reset();
8348             if ( !p2.hasNext() ) {
8349                 return false;
8350             }
8351             phy = p2.next();
8352             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8353                 return false;
8354             }
8355             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8356                 return false;
8357             }
8358         }
8359         catch ( final Exception e ) {
8360             e.printStackTrace( System.out );
8361             return false;
8362         }
8363         return true;
8364     }
8365
8366     private static boolean testNexusTreeParsingTranslating() {
8367         try {
8368             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8369             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
8370             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
8371             if ( phylogenies.length != 1 ) {
8372                 return false;
8373             }
8374             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8375                 return false;
8376             }
8377             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8378                 return false;
8379             }
8380             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8381                 return false;
8382             }
8383             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8384                 return false;
8385             }
8386             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8387                     .equals( "Aranaeus" ) ) {
8388                 return false;
8389             }
8390             phylogenies = null;
8391             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
8392             if ( phylogenies.length != 3 ) {
8393                 return false;
8394             }
8395             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8396                 return false;
8397             }
8398             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8399                 return false;
8400             }
8401             if ( phylogenies[ 0 ].isRooted() ) {
8402                 return false;
8403             }
8404             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8405                 return false;
8406             }
8407             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8408                 return false;
8409             }
8410             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8411                     .equals( "Aranaeus" ) ) {
8412                 return false;
8413             }
8414             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8415                 return false;
8416             }
8417             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8418                 return false;
8419             }
8420             if ( phylogenies[ 1 ].isRooted() ) {
8421                 return false;
8422             }
8423             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8424                 return false;
8425             }
8426             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8427                 return false;
8428             }
8429             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8430                     .equals( "Aranaeus" ) ) {
8431                 return false;
8432             }
8433             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8434                 return false;
8435             }
8436             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8437                 return false;
8438             }
8439             if ( !phylogenies[ 2 ].isRooted() ) {
8440                 return false;
8441             }
8442             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8443                 return false;
8444             }
8445             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8446                 return false;
8447             }
8448             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8449                     .equals( "Aranaeus" ) ) {
8450                 return false;
8451             }
8452             phylogenies = null;
8453             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8454             if ( phylogenies.length != 3 ) {
8455                 return false;
8456             }
8457             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8458                 return false;
8459             }
8460             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8461                 return false;
8462             }
8463             if ( phylogenies[ 0 ].isRooted() ) {
8464                 return false;
8465             }
8466             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8467                 return false;
8468             }
8469             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8470                 return false;
8471             }
8472             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8473                     .equals( "Aranaeus" ) ) {
8474                 return false;
8475             }
8476             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8477                 return false;
8478             }
8479             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8480                 return false;
8481             }
8482             if ( phylogenies[ 1 ].isRooted() ) {
8483                 return false;
8484             }
8485             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8486                 return false;
8487             }
8488             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8489                 return false;
8490             }
8491             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8492                     .equals( "Aranaeus" ) ) {
8493                 return false;
8494             }
8495             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8496                 return false;
8497             }
8498             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8499                 return false;
8500             }
8501             if ( !phylogenies[ 2 ].isRooted() ) {
8502                 return false;
8503             }
8504             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8505                 return false;
8506             }
8507             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8508                 return false;
8509             }
8510             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8511                     .equals( "Aranaeus" ) ) {
8512                 return false;
8513             }
8514             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8515             if ( phylogenies.length != 3 ) {
8516                 return false;
8517             }
8518             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8519                            0.00100049 ) ) {
8520                 return false;
8521             }
8522         }
8523         catch ( final Exception e ) {
8524             e.printStackTrace( System.out );
8525             return false;
8526         }
8527         return true;
8528     }
8529
8530     private static boolean testNHParsing() {
8531         try {
8532             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8533             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8534             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8535                 return false;
8536             }
8537             final NHXParser nhxp = new NHXParser();
8538             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8539             nhxp.setReplaceUnderscores( true );
8540             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8541             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8542                 return false;
8543             }
8544             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8545                 return false;
8546             }
8547             final Phylogeny p1b = factory
8548                     .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 ",
8549                              new NHXParser() )[ 0 ];
8550             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8551                 return false;
8552             }
8553             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8554                 return false;
8555             }
8556             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ).toString(), new NHXParser() )[ 0 ];
8557             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8558             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8559             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ).toString(), new NHXParser() )[ 0 ];
8560             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8561             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8562             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8563             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8564             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8565             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8566             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8567                     + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8568                     + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8569                     new NHXParser() );
8570             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8571                 return false;
8572             }
8573             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8574                 return false;
8575             }
8576             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8577                 return false;
8578             }
8579             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8580                 return false;
8581             }
8582             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8583             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8584             final String p16_S = "((A,B),C)";
8585             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8586             if ( p16.length != 1 ) {
8587                 return false;
8588             }
8589             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8590                 return false;
8591             }
8592             final String p17_S = "(C,(A,B))";
8593             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8594             if ( p17.length != 1 ) {
8595                 return false;
8596             }
8597             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8598                 return false;
8599             }
8600             final String p18_S = "((A,B),(C,D))";
8601             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8602             if ( p18.length != 1 ) {
8603                 return false;
8604             }
8605             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8606                 return false;
8607             }
8608             final String p19_S = "(((A,B),C),D)";
8609             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8610             if ( p19.length != 1 ) {
8611                 return false;
8612             }
8613             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8614                 return false;
8615             }
8616             final String p20_S = "(A,(B,(C,D)))";
8617             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8618             if ( p20.length != 1 ) {
8619                 return false;
8620             }
8621             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8622                 return false;
8623             }
8624             final String p21_S = "(A,(B,(C,(D,E))))";
8625             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8626             if ( p21.length != 1 ) {
8627                 return false;
8628             }
8629             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8630                 return false;
8631             }
8632             final String p22_S = "((((A,B),C),D),E)";
8633             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8634             if ( p22.length != 1 ) {
8635                 return false;
8636             }
8637             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8638                 return false;
8639             }
8640             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8641             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8642             if ( p23.length != 1 ) {
8643                 System.out.println( "xl=" + p23.length );
8644                 System.exit( -1 );
8645                 return false;
8646             }
8647             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8648                 return false;
8649             }
8650             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8651             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8652             if ( p24.length != 1 ) {
8653                 return false;
8654             }
8655             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8656                 return false;
8657             }
8658             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8659             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8660             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8661             if ( p241.length != 2 ) {
8662                 return false;
8663             }
8664             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8665                 return false;
8666             }
8667             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8668                 return false;
8669             }
8670             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8671                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8672                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8673                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8674                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8675                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8676                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8677                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8678             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8679             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8680                 return false;
8681             }
8682             final String p26_S = "(A,B)ab";
8683             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8684             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8685                 return false;
8686             }
8687             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8688             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8689             if ( p27s.length != 1 ) {
8690                 System.out.println( "xxl=" + p27s.length );
8691                 System.exit( -1 );
8692                 return false;
8693             }
8694             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8695                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8696                 System.exit( -1 );
8697                 return false;
8698             }
8699             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8700                                                     new NHXParser() );
8701             if ( p27.length != 1 ) {
8702                 System.out.println( "yl=" + p27.length );
8703                 System.exit( -1 );
8704                 return false;
8705             }
8706             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8707                 System.out.println( p27[ 0 ].toNewHampshireX() );
8708                 System.exit( -1 );
8709                 return false;
8710             }
8711             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8712             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8713             final String p28_S3 = "(A,B)ab";
8714             final String p28_S4 = "((((A,B),C),D),;E;)";
8715             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8716                                                     new NHXParser() );
8717             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8718                 return false;
8719             }
8720             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8721                 return false;
8722             }
8723             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8724                 return false;
8725             }
8726             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8727                 return false;
8728             }
8729             if ( p28.length != 4 ) {
8730                 return false;
8731             }
8732             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";
8733             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8734             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8735                 return false;
8736             }
8737             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";
8738             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8739             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8740                 return false;
8741             }
8742             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8743             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8744             if ( ( p32.length != 0 ) ) {
8745                 return false;
8746             }
8747             final String p33_S = "A";
8748             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8749             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8750                 return false;
8751             }
8752             final String p34_S = "B;";
8753             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8754             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8755                 return false;
8756             }
8757             final String p35_S = "B:0.2";
8758             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8759             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8760                 return false;
8761             }
8762             final String p36_S = "(A)";
8763             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8764             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8765                 return false;
8766             }
8767             final String p37_S = "((A))";
8768             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8769             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8770                 return false;
8771             }
8772             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8773             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8774             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8775                 return false;
8776             }
8777             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8778             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8779             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8780                 return false;
8781             }
8782             final String p40_S = "(A,B,C)";
8783             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8784             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8785                 return false;
8786             }
8787             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8788             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8789             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8790                 return false;
8791             }
8792             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8793             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8794             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8795                 return false;
8796             }
8797             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)";
8798             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8799             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8800                 return false;
8801             }
8802             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)))";
8803             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8804             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8805                 return false;
8806             }
8807             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8808             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8809             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8810                 return false;
8811             }
8812             final String p46_S = "";
8813             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8814             if ( p46.length != 0 ) {
8815                 return false;
8816             }
8817             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ).toString(), new NHXParser() )[ 0 ];
8818             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8819                 return false;
8820             }
8821             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8822             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8823                 return false;
8824             }
8825             final Phylogeny p49 = factory
8826                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ).toString(),
8827                              new NHXParser() )[ 0 ];
8828             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8829                 return false;
8830             }
8831             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8832             if ( p50.getNode( "A" ) == null ) {
8833                 return false;
8834             }
8835             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8836                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8837                 return false;
8838             }
8839             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8840                 return false;
8841             }
8842             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8843                     .equals( "((A,B)88:2.0,C);" ) ) {
8844                 return false;
8845             }
8846             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8847             if ( p51.getNode( "A(A" ) == null ) {
8848                 return false;
8849             }
8850             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8851             if ( p52.getNode( "A(A" ) == null ) {
8852                 return false;
8853             }
8854             final Phylogeny p53 = factory
8855                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ).toString(),
8856                              new NHXParser() )[ 0 ];
8857             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8858                 return false;
8859             }
8860             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ).toString(), new NHXParser() )[ 0 ];
8861             if ( p54.getNode( "A" ) == null ) {
8862                 return false;
8863             }
8864             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8865                 return false;
8866             }
8867             final Phylogeny p55 = factory
8868                     .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(),
8869                              new NHXParser() )[ 0 ];
8870             if ( !p55
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.1x:0.0798012);" ) ) {
8873                 System.out.println( p55.toNewHampshire() );
8874                 return false;
8875             }
8876             final Phylogeny p56 = 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 ( !p56
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 Phylogeny p57 = factory
8886                     .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(),
8887                              new NHXParser() )[ 0 ];
8888             if ( !p57
8889                     .toNewHampshire()
8890                     .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);" ) ) {
8891                 System.out.println( p56.toNewHampshire() );
8892                 return false;
8893             }
8894             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8895             final Phylogeny p58 = factory.create( s58, new NHXParser() )[ 0 ];
8896             if ( !p58.toNewHampshire().equals( s58 ) ) {
8897                 System.out.println( p58.toNewHampshire() );
8898                 return false;
8899             }
8900             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8901             final Phylogeny p59 = factory.create( s59 , new NHXParser() )[ 0 ];
8902             if ( !p59.toNewHampshire().equals( s59 ) ) {
8903                 System.out.println( p59.toNewHampshire() );
8904                 return false;
8905             }
8906             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8907             final Phylogeny p60 = factory.create( s60, new NHXParser() )[ 0 ];
8908             if ( !p60.toNewHampshire().equals( s60 ) ) {
8909                 System.out.println( p60.toNewHampshire() );
8910                 return false;
8911             }
8912             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8913             final Phylogeny p61 = factory.create( s61, new NHXParser() )[ 0 ];
8914             if ( !p61.toNewHampshire()
8915                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8916                 System.out.println( p61.toNewHampshire() );
8917                 return false;
8918             }
8919         }
8920         catch ( final Exception e ) {
8921             e.printStackTrace( System.out );
8922             return false;
8923         }
8924         return true;
8925     }
8926     
8927     private static boolean testNHParsingSpecialChars() {
8928         try {
8929             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();   
8930             final String i0 = "(A!+=~QWERTY!@#$%^&*-,€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ)";
8931             final Phylogeny p0 = factory.create( i0, new NHXParser() )[ 0 ];
8932             if ( !p0.toNewHampshireX().equals( i0 ) ) {
8933                 System.out.println();
8934                 System.out.println( p0.toNewHampshireX() );
8935                 System.out.println( i0 );
8936                 return false;
8937             }
8938             final String i1 = "(हिंदी,한글,ไทย,'Tiếng Việt',ひらがなカタカナ漢字,繁體字,русский)";
8939             final Phylogeny p1 = factory.create( i1, new NHXParser() )[ 0 ];
8940             if ( !p1.toNewHampshireX().equals( i1 ) ) {
8941                 System.out.println();
8942                 System.out.println( p1.toNewHampshireX() );
8943                 System.out.println( i1 );
8944                 return false;
8945             }
8946         }
8947         catch ( final Exception e ) {
8948             e.printStackTrace( System.out );
8949             return false;
8950         }
8951         return true;
8952     }
8953     
8954     
8955     
8956     private static boolean testNHParsingIter() {
8957         try {
8958             final String p0_str = "(A,B);";
8959             final NHXParser p = new NHXParser();
8960             p.setSource( p0_str );
8961             if ( !p.hasNext() ) {
8962                 return false;
8963             }
8964             final Phylogeny p0 = p.next();
8965             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8966                 System.out.println( p0.toNewHampshire() );
8967                 return false;
8968             }
8969             if ( p.hasNext() ) {
8970                 return false;
8971             }
8972             if ( p.next() != null ) {
8973                 return false;
8974             }
8975             //
8976             final String p00_str = "(A,B)root;";
8977             p.setSource( p00_str );
8978             final Phylogeny p00 = p.next();
8979             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8980                 System.out.println( p00.toNewHampshire() );
8981                 return false;
8982             }
8983             //
8984             final String p000_str = "A;";
8985             p.setSource( p000_str );
8986             final Phylogeny p000 = p.next();
8987             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8988                 System.out.println( p000.toNewHampshire() );
8989                 return false;
8990             }
8991             //
8992             final String p0000_str = "A";
8993             p.setSource( p0000_str );
8994             final Phylogeny p0000 = p.next();
8995             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8996                 System.out.println( p0000.toNewHampshire() );
8997                 return false;
8998             }
8999             //
9000             p.setSource( "(A)" );
9001             final Phylogeny p00000 = p.next();
9002             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
9003                 System.out.println( p00000.toNewHampshire() );
9004                 return false;
9005             }
9006             //
9007             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
9008             p.setSource( p1_str );
9009             if ( !p.hasNext() ) {
9010                 return false;
9011             }
9012             final Phylogeny p1_0 = p.next();
9013             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
9014                 System.out.println( p1_0.toNewHampshire() );
9015                 return false;
9016             }
9017             if ( !p.hasNext() ) {
9018                 return false;
9019             }
9020             final Phylogeny p1_1 = p.next();
9021             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
9022                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
9023                 return false;
9024             }
9025             if ( !p.hasNext() ) {
9026                 return false;
9027             }
9028             final Phylogeny p1_2 = p.next();
9029             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
9030                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
9031                 return false;
9032             }
9033             if ( !p.hasNext() ) {
9034                 return false;
9035             }
9036             final Phylogeny p1_3 = p.next();
9037             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
9038                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
9039                 return false;
9040             }
9041             if ( p.hasNext() ) {
9042                 return false;
9043             }
9044             if ( p.next() != null ) {
9045                 return false;
9046             }
9047             //
9048             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
9049             p.setSource( p2_str );
9050             if ( !p.hasNext() ) {
9051                 return false;
9052             }
9053             Phylogeny p2_0 = p.next();
9054             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9055                 System.out.println( p2_0.toNewHampshire() );
9056                 return false;
9057             }
9058             if ( !p.hasNext() ) {
9059                 return false;
9060             }
9061             Phylogeny p2_1 = p.next();
9062             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9063                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9064                 return false;
9065             }
9066             if ( !p.hasNext() ) {
9067                 return false;
9068             }
9069             Phylogeny p2_2 = p.next();
9070             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9071                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9072                 return false;
9073             }
9074             if ( !p.hasNext() ) {
9075                 return false;
9076             }
9077             Phylogeny p2_3 = p.next();
9078             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9079                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9080                 return false;
9081             }
9082             if ( !p.hasNext() ) {
9083                 return false;
9084             }
9085             Phylogeny p2_4 = p.next();
9086             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9087                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9088                 return false;
9089             }
9090             if ( p.hasNext() ) {
9091                 return false;
9092             }
9093             if ( p.next() != null ) {
9094                 return false;
9095             }
9096             ////
9097             p.reset();
9098             if ( !p.hasNext() ) {
9099                 return false;
9100             }
9101             p2_0 = p.next();
9102             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9103                 System.out.println( p2_0.toNewHampshire() );
9104                 return false;
9105             }
9106             if ( !p.hasNext() ) {
9107                 return false;
9108             }
9109             p2_1 = p.next();
9110             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9111                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9112                 return false;
9113             }
9114             if ( !p.hasNext() ) {
9115                 return false;
9116             }
9117             p2_2 = p.next();
9118             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9119                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9120                 return false;
9121             }
9122             if ( !p.hasNext() ) {
9123                 return false;
9124             }
9125             p2_3 = p.next();
9126             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9127                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9128                 return false;
9129             }
9130             if ( !p.hasNext() ) {
9131                 return false;
9132             }
9133             p2_4 = p.next();
9134             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9135                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9136                 return false;
9137             }
9138             if ( p.hasNext() ) {
9139                 return false;
9140             }
9141             if ( p.next() != null ) {
9142                 return false;
9143             }
9144             //
9145             final String p3_str = "((A,B),C)abc";
9146             p.setSource( p3_str );
9147             if ( !p.hasNext() ) {
9148                 return false;
9149             }
9150             final Phylogeny p3_0 = p.next();
9151             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
9152                 return false;
9153             }
9154             if ( p.hasNext() ) {
9155                 return false;
9156             }
9157             if ( p.next() != null ) {
9158                 return false;
9159             }
9160             //
9161             final String p4_str = "((A,B)ab,C)abc";
9162             p.setSource( p4_str );
9163             if ( !p.hasNext() ) {
9164                 return false;
9165             }
9166             final Phylogeny p4_0 = p.next();
9167             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
9168                 return false;
9169             }
9170             if ( p.hasNext() ) {
9171                 return false;
9172             }
9173             if ( p.next() != null ) {
9174                 return false;
9175             }
9176             //
9177             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
9178             p.setSource( p5_str );
9179             if ( !p.hasNext() ) {
9180                 return false;
9181             }
9182             final Phylogeny p5_0 = p.next();
9183             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
9184                 return false;
9185             }
9186             if ( p.hasNext() ) {
9187                 return false;
9188             }
9189             if ( p.next() != null ) {
9190                 return false;
9191             }
9192             //
9193             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
9194             p.setSource( p6_str );
9195             if ( !p.hasNext() ) {
9196                 return false;
9197             }
9198             Phylogeny p6_0 = p.next();
9199             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9200                 return false;
9201             }
9202             if ( p.hasNext() ) {
9203                 return false;
9204             }
9205             if ( p.next() != null ) {
9206                 return false;
9207             }
9208             p.reset();
9209             if ( !p.hasNext() ) {
9210                 return false;
9211             }
9212             p6_0 = p.next();
9213             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9214                 return false;
9215             }
9216             if ( p.hasNext() ) {
9217                 return false;
9218             }
9219             if ( p.next() != null ) {
9220                 return false;
9221             }
9222             //
9223             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
9224             p.setSource( p7_str );
9225             if ( !p.hasNext() ) {
9226                 return false;
9227             }
9228             Phylogeny p7_0 = p.next();
9229             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9230                 return false;
9231             }
9232             if ( p.hasNext() ) {
9233                 return false;
9234             }
9235             if ( p.next() != null ) {
9236                 return false;
9237             }
9238             p.reset();
9239             if ( !p.hasNext() ) {
9240                 return false;
9241             }
9242             p7_0 = p.next();
9243             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9244                 return false;
9245             }
9246             if ( p.hasNext() ) {
9247                 return false;
9248             }
9249             if ( p.next() != null ) {
9250                 return false;
9251             }
9252             //
9253             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
9254             p.setSource( p8_str );
9255             if ( !p.hasNext() ) {
9256                 return false;
9257             }
9258             Phylogeny p8_0 = p.next();
9259             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9260                 return false;
9261             }
9262             if ( !p.hasNext() ) {
9263                 return false;
9264             }
9265             if ( !p.hasNext() ) {
9266                 return false;
9267             }
9268             Phylogeny p8_1 = p.next();
9269             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9270                 return false;
9271             }
9272             if ( p.hasNext() ) {
9273                 return false;
9274             }
9275             if ( p.next() != null ) {
9276                 return false;
9277             }
9278             p.reset();
9279             if ( !p.hasNext() ) {
9280                 return false;
9281             }
9282             p8_0 = p.next();
9283             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9284                 return false;
9285             }
9286             if ( !p.hasNext() ) {
9287                 return false;
9288             }
9289             p8_1 = p.next();
9290             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9291                 return false;
9292             }
9293             if ( p.hasNext() ) {
9294                 return false;
9295             }
9296             if ( p.next() != null ) {
9297                 return false;
9298             }
9299             p.reset();
9300             //
9301             p.setSource( "" );
9302             if ( p.hasNext() ) {
9303                 return false;
9304             }
9305             //
9306             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
9307             if ( !p.hasNext() ) {
9308                 return false;
9309             }
9310             Phylogeny p_27 = p.next();
9311             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9312                 System.out.println( p_27.toNewHampshireX() );
9313                 System.exit( -1 );
9314                 return false;
9315             }
9316             if ( p.hasNext() ) {
9317                 return false;
9318             }
9319             if ( p.next() != null ) {
9320                 return false;
9321             }
9322             p.reset();
9323             if ( !p.hasNext() ) {
9324                 return false;
9325             }
9326             p_27 = p.next();
9327             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9328                 System.out.println( p_27.toNewHampshireX() );
9329                 System.exit( -1 );
9330                 return false;
9331             }
9332             if ( p.hasNext() ) {
9333                 return false;
9334             }
9335             if ( p.next() != null ) {
9336                 return false;
9337             }
9338             //
9339             final String p30_str = "(A,B);(C,D)";
9340             final NHXParser p30 = new NHXParser();
9341             p30.setSource( p30_str );
9342             if ( !p30.hasNext() ) {
9343                 return false;
9344             }
9345             Phylogeny phy30 = p30.next();
9346             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9347                 System.out.println( phy30.toNewHampshire() );
9348                 return false;
9349             }
9350             if ( !p30.hasNext() ) {
9351                 return false;
9352             }
9353             Phylogeny phy301 = p30.next();
9354             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9355                 System.out.println( phy301.toNewHampshire() );
9356                 return false;
9357             }
9358             if ( p30.hasNext() ) {
9359                 return false;
9360             }
9361             if ( p30.hasNext() ) {
9362                 return false;
9363             }
9364             if ( p30.next() != null ) {
9365                 return false;
9366             }
9367             if ( p30.next() != null ) {
9368                 return false;
9369             }
9370             p30.reset();
9371             if ( !p30.hasNext() ) {
9372                 return false;
9373             }
9374             phy30 = p30.next();
9375             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9376                 System.out.println( phy30.toNewHampshire() );
9377                 return false;
9378             }
9379             if ( !p30.hasNext() ) {
9380                 return false;
9381             }
9382             phy301 = p30.next();
9383             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9384                 System.out.println( phy301.toNewHampshire() );
9385                 return false;
9386             }
9387             if ( p30.hasNext() ) {
9388                 return false;
9389             }
9390             if ( p30.hasNext() ) {
9391                 return false;
9392             }
9393             if ( p30.next() != null ) {
9394                 return false;
9395             }
9396             if ( p30.next() != null ) {
9397                 return false;
9398             }
9399         }
9400         catch ( final Exception e ) {
9401             e.printStackTrace( System.out );
9402             return false;
9403         }
9404         return true;
9405     }
9406
9407     private static boolean testNHXconversion() {
9408         try {
9409             final PhylogenyNode n1 = new PhylogenyNode();
9410             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9411             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9412             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9413             final PhylogenyNode n5 = PhylogenyNode
9414                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
9415             final PhylogenyNode n6 = PhylogenyNode
9416                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
9417             if ( !n1.toNewHampshireX().equals( "" ) ) {
9418                 return false;
9419             }
9420             if ( !n2.toNewHampshireX().equals( "" ) ) {
9421                 return false;
9422             }
9423             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
9424                 return false;
9425             }
9426             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
9427                 return false;
9428             }
9429             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
9430                 return false;
9431             }
9432             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9433                 System.out.println( n6.toNewHampshireX() );
9434                 return false;
9435             }
9436             final PhylogenyNode n7 = new PhylogenyNode();
9437             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9438             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9439                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9440                 System.out.println( n7
9441                                     .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9442                 return false;
9443             }
9444         }
9445         catch ( final Exception e ) {
9446             e.printStackTrace( System.out );
9447             return false;
9448         }
9449         return true;
9450     }
9451
9452     private static boolean testNHXNodeParsing() {
9453         try {
9454             final PhylogenyNode n1 = new PhylogenyNode();
9455             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9456             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9457             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9458             final PhylogenyNode n5 = PhylogenyNode
9459                     .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]" );
9460             if ( !n3.getName().equals( "n3" ) ) {
9461                 return false;
9462             }
9463             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9464                 return false;
9465             }
9466             if ( n3.isDuplication() ) {
9467                 return false;
9468             }
9469             if ( n3.isHasAssignedEvent() ) {
9470                 return false;
9471             }
9472             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9473                 return false;
9474             }
9475             if ( !n4.getName().equals( "n4" ) ) {
9476                 return false;
9477             }
9478             if ( n4.getDistanceToParent() != 0.01 ) {
9479                 return false;
9480             }
9481             if ( !n5.getName().equals( "n5" ) ) {
9482                 return false;
9483             }
9484             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9485                 return false;
9486             }
9487             if ( n5.getDistanceToParent() != 0.1 ) {
9488                 return false;
9489             }
9490             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9491                 return false;
9492             }
9493             if ( !n5.isDuplication() ) {
9494                 return false;
9495             }
9496             if ( !n5.isHasAssignedEvent() ) {
9497                 return false;
9498             }
9499             final PhylogenyNode n8 = PhylogenyNode
9500                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9501                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9502             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9503                 return false;
9504             }
9505             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9506                 return false;
9507             }
9508             final PhylogenyNode n9 = PhylogenyNode
9509                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9510                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9511             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9512                 return false;
9513             }
9514             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9515                 return false;
9516             }
9517             final PhylogenyNode n10 = PhylogenyNode
9518                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9519             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9520                 return false;
9521             }
9522             final PhylogenyNode n20 = PhylogenyNode
9523                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9524             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9525                 return false;
9526             }
9527             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9528                 return false;
9529             }
9530             final PhylogenyNode n20x = PhylogenyNode
9531                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9532             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9533                 return false;
9534             }
9535             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9536                 return false;
9537             }
9538             final PhylogenyNode n20xx = PhylogenyNode
9539                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9540             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9541                 return false;
9542             }
9543             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9544                 return false;
9545             }
9546             final PhylogenyNode n20xxx = PhylogenyNode
9547                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9548             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9549                 return false;
9550             }
9551             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9552                 return false;
9553             }
9554             final PhylogenyNode n20xxxx = PhylogenyNode
9555                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9556             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9557                 return false;
9558             }
9559             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9560                 return false;
9561             }
9562             final PhylogenyNode n21 = PhylogenyNode
9563                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9564             if ( !n21.getName().equals( "N21_PIG" ) ) {
9565                 return false;
9566             }
9567             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9568                 return false;
9569             }
9570             final PhylogenyNode n21x = PhylogenyNode
9571                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9572             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9573                 return false;
9574             }
9575             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9576                 return false;
9577             }
9578             final PhylogenyNode n22 = PhylogenyNode
9579                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9580             if ( !n22.getName().equals( "n22/PIG" ) ) {
9581                 return false;
9582             }
9583             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9584                 return false;
9585             }
9586             final PhylogenyNode n23 = PhylogenyNode
9587                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9588             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9589                 return false;
9590             }
9591             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9592                 return false;
9593             }
9594             final PhylogenyNode a = PhylogenyNode
9595                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9596             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9597                 return false;
9598             }
9599             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9600                 return false;
9601             }
9602             final PhylogenyNode c1 = PhylogenyNode
9603                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9604                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9605             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9606                 return false;
9607             }
9608             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9609                 return false;
9610             }
9611             final PhylogenyNode c2 = PhylogenyNode
9612                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9613                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9614             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9615                 return false;
9616             }
9617             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9618                 return false;
9619             }
9620             final PhylogenyNode e3 = PhylogenyNode
9621                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9622             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9623                 return false;
9624             }
9625             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9626                 return false;
9627             }
9628             final PhylogenyNode n11 = PhylogenyNode
9629                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9630                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9631             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9632                 return false;
9633             }
9634             if ( n11.getDistanceToParent() != 0.4 ) {
9635                 return false;
9636             }
9637             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9638                 return false;
9639             }
9640             final PhylogenyNode n12 = PhylogenyNode
9641                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9642                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9643             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9644                 return false;
9645             }
9646             if ( n12.getDistanceToParent() != 0.4 ) {
9647                 return false;
9648             }
9649             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9650                 return false;
9651             }
9652             final PhylogenyNode o = PhylogenyNode
9653                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9654             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9655                 return false;
9656             }
9657             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9658                 return false;
9659             }
9660             if ( n1.getName().compareTo( "" ) != 0 ) {
9661                 return false;
9662             }
9663             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9664                 return false;
9665             }
9666             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9667                 return false;
9668             }
9669             if ( n2.getName().compareTo( "" ) != 0 ) {
9670                 return false;
9671             }
9672             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9673                 return false;
9674             }
9675             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9676                 return false;
9677             }
9678             final PhylogenyNode n00 = PhylogenyNode
9679                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9680             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9681                 return false;
9682             }
9683             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9684                 return false;
9685             }
9686             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9687             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9688                 return false;
9689             }
9690             final PhylogenyNode n13 = PhylogenyNode
9691                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9692             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9693                 return false;
9694             }
9695             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9696                 return false;
9697             }
9698             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9699                 return false;
9700             }
9701             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9702                 return false;
9703             }
9704             final PhylogenyNode n14 = PhylogenyNode
9705                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9706             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9707                 return false;
9708             }
9709             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9710                 return false;
9711             }
9712             final PhylogenyNode n15 = PhylogenyNode
9713                     .createInstanceFromNhxString( "something_wicked[123]",
9714                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9715             if ( !n15.getName().equals( "something_wicked" ) ) {
9716                 return false;
9717             }
9718             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9719                 return false;
9720             }
9721             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9722                 return false;
9723             }
9724             final PhylogenyNode n16 = PhylogenyNode
9725                     .createInstanceFromNhxString( "something_wicked2[9]",
9726                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9727             if ( !n16.getName().equals( "something_wicked2" ) ) {
9728                 return false;
9729             }
9730             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9731                 return false;
9732             }
9733             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9734                 return false;
9735             }
9736             final PhylogenyNode n17 = PhylogenyNode
9737                     .createInstanceFromNhxString( "something_wicked3[a]",
9738                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9739             if ( !n17.getName().equals( "something_wicked3" ) ) {
9740                 return false;
9741             }
9742             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9743                 return false;
9744             }
9745             final PhylogenyNode n18 = PhylogenyNode
9746                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9747             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9748                 return false;
9749             }
9750             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9751                 return false;
9752             }
9753             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9754                 return false;
9755             }
9756             final PhylogenyNode n19 = PhylogenyNode
9757                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9758             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9759                 return false;
9760             }
9761             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9762                 return false;
9763             }
9764             final PhylogenyNode n30 = PhylogenyNode
9765                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9766                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9767             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9768                 return false;
9769             }
9770             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9771                 return false;
9772             }
9773             final PhylogenyNode n31 = PhylogenyNode
9774                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9775                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9776             if ( n31.getNodeData().isHasTaxonomy() ) {
9777                 return false;
9778             }
9779             final PhylogenyNode n32 = PhylogenyNode
9780                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9781             if ( n32.getNodeData().isHasTaxonomy() ) {
9782                 return false;
9783             }
9784             final PhylogenyNode n40 = PhylogenyNode
9785                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9786             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9787                 return false;
9788             }
9789             final PhylogenyNode n41 = PhylogenyNode
9790                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9791             if ( n41.getNodeData().isHasTaxonomy() ) {
9792                 return false;
9793             }
9794             final PhylogenyNode n42 = PhylogenyNode
9795                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9796             if ( n42.getNodeData().isHasTaxonomy() ) {
9797                 return false;
9798             }
9799             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9800                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9801             if ( n43.getNodeData().isHasTaxonomy() ) {
9802                 return false;
9803             }
9804             final PhylogenyNode n44 = PhylogenyNode
9805                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9806             if ( n44.getNodeData().isHasTaxonomy() ) {
9807                 return false;
9808             }
9809         }
9810         catch ( final Exception e ) {
9811             e.printStackTrace( System.out );
9812             return false;
9813         }
9814         return true;
9815     }
9816
9817     
9818     private static boolean testNHXNodeParsing2() {
9819         try {
9820           
9821             final PhylogenyNode n0_0 = PhylogenyNode
9822                     .createInstanceFromNhxString( "n0:[ignore me 123]:1E-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9823             if ( !n0_0.getName().equals( "n0" ) ) {
9824                 return false;
9825             }
9826             if ( !isEqual( n0_0.getDistanceToParent(), 0.001 ) ) {
9827                 return false;
9828             }
9829             final PhylogenyNode n0_1 = PhylogenyNode
9830                     .createInstanceFromNhxString( "n0[ignore me 123]:1E-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9831             if ( !n0_1.getName().equals( "n0" ) ) {
9832                 return false;
9833             }
9834             if ( !isEqual( n0_1.getDistanceToParent(), 0.001 ) ) {
9835                 return false;
9836             }
9837             final PhylogenyNode n0_2 = PhylogenyNode
9838                     .createInstanceFromNhxString( "n0:1E-3[ignore me 123]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9839             if ( !n0_2.getName().equals( "n0" ) ) {
9840                 return false;
9841             }
9842             if ( !isEqual( n0_2.getDistanceToParent(), 0.001 ) ) {
9843                 return false;
9844             }
9845             final PhylogenyNode n0_3 = PhylogenyNode
9846                     .createInstanceFromNhxString( "n0:1E-3:[ignore me 123]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9847             if ( !n0_3.getName().equals( "n0" ) ) {
9848                 return false;
9849             }
9850             if ( !isEqual( n0_3.getDistanceToParent(), 0.001 ) ) {
9851                 return false;
9852             }
9853             final PhylogenyNode n0_4 = PhylogenyNode
9854                     .createInstanceFromNhxString( "n0:0.001:[ignore me 123]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9855             if ( !n0_4.getName().equals( "n0" ) ) {
9856                 return false;
9857             }
9858             if ( !isEqual( n0_4.getDistanceToParent(), 0.001 ) ) {
9859                 return false;
9860             }
9861             final PhylogenyNode n1_0 = PhylogenyNode
9862                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9863             if ( !n1_0.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9864                 return false;
9865             }
9866             if ( n1_0.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
9867                return false;
9868             }
9869             final PhylogenyNode n1_1 = PhylogenyNode
9870                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]:0.001", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9871             if ( !n1_1.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9872                 return false;
9873             }
9874             if ( n1_1.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
9875                return false;
9876             }
9877             if ( !isEqual( n1_1.getDistanceToParent(), 0.001 ) ) {
9878                 return false;
9879             }
9880             final PhylogenyNode n1_2 = PhylogenyNode
9881                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:0.001[&!color=#FFFFFF]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9882             if ( !n1_2.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9883                 return false;
9884             }
9885             if ( n1_2.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
9886                return false;
9887             }
9888             if ( !isEqual( n1_2.getDistanceToParent(), 0.001 ) ) {
9889                 return false;
9890             }
9891             final PhylogenyNode n1_3 = PhylogenyNode
9892                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[&boostrap=69,&!color=#FFFFFF]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9893             if ( !n1_3.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9894                 return false;
9895             }
9896             if ( n1_3.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
9897                return false;
9898             }
9899             if ( !isEqual( n1_3.getDistanceToParent(), 0.001 ) ) {
9900                 return false;
9901             }
9902             if ( !isEqual( n1_3.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
9903                 return false;
9904             }
9905             if ( !n1_3.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
9906                 return false;
9907             }
9908             final PhylogenyNode n1_4 = PhylogenyNode
9909                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&bootstrap=69,&!colour=#FFFFFF]:1e-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9910             if ( !n1_4.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9911                 return false;
9912             }
9913             if ( n1_4.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
9914                return false;
9915             }
9916             if ( !isEqual( n1_4.getDistanceToParent(), 0.001 ) ) {
9917                 return false;
9918             }
9919             if ( !isEqual( n1_4.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
9920                 return false;
9921             }
9922             if ( !n1_4.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
9923                 return false;
9924             }
9925             final PhylogenyNode n1_5 = PhylogenyNode
9926                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[69.0]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9927             if ( !n1_5.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9928                 return false;
9929             }
9930             if ( !isEqual( n1_5.getDistanceToParent(), 0.001 ) ) {
9931                 return false;
9932             }
9933             if ( !isEqual( n1_5.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
9934                 return false;
9935             }       
9936             final PhylogenyNode n1_6 = PhylogenyNode
9937                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00]:1e-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9938             if ( !n1_6.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9939                 return false;
9940             }
9941            
9942             if ( !isEqual( n1_6.getDistanceToParent(), 0.001 ) ) {
9943                 return false;
9944             }
9945             if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getStandardDeviation(), 0.11 ) ) {
9946                 return false;
9947             }
9948             if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getValue(), 0.95 ) ) {
9949                 return false;
9950             }
9951             if ( !n1_6.getBranchData().getConfidence( 0 ).getType().equals( "posterior probability" ) ) {
9952                 return false;
9953             }
9954         }
9955         catch ( final Exception e ) {
9956             e.printStackTrace( System.out );
9957             return false;
9958         }
9959         return true;
9960     }
9961     
9962     private static boolean testNHXParsing() {
9963         try {
9964             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9965             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9966             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9967                 return false;
9968             }
9969             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]";
9970             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9971             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9972                 return false;
9973             }
9974             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]";
9975             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9976             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9977                 return false;
9978             }
9979             final Phylogeny[] p3 = factory
9980                     .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]",
9981                              new NHXParser() );
9982             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9983                 return false;
9984             }
9985             final Phylogeny[] p4 = factory
9986                     .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(]",
9987                              new NHXParser() );
9988             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9989                 return false;
9990             }
9991             final Phylogeny[] p5 = factory
9992                     .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(((]",
9993                              new NHXParser() );
9994             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9995                 return false;
9996             }
9997             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)";
9998             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)";
9999             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
10000             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
10001                 return false;
10002             }
10003             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)))";
10004             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)))";
10005             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
10006             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
10007                 return false;
10008             }
10009             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])   ))[,,, ])))))))";
10010             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
10011             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
10012             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
10013                 return false;
10014             }
10015             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
10016             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10017                 return false;
10018             }
10019             final Phylogeny p10 = factory
10020                     .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]",
10021                              new NHXParser() )[ 0 ];
10022             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10023                 return false;
10024             }
10025             final Phylogeny p11 = factory
10026                     .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]",
10027                              new NHXParser() )[ 0 ];
10028             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10029                 return false;
10030             }
10031             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]",
10032                                                   new NHXParser() )[ 0 ];
10033             if ( !p12.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10034                 return false;
10035             }
10036         }
10037         catch ( final Exception e ) {
10038             e.printStackTrace( System.out );
10039             return false;
10040         }
10041         return true;
10042     }
10043
10044     private static boolean testNHXParsingMB() {
10045         try {
10046             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10047             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
10048                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10049                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
10050                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
10051                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
10052                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10053                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
10054                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
10055                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
10056             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
10057                 return false;
10058             }
10059             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
10060                 return false;
10061             }
10062             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
10063                            0.1100000000000000e+00 ) ) {
10064                 return false;
10065             }
10066             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
10067                 return false;
10068             }
10069             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
10070                 return false;
10071             }
10072             final Phylogeny p2 = factory
10073                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
10074                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10075                             + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
10076                             + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
10077                             + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
10078                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10079                             + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
10080                             + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
10081                             + "7.369400000000000e-02}])",
10082                             new NHXParser() )[ 0 ];
10083             if ( p2.getNode( "1" ) == null ) {
10084                 return false;
10085             }
10086             if ( p2.getNode( "2" ) == null ) {
10087                 return false;
10088             }
10089         }
10090         catch ( final Exception e ) {
10091             e.printStackTrace( System.out );
10092             System.exit( -1 );
10093             return false;
10094         }
10095         return true;
10096     }
10097
10098     private static boolean testNHXParsingQuotes() {
10099         try {
10100             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10101             final NHXParser p = new NHXParser();
10102             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
10103             if ( phylogenies_0.length != 5 ) {
10104                 return false;
10105             }
10106             final Phylogeny phy = phylogenies_0[ 4 ];
10107             if ( phy.getNumberOfExternalNodes() != 7 ) {
10108                 return false;
10109             }
10110             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
10111                 return false;
10112             }
10113             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
10114                 return false;
10115             }
10116             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
10117                     .getScientificName().equals( "hsapiens" ) ) {
10118                 return false;
10119             }
10120             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
10121                 return false;
10122             }
10123             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
10124                 return false;
10125             }
10126             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
10127                 return false;
10128             }
10129             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
10130                 return false;
10131             }
10132             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
10133                 return false;
10134             }
10135             final NHXParser p1p = new NHXParser();
10136             p1p.setIgnoreQuotes( true );
10137             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
10138             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
10139                 return false;
10140             }
10141             final NHXParser p2p = new NHXParser();
10142             p1p.setIgnoreQuotes( false );
10143             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
10144             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
10145                 return false;
10146             }
10147             final NHXParser p3p = new NHXParser();
10148             p3p.setIgnoreQuotes( false );
10149             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
10150             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
10151                 return false;
10152             }
10153             final NHXParser p4p = new NHXParser();
10154             p4p.setIgnoreQuotes( false );
10155             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
10156             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
10157                 return false;
10158             }
10159             final Phylogeny p10 = factory
10160                     .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]",
10161                              new NHXParser() )[ 0 ];
10162             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]";
10163             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
10164                 return false;
10165             }
10166             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
10167             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
10168                 return false;
10169             }
10170             final Phylogeny p12 = factory
10171                     .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]",
10172                              new NHXParser() )[ 0 ];
10173             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]";
10174             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
10175                 return false;
10176             }
10177             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
10178             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
10179                 return false;
10180             }
10181             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;";
10182             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
10183                 return false;
10184             }
10185             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
10186             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
10187                 return false;
10188             }
10189         }
10190         catch ( final Exception e ) {
10191             e.printStackTrace( System.out );
10192             return false;
10193         }
10194         return true;
10195     }
10196
10197     private static boolean testNodeRemoval() {
10198         try {
10199             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10200             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
10201             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
10202             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
10203                 return false;
10204             }
10205             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
10206             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
10207             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
10208                 return false;
10209             }
10210             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
10211             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
10212             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
10213                 return false;
10214             }
10215         }
10216         catch ( final Exception e ) {
10217             e.printStackTrace( System.out );
10218             return false;
10219         }
10220         return true;
10221     }
10222
10223     private static boolean testPhylogenyBranch() {
10224         try {
10225             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
10226             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
10227             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
10228             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
10229             if ( !a1b1.equals( a1b1 ) ) {
10230                 return false;
10231             }
10232             if ( !a1b1.equals( b1a1 ) ) {
10233                 return false;
10234             }
10235             if ( !b1a1.equals( a1b1 ) ) {
10236                 return false;
10237             }
10238             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
10239             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
10240             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
10241             if ( a1_b1.equals( b1_a1 ) ) {
10242                 return false;
10243             }
10244             if ( a1_b1.equals( a1_b1_ ) ) {
10245                 return false;
10246             }
10247             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
10248             if ( !a1_b1.equals( b1_a1_ ) ) {
10249                 return false;
10250             }
10251             if ( a1_b1_.equals( b1_a1_ ) ) {
10252                 return false;
10253             }
10254             if ( !a1_b1_.equals( b1_a1 ) ) {
10255                 return false;
10256             }
10257         }
10258         catch ( final Exception e ) {
10259             e.printStackTrace( System.out );
10260             return false;
10261         }
10262         return true;
10263     }
10264
10265     private static boolean testPhyloXMLparsingOfDistributionElement() {
10266         try {
10267             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10268             PhyloXmlParser xml_parser = null;
10269             try {
10270                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
10271             }
10272             catch ( final Exception e ) {
10273                 // Do nothing -- means were not running from jar.
10274             }
10275             if ( xml_parser == null ) {
10276                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
10277                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
10278                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
10279                 }
10280                 else {
10281                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
10282                 }
10283             }
10284             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml" ),
10285                                                               xml_parser );
10286             if ( xml_parser.getErrorCount() > 0 ) {
10287                 System.out.println( xml_parser.getErrorMessages().toString() );
10288                 return false;
10289             }
10290             if ( phylogenies_0.length != 1 ) {
10291                 return false;
10292             }
10293             final Phylogeny t1 = phylogenies_0[ 0 ];
10294             PhylogenyNode n = null;
10295             Distribution d = null;
10296             n = t1.getNode( "root node" );
10297             if ( !n.getNodeData().isHasDistribution() ) {
10298                 return false;
10299             }
10300             if ( n.getNodeData().getDistributions().size() != 1 ) {
10301                 return false;
10302             }
10303             d = n.getNodeData().getDistribution();
10304             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10305                 return false;
10306             }
10307             if ( d.getPoints().size() != 1 ) {
10308                 return false;
10309             }
10310             if ( d.getPolygons() != null ) {
10311                 return false;
10312             }
10313             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10314                 return false;
10315             }
10316             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10317                 return false;
10318             }
10319             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10320                 return false;
10321             }
10322             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10323                 return false;
10324             }
10325             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10326                 return false;
10327             }
10328             n = t1.getNode( "node a" );
10329             if ( !n.getNodeData().isHasDistribution() ) {
10330                 return false;
10331             }
10332             if ( n.getNodeData().getDistributions().size() != 2 ) {
10333                 return false;
10334             }
10335             d = n.getNodeData().getDistribution( 1 );
10336             if ( !d.getDesc().equals( "San Diego" ) ) {
10337                 return false;
10338             }
10339             if ( d.getPoints().size() != 1 ) {
10340                 return false;
10341             }
10342             if ( d.getPolygons() != null ) {
10343                 return false;
10344             }
10345             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10346                 return false;
10347             }
10348             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10349                 return false;
10350             }
10351             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10352                 return false;
10353             }
10354             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10355                 return false;
10356             }
10357             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10358                 return false;
10359             }
10360             n = t1.getNode( "node bb" );
10361             if ( !n.getNodeData().isHasDistribution() ) {
10362                 return false;
10363             }
10364             if ( n.getNodeData().getDistributions().size() != 1 ) {
10365                 return false;
10366             }
10367             d = n.getNodeData().getDistribution( 0 );
10368             if ( d.getPoints().size() != 3 ) {
10369                 return false;
10370             }
10371             if ( d.getPolygons().size() != 2 ) {
10372                 return false;
10373             }
10374             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10375                 return false;
10376             }
10377             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10378                 return false;
10379             }
10380             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10381                 return false;
10382             }
10383             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10384                 return false;
10385             }
10386             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10387                 return false;
10388             }
10389             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10390                 return false;
10391             }
10392             Polygon p = d.getPolygons().get( 0 );
10393             if ( p.getPoints().size() != 3 ) {
10394                 return false;
10395             }
10396             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10397                 return false;
10398             }
10399             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10400                 return false;
10401             }
10402             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10403                 return false;
10404             }
10405             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10406                 return false;
10407             }
10408             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10409                 return false;
10410             }
10411             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10412                 return false;
10413             }
10414             p = d.getPolygons().get( 1 );
10415             if ( p.getPoints().size() != 3 ) {
10416                 return false;
10417             }
10418             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10419                 return false;
10420             }
10421             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10422                 return false;
10423             }
10424             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10425                 return false;
10426             }
10427             // Roundtrip:
10428             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
10429             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
10430             if ( rt.length != 1 ) {
10431                 return false;
10432             }
10433             final Phylogeny t1_rt = rt[ 0 ];
10434             n = t1_rt.getNode( "root node" );
10435             if ( !n.getNodeData().isHasDistribution() ) {
10436                 return false;
10437             }
10438             if ( n.getNodeData().getDistributions().size() != 1 ) {
10439                 return false;
10440             }
10441             d = n.getNodeData().getDistribution();
10442             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10443                 return false;
10444             }
10445             if ( d.getPoints().size() != 1 ) {
10446                 return false;
10447             }
10448             if ( d.getPolygons() != null ) {
10449                 return false;
10450             }
10451             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10452                 return false;
10453             }
10454             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10455                 return false;
10456             }
10457             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10458                 return false;
10459             }
10460             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10461                 return false;
10462             }
10463             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10464                 return false;
10465             }
10466             n = t1_rt.getNode( "node a" );
10467             if ( !n.getNodeData().isHasDistribution() ) {
10468                 return false;
10469             }
10470             if ( n.getNodeData().getDistributions().size() != 2 ) {
10471                 return false;
10472             }
10473             d = n.getNodeData().getDistribution( 1 );
10474             if ( !d.getDesc().equals( "San Diego" ) ) {
10475                 return false;
10476             }
10477             if ( d.getPoints().size() != 1 ) {
10478                 return false;
10479             }
10480             if ( d.getPolygons() != null ) {
10481                 return false;
10482             }
10483             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10484                 return false;
10485             }
10486             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10487                 return false;
10488             }
10489             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10490                 return false;
10491             }
10492             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10493                 return false;
10494             }
10495             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10496                 return false;
10497             }
10498             n = t1_rt.getNode( "node bb" );
10499             if ( !n.getNodeData().isHasDistribution() ) {
10500                 return false;
10501             }
10502             if ( n.getNodeData().getDistributions().size() != 1 ) {
10503                 return false;
10504             }
10505             d = n.getNodeData().getDistribution( 0 );
10506             if ( d.getPoints().size() != 3 ) {
10507                 return false;
10508             }
10509             if ( d.getPolygons().size() != 2 ) {
10510                 return false;
10511             }
10512             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10513                 return false;
10514             }
10515             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10516                 return false;
10517             }
10518             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10519                 return false;
10520             }
10521             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10522                 return false;
10523             }
10524             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10525                 return false;
10526             }
10527             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10528                 return false;
10529             }
10530             p = d.getPolygons().get( 0 );
10531             if ( p.getPoints().size() != 3 ) {
10532                 return false;
10533             }
10534             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10535                 return false;
10536             }
10537             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10538                 return false;
10539             }
10540             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10541                 return false;
10542             }
10543             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10544                 return false;
10545             }
10546             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10547                 return false;
10548             }
10549             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10550                 return false;
10551             }
10552             p = d.getPolygons().get( 1 );
10553             if ( p.getPoints().size() != 3 ) {
10554                 return false;
10555             }
10556             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10557                 return false;
10558             }
10559             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10560                 return false;
10561             }
10562             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10563                 return false;
10564             }
10565         }
10566         catch ( final Exception e ) {
10567             e.printStackTrace( System.out );
10568             return false;
10569         }
10570         return true;
10571     }
10572
10573     private static boolean testPostOrderIterator() {
10574         try {
10575             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10576             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10577             PhylogenyNodeIterator it0;
10578             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
10579                 it0.next();
10580             }
10581             for( it0.reset(); it0.hasNext(); ) {
10582                 it0.next();
10583             }
10584             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10585             final PhylogenyNodeIterator it = t1.iteratorPostorder();
10586             if ( !it.next().getName().equals( "A" ) ) {
10587                 return false;
10588             }
10589             if ( !it.next().getName().equals( "B" ) ) {
10590                 return false;
10591             }
10592             if ( !it.next().getName().equals( "ab" ) ) {
10593                 return false;
10594             }
10595             if ( !it.next().getName().equals( "C" ) ) {
10596                 return false;
10597             }
10598             if ( !it.next().getName().equals( "D" ) ) {
10599                 return false;
10600             }
10601             if ( !it.next().getName().equals( "cd" ) ) {
10602                 return false;
10603             }
10604             if ( !it.next().getName().equals( "abcd" ) ) {
10605                 return false;
10606             }
10607             if ( !it.next().getName().equals( "E" ) ) {
10608                 return false;
10609             }
10610             if ( !it.next().getName().equals( "F" ) ) {
10611                 return false;
10612             }
10613             if ( !it.next().getName().equals( "ef" ) ) {
10614                 return false;
10615             }
10616             if ( !it.next().getName().equals( "G" ) ) {
10617                 return false;
10618             }
10619             if ( !it.next().getName().equals( "H" ) ) {
10620                 return false;
10621             }
10622             if ( !it.next().getName().equals( "gh" ) ) {
10623                 return false;
10624             }
10625             if ( !it.next().getName().equals( "efgh" ) ) {
10626                 return false;
10627             }
10628             if ( !it.next().getName().equals( "r" ) ) {
10629                 return false;
10630             }
10631             if ( it.hasNext() ) {
10632                 return false;
10633             }
10634         }
10635         catch ( final Exception e ) {
10636             e.printStackTrace( System.out );
10637             return false;
10638         }
10639         return true;
10640     }
10641
10642     private static boolean testPreOrderIterator() {
10643         try {
10644             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10645             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10646             PhylogenyNodeIterator it0;
10647             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10648                 it0.next();
10649             }
10650             for( it0.reset(); it0.hasNext(); ) {
10651                 it0.next();
10652             }
10653             PhylogenyNodeIterator it = t0.iteratorPreorder();
10654             if ( !it.next().getName().equals( "r" ) ) {
10655                 return false;
10656             }
10657             if ( !it.next().getName().equals( "ab" ) ) {
10658                 return false;
10659             }
10660             if ( !it.next().getName().equals( "A" ) ) {
10661                 return false;
10662             }
10663             if ( !it.next().getName().equals( "B" ) ) {
10664                 return false;
10665             }
10666             if ( !it.next().getName().equals( "cd" ) ) {
10667                 return false;
10668             }
10669             if ( !it.next().getName().equals( "C" ) ) {
10670                 return false;
10671             }
10672             if ( !it.next().getName().equals( "D" ) ) {
10673                 return false;
10674             }
10675             if ( it.hasNext() ) {
10676                 return false;
10677             }
10678             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10679             it = t1.iteratorPreorder();
10680             if ( !it.next().getName().equals( "r" ) ) {
10681                 return false;
10682             }
10683             if ( !it.next().getName().equals( "abcd" ) ) {
10684                 return false;
10685             }
10686             if ( !it.next().getName().equals( "ab" ) ) {
10687                 return false;
10688             }
10689             if ( !it.next().getName().equals( "A" ) ) {
10690                 return false;
10691             }
10692             if ( !it.next().getName().equals( "B" ) ) {
10693                 return false;
10694             }
10695             if ( !it.next().getName().equals( "cd" ) ) {
10696                 return false;
10697             }
10698             if ( !it.next().getName().equals( "C" ) ) {
10699                 return false;
10700             }
10701             if ( !it.next().getName().equals( "D" ) ) {
10702                 return false;
10703             }
10704             if ( !it.next().getName().equals( "efgh" ) ) {
10705                 return false;
10706             }
10707             if ( !it.next().getName().equals( "ef" ) ) {
10708                 return false;
10709             }
10710             if ( !it.next().getName().equals( "E" ) ) {
10711                 return false;
10712             }
10713             if ( !it.next().getName().equals( "F" ) ) {
10714                 return false;
10715             }
10716             if ( !it.next().getName().equals( "gh" ) ) {
10717                 return false;
10718             }
10719             if ( !it.next().getName().equals( "G" ) ) {
10720                 return false;
10721             }
10722             if ( !it.next().getName().equals( "H" ) ) {
10723                 return false;
10724             }
10725             if ( it.hasNext() ) {
10726                 return false;
10727             }
10728         }
10729         catch ( final Exception e ) {
10730             e.printStackTrace( System.out );
10731             return false;
10732         }
10733         return true;
10734     }
10735
10736     private static boolean testPropertiesMap() {
10737         try {
10738             final PropertiesMap pm = new PropertiesMap();
10739             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10740             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10741             final Property p2 = new Property( "something:else",
10742                                               "?",
10743                                               "improbable:research",
10744                                               "xsd:decimal",
10745                                               AppliesTo.NODE );
10746             pm.addProperty( p0 );
10747             pm.addProperty( p1 );
10748             pm.addProperty( p2 );
10749             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10750                 return false;
10751             }
10752             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10753                 return false;
10754             }
10755             if ( pm.getProperties().size() != 3 ) {
10756                 return false;
10757             }
10758             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10759                 return false;
10760             }
10761             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10762                 return false;
10763             }
10764             if ( pm.getProperties().size() != 3 ) {
10765                 return false;
10766             }
10767             pm.removeProperty( "dimensions:diameter" );
10768             if ( pm.getProperties().size() != 2 ) {
10769                 return false;
10770             }
10771             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10772                 return false;
10773             }
10774             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10775                 return false;
10776             }
10777         }
10778         catch ( final Exception e ) {
10779             e.printStackTrace( System.out );
10780             return false;
10781         }
10782         return true;
10783     }
10784
10785     private static boolean testProteinId() {
10786         try {
10787             final ProteinId id1 = new ProteinId( "a" );
10788             final ProteinId id2 = new ProteinId( "a" );
10789             final ProteinId id3 = new ProteinId( "A" );
10790             final ProteinId id4 = new ProteinId( "b" );
10791             if ( !id1.equals( id1 ) ) {
10792                 return false;
10793             }
10794             if ( id1.getId().equals( "x" ) ) {
10795                 return false;
10796             }
10797             if ( id1.getId().equals( null ) ) {
10798                 return false;
10799             }
10800             if ( !id1.equals( id2 ) ) {
10801                 return false;
10802             }
10803             if ( id1.equals( id3 ) ) {
10804                 return false;
10805             }
10806             if ( id1.hashCode() != id1.hashCode() ) {
10807                 return false;
10808             }
10809             if ( id1.hashCode() != id2.hashCode() ) {
10810                 return false;
10811             }
10812             if ( id1.hashCode() == id3.hashCode() ) {
10813                 return false;
10814             }
10815             if ( id1.compareTo( id1 ) != 0 ) {
10816                 return false;
10817             }
10818             if ( id1.compareTo( id2 ) != 0 ) {
10819                 return false;
10820             }
10821             if ( id1.compareTo( id3 ) != 0 ) {
10822                 return false;
10823             }
10824             if ( id1.compareTo( id4 ) >= 0 ) {
10825                 return false;
10826             }
10827             if ( id4.compareTo( id1 ) <= 0 ) {
10828                 return false;
10829             }
10830             if ( !id4.getId().equals( "b" ) ) {
10831                 return false;
10832             }
10833             final ProteinId id5 = new ProteinId( " C " );
10834             if ( !id5.getId().equals( "C" ) ) {
10835                 return false;
10836             }
10837             if ( id5.equals( id1 ) ) {
10838                 return false;
10839             }
10840         }
10841         catch ( final Exception e ) {
10842             e.printStackTrace( System.out );
10843             return false;
10844         }
10845         return true;
10846     }
10847
10848     private static boolean testReIdMethods() {
10849         try {
10850             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10851             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10852             final long count = PhylogenyNode.getNodeCount();
10853             p.levelOrderReID();
10854             if ( p.getNode( "r" ).getId() != count ) {
10855                 return false;
10856             }
10857             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10858                 return false;
10859             }
10860             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10861                 return false;
10862             }
10863             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10864                 return false;
10865             }
10866             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10867                 return false;
10868             }
10869             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10870                 return false;
10871             }
10872             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10873                 return false;
10874             }
10875             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10876                 return false;
10877             }
10878             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10879                 return false;
10880             }
10881             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10882                 return false;
10883             }
10884             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10885                 return false;
10886             }
10887             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10888                 return false;
10889             }
10890             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10891                 return false;
10892             }
10893             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10894                 return false;
10895             }
10896             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10897                 return false;
10898             }
10899         }
10900         catch ( final Exception e ) {
10901             e.printStackTrace( System.out );
10902             return false;
10903         }
10904         return true;
10905     }
10906
10907     private static boolean testRerooting() {
10908         try {
10909             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10910             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",
10911                                                  new NHXParser() )[ 0 ];
10912             if ( !t1.isRooted() ) {
10913                 return false;
10914             }
10915             t1.reRoot( t1.getNode( "D" ) );
10916             t1.reRoot( t1.getNode( "CD" ) );
10917             t1.reRoot( t1.getNode( "A" ) );
10918             t1.reRoot( t1.getNode( "B" ) );
10919             t1.reRoot( t1.getNode( "AB" ) );
10920             t1.reRoot( t1.getNode( "D" ) );
10921             t1.reRoot( t1.getNode( "C" ) );
10922             t1.reRoot( t1.getNode( "CD" ) );
10923             t1.reRoot( t1.getNode( "A" ) );
10924             t1.reRoot( t1.getNode( "B" ) );
10925             t1.reRoot( t1.getNode( "AB" ) );
10926             t1.reRoot( t1.getNode( "D" ) );
10927             t1.reRoot( t1.getNode( "D" ) );
10928             t1.reRoot( t1.getNode( "C" ) );
10929             t1.reRoot( t1.getNode( "A" ) );
10930             t1.reRoot( t1.getNode( "B" ) );
10931             t1.reRoot( t1.getNode( "AB" ) );
10932             t1.reRoot( t1.getNode( "C" ) );
10933             t1.reRoot( t1.getNode( "D" ) );
10934             t1.reRoot( t1.getNode( "CD" ) );
10935             t1.reRoot( t1.getNode( "D" ) );
10936             t1.reRoot( t1.getNode( "A" ) );
10937             t1.reRoot( t1.getNode( "B" ) );
10938             t1.reRoot( t1.getNode( "AB" ) );
10939             t1.reRoot( t1.getNode( "C" ) );
10940             t1.reRoot( t1.getNode( "D" ) );
10941             t1.reRoot( t1.getNode( "CD" ) );
10942             t1.reRoot( t1.getNode( "D" ) );
10943             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10944                 return false;
10945             }
10946             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10947                 return false;
10948             }
10949             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10950                 return false;
10951             }
10952             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10953                 return false;
10954             }
10955             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10956                 return false;
10957             }
10958             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10959                 return false;
10960             }
10961             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",
10962                                                  new NHXParser() )[ 0 ];
10963             t2.reRoot( t2.getNode( "A" ) );
10964             t2.reRoot( t2.getNode( "D" ) );
10965             t2.reRoot( t2.getNode( "ABC" ) );
10966             t2.reRoot( t2.getNode( "A" ) );
10967             t2.reRoot( t2.getNode( "B" ) );
10968             t2.reRoot( t2.getNode( "D" ) );
10969             t2.reRoot( t2.getNode( "C" ) );
10970             t2.reRoot( t2.getNode( "ABC" ) );
10971             t2.reRoot( t2.getNode( "A" ) );
10972             t2.reRoot( t2.getNode( "B" ) );
10973             t2.reRoot( t2.getNode( "AB" ) );
10974             t2.reRoot( t2.getNode( "AB" ) );
10975             t2.reRoot( t2.getNode( "D" ) );
10976             t2.reRoot( t2.getNode( "C" ) );
10977             t2.reRoot( t2.getNode( "B" ) );
10978             t2.reRoot( t2.getNode( "AB" ) );
10979             t2.reRoot( t2.getNode( "D" ) );
10980             t2.reRoot( t2.getNode( "D" ) );
10981             t2.reRoot( t2.getNode( "ABC" ) );
10982             t2.reRoot( t2.getNode( "A" ) );
10983             t2.reRoot( t2.getNode( "B" ) );
10984             t2.reRoot( t2.getNode( "AB" ) );
10985             t2.reRoot( t2.getNode( "D" ) );
10986             t2.reRoot( t2.getNode( "C" ) );
10987             t2.reRoot( t2.getNode( "ABC" ) );
10988             t2.reRoot( t2.getNode( "A" ) );
10989             t2.reRoot( t2.getNode( "B" ) );
10990             t2.reRoot( t2.getNode( "AB" ) );
10991             t2.reRoot( t2.getNode( "D" ) );
10992             t2.reRoot( t2.getNode( "D" ) );
10993             t2.reRoot( t2.getNode( "C" ) );
10994             t2.reRoot( t2.getNode( "A" ) );
10995             t2.reRoot( t2.getNode( "B" ) );
10996             t2.reRoot( t2.getNode( "AB" ) );
10997             t2.reRoot( t2.getNode( "C" ) );
10998             t2.reRoot( t2.getNode( "D" ) );
10999             t2.reRoot( t2.getNode( "ABC" ) );
11000             t2.reRoot( t2.getNode( "D" ) );
11001             t2.reRoot( t2.getNode( "A" ) );
11002             t2.reRoot( t2.getNode( "B" ) );
11003             t2.reRoot( t2.getNode( "AB" ) );
11004             t2.reRoot( t2.getNode( "C" ) );
11005             t2.reRoot( t2.getNode( "D" ) );
11006             t2.reRoot( t2.getNode( "ABC" ) );
11007             t2.reRoot( t2.getNode( "D" ) );
11008             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11009                 return false;
11010             }
11011             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11012                 return false;
11013             }
11014             t2.reRoot( t2.getNode( "ABC" ) );
11015             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11016                 return false;
11017             }
11018             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11019                 return false;
11020             }
11021             t2.reRoot( t2.getNode( "AB" ) );
11022             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11023                 return false;
11024             }
11025             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11026                 return false;
11027             }
11028             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11029                 return false;
11030             }
11031             t2.reRoot( t2.getNode( "AB" ) );
11032             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11033                 return false;
11034             }
11035             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11036                 return false;
11037             }
11038             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11039                 return false;
11040             }
11041             t2.reRoot( t2.getNode( "D" ) );
11042             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11043                 return false;
11044             }
11045             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11046                 return false;
11047             }
11048             t2.reRoot( t2.getNode( "ABC" ) );
11049             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11050                 return false;
11051             }
11052             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11053                 return false;
11054             }
11055             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
11056                                                  new NHXParser() )[ 0 ];
11057             t3.reRoot( t3.getNode( "B" ) );
11058             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11059                 return false;
11060             }
11061             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11062                 return false;
11063             }
11064             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11065                 return false;
11066             }
11067             t3.reRoot( t3.getNode( "B" ) );
11068             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11069                 return false;
11070             }
11071             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11072                 return false;
11073             }
11074             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11075                 return false;
11076             }
11077             t3.reRoot( t3.getRoot() );
11078             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11079                 return false;
11080             }
11081             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11082                 return false;
11083             }
11084             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11085                 return false;
11086             }
11087         }
11088         catch ( final Exception e ) {
11089             e.printStackTrace( System.out );
11090             return false;
11091         }
11092         return true;
11093     }
11094
11095     private static boolean testSDIse() {
11096         try {
11097             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11098             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
11099             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
11100             gene1.setRooted( true );
11101             species1.setRooted( true );
11102             final SDI sdi = new SDI( gene1, species1 );
11103             if ( !gene1.getRoot().isDuplication() ) {
11104                 return false;
11105             }
11106             final Phylogeny species2 = factory
11107                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11108                              new NHXParser() )[ 0 ];
11109             final Phylogeny gene2 = factory
11110                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11111                              new NHXParser() )[ 0 ];
11112             species2.setRooted( true );
11113             gene2.setRooted( true );
11114             final SDI sdi2 = new SDI( gene2, species2 );
11115             if ( sdi2.getDuplicationsSum() != 0 ) {
11116                 return false;
11117             }
11118             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
11119                 return false;
11120             }
11121             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
11122                 return false;
11123             }
11124             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
11125                 return false;
11126             }
11127             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
11128                 return false;
11129             }
11130             if ( !gene2.getNode( "r" ).isSpeciation() ) {
11131                 return false;
11132             }
11133             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
11134                 return false;
11135             }
11136             final Phylogeny species3 = factory
11137                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11138                              new NHXParser() )[ 0 ];
11139             final Phylogeny gene3 = factory
11140                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11141                              new NHXParser() )[ 0 ];
11142             species3.setRooted( true );
11143             gene3.setRooted( true );
11144             final SDI sdi3 = new SDI( gene3, species3 );
11145             if ( sdi3.getDuplicationsSum() != 1 ) {
11146                 return false;
11147             }
11148             if ( !gene3.getNode( "aa" ).isDuplication() ) {
11149                 return false;
11150             }
11151             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
11152                 return false;
11153             }
11154             final Phylogeny species4 = factory
11155                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11156                              new NHXParser() )[ 0 ];
11157             final Phylogeny gene4 = factory
11158                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11159                              new NHXParser() )[ 0 ];
11160             species4.setRooted( true );
11161             gene4.setRooted( true );
11162             final SDI sdi4 = new SDI( gene4, species4 );
11163             if ( sdi4.getDuplicationsSum() != 1 ) {
11164                 return false;
11165             }
11166             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
11167                 return false;
11168             }
11169             if ( !gene4.getNode( "abc" ).isDuplication() ) {
11170                 return false;
11171             }
11172             if ( gene4.getNode( "abcd" ).isDuplication() ) {
11173                 return false;
11174             }
11175             if ( species4.getNumberOfExternalNodes() != 6 ) {
11176                 return false;
11177             }
11178             if ( gene4.getNumberOfExternalNodes() != 6 ) {
11179                 return false;
11180             }
11181             final Phylogeny species5 = factory
11182                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11183                              new NHXParser() )[ 0 ];
11184             final Phylogeny gene5 = factory
11185                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11186                              new NHXParser() )[ 0 ];
11187             species5.setRooted( true );
11188             gene5.setRooted( true );
11189             final SDI sdi5 = new SDI( gene5, species5 );
11190             if ( sdi5.getDuplicationsSum() != 2 ) {
11191                 return false;
11192             }
11193             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
11194                 return false;
11195             }
11196             if ( !gene5.getNode( "adc" ).isDuplication() ) {
11197                 return false;
11198             }
11199             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
11200                 return false;
11201             }
11202             if ( species5.getNumberOfExternalNodes() != 6 ) {
11203                 return false;
11204             }
11205             if ( gene5.getNumberOfExternalNodes() != 6 ) {
11206                 return false;
11207             }
11208             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
11209             // Conjecture for Comparing Molecular Phylogenies"
11210             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
11211             final Phylogeny species6 = factory
11212                     .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,"
11213                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11214                             new NHXParser() )[ 0 ];
11215             final Phylogeny gene6 = factory
11216                     .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,"
11217                             + "((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,"
11218                             + "(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;",
11219                             new NHXParser() )[ 0 ];
11220             species6.setRooted( true );
11221             gene6.setRooted( true );
11222             final SDI sdi6 = new SDI( gene6, species6 );
11223             if ( sdi6.getDuplicationsSum() != 3 ) {
11224                 return false;
11225             }
11226             if ( !gene6.getNode( "r" ).isDuplication() ) {
11227                 return false;
11228             }
11229             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
11230                 return false;
11231             }
11232             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
11233                 return false;
11234             }
11235             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
11236                 return false;
11237             }
11238             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
11239                 return false;
11240             }
11241             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
11242                 return false;
11243             }
11244             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
11245                 return false;
11246             }
11247             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
11248                 return false;
11249             }
11250             sdi6.computeMappingCostL();
11251             if ( sdi6.computeMappingCostL() != 17 ) {
11252                 return false;
11253             }
11254             if ( species6.getNumberOfExternalNodes() != 9 ) {
11255                 return false;
11256             }
11257             if ( gene6.getNumberOfExternalNodes() != 9 ) {
11258                 return false;
11259             }
11260             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
11261                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
11262                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
11263                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
11264                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
11265             species7.setRooted( true );
11266             final Phylogeny gene7_1 = Test
11267                     .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])" );
11268             gene7_1.setRooted( true );
11269             final SDI sdi7 = new SDI( gene7_1, species7 );
11270             if ( sdi7.getDuplicationsSum() != 0 ) {
11271                 return false;
11272             }
11273             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
11274                 return false;
11275             }
11276             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
11277                 return false;
11278             }
11279             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
11280                 return false;
11281             }
11282             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
11283                 return false;
11284             }
11285             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
11286                 return false;
11287             }
11288             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
11289                 return false;
11290             }
11291             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
11292                 return false;
11293             }
11294             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
11295                 return false;
11296             }
11297             final Phylogeny gene7_2 = Test
11298                     .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])" );
11299             gene7_2.setRooted( true );
11300             final SDI sdi7_2 = new SDI( gene7_2, species7 );
11301             if ( sdi7_2.getDuplicationsSum() != 1 ) {
11302                 return false;
11303             }
11304             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
11305                 return false;
11306             }
11307             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
11308                 return false;
11309             }
11310             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
11311                 return false;
11312             }
11313             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
11314                 return false;
11315             }
11316             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
11317                 return false;
11318             }
11319             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
11320                 return false;
11321             }
11322             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
11323                 return false;
11324             }
11325             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
11326                 return false;
11327             }
11328             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
11329                 return false;
11330             }
11331         }
11332         catch ( final Exception e ) {
11333             return false;
11334         }
11335         return true;
11336     }
11337
11338     private static boolean testSDIunrooted() {
11339         try {
11340             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11341             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
11342             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
11343             final Iterator<PhylogenyBranch> iter = l.iterator();
11344             PhylogenyBranch br = iter.next();
11345             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
11346                 return false;
11347             }
11348             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
11349                 return false;
11350             }
11351             br = iter.next();
11352             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11353                 return false;
11354             }
11355             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11356                 return false;
11357             }
11358             br = iter.next();
11359             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
11360                 return false;
11361             }
11362             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
11363                 return false;
11364             }
11365             br = iter.next();
11366             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11367                 return false;
11368             }
11369             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11370                 return false;
11371             }
11372             br = iter.next();
11373             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11374                 return false;
11375             }
11376             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11377                 return false;
11378             }
11379             br = iter.next();
11380             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11381                 return false;
11382             }
11383             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11384                 return false;
11385             }
11386             br = iter.next();
11387             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11388                 return false;
11389             }
11390             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11391                 return false;
11392             }
11393             br = iter.next();
11394             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11395                 return false;
11396             }
11397             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11398                 return false;
11399             }
11400             br = iter.next();
11401             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11402                 return false;
11403             }
11404             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11405                 return false;
11406             }
11407             br = iter.next();
11408             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11409                 return false;
11410             }
11411             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11412                 return false;
11413             }
11414             br = iter.next();
11415             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11416                 return false;
11417             }
11418             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11419                 return false;
11420             }
11421             br = iter.next();
11422             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
11423                 return false;
11424             }
11425             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
11426                 return false;
11427             }
11428             br = iter.next();
11429             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11430                 return false;
11431             }
11432             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11433                 return false;
11434             }
11435             br = iter.next();
11436             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
11437                 return false;
11438             }
11439             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
11440                 return false;
11441             }
11442             br = iter.next();
11443             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
11444                 return false;
11445             }
11446             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
11447                 return false;
11448             }
11449             if ( iter.hasNext() ) {
11450                 return false;
11451             }
11452             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
11453             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
11454             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
11455             br = iter1.next();
11456             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11457                 return false;
11458             }
11459             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11460                 return false;
11461             }
11462             br = iter1.next();
11463             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11464                 return false;
11465             }
11466             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11467                 return false;
11468             }
11469             br = iter1.next();
11470             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11471                 return false;
11472             }
11473             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11474                 return false;
11475             }
11476             if ( iter1.hasNext() ) {
11477                 return false;
11478             }
11479             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
11480             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
11481             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
11482             br = iter2.next();
11483             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11484                 return false;
11485             }
11486             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11487                 return false;
11488             }
11489             br = iter2.next();
11490             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11491                 return false;
11492             }
11493             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11494                 return false;
11495             }
11496             br = iter2.next();
11497             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11498                 return false;
11499             }
11500             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11501                 return false;
11502             }
11503             if ( iter2.hasNext() ) {
11504                 return false;
11505             }
11506             final Phylogeny species0 = factory
11507                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11508                              new NHXParser() )[ 0 ];
11509             final Phylogeny gene1 = factory
11510                     .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])",
11511                              new NHXParser() )[ 0 ];
11512             species0.setRooted( true );
11513             gene1.setRooted( true );
11514             final SDIR sdi_unrooted = new SDIR();
11515             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
11516             if ( sdi_unrooted.getCount() != 1 ) {
11517                 return false;
11518             }
11519             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
11520                 return false;
11521             }
11522             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
11523                 return false;
11524             }
11525             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
11526                 return false;
11527             }
11528             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11529                 return false;
11530             }
11531             final Phylogeny gene2 = factory
11532                     .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])",
11533                              new NHXParser() )[ 0 ];
11534             gene2.setRooted( true );
11535             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
11536             if ( sdi_unrooted.getCount() != 1 ) {
11537                 return false;
11538             }
11539             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11540                 return false;
11541             }
11542             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11543                 return false;
11544             }
11545             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
11546                 return false;
11547             }
11548             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11549                 return false;
11550             }
11551             final Phylogeny species6 = factory
11552                     .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,"
11553                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11554                             new NHXParser() )[ 0 ];
11555             final Phylogeny gene6 = factory
11556                     .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],"
11557                             + "(((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],"
11558                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11559                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11560                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11561                             new NHXParser() )[ 0 ];
11562             species6.setRooted( true );
11563             gene6.setRooted( true );
11564             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
11565             if ( sdi_unrooted.getCount() != 1 ) {
11566                 return false;
11567             }
11568             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11569                 return false;
11570             }
11571             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11572                 return false;
11573             }
11574             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11575                 return false;
11576             }
11577             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11578                 return false;
11579             }
11580             if ( !p6[ 0 ].getRoot().isDuplication() ) {
11581                 return false;
11582             }
11583             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11584                 return false;
11585             }
11586             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11587                 return false;
11588             }
11589             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11590                 return false;
11591             }
11592             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11593                 return false;
11594             }
11595             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11596                 return false;
11597             }
11598             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11599                 return false;
11600             }
11601             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11602                 return false;
11603             }
11604             p6 = null;
11605             final Phylogeny species7 = factory
11606                     .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,"
11607                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11608                             new NHXParser() )[ 0 ];
11609             final Phylogeny gene7 = factory
11610                     .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],"
11611                             + "(((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],"
11612                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11613                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11614                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11615                             new NHXParser() )[ 0 ];
11616             species7.setRooted( true );
11617             gene7.setRooted( true );
11618             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11619             if ( sdi_unrooted.getCount() != 1 ) {
11620                 return false;
11621             }
11622             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11623                 return false;
11624             }
11625             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11626                 return false;
11627             }
11628             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11629                 return false;
11630             }
11631             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11632                 return false;
11633             }
11634             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11635                 return false;
11636             }
11637             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11638                 return false;
11639             }
11640             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11641                 return false;
11642             }
11643             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11644                 return false;
11645             }
11646             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11647                 return false;
11648             }
11649             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11650                 return false;
11651             }
11652             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11653                 return false;
11654             }
11655             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11656                 return false;
11657             }
11658             p7 = null;
11659             final Phylogeny species8 = factory
11660                     .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,"
11661                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11662                             new NHXParser() )[ 0 ];
11663             final Phylogeny gene8 = factory
11664                     .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],"
11665                             + "(((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],"
11666                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11667                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11668                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11669                             new NHXParser() )[ 0 ];
11670             species8.setRooted( true );
11671             gene8.setRooted( true );
11672             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11673             if ( sdi_unrooted.getCount() != 1 ) {
11674                 return false;
11675             }
11676             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11677                 return false;
11678             }
11679             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11680                 return false;
11681             }
11682             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11683                 return false;
11684             }
11685             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11686                 return false;
11687             }
11688             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11689                 return false;
11690             }
11691             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11692                 return false;
11693             }
11694             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11695                 return false;
11696             }
11697             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11698                 return false;
11699             }
11700             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11701                 return false;
11702             }
11703             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11704                 return false;
11705             }
11706             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11707                 return false;
11708             }
11709             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11710                 return false;
11711             }
11712             p8 = null;
11713         }
11714         catch ( final Exception e ) {
11715             e.printStackTrace( System.out );
11716             return false;
11717         }
11718         return true;
11719     }
11720
11721     private static boolean testSequenceDbWsTools1() {
11722         try {
11723             final PhylogenyNode n = new PhylogenyNode();
11724             n.setName( "NP_001025424" );
11725             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11726             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11727                     || !acc.getValue().equals( "NP_001025424" ) ) {
11728                 return false;
11729             }
11730             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11731             acc = SequenceDbWsTools.obtainSeqAccession( n );
11732             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11733                     || !acc.getValue().equals( "NP_001025424" ) ) {
11734                 return false;
11735             }
11736             n.setName( "NP_001025424.1" );
11737             acc = SequenceDbWsTools.obtainSeqAccession( n );
11738             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11739                     || !acc.getValue().equals( "NP_001025424" ) ) {
11740                 return false;
11741             }
11742             n.setName( "NM_001030253" );
11743             acc = SequenceDbWsTools.obtainSeqAccession( n );
11744             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11745                     || !acc.getValue().equals( "NM_001030253" ) ) {
11746                 return false;
11747             }
11748             n.setName( "BCL2_HUMAN" );
11749             acc = SequenceDbWsTools.obtainSeqAccession( n );
11750             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11751                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11752                 System.out.println( acc.toString() );
11753                 return false;
11754             }
11755             n.setName( "P10415" );
11756             acc = SequenceDbWsTools.obtainSeqAccession( n );
11757             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11758                     || !acc.getValue().equals( "P10415" ) ) {
11759                 System.out.println( acc.toString() );
11760                 return false;
11761             }
11762             n.setName( " P10415 " );
11763             acc = SequenceDbWsTools.obtainSeqAccession( n );
11764             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11765                     || !acc.getValue().equals( "P10415" ) ) {
11766                 System.out.println( acc.toString() );
11767                 return false;
11768             }
11769             n.setName( "_P10415|" );
11770             acc = SequenceDbWsTools.obtainSeqAccession( n );
11771             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11772                     || !acc.getValue().equals( "P10415" ) ) {
11773                 System.out.println( acc.toString() );
11774                 return false;
11775             }
11776             n.setName( "AY695820" );
11777             acc = SequenceDbWsTools.obtainSeqAccession( n );
11778             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11779                     || !acc.getValue().equals( "AY695820" ) ) {
11780                 System.out.println( acc.toString() );
11781                 return false;
11782             }
11783             n.setName( "_AY695820_" );
11784             acc = SequenceDbWsTools.obtainSeqAccession( n );
11785             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11786                     || !acc.getValue().equals( "AY695820" ) ) {
11787                 System.out.println( acc.toString() );
11788                 return false;
11789             }
11790             n.setName( "AAA59452" );
11791             acc = SequenceDbWsTools.obtainSeqAccession( n );
11792             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11793                     || !acc.getValue().equals( "AAA59452" ) ) {
11794                 System.out.println( acc.toString() );
11795                 return false;
11796             }
11797             n.setName( "_AAA59452_" );
11798             acc = SequenceDbWsTools.obtainSeqAccession( n );
11799             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11800                     || !acc.getValue().equals( "AAA59452" ) ) {
11801                 System.out.println( acc.toString() );
11802                 return false;
11803             }
11804             n.setName( "AAA59452.1" );
11805             acc = SequenceDbWsTools.obtainSeqAccession( n );
11806             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11807                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11808                 System.out.println( acc.toString() );
11809                 return false;
11810             }
11811             n.setName( "_AAA59452.1_" );
11812             acc = SequenceDbWsTools.obtainSeqAccession( n );
11813             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11814                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11815                 System.out.println( acc.toString() );
11816                 return false;
11817             }
11818             n.setName( "GI:94894583" );
11819             acc = SequenceDbWsTools.obtainSeqAccession( n );
11820             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11821                     || !acc.getValue().equals( "94894583" ) ) {
11822                 System.out.println( acc.toString() );
11823                 return false;
11824             }
11825             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11826             acc = SequenceDbWsTools.obtainSeqAccession( n );
11827             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11828                     || !acc.getValue().equals( "71845847" ) ) {
11829                 System.out.println( acc.toString() );
11830                 return false;
11831             }
11832             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11833             acc = SequenceDbWsTools.obtainSeqAccession( n );
11834             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11835                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11836                 System.out.println( acc.toString() );
11837                 return false;
11838             }
11839         }
11840         catch ( final Exception e ) {
11841             return false;
11842         }
11843         return true;
11844     }
11845
11846     private static boolean testSequenceDbWsTools2() {
11847         try {
11848             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11849             SequenceDbWsTools.obtainSeqInformation( n1 );
11850             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11851                 return false;
11852             }
11853             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11854                 return false;
11855             }
11856             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11857                 return false;
11858             }
11859             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11860                 return false;
11861             }
11862             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11863             SequenceDbWsTools.obtainSeqInformation( n2 );
11864             if ( !n2.getNodeData().getSequence().getName().equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
11865                 return false;
11866             }
11867             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11868                 return false;
11869             }
11870             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11871                 return false;
11872             }
11873             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11874                 return false;
11875             }
11876             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11877             SequenceDbWsTools.obtainSeqInformation( n3 );
11878             if ( !n3.getNodeData().getSequence().getName()
11879                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11880                 return false;
11881             }
11882             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11883                 return false;
11884             }
11885             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11886                 return false;
11887             }
11888             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11889                 return false;
11890             }
11891         }
11892         catch ( final IOException e ) {
11893             System.out.println();
11894             System.out.println( "the following might be due to absence internet connection:" );
11895             e.printStackTrace( System.out );
11896             return true;
11897         }
11898         catch ( final Exception e ) {
11899             e.printStackTrace();
11900             return false;
11901         }
11902         return true;
11903     }
11904
11905     private static boolean testSequenceIdParsing() {
11906         try {
11907             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11908             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11909                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11910                 if ( id != null ) {
11911                     System.out.println( "value   =" + id.getValue() );
11912                     System.out.println( "provider=" + id.getSource() );
11913                 }
11914                 return false;
11915             }
11916             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11917             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11918                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11919                 if ( id != null ) {
11920                     System.out.println( "value   =" + id.getValue() );
11921                     System.out.println( "provider=" + id.getSource() );
11922                 }
11923                 return false;
11924             }
11925             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11926             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11927                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11928                 if ( id != null ) {
11929                     System.out.println( "value   =" + id.getValue() );
11930                     System.out.println( "provider=" + id.getSource() );
11931                 }
11932                 return false;
11933             }
11934             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11935             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11936                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11937                 if ( id != null ) {
11938                     System.out.println( "value   =" + id.getValue() );
11939                     System.out.println( "provider=" + id.getSource() );
11940                 }
11941                 return false;
11942             }
11943             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11944             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11945                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11946                 if ( id != null ) {
11947                     System.out.println( "value   =" + id.getValue() );
11948                     System.out.println( "provider=" + id.getSource() );
11949                 }
11950                 return false;
11951             }
11952             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11953             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11954                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11955                 if ( id != null ) {
11956                     System.out.println( "value   =" + id.getValue() );
11957                     System.out.println( "provider=" + id.getSource() );
11958                 }
11959                 return false;
11960             }
11961             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11962             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11963                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11964                 if ( id != null ) {
11965                     System.out.println( "value   =" + id.getValue() );
11966                     System.out.println( "provider=" + id.getSource() );
11967                 }
11968                 return false;
11969             }
11970             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11971             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11972                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11973                 if ( id != null ) {
11974                     System.out.println( "value   =" + id.getValue() );
11975                     System.out.println( "provider=" + id.getSource() );
11976                 }
11977                 return false;
11978             }
11979             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11980             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11981                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11982                 if ( id != null ) {
11983                     System.out.println( "value   =" + id.getValue() );
11984                     System.out.println( "provider=" + id.getSource() );
11985                 }
11986                 return false;
11987             }
11988             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11989             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11990                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11991                 if ( id != null ) {
11992                     System.out.println( "value   =" + id.getValue() );
11993                     System.out.println( "provider=" + id.getSource() );
11994                 }
11995                 return false;
11996             }
11997             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11998             if ( id != null ) {
11999                 System.out.println( "value   =" + id.getValue() );
12000                 System.out.println( "provider=" + id.getSource() );
12001                 return false;
12002             }
12003             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
12004             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12005                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
12006                 if ( id != null ) {
12007                     System.out.println( "value   =" + id.getValue() );
12008                     System.out.println( "provider=" + id.getSource() );
12009                 }
12010                 return false;
12011             }
12012             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
12013             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12014                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
12015                 if ( id != null ) {
12016                     System.out.println( "value   =" + id.getValue() );
12017                     System.out.println( "provider=" + id.getSource() );
12018                 }
12019                 return false;
12020             }
12021             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
12022             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12023                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
12024                 if ( id != null ) {
12025                     System.out.println( "value   =" + id.getValue() );
12026                     System.out.println( "provider=" + id.getSource() );
12027                 }
12028                 return false;
12029             }
12030             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
12031             if ( id != null ) {
12032                 System.out.println( "value   =" + id.getValue() );
12033                 System.out.println( "provider=" + id.getSource() );
12034                 return false;
12035             }
12036         }
12037         catch ( final Exception e ) {
12038             e.printStackTrace( System.out );
12039             return false;
12040         }
12041         return true;
12042     }
12043
12044     private static boolean testSequenceWriter() {
12045         try {
12046             final String n = ForesterUtil.LINE_SEPARATOR;
12047             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
12048                 return false;
12049             }
12050             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
12051                 return false;
12052             }
12053             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
12054                 return false;
12055             }
12056             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
12057                 return false;
12058             }
12059             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
12060                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
12061                 return false;
12062             }
12063             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
12064                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
12065                 return false;
12066             }
12067         }
12068         catch ( final Exception e ) {
12069             e.printStackTrace();
12070             return false;
12071         }
12072         return true;
12073     }
12074
12075     private static boolean testSpecies() {
12076         try {
12077             final Species s1 = new BasicSpecies( "a" );
12078             final Species s2 = new BasicSpecies( "a" );
12079             final Species s3 = new BasicSpecies( "A" );
12080             final Species s4 = new BasicSpecies( "b" );
12081             if ( !s1.equals( s1 ) ) {
12082                 return false;
12083             }
12084             if ( s1.getSpeciesId().equals( "x" ) ) {
12085                 return false;
12086             }
12087             if ( s1.getSpeciesId().equals( null ) ) {
12088                 return false;
12089             }
12090             if ( !s1.equals( s2 ) ) {
12091                 return false;
12092             }
12093             if ( s1.equals( s3 ) ) {
12094                 return false;
12095             }
12096             if ( s1.hashCode() != s1.hashCode() ) {
12097                 return false;
12098             }
12099             if ( s1.hashCode() != s2.hashCode() ) {
12100                 return false;
12101             }
12102             if ( s1.hashCode() == s3.hashCode() ) {
12103                 return false;
12104             }
12105             if ( s1.compareTo( s1 ) != 0 ) {
12106                 return false;
12107             }
12108             if ( s1.compareTo( s2 ) != 0 ) {
12109                 return false;
12110             }
12111             if ( s1.compareTo( s3 ) != 0 ) {
12112                 return false;
12113             }
12114             if ( s1.compareTo( s4 ) >= 0 ) {
12115                 return false;
12116             }
12117             if ( s4.compareTo( s1 ) <= 0 ) {
12118                 return false;
12119             }
12120             if ( !s4.getSpeciesId().equals( "b" ) ) {
12121                 return false;
12122             }
12123             final Species s5 = new BasicSpecies( " C " );
12124             if ( !s5.getSpeciesId().equals( "C" ) ) {
12125                 return false;
12126             }
12127             if ( s5.equals( s1 ) ) {
12128                 return false;
12129             }
12130         }
12131         catch ( final Exception e ) {
12132             e.printStackTrace( System.out );
12133             return false;
12134         }
12135         return true;
12136     }
12137
12138     private static boolean testSplit() {
12139         try {
12140             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12141             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12142             //Archaeopteryx.createApplication( p0 );
12143             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
12144             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12145             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12146             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12147             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12148             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12149             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12150             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12151             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12152             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12153             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
12154             // System.out.println( s0.toString() );
12155             //
12156             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12157             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12158             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12159             if ( s0.match( query_nodes ) ) {
12160                 return false;
12161             }
12162             query_nodes = new HashSet<PhylogenyNode>();
12163             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12164             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12165             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12166             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12167             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12168             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12169             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12170             if ( !s0.match( query_nodes ) ) {
12171                 return false;
12172             }
12173             //
12174             query_nodes = new HashSet<PhylogenyNode>();
12175             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12176             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12177             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12178             if ( !s0.match( query_nodes ) ) {
12179                 return false;
12180             }
12181             //
12182             query_nodes = new HashSet<PhylogenyNode>();
12183             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12184             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12185             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12186             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12187             if ( !s0.match( query_nodes ) ) {
12188                 return false;
12189             }
12190             //
12191             query_nodes = new HashSet<PhylogenyNode>();
12192             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12193             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12194             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12195             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12196             if ( !s0.match( query_nodes ) ) {
12197                 return false;
12198             }
12199             //
12200             query_nodes = new HashSet<PhylogenyNode>();
12201             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12202             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12203             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12204             if ( !s0.match( query_nodes ) ) {
12205                 return false;
12206             }
12207             query_nodes = new HashSet<PhylogenyNode>();
12208             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12209             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12210             if ( !s0.match( query_nodes ) ) {
12211                 return false;
12212             }
12213             query_nodes = new HashSet<PhylogenyNode>();
12214             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12215             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12216             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12217             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12218             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12219             if ( !s0.match( query_nodes ) ) {
12220                 return false;
12221             }
12222             query_nodes = new HashSet<PhylogenyNode>();
12223             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12224             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12225             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12226             if ( !s0.match( query_nodes ) ) {
12227                 return false;
12228             }
12229             query_nodes = new HashSet<PhylogenyNode>();
12230             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12231             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12232             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12233             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12234             if ( !s0.match( query_nodes ) ) {
12235                 return false;
12236             }
12237             query_nodes = new HashSet<PhylogenyNode>();
12238             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12239             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12240             if ( s0.match( query_nodes ) ) {
12241                 return false;
12242             }
12243             query_nodes = new HashSet<PhylogenyNode>();
12244             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12245             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12246             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12247             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12248             if ( s0.match( query_nodes ) ) {
12249                 return false;
12250             }
12251             query_nodes = new HashSet<PhylogenyNode>();
12252             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12253             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12254             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12255             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12256             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12257             if ( s0.match( query_nodes ) ) {
12258                 return false;
12259             }
12260             query_nodes = new HashSet<PhylogenyNode>();
12261             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12262             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12263             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12264             if ( s0.match( query_nodes ) ) {
12265                 return false;
12266             }
12267             query_nodes = new HashSet<PhylogenyNode>();
12268             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12269             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12270             if ( s0.match( query_nodes ) ) {
12271                 return false;
12272             }
12273             query_nodes = new HashSet<PhylogenyNode>();
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             query_nodes = new HashSet<PhylogenyNode>();
12280             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12281             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12282             if ( s0.match( query_nodes ) ) {
12283                 return false;
12284             }
12285             query_nodes = new HashSet<PhylogenyNode>();
12286             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12287             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12288             if ( s0.match( query_nodes ) ) {
12289                 return false;
12290             }
12291             query_nodes = new HashSet<PhylogenyNode>();
12292             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12293             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12294             if ( s0.match( query_nodes ) ) {
12295                 return false;
12296             }
12297             query_nodes = new HashSet<PhylogenyNode>();
12298             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12299             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12300             if ( s0.match( query_nodes ) ) {
12301                 return false;
12302             }
12303             query_nodes = new HashSet<PhylogenyNode>();
12304             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12305             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12306             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12307             if ( s0.match( query_nodes ) ) {
12308                 return false;
12309             }
12310             query_nodes = new HashSet<PhylogenyNode>();
12311             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12312             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12313             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12314             if ( s0.match( query_nodes ) ) {
12315                 return false;
12316             }
12317             query_nodes = new HashSet<PhylogenyNode>();
12318             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12319             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12320             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12321             if ( s0.match( query_nodes ) ) {
12322                 return false;
12323             }
12324             query_nodes = new HashSet<PhylogenyNode>();
12325             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12326             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12327             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12328             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12329             if ( s0.match( query_nodes ) ) {
12330                 return false;
12331             }
12332             /////////
12333             //            query_nodes = new HashSet<PhylogenyNode>();
12334             //            query_nodes.add( new PhylogenyNode( "X" ) );
12335             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12336             //            query_nodes.add( new PhylogenyNode( "A" ) );
12337             //            query_nodes.add( new PhylogenyNode( "B" ) );
12338             //            query_nodes.add( new PhylogenyNode( "C" ) );
12339             //            query_nodes.add( new PhylogenyNode( "D" ) );
12340             //            query_nodes.add( new PhylogenyNode( "E" ) );
12341             //            query_nodes.add( new PhylogenyNode( "F" ) );
12342             //            query_nodes.add( new PhylogenyNode( "G" ) );
12343             //            if ( !s0.match( query_nodes ) ) {
12344             //                return false;
12345             //            }
12346             //            query_nodes = new HashSet<PhylogenyNode>();
12347             //            query_nodes.add( new PhylogenyNode( "X" ) );
12348             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12349             //            query_nodes.add( new PhylogenyNode( "A" ) );
12350             //            query_nodes.add( new PhylogenyNode( "B" ) );
12351             //            query_nodes.add( new PhylogenyNode( "C" ) );
12352             //            if ( !s0.match( query_nodes ) ) {
12353             //                return false;
12354             //            }
12355             //            //
12356             //            query_nodes = new HashSet<PhylogenyNode>();
12357             //            query_nodes.add( new PhylogenyNode( "X" ) );
12358             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12359             //            query_nodes.add( new PhylogenyNode( "D" ) );
12360             //            query_nodes.add( new PhylogenyNode( "E" ) );
12361             //            query_nodes.add( new PhylogenyNode( "F" ) );
12362             //            query_nodes.add( new PhylogenyNode( "G" ) );
12363             //            if ( !s0.match( query_nodes ) ) {
12364             //                return false;
12365             //            }
12366             //            //
12367             //            query_nodes = new HashSet<PhylogenyNode>();
12368             //            query_nodes.add( new PhylogenyNode( "X" ) );
12369             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12370             //            query_nodes.add( new PhylogenyNode( "A" ) );
12371             //            query_nodes.add( new PhylogenyNode( "B" ) );
12372             //            query_nodes.add( new PhylogenyNode( "C" ) );
12373             //            query_nodes.add( new PhylogenyNode( "D" ) );
12374             //            if ( !s0.match( query_nodes ) ) {
12375             //                return false;
12376             //            }
12377             //            //
12378             //            query_nodes = new HashSet<PhylogenyNode>();
12379             //            query_nodes.add( new PhylogenyNode( "X" ) );
12380             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12381             //            query_nodes.add( new PhylogenyNode( "E" ) );
12382             //            query_nodes.add( new PhylogenyNode( "F" ) );
12383             //            query_nodes.add( new PhylogenyNode( "G" ) );
12384             //            if ( !s0.match( query_nodes ) ) {
12385             //                return false;
12386             //            }
12387             //            //
12388             //            query_nodes = new HashSet<PhylogenyNode>();
12389             //            query_nodes.add( new PhylogenyNode( "X" ) );
12390             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12391             //            query_nodes.add( new PhylogenyNode( "F" ) );
12392             //            query_nodes.add( new PhylogenyNode( "G" ) );
12393             //            if ( !s0.match( query_nodes ) ) {
12394             //                return false;
12395             //            }
12396             //
12397             query_nodes = new HashSet<PhylogenyNode>();
12398             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12399             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12400             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12401             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12402             if ( s0.match( query_nodes ) ) {
12403                 return false;
12404             }
12405             //
12406             query_nodes = new HashSet<PhylogenyNode>();
12407             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12408             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12409             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12410             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12411             if ( s0.match( query_nodes ) ) {
12412                 return false;
12413             }
12414             ///////////////////////////
12415             //
12416             query_nodes = new HashSet<PhylogenyNode>();
12417             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12418             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12419             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12420             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12421             if ( s0.match( query_nodes ) ) {
12422                 return false;
12423             }
12424             //
12425             query_nodes = new HashSet<PhylogenyNode>();
12426             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12427             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12428             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12429             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12430             if ( s0.match( query_nodes ) ) {
12431                 return false;
12432             }
12433             //
12434             query_nodes = new HashSet<PhylogenyNode>();
12435             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12436             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12437             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12438             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12439             if ( s0.match( query_nodes ) ) {
12440                 return false;
12441             }
12442             //
12443             query_nodes = new HashSet<PhylogenyNode>();
12444             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12445             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12446             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12447             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12448             if ( s0.match( query_nodes ) ) {
12449                 return false;
12450             }
12451             //
12452             query_nodes = new HashSet<PhylogenyNode>();
12453             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12454             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12455             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12456             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12457             if ( s0.match( query_nodes ) ) {
12458                 return false;
12459             }
12460             //
12461             query_nodes = new HashSet<PhylogenyNode>();
12462             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12463             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12464             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12465             if ( s0.match( query_nodes ) ) {
12466                 return false;
12467             }
12468             //
12469             query_nodes = new HashSet<PhylogenyNode>();
12470             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12471             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12472             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12473             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12474             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12475             if ( s0.match( query_nodes ) ) {
12476                 return false;
12477             }
12478             //
12479             query_nodes = new HashSet<PhylogenyNode>();
12480             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12481             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12482             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12483             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12484             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12485             if ( s0.match( query_nodes ) ) {
12486                 return false;
12487             }
12488             //
12489             query_nodes = new HashSet<PhylogenyNode>();
12490             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12491             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12492             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12493             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12494             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12495             if ( s0.match( query_nodes ) ) {
12496                 return false;
12497             }
12498             //
12499             query_nodes = new HashSet<PhylogenyNode>();
12500             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12501             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12502             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12503             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12504             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12505             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12506             if ( s0.match( query_nodes ) ) {
12507                 return false;
12508             }
12509         }
12510         catch ( final Exception e ) {
12511             e.printStackTrace();
12512             return false;
12513         }
12514         return true;
12515     }
12516
12517     private static boolean testSplitStrict() {
12518         try {
12519             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12520             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12521             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
12522             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12523             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12524             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12525             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12526             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12527             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12528             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12529             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
12530             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12531             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12532             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12533             if ( s0.match( query_nodes ) ) {
12534                 return false;
12535             }
12536             query_nodes = new HashSet<PhylogenyNode>();
12537             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12538             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12539             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12540             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12541             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12542             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12543             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12544             if ( !s0.match( query_nodes ) ) {
12545                 return false;
12546             }
12547             //
12548             query_nodes = new HashSet<PhylogenyNode>();
12549             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12550             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12551             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12552             if ( !s0.match( query_nodes ) ) {
12553                 return false;
12554             }
12555             //
12556             query_nodes = new HashSet<PhylogenyNode>();
12557             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12558             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12559             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12560             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12561             if ( !s0.match( query_nodes ) ) {
12562                 return false;
12563             }
12564             //
12565             query_nodes = new HashSet<PhylogenyNode>();
12566             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12567             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12568             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12569             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12570             if ( !s0.match( query_nodes ) ) {
12571                 return false;
12572             }
12573             //
12574             query_nodes = new HashSet<PhylogenyNode>();
12575             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12576             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12577             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12578             if ( !s0.match( query_nodes ) ) {
12579                 return false;
12580             }
12581             //
12582             query_nodes = new HashSet<PhylogenyNode>();
12583             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12584             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12585             if ( !s0.match( query_nodes ) ) {
12586                 return false;
12587             }
12588             //
12589             query_nodes = new HashSet<PhylogenyNode>();
12590             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12591             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12592             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12593             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12594             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12595             if ( !s0.match( query_nodes ) ) {
12596                 return false;
12597             }
12598             //
12599             query_nodes = new HashSet<PhylogenyNode>();
12600             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12601             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12602             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12603             if ( !s0.match( query_nodes ) ) {
12604                 return false;
12605             }
12606             //
12607             query_nodes = new HashSet<PhylogenyNode>();
12608             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12609             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12610             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12611             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12612             if ( !s0.match( query_nodes ) ) {
12613                 return false;
12614             }
12615             //
12616             query_nodes = new HashSet<PhylogenyNode>();
12617             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12618             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12619             if ( s0.match( query_nodes ) ) {
12620                 return false;
12621             }
12622             //
12623             query_nodes = new HashSet<PhylogenyNode>();
12624             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12625             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12626             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12627             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12628             if ( s0.match( query_nodes ) ) {
12629                 return false;
12630             }
12631             //
12632             query_nodes = new HashSet<PhylogenyNode>();
12633             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12634             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12635             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12636             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12637             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12638             if ( s0.match( query_nodes ) ) {
12639                 return false;
12640             }
12641             //
12642             query_nodes = new HashSet<PhylogenyNode>();
12643             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12644             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12645             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12646             if ( s0.match( query_nodes ) ) {
12647                 return false;
12648             }
12649             //
12650             query_nodes = new HashSet<PhylogenyNode>();
12651             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12652             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12653             if ( s0.match( query_nodes ) ) {
12654                 return false;
12655             }
12656             //
12657             query_nodes = new HashSet<PhylogenyNode>();
12658             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12659             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12660             if ( s0.match( query_nodes ) ) {
12661                 return false;
12662             }
12663             //
12664             query_nodes = new HashSet<PhylogenyNode>();
12665             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12666             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12667             if ( s0.match( query_nodes ) ) {
12668                 return false;
12669             }
12670             //
12671             query_nodes = new HashSet<PhylogenyNode>();
12672             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12673             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12674             if ( s0.match( query_nodes ) ) {
12675                 return false;
12676             }
12677             //
12678             query_nodes = new HashSet<PhylogenyNode>();
12679             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12680             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12681             if ( s0.match( query_nodes ) ) {
12682                 return false;
12683             }
12684             //
12685             query_nodes = new HashSet<PhylogenyNode>();
12686             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12688             if ( s0.match( query_nodes ) ) {
12689                 return false;
12690             }
12691             //
12692             query_nodes = new HashSet<PhylogenyNode>();
12693             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12694             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12695             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12696             if ( s0.match( query_nodes ) ) {
12697                 return false;
12698             }
12699             //
12700             query_nodes = new HashSet<PhylogenyNode>();
12701             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12702             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12703             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12704             if ( s0.match( query_nodes ) ) {
12705                 return false;
12706             }
12707             //
12708             query_nodes = new HashSet<PhylogenyNode>();
12709             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12710             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12711             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12712             if ( s0.match( query_nodes ) ) {
12713                 return false;
12714             }
12715             //
12716             query_nodes = new HashSet<PhylogenyNode>();
12717             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12718             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12719             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12720             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12721             if ( s0.match( query_nodes ) ) {
12722                 return false;
12723             }
12724         }
12725         catch ( final Exception e ) {
12726             e.printStackTrace();
12727             return false;
12728         }
12729         return true;
12730     }
12731
12732     private static boolean testSubtreeDeletion() {
12733         try {
12734             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12735             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12736             t1.deleteSubtree( t1.getNode( "A" ), false );
12737             if ( t1.getNumberOfExternalNodes() != 5 ) {
12738                 return false;
12739             }
12740             t1.toNewHampshireX();
12741             t1.deleteSubtree( t1.getNode( "E" ), false );
12742             if ( t1.getNumberOfExternalNodes() != 4 ) {
12743                 return false;
12744             }
12745             t1.toNewHampshireX();
12746             t1.deleteSubtree( t1.getNode( "F" ), false );
12747             if ( t1.getNumberOfExternalNodes() != 3 ) {
12748                 return false;
12749             }
12750             t1.toNewHampshireX();
12751             t1.deleteSubtree( t1.getNode( "D" ), false );
12752             t1.toNewHampshireX();
12753             if ( t1.getNumberOfExternalNodes() != 3 ) {
12754                 return false;
12755             }
12756             t1.deleteSubtree( t1.getNode( "def" ), false );
12757             t1.toNewHampshireX();
12758             if ( t1.getNumberOfExternalNodes() != 2 ) {
12759                 return false;
12760             }
12761             t1.deleteSubtree( t1.getNode( "B" ), false );
12762             t1.toNewHampshireX();
12763             if ( t1.getNumberOfExternalNodes() != 1 ) {
12764                 return false;
12765             }
12766             t1.deleteSubtree( t1.getNode( "C" ), false );
12767             t1.toNewHampshireX();
12768             if ( t1.getNumberOfExternalNodes() != 1 ) {
12769                 return false;
12770             }
12771             t1.deleteSubtree( t1.getNode( "abc" ), false );
12772             t1.toNewHampshireX();
12773             if ( t1.getNumberOfExternalNodes() != 1 ) {
12774                 return false;
12775             }
12776             t1.deleteSubtree( t1.getNode( "r" ), false );
12777             if ( t1.getNumberOfExternalNodes() != 0 ) {
12778                 return false;
12779             }
12780             if ( !t1.isEmpty() ) {
12781                 return false;
12782             }
12783             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12784             t2.deleteSubtree( t2.getNode( "A" ), false );
12785             t2.toNewHampshireX();
12786             if ( t2.getNumberOfExternalNodes() != 5 ) {
12787                 return false;
12788             }
12789             t2.deleteSubtree( t2.getNode( "abc" ), false );
12790             t2.toNewHampshireX();
12791             if ( t2.getNumberOfExternalNodes() != 3 ) {
12792                 return false;
12793             }
12794             t2.deleteSubtree( t2.getNode( "def" ), false );
12795             t2.toNewHampshireX();
12796             if ( t2.getNumberOfExternalNodes() != 1 ) {
12797                 return false;
12798             }
12799         }
12800         catch ( final Exception e ) {
12801             e.printStackTrace( System.out );
12802             return false;
12803         }
12804         return true;
12805     }
12806
12807     private static boolean testSupportCount() {
12808         try {
12809             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12810             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12811             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12812                     + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12813                     + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12814                     + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12815                     + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12816                     new NHXParser() );
12817             SupportCount.count( t0_1, phylogenies_1, true, false );
12818             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12819             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12820                     + "(((((A,B),C),D),E),((F,G),X))"
12821                     + "(((((A,Y),B),C),D),((F,G),E))"
12822                     + "(((((A,B),C),D),E),(F,G))"
12823                     + "(((((A,B),C),D),E),(F,G))"
12824                     + "(((((A,B),C),D),E),(F,G))"
12825                     + "(((((A,B),C),D),E),(F,G),Z)"
12826                     + "(((((A,B),C),D),E),(F,G))"
12827                     + "((((((A,B),C),D),E),F),G)"
12828                     + "(((((X,Y),F,G),E),((A,B),C)),D)",
12829                     new NHXParser() );
12830             SupportCount.count( t0_2, phylogenies_2, true, false );
12831             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12832             while ( it.hasNext() ) {
12833                 final PhylogenyNode n = it.next();
12834                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12835                     return false;
12836                 }
12837             }
12838             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12839             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12840                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12841             SupportCount.count( t0_3, phylogenies_3, true, false );
12842             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12843             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12844                 return false;
12845             }
12846             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12847                 return false;
12848             }
12849             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12850                 return false;
12851             }
12852             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12853                 return false;
12854             }
12855             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12856                 return false;
12857             }
12858             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12859                 return false;
12860             }
12861             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12862                 return false;
12863             }
12864             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12865                 return false;
12866             }
12867             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12868                 return false;
12869             }
12870             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12871                 return false;
12872             }
12873             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12874             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12875                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12876             SupportCount.count( t0_4, phylogenies_4, true, false );
12877             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12878             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12879                 return false;
12880             }
12881             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12882                 return false;
12883             }
12884             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12885                 return false;
12886             }
12887             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12888                 return false;
12889             }
12890             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12891                 return false;
12892             }
12893             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12894                 return false;
12895             }
12896             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12897                 return false;
12898             }
12899             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12900                 return false;
12901             }
12902             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12903                 return false;
12904             }
12905             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12906                 return false;
12907             }
12908             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12909             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12910             double d = SupportCount.compare( b1, a, true, true, true );
12911             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12912                 return false;
12913             }
12914             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12915             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12916             d = SupportCount.compare( b2, a, true, true, true );
12917             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12918                 return false;
12919             }
12920             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12921             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12922             d = SupportCount.compare( b3, a, true, true, true );
12923             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12924                 return false;
12925             }
12926             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12927             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12928             d = SupportCount.compare( b4, a, true, true, false );
12929             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12930                 return false;
12931             }
12932         }
12933         catch ( final Exception e ) {
12934             e.printStackTrace( System.out );
12935             return false;
12936         }
12937         return true;
12938     }
12939
12940     private static boolean testSupportTransfer() {
12941         try {
12942             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12943             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)",
12944                                                  new NHXParser() )[ 0 ];
12945             final Phylogeny p2 = factory
12946                     .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 ];
12947             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12948                 return false;
12949             }
12950             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12951                 return false;
12952             }
12953             support_transfer.moveBranchLengthsToBootstrap( p1 );
12954             support_transfer.transferSupportValues( p1, p2 );
12955             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12956                 return false;
12957             }
12958             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12959                 return false;
12960             }
12961             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12962                 return false;
12963             }
12964             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12965                 return false;
12966             }
12967             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12968                 return false;
12969             }
12970             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12971                 return false;
12972             }
12973             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12974                 return false;
12975             }
12976             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12977                 return false;
12978             }
12979         }
12980         catch ( final Exception e ) {
12981             e.printStackTrace( System.out );
12982             return false;
12983         }
12984         return true;
12985     }
12986
12987     private static boolean testTaxonomyExtraction() {
12988         try {
12989             final PhylogenyNode n0 = PhylogenyNode
12990                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12991             if ( n0.getNodeData().isHasTaxonomy() ) {
12992                 return false;
12993             }
12994             final PhylogenyNode n1 = PhylogenyNode
12995                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12996             if ( n1.getNodeData().isHasTaxonomy() ) {
12997                 System.out.println( n1.toString() );
12998                 return false;
12999             }
13000             final PhylogenyNode n2x = PhylogenyNode
13001                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13002             if ( n2x.getNodeData().isHasTaxonomy() ) {
13003                 return false;
13004             }
13005             final PhylogenyNode n3 = PhylogenyNode
13006                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13007             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13008                 System.out.println( n3.toString() );
13009                 return false;
13010             }
13011             final PhylogenyNode n4 = PhylogenyNode
13012                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13013             if ( n4.getNodeData().isHasTaxonomy() ) {
13014                 System.out.println( n4.toString() );
13015                 return false;
13016             }
13017             final PhylogenyNode n5 = PhylogenyNode
13018                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13019             if ( n5.getNodeData().isHasTaxonomy() ) {
13020                 System.out.println( n5.toString() );
13021                 return false;
13022             }
13023             final PhylogenyNode n6 = PhylogenyNode
13024                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13025             if ( n6.getNodeData().isHasTaxonomy() ) {
13026                 System.out.println( n6.toString() );
13027                 return false;
13028             }
13029             final PhylogenyNode n7 = PhylogenyNode
13030                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13031             if ( n7.getNodeData().isHasTaxonomy() ) {
13032                 System.out.println( n7.toString() );
13033                 return false;
13034             }
13035             final PhylogenyNode n8 = PhylogenyNode
13036                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13037             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13038                 System.out.println( n8.toString() );
13039                 return false;
13040             }
13041             final PhylogenyNode n9 = PhylogenyNode
13042                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13043             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13044                 System.out.println( n9.toString() );
13045                 return false;
13046             }
13047             final PhylogenyNode n10x = PhylogenyNode
13048                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13049             if ( n10x.getNodeData().isHasTaxonomy() ) {
13050                 System.out.println( n10x.toString() );
13051                 return false;
13052             }
13053             final PhylogenyNode n10xx = PhylogenyNode
13054                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13055             if ( n10xx.getNodeData().isHasTaxonomy() ) {
13056                 System.out.println( n10xx.toString() );
13057                 return false;
13058             }
13059             final PhylogenyNode n10 = PhylogenyNode
13060                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13061             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
13062                 System.out.println( n10.toString() );
13063                 return false;
13064             }
13065             final PhylogenyNode n11 = PhylogenyNode
13066                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13067             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13068                 System.out.println( n11.toString() );
13069                 return false;
13070             }
13071             final PhylogenyNode n12 = PhylogenyNode
13072                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
13073                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13074             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13075                 System.out.println( n12.toString() );
13076                 return false;
13077             }
13078             final PhylogenyNode n13 = PhylogenyNode
13079                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13080             if ( n13.getNodeData().isHasTaxonomy() ) {
13081                 System.out.println( n13.toString() );
13082                 return false;
13083             }
13084             final PhylogenyNode n14 = PhylogenyNode
13085                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13086             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13087                 System.out.println( n14.toString() );
13088                 return false;
13089             }
13090             final PhylogenyNode n15 = PhylogenyNode
13091                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13092             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13093                 System.out.println( n15.toString() );
13094                 return false;
13095             }
13096             final PhylogenyNode n16 = PhylogenyNode
13097                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13098             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13099                 System.out.println( n16.toString() );
13100                 return false;
13101             }
13102             final PhylogenyNode n17 = PhylogenyNode
13103                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13104             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13105                 System.out.println( n17.toString() );
13106                 return false;
13107             }
13108             final PhylogenyNode n18 = PhylogenyNode
13109                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13110             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13111                 System.out.println( n18.toString() );
13112                 return false;
13113             }
13114             final PhylogenyNode n19 = PhylogenyNode
13115                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
13116                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13117             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13118                 System.out.println( n19.toString() );
13119                 return false;
13120             }
13121             final PhylogenyNode n20 = PhylogenyNode
13122                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13123             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13124                 System.out.println( n20.toString() );
13125                 return false;
13126             }
13127             final PhylogenyNode n21 = PhylogenyNode
13128                     .createInstanceFromNhxString( "Mus musculus musculus K392",
13129                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13130             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13131                 System.out.println( n21.toString() );
13132                 return false;
13133             }
13134             final PhylogenyNode n23 = PhylogenyNode
13135                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
13136                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13137             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13138                 System.out.println( n23.toString() );
13139                 return false;
13140             }
13141             final PhylogenyNode n24 = PhylogenyNode
13142                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13143             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13144                 System.out.println( n24.toString() );
13145                 return false;
13146             }
13147             //
13148             final PhylogenyNode n25 = PhylogenyNode
13149                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
13150                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13151             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
13152                 System.out.println( n25.toString() );
13153                 return false;
13154             }
13155             final PhylogenyNode n26 = PhylogenyNode
13156                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
13157                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13158             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13159                 System.out.println( n26.toString() );
13160                 return false;
13161             }
13162             final PhylogenyNode n27 = PhylogenyNode
13163                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13164             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13165                 System.out.println( n27.toString() );
13166                 return false;
13167             }
13168         }
13169         catch ( final Exception e ) {
13170             e.printStackTrace( System.out );
13171             return false;
13172         }
13173         return true;
13174     }
13175
13176     private static boolean testTreeCopy() {
13177         try {
13178             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
13179             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
13180             final Phylogeny t1 = t0.copy();
13181             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
13182                 return false;
13183             }
13184             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13185                 return false;
13186             }
13187             t0.deleteSubtree( t0.getNode( "c" ), true );
13188             t0.deleteSubtree( t0.getNode( "a" ), true );
13189             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
13190             t0.getNode( "b" ).setName( "Bee" );
13191             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
13192                 return false;
13193             }
13194             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13195                 return false;
13196             }
13197             t0.deleteSubtree( t0.getNode( "e" ), true );
13198             t0.deleteSubtree( t0.getNode( "Bee" ), true );
13199             t0.deleteSubtree( t0.getNode( "d" ), true );
13200             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13201                 return false;
13202             }
13203         }
13204         catch ( final Exception e ) {
13205             e.printStackTrace();
13206             return false;
13207         }
13208         return true;
13209     }
13210
13211     private static boolean testTreeMethods() {
13212         try {
13213             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13214             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
13215             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
13216             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
13217                 System.out.println( t0.toNewHampshireX() );
13218                 return false;
13219             }
13220             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
13221             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
13222             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
13223                 return false;
13224             }
13225             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
13226                 return false;
13227             }
13228             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
13229                 return false;
13230             }
13231         }
13232         catch ( final Exception e ) {
13233             e.printStackTrace( System.out );
13234             return false;
13235         }
13236         return true;
13237     }
13238
13239     private static boolean testUniprotEntryRetrieval() {
13240         try {
13241             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 5000 );
13242             if ( !entry.getAccession().equals( "P12345" ) ) {
13243                 return false;
13244             }
13245             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
13246                 return false;
13247             }
13248             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
13249                 return false;
13250             }
13251             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
13252                 return false;
13253             }
13254             if ( !entry.getGeneName().equals( "GOT2" ) ) {
13255                 return false;
13256             }
13257             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
13258                 return false;
13259             }
13260             if ( entry.getMolecularSequence() == null ) {
13261                 return false;
13262             }
13263             if ( !entry
13264                     .getMolecularSequence()
13265                     .getMolecularSequenceAsString()
13266                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
13267                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
13268                 System.out.println( "got: " + entry.getMolecularSequence().getMolecularSequenceAsString() );
13269                 System.out.println( "expected something else." );
13270                 return false;
13271             }
13272         }
13273         catch ( final IOException e ) {
13274             System.out.println();
13275             System.out.println( "the following might be due to absence internet connection:" );
13276             e.printStackTrace( System.out );
13277             return true;
13278         }
13279         catch ( final NullPointerException f ) {
13280             f.printStackTrace( System.out );
13281             return false;
13282         }
13283         catch ( final Exception e ) {
13284             return false;
13285         }
13286         return true;
13287     }
13288
13289     private static boolean testUniprotTaxonomySearch() {
13290         try {
13291             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
13292                                                                                                  10 );
13293             if ( results.size() != 1 ) {
13294                 return false;
13295             }
13296             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13297                 return false;
13298             }
13299             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13300                 return false;
13301             }
13302             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13303                 return false;
13304             }
13305             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13306                 return false;
13307             }
13308             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13309                 return false;
13310             }
13311             results = null;
13312             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
13313             if ( results.size() != 1 ) {
13314                 return false;
13315             }
13316             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13317                 return false;
13318             }
13319             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13320                 return false;
13321             }
13322             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13323                 return false;
13324             }
13325             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13326                 return false;
13327             }
13328             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13329                 return false;
13330             }
13331             results = null;
13332             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
13333             if ( results.size() != 1 ) {
13334                 return false;
13335             }
13336             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13337                 return false;
13338             }
13339             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13340                 return false;
13341             }
13342             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13343                 return false;
13344             }
13345             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13346                 return false;
13347             }
13348             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13349                 return false;
13350             }
13351             results = null;
13352             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
13353             if ( results.size() != 1 ) {
13354                 return false;
13355             }
13356             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13357                 return false;
13358             }
13359             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13360                 return false;
13361             }
13362             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13363                 return false;
13364             }
13365             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13366                 return false;
13367             }
13368             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13369                 return false;
13370             }
13371             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
13372                 return false;
13373             }
13374             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
13375                 return false;
13376             }
13377             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13378                     .equals( "Nematostella vectensis" ) ) {
13379                 System.out.println( results.get( 0 ).getLineage() );
13380                 return false;
13381             }
13382             //
13383             results = null;
13384             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
13385             if ( results.size() != 1 ) {
13386                 return false;
13387             }
13388             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13389                 return false;
13390             }
13391             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13392                 return false;
13393             }
13394             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13395                 return false;
13396             }
13397             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13398                 return false;
13399             }
13400             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13401                 return false;
13402             }
13403             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13404                     .equals( "Xenopus tropicalis" ) ) {
13405                 System.out.println( results.get( 0 ).getLineage() );
13406                 return false;
13407             }
13408             //
13409             results = null;
13410             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
13411             if ( results.size() != 1 ) {
13412                 return false;
13413             }
13414             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13415                 return false;
13416             }
13417             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13418                 return false;
13419             }
13420             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13421                 return false;
13422             }
13423             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13424                 return false;
13425             }
13426             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13427                 return false;
13428             }
13429             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13430                     .equals( "Xenopus tropicalis" ) ) {
13431                 System.out.println( results.get( 0 ).getLineage() );
13432                 return false;
13433             }
13434             //
13435             results = null;
13436             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
13437             if ( results.size() != 1 ) {
13438                 return false;
13439             }
13440             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13441                 return false;
13442             }
13443             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13444                 return false;
13445             }
13446             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13447                 return false;
13448             }
13449             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13450                 return false;
13451             }
13452             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13453                 return false;
13454             }
13455             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13456                     .equals( "Xenopus tropicalis" ) ) {
13457                 System.out.println( results.get( 0 ).getLineage() );
13458                 return false;
13459             }
13460         }
13461         catch ( final IOException e ) {
13462             System.out.println();
13463             System.out.println( "the following might be due to absence internet connection:" );
13464             e.printStackTrace( System.out );
13465             return true;
13466         }
13467         catch ( final Exception e ) {
13468             return false;
13469         }
13470         return true;
13471     }
13472     
13473     
13474 }