3efa3540f5a216bee1b3432b249861e31c520cd3
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24
25 package org.forester.test;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.StringWriter;
32 import java.io.Writer;
33 import java.net.URL;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.HashSet;
37 import java.util.Iterator;
38 import java.util.List;
39 import java.util.Locale;
40 import java.util.Set;
41 import java.util.SortedSet;
42
43 import javax.net.ssl.HttpsURLConnection;
44 import javax.net.ssl.SSLContext;
45
46 import org.forester.application.support_transfer;
47 import org.forester.archaeopteryx.AptxUtil;
48 import org.forester.archaeopteryx.TreePanelUtil;
49 import org.forester.archaeopteryx.webservices.WebserviceUtil;
50 import org.forester.development.DevelopmentTools;
51 import org.forester.evoinference.TestPhylogenyReconstruction;
52 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
53 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
54 import org.forester.go.TestGo;
55 import org.forester.io.parsers.FastaParser;
56 import org.forester.io.parsers.GeneralMsaParser;
57 import org.forester.io.parsers.HmmscanPerDomainTableParser;
58 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
59 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
60 import org.forester.io.parsers.nexus.NexusCharactersParser;
61 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
62 import org.forester.io.parsers.nhx.NHXParser;
63 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
64 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
65 import org.forester.io.parsers.tol.TolParser;
66 import org.forester.io.parsers.util.ParserUtils;
67 import org.forester.io.writers.PhylogenyWriter;
68 import org.forester.io.writers.SequenceWriter;
69 import org.forester.msa.BasicMsa;
70 import org.forester.msa.DeleteableMsa;
71 import org.forester.msa.Mafft;
72 import org.forester.msa.Msa;
73 import org.forester.msa.Msa.MSA_FORMAT;
74 import org.forester.msa.MsaInferrer;
75 import org.forester.msa.MsaMethods;
76 import org.forester.pccx.TestPccx;
77 import org.forester.phylogeny.Phylogeny;
78 import org.forester.phylogeny.PhylogenyBranch;
79 import org.forester.phylogeny.PhylogenyMethods;
80 import org.forester.phylogeny.PhylogenyNode;
81 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
82 import org.forester.phylogeny.data.Accession;
83 import org.forester.phylogeny.data.Accession.Source;
84 import org.forester.phylogeny.data.BinaryCharacters;
85 import org.forester.phylogeny.data.BranchWidth;
86 import org.forester.phylogeny.data.Confidence;
87 import org.forester.phylogeny.data.Distribution;
88 import org.forester.phylogeny.data.DomainArchitecture;
89 import org.forester.phylogeny.data.Event;
90 import org.forester.phylogeny.data.Identifier;
91 import org.forester.phylogeny.data.PhylogenyData;
92 import org.forester.phylogeny.data.PhylogenyDataUtil;
93 import org.forester.phylogeny.data.Polygon;
94 import org.forester.phylogeny.data.PropertiesMap;
95 import org.forester.phylogeny.data.Property;
96 import org.forester.phylogeny.data.Property.AppliesTo;
97 import org.forester.phylogeny.data.ProteinDomain;
98 import org.forester.phylogeny.data.Taxonomy;
99 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
100 import org.forester.phylogeny.factories.PhylogenyFactory;
101 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
102 import org.forester.protein.BasicDomain;
103 import org.forester.protein.BasicProtein;
104 import org.forester.protein.Domain;
105 import org.forester.protein.Protein;
106 import org.forester.protein.ProteinId;
107 import org.forester.rio.TestRIO;
108 import org.forester.sdi.SDI;
109 import org.forester.sdi.SDIR;
110 import org.forester.sdi.TestGSDI;
111 import org.forester.sequence.BasicSequence;
112 import org.forester.sequence.MolecularSequence;
113 import org.forester.species.BasicSpecies;
114 import org.forester.species.Species;
115 import org.forester.surfacing.TestSurfacing;
116 import org.forester.tools.ConfidenceAssessor;
117 import org.forester.tools.SupportCount;
118 import org.forester.tools.TreeSplitMatrix;
119 import org.forester.util.AsciiHistogram;
120 import org.forester.util.BasicDescriptiveStatistics;
121 import org.forester.util.BasicTable;
122 import org.forester.util.BasicTableParser;
123 import org.forester.util.DescriptiveStatistics;
124 import org.forester.util.ForesterConstants;
125 import org.forester.util.ForesterUtil;
126 import org.forester.util.GeneralTable;
127 import org.forester.util.SequenceAccessionTools;
128 import org.forester.ws.seqdb.SequenceDatabaseEntry;
129 import org.forester.ws.seqdb.SequenceDbWsTools;
130 import org.forester.ws.seqdb.UniProtTaxonomy;
131
132
133 @SuppressWarnings( "unused")
134 public final class Test {
135
136     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
137             + ForesterUtil.getFileSeparator() + "resources"
138             + ForesterUtil.getFileSeparator();
139     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
140             + ForesterUtil.getFileSeparator() + "test_data"
141             + ForesterUtil.getFileSeparator();
142     private final static boolean PERFORM_DB_TESTS          = true;
143     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
144     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
145             + ForesterConstants.PHYLO_XML_VERSION + "/"
146             + ForesterConstants.PHYLO_XML_XSD;
147     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
148             + ForesterConstants.PHYLO_XML_VERSION + "/"
149             + ForesterConstants.PHYLO_XML_XSD;
150     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
151     private final static double  ZERO_DIFF                 = 1.0E-9;
152
153     private static boolean isEqual( final double a, final double b ) {
154         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
155     }
156
157     public static void main( final String[] args ) {
158         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
159         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
160                             + "]" );
161         Locale.setDefault( Locale.US );
162         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
163         int failed = 0;
164         int succeeded = 0;
165         System.out.print( "[Test if directory with files for testing exists/is readable: " );
166         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
167             System.out.println( "OK.]" );
168         }
169         else {
170             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
171             System.out.println( "Testing aborted." );
172             System.exit( -1 );
173         }
174         System.out.print( "[Test if resources directory exists/is readable: " );
175         if ( testDir( PATH_TO_RESOURCES ) ) {
176             System.out.println( "OK.]" );
177         }
178         else {
179             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
180             System.out.println( "Testing aborted." );
181             System.exit( -1 );
182         }
183         final long start_time = new Date().getTime();
184         
185         System.out.print( "Basic node methods: " );
186         if ( Test.testBasicNodeMethods() ) {
187             System.out.println( "OK." );
188             succeeded++;
189         }
190         else {
191             System.out.println( "failed." );
192             failed++;
193         }
194         System.out.print( "Protein id: " );
195         if ( !testProteinId() ) {
196             System.out.println( "failed." );
197             failed++;
198         }
199         else {
200             succeeded++;
201         }
202         System.out.println( "OK." );
203         System.out.print( "Species: " );
204         if ( !testSpecies() ) {
205             System.out.println( "failed." );
206             failed++;
207         }
208         else {
209             succeeded++;
210         }
211         System.out.println( "OK." );
212         System.out.print( "Basic domain: " );
213         if ( !testBasicDomain() ) {
214             System.out.println( "failed." );
215             failed++;
216         }
217         else {
218             succeeded++;
219         }
220         System.out.println( "OK." );
221         System.out.print( "Basic protein: " );
222         if ( !testBasicProtein() ) {
223             System.out.println( "failed." );
224             failed++;
225         }
226         else {
227             succeeded++;
228         }
229         System.out.println( "OK." );
230         System.out.print( "Sequence writer: " );
231         if ( testSequenceWriter() ) {
232             System.out.println( "OK." );
233             succeeded++;
234         }
235         else {
236             System.out.println( "failed." );
237             failed++;
238         }
239         System.out.print( "Sequence id parsing: " );
240         if ( testSequenceIdParsing() ) {
241             System.out.println( "OK." );
242             succeeded++;
243         }
244         else {
245             System.out.println( "failed." );
246             failed++;
247         }
248         System.out.print( "UniProtKB id extraction: " );
249         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
250             System.out.println( "OK." );
251             succeeded++;
252         }
253         else {
254             System.out.println( "failed." );
255             failed++;
256         }
257         System.out.print( "Sequence DB tools 1: " );
258         if ( testSequenceDbWsTools1() ) {
259             System.out.println( "OK." );
260             succeeded++;
261         }
262         else {
263             System.out.println( "failed." );
264             failed++;
265         }
266         System.out.print( "Hmmscan output parser: " );
267         if ( testHmmscanOutputParser() ) {
268             System.out.println( "OK." );
269             succeeded++;
270         }
271         else {
272             System.out.println( "failed." );
273             failed++;
274         }
275         System.out.print( "Overlap removal: " );
276         if ( !org.forester.test.Test.testOverlapRemoval() ) {
277             System.out.println( "failed." );
278             failed++;
279         }
280         else {
281             succeeded++;
282         }
283         System.out.println( "OK." );
284         System.out.print( "Engulfing overlap removal: " );
285         if ( !Test.testEngulfingOverlapRemoval() ) {
286             System.out.println( "failed." );
287             failed++;
288         }
289         else {
290             succeeded++;
291         }
292         System.out.println( "OK." );
293         System.out.print( "Taxonomy data extraction: " );
294         if ( Test.testExtractTaxonomyDataFromNodeName() ) {
295             System.out.println( "OK." );
296             succeeded++;
297         }
298         else {
299             System.out.println( "failed." );
300             failed++;
301         }
302         System.out.print( "Taxonomy code extraction: " );
303         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
304             System.out.println( "OK." );
305             succeeded++;
306         }
307         else {
308             System.out.println( "failed." );
309             failed++;
310         }
311         System.out.print( "SN extraction: " );
312         if ( Test.testExtractSNFromNodeName() ) {
313             System.out.println( "OK." );
314             succeeded++;
315         }
316         else {
317             System.out.println( "failed." );
318             failed++;
319         }
320         System.out.print( "Taxonomy extraction (general): " );
321         if ( Test.testTaxonomyExtraction() ) {
322             System.out.println( "OK." );
323             succeeded++;
324         }
325         else {
326             System.out.println( "failed." );
327             failed++;
328         }
329         System.out.print( "Uri for Aptx web sequence accession: " );
330         if ( Test.testCreateUriForSeqWeb() ) {
331             System.out.println( "OK." );
332             succeeded++;
333         }
334         else {
335             System.out.println( "failed." );
336             failed++;
337         }
338         System.out.print( "Basic node construction and parsing of NHX (node level): " );
339         if ( Test.testNHXNodeParsing() ) {
340             System.out.println( "OK." );
341             succeeded++;
342         }
343         else {
344             System.out.println( "failed." );
345             failed++;
346         }
347         System.out.print( "NHX parsing iterating: " );
348         if ( Test.testNHParsingIter() ) {
349             System.out.println( "OK." );
350             succeeded++;
351         }
352         else {
353             System.out.println( "failed." );
354             failed++;
355         }
356         System.out.print( "NH parsing: " );
357         if ( Test.testNHParsing() ) {
358             System.out.println( "OK." );
359             succeeded++;
360         }
361         else {
362             System.out.println( "failed." );
363             failed++;
364         }
365         System.out.print( "Conversion to NHX (node level): " );
366         if ( Test.testNHXconversion() ) {
367             System.out.println( "OK." );
368             succeeded++;
369         }
370         else {
371             System.out.println( "failed." );
372             failed++;
373         }
374         System.out.print( "NHX parsing: " );
375         if ( Test.testNHXParsing() ) {
376             System.out.println( "OK." );
377             succeeded++;
378         }
379         else {
380             System.out.println( "failed." );
381             failed++;
382         }
383         System.out.print( "NHX parsing with quotes: " );
384         if ( Test.testNHXParsingQuotes() ) {
385             System.out.println( "OK." );
386             succeeded++;
387         }
388         else {
389             System.out.println( "failed." );
390             failed++;
391         }
392         System.out.print( "NHX parsing (MrBayes): " );
393         if ( Test.testNHXParsingMB() ) {
394             System.out.println( "OK." );
395             succeeded++;
396         }
397         else {
398             System.out.println( "failed." );
399             failed++;
400         }
401         System.out.print( "Nexus characters parsing: " );
402         if ( Test.testNexusCharactersParsing() ) {
403             System.out.println( "OK." );
404             succeeded++;
405         }
406         else {
407             System.out.println( "failed." );
408             failed++;
409         }
410         System.out.print( "Nexus tree parsing iterating: " );
411         if ( Test.testNexusTreeParsingIterating() ) {
412             System.out.println( "OK." );
413             succeeded++;
414         }
415         else {
416             System.out.println( "failed." );
417             failed++;
418         }
419         System.out.print( "Nexus tree parsing: " );
420         if ( Test.testNexusTreeParsing() ) {
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 (translating): " );
429         if ( Test.testNexusTreeParsingTranslating() ) {
430             System.out.println( "OK." );
431             succeeded++;
432         }
433         else {
434             System.out.println( "failed." );
435             failed++;
436         }
437         System.out.print( "Nexus matrix parsing: " );
438         if ( Test.testNexusMatrixParsing() ) {
439             System.out.println( "OK." );
440             succeeded++;
441         }
442         else {
443             System.out.println( "failed." );
444             failed++;
445         }
446         System.out.print( "Basic phyloXML parsing: " );
447         if ( Test.testBasicPhyloXMLparsing() ) {
448             System.out.println( "OK." );
449             succeeded++;
450         }
451         else {
452             System.out.println( "failed." );
453             failed++;
454         }
455         System.out.print( "Basic phyloXML parsing (validating against schema): " );
456         if ( testBasicPhyloXMLparsingValidating() ) {
457             System.out.println( "OK." );
458             succeeded++;
459         }
460         else {
461             System.out.println( "failed." );
462             failed++;
463         }
464         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
465         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
466             System.out.println( "OK." );
467             succeeded++;
468         }
469         else {
470             System.out.println( "failed." );
471             failed++;
472         }
473         System.out.print( "phyloXML Distribution Element: " );
474         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
475             System.out.println( "OK." );
476             succeeded++;
477         }
478         else {
479             System.out.println( "failed." );
480             failed++;
481         }
482         System.out.print( "Tol XML parsing: " );
483         if ( Test.testBasicTolXMLparsing() ) {
484             System.out.println( "OK." );
485             succeeded++;
486         }
487         else {
488             System.out.println( "failed." );
489             failed++;
490         }
491         System.out.print( "Copying of node data: " );
492         if ( Test.testCopyOfNodeData() ) {
493             System.out.println( "OK." );
494             succeeded++;
495         }
496         else {
497             System.out.println( "failed." );
498             failed++;
499         }
500         System.out.print( "Tree copy: " );
501         if ( Test.testTreeCopy() ) {
502             System.out.println( "OK." );
503             succeeded++;
504         }
505         else {
506             System.out.println( "failed." );
507             failed++;
508         }
509         System.out.print( "Basic tree methods: " );
510         if ( Test.testBasicTreeMethods() ) {
511             System.out.println( "OK." );
512             succeeded++;
513         }
514         else {
515             System.out.println( "failed." );
516             failed++;
517         }
518         System.out.print( "Tree methods: " );
519         if ( Test.testTreeMethods() ) {
520             System.out.println( "OK." );
521             succeeded++;
522         }
523         else {
524             System.out.println( "failed." );
525             failed++;
526         }
527         System.out.print( "Postorder Iterator: " );
528         if ( Test.testPostOrderIterator() ) {
529             System.out.println( "OK." );
530             succeeded++;
531         }
532         else {
533             System.out.println( "failed." );
534             failed++;
535         }
536         System.out.print( "Preorder Iterator: " );
537         if ( Test.testPreOrderIterator() ) {
538             System.out.println( "OK." );
539             succeeded++;
540         }
541         else {
542             System.out.println( "failed." );
543             failed++;
544         }
545         System.out.print( "Levelorder Iterator: " );
546         if ( Test.testLevelOrderIterator() ) {
547             System.out.println( "OK." );
548             succeeded++;
549         }
550         else {
551             System.out.println( "failed." );
552             failed++;
553         }
554         System.out.print( "Re-id methods: " );
555         if ( Test.testReIdMethods() ) {
556             System.out.println( "OK." );
557             succeeded++;
558         }
559         else {
560             System.out.println( "failed." );
561             failed++;
562         }
563         System.out.print( "Methods on last external nodes: " );
564         if ( Test.testLastExternalNodeMethods() ) {
565             System.out.println( "OK." );
566             succeeded++;
567         }
568         else {
569             System.out.println( "failed." );
570             failed++;
571         }
572         System.out.print( "Methods on external nodes: " );
573         if ( Test.testExternalNodeRelatedMethods() ) {
574             System.out.println( "OK." );
575             succeeded++;
576         }
577         else {
578             System.out.println( "failed." );
579             failed++;
580         }
581         System.out.print( "Deletion of external nodes: " );
582         if ( Test.testDeletionOfExternalNodes() ) {
583             System.out.println( "OK." );
584             succeeded++;
585         }
586         else {
587             System.out.println( "failed." );
588             failed++;
589         }
590         System.out.print( "Subtree deletion: " );
591         if ( Test.testSubtreeDeletion() ) {
592             System.out.println( "OK." );
593             succeeded++;
594         }
595         else {
596             System.out.println( "failed." );
597             failed++;
598         }
599         System.out.print( "Phylogeny branch: " );
600         if ( Test.testPhylogenyBranch() ) {
601             System.out.println( "OK." );
602             succeeded++;
603         }
604         else {
605             System.out.println( "failed." );
606             failed++;
607         }
608         System.out.print( "Rerooting: " );
609         if ( Test.testRerooting() ) {
610             System.out.println( "OK." );
611             succeeded++;
612         }
613         else {
614             System.out.println( "failed." );
615             failed++;
616         }
617         System.out.print( "Mipoint rooting: " );
618         if ( Test.testMidpointrooting() ) {
619             System.out.println( "OK." );
620             succeeded++;
621         }
622         else {
623             System.out.println( "failed." );
624             failed++;
625         }
626         System.out.print( "Node removal: " );
627         if ( Test.testNodeRemoval() ) {
628             System.out.println( "OK." );
629             succeeded++;
630         }
631         else {
632             System.out.println( "failed." );
633             failed++;
634         }
635         System.out.print( "Support count: " );
636         if ( Test.testSupportCount() ) {
637             System.out.println( "OK." );
638             succeeded++;
639         }
640         else {
641             System.out.println( "failed." );
642             failed++;
643         }
644         System.out.print( "Support transfer: " );
645         if ( Test.testSupportTransfer() ) {
646             System.out.println( "OK." );
647             succeeded++;
648         }
649         else {
650             System.out.println( "failed." );
651             failed++;
652         }
653         System.out.print( "Finding of LCA: " );
654         if ( Test.testGetLCA() ) {
655             System.out.println( "OK." );
656             succeeded++;
657         }
658         else {
659             System.out.println( "failed." );
660             failed++;
661         }
662         System.out.print( "Finding of LCA 2: " );
663         if ( Test.testGetLCA2() ) {
664             System.out.println( "OK." );
665             succeeded++;
666         }
667         else {
668             System.out.println( "failed." );
669             failed++;
670         }
671         System.out.print( "Calculation of distance between nodes: " );
672         if ( Test.testGetDistance() ) {
673             System.out.println( "OK." );
674             succeeded++;
675         }
676         else {
677             System.out.println( "failed." );
678             failed++;
679         }
680         System.out.print( "Descriptive statistics: " );
681         if ( Test.testDescriptiveStatistics() ) {
682             System.out.println( "OK." );
683             succeeded++;
684         }
685         else {
686             System.out.println( "failed." );
687             failed++;
688         }
689         System.out.print( "Data objects and methods: " );
690         if ( Test.testDataObjects() ) {
691             System.out.println( "OK." );
692             succeeded++;
693         }
694         else {
695             System.out.println( "failed." );
696             failed++;
697         }
698         System.out.print( "Properties map: " );
699         if ( Test.testPropertiesMap() ) {
700             System.out.println( "OK." );
701             succeeded++;
702         }
703         else {
704             System.out.println( "failed." );
705             failed++;
706         }
707         System.out.print( "SDIse: " );
708         if ( Test.testSDIse() ) {
709             System.out.println( "OK." );
710             succeeded++;
711         }
712         else {
713             System.out.println( "failed." );
714             failed++;
715         }
716         System.out.print( "SDIunrooted: " );
717         if ( Test.testSDIunrooted() ) {
718             System.out.println( "OK." );
719             succeeded++;
720         }
721         else {
722             System.out.println( "failed." );
723             failed++;
724         }
725         System.out.print( "GSDI: " );
726         if ( TestGSDI.test() ) {
727             System.out.println( "OK." );
728             succeeded++;
729         }
730         else {
731             System.out.println( "failed." );
732             failed++;
733         }
734         System.out.print( "RIO: " );
735         if ( TestRIO.test() ) {
736             System.out.println( "OK." );
737             succeeded++;
738         }
739         else {
740             System.out.println( "failed." );
741             failed++;
742         }
743         System.out.print( "Phylogeny reconstruction:" );
744         System.out.println();
745         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
746             System.out.println( "OK." );
747             succeeded++;
748         }
749         else {
750             System.out.println( "failed." );
751             failed++;
752         }
753         System.out.print( "Analysis of domain architectures: " );
754         System.out.println();
755         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
756             System.out.println( "OK." );
757             succeeded++;
758         }
759         else {
760             System.out.println( "failed." );
761             failed++;
762         }
763         System.out.print( "GO: " );
764         System.out.println();
765         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
766             System.out.println( "OK." );
767             succeeded++;
768         }
769         else {
770             System.out.println( "failed." );
771             failed++;
772         }
773         System.out.print( "Modeling tools: " );
774         if ( TestPccx.test() ) {
775             System.out.println( "OK." );
776             succeeded++;
777         }
778         else {
779             System.out.println( "failed." );
780             failed++;
781         }
782         System.out.print( "Split Matrix strict: " );
783         if ( Test.testSplitStrict() ) {
784             System.out.println( "OK." );
785             succeeded++;
786         }
787         else {
788             System.out.println( "failed." );
789             failed++;
790         }
791         System.out.print( "Split Matrix: " );
792         if ( Test.testSplit() ) {
793             System.out.println( "OK." );
794             succeeded++;
795         }
796         else {
797             System.out.println( "failed." );
798             failed++;
799         }
800         System.out.print( "Confidence Assessor: " );
801         if ( Test.testConfidenceAssessor() ) {
802             System.out.println( "OK." );
803             succeeded++;
804         }
805         else {
806             System.out.println( "failed." );
807             failed++;
808         }
809         System.out.print( "Basic table: " );
810         if ( Test.testBasicTable() ) {
811             System.out.println( "OK." );
812             succeeded++;
813         }
814         else {
815             System.out.println( "failed." );
816             failed++;
817         }
818         System.out.print( "General table: " );
819         if ( Test.testGeneralTable() ) {
820             System.out.println( "OK." );
821             succeeded++;
822         }
823         else {
824             System.out.println( "failed." );
825             failed++;
826         }
827         System.out.print( "Amino acid sequence: " );
828         if ( Test.testAminoAcidSequence() ) {
829             System.out.println( "OK." );
830             succeeded++;
831         }
832         else {
833             System.out.println( "failed." );
834             failed++;
835         }
836         System.out.print( "General MSA parser: " );
837         if ( Test.testGeneralMsaParser() ) {
838             System.out.println( "OK." );
839             succeeded++;
840         }
841         else {
842             System.out.println( "failed." );
843             failed++;
844         }
845         System.out.print( "Fasta parser for msa: " );
846         if ( Test.testFastaParser() ) {
847             System.out.println( "OK." );
848             succeeded++;
849         }
850         else {
851             System.out.println( "failed." );
852             failed++;
853         }
854         System.out.print( "Creation of balanced phylogeny: " );
855         if ( Test.testCreateBalancedPhylogeny() ) {
856             System.out.println( "OK." );
857             succeeded++;
858         }
859         else {
860             System.out.println( "failed." );
861             failed++;
862         }
863         System.out.print( "Genbank accessor parsing: " );
864         if ( Test.testGenbankAccessorParsing() ) {
865             System.out.println( "OK." );
866             succeeded++;
867         }
868         else {
869             System.out.println( "failed." );
870             failed++;
871         }
872         String path = "";
873         final String os = ForesterUtil.OS_NAME.toLowerCase();
874         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
875             path = "/usr/local/bin/mafft";
876         }
877         else if ( os.indexOf( "win" ) >= 0 ) {
878             path = "C:\\Program Files\\mafft-win\\mafft.bat";
879         }
880         else {
881             path = "mafft";
882             if ( !MsaInferrer.isInstalled( path ) ) {
883                 path = "/usr/bin/mafft";
884             }
885             if ( !MsaInferrer.isInstalled( path ) ) {
886                 path = "/usr/local/bin/mafft";
887             }
888         }
889         if ( MsaInferrer.isInstalled( path ) ) {
890             System.out.print( "MAFFT (external program): " );
891             if ( Test.testMafft( path ) ) {
892                 System.out.println( "OK." );
893                 succeeded++;
894             }
895             else {
896                 System.out.println( "failed [will not count towards failed tests]" );
897             }
898         }
899         System.out.print( "Next nodes with collapsed: " );
900         if ( Test.testNextNodeWithCollapsing() ) {
901             System.out.println( "OK." );
902             succeeded++;
903         }
904         else {
905             System.out.println( "failed." );
906             failed++;
907         }
908         System.out.print( "Simple MSA quality: " );
909         if ( Test.testMsaQualityMethod() ) {
910             System.out.println( "OK." );
911             succeeded++;
912         }
913         else {
914             System.out.println( "failed." );
915             failed++;
916         }
917         System.out.print( "Deleteable MSA: " );
918         if ( Test.testDeleteableMsa() ) {
919             System.out.println( "OK." );
920             succeeded++;
921         }
922         else {
923             System.out.println( "failed." );
924             failed++;
925         }
926         System.out.print( "MSA entropy: " );
927         if ( Test.testMsaEntropy() ) {
928             System.out.println( "OK." );
929             succeeded++;
930         }
931         else {
932             System.out.println( "failed." );
933             failed++;
934         }
935         if ( PERFORM_DB_TESTS ) {
936             System.out.print( "Uniprot Entry Retrieval: " );
937             if ( Test.testUniprotEntryRetrieval() ) {
938                 System.out.println( "OK." );
939                 succeeded++;
940             }
941             else {
942                 System.out.println( "failed." );
943                 failed++;
944             }
945             System.out.print( "Ebi Entry Retrieval: " );
946             if ( Test.testEbiEntryRetrieval() ) {
947                 System.out.println( "OK." );
948                 succeeded++;
949             }
950             else {
951                 System.out.println( "failed." );
952                 failed++;
953             }
954             System.out.print( "Sequence DB tools 2: " );
955             if ( testSequenceDbWsTools2() ) {
956                 System.out.println( "OK." );
957                 succeeded++;
958             }
959             else {
960                 System.out.println( "failed." );
961                 failed++;
962                 System.exit( -1 );
963             }
964             System.out.print( "Uniprot Taxonomy Search: " );
965             if ( Test.testUniprotTaxonomySearch() ) {
966                 System.out.println( "OK." );
967                 succeeded++;
968             }
969             else {
970                 System.out.println( "failed." );
971                 failed++;
972             }
973         }
974         if ( PERFORM_WEB_TREE_ACCESS ) {
975             System.out.print( "TreeBase acccess: " );
976             if ( Test.testTreeBaseReading() ) {
977                 System.out.println( "OK." );
978                 succeeded++;
979             }
980             else {
981                 System.out.println( "failed." );
982                 failed++;
983             }
984             System.out.print( "ToL access: " );
985             if ( Test.testToLReading() ) {
986                 System.out.println( "OK." );
987                 succeeded++;
988             }
989             else {
990                 System.out.println( "failed." );
991                 failed++;
992             }
993             System.out.print( "NHX parsing from URL: " );
994             if ( Test.testNHXparsingFromURL() ) {
995                 System.out.println( "OK." );
996                 succeeded++;
997             }
998             else {
999                 System.out.println( "failed." );
1000                 failed++;
1001             }
1002             System.out.print( "NHX parsing from URL 2: " );
1003             if ( Test.testNHXparsingFromURL2() ) {
1004                 System.out.println( "OK." );
1005                 succeeded++;
1006             }
1007             else {
1008                 System.out.println( "failed." );
1009                 failed++;
1010             }
1011             System.out.print( "phyloXML parsing from URL: " );
1012             if ( Test.testPhyloXMLparsingFromURL() ) {
1013                 System.out.println( "OK." );
1014                 succeeded++;
1015             }
1016             else {
1017                 System.out.println( "failed." );
1018                 failed++;
1019             }
1020             System.out.print( "TreeFam access: " );
1021             if ( Test.testTreeFamReading() ) {
1022                 System.out.println( "OK." );
1023                 succeeded++;
1024             }
1025             else {
1026                 System.out.println( "failed." );
1027                 failed++;
1028             }
1029             System.out.print( "Pfam tree access: " );
1030             if ( Test.testPfamTreeReading() ) {
1031                 System.out.println( "OK." );
1032                 succeeded++;
1033             }
1034             else {
1035                 System.out.println( "failed." );
1036                 failed++;
1037             }
1038         }
1039         System.out.println();
1040         final Runtime rt = java.lang.Runtime.getRuntime();
1041         final long free_memory = rt.freeMemory() / 1000000;
1042         final long total_memory = rt.totalMemory() / 1000000;
1043         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1044                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1045         System.out.println();
1046         System.out.println( "Successful tests: " + succeeded );
1047         System.out.println( "Failed     tests: " + failed );
1048         System.out.println();
1049         if ( failed < 1 ) {
1050             System.out.println( "OK." );
1051         }
1052         else {
1053             System.out.println( "Not OK." );
1054         }
1055     }
1056
1057     private static boolean testEngulfingOverlapRemoval() {
1058         try {
1059             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1060             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1061             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1062             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1063             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1064             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1065             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1066             final List<Boolean> covered = new ArrayList<Boolean>();
1067             covered.add( true ); // 0
1068             covered.add( false ); // 1
1069             covered.add( true ); // 2
1070             covered.add( false ); // 3
1071             covered.add( true ); // 4
1072             covered.add( true ); // 5
1073             covered.add( false ); // 6
1074             covered.add( true ); // 7
1075             covered.add( true ); // 8
1076             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1077                 return false;
1078             }
1079             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1080                 return false;
1081             }
1082             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1083                 return false;
1084             }
1085             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1086                 return false;
1087             }
1088             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1089                 return false;
1090             }
1091             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1092                 return false;
1093             }
1094             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1095                 return false;
1096             }
1097             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1098             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1099             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1100             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1101             abc.addProteinDomain( a );
1102             abc.addProteinDomain( b );
1103             abc.addProteinDomain( c );
1104             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1105             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1106             if ( abc.getNumberOfProteinDomains() != 3 ) {
1107                 return false;
1108             }
1109             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1110                 return false;
1111             }
1112             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1113                 return false;
1114             }
1115             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1116                 return false;
1117             }
1118             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1119                 return false;
1120             }
1121             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1122             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1123             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1124             final Protein def = new BasicProtein( "def", "nemve", 0 );
1125             def.addProteinDomain( d );
1126             def.addProteinDomain( e );
1127             def.addProteinDomain( f );
1128             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1129             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1130             if ( def.getNumberOfProteinDomains() != 3 ) {
1131                 return false;
1132             }
1133             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1134                 return false;
1135             }
1136             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1137                 return false;
1138             }
1139             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1140                 return false;
1141             }
1142             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1143                 return false;
1144             }
1145             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1146                 return false;
1147             }
1148         }
1149         catch ( final Exception e ) {
1150             e.printStackTrace( System.out );
1151             return false;
1152         }
1153         return true;
1154     }
1155
1156     private static final boolean testNHXparsingFromURL2() {
1157         try {
1158             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1159             final Phylogeny phys[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1160                                                                       false,
1161                                                                       false,
1162                                                                       false,
1163                                                                       TAXONOMY_EXTRACTION.NO,
1164                                                                       false );
1165             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1166                 return false;
1167             }
1168             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1169                 System.out.println( phys[ 0 ].toNewHampshire() );
1170                 return false;
1171             }
1172             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1173                 System.out.println( phys[ 1 ].toNewHampshire() );
1174                 return false;
1175             }
1176             final Phylogeny phys2[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1177                                                                        false,
1178                                                                        false,
1179                                                                        false,
1180                                                                        TAXONOMY_EXTRACTION.NO,
1181                                                                        false );
1182             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1183                 return false;
1184             }
1185             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1186                 System.out.println( phys2[ 0 ].toNewHampshire() );
1187                 return false;
1188             }
1189             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1190                 System.out.println( phys2[ 1 ].toNewHampshire() );
1191                 return false;
1192             }
1193             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1194                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1195             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1196                 return false;
1197             }
1198             if ( !phys3[ 0 ]
1199                     .toNewHampshire()
1200                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1201                 System.out.println( phys3[ 0 ].toNewHampshire() );
1202                 return false;
1203             }
1204             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1205                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1206             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1207                 return false;
1208             }
1209             if ( !phys4[ 0 ]
1210                     .toNewHampshire()
1211                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1212                 System.out.println( phys4[ 0 ].toNewHampshire() );
1213                 return false;
1214             }
1215         }
1216         catch ( final Exception e ) {
1217             e.printStackTrace();
1218             return false;
1219         }
1220         return true;
1221     }
1222
1223     private static final boolean testNHXparsingFromURL() {
1224         try {
1225             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1226             final URL u = new URL( s );
1227             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1228             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1229             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1230                 return false;
1231             }
1232             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1233                 System.out.println( phys[ 0 ].toNewHampshire() );
1234                 return false;
1235             }
1236             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1237                 System.out.println( phys[ 1 ].toNewHampshire() );
1238                 return false;
1239             }
1240             final URL u2 = new URL( s );
1241             final Phylogeny[] phys2 = factory.create( u2.openStream(), new NHXParser() );
1242             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1243                 return false;
1244             }
1245             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1246                 System.out.println( phys2[ 0 ].toNewHampshire() );
1247                 return false;
1248             }
1249             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1250             final NHXParser p = new NHXParser();
1251             final URL u3 = new URL( s );
1252             p.setSource( u3 );
1253             if ( !p.hasNext() ) {
1254                 return false;
1255             }
1256             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1257                 return false;
1258             }
1259             if ( !p.hasNext() ) {
1260                 return false;
1261             }
1262             p.reset();
1263             if ( !p.hasNext() ) {
1264                 return false;
1265             }
1266             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1267                 return false;
1268             }
1269             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1270                 return false;
1271             }
1272             p.reset();
1273             if ( !p.hasNext() ) {
1274                 return false;
1275             }
1276             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1277                 return false;
1278             }
1279             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1280                 return false;
1281             }
1282         }
1283         catch ( final Exception e ) {
1284             System.out.println( e.toString() );
1285             e.printStackTrace();
1286             return false;
1287         }
1288         return true;
1289     }
1290
1291     private static boolean testOverlapRemoval() {
1292         try {
1293             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1294             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1295             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1296             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1297             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1298             final List<Boolean> covered = new ArrayList<Boolean>();
1299             covered.add( true ); // 0
1300             covered.add( false ); // 1
1301             covered.add( true ); // 2
1302             covered.add( false ); // 3
1303             covered.add( true ); // 4
1304             covered.add( true ); // 5
1305             covered.add( false ); // 6
1306             covered.add( true ); // 7
1307             covered.add( true ); // 8
1308             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1309                 return false;
1310             }
1311             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1312                 return false;
1313             }
1314             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1315                 return false;
1316             }
1317             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1318                 return false;
1319             }
1320             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1321                 return false;
1322             }
1323             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1324             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1325             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1326             ab.addProteinDomain( a );
1327             ab.addProteinDomain( b );
1328             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1329             if ( ab.getNumberOfProteinDomains() != 2 ) {
1330                 return false;
1331             }
1332             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1333                 return false;
1334             }
1335             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1336                 return false;
1337             }
1338             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1339             if ( ab.getNumberOfProteinDomains() != 2 ) {
1340                 return false;
1341             }
1342             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1343                 return false;
1344             }
1345             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1346             final Domain d = new BasicDomain( "d",
1347                                               ( short ) 10000,
1348                                               ( short ) 10500,
1349                                               ( short ) 1,
1350                                               ( short ) 1,
1351                                               0.0000001,
1352                                               1 );
1353             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1354             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1355             cde.addProteinDomain( c );
1356             cde.addProteinDomain( d );
1357             cde.addProteinDomain( e );
1358             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1359             if ( cde.getNumberOfProteinDomains() != 3 ) {
1360                 return false;
1361             }
1362             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1363                 return false;
1364             }
1365             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1366             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1367             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1368             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1369             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1370             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1371             fghi.addProteinDomain( f );
1372             fghi.addProteinDomain( g );
1373             fghi.addProteinDomain( h );
1374             fghi.addProteinDomain( i );
1375             fghi.addProteinDomain( i );
1376             fghi.addProteinDomain( i );
1377             fghi.addProteinDomain( i2 );
1378             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1379             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1380                 return false;
1381             }
1382             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1383                 return false;
1384             }
1385             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1386                 return false;
1387             }
1388             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1389             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1390                 return false;
1391             }
1392             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1393                 return false;
1394             }
1395             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1396             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1397             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1398             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1399             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1400             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1401             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1402             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1403             jklm.addProteinDomain( j );
1404             jklm.addProteinDomain( k );
1405             jklm.addProteinDomain( l );
1406             jklm.addProteinDomain( m );
1407             jklm.addProteinDomain( m0 );
1408             jklm.addProteinDomain( m1 );
1409             jklm.addProteinDomain( m2 );
1410             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1411             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1412                 return false;
1413             }
1414             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1415                 return false;
1416             }
1417             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1418                 return false;
1419             }
1420             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1421             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1422                 return false;
1423             }
1424             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1425                 return false;
1426             }
1427             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1428             final Protein od = new BasicProtein( "od", "varanus", 0 );
1429             od.addProteinDomain( only );
1430             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1431             if ( od.getNumberOfProteinDomains() != 1 ) {
1432                 return false;
1433             }
1434             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1435                 return false;
1436             }
1437         }
1438         catch ( final Exception e ) {
1439             e.printStackTrace( System.out );
1440             return false;
1441         }
1442         return true;
1443     }
1444
1445     private static final boolean testPfamTreeReading() {
1446         try {
1447             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1448             final NHXParser parser = new NHXParser();
1449             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1450             parser.setReplaceUnderscores( false );
1451             parser.setGuessRootedness( true );
1452             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser);
1453             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1454                 return false;
1455             }
1456             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1457                 return false;
1458             }
1459             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u, parser);
1460             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
1461                 return false;
1462             }
1463             if ( phys2[ 0 ].getNumberOfExternalNodes() != phys[ 0 ].getNumberOfExternalNodes() ) {
1464                 return false;
1465             }
1466         }
1467         catch ( final Exception e ) {
1468             e.printStackTrace();
1469             return false;
1470         }
1471         return true;
1472     }
1473
1474     private static final boolean testPhyloXMLparsingFromURL() {
1475         try {
1476             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1477             final URL u = new URL( s );
1478             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1479             
1480             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1481                 return false;
1482             }
1483             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1484             
1485             if ( ( phys2 == null ) || ( phys2.length != 2 ) ) {
1486                 return false;
1487             }
1488         }
1489         catch ( final Exception e ) {
1490             e.printStackTrace();
1491             return false;
1492         }
1493         return true;
1494     }
1495
1496     private static final boolean testToLReading() {
1497         try {
1498             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1499             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, new TolParser() );
1500             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1501                 return false;
1502             }
1503             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1504                 return false;
1505             }
1506             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1507                 return false;
1508             }
1509             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1510                 return false;
1511             }
1512             //
1513             final URL u2 = new URL( WebserviceUtil.TOL_URL_BASE + "17706" );
1514             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, new TolParser() );
1515             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
1516                 return false;
1517             }
1518             if ( !phys2[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "17706" ) ) {
1519                 return false;
1520             }
1521             if ( phys2[ 0 ].getNumberOfExternalNodes() < 5 ) {
1522                 return false;
1523             }
1524         }
1525         catch ( final Exception e ) {
1526             e.printStackTrace();
1527             return false;
1528         }
1529         return true;
1530     }
1531
1532     private static final boolean testTreeBaseReading() {
1533         try {
1534             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "72557?format=nexus" );  
1535             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1536             parser.setReplaceUnderscores( true );
1537             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1538             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1539                 return false;
1540             }
1541             final URL u_1 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2406?format=nexus" );  
1542             final NexusPhylogeniesParser parser_1 = new NexusPhylogeniesParser();
1543             final Phylogeny[] phys_1 = ForesterUtil.readPhylogeniesFromUrl( u_1, parser_1 );
1544             if ( ( phys_1 == null ) || ( phys_1.length != 1 ) ) {
1545                 return false;
1546             }
1547             final URL u_2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "422?format=nexus" );  
1548             final NexusPhylogeniesParser parser_2 = new NexusPhylogeniesParser();
1549             final Phylogeny[] phys_2 = ForesterUtil.readPhylogeniesFromUrl( u_2, parser_2 );
1550             if ( ( phys_2 == null ) || ( phys_2.length != 1 ) ) {
1551                 return false;
1552             }
1553             final URL u_3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2654?format=nexus" );  
1554             final NexusPhylogeniesParser parser_3 = new NexusPhylogeniesParser();
1555             final Phylogeny[] phys_3 = ForesterUtil.readPhylogeniesFromUrl( u_3, parser_3 );
1556              if ( ( phys_3 == null ) || ( phys_3.length != 1 ) ) {
1557                 return false;
1558             }
1559             final URL u_4 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );  
1560             final NexusPhylogeniesParser parser_4 = new NexusPhylogeniesParser();
1561             final Phylogeny[] phys_4 = ForesterUtil.readPhylogeniesFromUrl( u_4, parser_4 );
1562              if ( ( phys_4 == null ) || ( phys_4.length != 1 ) ) {
1563                 return false;
1564             }
1565             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1566             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1567             parser2.setReplaceUnderscores( true );
1568             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, parser2 );
1569             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1570                 return false;
1571             }
1572             final URL u3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14909?format=nexus" );
1573             final NexusPhylogeniesParser parser3 = new NexusPhylogeniesParser();
1574             final Phylogeny[] phys3 = ForesterUtil.readPhylogeniesFromUrl( u3, parser3 );
1575             if ( ( phys3 == null ) || ( phys3.length != 2 ) ) {
1576                 return false;
1577             }
1578             final Phylogeny[] phys4 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14525?format=nexus" ),
1579                     new NexusPhylogeniesParser() );
1580             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1581                 return false;
1582             }
1583             final Phylogeny[] phys5 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15632?format=nexus" ) ,
1584                     new NexusPhylogeniesParser() );
1585             if ( ( phys5 == null ) || ( phys5.length != 1 ) ) {
1586                 return false;
1587             }
1588             final Phylogeny[] phys6 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "10190?format=nexus" ) ,
1589                     new NexusPhylogeniesParser() );
1590             if ( ( phys6 == null ) || ( phys6.length != 1 ) ) {
1591                 return false;
1592             }
1593             final Phylogeny[] phys7 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "13246?format=nexus" ) ,
1594                     new NexusPhylogeniesParser() );
1595             if ( ( phys7 == null ) || ( phys7.length != 2 ) ) {
1596                 return false;
1597             }
1598             final Phylogeny[] phys8 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "11662?format=nexus" ) ,
1599                     new NexusPhylogeniesParser() );
1600             if ( ( phys8 == null ) || ( phys8.length != 2 ) ) {
1601                 return false;
1602             }
1603             final Phylogeny[] phys9 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "562?format=nexus" ) ,
1604                     new NexusPhylogeniesParser() );
1605             if ( ( phys9 == null ) || ( phys9.length != 4 ) ) {
1606                 return false;
1607             }
1608             final Phylogeny[] phys16424 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "16424?format=nexus" ) ,
1609                     new NexusPhylogeniesParser() );
1610             if ( ( phys16424 == null ) || ( phys16424.length != 1 ) ) {
1611                 return false;
1612             }
1613             final Phylogeny[] phys17878 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "17878?format=nexus" ) ,
1614                     new NexusPhylogeniesParser() );
1615             if ( ( phys17878 == null ) || ( phys17878.length != 17 ) ) {
1616                 return false;
1617             }
1618             final Phylogeny[] phys18804 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "18804?format=nexus" ) ,
1619                     new NexusPhylogeniesParser() );
1620             if ( ( phys18804 == null ) || ( phys18804.length != 2 ) ) {
1621                 return false;
1622             }
1623             final Phylogeny[] phys346 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "346?format=nexus" ) ,
1624                     new NexusPhylogeniesParser() );
1625             if ( ( phys346 == null ) || ( phys346.length != 1 ) ) {
1626                 return false;
1627             }
1628         }
1629         catch ( final Exception e ) {
1630             e.printStackTrace();
1631             return false;
1632         }
1633         return true;
1634     }
1635
1636     private static final boolean testTreeFamReading() {
1637         try {
1638             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1639             final NHXParser parser = new NHXParser();
1640             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1641             parser.setReplaceUnderscores( false );
1642             parser.setGuessRootedness( true );
1643             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1644             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1645                 return false;
1646             }
1647             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1648                 return false;
1649             }
1650         }
1651         catch ( final Exception e ) {
1652             e.printStackTrace();
1653             return false;
1654         }
1655         return true;
1656     }
1657
1658     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1659         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1660         return p;
1661     }
1662
1663     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1664         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1665     }
1666
1667     private static boolean testAminoAcidSequence() {
1668         try {
1669             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1670             if ( aa1.getLength() != 13 ) {
1671                 return false;
1672             }
1673             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1674                 return false;
1675             }
1676             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1677                 return false;
1678             }
1679             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1680                 return false;
1681             }
1682             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1683             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1684                 return false;
1685             }
1686             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1687             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1688                 return false;
1689             }
1690             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1691             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1692                 return false;
1693             }
1694         }
1695         catch ( final Exception e ) {
1696             e.printStackTrace();
1697             return false;
1698         }
1699         return true;
1700     }
1701
1702     private static boolean testBasicDomain() {
1703         try {
1704             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1705             if ( !pd.getDomainId().equals( "id" ) ) {
1706                 return false;
1707             }
1708             if ( pd.getNumber() != 1 ) {
1709                 return false;
1710             }
1711             if ( pd.getTotalCount() != 4 ) {
1712                 return false;
1713             }
1714             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1715                 return false;
1716             }
1717             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1718             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1719             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1720             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1721             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1722             if ( !a1.equals( a1 ) ) {
1723                 return false;
1724             }
1725             if ( !a1.equals( a1_copy ) ) {
1726                 return false;
1727             }
1728             if ( !a1.equals( a1_equal ) ) {
1729                 return false;
1730             }
1731             if ( !a1.equals( a2 ) ) {
1732                 return false;
1733             }
1734             if ( a1.equals( a3 ) ) {
1735                 return false;
1736             }
1737             if ( a1.compareTo( a1 ) != 0 ) {
1738                 return false;
1739             }
1740             if ( a1.compareTo( a1_copy ) != 0 ) {
1741                 return false;
1742             }
1743             if ( a1.compareTo( a1_equal ) != 0 ) {
1744                 return false;
1745             }
1746             if ( a1.compareTo( a2 ) != 0 ) {
1747                 return false;
1748             }
1749             if ( a1.compareTo( a3 ) == 0 ) {
1750                 return false;
1751             }
1752         }
1753         catch ( final Exception e ) {
1754             e.printStackTrace( System.out );
1755             return false;
1756         }
1757         return true;
1758     }
1759
1760     private static boolean testBasicNodeMethods() {
1761         try {
1762             if ( PhylogenyNode.getNodeCount() != 0 ) {
1763                 return false;
1764             }
1765             final PhylogenyNode n1 = new PhylogenyNode();
1766             final PhylogenyNode n2 = PhylogenyNode
1767                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1768             final PhylogenyNode n3 = PhylogenyNode
1769                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1770             final PhylogenyNode n4 = PhylogenyNode
1771                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1772             if ( n1.isHasAssignedEvent() ) {
1773                 return false;
1774             }
1775             if ( PhylogenyNode.getNodeCount() != 4 ) {
1776                 return false;
1777             }
1778             if ( n3.getIndicator() != 0 ) {
1779                 return false;
1780             }
1781             if ( n3.getNumberOfExternalNodes() != 1 ) {
1782                 return false;
1783             }
1784             if ( !n3.isExternal() ) {
1785                 return false;
1786             }
1787             if ( !n3.isRoot() ) {
1788                 return false;
1789             }
1790             if ( !n4.getName().equals( "n4" ) ) {
1791                 return false;
1792             }
1793         }
1794         catch ( final Exception e ) {
1795             e.printStackTrace( System.out );
1796             return false;
1797         }
1798         return true;
1799     }
1800
1801     private static boolean testBasicPhyloXMLparsing() {
1802         try {
1803             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1804             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1805             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1806                                                               xml_parser );
1807             if ( xml_parser.getErrorCount() > 0 ) {
1808                 System.out.println( xml_parser.getErrorMessages().toString() );
1809                 return false;
1810             }
1811             if ( phylogenies_0.length != 4 ) {
1812                 return false;
1813             }
1814             final Phylogeny t1 = phylogenies_0[ 0 ];
1815             final Phylogeny t2 = phylogenies_0[ 1 ];
1816             final Phylogeny t3 = phylogenies_0[ 2 ];
1817             final Phylogeny t4 = phylogenies_0[ 3 ];
1818             if ( t1.getNumberOfExternalNodes() != 1 ) {
1819                 return false;
1820             }
1821             if ( !t1.isRooted() ) {
1822                 return false;
1823             }
1824             if ( t1.isRerootable() ) {
1825                 return false;
1826             }
1827             if ( !t1.getType().equals( "gene_tree" ) ) {
1828                 return false;
1829             }
1830             if ( t2.getNumberOfExternalNodes() != 2 ) {
1831                 return false;
1832             }
1833             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1834                 return false;
1835             }
1836             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1837                 return false;
1838             }
1839             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1840                 return false;
1841             }
1842             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1843                 return false;
1844             }
1845             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1846                 return false;
1847             }
1848             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1849                 return false;
1850             }
1851             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1852                     .startsWith( "actgtgggggt" ) ) {
1853                 return false;
1854             }
1855             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1856                     .startsWith( "ctgtgatgcat" ) ) {
1857                 return false;
1858             }
1859             if ( t3.getNumberOfExternalNodes() != 4 ) {
1860                 return false;
1861             }
1862             if ( !t1.getName().equals( "t1" ) ) {
1863                 return false;
1864             }
1865             if ( !t2.getName().equals( "t2" ) ) {
1866                 return false;
1867             }
1868             if ( !t3.getName().equals( "t3" ) ) {
1869                 return false;
1870             }
1871             if ( !t4.getName().equals( "t4" ) ) {
1872                 return false;
1873             }
1874             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1875                 return false;
1876             }
1877             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1878                 return false;
1879             }
1880             if ( !t3.getNode( "root node" ).isDuplication() ) {
1881                 return false;
1882             }
1883             if ( !t3.getNode( "node a" ).isDuplication() ) {
1884                 return false;
1885             }
1886             if ( t3.getNode( "node a" ).isSpeciation() ) {
1887                 return false;
1888             }
1889             if ( t3.getNode( "node bc" ).isDuplication() ) {
1890                 return false;
1891             }
1892             if ( !t3.getNode( "node bc" ).isSpeciation() ) {
1893                 return false;
1894             }
1895             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1896                 return false;
1897             }
1898             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1899                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1900                 return false;
1901             }
1902             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1903                 return false;
1904             }
1905             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1906                 return false;
1907             }
1908             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1909                 return false;
1910             }
1911             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1912                     .equals( "apoptosis" ) ) {
1913                 return false;
1914             }
1915             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1916                     .equals( "GO:0006915" ) ) {
1917                 return false;
1918             }
1919             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1920                     .equals( "UniProtKB" ) ) {
1921                 return false;
1922             }
1923             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1924                     .equals( "experimental" ) ) {
1925                 return false;
1926             }
1927             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1928                     .equals( "function" ) ) {
1929                 return false;
1930             }
1931             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1932                     .getValue() != 1 ) {
1933                 return false;
1934             }
1935             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1936                     .getType().equals( "ml" ) ) {
1937                 return false;
1938             }
1939             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1940                     .equals( "apoptosis" ) ) {
1941                 return false;
1942             }
1943             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1944                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1945                 return false;
1946             }
1947             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1948                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1949                 return false;
1950             }
1951             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1952                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1953                 return false;
1954             }
1955             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1956                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1957                 return false;
1958             }
1959             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1960                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1961                 return false;
1962             }
1963             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1964                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1965                 return false;
1966             }
1967             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1968                     .equals( "GO:0005829" ) ) {
1969                 return false;
1970             }
1971             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1972                     .equals( "intracellular organelle" ) ) {
1973                 return false;
1974             }
1975             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1976                 return false;
1977             }
1978             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1979                     .equals( "UniProt link" ) ) ) {
1980                 return false;
1981             }
1982             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1983                 return false;
1984             }
1985             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1986             if ( x.size() != 4 ) {
1987                 return false;
1988             }
1989             int c = 0;
1990             for( final Accession acc : x ) {
1991                 if ( c == 0 ) {
1992                     if ( !acc.getSource().equals( "KEGG" ) ) {
1993                         return false;
1994                     }
1995                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1996                         return false;
1997                     }
1998                 }
1999                 c++;
2000             }
2001         }
2002         catch ( final Exception e ) {
2003             e.printStackTrace( System.out );
2004             return false;
2005         }
2006         return true;
2007     }
2008
2009     private static boolean testBasicPhyloXMLparsingRoundtrip() {
2010         try {
2011             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2012             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2013             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2014                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2015             }
2016             else {
2017                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2018             }
2019             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2020                                                               xml_parser );
2021             if ( xml_parser.getErrorCount() > 0 ) {
2022                 System.out.println( xml_parser.getErrorMessages().toString() );
2023                 return false;
2024             }
2025             if ( phylogenies_0.length != 4 ) {
2026                 return false;
2027             }
2028             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
2029             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
2030             if ( phylogenies_t1.length != 1 ) {
2031                 return false;
2032             }
2033             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
2034             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
2035                 return false;
2036             }
2037             if ( !t1_rt.isRooted() ) {
2038                 return false;
2039             }
2040             if ( t1_rt.isRerootable() ) {
2041                 return false;
2042             }
2043             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
2044                 return false;
2045             }
2046             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
2047             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
2048             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
2049             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2050                 return false;
2051             }
2052             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2053                 return false;
2054             }
2055             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2056                 return false;
2057             }
2058             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2059                 return false;
2060             }
2061             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2062                     .startsWith( "actgtgggggt" ) ) {
2063                 return false;
2064             }
2065             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2066                     .startsWith( "ctgtgatgcat" ) ) {
2067                 return false;
2068             }
2069             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
2070             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
2071             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
2072             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
2073             if ( phylogenies_1.length != 1 ) {
2074                 return false;
2075             }
2076             final Phylogeny t3_rt = phylogenies_1[ 0 ];
2077             if ( !t3_rt.getName().equals( "t3" ) ) {
2078                 return false;
2079             }
2080             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
2081                 return false;
2082             }
2083             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
2084                 return false;
2085             }
2086             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
2087                 return false;
2088             }
2089             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2090                 return false;
2091             }
2092             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
2093                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2094                 return false;
2095             }
2096             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2097                 return false;
2098             }
2099             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2100                 return false;
2101             }
2102             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2103                     .equals( "UniProtKB" ) ) {
2104                 return false;
2105             }
2106             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2107                     .equals( "apoptosis" ) ) {
2108                 return false;
2109             }
2110             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2111                     .equals( "GO:0006915" ) ) {
2112                 return false;
2113             }
2114             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2115                     .equals( "UniProtKB" ) ) {
2116                 return false;
2117             }
2118             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2119                     .equals( "experimental" ) ) {
2120                 return false;
2121             }
2122             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2123                     .equals( "function" ) ) {
2124                 return false;
2125             }
2126             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2127                     .getValue() != 1 ) {
2128                 return false;
2129             }
2130             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2131                     .getType().equals( "ml" ) ) {
2132                 return false;
2133             }
2134             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2135                     .equals( "apoptosis" ) ) {
2136                 return false;
2137             }
2138             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2139                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2140                 return false;
2141             }
2142             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2143                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2144                 return false;
2145             }
2146             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2147                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2148                 return false;
2149             }
2150             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2151                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2152                 return false;
2153             }
2154             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2155                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2156                 return false;
2157             }
2158             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2159                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2160                 return false;
2161             }
2162             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2163                     .equals( "GO:0005829" ) ) {
2164                 return false;
2165             }
2166             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2167                     .equals( "intracellular organelle" ) ) {
2168                 return false;
2169             }
2170             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2171                 return false;
2172             }
2173             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2174                     .equals( "UniProt link" ) ) ) {
2175                 return false;
2176             }
2177             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2178                 return false;
2179             }
2180             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
2181                 return false;
2182             }
2183             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2184                     .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." ) ) ) {
2185                 return false;
2186             }
2187             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2188                 return false;
2189             }
2190             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2191                 return false;
2192             }
2193             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
2194                 return false;
2195             }
2196             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2197                 return false;
2198             }
2199             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2200                     .equals( "ncbi" ) ) {
2201                 return false;
2202             }
2203             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2204                 return false;
2205             }
2206             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2207                     .getName().equals( "B" ) ) {
2208                 return false;
2209             }
2210             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2211                     .getFrom() != 21 ) {
2212                 return false;
2213             }
2214             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2215                 return false;
2216             }
2217             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2218                     .getLength() != 24 ) {
2219                 return false;
2220             }
2221             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2222                     .getConfidence() != 0 ) {
2223                 return false;
2224             }
2225             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2226                     .equals( "pfam" ) ) {
2227                 return false;
2228             }
2229             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2230                 return false;
2231             }
2232             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2233                 return false;
2234             }
2235             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2236                 return false;
2237             }
2238             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2239                 return false;
2240             }
2241             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2242             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2243                 return false;
2244             }
2245             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2246                 return false;
2247             }
2248             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2249                 return false;
2250             }
2251             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2252                 return false;
2253             }
2254             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2255                 return false;
2256             }
2257             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2258                 return false;
2259             }
2260             if ( taxbb.getSynonyms().size() != 2 ) {
2261                 return false;
2262             }
2263             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2264                 return false;
2265             }
2266             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2267                 return false;
2268             }
2269             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2270                 return false;
2271             }
2272             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2273                 return false;
2274             }
2275             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2276                 return false;
2277             }
2278             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2279                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2280                 return false;
2281             }
2282             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2283                 return false;
2284             }
2285             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2286                 return false;
2287             }
2288             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2289                 return false;
2290             }
2291             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2292                 return false;
2293             }
2294             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2295                 return false;
2296             }
2297             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2298                 return false;
2299             }
2300             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2301                 return false;
2302             }
2303             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2304                 return false;
2305             }
2306             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2307                     .equalsIgnoreCase( "435" ) ) {
2308                 return false;
2309             }
2310             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2311                 return false;
2312             }
2313             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2314                     .equalsIgnoreCase( "443.7" ) ) {
2315                 return false;
2316             }
2317             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2318                 return false;
2319             }
2320             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2321                 return false;
2322             }
2323             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2324                     .equalsIgnoreCase( "433" ) ) {
2325                 return false;
2326             }
2327             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2328                     .getCrossReferences();
2329             if ( x.size() != 4 ) {
2330                 return false;
2331             }
2332             int c = 0;
2333             for( final Accession acc : x ) {
2334                 if ( c == 0 ) {
2335                     if ( !acc.getSource().equals( "KEGG" ) ) {
2336                         return false;
2337                     }
2338                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2339                         return false;
2340                     }
2341                 }
2342                 c++;
2343             }
2344         }
2345         catch ( final Exception e ) {
2346             e.printStackTrace( System.out );
2347             return false;
2348         }
2349         return true;
2350     }
2351
2352     private static boolean testBasicPhyloXMLparsingValidating() {
2353         try {
2354             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2355             PhyloXmlParser xml_parser = null;
2356             try {
2357                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2358             }
2359             catch ( final Exception e ) {
2360                 // Do nothing -- means were not running from jar.
2361             }
2362             if ( xml_parser == null ) {
2363                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2364                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2365                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2366                 }
2367                 else {
2368                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2369                 }
2370             }
2371             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2372                                                               xml_parser );
2373             if ( xml_parser.getErrorCount() > 0 ) {
2374                 System.out.println( xml_parser.getErrorMessages().toString() );
2375                 return false;
2376             }
2377             if ( phylogenies_0.length != 4 ) {
2378                 return false;
2379             }
2380             final Phylogeny t1 = phylogenies_0[ 0 ];
2381             final Phylogeny t2 = phylogenies_0[ 1 ];
2382             final Phylogeny t3 = phylogenies_0[ 2 ];
2383             final Phylogeny t4 = phylogenies_0[ 3 ];
2384             if ( !t1.getName().equals( "t1" ) ) {
2385                 return false;
2386             }
2387             if ( !t2.getName().equals( "t2" ) ) {
2388                 return false;
2389             }
2390             if ( !t3.getName().equals( "t3" ) ) {
2391                 return false;
2392             }
2393             if ( !t4.getName().equals( "t4" ) ) {
2394                 return false;
2395             }
2396             if ( t1.getNumberOfExternalNodes() != 1 ) {
2397                 return false;
2398             }
2399             if ( t2.getNumberOfExternalNodes() != 2 ) {
2400                 return false;
2401             }
2402             if ( t3.getNumberOfExternalNodes() != 4 ) {
2403                 return false;
2404             }
2405             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2406             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2407             if ( xml_parser.getErrorCount() > 0 ) {
2408                 System.out.println( "errors:" );
2409                 System.out.println( xml_parser.getErrorMessages().toString() );
2410                 return false;
2411             }
2412             if ( phylogenies_1.length != 4 ) {
2413                 return false;
2414             }
2415             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2416                                                               xml_parser );
2417             if ( xml_parser.getErrorCount() > 0 ) {
2418                 System.out.println( "errors:" );
2419                 System.out.println( xml_parser.getErrorMessages().toString() );
2420                 return false;
2421             }
2422             if ( phylogenies_2.length != 1 ) {
2423                 return false;
2424             }
2425             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2426                 return false;
2427             }
2428             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2429                                                               xml_parser );
2430             if ( xml_parser.getErrorCount() > 0 ) {
2431                 System.out.println( xml_parser.getErrorMessages().toString() );
2432                 return false;
2433             }
2434             if ( phylogenies_3.length != 2 ) {
2435                 return false;
2436             }
2437             final Phylogeny a = phylogenies_3[ 0 ];
2438             if ( !a.getName().equals( "tree 4" ) ) {
2439                 return false;
2440             }
2441             if ( a.getNumberOfExternalNodes() != 3 ) {
2442                 return false;
2443             }
2444             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2445                 return false;
2446             }
2447             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2448                 return false;
2449             }
2450             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2451                                                               xml_parser );
2452             if ( xml_parser.getErrorCount() > 0 ) {
2453                 System.out.println( xml_parser.getErrorMessages().toString() );
2454                 return false;
2455             }
2456             if ( phylogenies_4.length != 1 ) {
2457                 return false;
2458             }
2459             final Phylogeny s = phylogenies_4[ 0 ];
2460             if ( s.getNumberOfExternalNodes() != 6 ) {
2461                 return false;
2462             }
2463             s.getNode( "first" );
2464             s.getNode( "<>" );
2465             s.getNode( "\"<a'b&c'd\">\"" );
2466             s.getNode( "'''\"" );
2467             s.getNode( "\"\"\"" );
2468             s.getNode( "dick & doof" );
2469         }
2470         catch ( final Exception e ) {
2471             e.printStackTrace( System.out );
2472             return false;
2473         }
2474         return true;
2475     }
2476
2477     private static boolean testBasicProtein() {
2478         try {
2479             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2480             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2481             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2482             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2483             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2484             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2485             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2486             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2487             p0.addProteinDomain( y );
2488             p0.addProteinDomain( e );
2489             p0.addProteinDomain( b );
2490             p0.addProteinDomain( c );
2491             p0.addProteinDomain( d );
2492             p0.addProteinDomain( a );
2493             p0.addProteinDomain( x );
2494             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2495                 return false;
2496             }
2497             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2498                 return false;
2499             }
2500             //
2501             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2502             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2503             aa0.addProteinDomain( a1 );
2504             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2505                 return false;
2506             }
2507             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2508                 return false;
2509             }
2510             //
2511             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2512             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2513             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2514             aa1.addProteinDomain( a11 );
2515             aa1.addProteinDomain( a12 );
2516             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2517                 return false;
2518             }
2519             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2520                 return false;
2521             }
2522             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2523             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2524                 return false;
2525             }
2526             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2527                 return false;
2528             }
2529             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2530                 return false;
2531             }
2532             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2533             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2534                 return false;
2535             }
2536             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2537                 return false;
2538             }
2539             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2540                 return false;
2541             }
2542             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2543                 return false;
2544             }
2545             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2546             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2547                 return false;
2548             }
2549             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2550                 return false;
2551             }
2552             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2553                 return false;
2554             }
2555             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2556                 return false;
2557             }
2558             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2559             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2560                 return false;
2561             }
2562             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2563                 return false;
2564             }
2565             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2566                 return false;
2567             }
2568             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2569                 return false;
2570             }
2571             //
2572             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2573             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2574             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2575             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2576             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2577             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2578             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2579             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2580             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2581             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2582             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2583             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2584             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2585             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2586             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2587             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2588             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2589             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2590             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2591             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2592             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2593             p00.addProteinDomain( y0 );
2594             p00.addProteinDomain( e0 );
2595             p00.addProteinDomain( b0 );
2596             p00.addProteinDomain( c0 );
2597             p00.addProteinDomain( d0 );
2598             p00.addProteinDomain( a0 );
2599             p00.addProteinDomain( x0 );
2600             p00.addProteinDomain( y1 );
2601             p00.addProteinDomain( y2 );
2602             p00.addProteinDomain( y3 );
2603             p00.addProteinDomain( e1 );
2604             p00.addProteinDomain( e2 );
2605             p00.addProteinDomain( e3 );
2606             p00.addProteinDomain( e4 );
2607             p00.addProteinDomain( e5 );
2608             p00.addProteinDomain( z0 );
2609             p00.addProteinDomain( z1 );
2610             p00.addProteinDomain( z2 );
2611             p00.addProteinDomain( zz0 );
2612             p00.addProteinDomain( zz1 );
2613             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2614                 return false;
2615             }
2616             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2617                 return false;
2618             }
2619             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2620                 return false;
2621             }
2622             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2623                 return false;
2624             }
2625             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" ) ) {
2626                 return false;
2627             }
2628             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2629             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2630             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2631             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2632             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2633             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2634             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2635             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2636             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2637             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2638             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2639             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2640             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2641             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2642             p.addProteinDomain( B15 );
2643             p.addProteinDomain( C50 );
2644             p.addProteinDomain( A60 );
2645             p.addProteinDomain( A30 );
2646             p.addProteinDomain( C70 );
2647             p.addProteinDomain( B35 );
2648             p.addProteinDomain( B40 );
2649             p.addProteinDomain( A0 );
2650             p.addProteinDomain( A10 );
2651             p.addProteinDomain( A20 );
2652             p.addProteinDomain( B25 );
2653             p.addProteinDomain( D80 );
2654             List<String> domains_ids = new ArrayList<String>();
2655             domains_ids.add( "A" );
2656             domains_ids.add( "B" );
2657             domains_ids.add( "C" );
2658             if ( !p.contains( domains_ids, false ) ) {
2659                 return false;
2660             }
2661             if ( !p.contains( domains_ids, true ) ) {
2662                 return false;
2663             }
2664             domains_ids.add( "X" );
2665             if ( p.contains( domains_ids, false ) ) {
2666                 return false;
2667             }
2668             if ( p.contains( domains_ids, true ) ) {
2669                 return false;
2670             }
2671             domains_ids = new ArrayList<String>();
2672             domains_ids.add( "A" );
2673             domains_ids.add( "C" );
2674             domains_ids.add( "D" );
2675             if ( !p.contains( domains_ids, false ) ) {
2676                 return false;
2677             }
2678             if ( !p.contains( domains_ids, true ) ) {
2679                 return false;
2680             }
2681             domains_ids = new ArrayList<String>();
2682             domains_ids.add( "A" );
2683             domains_ids.add( "D" );
2684             domains_ids.add( "C" );
2685             if ( !p.contains( domains_ids, false ) ) {
2686                 return false;
2687             }
2688             if ( p.contains( domains_ids, true ) ) {
2689                 return false;
2690             }
2691             domains_ids = new ArrayList<String>();
2692             domains_ids.add( "A" );
2693             domains_ids.add( "A" );
2694             domains_ids.add( "B" );
2695             if ( !p.contains( domains_ids, false ) ) {
2696                 return false;
2697             }
2698             if ( !p.contains( domains_ids, true ) ) {
2699                 return false;
2700             }
2701             domains_ids = new ArrayList<String>();
2702             domains_ids.add( "A" );
2703             domains_ids.add( "A" );
2704             domains_ids.add( "A" );
2705             domains_ids.add( "B" );
2706             domains_ids.add( "B" );
2707             if ( !p.contains( domains_ids, false ) ) {
2708                 return false;
2709             }
2710             if ( !p.contains( domains_ids, true ) ) {
2711                 return false;
2712             }
2713             domains_ids = new ArrayList<String>();
2714             domains_ids.add( "A" );
2715             domains_ids.add( "A" );
2716             domains_ids.add( "B" );
2717             domains_ids.add( "A" );
2718             domains_ids.add( "B" );
2719             domains_ids.add( "B" );
2720             domains_ids.add( "A" );
2721             domains_ids.add( "B" );
2722             domains_ids.add( "C" );
2723             domains_ids.add( "A" );
2724             domains_ids.add( "C" );
2725             domains_ids.add( "D" );
2726             if ( !p.contains( domains_ids, false ) ) {
2727                 return false;
2728             }
2729             if ( p.contains( domains_ids, true ) ) {
2730                 return false;
2731             }
2732         }
2733         catch ( final Exception e ) {
2734             e.printStackTrace( System.out );
2735             return false;
2736         }
2737         return true;
2738     }
2739
2740     private static boolean testBasicTable() {
2741         try {
2742             final BasicTable<String> t0 = new BasicTable<String>();
2743             if ( t0.getNumberOfColumns() != 0 ) {
2744                 return false;
2745             }
2746             if ( t0.getNumberOfRows() != 0 ) {
2747                 return false;
2748             }
2749             t0.setValue( 3, 2, "23" );
2750             t0.setValue( 10, 1, "error" );
2751             t0.setValue( 10, 1, "110" );
2752             t0.setValue( 9, 1, "19" );
2753             t0.setValue( 1, 10, "101" );
2754             t0.setValue( 10, 10, "1010" );
2755             t0.setValue( 100, 10, "10100" );
2756             t0.setValue( 0, 0, "00" );
2757             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2758                 return false;
2759             }
2760             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2761                 return false;
2762             }
2763             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2764                 return false;
2765             }
2766             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2767                 return false;
2768             }
2769             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2770                 return false;
2771             }
2772             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2773                 return false;
2774             }
2775             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2776                 return false;
2777             }
2778             if ( t0.getNumberOfColumns() != 101 ) {
2779                 return false;
2780             }
2781             if ( t0.getNumberOfRows() != 11 ) {
2782                 return false;
2783             }
2784             if ( t0.getValueAsString( 49, 4 ) != null ) {
2785                 return false;
2786             }
2787             final String l = ForesterUtil.getLineSeparator();
2788             final StringBuffer source = new StringBuffer();
2789             source.append( "" + l );
2790             source.append( "# 1 1 1 1 1 1 1 1" + l );
2791             source.append( " 00 01 02 03" + l );
2792             source.append( "   10 11 12 13  " + l );
2793             source.append( "20 21 22 23 " + l );
2794             source.append( "    30  31    32 33" + l );
2795             source.append( "40 41 42 43" + l );
2796             source.append( "  # 1 1 1 1 1 " + l );
2797             source.append( "50 51 52 53 54" + l );
2798             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2799             if ( t1.getNumberOfColumns() != 5 ) {
2800                 return false;
2801             }
2802             if ( t1.getNumberOfRows() != 6 ) {
2803                 return false;
2804             }
2805             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2806                 return false;
2807             }
2808             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2809                 return false;
2810             }
2811             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2812                 return false;
2813             }
2814             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2815                 return false;
2816             }
2817             final StringBuffer source1 = new StringBuffer();
2818             source1.append( "" + l );
2819             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2820             source1.append( " 00; 01 ;02;03" + l );
2821             source1.append( "   10; 11; 12; 13  " + l );
2822             source1.append( "20; 21; 22; 23 " + l );
2823             source1.append( "    30;  31;    32; 33" + l );
2824             source1.append( "40;41;42;43" + l );
2825             source1.append( "  # 1 1 1 1 1 " + l );
2826             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2827             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2828             if ( t2.getNumberOfColumns() != 5 ) {
2829                 return false;
2830             }
2831             if ( t2.getNumberOfRows() != 6 ) {
2832                 return false;
2833             }
2834             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2835                 return false;
2836             }
2837             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2838                 return false;
2839             }
2840             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2841                 return false;
2842             }
2843             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2844                 return false;
2845             }
2846             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2847                 return false;
2848             }
2849             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2850                 return false;
2851             }
2852             final StringBuffer source2 = new StringBuffer();
2853             source2.append( "" + l );
2854             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2855             source2.append( " 00; 01 ;02;03" + l );
2856             source2.append( "   10; 11; 12; 13  " + l );
2857             source2.append( "20; 21; 22; 23 " + l );
2858             source2.append( "                     " + l );
2859             source2.append( "    30;  31;    32; 33" + l );
2860             source2.append( "40;41;42;43" + l );
2861             source2.append( "  comment: 1 1 1 1 1 " + l );
2862             source2.append( ";;;50  ;   52; 53;;54   " + l );
2863             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2864                                                                         ';',
2865                                                                         false,
2866                                                                         false,
2867                                                                         "comment:",
2868                                                                         false );
2869             if ( tl.size() != 2 ) {
2870                 return false;
2871             }
2872             final BasicTable<String> t3 = tl.get( 0 );
2873             final BasicTable<String> t4 = tl.get( 1 );
2874             if ( t3.getNumberOfColumns() != 4 ) {
2875                 return false;
2876             }
2877             if ( t3.getNumberOfRows() != 3 ) {
2878                 return false;
2879             }
2880             if ( t4.getNumberOfColumns() != 4 ) {
2881                 return false;
2882             }
2883             if ( t4.getNumberOfRows() != 3 ) {
2884                 return false;
2885             }
2886             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2887                 return false;
2888             }
2889             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2890                 return false;
2891             }
2892         }
2893         catch ( final Exception e ) {
2894             e.printStackTrace( System.out );
2895             return false;
2896         }
2897         return true;
2898     }
2899
2900     private static boolean testBasicTolXMLparsing() {
2901         try {
2902             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2903             final TolParser parser = new TolParser();
2904             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2905             if ( parser.getErrorCount() > 0 ) {
2906                 System.out.println( parser.getErrorMessages().toString() );
2907                 return false;
2908             }
2909             if ( phylogenies_0.length != 1 ) {
2910                 return false;
2911             }
2912             final Phylogeny t1 = phylogenies_0[ 0 ];
2913             if ( t1.getNumberOfExternalNodes() != 5 ) {
2914                 return false;
2915             }
2916             if ( !t1.isRooted() ) {
2917                 return false;
2918             }
2919             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2920                 return false;
2921             }
2922             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2923                 return false;
2924             }
2925             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2926                 return false;
2927             }
2928             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2929                 return false;
2930             }
2931             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2932             if ( parser.getErrorCount() > 0 ) {
2933                 System.out.println( parser.getErrorMessages().toString() );
2934                 return false;
2935             }
2936             if ( phylogenies_1.length != 1 ) {
2937                 return false;
2938             }
2939             final Phylogeny t2 = phylogenies_1[ 0 ];
2940             if ( t2.getNumberOfExternalNodes() != 664 ) {
2941                 return false;
2942             }
2943             if ( !t2.isRooted() ) {
2944                 return false;
2945             }
2946             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2947                 return false;
2948             }
2949             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2950                 return false;
2951             }
2952             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2953                 return false;
2954             }
2955             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2956                 return false;
2957             }
2958             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2959                 return false;
2960             }
2961             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2962                     .equals( "Aquifex" ) ) {
2963                 return false;
2964             }
2965             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2966             if ( parser.getErrorCount() > 0 ) {
2967                 System.out.println( parser.getErrorMessages().toString() );
2968                 return false;
2969             }
2970             if ( phylogenies_2.length != 1 ) {
2971                 return false;
2972             }
2973             final Phylogeny t3 = phylogenies_2[ 0 ];
2974             if ( t3.getNumberOfExternalNodes() != 184 ) {
2975                 return false;
2976             }
2977             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2978                 return false;
2979             }
2980             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2981                 return false;
2982             }
2983             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2984                 return false;
2985             }
2986             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2987             if ( parser.getErrorCount() > 0 ) {
2988                 System.out.println( parser.getErrorMessages().toString() );
2989                 return false;
2990             }
2991             if ( phylogenies_3.length != 1 ) {
2992                 return false;
2993             }
2994             final Phylogeny t4 = phylogenies_3[ 0 ];
2995             if ( t4.getNumberOfExternalNodes() != 1 ) {
2996                 return false;
2997             }
2998             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2999                 return false;
3000             }
3001             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
3002                 return false;
3003             }
3004             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
3005                 return false;
3006             }
3007             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
3008             if ( parser.getErrorCount() > 0 ) {
3009                 System.out.println( parser.getErrorMessages().toString() );
3010                 return false;
3011             }
3012             if ( phylogenies_4.length != 1 ) {
3013                 return false;
3014             }
3015             final Phylogeny t5 = phylogenies_4[ 0 ];
3016             if ( t5.getNumberOfExternalNodes() != 13 ) {
3017                 return false;
3018             }
3019             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
3020                 return false;
3021             }
3022             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
3023                 return false;
3024             }
3025             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
3026                 return false;
3027             }
3028         }
3029         catch ( final Exception e ) {
3030             e.printStackTrace( System.out );
3031             return false;
3032         }
3033         return true;
3034     }
3035
3036     private static boolean testBasicTreeMethods() {
3037         try {
3038             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3039             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
3040             if ( t2.getNumberOfExternalNodes() != 4 ) {
3041                 return false;
3042             }
3043             if ( t2.getHeight() != 8.5 ) {
3044                 return false;
3045             }
3046             if ( !t2.isCompletelyBinary() ) {
3047                 return false;
3048             }
3049             if ( t2.isEmpty() ) {
3050                 return false;
3051             }
3052             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
3053             if ( t3.getNumberOfExternalNodes() != 5 ) {
3054                 return false;
3055             }
3056             if ( t3.getHeight() != 11 ) {
3057                 return false;
3058             }
3059             if ( t3.isCompletelyBinary() ) {
3060                 return false;
3061             }
3062             final PhylogenyNode n = t3.getNode( "ABC" );
3063             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 ];
3064             if ( t4.getNumberOfExternalNodes() != 9 ) {
3065                 return false;
3066             }
3067             if ( t4.getHeight() != 11 ) {
3068                 return false;
3069             }
3070             if ( t4.isCompletelyBinary() ) {
3071                 return false;
3072             }
3073             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)" );
3074             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
3075             if ( t5.getNumberOfExternalNodes() != 8 ) {
3076                 return false;
3077             }
3078             if ( t5.getHeight() != 15 ) {
3079                 return false;
3080             }
3081             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)" );
3082             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
3083             if ( t6.getHeight() != 15 ) {
3084                 return false;
3085             }
3086             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)" );
3087             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
3088             if ( t7.getHeight() != 15 ) {
3089                 return false;
3090             }
3091             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)" );
3092             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
3093             if ( t8.getNumberOfExternalNodes() != 10 ) {
3094                 return false;
3095             }
3096             if ( t8.getHeight() != 15 ) {
3097                 return false;
3098             }
3099             final char[] a9 = new char[] { 'a' };
3100             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
3101             if ( t9.getHeight() != 0 ) {
3102                 return false;
3103             }
3104             final char[] a10 = new char[] { 'a', ':', '6' };
3105             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
3106             if ( t10.getHeight() != 6 ) {
3107                 return false;
3108             }
3109         }
3110         catch ( final Exception e ) {
3111             e.printStackTrace( System.out );
3112             return false;
3113         }
3114         return true;
3115     }
3116
3117     private static boolean testConfidenceAssessor() {
3118         try {
3119             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3120             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3121             final Phylogeny[] ev0 = factory
3122                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3123                              new NHXParser() );
3124             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3125             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3126                 return false;
3127             }
3128             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3129                 return false;
3130             }
3131             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3132             final Phylogeny[] ev1 = factory
3133                     .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)));",
3134                              new NHXParser() );
3135             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3136             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3137                 return false;
3138             }
3139             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3140                 return false;
3141             }
3142             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3143             final Phylogeny[] ev_b = factory
3144                     .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",
3145                              new NHXParser() );
3146             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3147             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3148                 return false;
3149             }
3150             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3151                 return false;
3152             }
3153             //
3154             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3155             final Phylogeny[] ev1x = factory
3156                     .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)));",
3157                              new NHXParser() );
3158             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3159             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3160                 return false;
3161             }
3162             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3163                 return false;
3164             }
3165             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3166             final Phylogeny[] ev_bx = factory
3167                     .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",
3168                              new NHXParser() );
3169             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3170             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3171                 return false;
3172             }
3173             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3174                 return false;
3175             }
3176             final Phylogeny[] t2 = factory
3177                     .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);",
3178                              new NHXParser() );
3179             final Phylogeny[] ev2 = factory
3180                     .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);",
3181                              new NHXParser() );
3182             for( final Phylogeny target : t2 ) {
3183                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3184             }
3185             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3186                                                  new NHXParser() )[ 0 ];
3187             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3188             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3189             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3190                 return false;
3191             }
3192             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3193                 return false;
3194             }
3195             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3196                 return false;
3197             }
3198         }
3199         catch ( final Exception e ) {
3200             e.printStackTrace();
3201             return false;
3202         }
3203         return true;
3204     }
3205
3206     private static boolean testCopyOfNodeData() {
3207         try {
3208             final PhylogenyNode n1 = PhylogenyNode
3209                     .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]" );
3210             final PhylogenyNode n2 = n1.copyNodeData();
3211             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3212                 return false;
3213             }
3214         }
3215         catch ( final Exception e ) {
3216             e.printStackTrace();
3217             return false;
3218         }
3219         return true;
3220     }
3221
3222     private static boolean testCreateBalancedPhylogeny() {
3223         try {
3224             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3225             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3226                 return false;
3227             }
3228             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3229                 return false;
3230             }
3231             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3232             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3233                 return false;
3234             }
3235             if ( p1.getNumberOfExternalNodes() != 100 ) {
3236                 return false;
3237             }
3238         }
3239         catch ( final Exception e ) {
3240             e.printStackTrace();
3241             return false;
3242         }
3243         return true;
3244     }
3245
3246     private static boolean testCreateUriForSeqWeb() {
3247         try {
3248             final PhylogenyNode n = new PhylogenyNode();
3249             n.setName( "tr|B3RJ64" );
3250             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3251                 return false;
3252             }
3253             n.setName( "B0LM41_HUMAN" );
3254             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3255                 return false;
3256             }
3257             n.setName( "NP_001025424" );
3258             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3259                 return false;
3260             }
3261             n.setName( "_NM_001030253-" );
3262             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3263                 return false;
3264             }
3265             n.setName( "XM_002122186" );
3266             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3267                 return false;
3268             }
3269             n.setName( "dgh_AAA34956_gdg" );
3270             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3271                 return false;
3272             }
3273             n.setName( "AAA34956" );
3274             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3275                 return false;
3276             }
3277             n.setName( "GI:394892" );
3278             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3279                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3280                 return false;
3281             }
3282             n.setName( "gi_394892" );
3283             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3284                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3285                 return false;
3286             }
3287             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3288             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3289                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3290                 return false;
3291             }
3292             n.setName( "P12345" );
3293             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3294                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3295                 return false;
3296             }
3297             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3298             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3299                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3300                 return false;
3301             }
3302         }
3303         catch ( final Exception e ) {
3304             e.printStackTrace( System.out );
3305             return false;
3306         }
3307         return true;
3308     }
3309
3310     private static boolean testDataObjects() {
3311         try {
3312             final Confidence s0 = new Confidence();
3313             final Confidence s1 = new Confidence();
3314             if ( !s0.isEqual( s1 ) ) {
3315                 return false;
3316             }
3317             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3318             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3319             if ( s2.isEqual( s1 ) ) {
3320                 return false;
3321             }
3322             if ( !s2.isEqual( s3 ) ) {
3323                 return false;
3324             }
3325             final Confidence s4 = ( Confidence ) s3.copy();
3326             if ( !s4.isEqual( s3 ) ) {
3327                 return false;
3328             }
3329             s3.asSimpleText();
3330             s3.asText();
3331             // Taxonomy
3332             // ----------
3333             final Taxonomy t1 = new Taxonomy();
3334             final Taxonomy t2 = new Taxonomy();
3335             final Taxonomy t3 = new Taxonomy();
3336             final Taxonomy t4 = new Taxonomy();
3337             final Taxonomy t5 = new Taxonomy();
3338             t1.setIdentifier( new Identifier( "ecoli" ) );
3339             t1.setTaxonomyCode( "ECOLI" );
3340             t1.setScientificName( "E. coli" );
3341             t1.setCommonName( "coli" );
3342             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3343             if ( !t1.isEqual( t0 ) ) {
3344                 return false;
3345             }
3346             t2.setIdentifier( new Identifier( "ecoli" ) );
3347             t2.setTaxonomyCode( "OTHER" );
3348             t2.setScientificName( "what" );
3349             t2.setCommonName( "something" );
3350             if ( !t1.isEqual( t2 ) ) {
3351                 return false;
3352             }
3353             t2.setIdentifier( new Identifier( "nemve" ) );
3354             if ( t1.isEqual( t2 ) ) {
3355                 return false;
3356             }
3357             t1.setIdentifier( null );
3358             t3.setTaxonomyCode( "ECOLI" );
3359             t3.setScientificName( "what" );
3360             t3.setCommonName( "something" );
3361             if ( !t1.isEqual( t3 ) ) {
3362                 return false;
3363             }
3364             t1.setIdentifier( null );
3365             t1.setTaxonomyCode( "" );
3366             t4.setScientificName( "E. ColI" );
3367             t4.setCommonName( "something" );
3368             if ( !t1.isEqual( t4 ) ) {
3369                 return false;
3370             }
3371             t4.setScientificName( "B. subtilis" );
3372             t4.setCommonName( "something" );
3373             if ( t1.isEqual( t4 ) ) {
3374                 return false;
3375             }
3376             t1.setIdentifier( null );
3377             t1.setTaxonomyCode( "" );
3378             t1.setScientificName( "" );
3379             t5.setCommonName( "COLI" );
3380             if ( !t1.isEqual( t5 ) ) {
3381                 return false;
3382             }
3383             t5.setCommonName( "vibrio" );
3384             if ( t1.isEqual( t5 ) ) {
3385                 return false;
3386             }
3387             // Identifier
3388             // ----------
3389             final Identifier id0 = new Identifier( "123", "pfam" );
3390             final Identifier id1 = ( Identifier ) id0.copy();
3391             if ( !id1.isEqual( id1 ) ) {
3392                 return false;
3393             }
3394             if ( !id1.isEqual( id0 ) ) {
3395                 return false;
3396             }
3397             if ( !id0.isEqual( id1 ) ) {
3398                 return false;
3399             }
3400             id1.asSimpleText();
3401             id1.asText();
3402             // ProteinDomain
3403             // ---------------
3404             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3405             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3406             if ( !pd1.isEqual( pd1 ) ) {
3407                 return false;
3408             }
3409             if ( !pd1.isEqual( pd0 ) ) {
3410                 return false;
3411             }
3412             pd1.asSimpleText();
3413             pd1.asText();
3414             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3415             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3416             if ( !pd3.isEqual( pd3 ) ) {
3417                 return false;
3418             }
3419             if ( !pd2.isEqual( pd3 ) ) {
3420                 return false;
3421             }
3422             if ( !pd0.isEqual( pd3 ) ) {
3423                 return false;
3424             }
3425             pd3.asSimpleText();
3426             pd3.asText();
3427             // DomainArchitecture
3428             // ------------------
3429             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3430             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3431             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3432             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3433             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3434             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3435             domains0.add( d2 );
3436             domains0.add( d0 );
3437             domains0.add( d3 );
3438             domains0.add( d1 );
3439             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3440             if ( ds0.getNumberOfDomains() != 4 ) {
3441                 return false;
3442             }
3443             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3444             if ( !ds0.isEqual( ds0 ) ) {
3445                 return false;
3446             }
3447             if ( !ds0.isEqual( ds1 ) ) {
3448                 return false;
3449             }
3450             if ( ds1.getNumberOfDomains() != 4 ) {
3451                 return false;
3452             }
3453             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3454             domains1.add( d1 );
3455             domains1.add( d2 );
3456             domains1.add( d4 );
3457             domains1.add( d0 );
3458             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3459             if ( ds0.isEqual( ds2 ) ) {
3460                 return false;
3461             }
3462             ds1.asSimpleText();
3463             ds1.asText();
3464             ds1.toNHX();
3465             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3466             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3467                 System.out.println( ds3.toNHX() );
3468                 return false;
3469             }
3470             if ( ds3.getNumberOfDomains() != 3 ) {
3471                 return false;
3472             }
3473             // Event
3474             // -----
3475             final Event e1 = new Event( Event.EventType.fusion );
3476             if ( e1.isDuplication() ) {
3477                 return false;
3478             }
3479             if ( !e1.isFusion() ) {
3480                 return false;
3481             }
3482             if ( !e1.asText().toString().equals( "fusion" ) ) {
3483                 return false;
3484             }
3485             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3486                 return false;
3487             }
3488             final Event e11 = new Event( Event.EventType.fusion );
3489             if ( !e11.isEqual( e1 ) ) {
3490                 return false;
3491             }
3492             if ( !e11.toNHX().toString().equals( "" ) ) {
3493                 return false;
3494             }
3495             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3496             if ( e2.isDuplication() ) {
3497                 return false;
3498             }
3499             if ( !e2.isSpeciationOrDuplication() ) {
3500                 return false;
3501             }
3502             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3503                 return false;
3504             }
3505             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3506                 return false;
3507             }
3508             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3509                 return false;
3510             }
3511             if ( e11.isEqual( e2 ) ) {
3512                 return false;
3513             }
3514             final Event e2c = ( Event ) e2.copy();
3515             if ( !e2c.isEqual( e2 ) ) {
3516                 return false;
3517             }
3518             Event e3 = new Event( 1, 2, 3 );
3519             if ( e3.isDuplication() ) {
3520                 return false;
3521             }
3522             if ( e3.isSpeciation() ) {
3523                 return false;
3524             }
3525             if ( e3.isGeneLoss() ) {
3526                 return false;
3527             }
3528             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3529                 return false;
3530             }
3531             final Event e3c = ( Event ) e3.copy();
3532             final Event e3cc = ( Event ) e3c.copy();
3533             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3534                 return false;
3535             }
3536             e3 = null;
3537             if ( !e3c.isEqual( e3cc ) ) {
3538                 return false;
3539             }
3540             Event e4 = new Event( 1, 2, 3 );
3541             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3542                 return false;
3543             }
3544             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3545                 return false;
3546             }
3547             final Event e4c = ( Event ) e4.copy();
3548             e4 = null;
3549             final Event e4cc = ( Event ) e4c.copy();
3550             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3551                 return false;
3552             }
3553             if ( !e4c.isEqual( e4cc ) ) {
3554                 return false;
3555             }
3556             final Event e5 = new Event();
3557             if ( !e5.isUnassigned() ) {
3558                 return false;
3559             }
3560             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3561                 return false;
3562             }
3563             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3564                 return false;
3565             }
3566             final Event e6 = new Event( 1, 0, 0 );
3567             if ( !e6.asText().toString().equals( "duplication" ) ) {
3568                 return false;
3569             }
3570             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3571                 return false;
3572             }
3573             final Event e7 = new Event( 0, 1, 0 );
3574             if ( !e7.asText().toString().equals( "speciation" ) ) {
3575                 return false;
3576             }
3577             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3578                 return false;
3579             }
3580             final Event e8 = new Event( 0, 0, 1 );
3581             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3582                 return false;
3583             }
3584             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3585                 return false;
3586             }
3587         }
3588         catch ( final Exception e ) {
3589             e.printStackTrace( System.out );
3590             return false;
3591         }
3592         return true;
3593     }
3594
3595     private static boolean testDeletionOfExternalNodes() {
3596         try {
3597             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3598             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3599             final PhylogenyWriter w = new PhylogenyWriter();
3600             if ( t0.isEmpty() ) {
3601                 return false;
3602             }
3603             if ( t0.getNumberOfExternalNodes() != 1 ) {
3604                 return false;
3605             }
3606             t0.deleteSubtree( t0.getNode( "A" ), false );
3607             if ( t0.getNumberOfExternalNodes() != 0 ) {
3608                 return false;
3609             }
3610             if ( !t0.isEmpty() ) {
3611                 return false;
3612             }
3613             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3614             if ( t1.getNumberOfExternalNodes() != 2 ) {
3615                 return false;
3616             }
3617             t1.deleteSubtree( t1.getNode( "A" ), false );
3618             if ( t1.getNumberOfExternalNodes() != 1 ) {
3619                 return false;
3620             }
3621             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3622                 return false;
3623             }
3624             t1.deleteSubtree( t1.getNode( "B" ), false );
3625             if ( t1.getNumberOfExternalNodes() != 1 ) {
3626                 return false;
3627             }
3628             t1.deleteSubtree( t1.getNode( "r" ), false );
3629             if ( !t1.isEmpty() ) {
3630                 return false;
3631             }
3632             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3633             if ( t2.getNumberOfExternalNodes() != 3 ) {
3634                 return false;
3635             }
3636             t2.deleteSubtree( t2.getNode( "B" ), false );
3637             if ( t2.getNumberOfExternalNodes() != 2 ) {
3638                 return false;
3639             }
3640             t2.toNewHampshireX();
3641             PhylogenyNode n = t2.getNode( "A" );
3642             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3643                 return false;
3644             }
3645             t2.deleteSubtree( t2.getNode( "A" ), false );
3646             if ( t2.getNumberOfExternalNodes() != 2 ) {
3647                 return false;
3648             }
3649             t2.deleteSubtree( t2.getNode( "C" ), true );
3650             if ( t2.getNumberOfExternalNodes() != 1 ) {
3651                 return false;
3652             }
3653             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3654             if ( t3.getNumberOfExternalNodes() != 4 ) {
3655                 return false;
3656             }
3657             t3.deleteSubtree( t3.getNode( "B" ), true );
3658             if ( t3.getNumberOfExternalNodes() != 3 ) {
3659                 return false;
3660             }
3661             n = t3.getNode( "A" );
3662             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3663                 return false;
3664             }
3665             n = n.getNextExternalNode();
3666             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3667                 return false;
3668             }
3669             t3.deleteSubtree( t3.getNode( "A" ), true );
3670             if ( t3.getNumberOfExternalNodes() != 2 ) {
3671                 return false;
3672             }
3673             n = t3.getNode( "C" );
3674             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3675                 return false;
3676             }
3677             t3.deleteSubtree( t3.getNode( "C" ), true );
3678             if ( t3.getNumberOfExternalNodes() != 1 ) {
3679                 return false;
3680             }
3681             t3.deleteSubtree( t3.getNode( "D" ), true );
3682             if ( t3.getNumberOfExternalNodes() != 0 ) {
3683                 return false;
3684             }
3685             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3686             if ( t4.getNumberOfExternalNodes() != 6 ) {
3687                 return false;
3688             }
3689             t4.deleteSubtree( t4.getNode( "B2" ), true );
3690             if ( t4.getNumberOfExternalNodes() != 5 ) {
3691                 return false;
3692             }
3693             String s = w.toNewHampshire( t4, true ).toString();
3694             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3695                 return false;
3696             }
3697             t4.deleteSubtree( t4.getNode( "B11" ), true );
3698             if ( t4.getNumberOfExternalNodes() != 4 ) {
3699                 return false;
3700             }
3701             t4.deleteSubtree( t4.getNode( "C" ), true );
3702             if ( t4.getNumberOfExternalNodes() != 3 ) {
3703                 return false;
3704             }
3705             n = t4.getNode( "A" );
3706             n = n.getNextExternalNode();
3707             if ( !n.getName().equals( "B12" ) ) {
3708                 return false;
3709             }
3710             n = n.getNextExternalNode();
3711             if ( !n.getName().equals( "D" ) ) {
3712                 return false;
3713             }
3714             s = w.toNewHampshire( t4, true ).toString();
3715             if ( !s.equals( "((A,B12),D);" ) ) {
3716                 return false;
3717             }
3718             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3719             t5.deleteSubtree( t5.getNode( "A" ), true );
3720             if ( t5.getNumberOfExternalNodes() != 5 ) {
3721                 return false;
3722             }
3723             s = w.toNewHampshire( t5, true ).toString();
3724             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3725                 return false;
3726             }
3727             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3728             t6.deleteSubtree( t6.getNode( "B11" ), true );
3729             if ( t6.getNumberOfExternalNodes() != 5 ) {
3730                 return false;
3731             }
3732             s = w.toNewHampshire( t6, false ).toString();
3733             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3734                 return false;
3735             }
3736             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3737             t7.deleteSubtree( t7.getNode( "B12" ), true );
3738             if ( t7.getNumberOfExternalNodes() != 5 ) {
3739                 return false;
3740             }
3741             s = w.toNewHampshire( t7, true ).toString();
3742             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3743                 return false;
3744             }
3745             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3746             t8.deleteSubtree( t8.getNode( "B2" ), true );
3747             if ( t8.getNumberOfExternalNodes() != 5 ) {
3748                 return false;
3749             }
3750             s = w.toNewHampshire( t8, false ).toString();
3751             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3752                 return false;
3753             }
3754             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3755             t9.deleteSubtree( t9.getNode( "C" ), true );
3756             if ( t9.getNumberOfExternalNodes() != 5 ) {
3757                 return false;
3758             }
3759             s = w.toNewHampshire( t9, true ).toString();
3760             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3761                 return false;
3762             }
3763             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3764             t10.deleteSubtree( t10.getNode( "D" ), true );
3765             if ( t10.getNumberOfExternalNodes() != 5 ) {
3766                 return false;
3767             }
3768             s = w.toNewHampshire( t10, true ).toString();
3769             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3770                 return false;
3771             }
3772             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3773             t11.deleteSubtree( t11.getNode( "A" ), true );
3774             if ( t11.getNumberOfExternalNodes() != 2 ) {
3775                 return false;
3776             }
3777             s = w.toNewHampshire( t11, true ).toString();
3778             if ( !s.equals( "(B,C);" ) ) {
3779                 return false;
3780             }
3781             t11.deleteSubtree( t11.getNode( "C" ), true );
3782             if ( t11.getNumberOfExternalNodes() != 1 ) {
3783                 return false;
3784             }
3785             s = w.toNewHampshire( t11, false ).toString();
3786             if ( !s.equals( "B;" ) ) {
3787                 return false;
3788             }
3789             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3790             t12.deleteSubtree( t12.getNode( "B2" ), true );
3791             if ( t12.getNumberOfExternalNodes() != 8 ) {
3792                 return false;
3793             }
3794             s = w.toNewHampshire( t12, true ).toString();
3795             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3796                 return false;
3797             }
3798             t12.deleteSubtree( t12.getNode( "B3" ), true );
3799             if ( t12.getNumberOfExternalNodes() != 7 ) {
3800                 return false;
3801             }
3802             s = w.toNewHampshire( t12, true ).toString();
3803             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3804                 return false;
3805             }
3806             t12.deleteSubtree( t12.getNode( "C3" ), true );
3807             if ( t12.getNumberOfExternalNodes() != 6 ) {
3808                 return false;
3809             }
3810             s = w.toNewHampshire( t12, true ).toString();
3811             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3812                 return false;
3813             }
3814             t12.deleteSubtree( t12.getNode( "A1" ), true );
3815             if ( t12.getNumberOfExternalNodes() != 5 ) {
3816                 return false;
3817             }
3818             s = w.toNewHampshire( t12, true ).toString();
3819             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3820                 return false;
3821             }
3822             t12.deleteSubtree( t12.getNode( "B1" ), true );
3823             if ( t12.getNumberOfExternalNodes() != 4 ) {
3824                 return false;
3825             }
3826             s = w.toNewHampshire( t12, true ).toString();
3827             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3828                 return false;
3829             }
3830             t12.deleteSubtree( t12.getNode( "A3" ), true );
3831             if ( t12.getNumberOfExternalNodes() != 3 ) {
3832                 return false;
3833             }
3834             s = w.toNewHampshire( t12, true ).toString();
3835             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3836                 return false;
3837             }
3838             t12.deleteSubtree( t12.getNode( "A2" ), true );
3839             if ( t12.getNumberOfExternalNodes() != 2 ) {
3840                 return false;
3841             }
3842             s = w.toNewHampshire( t12, true ).toString();
3843             if ( !s.equals( "(C1,C2);" ) ) {
3844                 return false;
3845             }
3846             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3847             t13.deleteSubtree( t13.getNode( "D" ), true );
3848             if ( t13.getNumberOfExternalNodes() != 4 ) {
3849                 return false;
3850             }
3851             s = w.toNewHampshire( t13, true ).toString();
3852             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3853                 return false;
3854             }
3855             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3856             t14.deleteSubtree( t14.getNode( "E" ), true );
3857             if ( t14.getNumberOfExternalNodes() != 5 ) {
3858                 return false;
3859             }
3860             s = w.toNewHampshire( t14, true ).toString();
3861             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3862                 return false;
3863             }
3864             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3865             t15.deleteSubtree( t15.getNode( "B2" ), true );
3866             if ( t15.getNumberOfExternalNodes() != 11 ) {
3867                 return false;
3868             }
3869             t15.deleteSubtree( t15.getNode( "B1" ), true );
3870             if ( t15.getNumberOfExternalNodes() != 10 ) {
3871                 return false;
3872             }
3873             t15.deleteSubtree( t15.getNode( "B3" ), true );
3874             if ( t15.getNumberOfExternalNodes() != 9 ) {
3875                 return false;
3876             }
3877             t15.deleteSubtree( t15.getNode( "B4" ), true );
3878             if ( t15.getNumberOfExternalNodes() != 8 ) {
3879                 return false;
3880             }
3881             t15.deleteSubtree( t15.getNode( "A1" ), true );
3882             if ( t15.getNumberOfExternalNodes() != 7 ) {
3883                 return false;
3884             }
3885             t15.deleteSubtree( t15.getNode( "C4" ), true );
3886             if ( t15.getNumberOfExternalNodes() != 6 ) {
3887                 return false;
3888             }
3889         }
3890         catch ( final Exception e ) {
3891             e.printStackTrace( System.out );
3892             return false;
3893         }
3894         return true;
3895     }
3896
3897     private static boolean testDescriptiveStatistics() {
3898         try {
3899             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3900             dss1.addValue( 82 );
3901             dss1.addValue( 78 );
3902             dss1.addValue( 70 );
3903             dss1.addValue( 58 );
3904             dss1.addValue( 42 );
3905             if ( dss1.getN() != 5 ) {
3906                 return false;
3907             }
3908             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3909                 return false;
3910             }
3911             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3912                 return false;
3913             }
3914             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3915                 return false;
3916             }
3917             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3918                 return false;
3919             }
3920             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3921                 return false;
3922             }
3923             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3924                 return false;
3925             }
3926             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3927                 return false;
3928             }
3929             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3930                 return false;
3931             }
3932             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3933                 return false;
3934             }
3935             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3936                 return false;
3937             }
3938             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3939                 return false;
3940             }
3941             dss1.addValue( 123 );
3942             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3943                 return false;
3944             }
3945             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3946                 return false;
3947             }
3948             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3949                 return false;
3950             }
3951             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3952             dss2.addValue( -1.85 );
3953             dss2.addValue( 57.5 );
3954             dss2.addValue( 92.78 );
3955             dss2.addValue( 57.78 );
3956             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3957                 return false;
3958             }
3959             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3960                 return false;
3961             }
3962             final double[] a = dss2.getDataAsDoubleArray();
3963             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3964                 return false;
3965             }
3966             dss2.addValue( -100 );
3967             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3968                 return false;
3969             }
3970             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3971                 return false;
3972             }
3973             final double[] ds = new double[ 14 ];
3974             ds[ 0 ] = 34;
3975             ds[ 1 ] = 23;
3976             ds[ 2 ] = 1;
3977             ds[ 3 ] = 32;
3978             ds[ 4 ] = 11;
3979             ds[ 5 ] = 2;
3980             ds[ 6 ] = 12;
3981             ds[ 7 ] = 33;
3982             ds[ 8 ] = 13;
3983             ds[ 9 ] = 22;
3984             ds[ 10 ] = 21;
3985             ds[ 11 ] = 35;
3986             ds[ 12 ] = 24;
3987             ds[ 13 ] = 31;
3988             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3989             if ( bins.length != 4 ) {
3990                 return false;
3991             }
3992             if ( bins[ 0 ] != 2 ) {
3993                 return false;
3994             }
3995             if ( bins[ 1 ] != 3 ) {
3996                 return false;
3997             }
3998             if ( bins[ 2 ] != 4 ) {
3999                 return false;
4000             }
4001             if ( bins[ 3 ] != 5 ) {
4002                 return false;
4003             }
4004             final double[] ds1 = new double[ 9 ];
4005             ds1[ 0 ] = 10.0;
4006             ds1[ 1 ] = 19.0;
4007             ds1[ 2 ] = 9.999;
4008             ds1[ 3 ] = 0.0;
4009             ds1[ 4 ] = 39.9;
4010             ds1[ 5 ] = 39.999;
4011             ds1[ 6 ] = 30.0;
4012             ds1[ 7 ] = 19.999;
4013             ds1[ 8 ] = 30.1;
4014             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
4015             if ( bins1.length != 4 ) {
4016                 return false;
4017             }
4018             if ( bins1[ 0 ] != 2 ) {
4019                 return false;
4020             }
4021             if ( bins1[ 1 ] != 3 ) {
4022                 return false;
4023             }
4024             if ( bins1[ 2 ] != 0 ) {
4025                 return false;
4026             }
4027             if ( bins1[ 3 ] != 4 ) {
4028                 return false;
4029             }
4030             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
4031             if ( bins1_1.length != 3 ) {
4032                 return false;
4033             }
4034             if ( bins1_1[ 0 ] != 3 ) {
4035                 return false;
4036             }
4037             if ( bins1_1[ 1 ] != 2 ) {
4038                 return false;
4039             }
4040             if ( bins1_1[ 2 ] != 4 ) {
4041                 return false;
4042             }
4043             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
4044             if ( bins1_2.length != 3 ) {
4045                 return false;
4046             }
4047             if ( bins1_2[ 0 ] != 2 ) {
4048                 return false;
4049             }
4050             if ( bins1_2[ 1 ] != 2 ) {
4051                 return false;
4052             }
4053             if ( bins1_2[ 2 ] != 2 ) {
4054                 return false;
4055             }
4056             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
4057             dss3.addValue( 1 );
4058             dss3.addValue( 1 );
4059             dss3.addValue( 1 );
4060             dss3.addValue( 2 );
4061             dss3.addValue( 3 );
4062             dss3.addValue( 4 );
4063             dss3.addValue( 5 );
4064             dss3.addValue( 5 );
4065             dss3.addValue( 5 );
4066             dss3.addValue( 6 );
4067             dss3.addValue( 7 );
4068             dss3.addValue( 8 );
4069             dss3.addValue( 9 );
4070             dss3.addValue( 10 );
4071             dss3.addValue( 10 );
4072             dss3.addValue( 10 );
4073             final AsciiHistogram histo = new AsciiHistogram( dss3 );
4074             histo.toStringBuffer( 10, '=', 40, 5 );
4075             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
4076         }
4077         catch ( final Exception e ) {
4078             e.printStackTrace( System.out );
4079             return false;
4080         }
4081         return true;
4082     }
4083
4084     private static boolean testDir( final String file ) {
4085         try {
4086             final File f = new File( file );
4087             if ( !f.exists() ) {
4088                 return false;
4089             }
4090             if ( !f.isDirectory() ) {
4091                 return false;
4092             }
4093             if ( !f.canRead() ) {
4094                 return false;
4095             }
4096         }
4097         catch ( final Exception e ) {
4098             return false;
4099         }
4100         return true;
4101     }
4102
4103     private static boolean testEbiEntryRetrieval() {
4104         try {
4105             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
4106             if ( !entry.getAccession().equals( "AAK41263" ) ) {
4107                 System.out.println( entry.getAccession() );
4108                 return false;
4109             }
4110             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
4111                 System.out.println( entry.getTaxonomyScientificName() );
4112                 return false;
4113             }
4114             if ( !entry.getSequenceName()
4115                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4116                 System.out.println( entry.getSequenceName() );
4117                 return false;
4118             }
4119             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4120                 System.out.println( entry.getGeneName() );
4121                 return false;
4122             }
4123             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4124                 System.out.println( entry.getTaxonomyIdentifier() );
4125                 return false;
4126             }
4127             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4128                 System.out.println( entry.getAnnotations().first().getRefValue() );
4129                 return false;
4130             }
4131             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4132                 System.out.println( entry.getAnnotations().first().getRefSource() );
4133                 return false;
4134             }
4135             if ( entry.getCrossReferences().size() < 1 ) {
4136                 return false;
4137             }
4138             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4139             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4140                 return false;
4141             }
4142             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4143                 System.out.println( entry1.getTaxonomyScientificName() );
4144                 return false;
4145             }
4146             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4147                 System.out.println( entry1.getSequenceName() );
4148                 return false;
4149             }
4150             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4151                 System.out.println( entry1.getTaxonomyIdentifier() );
4152                 return false;
4153             }
4154             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4155                 System.out.println( entry1.getGeneName() );
4156                 return false;
4157             }
4158             if ( entry1.getCrossReferences().size() < 1 ) {
4159                 return false;
4160             }
4161             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4162             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4163                 return false;
4164             }
4165             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4166                 System.out.println( entry2.getTaxonomyScientificName() );
4167                 return false;
4168             }
4169             if ( !entry2.getSequenceName()
4170                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4171                 System.out.println( entry2.getSequenceName() );
4172                 return false;
4173             }
4174             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4175                 System.out.println( entry2.getTaxonomyIdentifier() );
4176                 return false;
4177             }
4178             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4179                 System.out.println( entry2.getGeneName() );
4180                 return false;
4181             }
4182             if ( entry2.getCrossReferences().size() < 1 ) {
4183                 return false;
4184             }
4185             if ( !entry2.getChromosome().equals( "20" ) ) {
4186                 return false;
4187             }
4188             if ( !entry2.getMap().equals( "20q11.22" ) ) {
4189                 return false;
4190             }
4191             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4192             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4193                 return false;
4194             }
4195             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4196                 System.out.println( entry3.getTaxonomyScientificName() );
4197                 return false;
4198             }
4199             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4200                 System.out.println( entry3.getSequenceName() );
4201                 return false;
4202             }
4203             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4204                 System.out.println( entry3.getTaxonomyIdentifier() );
4205                 return false;
4206             }
4207             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4208                 System.out.println( entry3.getSequenceSymbol() );
4209                 return false;
4210             }
4211             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4212                 return false;
4213             }
4214             if ( entry3.getCrossReferences().size() < 1 ) {
4215                 return false;
4216             }
4217             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4218             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4219                 return false;
4220             }
4221             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4222                 System.out.println( entry4.getTaxonomyScientificName() );
4223                 return false;
4224             }
4225             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4226                 System.out.println( entry4.getSequenceName() );
4227                 return false;
4228             }
4229             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4230                 System.out.println( entry4.getTaxonomyIdentifier() );
4231                 return false;
4232             }
4233             if ( !entry4.getGeneName().equals( "ras" ) ) {
4234                 System.out.println( entry4.getGeneName() );
4235                 return false;
4236             }
4237             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4238             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4239                 return false;
4240             }
4241             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4242                 System.out.println( entry5.getTaxonomyScientificName() );
4243                 return false;
4244             }
4245             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4246                 System.out.println( entry5.getSequenceName() );
4247                 return false;
4248             }
4249             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4250                 System.out.println( entry5.getTaxonomyIdentifier() );
4251                 return false;
4252             }
4253             final SequenceDatabaseEntry entry6 = SequenceDbWsTools.obtainEntry( "M30539" );
4254             if ( !entry6.getAccession().equals( "M30539" ) ) {
4255                 return false;
4256             }
4257             if ( !entry6.getGeneName().equals( "ras" ) ) {
4258                 return false;
4259             }
4260             if ( !entry6.getSequenceName().equals( "Human SK2 c-Ha-ras-1 oncogene-encoded protein gene, exon 1" ) ) {
4261                 return false;
4262             }
4263             if ( !entry6.getTaxonomyIdentifier().equals( "9606" ) ) {
4264                 return false;
4265             }
4266             if ( !entry6.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4267                 return false;
4268             }
4269             if ( entry6.getCrossReferences().size() < 1 ) {
4270                 return false;
4271             }
4272         }
4273         catch ( final IOException e ) {
4274             System.out.println();
4275             System.out.println( "the following might be due to absence internet connection:" );
4276             e.printStackTrace( System.out );
4277             return true;
4278         }
4279         catch ( final Exception e ) {
4280             e.printStackTrace();
4281             return false;
4282         }
4283         return true;
4284     }
4285
4286     private static boolean testExternalNodeRelatedMethods() {
4287         try {
4288             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4289             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4290             PhylogenyNode n = t1.getNode( "A" );
4291             n = n.getNextExternalNode();
4292             if ( !n.getName().equals( "B" ) ) {
4293                 return false;
4294             }
4295             n = n.getNextExternalNode();
4296             if ( !n.getName().equals( "C" ) ) {
4297                 return false;
4298             }
4299             n = n.getNextExternalNode();
4300             if ( !n.getName().equals( "D" ) ) {
4301                 return false;
4302             }
4303             n = t1.getNode( "B" );
4304             while ( !n.isLastExternalNode() ) {
4305                 n = n.getNextExternalNode();
4306             }
4307             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4308             n = t2.getNode( "A" );
4309             n = n.getNextExternalNode();
4310             if ( !n.getName().equals( "B" ) ) {
4311                 return false;
4312             }
4313             n = n.getNextExternalNode();
4314             if ( !n.getName().equals( "C" ) ) {
4315                 return false;
4316             }
4317             n = n.getNextExternalNode();
4318             if ( !n.getName().equals( "D" ) ) {
4319                 return false;
4320             }
4321             n = t2.getNode( "B" );
4322             while ( !n.isLastExternalNode() ) {
4323                 n = n.getNextExternalNode();
4324             }
4325             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4326             n = t3.getNode( "A" );
4327             n = n.getNextExternalNode();
4328             if ( !n.getName().equals( "B" ) ) {
4329                 return false;
4330             }
4331             n = n.getNextExternalNode();
4332             if ( !n.getName().equals( "C" ) ) {
4333                 return false;
4334             }
4335             n = n.getNextExternalNode();
4336             if ( !n.getName().equals( "D" ) ) {
4337                 return false;
4338             }
4339             n = n.getNextExternalNode();
4340             if ( !n.getName().equals( "E" ) ) {
4341                 return false;
4342             }
4343             n = n.getNextExternalNode();
4344             if ( !n.getName().equals( "F" ) ) {
4345                 return false;
4346             }
4347             n = n.getNextExternalNode();
4348             if ( !n.getName().equals( "G" ) ) {
4349                 return false;
4350             }
4351             n = n.getNextExternalNode();
4352             if ( !n.getName().equals( "H" ) ) {
4353                 return false;
4354             }
4355             n = t3.getNode( "B" );
4356             while ( !n.isLastExternalNode() ) {
4357                 n = n.getNextExternalNode();
4358             }
4359             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4360             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4361                 final PhylogenyNode node = iter.next();
4362             }
4363             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4364             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4365                 final PhylogenyNode node = iter.next();
4366             }
4367             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4368             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4369             if ( !iter.next().getName().equals( "A" ) ) {
4370                 return false;
4371             }
4372             if ( !iter.next().getName().equals( "B" ) ) {
4373                 return false;
4374             }
4375             if ( !iter.next().getName().equals( "C" ) ) {
4376                 return false;
4377             }
4378             if ( !iter.next().getName().equals( "D" ) ) {
4379                 return false;
4380             }
4381             if ( !iter.next().getName().equals( "E" ) ) {
4382                 return false;
4383             }
4384             if ( !iter.next().getName().equals( "F" ) ) {
4385                 return false;
4386             }
4387             if ( iter.hasNext() ) {
4388                 return false;
4389             }
4390         }
4391         catch ( final Exception e ) {
4392             e.printStackTrace( System.out );
4393             return false;
4394         }
4395         return true;
4396     }
4397
4398     private static boolean testExtractSNFromNodeName() {
4399         try {
4400             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4401                 return false;
4402             }
4403             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4404                 return false;
4405             }
4406             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4407                 return false;
4408             }
4409             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4410                     .equals( "Mus musculus musculus" ) ) {
4411                 return false;
4412             }
4413             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4414                     .equals( "Mus musculus musculus" ) ) {
4415                 return false;
4416             }
4417             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4418                     .equals( "Mus musculus musculus" ) ) {
4419                 return false;
4420             }
4421             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4422                     .equals( "Mus musculus musculus" ) ) {
4423                 return false;
4424             }
4425             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4426                 return false;
4427             }
4428             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4429                     .equals( "Mus musculus musculus" ) ) {
4430                 return false;
4431             }
4432             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4433                     .equals( "Mus musculus musculus" ) ) {
4434                 return false;
4435             }
4436             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4437                 return false;
4438             }
4439             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4440                 return false;
4441             }
4442             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4443                 return false;
4444             }
4445             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4446                 return false;
4447             }
4448             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4449                     .equals( "Mus musculus musculus" ) ) {
4450                 return false;
4451             }
4452             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4453                 return false;
4454             }
4455             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4456                 return false;
4457             }
4458             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4459                 return false;
4460             }
4461             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4462                 return false;
4463             }
4464             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4465                 return false;
4466             }
4467             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4468                 return false;
4469             }
4470             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4471                 return false;
4472             }
4473             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4474                 return false;
4475             }
4476             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4477                     .equals( "Mus musculus" ) ) {
4478                 return false;
4479             }
4480             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4481                     .equals( "Mus musculus" ) ) {
4482                 return false;
4483             }
4484             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4485                 return false;
4486             }
4487             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4488                     .equals( "Mus musculus musculus" ) ) {
4489                 return false;
4490             }
4491             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4492                     .equals( "Mus musculus musculus" ) ) {
4493                 return false;
4494             }
4495             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4496                     .equals( "Mus musculus musculus" ) ) {
4497                 return false;
4498             }
4499             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4500                 return false;
4501             }
4502             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4503                     .equals( "Pilostyles mexicana" ) ) {
4504                 return false;
4505             }
4506             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4507                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4508                 return false;
4509             }
4510             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4511                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4512                 return false;
4513             }
4514             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4515                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4516                 return false;
4517             }
4518             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4519                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4520                 return false;
4521             }
4522             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4523                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4524                 return false;
4525             }
4526             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4527                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4528                 return false;
4529             }
4530             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4531                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4532                 return false;
4533             }
4534             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4535                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4536                 return false;
4537             }
4538             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4539                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4540                 return false;
4541             }
4542             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4543                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4544                 return false;
4545             }
4546             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4547                     .equals( "Escherichia coli (strain K12)" ) ) {
4548                 return false;
4549             }
4550             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4551                     .equals( "Escherichia coli (strain K12)" ) ) {
4552                 return false;
4553             }
4554             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4555                     .equals( "Escherichia coli (str. K12)" ) ) {
4556                 return false;
4557             }
4558             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4559                     .equals( "Escherichia coli (str. K12)" ) ) {
4560                 return false;
4561             }
4562             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4563                     .equals( "Escherichia coli (str. K12)" ) ) {
4564                 return false;
4565             }
4566             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4567                     .equals( "Escherichia coli (var. K12)" ) ) {
4568                 return false;
4569             }
4570             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4571                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4572                 return false;
4573             }
4574             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4575                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4576                 return false;
4577             }
4578             if ( !ParserUtils
4579                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4580                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4581                 return false;
4582             }
4583             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4584                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4585                 return false;
4586             }
4587             if ( !ParserUtils
4588                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4589                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4590                 return false;
4591             }
4592             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4593                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4594                 return false;
4595             }
4596             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4597                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4598                 return false;
4599             }
4600             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4601                 return false;
4602             }
4603             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4604                 return false;
4605             }
4606             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4607                 return false;
4608             }
4609             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4610                     .equals( "Macrocera sp." ) ) {
4611                 return false;
4612             }
4613             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4614                 return false;
4615             }
4616             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4617                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4618                 return false;
4619             }
4620             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4621                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4622                 return false;
4623             }
4624             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4625                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4626                 return false;
4627             }
4628             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4629                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4630                 return false;
4631             }
4632         }
4633         catch ( final Exception e ) {
4634             e.printStackTrace( System.out );
4635             return false;
4636         }
4637         return true;
4638     }
4639
4640     private static boolean testExtractTaxonomyDataFromNodeName() {
4641         try {
4642             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
4643             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4644                 return false;
4645             }
4646             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
4647             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4648                 return false;
4649             }
4650             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
4651             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4652                 return false;
4653             }
4654             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
4655             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4656                 return false;
4657             }
4658             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
4659             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4660                 return false;
4661             }
4662             n = new PhylogenyNode( "HNRPR_HUMAN" );
4663             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4664                 return false;
4665             }
4666             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
4667             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4668                 return false;
4669             }
4670         }
4671         catch ( final Exception e ) {
4672             e.printStackTrace( System.out );
4673             return false;
4674         }
4675         return true;
4676     }
4677
4678     private static boolean testExtractTaxonomyCodeFromNodeName() {
4679         try {
4680             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4681                 return false;
4682             }
4683             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4684                     .equals( "SOYBN" ) ) {
4685                 return false;
4686             }
4687             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4688                     .equals( "ARATH" ) ) {
4689                 return false;
4690             }
4691             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4692                     .equals( "ARATH" ) ) {
4693                 return false;
4694             }
4695             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4696                 return false;
4697             }
4698             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4699                 return false;
4700             }
4701             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4702                 return false;
4703             }
4704             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4705                     .equals( "SOYBN" ) ) {
4706                 return false;
4707             }
4708             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4709                     .equals( "SOYBN" ) ) {
4710                 return false;
4711             }
4712             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4713                     .equals( "SOYBN" ) ) {
4714                 return false;
4715             }
4716             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4717                     .equals( "SOYBN" ) ) {
4718                 return false;
4719             }
4720             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4721                     .equals( "SOYBN" ) ) {
4722                 return false;
4723             }
4724             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4725                     .equals( "SOYBN" ) ) {
4726                 return false;
4727             }
4728             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4729                     .equals( "SOYBN" ) ) {
4730                 return false;
4731             }
4732             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4733                     .equals( "SOYBN" ) ) {
4734                 return false;
4735             }
4736             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4737                 return false;
4738             }
4739             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4740                     .equals( "SOYBN" ) ) {
4741                 return false;
4742             }
4743             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4744                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4745                 return false;
4746             }
4747             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4748                     .equals( "9YX45" ) ) {
4749                 return false;
4750             }
4751             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4752                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4753                                                                .equals( "MOUSE" ) ) {
4754                 return false;
4755             }
4756             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4757                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4758                                                                .equals( "MOUSE" ) ) {
4759                 return false;
4760             }
4761             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4762                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4763                                                                .equals( "MOUSE" ) ) {
4764                 return false;
4765             }
4766             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4767                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4768                 return false;
4769             }
4770             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4771                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4772                 return false;
4773             }
4774             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4775                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4776                 return false;
4777             }
4778             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4779                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4780                 return false;
4781             }
4782             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4783                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4784                 return false;
4785             }
4786             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4787                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4788                 return false;
4789             }
4790             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4791                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4792                 return false;
4793             }
4794             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4795                     .equals( "RAT" ) ) {
4796                 return false;
4797             }
4798             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4799                     .equals( "PIG" ) ) {
4800                 return false;
4801             }
4802             if ( !ParserUtils
4803                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4804                     .equals( "MOUSE" ) ) {
4805                 return false;
4806             }
4807             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4808                     .equals( "MOUSE" ) ) {
4809                 return false;
4810             }
4811             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4812                 return false;
4813             }
4814         }
4815         catch ( final Exception e ) {
4816             e.printStackTrace( System.out );
4817             return false;
4818         }
4819         return true;
4820     }
4821
4822     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4823         try {
4824             PhylogenyNode n = new PhylogenyNode();
4825             n.setName( "tr|B3RJ64" );
4826             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4827                 return false;
4828             }
4829             n.setName( "tr.B3RJ64" );
4830             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4831                 return false;
4832             }
4833             n.setName( "tr=B3RJ64" );
4834             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4835                 return false;
4836             }
4837             n.setName( "tr-B3RJ64" );
4838             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4839                 return false;
4840             }
4841             n.setName( "tr/B3RJ64" );
4842             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4843                 return false;
4844             }
4845             n.setName( "tr\\B3RJ64" );
4846             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4847                 return false;
4848             }
4849             n.setName( "tr_B3RJ64" );
4850             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4851                 return false;
4852             }
4853             n.setName( " tr|B3RJ64 " );
4854             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4855                 return false;
4856             }
4857             n.setName( "-tr|B3RJ64-" );
4858             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4859                 return false;
4860             }
4861             n.setName( "-tr=B3RJ64-" );
4862             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4863                 return false;
4864             }
4865             n.setName( "_tr=B3RJ64_" );
4866             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4867                 return false;
4868             }
4869             n.setName( " tr_tr|B3RJ64_sp|123 " );
4870             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4871                 return false;
4872             }
4873             n.setName( "B3RJ64" );
4874             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4875                 return false;
4876             }
4877             n.setName( "sp|B3RJ64" );
4878             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4879                 return false;
4880             }
4881             n.setName( "sp|B3RJ64C" );
4882             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4883                 return false;
4884             }
4885             n.setName( "sp B3RJ64" );
4886             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4887                 return false;
4888             }
4889             n.setName( "sp|B3RJ6X" );
4890             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4891                 return false;
4892             }
4893             n.setName( "sp|B3RJ6" );
4894             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4895                 return false;
4896             }
4897             n.setName( "K1PYK7_CRAGI" );
4898             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4899                 return false;
4900             }
4901             n.setName( "K1PYK7_PEA" );
4902             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4903                 return false;
4904             }
4905             n.setName( "K1PYK7_RAT" );
4906             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4907                 return false;
4908             }
4909             n.setName( "K1PYK7_PIG" );
4910             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4911                 return false;
4912             }
4913             n.setName( "~K1PYK7_PIG~" );
4914             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4915                 return false;
4916             }
4917             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4918             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4919                 return false;
4920             }
4921             n.setName( "K1PYKX_CRAGI" );
4922             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4923                 return false;
4924             }
4925             n.setName( "XXXXX_CRAGI" );
4926             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4927                 return false;
4928             }
4929             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4930             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4931                 return false;
4932             }
4933             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4934             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4935                 return false;
4936             }
4937             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4938             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4939                 return false;
4940             }
4941             n = new PhylogenyNode();
4942             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4943             seq.setSymbol( "K1PYK7_CRAGI" );
4944             n.getNodeData().addSequence( seq );
4945             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4946                 return false;
4947             }
4948             seq.setSymbol( "tr|B3RJ64" );
4949             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4950                 return false;
4951             }
4952             n = new PhylogenyNode();
4953             seq = new org.forester.phylogeny.data.Sequence();
4954             seq.setName( "K1PYK7_CRAGI" );
4955             n.getNodeData().addSequence( seq );
4956             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4957                 return false;
4958             }
4959             seq.setName( "tr|B3RJ64" );
4960             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4961                 return false;
4962             }
4963             n = new PhylogenyNode();
4964             seq = new org.forester.phylogeny.data.Sequence();
4965             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4966             n.getNodeData().addSequence( seq );
4967             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4968                 return false;
4969             }
4970             n = new PhylogenyNode();
4971             seq = new org.forester.phylogeny.data.Sequence();
4972             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4973             n.getNodeData().addSequence( seq );
4974             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4975                 return false;
4976             }
4977             //
4978             n = new PhylogenyNode();
4979             n.setName( "ACP19736" );
4980             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4981                 return false;
4982             }
4983             n = new PhylogenyNode();
4984             n.setName( "|ACP19736|" );
4985             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4986                 return false;
4987             }
4988         }
4989         catch ( final Exception e ) {
4990             e.printStackTrace( System.out );
4991             return false;
4992         }
4993         return true;
4994     }
4995
4996     private static boolean testFastaParser() {
4997         try {
4998             FileInputStream fis1 = new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" );
4999             if ( !FastaParser.isLikelyFasta( fis1 ) ) {
5000                 fis1.close();
5001                 return false;
5002             }
5003             else {
5004                 fis1.close();
5005             }
5006             FileInputStream fis2 = new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" );
5007             if ( FastaParser.isLikelyFasta( fis2 ) ) {
5008                 fis2.close();
5009                 return false;
5010             }
5011             else {
5012                 fis2.close();
5013             }
5014             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
5015             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
5016                 return false;
5017             }
5018             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
5019                 return false;
5020             }
5021             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
5022                 return false;
5023             }
5024             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
5025                 return false;
5026             }
5027             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
5028                 return false;
5029             }
5030             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
5031                 return false;
5032             }
5033         }
5034         catch ( final Exception e ) {
5035             e.printStackTrace();
5036             return false;
5037         }
5038         return true;
5039     }
5040
5041     private static boolean testGenbankAccessorParsing() {
5042         //The format for GenBank Accession numbers are:
5043         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
5044         //Protein:    3 letters + 5 numerals
5045         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
5046         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
5047             return false;
5048         }
5049         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
5050             return false;
5051         }
5052         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
5053             return false;
5054         }
5055         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
5056             return false;
5057         }
5058         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
5059             return false;
5060         }
5061         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
5062             return false;
5063         }
5064         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
5065             return false;
5066         }
5067         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
5068             return false;
5069         }
5070         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
5071             return false;
5072         }
5073         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
5074             return false;
5075         }
5076         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
5077             return false;
5078         }
5079         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
5080             return false;
5081         }
5082         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
5083             return false;
5084         }
5085         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
5086             return false;
5087         }
5088         return true;
5089     }
5090
5091     private static boolean testGeneralMsaParser() {
5092         try {
5093             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
5094             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
5095             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
5096             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
5097             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
5098             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
5099             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
5100             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
5101             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5102                 return false;
5103             }
5104             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5105                 return false;
5106             }
5107             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5108                 return false;
5109             }
5110             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5111                 return false;
5112             }
5113             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5114                 return false;
5115             }
5116             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5117                 return false;
5118             }
5119             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5120                 return false;
5121             }
5122             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5123                 return false;
5124             }
5125             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5126                 return false;
5127             }
5128             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5129                 return false;
5130             }
5131             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5132                 return false;
5133             }
5134             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5135                 return false;
5136             }
5137             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5138             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5139                 return false;
5140             }
5141             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5142                 return false;
5143             }
5144             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5145                 return false;
5146             }
5147             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5148             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5149                 return false;
5150             }
5151             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5152                 return false;
5153             }
5154             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5155                 return false;
5156             }
5157             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5158             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5159                 return false;
5160             }
5161             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5162                 return false;
5163             }
5164             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5165                 return false;
5166             }
5167         }
5168         catch ( final Exception e ) {
5169             e.printStackTrace();
5170             return false;
5171         }
5172         return true;
5173     }
5174
5175     private static boolean testGeneralTable() {
5176         try {
5177             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5178             t0.setValue( 3, 2, "23" );
5179             t0.setValue( 10, 1, "error" );
5180             t0.setValue( 10, 1, "110" );
5181             t0.setValue( 9, 1, "19" );
5182             t0.setValue( 1, 10, "101" );
5183             t0.setValue( 10, 10, "1010" );
5184             t0.setValue( 100, 10, "10100" );
5185             t0.setValue( 0, 0, "00" );
5186             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5187                 return false;
5188             }
5189             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5190                 return false;
5191             }
5192             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5193                 return false;
5194             }
5195             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5196                 return false;
5197             }
5198             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5199                 return false;
5200             }
5201             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5202                 return false;
5203             }
5204             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5205                 return false;
5206             }
5207             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5208                 return false;
5209             }
5210             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5211                 return false;
5212             }
5213             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5214             t1.setValue( "3", "2", "23" );
5215             t1.setValue( "10", "1", "error" );
5216             t1.setValue( "10", "1", "110" );
5217             t1.setValue( "9", "1", "19" );
5218             t1.setValue( "1", "10", "101" );
5219             t1.setValue( "10", "10", "1010" );
5220             t1.setValue( "100", "10", "10100" );
5221             t1.setValue( "0", "0", "00" );
5222             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5223             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5224                 return false;
5225             }
5226             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5227                 return false;
5228             }
5229             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5230                 return false;
5231             }
5232             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5233                 return false;
5234             }
5235             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5236                 return false;
5237             }
5238             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5239                 return false;
5240             }
5241             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5242                 return false;
5243             }
5244             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5245                 return false;
5246             }
5247             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5248                 return false;
5249             }
5250             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5251                 return false;
5252             }
5253         }
5254         catch ( final Exception e ) {
5255             e.printStackTrace( System.out );
5256             return false;
5257         }
5258         return true;
5259     }
5260
5261     private static boolean testGetDistance() {
5262         try {
5263             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5264             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",
5265                                                  new NHXParser() )[ 0 ];
5266             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5267                 return false;
5268             }
5269             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5270                 return false;
5271             }
5272             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5273                 return false;
5274             }
5275             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5276                 return false;
5277             }
5278             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5279                 return false;
5280             }
5281             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5282                 return false;
5283             }
5284             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5285                 return false;
5286             }
5287             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5288                 return false;
5289             }
5290             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5291                 return false;
5292             }
5293             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5294                 return false;
5295             }
5296             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5297                 return false;
5298             }
5299             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5300                 return false;
5301             }
5302             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5303                 return false;
5304             }
5305             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5306                 return false;
5307             }
5308             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5309                 return false;
5310             }
5311             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5312                 return false;
5313             }
5314             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5315                 return false;
5316             }
5317             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5318                 return false;
5319             }
5320             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5321                 return false;
5322             }
5323             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5324                 return false;
5325             }
5326             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5327                 return false;
5328             }
5329             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5330                 return false;
5331             }
5332             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5333                 return false;
5334             }
5335             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5336                 return false;
5337             }
5338             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5339                 return false;
5340             }
5341             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5342                 return false;
5343             }
5344             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5345                 return false;
5346             }
5347             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5348                 return false;
5349             }
5350             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5351                 return false;
5352             }
5353             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5354                 return false;
5355             }
5356             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5357                 return false;
5358             }
5359             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",
5360                                                  new NHXParser() )[ 0 ];
5361             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5362                 return false;
5363             }
5364             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5365                 return false;
5366             }
5367             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5368                 return false;
5369             }
5370             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5371                 return false;
5372             }
5373             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5374                 return false;
5375             }
5376             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5377                 return false;
5378             }
5379             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5380                 return false;
5381             }
5382             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5383                 return false;
5384             }
5385             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5386                 return false;
5387             }
5388             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5389                 return false;
5390             }
5391             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5392                 return false;
5393             }
5394         }
5395         catch ( final Exception e ) {
5396             e.printStackTrace( System.out );
5397             return false;
5398         }
5399         return true;
5400     }
5401
5402     private static boolean testGetLCA() {
5403         try {
5404             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5405             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5406                                                  new NHXParser() )[ 0 ];
5407             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5408             if ( !A.getName().equals( "A" ) ) {
5409                 return false;
5410             }
5411             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5412             if ( !gh.getName().equals( "gh" ) ) {
5413                 return false;
5414             }
5415             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5416             if ( !ab.getName().equals( "ab" ) ) {
5417                 return false;
5418             }
5419             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5420             if ( !ab2.getName().equals( "ab" ) ) {
5421                 return false;
5422             }
5423             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5424             if ( !gh2.getName().equals( "gh" ) ) {
5425                 return false;
5426             }
5427             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5428             if ( !gh3.getName().equals( "gh" ) ) {
5429                 return false;
5430             }
5431             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5432             if ( !abc.getName().equals( "abc" ) ) {
5433                 return false;
5434             }
5435             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5436             if ( !abc2.getName().equals( "abc" ) ) {
5437                 return false;
5438             }
5439             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5440             if ( !abcd.getName().equals( "abcd" ) ) {
5441                 return false;
5442             }
5443             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5444             if ( !abcd2.getName().equals( "abcd" ) ) {
5445                 return false;
5446             }
5447             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5448             if ( !abcdef.getName().equals( "abcdef" ) ) {
5449                 return false;
5450             }
5451             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5452             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5453                 return false;
5454             }
5455             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5456             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5457                 return false;
5458             }
5459             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5460             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5461                 return false;
5462             }
5463             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5464             if ( !abcde.getName().equals( "abcde" ) ) {
5465                 return false;
5466             }
5467             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5468             if ( !abcde2.getName().equals( "abcde" ) ) {
5469                 return false;
5470             }
5471             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5472             if ( !r.getName().equals( "abcdefgh" ) ) {
5473                 return false;
5474             }
5475             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5476             if ( !r2.getName().equals( "abcdefgh" ) ) {
5477                 return false;
5478             }
5479             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5480             if ( !r3.getName().equals( "abcdefgh" ) ) {
5481                 return false;
5482             }
5483             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5484             if ( !abcde3.getName().equals( "abcde" ) ) {
5485                 return false;
5486             }
5487             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5488             if ( !abcde4.getName().equals( "abcde" ) ) {
5489                 return false;
5490             }
5491             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5492             if ( !ab3.getName().equals( "ab" ) ) {
5493                 return false;
5494             }
5495             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5496             if ( !ab4.getName().equals( "ab" ) ) {
5497                 return false;
5498             }
5499             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5500             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5501             if ( !cd.getName().equals( "cd" ) ) {
5502                 return false;
5503             }
5504             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5505             if ( !cd2.getName().equals( "cd" ) ) {
5506                 return false;
5507             }
5508             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5509             if ( !cde.getName().equals( "cde" ) ) {
5510                 return false;
5511             }
5512             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5513             if ( !cde2.getName().equals( "cde" ) ) {
5514                 return false;
5515             }
5516             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5517             if ( !cdef.getName().equals( "cdef" ) ) {
5518                 return false;
5519             }
5520             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5521             if ( !cdef2.getName().equals( "cdef" ) ) {
5522                 return false;
5523             }
5524             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5525             if ( !cdef3.getName().equals( "cdef" ) ) {
5526                 return false;
5527             }
5528             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5529             if ( !rt.getName().equals( "r" ) ) {
5530                 return false;
5531             }
5532             final Phylogeny p3 = factory
5533                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5534                              new NHXParser() )[ 0 ];
5535             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5536             if ( !bc_3.getName().equals( "bc" ) ) {
5537                 return false;
5538             }
5539             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5540             if ( !ac_3.getName().equals( "abc" ) ) {
5541                 return false;
5542             }
5543             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5544             if ( !ad_3.getName().equals( "abcde" ) ) {
5545                 return false;
5546             }
5547             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5548             if ( !af_3.getName().equals( "abcdef" ) ) {
5549                 return false;
5550             }
5551             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5552             if ( !ag_3.getName().equals( "" ) ) {
5553                 return false;
5554             }
5555             if ( !ag_3.isRoot() ) {
5556                 return false;
5557             }
5558             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5559             if ( !al_3.getName().equals( "" ) ) {
5560                 return false;
5561             }
5562             if ( !al_3.isRoot() ) {
5563                 return false;
5564             }
5565             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5566             if ( !kl_3.getName().equals( "" ) ) {
5567                 return false;
5568             }
5569             if ( !kl_3.isRoot() ) {
5570                 return false;
5571             }
5572             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5573             if ( !fl_3.getName().equals( "" ) ) {
5574                 return false;
5575             }
5576             if ( !fl_3.isRoot() ) {
5577                 return false;
5578             }
5579             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5580             if ( !gk_3.getName().equals( "ghijk" ) ) {
5581                 return false;
5582             }
5583             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5584             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5585             if ( !r_4.getName().equals( "r" ) ) {
5586                 return false;
5587             }
5588             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5589             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5590             if ( !r_5.getName().equals( "root" ) ) {
5591                 return false;
5592             }
5593             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5594             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5595             if ( !r_6.getName().equals( "rot" ) ) {
5596                 return false;
5597             }
5598             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5599             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5600             if ( !r_7.getName().equals( "rott" ) ) {
5601                 return false;
5602             }
5603         }
5604         catch ( final Exception e ) {
5605             e.printStackTrace( System.out );
5606             return false;
5607         }
5608         return true;
5609     }
5610
5611     private static boolean testGetLCA2() {
5612         try {
5613             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5614             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5615             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5616             PhylogenyMethods.preOrderReId( p_a );
5617             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5618                                                                                               p_a.getNode( "a" ) );
5619             if ( !p_a_1.getName().equals( "a" ) ) {
5620                 return false;
5621             }
5622             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5623             PhylogenyMethods.preOrderReId( p_b );
5624             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5625                                                                                               p_b.getNode( "a" ) );
5626             if ( !p_b_1.getName().equals( "b" ) ) {
5627                 return false;
5628             }
5629             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5630                                                                                               p_b.getNode( "b" ) );
5631             if ( !p_b_2.getName().equals( "b" ) ) {
5632                 return false;
5633             }
5634             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5635             PhylogenyMethods.preOrderReId( p_c );
5636             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5637                                                                                               p_c.getNode( "a" ) );
5638             if ( !p_c_1.getName().equals( "b" ) ) {
5639                 return false;
5640             }
5641             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5642                                                                                               p_c.getNode( "c" ) );
5643             if ( !p_c_2.getName().equals( "c" ) ) {
5644                 System.out.println( p_c_2.getName() );
5645                 System.exit( -1 );
5646                 return false;
5647             }
5648             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5649                                                                                               p_c.getNode( "b" ) );
5650             if ( !p_c_3.getName().equals( "b" ) ) {
5651                 return false;
5652             }
5653             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5654                                                                                               p_c.getNode( "a" ) );
5655             if ( !p_c_4.getName().equals( "c" ) ) {
5656                 return false;
5657             }
5658             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5659                                                  new NHXParser() )[ 0 ];
5660             PhylogenyMethods.preOrderReId( p1 );
5661             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5662                                                                                           p1.getNode( "A" ) );
5663             if ( !A.getName().equals( "A" ) ) {
5664                 return false;
5665             }
5666             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5667                                                                                            p1.getNode( "gh" ) );
5668             if ( !gh.getName().equals( "gh" ) ) {
5669                 return false;
5670             }
5671             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5672                                                                                            p1.getNode( "B" ) );
5673             if ( !ab.getName().equals( "ab" ) ) {
5674                 return false;
5675             }
5676             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5677                                                                                             p1.getNode( "A" ) );
5678             if ( !ab2.getName().equals( "ab" ) ) {
5679                 return false;
5680             }
5681             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5682                                                                                             p1.getNode( "G" ) );
5683             if ( !gh2.getName().equals( "gh" ) ) {
5684                 return false;
5685             }
5686             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5687                                                                                             p1.getNode( "H" ) );
5688             if ( !gh3.getName().equals( "gh" ) ) {
5689                 return false;
5690             }
5691             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5692                                                                                             p1.getNode( "A" ) );
5693             if ( !abc.getName().equals( "abc" ) ) {
5694                 return false;
5695             }
5696             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5697                                                                                              p1.getNode( "C" ) );
5698             if ( !abc2.getName().equals( "abc" ) ) {
5699                 return false;
5700             }
5701             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5702                                                                                              p1.getNode( "D" ) );
5703             if ( !abcd.getName().equals( "abcd" ) ) {
5704                 return false;
5705             }
5706             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5707                                                                                               p1.getNode( "A" ) );
5708             if ( !abcd2.getName().equals( "abcd" ) ) {
5709                 return false;
5710             }
5711             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5712                                                                                                p1.getNode( "F" ) );
5713             if ( !abcdef.getName().equals( "abcdef" ) ) {
5714                 return false;
5715             }
5716             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5717                                                                                                 p1.getNode( "A" ) );
5718             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5719                 return false;
5720             }
5721             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5722                                                                                                 p1.getNode( "F" ) );
5723             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5724                 return false;
5725             }
5726             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5727                                                                                                 p1.getNode( "ab" ) );
5728             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5729                 return false;
5730             }
5731             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5732                                                                                               p1.getNode( "E" ) );
5733             if ( !abcde.getName().equals( "abcde" ) ) {
5734                 return false;
5735             }
5736             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5737                                                                                                p1.getNode( "A" ) );
5738             if ( !abcde2.getName().equals( "abcde" ) ) {
5739                 return false;
5740             }
5741             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5742                                                                                           p1.getNode( "abcdefgh" ) );
5743             if ( !r.getName().equals( "abcdefgh" ) ) {
5744                 return false;
5745             }
5746             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5747                                                                                            p1.getNode( "H" ) );
5748             if ( !r2.getName().equals( "abcdefgh" ) ) {
5749                 return false;
5750             }
5751             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5752                                                                                            p1.getNode( "A" ) );
5753             if ( !r3.getName().equals( "abcdefgh" ) ) {
5754                 return false;
5755             }
5756             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5757                                                                                                p1.getNode( "abcde" ) );
5758             if ( !abcde3.getName().equals( "abcde" ) ) {
5759                 return false;
5760             }
5761             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5762                                                                                                p1.getNode( "E" ) );
5763             if ( !abcde4.getName().equals( "abcde" ) ) {
5764                 return false;
5765             }
5766             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5767                                                                                             p1.getNode( "B" ) );
5768             if ( !ab3.getName().equals( "ab" ) ) {
5769                 return false;
5770             }
5771             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5772                                                                                             p1.getNode( "ab" ) );
5773             if ( !ab4.getName().equals( "ab" ) ) {
5774                 return false;
5775             }
5776             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5777             PhylogenyMethods.preOrderReId( p2 );
5778             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5779                                                                                            p2.getNode( "d" ) );
5780             if ( !cd.getName().equals( "cd" ) ) {
5781                 return false;
5782             }
5783             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5784                                                                                             p2.getNode( "c" ) );
5785             if ( !cd2.getName().equals( "cd" ) ) {
5786                 return false;
5787             }
5788             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5789                                                                                             p2.getNode( "e" ) );
5790             if ( !cde.getName().equals( "cde" ) ) {
5791                 return false;
5792             }
5793             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5794                                                                                              p2.getNode( "c" ) );
5795             if ( !cde2.getName().equals( "cde" ) ) {
5796                 return false;
5797             }
5798             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5799                                                                                              p2.getNode( "f" ) );
5800             if ( !cdef.getName().equals( "cdef" ) ) {
5801                 return false;
5802             }
5803             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5804                                                                                               p2.getNode( "f" ) );
5805             if ( !cdef2.getName().equals( "cdef" ) ) {
5806                 return false;
5807             }
5808             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5809                                                                                               p2.getNode( "d" ) );
5810             if ( !cdef3.getName().equals( "cdef" ) ) {
5811                 return false;
5812             }
5813             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5814                                                                                            p2.getNode( "a" ) );
5815             if ( !rt.getName().equals( "r" ) ) {
5816                 return false;
5817             }
5818             final Phylogeny p3 = factory
5819                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5820                              new NHXParser() )[ 0 ];
5821             PhylogenyMethods.preOrderReId( p3 );
5822             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5823                                                                                              p3.getNode( "c" ) );
5824             if ( !bc_3.getName().equals( "bc" ) ) {
5825                 return false;
5826             }
5827             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5828                                                                                              p3.getNode( "c" ) );
5829             if ( !ac_3.getName().equals( "abc" ) ) {
5830                 return false;
5831             }
5832             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5833                                                                                              p3.getNode( "d" ) );
5834             if ( !ad_3.getName().equals( "abcde" ) ) {
5835                 return false;
5836             }
5837             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5838                                                                                              p3.getNode( "f" ) );
5839             if ( !af_3.getName().equals( "abcdef" ) ) {
5840                 return false;
5841             }
5842             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5843                                                                                              p3.getNode( "g" ) );
5844             if ( !ag_3.getName().equals( "" ) ) {
5845                 return false;
5846             }
5847             if ( !ag_3.isRoot() ) {
5848                 return false;
5849             }
5850             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5851                                                                                              p3.getNode( "l" ) );
5852             if ( !al_3.getName().equals( "" ) ) {
5853                 return false;
5854             }
5855             if ( !al_3.isRoot() ) {
5856                 return false;
5857             }
5858             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5859                                                                                              p3.getNode( "l" ) );
5860             if ( !kl_3.getName().equals( "" ) ) {
5861                 return false;
5862             }
5863             if ( !kl_3.isRoot() ) {
5864                 return false;
5865             }
5866             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5867                                                                                              p3.getNode( "l" ) );
5868             if ( !fl_3.getName().equals( "" ) ) {
5869                 return false;
5870             }
5871             if ( !fl_3.isRoot() ) {
5872                 return false;
5873             }
5874             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5875                                                                                              p3.getNode( "k" ) );
5876             if ( !gk_3.getName().equals( "ghijk" ) ) {
5877                 return false;
5878             }
5879             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5880             PhylogenyMethods.preOrderReId( p4 );
5881             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5882                                                                                             p4.getNode( "c" ) );
5883             if ( !r_4.getName().equals( "r" ) ) {
5884                 return false;
5885             }
5886             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5887             PhylogenyMethods.preOrderReId( p5 );
5888             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5889                                                                                             p5.getNode( "c" ) );
5890             if ( !r_5.getName().equals( "root" ) ) {
5891                 return false;
5892             }
5893             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5894             PhylogenyMethods.preOrderReId( p6 );
5895             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5896                                                                                             p6.getNode( "a" ) );
5897             if ( !r_6.getName().equals( "rot" ) ) {
5898                 return false;
5899             }
5900             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5901             PhylogenyMethods.preOrderReId( p7 );
5902             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5903                                                                                             p7.getNode( "e" ) );
5904             if ( !r_7.getName().equals( "rott" ) ) {
5905                 return false;
5906             }
5907             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5908                                                                                              p7.getNode( "a" ) );
5909             if ( !r_71.getName().equals( "rott" ) ) {
5910                 return false;
5911             }
5912             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5913                                                                                              p7.getNode( "rott" ) );
5914             if ( !r_72.getName().equals( "rott" ) ) {
5915                 return false;
5916             }
5917             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5918                                                                                              p7.getNode( "a" ) );
5919             if ( !r_73.getName().equals( "rott" ) ) {
5920                 return false;
5921             }
5922             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5923                                                                                              p7.getNode( "rott" ) );
5924             if ( !r_74.getName().equals( "rott" ) ) {
5925                 return false;
5926             }
5927             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5928                                                                                              p7.getNode( "e" ) );
5929             if ( !r_75.getName().equals( "e" ) ) {
5930                 return false;
5931             }
5932         }
5933         catch ( final Exception e ) {
5934             e.printStackTrace( System.out );
5935             return false;
5936         }
5937         return true;
5938     }
5939
5940     private static boolean testHmmscanOutputParser() {
5941         final String test_dir = Test.PATH_TO_TEST_DATA;
5942         try {
5943             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5944                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5945             parser1.parse();
5946             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5947                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5948             final List<Protein> proteins = parser2.parse();
5949             if ( parser2.getProteinsEncountered() != 4 ) {
5950                 return false;
5951             }
5952             if ( proteins.size() != 4 ) {
5953                 return false;
5954             }
5955             if ( parser2.getDomainsEncountered() != 69 ) {
5956                 return false;
5957             }
5958             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5959                 return false;
5960             }
5961             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5962                 return false;
5963             }
5964             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5965                 return false;
5966             }
5967             final Protein p1 = proteins.get( 0 );
5968             if ( p1.getNumberOfProteinDomains() != 15 ) {
5969                 return false;
5970             }
5971             if ( p1.getLength() != 850 ) {
5972                 return false;
5973             }
5974             final Protein p2 = proteins.get( 1 );
5975             if ( p2.getNumberOfProteinDomains() != 51 ) {
5976                 return false;
5977             }
5978             if ( p2.getLength() != 1291 ) {
5979                 return false;
5980             }
5981             final Protein p3 = proteins.get( 2 );
5982             if ( p3.getNumberOfProteinDomains() != 2 ) {
5983                 return false;
5984             }
5985             final Protein p4 = proteins.get( 3 );
5986             if ( p4.getNumberOfProteinDomains() != 1 ) {
5987                 return false;
5988             }
5989             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5990                 return false;
5991             }
5992             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5993                 return false;
5994             }
5995             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5996                 return false;
5997             }
5998             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5999                 return false;
6000             }
6001             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
6002                 return false;
6003             }
6004             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
6005                 return false;
6006             }
6007             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
6008                 return false;
6009             }
6010         }
6011         catch ( final Exception e ) {
6012             e.printStackTrace( System.out );
6013             return false;
6014         }
6015         return true;
6016     }
6017
6018     private static boolean testLastExternalNodeMethods() {
6019         try {
6020             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6021             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
6022             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
6023             final PhylogenyNode n1 = t0.getNode( "A" );
6024             if ( n1.isLastExternalNode() ) {
6025                 return false;
6026             }
6027             final PhylogenyNode n2 = t0.getNode( "B" );
6028             if ( n2.isLastExternalNode() ) {
6029                 return false;
6030             }
6031             final PhylogenyNode n3 = t0.getNode( "C" );
6032             if ( n3.isLastExternalNode() ) {
6033                 return false;
6034             }
6035             final PhylogenyNode n4 = t0.getNode( "D" );
6036             if ( !n4.isLastExternalNode() ) {
6037                 return false;
6038             }
6039         }
6040         catch ( final Exception e ) {
6041             e.printStackTrace( System.out );
6042             return false;
6043         }
6044         return true;
6045     }
6046
6047     private static boolean testLevelOrderIterator() {
6048         try {
6049             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6050             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
6051             PhylogenyNodeIterator it0;
6052             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
6053                 it0.next();
6054             }
6055             for( it0.reset(); it0.hasNext(); ) {
6056                 it0.next();
6057             }
6058             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
6059             if ( !it.next().getName().equals( "r" ) ) {
6060                 return false;
6061             }
6062             if ( !it.next().getName().equals( "ab" ) ) {
6063                 return false;
6064             }
6065             if ( !it.next().getName().equals( "cd" ) ) {
6066                 return false;
6067             }
6068             if ( !it.next().getName().equals( "A" ) ) {
6069                 return false;
6070             }
6071             if ( !it.next().getName().equals( "B" ) ) {
6072                 return false;
6073             }
6074             if ( !it.next().getName().equals( "C" ) ) {
6075                 return false;
6076             }
6077             if ( !it.next().getName().equals( "D" ) ) {
6078                 return false;
6079             }
6080             if ( it.hasNext() ) {
6081                 return false;
6082             }
6083             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",
6084                                                  new NHXParser() )[ 0 ];
6085             PhylogenyNodeIterator it2;
6086             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
6087                 it2.next();
6088             }
6089             for( it2.reset(); it2.hasNext(); ) {
6090                 it2.next();
6091             }
6092             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
6093             if ( !it3.next().getName().equals( "r" ) ) {
6094                 return false;
6095             }
6096             if ( !it3.next().getName().equals( "abc" ) ) {
6097                 return false;
6098             }
6099             if ( !it3.next().getName().equals( "defg" ) ) {
6100                 return false;
6101             }
6102             if ( !it3.next().getName().equals( "A" ) ) {
6103                 return false;
6104             }
6105             if ( !it3.next().getName().equals( "B" ) ) {
6106                 return false;
6107             }
6108             if ( !it3.next().getName().equals( "C" ) ) {
6109                 return false;
6110             }
6111             if ( !it3.next().getName().equals( "D" ) ) {
6112                 return false;
6113             }
6114             if ( !it3.next().getName().equals( "E" ) ) {
6115                 return false;
6116             }
6117             if ( !it3.next().getName().equals( "F" ) ) {
6118                 return false;
6119             }
6120             if ( !it3.next().getName().equals( "G" ) ) {
6121                 return false;
6122             }
6123             if ( !it3.next().getName().equals( "1" ) ) {
6124                 return false;
6125             }
6126             if ( !it3.next().getName().equals( "2" ) ) {
6127                 return false;
6128             }
6129             if ( !it3.next().getName().equals( "3" ) ) {
6130                 return false;
6131             }
6132             if ( !it3.next().getName().equals( "4" ) ) {
6133                 return false;
6134             }
6135             if ( !it3.next().getName().equals( "5" ) ) {
6136                 return false;
6137             }
6138             if ( !it3.next().getName().equals( "6" ) ) {
6139                 return false;
6140             }
6141             if ( !it3.next().getName().equals( "f1" ) ) {
6142                 return false;
6143             }
6144             if ( !it3.next().getName().equals( "f2" ) ) {
6145                 return false;
6146             }
6147             if ( !it3.next().getName().equals( "f3" ) ) {
6148                 return false;
6149             }
6150             if ( !it3.next().getName().equals( "a" ) ) {
6151                 return false;
6152             }
6153             if ( !it3.next().getName().equals( "b" ) ) {
6154                 return false;
6155             }
6156             if ( !it3.next().getName().equals( "f21" ) ) {
6157                 return false;
6158             }
6159             if ( !it3.next().getName().equals( "X" ) ) {
6160                 return false;
6161             }
6162             if ( !it3.next().getName().equals( "Y" ) ) {
6163                 return false;
6164             }
6165             if ( !it3.next().getName().equals( "Z" ) ) {
6166                 return false;
6167             }
6168             if ( it3.hasNext() ) {
6169                 return false;
6170             }
6171             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6172             PhylogenyNodeIterator it4;
6173             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6174                 it4.next();
6175             }
6176             for( it4.reset(); it4.hasNext(); ) {
6177                 it4.next();
6178             }
6179             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6180             if ( !it5.next().getName().equals( "r" ) ) {
6181                 return false;
6182             }
6183             if ( !it5.next().getName().equals( "A" ) ) {
6184                 return false;
6185             }
6186             if ( !it5.next().getName().equals( "B" ) ) {
6187                 return false;
6188             }
6189             if ( !it5.next().getName().equals( "C" ) ) {
6190                 return false;
6191             }
6192             if ( !it5.next().getName().equals( "D" ) ) {
6193                 return false;
6194             }
6195             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6196             PhylogenyNodeIterator it6;
6197             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6198                 it6.next();
6199             }
6200             for( it6.reset(); it6.hasNext(); ) {
6201                 it6.next();
6202             }
6203             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6204             if ( !it7.next().getName().equals( "A" ) ) {
6205                 return false;
6206             }
6207             if ( it.hasNext() ) {
6208                 return false;
6209             }
6210         }
6211         catch ( final Exception e ) {
6212             e.printStackTrace( System.out );
6213             return false;
6214         }
6215         return true;
6216     }
6217
6218     private static boolean testMafft( final String path ) {
6219         try {
6220             final List<String> opts = new ArrayList<String>();
6221             opts.add( "--maxiterate" );
6222             opts.add( "1000" );
6223             opts.add( "--localpair" );
6224             opts.add( "--quiet" );
6225             Msa msa = null;
6226             final MsaInferrer mafft = Mafft.createInstance( path );
6227             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6228             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6229                 return false;
6230             }
6231             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6232                 return false;
6233             }
6234         }
6235         catch ( final Exception e ) {
6236             e.printStackTrace( System.out );
6237             return false;
6238         }
6239         return true;
6240     }
6241
6242     private static boolean testMidpointrooting() {
6243         try {
6244             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6245             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6246             PhylogenyMethods.midpointRoot( t0 );
6247             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6248                 return false;
6249             }
6250             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6251                 return false;
6252             }
6253             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6254                            1 ) ) {
6255                 return false;
6256             }
6257             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",
6258                                                  new NHXParser() )[ 0 ];
6259             if ( !t1.isRooted() ) {
6260                 return false;
6261             }
6262             PhylogenyMethods.midpointRoot( t1 );
6263             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6264                 return false;
6265             }
6266             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6267                 return false;
6268             }
6269             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6270                 return false;
6271             }
6272             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6273                 return false;
6274             }
6275             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6276                 return false;
6277             }
6278             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6279                 return false;
6280             }
6281             t1.reRoot( t1.getNode( "A" ) );
6282             PhylogenyMethods.midpointRoot( t1 );
6283             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6284                 return false;
6285             }
6286             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6287                 return false;
6288             }
6289             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6290                 return false;
6291             }
6292             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6293                 return false;
6294             }
6295             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6296                 System.exit( -1 );
6297                 return false;
6298             }
6299             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6300                 return false;
6301             }
6302         }
6303         catch ( final Exception e ) {
6304             e.printStackTrace( System.out );
6305             return false;
6306         }
6307         return true;
6308     }
6309
6310     private static boolean testMsaQualityMethod() {
6311         try {
6312             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6313             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6314             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6315             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6316             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6317             l.add( s0 );
6318             l.add( s1 );
6319             l.add( s2 );
6320             l.add( s3 );
6321             final Msa msa = BasicMsa.createInstance( l );
6322             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6323                 return false;
6324             }
6325             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6326                 return false;
6327             }
6328             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6329                 return false;
6330             }
6331             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6332                 return false;
6333             }
6334             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6335                 return false;
6336             }
6337             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6338                 return false;
6339             }
6340             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6341                 return false;
6342             }
6343         }
6344         catch ( final Exception e ) {
6345             e.printStackTrace( System.out );
6346             return false;
6347         }
6348         return true;
6349     }
6350
6351     private static boolean testMsaEntropy() {
6352         try {
6353             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6354             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6355             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6356             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6357             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6358             l.add( s0 );
6359             l.add( s1 );
6360             l.add( s2 );
6361             l.add( s3 );
6362             final Msa msa = BasicMsa.createInstance( l );
6363             //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6364             //FIXME
6365             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6366             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6367             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6368             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6369             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6370             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6371             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6372             //            System.out.println();
6373             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6374             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6375             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6376             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6377             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6378             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6379             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6380             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6381             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6382             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6383             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6384             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6385             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6386             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6387             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6388             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6389             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6390             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6391             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6392             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6393             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6394             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6395             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6396             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6397             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6398             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6399             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6400             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6401             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6402             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6403             final Msa msa2 = BasicMsa.createInstance( l2 );
6404             //            System.out.println();
6405             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6406             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6407             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6408         }
6409         catch ( final Exception e ) {
6410             e.printStackTrace( System.out );
6411             return false;
6412         }
6413         return true;
6414     }
6415
6416     private static boolean testDeleteableMsa() {
6417         try {
6418             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6419             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6420             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6421             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6422             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6423             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6424             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6425             l0.add( s0 );
6426             l0.add( s1 );
6427             l0.add( s2 );
6428             l0.add( s3 );
6429             l0.add( s4 );
6430             l0.add( s5 );
6431             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6432             dmsa0.deleteRow( "b", false );
6433             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6434                 return false;
6435             }
6436             dmsa0.deleteRow( "e", false );
6437             dmsa0.deleteRow( "a", false );
6438             dmsa0.deleteRow( "f", false );
6439             if ( dmsa0.getLength() != 4 ) {
6440                 return false;
6441             }
6442             if ( dmsa0.getNumberOfSequences() != 2 ) {
6443                 return false;
6444             }
6445             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6446                 return false;
6447             }
6448             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6449                 return false;
6450             }
6451             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6452                 return false;
6453             }
6454             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6455                 return false;
6456             }
6457             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6458                 return false;
6459             }
6460             dmsa0.deleteRow( "c", false );
6461             dmsa0.deleteRow( "d", false );
6462             if ( dmsa0.getNumberOfSequences() != 0 ) {
6463                 return false;
6464             }
6465             //
6466             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6467             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6468             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6469             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6470             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6471             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6472             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6473             l1.add( s_0 );
6474             l1.add( s_1 );
6475             l1.add( s_2 );
6476             l1.add( s_3 );
6477             l1.add( s_4 );
6478             l1.add( s_5 );
6479             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6480             dmsa1.deleteGapOnlyColumns();
6481             dmsa1.deleteRow( "a", false );
6482             dmsa1.deleteRow( "f", false );
6483             dmsa1.deleteRow( "d", false );
6484             dmsa1.deleteGapOnlyColumns();
6485             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6486                 return false;
6487             }
6488             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6489                 return false;
6490             }
6491             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6492                 return false;
6493             }
6494             dmsa1.deleteRow( "c", false );
6495             dmsa1.deleteGapOnlyColumns();
6496             final Writer w0 = new StringWriter();
6497             dmsa1.write( w0, MSA_FORMAT.FASTA );
6498             final Writer w1 = new StringWriter();
6499             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6500             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6501                 return false;
6502             }
6503             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6504                 return false;
6505             }
6506             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6507             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6508             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6509             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6510             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6511             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6512             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6513             l2.add( s__0 );
6514             l2.add( s__1 );
6515             l2.add( s__2 );
6516             l2.add( s__3 );
6517             l2.add( s__4 );
6518             l2.add( s__5 );
6519             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6520             dmsa2.deleteGapColumns( 0.5 );
6521             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6522                 return false;
6523             }
6524             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6525                 return false;
6526             }
6527             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6528                 return false;
6529             }
6530             dmsa2.deleteGapColumns( 0.2 );
6531             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6532                 return false;
6533             }
6534             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6535                 return false;
6536             }
6537             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6538                 return false;
6539             }
6540             dmsa2.deleteGapColumns( 0 );
6541             dmsa2.deleteRow( "a", false );
6542             dmsa2.deleteRow( "b", false );
6543             dmsa2.deleteRow( "f", false );
6544             dmsa2.deleteRow( "e", false );
6545             dmsa2.setIdentifier( 0, "new_c" );
6546             dmsa2.setIdentifier( 1, "new_d" );
6547             dmsa2.setResidueAt( 0, 0, 'x' );
6548             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6549             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6550                 return false;
6551             }
6552             final Writer w = new StringWriter();
6553             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6554             final String phylip = w.toString();
6555             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6556                 System.out.println( phylip );
6557                 return false;
6558             }
6559             final Writer w2 = new StringWriter();
6560             dmsa2.write( w2, MSA_FORMAT.FASTA );
6561             final String fasta = w2.toString();
6562             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6563                 System.out.println( fasta );
6564                 return false;
6565             }
6566         }
6567         catch ( final Exception e ) {
6568             e.printStackTrace( System.out );
6569             return false;
6570         }
6571         return true;
6572     }
6573
6574     private static boolean testNextNodeWithCollapsing() {
6575         try {
6576             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6577             PhylogenyNode n;
6578             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6579             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6580             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6581             t0.getNode( "cd" ).setCollapse( true );
6582             t0.getNode( "cde" ).setCollapse( true );
6583             n = t0.getFirstExternalNode();
6584             while ( n != null ) {
6585                 ext.add( n );
6586                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6587             }
6588             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6589                 return false;
6590             }
6591             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6592                 return false;
6593             }
6594             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6595                 return false;
6596             }
6597             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6598                 return false;
6599             }
6600             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6601                 return false;
6602             }
6603             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6604                 return false;
6605             }
6606             ext.clear();
6607             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6608             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6609             t1.getNode( "ab" ).setCollapse( true );
6610             t1.getNode( "cd" ).setCollapse( true );
6611             t1.getNode( "cde" ).setCollapse( true );
6612             n = t1.getNode( "ab" );
6613             ext = new ArrayList<PhylogenyNode>();
6614             while ( n != null ) {
6615                 ext.add( n );
6616                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6617             }
6618             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6619                 return false;
6620             }
6621             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6622                 return false;
6623             }
6624             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6625                 return false;
6626             }
6627             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6628                 return false;
6629             }
6630             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6631                 return false;
6632             }
6633             ext.clear();
6634             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6635             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6636             t2.getNode( "ab" ).setCollapse( true );
6637             t2.getNode( "cd" ).setCollapse( true );
6638             t2.getNode( "cde" ).setCollapse( true );
6639             t2.getNode( "c" ).setCollapse( true );
6640             t2.getNode( "d" ).setCollapse( true );
6641             t2.getNode( "e" ).setCollapse( true );
6642             t2.getNode( "gh" ).setCollapse( true );
6643             n = t2.getNode( "ab" );
6644             ext = new ArrayList<PhylogenyNode>();
6645             while ( n != null ) {
6646                 ext.add( n );
6647                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6648             }
6649             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6650                 return false;
6651             }
6652             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6653                 return false;
6654             }
6655             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6656                 return false;
6657             }
6658             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6659                 return false;
6660             }
6661             ext.clear();
6662             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6663             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6664             t3.getNode( "ab" ).setCollapse( true );
6665             t3.getNode( "cd" ).setCollapse( true );
6666             t3.getNode( "cde" ).setCollapse( true );
6667             t3.getNode( "c" ).setCollapse( true );
6668             t3.getNode( "d" ).setCollapse( true );
6669             t3.getNode( "e" ).setCollapse( true );
6670             t3.getNode( "gh" ).setCollapse( true );
6671             t3.getNode( "fgh" ).setCollapse( true );
6672             n = t3.getNode( "ab" );
6673             ext = new ArrayList<PhylogenyNode>();
6674             while ( n != null ) {
6675                 ext.add( n );
6676                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6677             }
6678             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6679                 return false;
6680             }
6681             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6682                 return false;
6683             }
6684             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6685                 return false;
6686             }
6687             ext.clear();
6688             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6689             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6690             t4.getNode( "ab" ).setCollapse( true );
6691             t4.getNode( "cd" ).setCollapse( true );
6692             t4.getNode( "cde" ).setCollapse( true );
6693             t4.getNode( "c" ).setCollapse( true );
6694             t4.getNode( "d" ).setCollapse( true );
6695             t4.getNode( "e" ).setCollapse( true );
6696             t4.getNode( "gh" ).setCollapse( true );
6697             t4.getNode( "fgh" ).setCollapse( true );
6698             t4.getNode( "abcdefgh" ).setCollapse( true );
6699             n = t4.getNode( "abcdefgh" );
6700             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6701                 return false;
6702             }
6703             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6704             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6705             ext.clear();
6706             n = t5.getFirstExternalNode();
6707             while ( n != null ) {
6708                 ext.add( n );
6709                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6710             }
6711             if ( ext.size() != 8 ) {
6712                 return false;
6713             }
6714             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6715                 return false;
6716             }
6717             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6718                 return false;
6719             }
6720             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6721                 return false;
6722             }
6723             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6724                 return false;
6725             }
6726             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6727                 return false;
6728             }
6729             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6730                 return false;
6731             }
6732             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6733                 return false;
6734             }
6735             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6736                 return false;
6737             }
6738             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6739             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6740             ext.clear();
6741             t6.getNode( "ab" ).setCollapse( true );
6742             n = t6.getNode( "ab" );
6743             while ( n != null ) {
6744                 ext.add( n );
6745                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6746             }
6747             if ( ext.size() != 7 ) {
6748                 return false;
6749             }
6750             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6751                 return false;
6752             }
6753             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6754                 return false;
6755             }
6756             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6757                 return false;
6758             }
6759             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6760                 return false;
6761             }
6762             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6763                 return false;
6764             }
6765             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6766                 return false;
6767             }
6768             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6769                 return false;
6770             }
6771             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6772             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6773             ext.clear();
6774             t7.getNode( "cd" ).setCollapse( true );
6775             n = t7.getNode( "a" );
6776             while ( n != null ) {
6777                 ext.add( n );
6778                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6779             }
6780             if ( ext.size() != 7 ) {
6781                 return false;
6782             }
6783             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6784                 return false;
6785             }
6786             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6787                 return false;
6788             }
6789             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6790                 return false;
6791             }
6792             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6793                 return false;
6794             }
6795             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6796                 return false;
6797             }
6798             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6799                 return false;
6800             }
6801             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6802                 return false;
6803             }
6804             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6805             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6806             ext.clear();
6807             t8.getNode( "cd" ).setCollapse( true );
6808             t8.getNode( "c" ).setCollapse( true );
6809             t8.getNode( "d" ).setCollapse( true );
6810             n = t8.getNode( "a" );
6811             while ( n != null ) {
6812                 ext.add( n );
6813                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6814             }
6815             if ( ext.size() != 7 ) {
6816                 return false;
6817             }
6818             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6819                 return false;
6820             }
6821             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6822                 return false;
6823             }
6824             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6825                 System.out.println( "2 fail" );
6826                 return false;
6827             }
6828             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6829                 return false;
6830             }
6831             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6832                 return false;
6833             }
6834             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6835                 return false;
6836             }
6837             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6838                 return false;
6839             }
6840             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6841             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6842             ext.clear();
6843             t9.getNode( "gh" ).setCollapse( true );
6844             n = t9.getNode( "a" );
6845             while ( n != null ) {
6846                 ext.add( n );
6847                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6848             }
6849             if ( ext.size() != 7 ) {
6850                 return false;
6851             }
6852             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6853                 return false;
6854             }
6855             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6856                 return false;
6857             }
6858             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6859                 return false;
6860             }
6861             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6862                 return false;
6863             }
6864             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6865                 return false;
6866             }
6867             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6868                 return false;
6869             }
6870             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6871                 return false;
6872             }
6873             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6874             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6875             ext.clear();
6876             t10.getNode( "gh" ).setCollapse( true );
6877             t10.getNode( "g" ).setCollapse( true );
6878             t10.getNode( "h" ).setCollapse( true );
6879             n = t10.getNode( "a" );
6880             while ( n != null ) {
6881                 ext.add( n );
6882                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6883             }
6884             if ( ext.size() != 7 ) {
6885                 return false;
6886             }
6887             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6888                 return false;
6889             }
6890             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6891                 return false;
6892             }
6893             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6894                 return false;
6895             }
6896             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6897                 return false;
6898             }
6899             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6900                 return false;
6901             }
6902             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6903                 return false;
6904             }
6905             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6906                 return false;
6907             }
6908             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6909             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6910             ext.clear();
6911             t11.getNode( "gh" ).setCollapse( true );
6912             t11.getNode( "fgh" ).setCollapse( true );
6913             n = t11.getNode( "a" );
6914             while ( n != null ) {
6915                 ext.add( n );
6916                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6917             }
6918             if ( ext.size() != 6 ) {
6919                 return false;
6920             }
6921             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6922                 return false;
6923             }
6924             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6925                 return false;
6926             }
6927             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6928                 return false;
6929             }
6930             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6931                 return false;
6932             }
6933             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6934                 return false;
6935             }
6936             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6937                 return false;
6938             }
6939             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6940             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6941             ext.clear();
6942             t12.getNode( "gh" ).setCollapse( true );
6943             t12.getNode( "fgh" ).setCollapse( true );
6944             t12.getNode( "g" ).setCollapse( true );
6945             t12.getNode( "h" ).setCollapse( true );
6946             t12.getNode( "f" ).setCollapse( true );
6947             n = t12.getNode( "a" );
6948             while ( n != null ) {
6949                 ext.add( n );
6950                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6951             }
6952             if ( ext.size() != 6 ) {
6953                 return false;
6954             }
6955             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6956                 return false;
6957             }
6958             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6959                 return false;
6960             }
6961             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6962                 return false;
6963             }
6964             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6965                 return false;
6966             }
6967             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6968                 return false;
6969             }
6970             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6971                 return false;
6972             }
6973             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6974             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6975             ext.clear();
6976             t13.getNode( "ab" ).setCollapse( true );
6977             t13.getNode( "b" ).setCollapse( true );
6978             t13.getNode( "fgh" ).setCollapse( true );
6979             t13.getNode( "gh" ).setCollapse( true );
6980             n = t13.getNode( "ab" );
6981             while ( n != null ) {
6982                 ext.add( n );
6983                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6984             }
6985             if ( ext.size() != 5 ) {
6986                 return false;
6987             }
6988             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6989                 return false;
6990             }
6991             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6992                 return false;
6993             }
6994             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6995                 return false;
6996             }
6997             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6998                 return false;
6999             }
7000             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7001                 return false;
7002             }
7003             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
7004             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
7005             ext.clear();
7006             t14.getNode( "ab" ).setCollapse( true );
7007             t14.getNode( "a" ).setCollapse( true );
7008             t14.getNode( "fgh" ).setCollapse( true );
7009             t14.getNode( "gh" ).setCollapse( true );
7010             n = t14.getNode( "ab" );
7011             while ( n != null ) {
7012                 ext.add( n );
7013                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7014             }
7015             if ( ext.size() != 5 ) {
7016                 return false;
7017             }
7018             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7019                 return false;
7020             }
7021             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7022                 return false;
7023             }
7024             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7025                 return false;
7026             }
7027             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7028                 return false;
7029             }
7030             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7031                 return false;
7032             }
7033             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" );
7034             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
7035             ext.clear();
7036             t15.getNode( "ab" ).setCollapse( true );
7037             t15.getNode( "a" ).setCollapse( true );
7038             t15.getNode( "fgh" ).setCollapse( true );
7039             t15.getNode( "gh" ).setCollapse( true );
7040             n = t15.getNode( "ab" );
7041             while ( n != null ) {
7042                 ext.add( n );
7043                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7044             }
7045             if ( ext.size() != 6 ) {
7046                 return false;
7047             }
7048             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7049                 return false;
7050             }
7051             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7052                 return false;
7053             }
7054             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7055                 return false;
7056             }
7057             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7058                 return false;
7059             }
7060             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
7061                 return false;
7062             }
7063             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7064                 return false;
7065             }
7066             //
7067             //
7068             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" );
7069             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
7070             ext.clear();
7071             t16.getNode( "ab" ).setCollapse( true );
7072             t16.getNode( "a" ).setCollapse( true );
7073             t16.getNode( "fgh" ).setCollapse( true );
7074             t16.getNode( "gh" ).setCollapse( true );
7075             t16.getNode( "cd" ).setCollapse( true );
7076             t16.getNode( "cde" ).setCollapse( true );
7077             t16.getNode( "d" ).setCollapse( true );
7078             t16.getNode( "x" ).setCollapse( true );
7079             n = t16.getNode( "ab" );
7080             while ( n != null ) {
7081                 ext.add( n );
7082                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7083             }
7084             if ( ext.size() != 4 ) {
7085                 return false;
7086             }
7087             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7088                 return false;
7089             }
7090             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7091                 return false;
7092             }
7093             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
7094                 return false;
7095             }
7096             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
7097                 return false;
7098             }
7099         }
7100         catch ( final Exception e ) {
7101             e.printStackTrace( System.out );
7102             return false;
7103         }
7104         return true;
7105     }
7106
7107     private static boolean testNexusCharactersParsing() {
7108         try {
7109             final NexusCharactersParser parser = new NexusCharactersParser();
7110             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
7111             parser.parse();
7112             String[] labels = parser.getCharStateLabels();
7113             if ( labels.length != 7 ) {
7114                 return false;
7115             }
7116             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7117                 return false;
7118             }
7119             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7120                 return false;
7121             }
7122             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7123                 return false;
7124             }
7125             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7126                 return false;
7127             }
7128             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7129                 return false;
7130             }
7131             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7132                 return false;
7133             }
7134             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7135                 return false;
7136             }
7137             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7138             parser.parse();
7139             labels = parser.getCharStateLabels();
7140             if ( labels.length != 7 ) {
7141                 return false;
7142             }
7143             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7144                 return false;
7145             }
7146             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7147                 return false;
7148             }
7149             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7150                 return false;
7151             }
7152             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7153                 return false;
7154             }
7155             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7156                 return false;
7157             }
7158             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7159                 return false;
7160             }
7161             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7162                 return false;
7163             }
7164         }
7165         catch ( final Exception e ) {
7166             e.printStackTrace( System.out );
7167             return false;
7168         }
7169         return true;
7170     }
7171
7172     private static boolean testNexusMatrixParsing() {
7173         try {
7174             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7175             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7176             parser.parse();
7177             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7178             if ( m.getNumberOfCharacters() != 9 ) {
7179                 return false;
7180             }
7181             if ( m.getNumberOfIdentifiers() != 5 ) {
7182                 return false;
7183             }
7184             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7185                 return false;
7186             }
7187             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7188                 return false;
7189             }
7190             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7191                 return false;
7192             }
7193             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7194                 return false;
7195             }
7196             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7197                 return false;
7198             }
7199             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7200                 return false;
7201             }
7202             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7203                 return false;
7204             }
7205             //            if ( labels.length != 7 ) {
7206             //                return false;
7207             //            }
7208             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7209             //                return false;
7210             //            }
7211             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7212             //                return false;
7213             //            }
7214             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7215             //                return false;
7216             //            }
7217             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7218             //                return false;
7219             //            }
7220             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7221             //                return false;
7222             //            }
7223             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7224             //                return false;
7225             //            }
7226             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7227             //                return false;
7228             //            }
7229             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7230             //            parser.parse();
7231             //            labels = parser.getCharStateLabels();
7232             //            if ( labels.length != 7 ) {
7233             //                return false;
7234             //            }
7235             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7236             //                return false;
7237             //            }
7238             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7239             //                return false;
7240             //            }
7241             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7242             //                return false;
7243             //            }
7244             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7245             //                return false;
7246             //            }
7247             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7248             //                return false;
7249             //            }
7250             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7251             //                return false;
7252             //            }
7253             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7254             //                return false;
7255             //            }
7256         }
7257         catch ( final Exception e ) {
7258             e.printStackTrace( System.out );
7259             return false;
7260         }
7261         return true;
7262     }
7263
7264     private static boolean testNexusTreeParsing() {
7265         try {
7266             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7267             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7268             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7269             if ( phylogenies.length != 1 ) {
7270                 return false;
7271             }
7272             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7273                 return false;
7274             }
7275             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7276                 return false;
7277             }
7278             phylogenies = null;
7279             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7280             if ( phylogenies.length != 1 ) {
7281                 return false;
7282             }
7283             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7284                 return false;
7285             }
7286             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7287                 return false;
7288             }
7289             phylogenies = null;
7290             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7291             if ( phylogenies.length != 1 ) {
7292                 return false;
7293             }
7294             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7295                 return false;
7296             }
7297             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7298                 return false;
7299             }
7300             if ( phylogenies[ 0 ].isRooted() ) {
7301                 return false;
7302             }
7303             phylogenies = null;
7304             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7305             if ( phylogenies.length != 18 ) {
7306                 return false;
7307             }
7308             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7309                 return false;
7310             }
7311             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7312                 return false;
7313             }
7314             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7315                 return false;
7316             }
7317             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7318                 return false;
7319             }
7320             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7321                 return false;
7322             }
7323             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7324                 return false;
7325             }
7326             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7327                 return false;
7328             }
7329             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7330                 return false;
7331             }
7332             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7333                 return false;
7334             }
7335             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7336                 return false;
7337             }
7338             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7339                 return false;
7340             }
7341             if ( phylogenies[ 8 ].isRooted() ) {
7342                 return false;
7343             }
7344             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7345                 return false;
7346             }
7347             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7348                 return false;
7349             }
7350             if ( !phylogenies[ 9 ].isRooted() ) {
7351                 return false;
7352             }
7353             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7354                 return false;
7355             }
7356             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7357                 return false;
7358             }
7359             if ( !phylogenies[ 10 ].isRooted() ) {
7360                 return false;
7361             }
7362             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7363                 return false;
7364             }
7365             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7366                 return false;
7367             }
7368             if ( phylogenies[ 11 ].isRooted() ) {
7369                 return false;
7370             }
7371             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7372                 return false;
7373             }
7374             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7375                 return false;
7376             }
7377             if ( !phylogenies[ 12 ].isRooted() ) {
7378                 return false;
7379             }
7380             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7381                 return false;
7382             }
7383             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7384                 return false;
7385             }
7386             if ( !phylogenies[ 13 ].isRooted() ) {
7387                 return false;
7388             }
7389             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7390                 return false;
7391             }
7392             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7393                 return false;
7394             }
7395             if ( !phylogenies[ 14 ].isRooted() ) {
7396                 return false;
7397             }
7398             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7399                 return false;
7400             }
7401             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7402                 return false;
7403             }
7404             if ( phylogenies[ 15 ].isRooted() ) {
7405                 return false;
7406             }
7407             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7408                 return false;
7409             }
7410             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7411                 return false;
7412             }
7413             if ( !phylogenies[ 16 ].isRooted() ) {
7414                 return false;
7415             }
7416             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7417                 return false;
7418             }
7419             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7420                 return false;
7421             }
7422             if ( phylogenies[ 17 ].isRooted() ) {
7423                 return false;
7424             }
7425             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7426                 return false;
7427             }
7428             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7429             phylogenies = null;
7430             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7431             if ( phylogenies.length != 9 ) {
7432                 return false;
7433             }
7434             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7435                            .getDistanceToParent() ) ) {
7436                 return false;
7437             }
7438             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7439                            .getDistanceToParent() ) ) {
7440                 return false;
7441             }
7442             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7443                 return false;
7444             }
7445             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7446                 return false;
7447             }
7448             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7449                 return false;
7450             }
7451             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7452                 return false;
7453             }
7454             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7455                 return false;
7456             }
7457         }
7458         catch ( final Exception e ) {
7459             e.printStackTrace( System.out );
7460             return false;
7461         }
7462         return true;
7463     }
7464
7465     private static boolean testNexusTreeParsingIterating() {
7466         try {
7467             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7468             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7469             if ( !p.hasNext() ) {
7470                 return false;
7471             }
7472             Phylogeny phy = p.next();
7473             if ( phy == null ) {
7474                 return false;
7475             }
7476             if ( phy.getNumberOfExternalNodes() != 25 ) {
7477                 return false;
7478             }
7479             if ( !phy.getName().equals( "" ) ) {
7480                 return false;
7481             }
7482             if ( p.hasNext() ) {
7483                 return false;
7484             }
7485             phy = p.next();
7486             if ( phy != null ) {
7487                 return false;
7488             }
7489             p.reset();
7490             if ( !p.hasNext() ) {
7491                 return false;
7492             }
7493             phy = p.next();
7494             if ( phy == null ) {
7495                 return false;
7496             }
7497             if ( phy.getNumberOfExternalNodes() != 25 ) {
7498                 return false;
7499             }
7500             if ( !phy.getName().equals( "" ) ) {
7501                 return false;
7502             }
7503             if ( p.hasNext() ) {
7504                 return false;
7505             }
7506             phy = p.next();
7507             if ( phy != null ) {
7508                 return false;
7509             }
7510             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7511             if ( !p.hasNext() ) {
7512                 return false;
7513             }
7514             phy = p.next();
7515             if ( phy == null ) {
7516                 return false;
7517             }
7518             if ( phy.getNumberOfExternalNodes() != 10 ) {
7519                 return false;
7520             }
7521             if ( !phy.getName().equals( "name" ) ) {
7522                 return false;
7523             }
7524             if ( p.hasNext() ) {
7525                 return false;
7526             }
7527             phy = p.next();
7528             if ( phy != null ) {
7529                 return false;
7530             }
7531             p.reset();
7532             if ( !p.hasNext() ) {
7533                 return false;
7534             }
7535             phy = p.next();
7536             if ( phy == null ) {
7537                 return false;
7538             }
7539             if ( phy.getNumberOfExternalNodes() != 10 ) {
7540                 return false;
7541             }
7542             if ( !phy.getName().equals( "name" ) ) {
7543                 return false;
7544             }
7545             if ( p.hasNext() ) {
7546                 return false;
7547             }
7548             phy = p.next();
7549             if ( phy != null ) {
7550                 return false;
7551             }
7552             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7553             if ( !p.hasNext() ) {
7554                 return false;
7555             }
7556             phy = p.next();
7557             if ( phy == null ) {
7558                 return false;
7559             }
7560             if ( phy.getNumberOfExternalNodes() != 3 ) {
7561                 return false;
7562             }
7563             if ( !phy.getName().equals( "" ) ) {
7564                 return false;
7565             }
7566             if ( phy.isRooted() ) {
7567                 return false;
7568             }
7569             if ( p.hasNext() ) {
7570                 return false;
7571             }
7572             phy = p.next();
7573             if ( phy != null ) {
7574                 return false;
7575             }
7576             //
7577             p.reset();
7578             if ( !p.hasNext() ) {
7579                 return false;
7580             }
7581             phy = p.next();
7582             if ( phy == null ) {
7583                 return false;
7584             }
7585             if ( phy.getNumberOfExternalNodes() != 3 ) {
7586                 return false;
7587             }
7588             if ( !phy.getName().equals( "" ) ) {
7589                 return false;
7590             }
7591             if ( p.hasNext() ) {
7592                 return false;
7593             }
7594             phy = p.next();
7595             if ( phy != null ) {
7596                 return false;
7597             }
7598             //
7599             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7600             if ( !p.hasNext() ) {
7601                 return false;
7602             }
7603             //0
7604             phy = p.next();
7605             if ( phy == null ) {
7606                 return false;
7607             }
7608             if ( phy.getNumberOfExternalNodes() != 10 ) {
7609                 return false;
7610             }
7611             if ( !phy.getName().equals( "tree 0" ) ) {
7612                 return false;
7613             }
7614             //1
7615             if ( !p.hasNext() ) {
7616                 return false;
7617             }
7618             phy = p.next();
7619             if ( phy == null ) {
7620                 return false;
7621             }
7622             if ( phy.getNumberOfExternalNodes() != 10 ) {
7623                 return false;
7624             }
7625             if ( !phy.getName().equals( "tree 1" ) ) {
7626                 return false;
7627             }
7628             //2
7629             if ( !p.hasNext() ) {
7630                 return false;
7631             }
7632             phy = p.next();
7633             if ( phy == null ) {
7634                 return false;
7635             }
7636             if ( phy.getNumberOfExternalNodes() != 3 ) {
7637                 System.out.println( phy.toString() );
7638                 return false;
7639             }
7640             if ( !phy.getName().equals( "" ) ) {
7641                 return false;
7642             }
7643             if ( phy.isRooted() ) {
7644                 return false;
7645             }
7646             //3
7647             if ( !p.hasNext() ) {
7648                 return false;
7649             }
7650             phy = p.next();
7651             if ( phy == null ) {
7652                 return false;
7653             }
7654             if ( phy.getNumberOfExternalNodes() != 4 ) {
7655                 return false;
7656             }
7657             if ( !phy.getName().equals( "" ) ) {
7658                 return false;
7659             }
7660             if ( !phy.isRooted() ) {
7661                 return false;
7662             }
7663             //4
7664             if ( !p.hasNext() ) {
7665                 return false;
7666             }
7667             phy = p.next();
7668             if ( phy == null ) {
7669                 return false;
7670             }
7671             if ( phy.getNumberOfExternalNodes() != 5 ) {
7672                 System.out.println( phy.getNumberOfExternalNodes() );
7673                 return false;
7674             }
7675             if ( !phy.getName().equals( "" ) ) {
7676                 return false;
7677             }
7678             if ( !phy.isRooted() ) {
7679                 return false;
7680             }
7681             //5
7682             if ( !p.hasNext() ) {
7683                 return false;
7684             }
7685             phy = p.next();
7686             if ( phy == null ) {
7687                 return false;
7688             }
7689             if ( phy.getNumberOfExternalNodes() != 3 ) {
7690                 return false;
7691             }
7692             if ( !phy.getName().equals( "" ) ) {
7693                 return false;
7694             }
7695             if ( phy.isRooted() ) {
7696                 return false;
7697             }
7698             //6
7699             if ( !p.hasNext() ) {
7700                 return false;
7701             }
7702             phy = p.next();
7703             if ( phy == null ) {
7704                 return false;
7705             }
7706             if ( phy.getNumberOfExternalNodes() != 2 ) {
7707                 return false;
7708             }
7709             if ( !phy.getName().equals( "" ) ) {
7710                 return false;
7711             }
7712             if ( !phy.isRooted() ) {
7713                 return false;
7714             }
7715             //7
7716             if ( !p.hasNext() ) {
7717                 return false;
7718             }
7719             phy = p.next();
7720             if ( phy.getNumberOfExternalNodes() != 3 ) {
7721                 return false;
7722             }
7723             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7724                 return false;
7725             }
7726             if ( !phy.isRooted() ) {
7727                 return false;
7728             }
7729             //8
7730             if ( !p.hasNext() ) {
7731                 return false;
7732             }
7733             phy = p.next();
7734             if ( phy.getNumberOfExternalNodes() != 3 ) {
7735                 return false;
7736             }
7737             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7738                 return false;
7739             }
7740             if ( !phy.getName().equals( "tree 8" ) ) {
7741                 return false;
7742             }
7743             //9
7744             if ( !p.hasNext() ) {
7745                 return false;
7746             }
7747             phy = p.next();
7748             if ( phy.getNumberOfExternalNodes() != 3 ) {
7749                 return false;
7750             }
7751             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7752                 return false;
7753             }
7754             if ( !phy.getName().equals( "tree 9" ) ) {
7755                 return false;
7756             }
7757             //10
7758             if ( !p.hasNext() ) {
7759                 return false;
7760             }
7761             phy = p.next();
7762             if ( phy.getNumberOfExternalNodes() != 3 ) {
7763                 return false;
7764             }
7765             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7766                 return false;
7767             }
7768             if ( !phy.getName().equals( "tree 10" ) ) {
7769                 return false;
7770             }
7771             if ( !phy.isRooted() ) {
7772                 return false;
7773             }
7774             //11
7775             if ( !p.hasNext() ) {
7776                 return false;
7777             }
7778             phy = p.next();
7779             if ( phy.getNumberOfExternalNodes() != 3 ) {
7780                 return false;
7781             }
7782             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7783                 return false;
7784             }
7785             if ( !phy.getName().equals( "tree 11" ) ) {
7786                 return false;
7787             }
7788             if ( phy.isRooted() ) {
7789                 return false;
7790             }
7791             //12
7792             if ( !p.hasNext() ) {
7793                 return false;
7794             }
7795             phy = p.next();
7796             if ( phy.getNumberOfExternalNodes() != 3 ) {
7797                 return false;
7798             }
7799             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7800                 return false;
7801             }
7802             if ( !phy.getName().equals( "tree 12" ) ) {
7803                 return false;
7804             }
7805             if ( !phy.isRooted() ) {
7806                 return false;
7807             }
7808             //13
7809             if ( !p.hasNext() ) {
7810                 return false;
7811             }
7812             phy = p.next();
7813             if ( phy.getNumberOfExternalNodes() != 3 ) {
7814                 return false;
7815             }
7816             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7817                 return false;
7818             }
7819             if ( !phy.getName().equals( "tree 13" ) ) {
7820                 return false;
7821             }
7822             if ( !phy.isRooted() ) {
7823                 return false;
7824             }
7825             //14
7826             if ( !p.hasNext() ) {
7827                 return false;
7828             }
7829             phy = p.next();
7830             if ( phy.getNumberOfExternalNodes() != 10 ) {
7831                 System.out.println( phy.getNumberOfExternalNodes() );
7832                 return false;
7833             }
7834             if ( !phy
7835                     .toNewHampshire()
7836                     .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;" ) ) {
7837                 System.out.println( phy.toNewHampshire() );
7838                 return false;
7839             }
7840             if ( !phy.getName().equals( "tree 14" ) ) {
7841                 return false;
7842             }
7843             if ( !phy.isRooted() ) {
7844                 return false;
7845             }
7846             //15
7847             if ( !p.hasNext() ) {
7848                 return false;
7849             }
7850             phy = p.next();
7851             if ( phy.getNumberOfExternalNodes() != 10 ) {
7852                 System.out.println( phy.getNumberOfExternalNodes() );
7853                 return false;
7854             }
7855             if ( !phy
7856                     .toNewHampshire()
7857                     .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;" ) ) {
7858                 System.out.println( phy.toNewHampshire() );
7859                 return false;
7860             }
7861             if ( !phy.getName().equals( "tree 15" ) ) {
7862                 return false;
7863             }
7864             if ( phy.isRooted() ) {
7865                 return false;
7866             }
7867             //16
7868             if ( !p.hasNext() ) {
7869                 return false;
7870             }
7871             phy = p.next();
7872             if ( phy.getNumberOfExternalNodes() != 10 ) {
7873                 System.out.println( phy.getNumberOfExternalNodes() );
7874                 return false;
7875             }
7876             if ( !phy
7877                     .toNewHampshire()
7878                     .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;" ) ) {
7879                 System.out.println( phy.toNewHampshire() );
7880                 return false;
7881             }
7882             if ( !phy.getName().equals( "tree 16" ) ) {
7883                 return false;
7884             }
7885             if ( !phy.isRooted() ) {
7886                 return false;
7887             }
7888             //17
7889             if ( !p.hasNext() ) {
7890                 return false;
7891             }
7892             phy = p.next();
7893             if ( phy.getNumberOfExternalNodes() != 10 ) {
7894                 System.out.println( phy.getNumberOfExternalNodes() );
7895                 return false;
7896             }
7897             if ( !phy
7898                     .toNewHampshire()
7899                     .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;" ) ) {
7900                 System.out.println( phy.toNewHampshire() );
7901                 return false;
7902             }
7903             if ( !phy.getName().equals( "tree 17" ) ) {
7904                 return false;
7905             }
7906             if ( phy.isRooted() ) {
7907                 return false;
7908             }
7909             //
7910             if ( p.hasNext() ) {
7911                 return false;
7912             }
7913             phy = p.next();
7914             if ( phy != null ) {
7915                 return false;
7916             }
7917             p.reset();
7918             //0
7919             if ( !p.hasNext() ) {
7920                 return false;
7921             }
7922             phy = p.next();
7923             if ( phy == null ) {
7924                 return false;
7925             }
7926             if ( phy.getNumberOfExternalNodes() != 10 ) {
7927                 return false;
7928             }
7929             if ( !phy.getName().equals( "tree 0" ) ) {
7930                 return false;
7931             }
7932             //1
7933             if ( !p.hasNext() ) {
7934                 return false;
7935             }
7936             phy = p.next();
7937             if ( phy == null ) {
7938                 return false;
7939             }
7940             if ( phy.getNumberOfExternalNodes() != 10 ) {
7941                 return false;
7942             }
7943             if ( !phy.getName().equals( "tree 1" ) ) {
7944                 return false;
7945             }
7946             //2
7947             if ( !p.hasNext() ) {
7948                 return false;
7949             }
7950             phy = p.next();
7951             if ( phy == null ) {
7952                 return false;
7953             }
7954             if ( phy.getNumberOfExternalNodes() != 3 ) {
7955                 return false;
7956             }
7957             if ( !phy.getName().equals( "" ) ) {
7958                 return false;
7959             }
7960             if ( phy.isRooted() ) {
7961                 return false;
7962             }
7963             //3
7964             if ( !p.hasNext() ) {
7965                 return false;
7966             }
7967             phy = p.next();
7968             if ( phy == null ) {
7969                 return false;
7970             }
7971             if ( phy.getNumberOfExternalNodes() != 4 ) {
7972                 return false;
7973             }
7974             if ( !phy.getName().equals( "" ) ) {
7975                 return false;
7976             }
7977             if ( !phy.isRooted() ) {
7978                 return false;
7979             }
7980             //4
7981             if ( !p.hasNext() ) {
7982                 return false;
7983             }
7984             phy = p.next();
7985             if ( phy == null ) {
7986                 return false;
7987             }
7988             if ( phy.getNumberOfExternalNodes() != 5 ) {
7989                 System.out.println( phy.getNumberOfExternalNodes() );
7990                 return false;
7991             }
7992             if ( !phy.getName().equals( "" ) ) {
7993                 return false;
7994             }
7995             if ( !phy.isRooted() ) {
7996                 return false;
7997             }
7998             //5
7999             if ( !p.hasNext() ) {
8000                 return false;
8001             }
8002             phy = p.next();
8003             if ( phy == null ) {
8004                 return false;
8005             }
8006             if ( phy.getNumberOfExternalNodes() != 3 ) {
8007                 return false;
8008             }
8009             if ( !phy.getName().equals( "" ) ) {
8010                 return false;
8011             }
8012             if ( phy.isRooted() ) {
8013                 return false;
8014             }
8015             //
8016             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
8017             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
8018             // 0
8019             if ( !p2.hasNext() ) {
8020                 return false;
8021             }
8022             phy = p2.next();
8023             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8024                 return false;
8025             }
8026             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8027                 return false;
8028             }
8029             // 1
8030             if ( !p2.hasNext() ) {
8031                 return false;
8032             }
8033             phy = p2.next();
8034             // 2
8035             if ( !p2.hasNext() ) {
8036                 return false;
8037             }
8038             phy = p2.next();
8039             // 3
8040             if ( !p2.hasNext() ) {
8041                 return false;
8042             }
8043             phy = p2.next();
8044             // 4
8045             if ( !p2.hasNext() ) {
8046                 return false;
8047             }
8048             phy = p2.next();
8049             // 5
8050             if ( !p2.hasNext() ) {
8051                 return false;
8052             }
8053             phy = p2.next();
8054             // 6
8055             if ( !p2.hasNext() ) {
8056                 return false;
8057             }
8058             phy = p2.next();
8059             // 7
8060             if ( !p2.hasNext() ) {
8061                 return false;
8062             }
8063             phy = p2.next();
8064             // 8
8065             if ( !p2.hasNext() ) {
8066                 return false;
8067             }
8068             phy = p2.next();
8069             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
8070                 return false;
8071             }
8072             if ( p2.hasNext() ) {
8073                 return false;
8074             }
8075             phy = p2.next();
8076             if ( phy != null ) {
8077                 return false;
8078             }
8079             // 0
8080             p2.reset();
8081             if ( !p2.hasNext() ) {
8082                 return false;
8083             }
8084             phy = p2.next();
8085             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8086                 return false;
8087             }
8088             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8089                 return false;
8090             }
8091         }
8092         catch ( final Exception e ) {
8093             e.printStackTrace( System.out );
8094             return false;
8095         }
8096         return true;
8097     }
8098
8099     private static boolean testNexusTreeParsingTranslating() {
8100         try {
8101             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8102             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
8103             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
8104             if ( phylogenies.length != 1 ) {
8105                 return false;
8106             }
8107             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8108                 return false;
8109             }
8110             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8111                 return false;
8112             }
8113             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8114                 return false;
8115             }
8116             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8117                 return false;
8118             }
8119             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8120                     .equals( "Aranaeus" ) ) {
8121                 return false;
8122             }
8123             phylogenies = null;
8124             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
8125             if ( phylogenies.length != 3 ) {
8126                 return false;
8127             }
8128             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8129                 return false;
8130             }
8131             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8132                 return false;
8133             }
8134             if ( phylogenies[ 0 ].isRooted() ) {
8135                 return false;
8136             }
8137             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8138                 return false;
8139             }
8140             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8141                 return false;
8142             }
8143             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8144                     .equals( "Aranaeus" ) ) {
8145                 return false;
8146             }
8147             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8148                 return false;
8149             }
8150             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8151                 return false;
8152             }
8153             if ( phylogenies[ 1 ].isRooted() ) {
8154                 return false;
8155             }
8156             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8157                 return false;
8158             }
8159             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8160                 return false;
8161             }
8162             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8163                     .equals( "Aranaeus" ) ) {
8164                 return false;
8165             }
8166             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8167                 return false;
8168             }
8169             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8170                 return false;
8171             }
8172             if ( !phylogenies[ 2 ].isRooted() ) {
8173                 return false;
8174             }
8175             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8176                 return false;
8177             }
8178             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8179                 return false;
8180             }
8181             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8182                     .equals( "Aranaeus" ) ) {
8183                 return false;
8184             }
8185             phylogenies = null;
8186             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8187             if ( phylogenies.length != 3 ) {
8188                 return false;
8189             }
8190             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8191                 return false;
8192             }
8193             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8194                 return false;
8195             }
8196             if ( phylogenies[ 0 ].isRooted() ) {
8197                 return false;
8198             }
8199             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8200                 return false;
8201             }
8202             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8203                 return false;
8204             }
8205             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8206                     .equals( "Aranaeus" ) ) {
8207                 return false;
8208             }
8209             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8210                 return false;
8211             }
8212             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8213                 return false;
8214             }
8215             if ( phylogenies[ 1 ].isRooted() ) {
8216                 return false;
8217             }
8218             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8219                 return false;
8220             }
8221             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8222                 return false;
8223             }
8224             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8225                     .equals( "Aranaeus" ) ) {
8226                 return false;
8227             }
8228             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8229                 return false;
8230             }
8231             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8232                 return false;
8233             }
8234             if ( !phylogenies[ 2 ].isRooted() ) {
8235                 return false;
8236             }
8237             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8238                 return false;
8239             }
8240             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8241                 return false;
8242             }
8243             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8244                     .equals( "Aranaeus" ) ) {
8245                 return false;
8246             }
8247             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8248             if ( phylogenies.length != 3 ) {
8249                 return false;
8250             }
8251             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8252                            0.00100049 ) ) {
8253                 return false;
8254             }
8255         }
8256         catch ( final Exception e ) {
8257             e.printStackTrace( System.out );
8258             return false;
8259         }
8260         return true;
8261     }
8262
8263     private static boolean testNHParsing() {
8264         try {
8265             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8266             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8267             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8268                 return false;
8269             }
8270             final NHXParser nhxp = new NHXParser();
8271             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8272             nhxp.setReplaceUnderscores( true );
8273             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8274             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8275                 return false;
8276             }
8277             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8278                 return false;
8279             }
8280             final Phylogeny p1b = factory
8281                     .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 ",
8282                              new NHXParser() )[ 0 ];
8283             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8284                 return false;
8285             }
8286             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8287                 return false;
8288             }
8289             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
8290             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8291             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8292             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
8293             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8294             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8295             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8296             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8297             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8298             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8299             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8300                     + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8301                     + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8302                     new NHXParser() );
8303             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8304                 return false;
8305             }
8306             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8307                 return false;
8308             }
8309             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8310                 return false;
8311             }
8312             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8313                 return false;
8314             }
8315             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8316             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8317             final String p16_S = "((A,B),C)";
8318             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8319             if ( p16.length != 1 ) {
8320                 return false;
8321             }
8322             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8323                 return false;
8324             }
8325             final String p17_S = "(C,(A,B))";
8326             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8327             if ( p17.length != 1 ) {
8328                 return false;
8329             }
8330             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8331                 return false;
8332             }
8333             final String p18_S = "((A,B),(C,D))";
8334             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8335             if ( p18.length != 1 ) {
8336                 return false;
8337             }
8338             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8339                 return false;
8340             }
8341             final String p19_S = "(((A,B),C),D)";
8342             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8343             if ( p19.length != 1 ) {
8344                 return false;
8345             }
8346             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8347                 return false;
8348             }
8349             final String p20_S = "(A,(B,(C,D)))";
8350             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8351             if ( p20.length != 1 ) {
8352                 return false;
8353             }
8354             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8355                 return false;
8356             }
8357             final String p21_S = "(A,(B,(C,(D,E))))";
8358             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8359             if ( p21.length != 1 ) {
8360                 return false;
8361             }
8362             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8363                 return false;
8364             }
8365             final String p22_S = "((((A,B),C),D),E)";
8366             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8367             if ( p22.length != 1 ) {
8368                 return false;
8369             }
8370             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8371                 return false;
8372             }
8373             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8374             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8375             if ( p23.length != 1 ) {
8376                 System.out.println( "xl=" + p23.length );
8377                 System.exit( -1 );
8378                 return false;
8379             }
8380             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8381                 return false;
8382             }
8383             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8384             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8385             if ( p24.length != 1 ) {
8386                 return false;
8387             }
8388             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8389                 return false;
8390             }
8391             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8392             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8393             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8394             if ( p241.length != 2 ) {
8395                 return false;
8396             }
8397             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8398                 return false;
8399             }
8400             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8401                 return false;
8402             }
8403             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8404                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8405                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8406                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8407                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8408                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8409                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8410                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8411             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8412             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8413                 return false;
8414             }
8415             final String p26_S = "(A,B)ab";
8416             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8417             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8418                 return false;
8419             }
8420             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8421             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8422             if ( p27s.length != 1 ) {
8423                 System.out.println( "xxl=" + p27s.length );
8424                 System.exit( -1 );
8425                 return false;
8426             }
8427             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8428                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8429                 System.exit( -1 );
8430                 return false;
8431             }
8432             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8433                                                     new NHXParser() );
8434             if ( p27.length != 1 ) {
8435                 System.out.println( "yl=" + p27.length );
8436                 System.exit( -1 );
8437                 return false;
8438             }
8439             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8440                 System.out.println( p27[ 0 ].toNewHampshireX() );
8441                 System.exit( -1 );
8442                 return false;
8443             }
8444             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8445             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8446             final String p28_S3 = "(A,B)ab";
8447             final String p28_S4 = "((((A,B),C),D),;E;)";
8448             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8449                                                     new NHXParser() );
8450             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8451                 return false;
8452             }
8453             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8454                 return false;
8455             }
8456             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8457                 return false;
8458             }
8459             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8460                 return false;
8461             }
8462             if ( p28.length != 4 ) {
8463                 return false;
8464             }
8465             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";
8466             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8467             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8468                 return false;
8469             }
8470             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";
8471             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8472             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8473                 return false;
8474             }
8475             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8476             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8477             if ( ( p32.length != 0 ) ) {
8478                 return false;
8479             }
8480             final String p33_S = "A";
8481             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8482             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8483                 return false;
8484             }
8485             final String p34_S = "B;";
8486             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8487             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8488                 return false;
8489             }
8490             final String p35_S = "B:0.2";
8491             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8492             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8493                 return false;
8494             }
8495             final String p36_S = "(A)";
8496             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8497             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8498                 return false;
8499             }
8500             final String p37_S = "((A))";
8501             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8502             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8503                 return false;
8504             }
8505             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8506             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8507             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8508                 return false;
8509             }
8510             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8511             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8512             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8513                 return false;
8514             }
8515             final String p40_S = "(A,B,C)";
8516             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8517             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8518                 return false;
8519             }
8520             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8521             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8522             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8523                 return false;
8524             }
8525             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8526             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8527             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8528                 return false;
8529             }
8530             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)";
8531             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8532             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8533                 return false;
8534             }
8535             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)))";
8536             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8537             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8538                 return false;
8539             }
8540             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8541             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8542             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8543                 return false;
8544             }
8545             final String p46_S = "";
8546             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8547             if ( p46.length != 0 ) {
8548                 return false;
8549             }
8550             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8551             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8552                 return false;
8553             }
8554             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8555             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8556                 return false;
8557             }
8558             final Phylogeny p49 = factory
8559                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8560                              new NHXParser() )[ 0 ];
8561             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8562                 return false;
8563             }
8564             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8565             if ( p50.getNode( "A" ) == null ) {
8566                 return false;
8567             }
8568             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8569                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8570                 return false;
8571             }
8572             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8573                 return false;
8574             }
8575             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8576                     .equals( "((A,B)88:2.0,C);" ) ) {
8577                 return false;
8578             }
8579             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8580             if ( p51.getNode( "A(A" ) == null ) {
8581                 return false;
8582             }
8583             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8584             if ( p52.getNode( "A(A" ) == null ) {
8585                 return false;
8586             }
8587             final Phylogeny p53 = factory
8588                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8589                              new NHXParser() )[ 0 ];
8590             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8591                 return false;
8592             }
8593             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8594             if ( p54.getNode( "A" ) == null ) {
8595                 return false;
8596             }
8597             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8598                 return false;
8599             }
8600             final Phylogeny p55 = factory
8601                     .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);" ),
8602                              new NHXParser() )[ 0 ];
8603             if ( !p55
8604                     .toNewHampshire()
8605                     .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);" ) ) {
8606                 System.out.println( p55.toNewHampshire() );
8607                 return false;
8608             }
8609             final Phylogeny p56 = factory
8610                     .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);" ),
8611                              new NHXParser() )[ 0 ];
8612             if ( !p56
8613                     .toNewHampshire()
8614                     .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);" ) ) {
8615                 System.out.println( p56.toNewHampshire() );
8616                 return false;
8617             }
8618             final Phylogeny p57 = factory
8619                     .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);" ),
8620                              new NHXParser() )[ 0 ];
8621             if ( !p57
8622                     .toNewHampshire()
8623                     .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);" ) ) {
8624                 System.out.println( p56.toNewHampshire() );
8625                 return false;
8626             }
8627             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8628             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8629             if ( !p58.toNewHampshire().equals( s58 ) ) {
8630                 System.out.println( p58.toNewHampshire() );
8631                 return false;
8632             }
8633             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8634             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8635             if ( !p59.toNewHampshire().equals( s59 ) ) {
8636                 System.out.println( p59.toNewHampshire() );
8637                 return false;
8638             }
8639             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8640             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8641             if ( !p60.toNewHampshire().equals( s60 ) ) {
8642                 System.out.println( p60.toNewHampshire() );
8643                 return false;
8644             }
8645             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8646             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8647             if ( !p61.toNewHampshire()
8648                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8649                 System.out.println( p61.toNewHampshire() );
8650                 return false;
8651             }
8652         }
8653         catch ( final Exception e ) {
8654             e.printStackTrace( System.out );
8655             return false;
8656         }
8657         return true;
8658     }
8659
8660     private static boolean testNHParsingIter() {
8661         try {
8662             final String p0_str = "(A,B);";
8663             final NHXParser p = new NHXParser();
8664             p.setSource( p0_str );
8665             if ( !p.hasNext() ) {
8666                 return false;
8667             }
8668             final Phylogeny p0 = p.next();
8669             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8670                 System.out.println( p0.toNewHampshire() );
8671                 return false;
8672             }
8673             if ( p.hasNext() ) {
8674                 return false;
8675             }
8676             if ( p.next() != null ) {
8677                 return false;
8678             }
8679             //
8680             final String p00_str = "(A,B)root;";
8681             p.setSource( p00_str );
8682             final Phylogeny p00 = p.next();
8683             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8684                 System.out.println( p00.toNewHampshire() );
8685                 return false;
8686             }
8687             //
8688             final String p000_str = "A;";
8689             p.setSource( p000_str );
8690             final Phylogeny p000 = p.next();
8691             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8692                 System.out.println( p000.toNewHampshire() );
8693                 return false;
8694             }
8695             //
8696             final String p0000_str = "A";
8697             p.setSource( p0000_str );
8698             final Phylogeny p0000 = p.next();
8699             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8700                 System.out.println( p0000.toNewHampshire() );
8701                 return false;
8702             }
8703             //
8704             p.setSource( "(A)" );
8705             final Phylogeny p00000 = p.next();
8706             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8707                 System.out.println( p00000.toNewHampshire() );
8708                 return false;
8709             }
8710             //
8711             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8712             p.setSource( p1_str );
8713             if ( !p.hasNext() ) {
8714                 return false;
8715             }
8716             final Phylogeny p1_0 = p.next();
8717             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8718                 System.out.println( p1_0.toNewHampshire() );
8719                 return false;
8720             }
8721             if ( !p.hasNext() ) {
8722                 return false;
8723             }
8724             final Phylogeny p1_1 = p.next();
8725             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8726                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8727                 return false;
8728             }
8729             if ( !p.hasNext() ) {
8730                 return false;
8731             }
8732             final Phylogeny p1_2 = p.next();
8733             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8734                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8735                 return false;
8736             }
8737             if ( !p.hasNext() ) {
8738                 return false;
8739             }
8740             final Phylogeny p1_3 = p.next();
8741             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8742                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8743                 return false;
8744             }
8745             if ( p.hasNext() ) {
8746                 return false;
8747             }
8748             if ( p.next() != null ) {
8749                 return false;
8750             }
8751             //
8752             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8753             p.setSource( p2_str );
8754             if ( !p.hasNext() ) {
8755                 return false;
8756             }
8757             Phylogeny p2_0 = p.next();
8758             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8759                 System.out.println( p2_0.toNewHampshire() );
8760                 return false;
8761             }
8762             if ( !p.hasNext() ) {
8763                 return false;
8764             }
8765             Phylogeny p2_1 = p.next();
8766             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8767                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8768                 return false;
8769             }
8770             if ( !p.hasNext() ) {
8771                 return false;
8772             }
8773             Phylogeny p2_2 = p.next();
8774             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8775                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8776                 return false;
8777             }
8778             if ( !p.hasNext() ) {
8779                 return false;
8780             }
8781             Phylogeny p2_3 = p.next();
8782             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8783                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8784                 return false;
8785             }
8786             if ( !p.hasNext() ) {
8787                 return false;
8788             }
8789             Phylogeny p2_4 = p.next();
8790             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8791                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8792                 return false;
8793             }
8794             if ( p.hasNext() ) {
8795                 return false;
8796             }
8797             if ( p.next() != null ) {
8798                 return false;
8799             }
8800             ////
8801             p.reset();
8802             if ( !p.hasNext() ) {
8803                 return false;
8804             }
8805             p2_0 = p.next();
8806             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8807                 System.out.println( p2_0.toNewHampshire() );
8808                 return false;
8809             }
8810             if ( !p.hasNext() ) {
8811                 return false;
8812             }
8813             p2_1 = p.next();
8814             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8815                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8816                 return false;
8817             }
8818             if ( !p.hasNext() ) {
8819                 return false;
8820             }
8821             p2_2 = p.next();
8822             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8823                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8824                 return false;
8825             }
8826             if ( !p.hasNext() ) {
8827                 return false;
8828             }
8829             p2_3 = p.next();
8830             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8831                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8832                 return false;
8833             }
8834             if ( !p.hasNext() ) {
8835                 return false;
8836             }
8837             p2_4 = p.next();
8838             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8839                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8840                 return false;
8841             }
8842             if ( p.hasNext() ) {
8843                 return false;
8844             }
8845             if ( p.next() != null ) {
8846                 return false;
8847             }
8848             //
8849             final String p3_str = "((A,B),C)abc";
8850             p.setSource( p3_str );
8851             if ( !p.hasNext() ) {
8852                 return false;
8853             }
8854             final Phylogeny p3_0 = p.next();
8855             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8856                 return false;
8857             }
8858             if ( p.hasNext() ) {
8859                 return false;
8860             }
8861             if ( p.next() != null ) {
8862                 return false;
8863             }
8864             //
8865             final String p4_str = "((A,B)ab,C)abc";
8866             p.setSource( p4_str );
8867             if ( !p.hasNext() ) {
8868                 return false;
8869             }
8870             final Phylogeny p4_0 = p.next();
8871             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8872                 return false;
8873             }
8874             if ( p.hasNext() ) {
8875                 return false;
8876             }
8877             if ( p.next() != null ) {
8878                 return false;
8879             }
8880             //
8881             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8882             p.setSource( p5_str );
8883             if ( !p.hasNext() ) {
8884                 return false;
8885             }
8886             final Phylogeny p5_0 = p.next();
8887             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8888                 return false;
8889             }
8890             if ( p.hasNext() ) {
8891                 return false;
8892             }
8893             if ( p.next() != null ) {
8894                 return false;
8895             }
8896             //
8897             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8898             p.setSource( p6_str );
8899             if ( !p.hasNext() ) {
8900                 return false;
8901             }
8902             Phylogeny p6_0 = p.next();
8903             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8904                 return false;
8905             }
8906             if ( p.hasNext() ) {
8907                 return false;
8908             }
8909             if ( p.next() != null ) {
8910                 return false;
8911             }
8912             p.reset();
8913             if ( !p.hasNext() ) {
8914                 return false;
8915             }
8916             p6_0 = p.next();
8917             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8918                 return false;
8919             }
8920             if ( p.hasNext() ) {
8921                 return false;
8922             }
8923             if ( p.next() != null ) {
8924                 return false;
8925             }
8926             //
8927             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8928             p.setSource( p7_str );
8929             if ( !p.hasNext() ) {
8930                 return false;
8931             }
8932             Phylogeny p7_0 = p.next();
8933             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8934                 return false;
8935             }
8936             if ( p.hasNext() ) {
8937                 return false;
8938             }
8939             if ( p.next() != null ) {
8940                 return false;
8941             }
8942             p.reset();
8943             if ( !p.hasNext() ) {
8944                 return false;
8945             }
8946             p7_0 = p.next();
8947             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8948                 return false;
8949             }
8950             if ( p.hasNext() ) {
8951                 return false;
8952             }
8953             if ( p.next() != null ) {
8954                 return false;
8955             }
8956             //
8957             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8958             p.setSource( p8_str );
8959             if ( !p.hasNext() ) {
8960                 return false;
8961             }
8962             Phylogeny p8_0 = p.next();
8963             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8964                 return false;
8965             }
8966             if ( !p.hasNext() ) {
8967                 return false;
8968             }
8969             if ( !p.hasNext() ) {
8970                 return false;
8971             }
8972             Phylogeny p8_1 = p.next();
8973             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8974                 return false;
8975             }
8976             if ( p.hasNext() ) {
8977                 return false;
8978             }
8979             if ( p.next() != null ) {
8980                 return false;
8981             }
8982             p.reset();
8983             if ( !p.hasNext() ) {
8984                 return false;
8985             }
8986             p8_0 = p.next();
8987             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8988                 return false;
8989             }
8990             if ( !p.hasNext() ) {
8991                 return false;
8992             }
8993             p8_1 = p.next();
8994             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8995                 return false;
8996             }
8997             if ( p.hasNext() ) {
8998                 return false;
8999             }
9000             if ( p.next() != null ) {
9001                 return false;
9002             }
9003             p.reset();
9004             //
9005             p.setSource( "" );
9006             if ( p.hasNext() ) {
9007                 return false;
9008             }
9009             //
9010             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
9011             if ( !p.hasNext() ) {
9012                 return false;
9013             }
9014             Phylogeny p_27 = p.next();
9015             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9016                 System.out.println( p_27.toNewHampshireX() );
9017                 System.exit( -1 );
9018                 return false;
9019             }
9020             if ( p.hasNext() ) {
9021                 return false;
9022             }
9023             if ( p.next() != null ) {
9024                 return false;
9025             }
9026             p.reset();
9027             if ( !p.hasNext() ) {
9028                 return false;
9029             }
9030             p_27 = p.next();
9031             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9032                 System.out.println( p_27.toNewHampshireX() );
9033                 System.exit( -1 );
9034                 return false;
9035             }
9036             if ( p.hasNext() ) {
9037                 return false;
9038             }
9039             if ( p.next() != null ) {
9040                 return false;
9041             }
9042             //
9043             final String p30_str = "(A,B);(C,D)";
9044             final NHXParser p30 = new NHXParser();
9045             p30.setSource( p30_str );
9046             if ( !p30.hasNext() ) {
9047                 return false;
9048             }
9049             Phylogeny phy30 = p30.next();
9050             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9051                 System.out.println( phy30.toNewHampshire() );
9052                 return false;
9053             }
9054             if ( !p30.hasNext() ) {
9055                 return false;
9056             }
9057             Phylogeny phy301 = p30.next();
9058             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9059                 System.out.println( phy301.toNewHampshire() );
9060                 return false;
9061             }
9062             if ( p30.hasNext() ) {
9063                 return false;
9064             }
9065             if ( p30.hasNext() ) {
9066                 return false;
9067             }
9068             if ( p30.next() != null ) {
9069                 return false;
9070             }
9071             if ( p30.next() != null ) {
9072                 return false;
9073             }
9074             p30.reset();
9075             if ( !p30.hasNext() ) {
9076                 return false;
9077             }
9078             phy30 = p30.next();
9079             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9080                 System.out.println( phy30.toNewHampshire() );
9081                 return false;
9082             }
9083             if ( !p30.hasNext() ) {
9084                 return false;
9085             }
9086             phy301 = p30.next();
9087             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9088                 System.out.println( phy301.toNewHampshire() );
9089                 return false;
9090             }
9091             if ( p30.hasNext() ) {
9092                 return false;
9093             }
9094             if ( p30.hasNext() ) {
9095                 return false;
9096             }
9097             if ( p30.next() != null ) {
9098                 return false;
9099             }
9100             if ( p30.next() != null ) {
9101                 return false;
9102             }
9103         }
9104         catch ( final Exception e ) {
9105             e.printStackTrace( System.out );
9106             return false;
9107         }
9108         return true;
9109     }
9110
9111     private static boolean testNHXconversion() {
9112         try {
9113             final PhylogenyNode n1 = new PhylogenyNode();
9114             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9115             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9116             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9117             final PhylogenyNode n5 = PhylogenyNode
9118                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
9119             final PhylogenyNode n6 = PhylogenyNode
9120                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
9121             if ( !n1.toNewHampshireX().equals( "" ) ) {
9122                 return false;
9123             }
9124             if ( !n2.toNewHampshireX().equals( "" ) ) {
9125                 return false;
9126             }
9127             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
9128                 return false;
9129             }
9130             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
9131                 return false;
9132             }
9133             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
9134                 return false;
9135             }
9136             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9137                 System.out.println( n6.toNewHampshireX() );
9138                 return false;
9139             }
9140             final PhylogenyNode n7 = new PhylogenyNode();
9141             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9142             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9143                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9144                 System.out.println( n7
9145                                     .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9146                 return false;
9147             }
9148         }
9149         catch ( final Exception e ) {
9150             e.printStackTrace( System.out );
9151             return false;
9152         }
9153         return true;
9154     }
9155
9156     private static boolean testNHXNodeParsing() {
9157         try {
9158             final PhylogenyNode n1 = new PhylogenyNode();
9159             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9160             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9161             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9162             final PhylogenyNode n5 = PhylogenyNode
9163                     .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]" );
9164             if ( !n3.getName().equals( "n3" ) ) {
9165                 return false;
9166             }
9167             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9168                 return false;
9169             }
9170             if ( n3.isDuplication() ) {
9171                 return false;
9172             }
9173             if ( n3.isHasAssignedEvent() ) {
9174                 return false;
9175             }
9176             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9177                 return false;
9178             }
9179             if ( !n4.getName().equals( "n4" ) ) {
9180                 return false;
9181             }
9182             if ( n4.getDistanceToParent() != 0.01 ) {
9183                 return false;
9184             }
9185             if ( !n5.getName().equals( "n5" ) ) {
9186                 return false;
9187             }
9188             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9189                 return false;
9190             }
9191             if ( n5.getDistanceToParent() != 0.1 ) {
9192                 return false;
9193             }
9194             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9195                 return false;
9196             }
9197             if ( !n5.isDuplication() ) {
9198                 return false;
9199             }
9200             if ( !n5.isHasAssignedEvent() ) {
9201                 return false;
9202             }
9203             final PhylogenyNode n8 = PhylogenyNode
9204                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9205                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9206             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9207                 return false;
9208             }
9209             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9210                 return false;
9211             }
9212             final PhylogenyNode n9 = PhylogenyNode
9213                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9214                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9215             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9216                 return false;
9217             }
9218             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9219                 return false;
9220             }
9221             final PhylogenyNode n10 = PhylogenyNode
9222                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9223             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9224                 return false;
9225             }
9226             final PhylogenyNode n20 = PhylogenyNode
9227                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9228             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9229                 return false;
9230             }
9231             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9232                 return false;
9233             }
9234             final PhylogenyNode n20x = PhylogenyNode
9235                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9236             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9237                 return false;
9238             }
9239             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9240                 return false;
9241             }
9242             final PhylogenyNode n20xx = PhylogenyNode
9243                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9244             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9245                 return false;
9246             }
9247             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9248                 return false;
9249             }
9250             final PhylogenyNode n20xxx = PhylogenyNode
9251                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9252             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9253                 return false;
9254             }
9255             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9256                 return false;
9257             }
9258             final PhylogenyNode n20xxxx = PhylogenyNode
9259                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9260             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9261                 return false;
9262             }
9263             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9264                 return false;
9265             }
9266             final PhylogenyNode n21 = PhylogenyNode
9267                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9268             if ( !n21.getName().equals( "N21_PIG" ) ) {
9269                 return false;
9270             }
9271             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9272                 return false;
9273             }
9274             final PhylogenyNode n21x = PhylogenyNode
9275                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9276             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9277                 return false;
9278             }
9279             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9280                 return false;
9281             }
9282             final PhylogenyNode n22 = PhylogenyNode
9283                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9284             if ( !n22.getName().equals( "n22/PIG" ) ) {
9285                 return false;
9286             }
9287             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9288                 return false;
9289             }
9290             final PhylogenyNode n23 = PhylogenyNode
9291                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9292             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9293                 return false;
9294             }
9295             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9296                 return false;
9297             }
9298             final PhylogenyNode a = PhylogenyNode
9299                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9300             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9301                 return false;
9302             }
9303             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9304                 return false;
9305             }
9306             final PhylogenyNode c1 = PhylogenyNode
9307                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9308                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9309             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9310                 return false;
9311             }
9312             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9313                 return false;
9314             }
9315             final PhylogenyNode c2 = PhylogenyNode
9316                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9317                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9318             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9319                 return false;
9320             }
9321             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9322                 return false;
9323             }
9324             final PhylogenyNode e3 = PhylogenyNode
9325                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9326             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9327                 return false;
9328             }
9329             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9330                 return false;
9331             }
9332             final PhylogenyNode n11 = PhylogenyNode
9333                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9334                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9335             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9336                 return false;
9337             }
9338             if ( n11.getDistanceToParent() != 0.4 ) {
9339                 return false;
9340             }
9341             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9342                 return false;
9343             }
9344             final PhylogenyNode n12 = PhylogenyNode
9345                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9346                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9347             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9348                 return false;
9349             }
9350             if ( n12.getDistanceToParent() != 0.4 ) {
9351                 return false;
9352             }
9353             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9354                 return false;
9355             }
9356             final PhylogenyNode o = PhylogenyNode
9357                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9358             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9359                 return false;
9360             }
9361             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9362                 return false;
9363             }
9364             if ( n1.getName().compareTo( "" ) != 0 ) {
9365                 return false;
9366             }
9367             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9368                 return false;
9369             }
9370             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9371                 return false;
9372             }
9373             if ( n2.getName().compareTo( "" ) != 0 ) {
9374                 return false;
9375             }
9376             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9377                 return false;
9378             }
9379             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9380                 return false;
9381             }
9382             final PhylogenyNode n00 = PhylogenyNode
9383                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9384             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9385                 return false;
9386             }
9387             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9388                 return false;
9389             }
9390             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9391             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9392                 return false;
9393             }
9394             final PhylogenyNode n13 = PhylogenyNode
9395                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9396             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9397                 return false;
9398             }
9399             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9400                 return false;
9401             }
9402             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9403                 return false;
9404             }
9405             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9406                 return false;
9407             }
9408             final PhylogenyNode n14 = PhylogenyNode
9409                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9410             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9411                 return false;
9412             }
9413             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9414                 return false;
9415             }
9416             final PhylogenyNode n15 = PhylogenyNode
9417                     .createInstanceFromNhxString( "something_wicked[123]",
9418                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9419             if ( !n15.getName().equals( "something_wicked" ) ) {
9420                 return false;
9421             }
9422             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9423                 return false;
9424             }
9425             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9426                 return false;
9427             }
9428             final PhylogenyNode n16 = PhylogenyNode
9429                     .createInstanceFromNhxString( "something_wicked2[9]",
9430                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9431             if ( !n16.getName().equals( "something_wicked2" ) ) {
9432                 return false;
9433             }
9434             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9435                 return false;
9436             }
9437             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9438                 return false;
9439             }
9440             final PhylogenyNode n17 = PhylogenyNode
9441                     .createInstanceFromNhxString( "something_wicked3[a]",
9442                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9443             if ( !n17.getName().equals( "something_wicked3" ) ) {
9444                 return false;
9445             }
9446             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9447                 return false;
9448             }
9449             final PhylogenyNode n18 = PhylogenyNode
9450                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9451             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9452                 return false;
9453             }
9454             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9455                 return false;
9456             }
9457             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9458                 return false;
9459             }
9460             final PhylogenyNode n19 = PhylogenyNode
9461                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9462             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9463                 return false;
9464             }
9465             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9466                 return false;
9467             }
9468             final PhylogenyNode n30 = PhylogenyNode
9469                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9470                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9471             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9472                 return false;
9473             }
9474             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9475                 return false;
9476             }
9477             final PhylogenyNode n31 = PhylogenyNode
9478                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9479                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9480             if ( n31.getNodeData().isHasTaxonomy() ) {
9481                 return false;
9482             }
9483             final PhylogenyNode n32 = PhylogenyNode
9484                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9485             if ( n32.getNodeData().isHasTaxonomy() ) {
9486                 return false;
9487             }
9488             final PhylogenyNode n40 = PhylogenyNode
9489                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9490             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9491                 return false;
9492             }
9493             final PhylogenyNode n41 = PhylogenyNode
9494                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9495             if ( n41.getNodeData().isHasTaxonomy() ) {
9496                 return false;
9497             }
9498             final PhylogenyNode n42 = PhylogenyNode
9499                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9500             if ( n42.getNodeData().isHasTaxonomy() ) {
9501                 return false;
9502             }
9503             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9504                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9505             if ( n43.getNodeData().isHasTaxonomy() ) {
9506                 return false;
9507             }
9508             final PhylogenyNode n44 = PhylogenyNode
9509                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9510             if ( n44.getNodeData().isHasTaxonomy() ) {
9511                 return false;
9512             }
9513         }
9514         catch ( final Exception e ) {
9515             e.printStackTrace( System.out );
9516             return false;
9517         }
9518         return true;
9519     }
9520
9521     private static boolean testNHXParsing() {
9522         try {
9523             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9524             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9525             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9526                 return false;
9527             }
9528             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]";
9529             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9530             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9531                 return false;
9532             }
9533             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]";
9534             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9535             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9536                 return false;
9537             }
9538             final Phylogeny[] p3 = factory
9539                     .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]",
9540                              new NHXParser() );
9541             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9542                 return false;
9543             }
9544             final Phylogeny[] p4 = factory
9545                     .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(]",
9546                              new NHXParser() );
9547             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9548                 return false;
9549             }
9550             final Phylogeny[] p5 = factory
9551                     .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(((]",
9552                              new NHXParser() );
9553             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9554                 return false;
9555             }
9556             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)";
9557             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)";
9558             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9559             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9560                 return false;
9561             }
9562             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)))";
9563             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)))";
9564             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9565             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9566                 return false;
9567             }
9568             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])   ))[,,, ])))))))";
9569             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9570             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9571             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9572                 return false;
9573             }
9574             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9575             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9576                 return false;
9577             }
9578             final Phylogeny p10 = factory
9579                     .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]",
9580                              new NHXParser() )[ 0 ];
9581             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9582                 return false;
9583             }
9584             final Phylogeny p11 = factory
9585                     .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]",
9586                              new NHXParser() )[ 0 ];
9587             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9588                 return false;
9589             }
9590             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]",
9591                                                   new NHXParser() )[ 0 ];
9592             if ( !p12.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9593                 return false;
9594             }
9595         }
9596         catch ( final Exception e ) {
9597             e.printStackTrace( System.out );
9598             return false;
9599         }
9600         return true;
9601     }
9602
9603     private static boolean testNHXParsingMB() {
9604         try {
9605             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9606             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9607                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9608                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9609                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9610                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9611                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9612                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9613                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9614                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9615             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9616                 return false;
9617             }
9618             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9619                 return false;
9620             }
9621             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9622                            0.1100000000000000e+00 ) ) {
9623                 return false;
9624             }
9625             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9626                 return false;
9627             }
9628             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9629                 return false;
9630             }
9631             final Phylogeny p2 = factory
9632                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9633                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9634                             + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9635                             + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9636                             + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9637                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9638                             + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9639                             + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9640                             + "7.369400000000000e-02}])",
9641                             new NHXParser() )[ 0 ];
9642             if ( p2.getNode( "1" ) == null ) {
9643                 return false;
9644             }
9645             if ( p2.getNode( "2" ) == null ) {
9646                 return false;
9647             }
9648         }
9649         catch ( final Exception e ) {
9650             e.printStackTrace( System.out );
9651             System.exit( -1 );
9652             return false;
9653         }
9654         return true;
9655     }
9656
9657     private static boolean testNHXParsingQuotes() {
9658         try {
9659             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9660             final NHXParser p = new NHXParser();
9661             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9662             if ( phylogenies_0.length != 5 ) {
9663                 return false;
9664             }
9665             final Phylogeny phy = phylogenies_0[ 4 ];
9666             if ( phy.getNumberOfExternalNodes() != 7 ) {
9667                 return false;
9668             }
9669             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9670                 return false;
9671             }
9672             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9673                 return false;
9674             }
9675             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9676                     .getScientificName().equals( "hsapiens" ) ) {
9677                 return false;
9678             }
9679             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9680                 return false;
9681             }
9682             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9683                 return false;
9684             }
9685             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9686                 return false;
9687             }
9688             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9689                 return false;
9690             }
9691             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9692                 return false;
9693             }
9694             final NHXParser p1p = new NHXParser();
9695             p1p.setIgnoreQuotes( true );
9696             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9697             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9698                 return false;
9699             }
9700             final NHXParser p2p = new NHXParser();
9701             p1p.setIgnoreQuotes( false );
9702             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9703             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9704                 return false;
9705             }
9706             final NHXParser p3p = new NHXParser();
9707             p3p.setIgnoreQuotes( false );
9708             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9709             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9710                 return false;
9711             }
9712             final NHXParser p4p = new NHXParser();
9713             p4p.setIgnoreQuotes( false );
9714             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9715             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9716                 return false;
9717             }
9718             final Phylogeny p10 = factory
9719                     .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]",
9720                              new NHXParser() )[ 0 ];
9721             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]";
9722             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9723                 return false;
9724             }
9725             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9726             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9727                 return false;
9728             }
9729             final Phylogeny p12 = factory
9730                     .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]",
9731                              new NHXParser() )[ 0 ];
9732             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]";
9733             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9734                 return false;
9735             }
9736             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9737             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9738                 return false;
9739             }
9740             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;";
9741             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9742                 return false;
9743             }
9744             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9745             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9746                 return false;
9747             }
9748         }
9749         catch ( final Exception e ) {
9750             e.printStackTrace( System.out );
9751             return false;
9752         }
9753         return true;
9754     }
9755
9756     private static boolean testNodeRemoval() {
9757         try {
9758             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9759             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9760             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9761             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9762                 return false;
9763             }
9764             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9765             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9766             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9767                 return false;
9768             }
9769             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9770             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9771             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9772                 return false;
9773             }
9774         }
9775         catch ( final Exception e ) {
9776             e.printStackTrace( System.out );
9777             return false;
9778         }
9779         return true;
9780     }
9781
9782     private static boolean testPhylogenyBranch() {
9783         try {
9784             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9785             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9786             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9787             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9788             if ( !a1b1.equals( a1b1 ) ) {
9789                 return false;
9790             }
9791             if ( !a1b1.equals( b1a1 ) ) {
9792                 return false;
9793             }
9794             if ( !b1a1.equals( a1b1 ) ) {
9795                 return false;
9796             }
9797             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9798             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9799             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9800             if ( a1_b1.equals( b1_a1 ) ) {
9801                 return false;
9802             }
9803             if ( a1_b1.equals( a1_b1_ ) ) {
9804                 return false;
9805             }
9806             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9807             if ( !a1_b1.equals( b1_a1_ ) ) {
9808                 return false;
9809             }
9810             if ( a1_b1_.equals( b1_a1_ ) ) {
9811                 return false;
9812             }
9813             if ( !a1_b1_.equals( b1_a1 ) ) {
9814                 return false;
9815             }
9816         }
9817         catch ( final Exception e ) {
9818             e.printStackTrace( System.out );
9819             return false;
9820         }
9821         return true;
9822     }
9823
9824     private static boolean testPhyloXMLparsingOfDistributionElement() {
9825         try {
9826             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9827             PhyloXmlParser xml_parser = null;
9828             try {
9829                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9830             }
9831             catch ( final Exception e ) {
9832                 // Do nothing -- means were not running from jar.
9833             }
9834             if ( xml_parser == null ) {
9835                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9836                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9837                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9838                 }
9839                 else {
9840                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9841                 }
9842             }
9843             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9844                                                               xml_parser );
9845             if ( xml_parser.getErrorCount() > 0 ) {
9846                 System.out.println( xml_parser.getErrorMessages().toString() );
9847                 return false;
9848             }
9849             if ( phylogenies_0.length != 1 ) {
9850                 return false;
9851             }
9852             final Phylogeny t1 = phylogenies_0[ 0 ];
9853             PhylogenyNode n = null;
9854             Distribution d = null;
9855             n = t1.getNode( "root node" );
9856             if ( !n.getNodeData().isHasDistribution() ) {
9857                 return false;
9858             }
9859             if ( n.getNodeData().getDistributions().size() != 1 ) {
9860                 return false;
9861             }
9862             d = n.getNodeData().getDistribution();
9863             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9864                 return false;
9865             }
9866             if ( d.getPoints().size() != 1 ) {
9867                 return false;
9868             }
9869             if ( d.getPolygons() != null ) {
9870                 return false;
9871             }
9872             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9873                 return false;
9874             }
9875             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9876                 return false;
9877             }
9878             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9879                 return false;
9880             }
9881             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9882                 return false;
9883             }
9884             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9885                 return false;
9886             }
9887             n = t1.getNode( "node a" );
9888             if ( !n.getNodeData().isHasDistribution() ) {
9889                 return false;
9890             }
9891             if ( n.getNodeData().getDistributions().size() != 2 ) {
9892                 return false;
9893             }
9894             d = n.getNodeData().getDistribution( 1 );
9895             if ( !d.getDesc().equals( "San Diego" ) ) {
9896                 return false;
9897             }
9898             if ( d.getPoints().size() != 1 ) {
9899                 return false;
9900             }
9901             if ( d.getPolygons() != null ) {
9902                 return false;
9903             }
9904             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9905                 return false;
9906             }
9907             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9908                 return false;
9909             }
9910             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9911                 return false;
9912             }
9913             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9914                 return false;
9915             }
9916             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9917                 return false;
9918             }
9919             n = t1.getNode( "node bb" );
9920             if ( !n.getNodeData().isHasDistribution() ) {
9921                 return false;
9922             }
9923             if ( n.getNodeData().getDistributions().size() != 1 ) {
9924                 return false;
9925             }
9926             d = n.getNodeData().getDistribution( 0 );
9927             if ( d.getPoints().size() != 3 ) {
9928                 return false;
9929             }
9930             if ( d.getPolygons().size() != 2 ) {
9931                 return false;
9932             }
9933             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9934                 return false;
9935             }
9936             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9937                 return false;
9938             }
9939             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9940                 return false;
9941             }
9942             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9943                 return false;
9944             }
9945             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9946                 return false;
9947             }
9948             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9949                 return false;
9950             }
9951             Polygon p = d.getPolygons().get( 0 );
9952             if ( p.getPoints().size() != 3 ) {
9953                 return false;
9954             }
9955             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9956                 return false;
9957             }
9958             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9959                 return false;
9960             }
9961             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9962                 return false;
9963             }
9964             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9965                 return false;
9966             }
9967             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9968                 return false;
9969             }
9970             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9971                 return false;
9972             }
9973             p = d.getPolygons().get( 1 );
9974             if ( p.getPoints().size() != 3 ) {
9975                 return false;
9976             }
9977             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9978                 return false;
9979             }
9980             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9981                 return false;
9982             }
9983             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9984                 return false;
9985             }
9986             // Roundtrip:
9987             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9988             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9989             if ( rt.length != 1 ) {
9990                 return false;
9991             }
9992             final Phylogeny t1_rt = rt[ 0 ];
9993             n = t1_rt.getNode( "root node" );
9994             if ( !n.getNodeData().isHasDistribution() ) {
9995                 return false;
9996             }
9997             if ( n.getNodeData().getDistributions().size() != 1 ) {
9998                 return false;
9999             }
10000             d = n.getNodeData().getDistribution();
10001             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10002                 return false;
10003             }
10004             if ( d.getPoints().size() != 1 ) {
10005                 return false;
10006             }
10007             if ( d.getPolygons() != null ) {
10008                 return false;
10009             }
10010             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10011                 return false;
10012             }
10013             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10014                 return false;
10015             }
10016             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10017                 return false;
10018             }
10019             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10020                 return false;
10021             }
10022             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10023                 return false;
10024             }
10025             n = t1_rt.getNode( "node a" );
10026             if ( !n.getNodeData().isHasDistribution() ) {
10027                 return false;
10028             }
10029             if ( n.getNodeData().getDistributions().size() != 2 ) {
10030                 return false;
10031             }
10032             d = n.getNodeData().getDistribution( 1 );
10033             if ( !d.getDesc().equals( "San Diego" ) ) {
10034                 return false;
10035             }
10036             if ( d.getPoints().size() != 1 ) {
10037                 return false;
10038             }
10039             if ( d.getPolygons() != null ) {
10040                 return false;
10041             }
10042             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10043                 return false;
10044             }
10045             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10046                 return false;
10047             }
10048             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10049                 return false;
10050             }
10051             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10052                 return false;
10053             }
10054             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10055                 return false;
10056             }
10057             n = t1_rt.getNode( "node bb" );
10058             if ( !n.getNodeData().isHasDistribution() ) {
10059                 return false;
10060             }
10061             if ( n.getNodeData().getDistributions().size() != 1 ) {
10062                 return false;
10063             }
10064             d = n.getNodeData().getDistribution( 0 );
10065             if ( d.getPoints().size() != 3 ) {
10066                 return false;
10067             }
10068             if ( d.getPolygons().size() != 2 ) {
10069                 return false;
10070             }
10071             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10072                 return false;
10073             }
10074             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10075                 return false;
10076             }
10077             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10078                 return false;
10079             }
10080             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10081                 return false;
10082             }
10083             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10084                 return false;
10085             }
10086             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10087                 return false;
10088             }
10089             p = d.getPolygons().get( 0 );
10090             if ( p.getPoints().size() != 3 ) {
10091                 return false;
10092             }
10093             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10094                 return false;
10095             }
10096             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10097                 return false;
10098             }
10099             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10100                 return false;
10101             }
10102             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10103                 return false;
10104             }
10105             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10106                 return false;
10107             }
10108             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10109                 return false;
10110             }
10111             p = d.getPolygons().get( 1 );
10112             if ( p.getPoints().size() != 3 ) {
10113                 return false;
10114             }
10115             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10116                 return false;
10117             }
10118             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10119                 return false;
10120             }
10121             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10122                 return false;
10123             }
10124         }
10125         catch ( final Exception e ) {
10126             e.printStackTrace( System.out );
10127             return false;
10128         }
10129         return true;
10130     }
10131
10132     private static boolean testPostOrderIterator() {
10133         try {
10134             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10135             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10136             PhylogenyNodeIterator it0;
10137             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
10138                 it0.next();
10139             }
10140             for( it0.reset(); it0.hasNext(); ) {
10141                 it0.next();
10142             }
10143             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10144             final PhylogenyNodeIterator it = t1.iteratorPostorder();
10145             if ( !it.next().getName().equals( "A" ) ) {
10146                 return false;
10147             }
10148             if ( !it.next().getName().equals( "B" ) ) {
10149                 return false;
10150             }
10151             if ( !it.next().getName().equals( "ab" ) ) {
10152                 return false;
10153             }
10154             if ( !it.next().getName().equals( "C" ) ) {
10155                 return false;
10156             }
10157             if ( !it.next().getName().equals( "D" ) ) {
10158                 return false;
10159             }
10160             if ( !it.next().getName().equals( "cd" ) ) {
10161                 return false;
10162             }
10163             if ( !it.next().getName().equals( "abcd" ) ) {
10164                 return false;
10165             }
10166             if ( !it.next().getName().equals( "E" ) ) {
10167                 return false;
10168             }
10169             if ( !it.next().getName().equals( "F" ) ) {
10170                 return false;
10171             }
10172             if ( !it.next().getName().equals( "ef" ) ) {
10173                 return false;
10174             }
10175             if ( !it.next().getName().equals( "G" ) ) {
10176                 return false;
10177             }
10178             if ( !it.next().getName().equals( "H" ) ) {
10179                 return false;
10180             }
10181             if ( !it.next().getName().equals( "gh" ) ) {
10182                 return false;
10183             }
10184             if ( !it.next().getName().equals( "efgh" ) ) {
10185                 return false;
10186             }
10187             if ( !it.next().getName().equals( "r" ) ) {
10188                 return false;
10189             }
10190             if ( it.hasNext() ) {
10191                 return false;
10192             }
10193         }
10194         catch ( final Exception e ) {
10195             e.printStackTrace( System.out );
10196             return false;
10197         }
10198         return true;
10199     }
10200
10201     private static boolean testPreOrderIterator() {
10202         try {
10203             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10204             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10205             PhylogenyNodeIterator it0;
10206             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10207                 it0.next();
10208             }
10209             for( it0.reset(); it0.hasNext(); ) {
10210                 it0.next();
10211             }
10212             PhylogenyNodeIterator it = t0.iteratorPreorder();
10213             if ( !it.next().getName().equals( "r" ) ) {
10214                 return false;
10215             }
10216             if ( !it.next().getName().equals( "ab" ) ) {
10217                 return false;
10218             }
10219             if ( !it.next().getName().equals( "A" ) ) {
10220                 return false;
10221             }
10222             if ( !it.next().getName().equals( "B" ) ) {
10223                 return false;
10224             }
10225             if ( !it.next().getName().equals( "cd" ) ) {
10226                 return false;
10227             }
10228             if ( !it.next().getName().equals( "C" ) ) {
10229                 return false;
10230             }
10231             if ( !it.next().getName().equals( "D" ) ) {
10232                 return false;
10233             }
10234             if ( it.hasNext() ) {
10235                 return false;
10236             }
10237             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10238             it = t1.iteratorPreorder();
10239             if ( !it.next().getName().equals( "r" ) ) {
10240                 return false;
10241             }
10242             if ( !it.next().getName().equals( "abcd" ) ) {
10243                 return false;
10244             }
10245             if ( !it.next().getName().equals( "ab" ) ) {
10246                 return false;
10247             }
10248             if ( !it.next().getName().equals( "A" ) ) {
10249                 return false;
10250             }
10251             if ( !it.next().getName().equals( "B" ) ) {
10252                 return false;
10253             }
10254             if ( !it.next().getName().equals( "cd" ) ) {
10255                 return false;
10256             }
10257             if ( !it.next().getName().equals( "C" ) ) {
10258                 return false;
10259             }
10260             if ( !it.next().getName().equals( "D" ) ) {
10261                 return false;
10262             }
10263             if ( !it.next().getName().equals( "efgh" ) ) {
10264                 return false;
10265             }
10266             if ( !it.next().getName().equals( "ef" ) ) {
10267                 return false;
10268             }
10269             if ( !it.next().getName().equals( "E" ) ) {
10270                 return false;
10271             }
10272             if ( !it.next().getName().equals( "F" ) ) {
10273                 return false;
10274             }
10275             if ( !it.next().getName().equals( "gh" ) ) {
10276                 return false;
10277             }
10278             if ( !it.next().getName().equals( "G" ) ) {
10279                 return false;
10280             }
10281             if ( !it.next().getName().equals( "H" ) ) {
10282                 return false;
10283             }
10284             if ( it.hasNext() ) {
10285                 return false;
10286             }
10287         }
10288         catch ( final Exception e ) {
10289             e.printStackTrace( System.out );
10290             return false;
10291         }
10292         return true;
10293     }
10294
10295     private static boolean testPropertiesMap() {
10296         try {
10297             final PropertiesMap pm = new PropertiesMap();
10298             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10299             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10300             final Property p2 = new Property( "something:else",
10301                                               "?",
10302                                               "improbable:research",
10303                                               "xsd:decimal",
10304                                               AppliesTo.NODE );
10305             pm.addProperty( p0 );
10306             pm.addProperty( p1 );
10307             pm.addProperty( p2 );
10308             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10309                 return false;
10310             }
10311             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10312                 return false;
10313             }
10314             if ( pm.getProperties().size() != 3 ) {
10315                 return false;
10316             }
10317             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10318                 return false;
10319             }
10320             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10321                 return false;
10322             }
10323             if ( pm.getProperties().size() != 3 ) {
10324                 return false;
10325             }
10326             pm.removeProperty( "dimensions:diameter" );
10327             if ( pm.getProperties().size() != 2 ) {
10328                 return false;
10329             }
10330             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10331                 return false;
10332             }
10333             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10334                 return false;
10335             }
10336         }
10337         catch ( final Exception e ) {
10338             e.printStackTrace( System.out );
10339             return false;
10340         }
10341         return true;
10342     }
10343
10344     private static boolean testProteinId() {
10345         try {
10346             final ProteinId id1 = new ProteinId( "a" );
10347             final ProteinId id2 = new ProteinId( "a" );
10348             final ProteinId id3 = new ProteinId( "A" );
10349             final ProteinId id4 = new ProteinId( "b" );
10350             if ( !id1.equals( id1 ) ) {
10351                 return false;
10352             }
10353             if ( id1.getId().equals( "x" ) ) {
10354                 return false;
10355             }
10356             if ( id1.getId().equals( null ) ) {
10357                 return false;
10358             }
10359             if ( !id1.equals( id2 ) ) {
10360                 return false;
10361             }
10362             if ( id1.equals( id3 ) ) {
10363                 return false;
10364             }
10365             if ( id1.hashCode() != id1.hashCode() ) {
10366                 return false;
10367             }
10368             if ( id1.hashCode() != id2.hashCode() ) {
10369                 return false;
10370             }
10371             if ( id1.hashCode() == id3.hashCode() ) {
10372                 return false;
10373             }
10374             if ( id1.compareTo( id1 ) != 0 ) {
10375                 return false;
10376             }
10377             if ( id1.compareTo( id2 ) != 0 ) {
10378                 return false;
10379             }
10380             if ( id1.compareTo( id3 ) != 0 ) {
10381                 return false;
10382             }
10383             if ( id1.compareTo( id4 ) >= 0 ) {
10384                 return false;
10385             }
10386             if ( id4.compareTo( id1 ) <= 0 ) {
10387                 return false;
10388             }
10389             if ( !id4.getId().equals( "b" ) ) {
10390                 return false;
10391             }
10392             final ProteinId id5 = new ProteinId( " C " );
10393             if ( !id5.getId().equals( "C" ) ) {
10394                 return false;
10395             }
10396             if ( id5.equals( id1 ) ) {
10397                 return false;
10398             }
10399         }
10400         catch ( final Exception e ) {
10401             e.printStackTrace( System.out );
10402             return false;
10403         }
10404         return true;
10405     }
10406
10407     private static boolean testReIdMethods() {
10408         try {
10409             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10410             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10411             final long count = PhylogenyNode.getNodeCount();
10412             p.levelOrderReID();
10413             if ( p.getNode( "r" ).getId() != count ) {
10414                 return false;
10415             }
10416             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10417                 return false;
10418             }
10419             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10420                 return false;
10421             }
10422             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10423                 return false;
10424             }
10425             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10426                 return false;
10427             }
10428             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10429                 return false;
10430             }
10431             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10432                 return false;
10433             }
10434             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10435                 return false;
10436             }
10437             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10438                 return false;
10439             }
10440             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10441                 return false;
10442             }
10443             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10444                 return false;
10445             }
10446             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10447                 return false;
10448             }
10449             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10450                 return false;
10451             }
10452             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10453                 return false;
10454             }
10455             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10456                 return false;
10457             }
10458         }
10459         catch ( final Exception e ) {
10460             e.printStackTrace( System.out );
10461             return false;
10462         }
10463         return true;
10464     }
10465
10466     private static boolean testRerooting() {
10467         try {
10468             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10469             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",
10470                                                  new NHXParser() )[ 0 ];
10471             if ( !t1.isRooted() ) {
10472                 return false;
10473             }
10474             t1.reRoot( t1.getNode( "D" ) );
10475             t1.reRoot( t1.getNode( "CD" ) );
10476             t1.reRoot( t1.getNode( "A" ) );
10477             t1.reRoot( t1.getNode( "B" ) );
10478             t1.reRoot( t1.getNode( "AB" ) );
10479             t1.reRoot( t1.getNode( "D" ) );
10480             t1.reRoot( t1.getNode( "C" ) );
10481             t1.reRoot( t1.getNode( "CD" ) );
10482             t1.reRoot( t1.getNode( "A" ) );
10483             t1.reRoot( t1.getNode( "B" ) );
10484             t1.reRoot( t1.getNode( "AB" ) );
10485             t1.reRoot( t1.getNode( "D" ) );
10486             t1.reRoot( t1.getNode( "D" ) );
10487             t1.reRoot( t1.getNode( "C" ) );
10488             t1.reRoot( t1.getNode( "A" ) );
10489             t1.reRoot( t1.getNode( "B" ) );
10490             t1.reRoot( t1.getNode( "AB" ) );
10491             t1.reRoot( t1.getNode( "C" ) );
10492             t1.reRoot( t1.getNode( "D" ) );
10493             t1.reRoot( t1.getNode( "CD" ) );
10494             t1.reRoot( t1.getNode( "D" ) );
10495             t1.reRoot( t1.getNode( "A" ) );
10496             t1.reRoot( t1.getNode( "B" ) );
10497             t1.reRoot( t1.getNode( "AB" ) );
10498             t1.reRoot( t1.getNode( "C" ) );
10499             t1.reRoot( t1.getNode( "D" ) );
10500             t1.reRoot( t1.getNode( "CD" ) );
10501             t1.reRoot( t1.getNode( "D" ) );
10502             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10503                 return false;
10504             }
10505             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10506                 return false;
10507             }
10508             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10509                 return false;
10510             }
10511             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10512                 return false;
10513             }
10514             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10515                 return false;
10516             }
10517             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10518                 return false;
10519             }
10520             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",
10521                                                  new NHXParser() )[ 0 ];
10522             t2.reRoot( t2.getNode( "A" ) );
10523             t2.reRoot( t2.getNode( "D" ) );
10524             t2.reRoot( t2.getNode( "ABC" ) );
10525             t2.reRoot( t2.getNode( "A" ) );
10526             t2.reRoot( t2.getNode( "B" ) );
10527             t2.reRoot( t2.getNode( "D" ) );
10528             t2.reRoot( t2.getNode( "C" ) );
10529             t2.reRoot( t2.getNode( "ABC" ) );
10530             t2.reRoot( t2.getNode( "A" ) );
10531             t2.reRoot( t2.getNode( "B" ) );
10532             t2.reRoot( t2.getNode( "AB" ) );
10533             t2.reRoot( t2.getNode( "AB" ) );
10534             t2.reRoot( t2.getNode( "D" ) );
10535             t2.reRoot( t2.getNode( "C" ) );
10536             t2.reRoot( t2.getNode( "B" ) );
10537             t2.reRoot( t2.getNode( "AB" ) );
10538             t2.reRoot( t2.getNode( "D" ) );
10539             t2.reRoot( t2.getNode( "D" ) );
10540             t2.reRoot( t2.getNode( "ABC" ) );
10541             t2.reRoot( t2.getNode( "A" ) );
10542             t2.reRoot( t2.getNode( "B" ) );
10543             t2.reRoot( t2.getNode( "AB" ) );
10544             t2.reRoot( t2.getNode( "D" ) );
10545             t2.reRoot( t2.getNode( "C" ) );
10546             t2.reRoot( t2.getNode( "ABC" ) );
10547             t2.reRoot( t2.getNode( "A" ) );
10548             t2.reRoot( t2.getNode( "B" ) );
10549             t2.reRoot( t2.getNode( "AB" ) );
10550             t2.reRoot( t2.getNode( "D" ) );
10551             t2.reRoot( t2.getNode( "D" ) );
10552             t2.reRoot( t2.getNode( "C" ) );
10553             t2.reRoot( t2.getNode( "A" ) );
10554             t2.reRoot( t2.getNode( "B" ) );
10555             t2.reRoot( t2.getNode( "AB" ) );
10556             t2.reRoot( t2.getNode( "C" ) );
10557             t2.reRoot( t2.getNode( "D" ) );
10558             t2.reRoot( t2.getNode( "ABC" ) );
10559             t2.reRoot( t2.getNode( "D" ) );
10560             t2.reRoot( t2.getNode( "A" ) );
10561             t2.reRoot( t2.getNode( "B" ) );
10562             t2.reRoot( t2.getNode( "AB" ) );
10563             t2.reRoot( t2.getNode( "C" ) );
10564             t2.reRoot( t2.getNode( "D" ) );
10565             t2.reRoot( t2.getNode( "ABC" ) );
10566             t2.reRoot( t2.getNode( "D" ) );
10567             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10568                 return false;
10569             }
10570             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10571                 return false;
10572             }
10573             t2.reRoot( t2.getNode( "ABC" ) );
10574             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10575                 return false;
10576             }
10577             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10578                 return false;
10579             }
10580             t2.reRoot( t2.getNode( "AB" ) );
10581             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10582                 return false;
10583             }
10584             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10585                 return false;
10586             }
10587             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10588                 return false;
10589             }
10590             t2.reRoot( t2.getNode( "AB" ) );
10591             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10592                 return false;
10593             }
10594             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10595                 return false;
10596             }
10597             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10598                 return false;
10599             }
10600             t2.reRoot( t2.getNode( "D" ) );
10601             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10602                 return false;
10603             }
10604             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10605                 return false;
10606             }
10607             t2.reRoot( t2.getNode( "ABC" ) );
10608             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10609                 return false;
10610             }
10611             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10612                 return false;
10613             }
10614             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10615                                                  new NHXParser() )[ 0 ];
10616             t3.reRoot( t3.getNode( "B" ) );
10617             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10618                 return false;
10619             }
10620             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10621                 return false;
10622             }
10623             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10624                 return false;
10625             }
10626             t3.reRoot( t3.getNode( "B" ) );
10627             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10628                 return false;
10629             }
10630             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10631                 return false;
10632             }
10633             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10634                 return false;
10635             }
10636             t3.reRoot( t3.getRoot() );
10637             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10638                 return false;
10639             }
10640             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10641                 return false;
10642             }
10643             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10644                 return false;
10645             }
10646         }
10647         catch ( final Exception e ) {
10648             e.printStackTrace( System.out );
10649             return false;
10650         }
10651         return true;
10652     }
10653
10654     private static boolean testSDIse() {
10655         try {
10656             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10657             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10658             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10659             gene1.setRooted( true );
10660             species1.setRooted( true );
10661             final SDI sdi = new SDI( gene1, species1 );
10662             if ( !gene1.getRoot().isDuplication() ) {
10663                 return false;
10664             }
10665             final Phylogeny species2 = factory
10666                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10667                              new NHXParser() )[ 0 ];
10668             final Phylogeny gene2 = factory
10669                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10670                              new NHXParser() )[ 0 ];
10671             species2.setRooted( true );
10672             gene2.setRooted( true );
10673             final SDI sdi2 = new SDI( gene2, species2 );
10674             if ( sdi2.getDuplicationsSum() != 0 ) {
10675                 return false;
10676             }
10677             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10678                 return false;
10679             }
10680             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10681                 return false;
10682             }
10683             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10684                 return false;
10685             }
10686             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10687                 return false;
10688             }
10689             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10690                 return false;
10691             }
10692             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10693                 return false;
10694             }
10695             final Phylogeny species3 = factory
10696                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10697                              new NHXParser() )[ 0 ];
10698             final Phylogeny gene3 = factory
10699                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10700                              new NHXParser() )[ 0 ];
10701             species3.setRooted( true );
10702             gene3.setRooted( true );
10703             final SDI sdi3 = new SDI( gene3, species3 );
10704             if ( sdi3.getDuplicationsSum() != 1 ) {
10705                 return false;
10706             }
10707             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10708                 return false;
10709             }
10710             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10711                 return false;
10712             }
10713             final Phylogeny species4 = factory
10714                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10715                              new NHXParser() )[ 0 ];
10716             final Phylogeny gene4 = factory
10717                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10718                              new NHXParser() )[ 0 ];
10719             species4.setRooted( true );
10720             gene4.setRooted( true );
10721             final SDI sdi4 = new SDI( gene4, species4 );
10722             if ( sdi4.getDuplicationsSum() != 1 ) {
10723                 return false;
10724             }
10725             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10726                 return false;
10727             }
10728             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10729                 return false;
10730             }
10731             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10732                 return false;
10733             }
10734             if ( species4.getNumberOfExternalNodes() != 6 ) {
10735                 return false;
10736             }
10737             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10738                 return false;
10739             }
10740             final Phylogeny species5 = factory
10741                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10742                              new NHXParser() )[ 0 ];
10743             final Phylogeny gene5 = factory
10744                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10745                              new NHXParser() )[ 0 ];
10746             species5.setRooted( true );
10747             gene5.setRooted( true );
10748             final SDI sdi5 = new SDI( gene5, species5 );
10749             if ( sdi5.getDuplicationsSum() != 2 ) {
10750                 return false;
10751             }
10752             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10753                 return false;
10754             }
10755             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10756                 return false;
10757             }
10758             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10759                 return false;
10760             }
10761             if ( species5.getNumberOfExternalNodes() != 6 ) {
10762                 return false;
10763             }
10764             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10765                 return false;
10766             }
10767             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10768             // Conjecture for Comparing Molecular Phylogenies"
10769             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10770             final Phylogeny species6 = factory
10771                     .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,"
10772                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10773                             new NHXParser() )[ 0 ];
10774             final Phylogeny gene6 = factory
10775                     .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,"
10776                             + "((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,"
10777                             + "(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;",
10778                             new NHXParser() )[ 0 ];
10779             species6.setRooted( true );
10780             gene6.setRooted( true );
10781             final SDI sdi6 = new SDI( gene6, species6 );
10782             if ( sdi6.getDuplicationsSum() != 3 ) {
10783                 return false;
10784             }
10785             if ( !gene6.getNode( "r" ).isDuplication() ) {
10786                 return false;
10787             }
10788             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10789                 return false;
10790             }
10791             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10792                 return false;
10793             }
10794             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10795                 return false;
10796             }
10797             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10798                 return false;
10799             }
10800             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10801                 return false;
10802             }
10803             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10804                 return false;
10805             }
10806             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10807                 return false;
10808             }
10809             sdi6.computeMappingCostL();
10810             if ( sdi6.computeMappingCostL() != 17 ) {
10811                 return false;
10812             }
10813             if ( species6.getNumberOfExternalNodes() != 9 ) {
10814                 return false;
10815             }
10816             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10817                 return false;
10818             }
10819             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10820                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10821                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10822                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10823                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10824             species7.setRooted( true );
10825             final Phylogeny gene7_1 = Test
10826                     .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])" );
10827             gene7_1.setRooted( true );
10828             final SDI sdi7 = new SDI( gene7_1, species7 );
10829             if ( sdi7.getDuplicationsSum() != 0 ) {
10830                 return false;
10831             }
10832             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10833                 return false;
10834             }
10835             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10836                 return false;
10837             }
10838             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10839                 return false;
10840             }
10841             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10842                 return false;
10843             }
10844             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10845                 return false;
10846             }
10847             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10848                 return false;
10849             }
10850             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10851                 return false;
10852             }
10853             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10854                 return false;
10855             }
10856             final Phylogeny gene7_2 = Test
10857                     .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])" );
10858             gene7_2.setRooted( true );
10859             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10860             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10861                 return false;
10862             }
10863             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10864                 return false;
10865             }
10866             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10867                 return false;
10868             }
10869             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10870                 return false;
10871             }
10872             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10873                 return false;
10874             }
10875             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10876                 return false;
10877             }
10878             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10879                 return false;
10880             }
10881             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10882                 return false;
10883             }
10884             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10885                 return false;
10886             }
10887             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10888                 return false;
10889             }
10890         }
10891         catch ( final Exception e ) {
10892             return false;
10893         }
10894         return true;
10895     }
10896
10897     private static boolean testSDIunrooted() {
10898         try {
10899             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10900             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10901             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10902             final Iterator<PhylogenyBranch> iter = l.iterator();
10903             PhylogenyBranch br = iter.next();
10904             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10905                 return false;
10906             }
10907             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10908                 return false;
10909             }
10910             br = iter.next();
10911             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10912                 return false;
10913             }
10914             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10915                 return false;
10916             }
10917             br = iter.next();
10918             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10919                 return false;
10920             }
10921             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10922                 return false;
10923             }
10924             br = iter.next();
10925             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10926                 return false;
10927             }
10928             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10929                 return false;
10930             }
10931             br = iter.next();
10932             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10933                 return false;
10934             }
10935             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10936                 return false;
10937             }
10938             br = iter.next();
10939             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10940                 return false;
10941             }
10942             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10943                 return false;
10944             }
10945             br = iter.next();
10946             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10947                 return false;
10948             }
10949             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10950                 return false;
10951             }
10952             br = iter.next();
10953             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10954                 return false;
10955             }
10956             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10957                 return false;
10958             }
10959             br = iter.next();
10960             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10961                 return false;
10962             }
10963             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10964                 return false;
10965             }
10966             br = iter.next();
10967             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10968                 return false;
10969             }
10970             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10971                 return false;
10972             }
10973             br = iter.next();
10974             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10975                 return false;
10976             }
10977             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10978                 return false;
10979             }
10980             br = iter.next();
10981             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10982                 return false;
10983             }
10984             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10985                 return false;
10986             }
10987             br = iter.next();
10988             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10989                 return false;
10990             }
10991             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10992                 return false;
10993             }
10994             br = iter.next();
10995             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10996                 return false;
10997             }
10998             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10999                 return false;
11000             }
11001             br = iter.next();
11002             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
11003                 return false;
11004             }
11005             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
11006                 return false;
11007             }
11008             if ( iter.hasNext() ) {
11009                 return false;
11010             }
11011             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
11012             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
11013             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
11014             br = iter1.next();
11015             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11016                 return false;
11017             }
11018             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11019                 return false;
11020             }
11021             br = iter1.next();
11022             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11023                 return false;
11024             }
11025             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11026                 return false;
11027             }
11028             br = iter1.next();
11029             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11030                 return false;
11031             }
11032             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11033                 return false;
11034             }
11035             if ( iter1.hasNext() ) {
11036                 return false;
11037             }
11038             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
11039             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
11040             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
11041             br = iter2.next();
11042             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11043                 return false;
11044             }
11045             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11046                 return false;
11047             }
11048             br = iter2.next();
11049             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11050                 return false;
11051             }
11052             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11053                 return false;
11054             }
11055             br = iter2.next();
11056             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11057                 return false;
11058             }
11059             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11060                 return false;
11061             }
11062             if ( iter2.hasNext() ) {
11063                 return false;
11064             }
11065             final Phylogeny species0 = factory
11066                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11067                              new NHXParser() )[ 0 ];
11068             final Phylogeny gene1 = factory
11069                     .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])",
11070                              new NHXParser() )[ 0 ];
11071             species0.setRooted( true );
11072             gene1.setRooted( true );
11073             final SDIR sdi_unrooted = new SDIR();
11074             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
11075             if ( sdi_unrooted.getCount() != 1 ) {
11076                 return false;
11077             }
11078             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
11079                 return false;
11080             }
11081             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
11082                 return false;
11083             }
11084             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
11085                 return false;
11086             }
11087             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11088                 return false;
11089             }
11090             final Phylogeny gene2 = factory
11091                     .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])",
11092                              new NHXParser() )[ 0 ];
11093             gene2.setRooted( true );
11094             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
11095             if ( sdi_unrooted.getCount() != 1 ) {
11096                 return false;
11097             }
11098             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11099                 return false;
11100             }
11101             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11102                 return false;
11103             }
11104             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
11105                 return false;
11106             }
11107             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11108                 return false;
11109             }
11110             final Phylogeny species6 = factory
11111                     .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,"
11112                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11113                             new NHXParser() )[ 0 ];
11114             final Phylogeny gene6 = factory
11115                     .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],"
11116                             + "(((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],"
11117                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11118                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11119                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11120                             new NHXParser() )[ 0 ];
11121             species6.setRooted( true );
11122             gene6.setRooted( true );
11123             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
11124             if ( sdi_unrooted.getCount() != 1 ) {
11125                 return false;
11126             }
11127             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11128                 return false;
11129             }
11130             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11131                 return false;
11132             }
11133             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11134                 return false;
11135             }
11136             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11137                 return false;
11138             }
11139             if ( !p6[ 0 ].getRoot().isDuplication() ) {
11140                 return false;
11141             }
11142             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11143                 return false;
11144             }
11145             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11146                 return false;
11147             }
11148             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11149                 return false;
11150             }
11151             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11152                 return false;
11153             }
11154             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11155                 return false;
11156             }
11157             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11158                 return false;
11159             }
11160             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11161                 return false;
11162             }
11163             p6 = null;
11164             final Phylogeny species7 = factory
11165                     .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,"
11166                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11167                             new NHXParser() )[ 0 ];
11168             final Phylogeny gene7 = factory
11169                     .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],"
11170                             + "(((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],"
11171                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11172                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11173                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11174                             new NHXParser() )[ 0 ];
11175             species7.setRooted( true );
11176             gene7.setRooted( true );
11177             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11178             if ( sdi_unrooted.getCount() != 1 ) {
11179                 return false;
11180             }
11181             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11182                 return false;
11183             }
11184             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11185                 return false;
11186             }
11187             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11188                 return false;
11189             }
11190             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11191                 return false;
11192             }
11193             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11194                 return false;
11195             }
11196             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11197                 return false;
11198             }
11199             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11200                 return false;
11201             }
11202             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11203                 return false;
11204             }
11205             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11206                 return false;
11207             }
11208             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11209                 return false;
11210             }
11211             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11212                 return false;
11213             }
11214             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11215                 return false;
11216             }
11217             p7 = null;
11218             final Phylogeny species8 = factory
11219                     .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,"
11220                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11221                             new NHXParser() )[ 0 ];
11222             final Phylogeny gene8 = factory
11223                     .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],"
11224                             + "(((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],"
11225                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11226                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11227                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11228                             new NHXParser() )[ 0 ];
11229             species8.setRooted( true );
11230             gene8.setRooted( true );
11231             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11232             if ( sdi_unrooted.getCount() != 1 ) {
11233                 return false;
11234             }
11235             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11236                 return false;
11237             }
11238             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11239                 return false;
11240             }
11241             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11242                 return false;
11243             }
11244             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11245                 return false;
11246             }
11247             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11248                 return false;
11249             }
11250             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11251                 return false;
11252             }
11253             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11254                 return false;
11255             }
11256             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11257                 return false;
11258             }
11259             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11260                 return false;
11261             }
11262             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11263                 return false;
11264             }
11265             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11266                 return false;
11267             }
11268             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11269                 return false;
11270             }
11271             p8 = null;
11272         }
11273         catch ( final Exception e ) {
11274             e.printStackTrace( System.out );
11275             return false;
11276         }
11277         return true;
11278     }
11279
11280     private static boolean testSequenceDbWsTools1() {
11281         try {
11282             final PhylogenyNode n = new PhylogenyNode();
11283             n.setName( "NP_001025424" );
11284             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11285             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11286                     || !acc.getValue().equals( "NP_001025424" ) ) {
11287                 return false;
11288             }
11289             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11290             acc = SequenceDbWsTools.obtainSeqAccession( n );
11291             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11292                     || !acc.getValue().equals( "NP_001025424" ) ) {
11293                 return false;
11294             }
11295             n.setName( "NP_001025424.1" );
11296             acc = SequenceDbWsTools.obtainSeqAccession( n );
11297             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11298                     || !acc.getValue().equals( "NP_001025424" ) ) {
11299                 return false;
11300             }
11301             n.setName( "NM_001030253" );
11302             acc = SequenceDbWsTools.obtainSeqAccession( n );
11303             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11304                     || !acc.getValue().equals( "NM_001030253" ) ) {
11305                 return false;
11306             }
11307             n.setName( "BCL2_HUMAN" );
11308             acc = SequenceDbWsTools.obtainSeqAccession( n );
11309             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11310                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11311                 System.out.println( acc.toString() );
11312                 return false;
11313             }
11314             n.setName( "P10415" );
11315             acc = SequenceDbWsTools.obtainSeqAccession( n );
11316             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11317                     || !acc.getValue().equals( "P10415" ) ) {
11318                 System.out.println( acc.toString() );
11319                 return false;
11320             }
11321             n.setName( " P10415 " );
11322             acc = SequenceDbWsTools.obtainSeqAccession( n );
11323             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11324                     || !acc.getValue().equals( "P10415" ) ) {
11325                 System.out.println( acc.toString() );
11326                 return false;
11327             }
11328             n.setName( "_P10415|" );
11329             acc = SequenceDbWsTools.obtainSeqAccession( n );
11330             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11331                     || !acc.getValue().equals( "P10415" ) ) {
11332                 System.out.println( acc.toString() );
11333                 return false;
11334             }
11335             n.setName( "AY695820" );
11336             acc = SequenceDbWsTools.obtainSeqAccession( n );
11337             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11338                     || !acc.getValue().equals( "AY695820" ) ) {
11339                 System.out.println( acc.toString() );
11340                 return false;
11341             }
11342             n.setName( "_AY695820_" );
11343             acc = SequenceDbWsTools.obtainSeqAccession( n );
11344             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11345                     || !acc.getValue().equals( "AY695820" ) ) {
11346                 System.out.println( acc.toString() );
11347                 return false;
11348             }
11349             n.setName( "AAA59452" );
11350             acc = SequenceDbWsTools.obtainSeqAccession( n );
11351             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11352                     || !acc.getValue().equals( "AAA59452" ) ) {
11353                 System.out.println( acc.toString() );
11354                 return false;
11355             }
11356             n.setName( "_AAA59452_" );
11357             acc = SequenceDbWsTools.obtainSeqAccession( n );
11358             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11359                     || !acc.getValue().equals( "AAA59452" ) ) {
11360                 System.out.println( acc.toString() );
11361                 return false;
11362             }
11363             n.setName( "AAA59452.1" );
11364             acc = SequenceDbWsTools.obtainSeqAccession( n );
11365             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11366                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11367                 System.out.println( acc.toString() );
11368                 return false;
11369             }
11370             n.setName( "_AAA59452.1_" );
11371             acc = SequenceDbWsTools.obtainSeqAccession( n );
11372             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11373                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11374                 System.out.println( acc.toString() );
11375                 return false;
11376             }
11377             n.setName( "GI:94894583" );
11378             acc = SequenceDbWsTools.obtainSeqAccession( n );
11379             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11380                     || !acc.getValue().equals( "94894583" ) ) {
11381                 System.out.println( acc.toString() );
11382                 return false;
11383             }
11384             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11385             acc = SequenceDbWsTools.obtainSeqAccession( n );
11386             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11387                     || !acc.getValue().equals( "71845847" ) ) {
11388                 System.out.println( acc.toString() );
11389                 return false;
11390             }
11391             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11392             acc = SequenceDbWsTools.obtainSeqAccession( n );
11393             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11394                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11395                 System.out.println( acc.toString() );
11396                 return false;
11397             }
11398         }
11399         catch ( final Exception e ) {
11400             return false;
11401         }
11402         return true;
11403     }
11404
11405     private static boolean testSequenceDbWsTools2() {
11406         try {
11407             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11408             SequenceDbWsTools.obtainSeqInformation( n1 );
11409             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11410                 return false;
11411             }
11412             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11413                 return false;
11414             }
11415             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11416                 return false;
11417             }
11418             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11419                 return false;
11420             }
11421             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11422             SequenceDbWsTools.obtainSeqInformation( n2 );
11423             if ( !n2.getNodeData().getSequence().getName().equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
11424                 return false;
11425             }
11426             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11427                 return false;
11428             }
11429             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11430                 return false;
11431             }
11432             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11433                 return false;
11434             }
11435             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11436             SequenceDbWsTools.obtainSeqInformation( n3 );
11437             if ( !n3.getNodeData().getSequence().getName()
11438                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11439                 return false;
11440             }
11441             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11442                 return false;
11443             }
11444             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11445                 return false;
11446             }
11447             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11448                 return false;
11449             }
11450         }
11451         catch ( final IOException e ) {
11452             System.out.println();
11453             System.out.println( "the following might be due to absence internet connection:" );
11454             e.printStackTrace( System.out );
11455             return true;
11456         }
11457         catch ( final Exception e ) {
11458             e.printStackTrace();
11459             return false;
11460         }
11461         return true;
11462     }
11463
11464     private static boolean testSequenceIdParsing() {
11465         try {
11466             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11467             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11468                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11469                 if ( id != null ) {
11470                     System.out.println( "value   =" + id.getValue() );
11471                     System.out.println( "provider=" + id.getSource() );
11472                 }
11473                 return false;
11474             }
11475             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11476             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11477                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11478                 if ( id != null ) {
11479                     System.out.println( "value   =" + id.getValue() );
11480                     System.out.println( "provider=" + id.getSource() );
11481                 }
11482                 return false;
11483             }
11484             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11485             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11486                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11487                 if ( id != null ) {
11488                     System.out.println( "value   =" + id.getValue() );
11489                     System.out.println( "provider=" + id.getSource() );
11490                 }
11491                 return false;
11492             }
11493             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11494             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11495                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11496                 if ( id != null ) {
11497                     System.out.println( "value   =" + id.getValue() );
11498                     System.out.println( "provider=" + id.getSource() );
11499                 }
11500                 return false;
11501             }
11502             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11503             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11504                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11505                 if ( id != null ) {
11506                     System.out.println( "value   =" + id.getValue() );
11507                     System.out.println( "provider=" + id.getSource() );
11508                 }
11509                 return false;
11510             }
11511             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11512             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11513                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11514                 if ( id != null ) {
11515                     System.out.println( "value   =" + id.getValue() );
11516                     System.out.println( "provider=" + id.getSource() );
11517                 }
11518                 return false;
11519             }
11520             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11521             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11522                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11523                 if ( id != null ) {
11524                     System.out.println( "value   =" + id.getValue() );
11525                     System.out.println( "provider=" + id.getSource() );
11526                 }
11527                 return false;
11528             }
11529             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11530             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11531                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11532                 if ( id != null ) {
11533                     System.out.println( "value   =" + id.getValue() );
11534                     System.out.println( "provider=" + id.getSource() );
11535                 }
11536                 return false;
11537             }
11538             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11539             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11540                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11541                 if ( id != null ) {
11542                     System.out.println( "value   =" + id.getValue() );
11543                     System.out.println( "provider=" + id.getSource() );
11544                 }
11545                 return false;
11546             }
11547             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11548             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11549                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11550                 if ( id != null ) {
11551                     System.out.println( "value   =" + id.getValue() );
11552                     System.out.println( "provider=" + id.getSource() );
11553                 }
11554                 return false;
11555             }
11556             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11557             if ( id != null ) {
11558                 System.out.println( "value   =" + id.getValue() );
11559                 System.out.println( "provider=" + id.getSource() );
11560                 return false;
11561             }
11562             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
11563             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11564                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
11565                 if ( id != null ) {
11566                     System.out.println( "value   =" + id.getValue() );
11567                     System.out.println( "provider=" + id.getSource() );
11568                 }
11569                 return false;
11570             }
11571             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
11572             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11573                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11574                 if ( id != null ) {
11575                     System.out.println( "value   =" + id.getValue() );
11576                     System.out.println( "provider=" + id.getSource() );
11577                 }
11578                 return false;
11579             }
11580             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
11581             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11582                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11583                 if ( id != null ) {
11584                     System.out.println( "value   =" + id.getValue() );
11585                     System.out.println( "provider=" + id.getSource() );
11586                 }
11587                 return false;
11588             }
11589             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
11590             if ( id != null ) {
11591                 System.out.println( "value   =" + id.getValue() );
11592                 System.out.println( "provider=" + id.getSource() );
11593                 return false;
11594             }
11595         }
11596         catch ( final Exception e ) {
11597             e.printStackTrace( System.out );
11598             return false;
11599         }
11600         return true;
11601     }
11602
11603     private static boolean testSequenceWriter() {
11604         try {
11605             final String n = ForesterUtil.LINE_SEPARATOR;
11606             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11607                 return false;
11608             }
11609             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11610                 return false;
11611             }
11612             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11613                 return false;
11614             }
11615             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11616                 return false;
11617             }
11618             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11619                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11620                 return false;
11621             }
11622             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11623                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11624                 return false;
11625             }
11626         }
11627         catch ( final Exception e ) {
11628             e.printStackTrace();
11629             return false;
11630         }
11631         return true;
11632     }
11633
11634     private static boolean testSpecies() {
11635         try {
11636             final Species s1 = new BasicSpecies( "a" );
11637             final Species s2 = new BasicSpecies( "a" );
11638             final Species s3 = new BasicSpecies( "A" );
11639             final Species s4 = new BasicSpecies( "b" );
11640             if ( !s1.equals( s1 ) ) {
11641                 return false;
11642             }
11643             if ( s1.getSpeciesId().equals( "x" ) ) {
11644                 return false;
11645             }
11646             if ( s1.getSpeciesId().equals( null ) ) {
11647                 return false;
11648             }
11649             if ( !s1.equals( s2 ) ) {
11650                 return false;
11651             }
11652             if ( s1.equals( s3 ) ) {
11653                 return false;
11654             }
11655             if ( s1.hashCode() != s1.hashCode() ) {
11656                 return false;
11657             }
11658             if ( s1.hashCode() != s2.hashCode() ) {
11659                 return false;
11660             }
11661             if ( s1.hashCode() == s3.hashCode() ) {
11662                 return false;
11663             }
11664             if ( s1.compareTo( s1 ) != 0 ) {
11665                 return false;
11666             }
11667             if ( s1.compareTo( s2 ) != 0 ) {
11668                 return false;
11669             }
11670             if ( s1.compareTo( s3 ) != 0 ) {
11671                 return false;
11672             }
11673             if ( s1.compareTo( s4 ) >= 0 ) {
11674                 return false;
11675             }
11676             if ( s4.compareTo( s1 ) <= 0 ) {
11677                 return false;
11678             }
11679             if ( !s4.getSpeciesId().equals( "b" ) ) {
11680                 return false;
11681             }
11682             final Species s5 = new BasicSpecies( " C " );
11683             if ( !s5.getSpeciesId().equals( "C" ) ) {
11684                 return false;
11685             }
11686             if ( s5.equals( s1 ) ) {
11687                 return false;
11688             }
11689         }
11690         catch ( final Exception e ) {
11691             e.printStackTrace( System.out );
11692             return false;
11693         }
11694         return true;
11695     }
11696
11697     private static boolean testSplit() {
11698         try {
11699             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11700             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11701             //Archaeopteryx.createApplication( p0 );
11702             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11703             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11704             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11705             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11706             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11707             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11708             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11709             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11710             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11711             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11712             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11713             // System.out.println( s0.toString() );
11714             //
11715             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11716             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11717             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11718             if ( s0.match( query_nodes ) ) {
11719                 return false;
11720             }
11721             query_nodes = new HashSet<PhylogenyNode>();
11722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11724             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11725             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11726             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11727             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11728             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11729             if ( !s0.match( query_nodes ) ) {
11730                 return false;
11731             }
11732             //
11733             query_nodes = new HashSet<PhylogenyNode>();
11734             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11735             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11736             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11737             if ( !s0.match( query_nodes ) ) {
11738                 return false;
11739             }
11740             //
11741             query_nodes = new HashSet<PhylogenyNode>();
11742             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11743             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11744             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11745             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11746             if ( !s0.match( query_nodes ) ) {
11747                 return false;
11748             }
11749             //
11750             query_nodes = new HashSet<PhylogenyNode>();
11751             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11752             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11753             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11754             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11755             if ( !s0.match( query_nodes ) ) {
11756                 return false;
11757             }
11758             //
11759             query_nodes = new HashSet<PhylogenyNode>();
11760             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11761             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11762             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11763             if ( !s0.match( query_nodes ) ) {
11764                 return false;
11765             }
11766             query_nodes = new HashSet<PhylogenyNode>();
11767             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11768             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11769             if ( !s0.match( query_nodes ) ) {
11770                 return false;
11771             }
11772             query_nodes = new HashSet<PhylogenyNode>();
11773             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11774             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11775             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11776             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11777             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11778             if ( !s0.match( query_nodes ) ) {
11779                 return false;
11780             }
11781             query_nodes = new HashSet<PhylogenyNode>();
11782             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11783             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11784             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11785             if ( !s0.match( query_nodes ) ) {
11786                 return false;
11787             }
11788             query_nodes = new HashSet<PhylogenyNode>();
11789             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11790             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11791             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11792             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11793             if ( !s0.match( query_nodes ) ) {
11794                 return false;
11795             }
11796             query_nodes = new HashSet<PhylogenyNode>();
11797             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11798             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11799             if ( s0.match( query_nodes ) ) {
11800                 return false;
11801             }
11802             query_nodes = new HashSet<PhylogenyNode>();
11803             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11804             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11805             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11806             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11807             if ( s0.match( query_nodes ) ) {
11808                 return false;
11809             }
11810             query_nodes = new HashSet<PhylogenyNode>();
11811             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11812             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11813             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11814             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11815             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11816             if ( s0.match( query_nodes ) ) {
11817                 return false;
11818             }
11819             query_nodes = new HashSet<PhylogenyNode>();
11820             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11822             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11823             if ( s0.match( query_nodes ) ) {
11824                 return false;
11825             }
11826             query_nodes = new HashSet<PhylogenyNode>();
11827             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11828             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11829             if ( s0.match( query_nodes ) ) {
11830                 return false;
11831             }
11832             query_nodes = new HashSet<PhylogenyNode>();
11833             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11834             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11835             if ( s0.match( query_nodes ) ) {
11836                 return false;
11837             }
11838             query_nodes = new HashSet<PhylogenyNode>();
11839             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11840             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11841             if ( s0.match( query_nodes ) ) {
11842                 return false;
11843             }
11844             query_nodes = new HashSet<PhylogenyNode>();
11845             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11846             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11847             if ( s0.match( query_nodes ) ) {
11848                 return false;
11849             }
11850             query_nodes = new HashSet<PhylogenyNode>();
11851             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11852             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11853             if ( s0.match( query_nodes ) ) {
11854                 return false;
11855             }
11856             query_nodes = new HashSet<PhylogenyNode>();
11857             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11858             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11859             if ( s0.match( query_nodes ) ) {
11860                 return false;
11861             }
11862             query_nodes = new HashSet<PhylogenyNode>();
11863             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11864             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11865             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11866             if ( s0.match( query_nodes ) ) {
11867                 return false;
11868             }
11869             query_nodes = new HashSet<PhylogenyNode>();
11870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11872             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11873             if ( s0.match( query_nodes ) ) {
11874                 return false;
11875             }
11876             query_nodes = new HashSet<PhylogenyNode>();
11877             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11878             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11879             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11880             if ( s0.match( query_nodes ) ) {
11881                 return false;
11882             }
11883             query_nodes = new HashSet<PhylogenyNode>();
11884             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11885             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11886             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11888             if ( s0.match( query_nodes ) ) {
11889                 return false;
11890             }
11891             /////////
11892             //            query_nodes = new HashSet<PhylogenyNode>();
11893             //            query_nodes.add( new PhylogenyNode( "X" ) );
11894             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11895             //            query_nodes.add( new PhylogenyNode( "A" ) );
11896             //            query_nodes.add( new PhylogenyNode( "B" ) );
11897             //            query_nodes.add( new PhylogenyNode( "C" ) );
11898             //            query_nodes.add( new PhylogenyNode( "D" ) );
11899             //            query_nodes.add( new PhylogenyNode( "E" ) );
11900             //            query_nodes.add( new PhylogenyNode( "F" ) );
11901             //            query_nodes.add( new PhylogenyNode( "G" ) );
11902             //            if ( !s0.match( query_nodes ) ) {
11903             //                return false;
11904             //            }
11905             //            query_nodes = new HashSet<PhylogenyNode>();
11906             //            query_nodes.add( new PhylogenyNode( "X" ) );
11907             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11908             //            query_nodes.add( new PhylogenyNode( "A" ) );
11909             //            query_nodes.add( new PhylogenyNode( "B" ) );
11910             //            query_nodes.add( new PhylogenyNode( "C" ) );
11911             //            if ( !s0.match( query_nodes ) ) {
11912             //                return false;
11913             //            }
11914             //            //
11915             //            query_nodes = new HashSet<PhylogenyNode>();
11916             //            query_nodes.add( new PhylogenyNode( "X" ) );
11917             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11918             //            query_nodes.add( new PhylogenyNode( "D" ) );
11919             //            query_nodes.add( new PhylogenyNode( "E" ) );
11920             //            query_nodes.add( new PhylogenyNode( "F" ) );
11921             //            query_nodes.add( new PhylogenyNode( "G" ) );
11922             //            if ( !s0.match( query_nodes ) ) {
11923             //                return false;
11924             //            }
11925             //            //
11926             //            query_nodes = new HashSet<PhylogenyNode>();
11927             //            query_nodes.add( new PhylogenyNode( "X" ) );
11928             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11929             //            query_nodes.add( new PhylogenyNode( "A" ) );
11930             //            query_nodes.add( new PhylogenyNode( "B" ) );
11931             //            query_nodes.add( new PhylogenyNode( "C" ) );
11932             //            query_nodes.add( new PhylogenyNode( "D" ) );
11933             //            if ( !s0.match( query_nodes ) ) {
11934             //                return false;
11935             //            }
11936             //            //
11937             //            query_nodes = new HashSet<PhylogenyNode>();
11938             //            query_nodes.add( new PhylogenyNode( "X" ) );
11939             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11940             //            query_nodes.add( new PhylogenyNode( "E" ) );
11941             //            query_nodes.add( new PhylogenyNode( "F" ) );
11942             //            query_nodes.add( new PhylogenyNode( "G" ) );
11943             //            if ( !s0.match( query_nodes ) ) {
11944             //                return false;
11945             //            }
11946             //            //
11947             //            query_nodes = new HashSet<PhylogenyNode>();
11948             //            query_nodes.add( new PhylogenyNode( "X" ) );
11949             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11950             //            query_nodes.add( new PhylogenyNode( "F" ) );
11951             //            query_nodes.add( new PhylogenyNode( "G" ) );
11952             //            if ( !s0.match( query_nodes ) ) {
11953             //                return false;
11954             //            }
11955             //
11956             query_nodes = new HashSet<PhylogenyNode>();
11957             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11958             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11959             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11960             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11961             if ( s0.match( query_nodes ) ) {
11962                 return false;
11963             }
11964             //
11965             query_nodes = new HashSet<PhylogenyNode>();
11966             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11967             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11968             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11969             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11970             if ( s0.match( query_nodes ) ) {
11971                 return false;
11972             }
11973             ///////////////////////////
11974             //
11975             query_nodes = new HashSet<PhylogenyNode>();
11976             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11977             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11978             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11979             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11980             if ( s0.match( query_nodes ) ) {
11981                 return false;
11982             }
11983             //
11984             query_nodes = new HashSet<PhylogenyNode>();
11985             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11986             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11987             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11988             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11989             if ( s0.match( query_nodes ) ) {
11990                 return false;
11991             }
11992             //
11993             query_nodes = new HashSet<PhylogenyNode>();
11994             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11995             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11996             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11997             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11998             if ( s0.match( query_nodes ) ) {
11999                 return false;
12000             }
12001             //
12002             query_nodes = new HashSet<PhylogenyNode>();
12003             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12004             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12005             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12006             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12007             if ( s0.match( query_nodes ) ) {
12008                 return false;
12009             }
12010             //
12011             query_nodes = new HashSet<PhylogenyNode>();
12012             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12013             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12014             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12015             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12016             if ( s0.match( query_nodes ) ) {
12017                 return false;
12018             }
12019             //
12020             query_nodes = new HashSet<PhylogenyNode>();
12021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12023             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12024             if ( s0.match( query_nodes ) ) {
12025                 return false;
12026             }
12027             //
12028             query_nodes = new HashSet<PhylogenyNode>();
12029             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12030             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12032             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12033             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12034             if ( s0.match( query_nodes ) ) {
12035                 return false;
12036             }
12037             //
12038             query_nodes = new HashSet<PhylogenyNode>();
12039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12040             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12041             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12042             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12043             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12044             if ( s0.match( query_nodes ) ) {
12045                 return false;
12046             }
12047             //
12048             query_nodes = new HashSet<PhylogenyNode>();
12049             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12050             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12051             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12052             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12053             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12054             if ( s0.match( query_nodes ) ) {
12055                 return false;
12056             }
12057             //
12058             query_nodes = new HashSet<PhylogenyNode>();
12059             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12060             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12061             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12062             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12063             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12064             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12065             if ( s0.match( query_nodes ) ) {
12066                 return false;
12067             }
12068         }
12069         catch ( final Exception e ) {
12070             e.printStackTrace();
12071             return false;
12072         }
12073         return true;
12074     }
12075
12076     private static boolean testSplitStrict() {
12077         try {
12078             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12079             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12080             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
12081             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12082             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12083             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12084             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12085             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12086             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12087             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12088             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
12089             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12090             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12091             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12092             if ( s0.match( query_nodes ) ) {
12093                 return false;
12094             }
12095             query_nodes = new HashSet<PhylogenyNode>();
12096             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12097             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12098             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12099             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12100             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12101             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12102             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12103             if ( !s0.match( query_nodes ) ) {
12104                 return false;
12105             }
12106             //
12107             query_nodes = new HashSet<PhylogenyNode>();
12108             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12109             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12110             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12111             if ( !s0.match( query_nodes ) ) {
12112                 return false;
12113             }
12114             //
12115             query_nodes = new HashSet<PhylogenyNode>();
12116             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12117             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12118             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12119             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12120             if ( !s0.match( query_nodes ) ) {
12121                 return false;
12122             }
12123             //
12124             query_nodes = new HashSet<PhylogenyNode>();
12125             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12126             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12127             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12128             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12129             if ( !s0.match( query_nodes ) ) {
12130                 return false;
12131             }
12132             //
12133             query_nodes = new HashSet<PhylogenyNode>();
12134             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12135             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12136             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12137             if ( !s0.match( query_nodes ) ) {
12138                 return false;
12139             }
12140             //
12141             query_nodes = new HashSet<PhylogenyNode>();
12142             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12143             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12144             if ( !s0.match( query_nodes ) ) {
12145                 return false;
12146             }
12147             //
12148             query_nodes = new HashSet<PhylogenyNode>();
12149             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12150             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12151             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12152             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12153             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12154             if ( !s0.match( query_nodes ) ) {
12155                 return false;
12156             }
12157             //
12158             query_nodes = new HashSet<PhylogenyNode>();
12159             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12160             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12161             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12162             if ( !s0.match( query_nodes ) ) {
12163                 return false;
12164             }
12165             //
12166             query_nodes = new HashSet<PhylogenyNode>();
12167             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12168             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12169             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12170             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12171             if ( !s0.match( query_nodes ) ) {
12172                 return false;
12173             }
12174             //
12175             query_nodes = new HashSet<PhylogenyNode>();
12176             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12177             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12178             if ( s0.match( query_nodes ) ) {
12179                 return false;
12180             }
12181             //
12182             query_nodes = new HashSet<PhylogenyNode>();
12183             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12184             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12185             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12186             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12187             if ( s0.match( query_nodes ) ) {
12188                 return false;
12189             }
12190             //
12191             query_nodes = new HashSet<PhylogenyNode>();
12192             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12193             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12194             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12195             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12196             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12197             if ( s0.match( query_nodes ) ) {
12198                 return false;
12199             }
12200             //
12201             query_nodes = new HashSet<PhylogenyNode>();
12202             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12203             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12204             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12205             if ( s0.match( query_nodes ) ) {
12206                 return false;
12207             }
12208             //
12209             query_nodes = new HashSet<PhylogenyNode>();
12210             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12211             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12212             if ( s0.match( query_nodes ) ) {
12213                 return false;
12214             }
12215             //
12216             query_nodes = new HashSet<PhylogenyNode>();
12217             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12218             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12219             if ( s0.match( query_nodes ) ) {
12220                 return false;
12221             }
12222             //
12223             query_nodes = new HashSet<PhylogenyNode>();
12224             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12225             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12226             if ( s0.match( query_nodes ) ) {
12227                 return false;
12228             }
12229             //
12230             query_nodes = new HashSet<PhylogenyNode>();
12231             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12232             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12233             if ( s0.match( query_nodes ) ) {
12234                 return false;
12235             }
12236             //
12237             query_nodes = new HashSet<PhylogenyNode>();
12238             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12239             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12240             if ( s0.match( query_nodes ) ) {
12241                 return false;
12242             }
12243             //
12244             query_nodes = new HashSet<PhylogenyNode>();
12245             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12246             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12247             if ( s0.match( query_nodes ) ) {
12248                 return false;
12249             }
12250             //
12251             query_nodes = new HashSet<PhylogenyNode>();
12252             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12253             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12254             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12255             if ( s0.match( query_nodes ) ) {
12256                 return false;
12257             }
12258             //
12259             query_nodes = new HashSet<PhylogenyNode>();
12260             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12261             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12262             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12263             if ( s0.match( query_nodes ) ) {
12264                 return false;
12265             }
12266             //
12267             query_nodes = new HashSet<PhylogenyNode>();
12268             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12269             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12270             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12271             if ( s0.match( query_nodes ) ) {
12272                 return false;
12273             }
12274             //
12275             query_nodes = new HashSet<PhylogenyNode>();
12276             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12277             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12278             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12279             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12280             if ( s0.match( query_nodes ) ) {
12281                 return false;
12282             }
12283         }
12284         catch ( final Exception e ) {
12285             e.printStackTrace();
12286             return false;
12287         }
12288         return true;
12289     }
12290
12291     private static boolean testSubtreeDeletion() {
12292         try {
12293             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12294             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12295             t1.deleteSubtree( t1.getNode( "A" ), false );
12296             if ( t1.getNumberOfExternalNodes() != 5 ) {
12297                 return false;
12298             }
12299             t1.toNewHampshireX();
12300             t1.deleteSubtree( t1.getNode( "E" ), false );
12301             if ( t1.getNumberOfExternalNodes() != 4 ) {
12302                 return false;
12303             }
12304             t1.toNewHampshireX();
12305             t1.deleteSubtree( t1.getNode( "F" ), false );
12306             if ( t1.getNumberOfExternalNodes() != 3 ) {
12307                 return false;
12308             }
12309             t1.toNewHampshireX();
12310             t1.deleteSubtree( t1.getNode( "D" ), false );
12311             t1.toNewHampshireX();
12312             if ( t1.getNumberOfExternalNodes() != 3 ) {
12313                 return false;
12314             }
12315             t1.deleteSubtree( t1.getNode( "def" ), false );
12316             t1.toNewHampshireX();
12317             if ( t1.getNumberOfExternalNodes() != 2 ) {
12318                 return false;
12319             }
12320             t1.deleteSubtree( t1.getNode( "B" ), false );
12321             t1.toNewHampshireX();
12322             if ( t1.getNumberOfExternalNodes() != 1 ) {
12323                 return false;
12324             }
12325             t1.deleteSubtree( t1.getNode( "C" ), false );
12326             t1.toNewHampshireX();
12327             if ( t1.getNumberOfExternalNodes() != 1 ) {
12328                 return false;
12329             }
12330             t1.deleteSubtree( t1.getNode( "abc" ), false );
12331             t1.toNewHampshireX();
12332             if ( t1.getNumberOfExternalNodes() != 1 ) {
12333                 return false;
12334             }
12335             t1.deleteSubtree( t1.getNode( "r" ), false );
12336             if ( t1.getNumberOfExternalNodes() != 0 ) {
12337                 return false;
12338             }
12339             if ( !t1.isEmpty() ) {
12340                 return false;
12341             }
12342             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12343             t2.deleteSubtree( t2.getNode( "A" ), false );
12344             t2.toNewHampshireX();
12345             if ( t2.getNumberOfExternalNodes() != 5 ) {
12346                 return false;
12347             }
12348             t2.deleteSubtree( t2.getNode( "abc" ), false );
12349             t2.toNewHampshireX();
12350             if ( t2.getNumberOfExternalNodes() != 3 ) {
12351                 return false;
12352             }
12353             t2.deleteSubtree( t2.getNode( "def" ), false );
12354             t2.toNewHampshireX();
12355             if ( t2.getNumberOfExternalNodes() != 1 ) {
12356                 return false;
12357             }
12358         }
12359         catch ( final Exception e ) {
12360             e.printStackTrace( System.out );
12361             return false;
12362         }
12363         return true;
12364     }
12365
12366     private static boolean testSupportCount() {
12367         try {
12368             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12369             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12370             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12371                     + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12372                     + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12373                     + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12374                     + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12375                     new NHXParser() );
12376             SupportCount.count( t0_1, phylogenies_1, true, false );
12377             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12378             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12379                     + "(((((A,B),C),D),E),((F,G),X))"
12380                     + "(((((A,Y),B),C),D),((F,G),E))"
12381                     + "(((((A,B),C),D),E),(F,G))"
12382                     + "(((((A,B),C),D),E),(F,G))"
12383                     + "(((((A,B),C),D),E),(F,G))"
12384                     + "(((((A,B),C),D),E),(F,G),Z)"
12385                     + "(((((A,B),C),D),E),(F,G))"
12386                     + "((((((A,B),C),D),E),F),G)"
12387                     + "(((((X,Y),F,G),E),((A,B),C)),D)",
12388                     new NHXParser() );
12389             SupportCount.count( t0_2, phylogenies_2, true, false );
12390             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12391             while ( it.hasNext() ) {
12392                 final PhylogenyNode n = it.next();
12393                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12394                     return false;
12395                 }
12396             }
12397             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12398             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12399                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12400             SupportCount.count( t0_3, phylogenies_3, true, false );
12401             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12402             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12403                 return false;
12404             }
12405             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12406                 return false;
12407             }
12408             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12409                 return false;
12410             }
12411             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12412                 return false;
12413             }
12414             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12415                 return false;
12416             }
12417             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12418                 return false;
12419             }
12420             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12421                 return false;
12422             }
12423             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12424                 return false;
12425             }
12426             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12427                 return false;
12428             }
12429             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12430                 return false;
12431             }
12432             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12433             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12434                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12435             SupportCount.count( t0_4, phylogenies_4, true, false );
12436             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12437             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12438                 return false;
12439             }
12440             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12441                 return false;
12442             }
12443             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12444                 return false;
12445             }
12446             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12447                 return false;
12448             }
12449             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12450                 return false;
12451             }
12452             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12453                 return false;
12454             }
12455             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12456                 return false;
12457             }
12458             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12459                 return false;
12460             }
12461             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12462                 return false;
12463             }
12464             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12465                 return false;
12466             }
12467             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12468             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12469             double d = SupportCount.compare( b1, a, true, true, true );
12470             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12471                 return false;
12472             }
12473             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12474             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12475             d = SupportCount.compare( b2, a, true, true, true );
12476             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12477                 return false;
12478             }
12479             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12480             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12481             d = SupportCount.compare( b3, a, true, true, true );
12482             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12483                 return false;
12484             }
12485             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12486             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12487             d = SupportCount.compare( b4, a, true, true, false );
12488             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12489                 return false;
12490             }
12491         }
12492         catch ( final Exception e ) {
12493             e.printStackTrace( System.out );
12494             return false;
12495         }
12496         return true;
12497     }
12498
12499     private static boolean testSupportTransfer() {
12500         try {
12501             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12502             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)",
12503                                                  new NHXParser() )[ 0 ];
12504             final Phylogeny p2 = factory
12505                     .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 ];
12506             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12507                 return false;
12508             }
12509             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12510                 return false;
12511             }
12512             support_transfer.moveBranchLengthsToBootstrap( p1 );
12513             support_transfer.transferSupportValues( p1, p2 );
12514             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12515                 return false;
12516             }
12517             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12518                 return false;
12519             }
12520             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12521                 return false;
12522             }
12523             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12524                 return false;
12525             }
12526             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12527                 return false;
12528             }
12529             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12530                 return false;
12531             }
12532             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12533                 return false;
12534             }
12535             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12536                 return false;
12537             }
12538         }
12539         catch ( final Exception e ) {
12540             e.printStackTrace( System.out );
12541             return false;
12542         }
12543         return true;
12544     }
12545
12546     private static boolean testTaxonomyExtraction() {
12547         try {
12548             final PhylogenyNode n0 = PhylogenyNode
12549                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12550             if ( n0.getNodeData().isHasTaxonomy() ) {
12551                 return false;
12552             }
12553             final PhylogenyNode n1 = PhylogenyNode
12554                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12555             if ( n1.getNodeData().isHasTaxonomy() ) {
12556                 System.out.println( n1.toString() );
12557                 return false;
12558             }
12559             final PhylogenyNode n2x = PhylogenyNode
12560                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12561             if ( n2x.getNodeData().isHasTaxonomy() ) {
12562                 return false;
12563             }
12564             final PhylogenyNode n3 = PhylogenyNode
12565                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12566             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12567                 System.out.println( n3.toString() );
12568                 return false;
12569             }
12570             final PhylogenyNode n4 = PhylogenyNode
12571                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12572             if ( n4.getNodeData().isHasTaxonomy() ) {
12573                 System.out.println( n4.toString() );
12574                 return false;
12575             }
12576             final PhylogenyNode n5 = PhylogenyNode
12577                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12578             if ( n5.getNodeData().isHasTaxonomy() ) {
12579                 System.out.println( n5.toString() );
12580                 return false;
12581             }
12582             final PhylogenyNode n6 = PhylogenyNode
12583                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12584             if ( n6.getNodeData().isHasTaxonomy() ) {
12585                 System.out.println( n6.toString() );
12586                 return false;
12587             }
12588             final PhylogenyNode n7 = PhylogenyNode
12589                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12590             if ( n7.getNodeData().isHasTaxonomy() ) {
12591                 System.out.println( n7.toString() );
12592                 return false;
12593             }
12594             final PhylogenyNode n8 = PhylogenyNode
12595                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12596             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12597                 System.out.println( n8.toString() );
12598                 return false;
12599             }
12600             final PhylogenyNode n9 = PhylogenyNode
12601                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12602             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12603                 System.out.println( n9.toString() );
12604                 return false;
12605             }
12606             final PhylogenyNode n10x = PhylogenyNode
12607                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12608             if ( n10x.getNodeData().isHasTaxonomy() ) {
12609                 System.out.println( n10x.toString() );
12610                 return false;
12611             }
12612             final PhylogenyNode n10xx = PhylogenyNode
12613                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12614             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12615                 System.out.println( n10xx.toString() );
12616                 return false;
12617             }
12618             final PhylogenyNode n10 = PhylogenyNode
12619                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12620             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12621                 System.out.println( n10.toString() );
12622                 return false;
12623             }
12624             final PhylogenyNode n11 = PhylogenyNode
12625                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12626             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12627                 System.out.println( n11.toString() );
12628                 return false;
12629             }
12630             final PhylogenyNode n12 = PhylogenyNode
12631                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12632                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12633             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12634                 System.out.println( n12.toString() );
12635                 return false;
12636             }
12637             final PhylogenyNode n13 = PhylogenyNode
12638                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12639             if ( n13.getNodeData().isHasTaxonomy() ) {
12640                 System.out.println( n13.toString() );
12641                 return false;
12642             }
12643             final PhylogenyNode n14 = PhylogenyNode
12644                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12645             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12646                 System.out.println( n14.toString() );
12647                 return false;
12648             }
12649             final PhylogenyNode n15 = PhylogenyNode
12650                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12651             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12652                 System.out.println( n15.toString() );
12653                 return false;
12654             }
12655             final PhylogenyNode n16 = PhylogenyNode
12656                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12657             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12658                 System.out.println( n16.toString() );
12659                 return false;
12660             }
12661             final PhylogenyNode n17 = PhylogenyNode
12662                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12663             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12664                 System.out.println( n17.toString() );
12665                 return false;
12666             }
12667             final PhylogenyNode n18 = PhylogenyNode
12668                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12669             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12670                 System.out.println( n18.toString() );
12671                 return false;
12672             }
12673             final PhylogenyNode n19 = PhylogenyNode
12674                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12675                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12676             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12677                 System.out.println( n19.toString() );
12678                 return false;
12679             }
12680             final PhylogenyNode n20 = PhylogenyNode
12681                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12682             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12683                 System.out.println( n20.toString() );
12684                 return false;
12685             }
12686             final PhylogenyNode n21 = PhylogenyNode
12687                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12688                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12689             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12690                 System.out.println( n21.toString() );
12691                 return false;
12692             }
12693             final PhylogenyNode n23 = PhylogenyNode
12694                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12695                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12696             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12697                 System.out.println( n23.toString() );
12698                 return false;
12699             }
12700             final PhylogenyNode n24 = PhylogenyNode
12701                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12702             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12703                 System.out.println( n24.toString() );
12704                 return false;
12705             }
12706             //
12707             final PhylogenyNode n25 = PhylogenyNode
12708                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12709                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12710             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12711                 System.out.println( n25.toString() );
12712                 return false;
12713             }
12714             final PhylogenyNode n26 = PhylogenyNode
12715                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12716                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12717             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12718                 System.out.println( n26.toString() );
12719                 return false;
12720             }
12721             final PhylogenyNode n27 = PhylogenyNode
12722                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12723             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12724                 System.out.println( n27.toString() );
12725                 return false;
12726             }
12727         }
12728         catch ( final Exception e ) {
12729             e.printStackTrace( System.out );
12730             return false;
12731         }
12732         return true;
12733     }
12734
12735     private static boolean testTreeCopy() {
12736         try {
12737             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12738             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12739             final Phylogeny t1 = t0.copy();
12740             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12741                 return false;
12742             }
12743             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12744                 return false;
12745             }
12746             t0.deleteSubtree( t0.getNode( "c" ), true );
12747             t0.deleteSubtree( t0.getNode( "a" ), true );
12748             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12749             t0.getNode( "b" ).setName( "Bee" );
12750             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12751                 return false;
12752             }
12753             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12754                 return false;
12755             }
12756             t0.deleteSubtree( t0.getNode( "e" ), true );
12757             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12758             t0.deleteSubtree( t0.getNode( "d" ), true );
12759             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12760                 return false;
12761             }
12762         }
12763         catch ( final Exception e ) {
12764             e.printStackTrace();
12765             return false;
12766         }
12767         return true;
12768     }
12769
12770     private static boolean testTreeMethods() {
12771         try {
12772             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12773             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12774             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12775             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12776                 System.out.println( t0.toNewHampshireX() );
12777                 return false;
12778             }
12779             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12780             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12781             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12782                 return false;
12783             }
12784             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12785                 return false;
12786             }
12787             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12788                 return false;
12789             }
12790         }
12791         catch ( final Exception e ) {
12792             e.printStackTrace( System.out );
12793             return false;
12794         }
12795         return true;
12796     }
12797
12798     private static boolean testUniprotEntryRetrieval() {
12799         try {
12800             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 5000 );
12801             if ( !entry.getAccession().equals( "P12345" ) ) {
12802                 return false;
12803             }
12804             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12805                 return false;
12806             }
12807             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12808                 return false;
12809             }
12810             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12811                 return false;
12812             }
12813             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12814                 return false;
12815             }
12816             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12817                 return false;
12818             }
12819             if ( entry.getMolecularSequence() == null ) {
12820                 return false;
12821             }
12822             if ( !entry
12823                     .getMolecularSequence()
12824                     .getMolecularSequenceAsString()
12825                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
12826                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
12827                 System.out.println( "got: " + entry.getMolecularSequence().getMolecularSequenceAsString() );
12828                 System.out.println( "expected something else." );
12829                 return false;
12830             }
12831         }
12832         catch ( final IOException e ) {
12833             System.out.println();
12834             System.out.println( "the following might be due to absence internet connection:" );
12835             e.printStackTrace( System.out );
12836             return true;
12837         }
12838         catch ( final NullPointerException f ) {
12839             f.printStackTrace( System.out );
12840             return false;
12841         }
12842         catch ( final Exception e ) {
12843             return false;
12844         }
12845         return true;
12846     }
12847
12848     private static boolean testUniprotTaxonomySearch() {
12849         try {
12850             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12851                                                                                                  10 );
12852             if ( results.size() != 1 ) {
12853                 return false;
12854             }
12855             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12856                 return false;
12857             }
12858             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12859                 return false;
12860             }
12861             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12862                 return false;
12863             }
12864             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12865                 return false;
12866             }
12867             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12868                 return false;
12869             }
12870             results = null;
12871             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12872             if ( results.size() != 1 ) {
12873                 return false;
12874             }
12875             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12876                 return false;
12877             }
12878             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12879                 return false;
12880             }
12881             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12882                 return false;
12883             }
12884             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12885                 return false;
12886             }
12887             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12888                 return false;
12889             }
12890             results = null;
12891             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12892             if ( results.size() != 1 ) {
12893                 return false;
12894             }
12895             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12896                 return false;
12897             }
12898             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12899                 return false;
12900             }
12901             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12902                 return false;
12903             }
12904             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12905                 return false;
12906             }
12907             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12908                 return false;
12909             }
12910             results = null;
12911             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12912             if ( results.size() != 1 ) {
12913                 return false;
12914             }
12915             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12916                 return false;
12917             }
12918             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12919                 return false;
12920             }
12921             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12922                 return false;
12923             }
12924             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12925                 return false;
12926             }
12927             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12928                 return false;
12929             }
12930             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12931                 return false;
12932             }
12933             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12934                 return false;
12935             }
12936             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12937                     .equals( "Nematostella vectensis" ) ) {
12938                 System.out.println( results.get( 0 ).getLineage() );
12939                 return false;
12940             }
12941             //
12942             results = null;
12943             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12944             if ( results.size() != 1 ) {
12945                 return false;
12946             }
12947             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12948                 return false;
12949             }
12950             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12951                 return false;
12952             }
12953             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12954                 return false;
12955             }
12956             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12957                 return false;
12958             }
12959             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12960                 return false;
12961             }
12962             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12963                     .equals( "Xenopus tropicalis" ) ) {
12964                 System.out.println( results.get( 0 ).getLineage() );
12965                 return false;
12966             }
12967             //
12968             results = null;
12969             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12970             if ( results.size() != 1 ) {
12971                 return false;
12972             }
12973             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12974                 return false;
12975             }
12976             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12977                 return false;
12978             }
12979             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12980                 return false;
12981             }
12982             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12983                 return false;
12984             }
12985             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12986                 return false;
12987             }
12988             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12989                     .equals( "Xenopus tropicalis" ) ) {
12990                 System.out.println( results.get( 0 ).getLineage() );
12991                 return false;
12992             }
12993             //
12994             results = null;
12995             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12996             if ( results.size() != 1 ) {
12997                 return false;
12998             }
12999             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13000                 return false;
13001             }
13002             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13003                 return false;
13004             }
13005             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13006                 return false;
13007             }
13008             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13009                 return false;
13010             }
13011             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13012                 return false;
13013             }
13014             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13015                     .equals( "Xenopus tropicalis" ) ) {
13016                 System.out.println( results.get( 0 ).getLineage() );
13017                 return false;
13018             }
13019         }
13020         catch ( final IOException e ) {
13021             System.out.println();
13022             System.out.println( "the following might be due to absence internet connection:" );
13023             e.printStackTrace( System.out );
13024             return true;
13025         }
13026         catch ( final Exception e ) {
13027             return false;
13028         }
13029         return true;
13030     }
13031     
13032     
13033 }