5ff446f2452baec80b9a46ee6a22ba3323e7b850
[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) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
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 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.test;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.File;
30 import java.io.FileInputStream;
31 import java.io.IOException;
32 import java.net.URL;
33 import java.util.ArrayList;
34 import java.util.Date;
35 import java.util.HashSet;
36 import java.util.Iterator;
37 import java.util.List;
38 import java.util.Locale;
39 import java.util.Set;
40 import java.util.SortedSet;
41
42 import org.forester.application.support_transfer;
43 import org.forester.archaeopteryx.TreePanelUtil;
44 import org.forester.archaeopteryx.webservices.WebserviceUtil;
45 import org.forester.development.DevelopmentTools;
46 import org.forester.evoinference.TestPhylogenyReconstruction;
47 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
48 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
49 import org.forester.go.TestGo;
50 import org.forester.io.parsers.FastaParser;
51 import org.forester.io.parsers.GeneralMsaParser;
52 import org.forester.io.parsers.HmmscanPerDomainTableParser;
53 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
54 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
55 import org.forester.io.parsers.nexus.NexusCharactersParser;
56 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
57 import org.forester.io.parsers.nhx.NHXParser;
58 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
59 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
60 import org.forester.io.parsers.tol.TolParser;
61 import org.forester.io.parsers.util.ParserUtils;
62 import org.forester.io.writers.PhylogenyWriter;
63 import org.forester.io.writers.SequenceWriter;
64 import org.forester.msa.BasicMsa;
65 import org.forester.msa.Mafft;
66 import org.forester.msa.Msa;
67 import org.forester.msa.MsaInferrer;
68 import org.forester.msa.MsaMethods;
69 import org.forester.pccx.TestPccx;
70 import org.forester.phylogeny.Phylogeny;
71 import org.forester.phylogeny.PhylogenyBranch;
72 import org.forester.phylogeny.PhylogenyMethods;
73 import org.forester.phylogeny.PhylogenyNode;
74 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
75 import org.forester.phylogeny.data.Accession;
76 import org.forester.phylogeny.data.Accession.Source;
77 import org.forester.phylogeny.data.BinaryCharacters;
78 import org.forester.phylogeny.data.BranchWidth;
79 import org.forester.phylogeny.data.Confidence;
80 import org.forester.phylogeny.data.Distribution;
81 import org.forester.phylogeny.data.DomainArchitecture;
82 import org.forester.phylogeny.data.Event;
83 import org.forester.phylogeny.data.Identifier;
84 import org.forester.phylogeny.data.PhylogenyData;
85 import org.forester.phylogeny.data.PhylogenyDataUtil;
86 import org.forester.phylogeny.data.Polygon;
87 import org.forester.phylogeny.data.PropertiesMap;
88 import org.forester.phylogeny.data.Property;
89 import org.forester.phylogeny.data.Property.AppliesTo;
90 import org.forester.phylogeny.data.ProteinDomain;
91 import org.forester.phylogeny.data.Taxonomy;
92 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
93 import org.forester.phylogeny.factories.PhylogenyFactory;
94 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
95 import org.forester.protein.BasicDomain;
96 import org.forester.protein.BasicProtein;
97 import org.forester.protein.Domain;
98 import org.forester.protein.Protein;
99 import org.forester.protein.ProteinId;
100 import org.forester.rio.TestRIO;
101 import org.forester.sdi.SDI;
102 import org.forester.sdi.SDIR;
103 import org.forester.sdi.TestGSDI;
104 import org.forester.sequence.BasicSequence;
105 import org.forester.sequence.Sequence;
106 import org.forester.species.BasicSpecies;
107 import org.forester.species.Species;
108 import org.forester.surfacing.TestSurfacing;
109 import org.forester.tools.ConfidenceAssessor;
110 import org.forester.tools.SupportCount;
111 import org.forester.tools.TreeSplitMatrix;
112 import org.forester.util.AsciiHistogram;
113 import org.forester.util.BasicDescriptiveStatistics;
114 import org.forester.util.BasicTable;
115 import org.forester.util.BasicTableParser;
116 import org.forester.util.DescriptiveStatistics;
117 import org.forester.util.ForesterConstants;
118 import org.forester.util.ForesterUtil;
119 import org.forester.util.GeneralTable;
120 import org.forester.util.SequenceAccessionTools;
121 import org.forester.ws.seqdb.SequenceDatabaseEntry;
122 import org.forester.ws.seqdb.SequenceDbWsTools;
123 import org.forester.ws.seqdb.UniProtTaxonomy;
124 import org.forester.ws.wabi.TxSearch;
125 import org.forester.ws.wabi.TxSearch.RANKS;
126 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
127 import org.forester.ws.wabi.TxSearch.TAX_RANK;
128
129 @SuppressWarnings( "unused")
130 public final class Test {
131
132     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
133                                                                    + ForesterUtil.getFileSeparator() + "resources"
134                                                                    + ForesterUtil.getFileSeparator();
135     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
136                                                                    + ForesterUtil.getFileSeparator() + "test_data"
137                                                                    + ForesterUtil.getFileSeparator();
138     private final static boolean PERFORM_DB_TESTS          = false;
139     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
140     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
141                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
142                                                                    + ForesterConstants.PHYLO_XML_XSD;
143     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
144                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
145                                                                    + ForesterConstants.PHYLO_XML_XSD;
146     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
147     private final static double  ZERO_DIFF                 = 1.0E-9;
148
149     public static boolean isEqual( final double a, final double b ) {
150         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
151     }
152
153     public static void main( final String[] args ) {
154         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
155         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
156                 + "]" );
157         Locale.setDefault( Locale.US );
158         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
159         int failed = 0;
160         int succeeded = 0;
161         System.out.print( "[Test if directory with files for testing exists/is readable: " );
162         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
163             System.out.println( "OK.]" );
164         }
165         else {
166             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
167             System.out.println( "Testing aborted." );
168             System.exit( -1 );
169         }
170         System.out.print( "[Test if resources directory exists/is readable: " );
171         if ( testDir( PATH_TO_RESOURCES ) ) {
172             System.out.println( "OK.]" );
173         }
174         else {
175             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
176             System.out.println( "Testing aborted." );
177             System.exit( -1 );
178         }
179         final long start_time = new Date().getTime();
180         System.out.print( "Basic node methods: " );
181         if ( Test.testBasicNodeMethods() ) {
182             System.out.println( "OK." );
183             succeeded++;
184         }
185         else {
186             System.out.println( "failed." );
187             failed++;
188         }
189         System.out.print( "Protein id: " );
190         if ( !testProteinId() ) {
191             System.out.println( "failed." );
192             failed++;
193         }
194         else {
195             succeeded++;
196         }
197         System.out.println( "OK." );
198         System.out.print( "Species: " );
199         if ( !testSpecies() ) {
200             System.out.println( "failed." );
201             failed++;
202         }
203         else {
204             succeeded++;
205         }
206         System.out.println( "OK." );
207         System.out.print( "Basic domain: " );
208         if ( !testBasicDomain() ) {
209             System.out.println( "failed." );
210             failed++;
211         }
212         else {
213             succeeded++;
214         }
215         System.out.println( "OK." );
216         System.out.print( "Basic protein: " );
217         if ( !testBasicProtein() ) {
218             System.out.println( "failed." );
219             failed++;
220         }
221         else {
222             succeeded++;
223         }
224         System.out.println( "OK." );
225         System.out.print( "Sequence writer: " );
226         if ( testSequenceWriter() ) {
227             System.out.println( "OK." );
228             succeeded++;
229         }
230         else {
231             System.out.println( "failed." );
232             failed++;
233         }
234         System.out.print( "Sequence id parsing: " );
235         if ( testSequenceIdParsing() ) {
236             System.out.println( "OK." );
237             succeeded++;
238         }
239         else {
240             System.out.println( "failed." );
241             failed++;
242         }
243         System.out.print( "UniProtKB id extraction: " );
244         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
245             System.out.println( "OK." );
246             succeeded++;
247         }
248         else {
249             System.out.println( "failed." );
250             failed++;
251         }
252         System.out.print( "Sequence DB tools 1: " );
253         if ( testSequenceDbWsTools1() ) {
254             System.out.println( "OK." );
255             succeeded++;
256         }
257         else {
258             System.out.println( "failed." );
259             failed++;
260         }
261         System.out.print( "Hmmscan output parser: " );
262         if ( testHmmscanOutputParser() ) {
263             System.out.println( "OK." );
264             succeeded++;
265         }
266         else {
267             System.out.println( "failed." );
268             failed++;
269         }
270         System.out.print( "Overlap removal: " );
271         if ( !org.forester.test.Test.testOverlapRemoval() ) {
272             System.out.println( "failed." );
273             failed++;
274         }
275         else {
276             succeeded++;
277         }
278         System.out.println( "OK." );
279         System.out.print( "Engulfing overlap removal: " );
280         if ( !Test.testEngulfingOverlapRemoval() ) {
281             System.out.println( "failed." );
282             failed++;
283         }
284         else {
285             succeeded++;
286         }
287         System.out.println( "OK." );
288         System.out.print( "Taxonomy code extraction: " );
289         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
290             System.out.println( "OK." );
291             succeeded++;
292         }
293         else {
294             System.out.println( "failed." );
295             failed++;
296         }
297         System.out.print( "SN extraction: " );
298         if ( Test.testExtractSNFromNodeName() ) {
299             System.out.println( "OK." );
300             succeeded++;
301         }
302         else {
303             System.out.println( "failed." );
304             failed++;
305         }
306         System.out.print( "Taxonomy extraction (general): " );
307         if ( Test.testTaxonomyExtraction() ) {
308             System.out.println( "OK." );
309             succeeded++;
310         }
311         else {
312             System.out.println( "failed." );
313             failed++;
314         }
315         System.out.print( "Uri for Aptx web sequence accession: " );
316         if ( Test.testCreateUriForSeqWeb() ) {
317             System.out.println( "OK." );
318             succeeded++;
319         }
320         else {
321             System.out.println( "failed." );
322             failed++;
323         }
324         System.out.print( "Basic node construction and parsing of NHX (node level): " );
325         if ( Test.testNHXNodeParsing() ) {
326             System.out.println( "OK." );
327             succeeded++;
328         }
329         else {
330             System.out.println( "failed." );
331             failed++;
332         }
333         System.out.print( "NHX parsing iterating: " );
334         if ( Test.testNHParsingIter() ) {
335             System.out.println( "OK." );
336             succeeded++;
337         }
338         else {
339             System.out.println( "failed." );
340             failed++;
341         }
342         System.out.print( "NH parsing: " );
343         if ( Test.testNHParsing() ) {
344             System.out.println( "OK." );
345             succeeded++;
346         }
347         else {
348             System.out.println( "failed." );
349             failed++;
350         }
351         System.out.print( "Conversion to NHX (node level): " );
352         if ( Test.testNHXconversion() ) {
353             System.out.println( "OK." );
354             succeeded++;
355         }
356         else {
357             System.out.println( "failed." );
358             failed++;
359         }
360         System.out.print( "NHX parsing: " );
361         if ( Test.testNHXParsing() ) {
362             System.out.println( "OK." );
363             succeeded++;
364         }
365         else {
366             System.out.println( "failed." );
367             failed++;
368         }
369         System.out.print( "NHX parsing with quotes: " );
370         if ( Test.testNHXParsingQuotes() ) {
371             System.out.println( "OK." );
372             succeeded++;
373         }
374         else {
375             System.out.println( "failed." );
376             failed++;
377         }
378         System.out.print( "NHX parsing (MrBayes): " );
379         if ( Test.testNHXParsingMB() ) {
380             System.out.println( "OK." );
381             succeeded++;
382         }
383         else {
384             System.out.println( "failed." );
385             failed++;
386         }
387         System.out.print( "Nexus characters parsing: " );
388         if ( Test.testNexusCharactersParsing() ) {
389             System.out.println( "OK." );
390             succeeded++;
391         }
392         else {
393             System.out.println( "failed." );
394             failed++;
395         }
396         System.out.print( "Nexus tree parsing iterating: " );
397         if ( Test.testNexusTreeParsingIterating() ) {
398             System.out.println( "OK." );
399             succeeded++;
400         }
401         else {
402             System.out.println( "failed." );
403             failed++;
404         }
405         System.out.print( "Nexus tree parsing: " );
406         if ( Test.testNexusTreeParsing() ) {
407             System.out.println( "OK." );
408             succeeded++;
409         }
410         else {
411             System.out.println( "failed." );
412             failed++;
413         }
414         System.out.print( "Nexus tree parsing (translating): " );
415         if ( Test.testNexusTreeParsingTranslating() ) {
416             System.out.println( "OK." );
417             succeeded++;
418         }
419         else {
420             System.out.println( "failed." );
421             failed++;
422         }
423         System.out.print( "Nexus matrix parsing: " );
424         if ( Test.testNexusMatrixParsing() ) {
425             System.out.println( "OK." );
426             succeeded++;
427         }
428         else {
429             System.out.println( "failed." );
430             failed++;
431         }
432         System.out.print( "Basic phyloXML parsing: " );
433         if ( Test.testBasicPhyloXMLparsing() ) {
434             System.out.println( "OK." );
435             succeeded++;
436         }
437         else {
438             System.out.println( "failed." );
439             failed++;
440         }
441         System.out.print( "Basic phyloXML parsing (validating against schema): " );
442         if ( testBasicPhyloXMLparsingValidating() ) {
443             System.out.println( "OK." );
444             succeeded++;
445         }
446         else {
447             System.out.println( "failed." );
448             failed++;
449         }
450         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
451         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
452             System.out.println( "OK." );
453             succeeded++;
454         }
455         else {
456             System.out.println( "failed." );
457             failed++;
458         }
459         System.out.print( "phyloXML Distribution Element: " );
460         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
461             System.out.println( "OK." );
462             succeeded++;
463         }
464         else {
465             System.out.println( "failed." );
466             failed++;
467         }
468         System.out.print( "Tol XML parsing: " );
469         if ( Test.testBasicTolXMLparsing() ) {
470             System.out.println( "OK." );
471             succeeded++;
472         }
473         else {
474             System.out.println( "failed." );
475             failed++;
476         }
477         System.out.print( "Copying of node data: " );
478         if ( Test.testCopyOfNodeData() ) {
479             System.out.println( "OK." );
480             succeeded++;
481         }
482         else {
483             System.out.println( "failed." );
484             failed++;
485         }
486         System.out.print( "Tree copy: " );
487         if ( Test.testTreeCopy() ) {
488             System.out.println( "OK." );
489             succeeded++;
490         }
491         else {
492             System.out.println( "failed." );
493             failed++;
494         }
495         System.out.print( "Basic tree methods: " );
496         if ( Test.testBasicTreeMethods() ) {
497             System.out.println( "OK." );
498             succeeded++;
499         }
500         else {
501             System.out.println( "failed." );
502             failed++;
503         }
504         System.out.print( "Tree methods: " );
505         if ( Test.testTreeMethods() ) {
506             System.out.println( "OK." );
507             succeeded++;
508         }
509         else {
510             System.out.println( "failed." );
511             failed++;
512         }
513         System.out.print( "Postorder Iterator: " );
514         if ( Test.testPostOrderIterator() ) {
515             System.out.println( "OK." );
516             succeeded++;
517         }
518         else {
519             System.out.println( "failed." );
520             failed++;
521         }
522         System.out.print( "Preorder Iterator: " );
523         if ( Test.testPreOrderIterator() ) {
524             System.out.println( "OK." );
525             succeeded++;
526         }
527         else {
528             System.out.println( "failed." );
529             failed++;
530         }
531         System.out.print( "Levelorder Iterator: " );
532         if ( Test.testLevelOrderIterator() ) {
533             System.out.println( "OK." );
534             succeeded++;
535         }
536         else {
537             System.out.println( "failed." );
538             failed++;
539         }
540         System.out.print( "Re-id methods: " );
541         if ( Test.testReIdMethods() ) {
542             System.out.println( "OK." );
543             succeeded++;
544         }
545         else {
546             System.out.println( "failed." );
547             failed++;
548         }
549         System.out.print( "Methods on last external nodes: " );
550         if ( Test.testLastExternalNodeMethods() ) {
551             System.out.println( "OK." );
552             succeeded++;
553         }
554         else {
555             System.out.println( "failed." );
556             failed++;
557         }
558         System.out.print( "Methods on external nodes: " );
559         if ( Test.testExternalNodeRelatedMethods() ) {
560             System.out.println( "OK." );
561             succeeded++;
562         }
563         else {
564             System.out.println( "failed." );
565             failed++;
566         }
567         System.out.print( "Deletion of external nodes: " );
568         if ( Test.testDeletionOfExternalNodes() ) {
569             System.out.println( "OK." );
570             succeeded++;
571         }
572         else {
573             System.out.println( "failed." );
574             failed++;
575         }
576         System.out.print( "Subtree deletion: " );
577         if ( Test.testSubtreeDeletion() ) {
578             System.out.println( "OK." );
579             succeeded++;
580         }
581         else {
582             System.out.println( "failed." );
583             failed++;
584         }
585         System.out.print( "Phylogeny branch: " );
586         if ( Test.testPhylogenyBranch() ) {
587             System.out.println( "OK." );
588             succeeded++;
589         }
590         else {
591             System.out.println( "failed." );
592             failed++;
593         }
594         System.out.print( "Rerooting: " );
595         if ( Test.testRerooting() ) {
596             System.out.println( "OK." );
597             succeeded++;
598         }
599         else {
600             System.out.println( "failed." );
601             failed++;
602         }
603         System.out.print( "Mipoint rooting: " );
604         if ( Test.testMidpointrooting() ) {
605             System.out.println( "OK." );
606             succeeded++;
607         }
608         else {
609             System.out.println( "failed." );
610             failed++;
611         }
612         System.out.print( "Node removal: " );
613         if ( Test.testNodeRemoval() ) {
614             System.out.println( "OK." );
615             succeeded++;
616         }
617         else {
618             System.out.println( "failed." );
619             failed++;
620         }
621         System.out.print( "Support count: " );
622         if ( Test.testSupportCount() ) {
623             System.out.println( "OK." );
624             succeeded++;
625         }
626         else {
627             System.out.println( "failed." );
628             failed++;
629         }
630         System.out.print( "Support transfer: " );
631         if ( Test.testSupportTransfer() ) {
632             System.out.println( "OK." );
633             succeeded++;
634         }
635         else {
636             System.out.println( "failed." );
637             failed++;
638         }
639         System.out.print( "Finding of LCA: " );
640         if ( Test.testGetLCA() ) {
641             System.out.println( "OK." );
642             succeeded++;
643         }
644         else {
645             System.out.println( "failed." );
646             failed++;
647         }
648         System.out.print( "Finding of LCA 2: " );
649         if ( Test.testGetLCA2() ) {
650             System.out.println( "OK." );
651             succeeded++;
652         }
653         else {
654             System.out.println( "failed." );
655             failed++;
656         }
657         System.out.print( "Calculation of distance between nodes: " );
658         if ( Test.testGetDistance() ) {
659             System.out.println( "OK." );
660             succeeded++;
661         }
662         else {
663             System.out.println( "failed." );
664             failed++;
665         }
666         System.out.print( "Descriptive statistics: " );
667         if ( Test.testDescriptiveStatistics() ) {
668             System.out.println( "OK." );
669             succeeded++;
670         }
671         else {
672             System.out.println( "failed." );
673             failed++;
674         }
675         System.out.print( "Data objects and methods: " );
676         if ( Test.testDataObjects() ) {
677             System.out.println( "OK." );
678             succeeded++;
679         }
680         else {
681             System.out.println( "failed." );
682             failed++;
683         }
684         System.out.print( "Properties map: " );
685         if ( Test.testPropertiesMap() ) {
686             System.out.println( "OK." );
687             succeeded++;
688         }
689         else {
690             System.out.println( "failed." );
691             failed++;
692         }
693         System.out.print( "SDIse: " );
694         if ( Test.testSDIse() ) {
695             System.out.println( "OK." );
696             succeeded++;
697         }
698         else {
699             System.out.println( "failed." );
700             failed++;
701         }
702         System.out.print( "SDIunrooted: " );
703         if ( Test.testSDIunrooted() ) {
704             System.out.println( "OK." );
705             succeeded++;
706         }
707         else {
708             System.out.println( "failed." );
709             failed++;
710         }
711         System.out.print( "GSDI: " );
712         if ( TestGSDI.test() ) {
713             System.out.println( "OK." );
714             succeeded++;
715         }
716         else {
717             System.out.println( "failed." );
718             failed++;
719         }
720         System.out.print( "RIO: " );
721         if ( TestRIO.test() ) {
722             System.out.println( "OK." );
723             succeeded++;
724         }
725         else {
726             System.out.println( "failed." );
727             failed++;
728         }
729         System.out.print( "Phylogeny reconstruction:" );
730         System.out.println();
731         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
732             System.out.println( "OK." );
733             succeeded++;
734         }
735         else {
736             System.out.println( "failed." );
737             failed++;
738         }
739         System.out.print( "Analysis of domain architectures: " );
740         System.out.println();
741         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
742             System.out.println( "OK." );
743             succeeded++;
744         }
745         else {
746             System.out.println( "failed." );
747             failed++;
748         }
749         System.out.print( "GO: " );
750         System.out.println();
751         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
752             System.out.println( "OK." );
753             succeeded++;
754         }
755         else {
756             System.out.println( "failed." );
757             failed++;
758         }
759         System.out.print( "Modeling tools: " );
760         if ( TestPccx.test() ) {
761             System.out.println( "OK." );
762             succeeded++;
763         }
764         else {
765             System.out.println( "failed." );
766             failed++;
767         }
768         System.out.print( "Split Matrix strict: " );
769         if ( Test.testSplitStrict() ) {
770             System.out.println( "OK." );
771             succeeded++;
772         }
773         else {
774             System.out.println( "failed." );
775             failed++;
776         }
777         System.out.print( "Split Matrix: " );
778         if ( Test.testSplit() ) {
779             System.out.println( "OK." );
780             succeeded++;
781         }
782         else {
783             System.out.println( "failed." );
784             failed++;
785         }
786         System.out.print( "Confidence Assessor: " );
787         if ( Test.testConfidenceAssessor() ) {
788             System.out.println( "OK." );
789             succeeded++;
790         }
791         else {
792             System.out.println( "failed." );
793             failed++;
794         }
795         System.out.print( "Basic table: " );
796         if ( Test.testBasicTable() ) {
797             System.out.println( "OK." );
798             succeeded++;
799         }
800         else {
801             System.out.println( "failed." );
802             failed++;
803         }
804         System.out.print( "General table: " );
805         if ( Test.testGeneralTable() ) {
806             System.out.println( "OK." );
807             succeeded++;
808         }
809         else {
810             System.out.println( "failed." );
811             failed++;
812         }
813         System.out.print( "Amino acid sequence: " );
814         if ( Test.testAminoAcidSequence() ) {
815             System.out.println( "OK." );
816             succeeded++;
817         }
818         else {
819             System.out.println( "failed." );
820             failed++;
821         }
822         System.out.print( "General MSA parser: " );
823         if ( Test.testGeneralMsaParser() ) {
824             System.out.println( "OK." );
825             succeeded++;
826         }
827         else {
828             System.out.println( "failed." );
829             failed++;
830         }
831         System.out.print( "Fasta parser for msa: " );
832         if ( Test.testFastaParser() ) {
833             System.out.println( "OK." );
834             succeeded++;
835         }
836         else {
837             System.out.println( "failed." );
838             failed++;
839         }
840         System.out.print( "Creation of balanced phylogeny: " );
841         if ( Test.testCreateBalancedPhylogeny() ) {
842             System.out.println( "OK." );
843             succeeded++;
844         }
845         else {
846             System.out.println( "failed." );
847             failed++;
848         }
849         System.out.print( "Genbank accessor parsing: " );
850         if ( Test.testGenbankAccessorParsing() ) {
851             System.out.println( "OK." );
852             succeeded++;
853         }
854         else {
855             System.out.println( "failed." );
856             failed++;
857         }
858         String path = "";
859         final String os = ForesterUtil.OS_NAME.toLowerCase();
860         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
861             path = "/usr/local/bin/mafft";
862         }
863         else if ( os.indexOf( "win" ) >= 0 ) {
864             path = "C:\\Program Files\\mafft-win\\mafft.bat";
865         }
866         else {
867             path = "mafft";
868             if ( !MsaInferrer.isInstalled( path ) ) {
869                 path = "/usr/bin/mafft";
870             }
871             if ( !MsaInferrer.isInstalled( path ) ) {
872                 path = "/usr/local/bin/mafft";
873             }
874         }
875         if ( MsaInferrer.isInstalled( path ) ) {
876             System.out.print( "MAFFT (external program): " );
877             if ( Test.testMafft( path ) ) {
878                 System.out.println( "OK." );
879                 succeeded++;
880             }
881             else {
882                 System.out.println( "failed [will not count towards failed tests]" );
883             }
884         }
885         System.out.print( "Next nodes with collapsed: " );
886         if ( Test.testNextNodeWithCollapsing() ) {
887             System.out.println( "OK." );
888             succeeded++;
889         }
890         else {
891             System.out.println( "failed." );
892             failed++;
893         }
894         System.out.print( "Simple MSA quality: " );
895         if ( Test.testMsaQualityMethod() ) {
896             System.out.println( "OK." );
897             succeeded++;
898         }
899         else {
900             System.out.println( "failed." );
901             failed++;
902         }
903         if ( PERFORM_DB_TESTS ) {
904             System.out.print( "Uniprot Entry Retrieval: " );
905             if ( Test.testUniprotEntryRetrieval() ) {
906                 System.out.println( "OK." );
907                 succeeded++;
908             }
909             else {
910                 System.out.println( "failed." );
911                 failed++;
912             }
913             System.out.print( "Ebi Entry Retrieval: " );
914             if ( Test.testEbiEntryRetrieval() ) {
915                 System.out.println( "OK." );
916                 succeeded++;
917             }
918             else {
919                 System.out.println( "failed." );
920                 failed++;
921             }
922             System.out.print( "Sequence DB tools 2: " );
923             if ( testSequenceDbWsTools2() ) {
924                 System.out.println( "OK." );
925                 succeeded++;
926             }
927             else {
928                 System.out.println( "failed." );
929                 failed++;
930                 System.exit( -1 );
931             }
932             System.out.print( "Uniprot Taxonomy Search: " );
933             if ( Test.testUniprotTaxonomySearch() ) {
934                 System.out.println( "OK." );
935                 succeeded++;
936             }
937             else {
938                 System.out.println( "failed." );
939                 failed++;
940             }
941         }
942         if ( PERFORM_WEB_TREE_ACCESS ) {
943             System.out.print( "NHX parsing from URL: " );
944             if ( Test.testNHXparsingFromURL() ) {
945                 System.out.println( "OK." );
946                 succeeded++;
947             }
948             else {
949                 System.out.println( "failed." );
950                 failed++;
951             }
952             System.out.print( "phyloXML parsing from URL: " );
953             if ( Test.testPhyloXMLparsingFromURL() ) {
954                 System.out.println( "OK." );
955                 succeeded++;
956             }
957             else {
958                 System.out.println( "failed." );
959                 failed++;
960             }
961             System.out.print( "TreeBase acccess: " );
962             if ( Test.testTreeBaseReading() ) {
963                 System.out.println( "OK." );
964                 succeeded++;
965             }
966             else {
967                 System.out.println( "failed." );
968                 failed++;
969             }
970             //
971             System.out.print( "ToL access: " );
972             if ( Test.testToLReading() ) {
973                 System.out.println( "OK." );
974                 succeeded++;
975             }
976             else {
977                 System.out.println( "failed." );
978                 failed++;
979             }
980             //
981             System.out.print( "TreeFam access: " );
982             if ( Test.testTreeFamReading() ) {
983                 System.out.println( "OK." );
984                 succeeded++;
985             }
986             else {
987                 System.out.println( "failed." );
988                 failed++;
989             }
990             //
991             //
992             System.out.print( "Pfam tree access: " );
993             if ( Test.testPfamTreeReading() ) {
994                 System.out.println( "OK." );
995                 succeeded++;
996             }
997             else {
998                 System.out.println( "failed." );
999                 failed++;
1000             }
1001         }
1002         System.out.println();
1003         final Runtime rt = java.lang.Runtime.getRuntime();
1004         final long free_memory = rt.freeMemory() / 1000000;
1005         final long total_memory = rt.totalMemory() / 1000000;
1006         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1007                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1008         System.out.println();
1009         System.out.println( "Successful tests: " + succeeded );
1010         System.out.println( "Failed     tests: " + failed );
1011         System.out.println();
1012         if ( failed < 1 ) {
1013             System.out.println( "OK." );
1014         }
1015         else {
1016             System.out.println( "Not OK." );
1017         }
1018     }
1019
1020     public static boolean testEngulfingOverlapRemoval() {
1021         try {
1022             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1023             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1024             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1025             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1026             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1027             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1028             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1029             final List<Boolean> covered = new ArrayList<Boolean>();
1030             covered.add( true ); // 0
1031             covered.add( false ); // 1
1032             covered.add( true ); // 2
1033             covered.add( false ); // 3
1034             covered.add( true ); // 4
1035             covered.add( true ); // 5
1036             covered.add( false ); // 6
1037             covered.add( true ); // 7
1038             covered.add( true ); // 8
1039             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1040                 return false;
1041             }
1042             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1043                 return false;
1044             }
1045             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1046                 return false;
1047             }
1048             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1049                 return false;
1050             }
1051             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1052                 return false;
1053             }
1054             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1055                 return false;
1056             }
1057             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1058                 return false;
1059             }
1060             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1061             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1062             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1063             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1064             abc.addProteinDomain( a );
1065             abc.addProteinDomain( b );
1066             abc.addProteinDomain( c );
1067             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1068             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1069             if ( abc.getNumberOfProteinDomains() != 3 ) {
1070                 return false;
1071             }
1072             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1073                 return false;
1074             }
1075             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1076                 return false;
1077             }
1078             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1079                 return false;
1080             }
1081             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1082                 return false;
1083             }
1084             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1085             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1086             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1087             final Protein def = new BasicProtein( "def", "nemve", 0 );
1088             def.addProteinDomain( d );
1089             def.addProteinDomain( e );
1090             def.addProteinDomain( f );
1091             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1092             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1093             if ( def.getNumberOfProteinDomains() != 3 ) {
1094                 return false;
1095             }
1096             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1097                 return false;
1098             }
1099             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1100                 return false;
1101             }
1102             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1103                 return false;
1104             }
1105             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1106                 return false;
1107             }
1108             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1109                 return false;
1110             }
1111         }
1112         catch ( final Exception e ) {
1113             e.printStackTrace( System.out );
1114             return false;
1115         }
1116         return true;
1117     }
1118
1119     public static final boolean testNHXparsingFromURL() {
1120         try {
1121             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1122             final URL u = new URL( s );
1123             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1124             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1125             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1126                 return false;
1127             }
1128             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1129                 System.out.println( phys[ 0 ].toNewHampshire() );
1130                 return false;
1131             }
1132             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1133                 System.out.println( phys[ 1 ].toNewHampshire() );
1134                 return false;
1135             }
1136             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1137             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1138                 return false;
1139             }
1140             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1141                 System.out.println( phys2[ 0 ].toNewHampshire() );
1142                 return false;
1143             }
1144             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1145             final NHXParser p = new NHXParser();
1146             final URL u2 = new URL( s );
1147             p.setSource( u2 );
1148             if ( !p.hasNext() ) {
1149                 return false;
1150             }
1151             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1152                 return false;
1153             }
1154             if ( !p.hasNext() ) {
1155                 return false;
1156             }
1157             p.reset();
1158             if ( !p.hasNext() ) {
1159                 return false;
1160             }
1161             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1162                 return false;
1163             }
1164             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1165                 return false;
1166             }
1167             p.reset();
1168             if ( !p.hasNext() ) {
1169                 return false;
1170             }
1171             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1172                 return false;
1173             }
1174             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1175                 return false;
1176             }
1177         }
1178         catch ( final Exception e ) {
1179             e.printStackTrace();
1180         }
1181         return true;
1182     }
1183
1184     public static boolean testOverlapRemoval() {
1185         try {
1186             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1187             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1188             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1189             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1190             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1191             final List<Boolean> covered = new ArrayList<Boolean>();
1192             covered.add( true ); // 0
1193             covered.add( false ); // 1
1194             covered.add( true ); // 2
1195             covered.add( false ); // 3
1196             covered.add( true ); // 4
1197             covered.add( true ); // 5
1198             covered.add( false ); // 6
1199             covered.add( true ); // 7
1200             covered.add( true ); // 8
1201             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1202                 return false;
1203             }
1204             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1205                 return false;
1206             }
1207             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1208                 return false;
1209             }
1210             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1211                 return false;
1212             }
1213             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1214                 return false;
1215             }
1216             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1217             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1218             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1219             ab.addProteinDomain( a );
1220             ab.addProteinDomain( b );
1221             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1222             if ( ab.getNumberOfProteinDomains() != 2 ) {
1223                 return false;
1224             }
1225             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1226                 return false;
1227             }
1228             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1229                 return false;
1230             }
1231             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1232             if ( ab.getNumberOfProteinDomains() != 2 ) {
1233                 return false;
1234             }
1235             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1236                 return false;
1237             }
1238             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1239             final Domain d = new BasicDomain( "d",
1240                                               ( short ) 10000,
1241                                               ( short ) 10500,
1242                                               ( short ) 1,
1243                                               ( short ) 1,
1244                                               0.0000001,
1245                                               1 );
1246             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1247             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1248             cde.addProteinDomain( c );
1249             cde.addProteinDomain( d );
1250             cde.addProteinDomain( e );
1251             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1252             if ( cde.getNumberOfProteinDomains() != 3 ) {
1253                 return false;
1254             }
1255             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1256                 return false;
1257             }
1258             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1259             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1260             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1261             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1262             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1263             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1264             fghi.addProteinDomain( f );
1265             fghi.addProteinDomain( g );
1266             fghi.addProteinDomain( h );
1267             fghi.addProteinDomain( i );
1268             fghi.addProteinDomain( i );
1269             fghi.addProteinDomain( i );
1270             fghi.addProteinDomain( i2 );
1271             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1272             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1273                 return false;
1274             }
1275             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1276                 return false;
1277             }
1278             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1279                 return false;
1280             }
1281             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1282             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1283                 return false;
1284             }
1285             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1286                 return false;
1287             }
1288             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1289             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1290             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1291             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1292             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1293             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1294             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1295             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1296             jklm.addProteinDomain( j );
1297             jklm.addProteinDomain( k );
1298             jklm.addProteinDomain( l );
1299             jklm.addProteinDomain( m );
1300             jklm.addProteinDomain( m0 );
1301             jklm.addProteinDomain( m1 );
1302             jklm.addProteinDomain( m2 );
1303             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1304             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1305                 return false;
1306             }
1307             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1308                 return false;
1309             }
1310             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1311                 return false;
1312             }
1313             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1314             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1315                 return false;
1316             }
1317             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1318                 return false;
1319             }
1320             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1321             final Protein od = new BasicProtein( "od", "varanus", 0 );
1322             od.addProteinDomain( only );
1323             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1324             if ( od.getNumberOfProteinDomains() != 1 ) {
1325                 return false;
1326             }
1327             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1328                 return false;
1329             }
1330         }
1331         catch ( final Exception e ) {
1332             e.printStackTrace( System.out );
1333             return false;
1334         }
1335         return true;
1336     }
1337
1338     public static final boolean testPfamTreeReading() {
1339         try {
1340             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1341             final NHXParser parser = new NHXParser();
1342             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1343             parser.setReplaceUnderscores( false );
1344             parser.setGuessRootedness( true );
1345             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1346             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1347             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1348                 return false;
1349             }
1350             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1351                 return false;
1352             }
1353         }
1354         catch ( final Exception e ) {
1355             e.printStackTrace();
1356         }
1357         return true;
1358     }
1359
1360     public static final boolean testPhyloXMLparsingFromURL() {
1361         try {
1362             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1363             final URL u = new URL( s );
1364             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1365             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1366             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1367                 return false;
1368             }
1369         }
1370         catch ( final Exception e ) {
1371             e.printStackTrace();
1372         }
1373         return true;
1374     }
1375
1376     public static final boolean testToLReading() {
1377         try {
1378             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1379             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1380             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1381             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1382                 return false;
1383             }
1384             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1385                 return false;
1386             }
1387             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1388                 return false;
1389             }
1390             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1391                 return false;
1392             }
1393         }
1394         catch ( final Exception e ) {
1395             e.printStackTrace();
1396         }
1397         return true;
1398     }
1399
1400     public static final boolean testTreeBaseReading() {
1401         try {
1402             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1403             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1404             parser.setReplaceUnderscores( true );
1405             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1406             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1407             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1408                 return false;
1409             }
1410             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1411             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1412             parser2.setReplaceUnderscores( true );
1413             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1414             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1415             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1416                 return false;
1417             }
1418         }
1419         catch ( final Exception e ) {
1420             e.printStackTrace();
1421         }
1422         return true;
1423     }
1424
1425     public static final boolean testTreeFamReading() {
1426         try {
1427             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1428             final NHXParser parser = new NHXParser();
1429             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1430             parser.setReplaceUnderscores( false );
1431             parser.setGuessRootedness( true );
1432             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1433             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1434             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1435                 return false;
1436             }
1437             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1438                 return false;
1439             }
1440         }
1441         catch ( final Exception e ) {
1442             e.printStackTrace();
1443         }
1444         return true;
1445     }
1446
1447     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1448         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1449         return p;
1450     }
1451
1452     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1453         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1454     }
1455
1456     private static boolean testAminoAcidSequence() {
1457         try {
1458             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1459             if ( aa1.getLength() != 13 ) {
1460                 return false;
1461             }
1462             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1463                 return false;
1464             }
1465             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1466                 return false;
1467             }
1468             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1469                 return false;
1470             }
1471             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1472             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1473                 return false;
1474             }
1475             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1476             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1477                 return false;
1478             }
1479             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1480             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1481                 return false;
1482             }
1483         }
1484         catch ( final Exception e ) {
1485             e.printStackTrace();
1486             return false;
1487         }
1488         return true;
1489     }
1490
1491     private static boolean testBasicDomain() {
1492         try {
1493             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1494             if ( !pd.getDomainId().equals( "id" ) ) {
1495                 return false;
1496             }
1497             if ( pd.getNumber() != 1 ) {
1498                 return false;
1499             }
1500             if ( pd.getTotalCount() != 4 ) {
1501                 return false;
1502             }
1503             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1504                 return false;
1505             }
1506             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1507             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1508             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1509             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1510             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1511             if ( !a1.equals( a1 ) ) {
1512                 return false;
1513             }
1514             if ( !a1.equals( a1_copy ) ) {
1515                 return false;
1516             }
1517             if ( !a1.equals( a1_equal ) ) {
1518                 return false;
1519             }
1520             if ( !a1.equals( a2 ) ) {
1521                 return false;
1522             }
1523             if ( a1.equals( a3 ) ) {
1524                 return false;
1525             }
1526             if ( a1.compareTo( a1 ) != 0 ) {
1527                 return false;
1528             }
1529             if ( a1.compareTo( a1_copy ) != 0 ) {
1530                 return false;
1531             }
1532             if ( a1.compareTo( a1_equal ) != 0 ) {
1533                 return false;
1534             }
1535             if ( a1.compareTo( a2 ) != 0 ) {
1536                 return false;
1537             }
1538             if ( a1.compareTo( a3 ) == 0 ) {
1539                 return false;
1540             }
1541         }
1542         catch ( final Exception e ) {
1543             e.printStackTrace( System.out );
1544             return false;
1545         }
1546         return true;
1547     }
1548
1549     private static boolean testBasicNodeMethods() {
1550         try {
1551             if ( PhylogenyNode.getNodeCount() != 0 ) {
1552                 return false;
1553             }
1554             final PhylogenyNode n1 = new PhylogenyNode();
1555             final PhylogenyNode n2 = PhylogenyNode
1556                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1557             final PhylogenyNode n3 = PhylogenyNode
1558                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1559             final PhylogenyNode n4 = PhylogenyNode
1560                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1561             if ( n1.isHasAssignedEvent() ) {
1562                 return false;
1563             }
1564             if ( PhylogenyNode.getNodeCount() != 4 ) {
1565                 return false;
1566             }
1567             if ( n3.getIndicator() != 0 ) {
1568                 return false;
1569             }
1570             if ( n3.getNumberOfExternalNodes() != 1 ) {
1571                 return false;
1572             }
1573             if ( !n3.isExternal() ) {
1574                 return false;
1575             }
1576             if ( !n3.isRoot() ) {
1577                 return false;
1578             }
1579             if ( !n4.getName().equals( "n4" ) ) {
1580                 return false;
1581             }
1582         }
1583         catch ( final Exception e ) {
1584             e.printStackTrace( System.out );
1585             return false;
1586         }
1587         return true;
1588     }
1589
1590     private static boolean testBasicPhyloXMLparsing() {
1591         try {
1592             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1593             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1594             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1595                                                               xml_parser );
1596             if ( xml_parser.getErrorCount() > 0 ) {
1597                 System.out.println( xml_parser.getErrorMessages().toString() );
1598                 return false;
1599             }
1600             if ( phylogenies_0.length != 4 ) {
1601                 return false;
1602             }
1603             final Phylogeny t1 = phylogenies_0[ 0 ];
1604             final Phylogeny t2 = phylogenies_0[ 1 ];
1605             final Phylogeny t3 = phylogenies_0[ 2 ];
1606             final Phylogeny t4 = phylogenies_0[ 3 ];
1607             if ( t1.getNumberOfExternalNodes() != 1 ) {
1608                 return false;
1609             }
1610             if ( !t1.isRooted() ) {
1611                 return false;
1612             }
1613             if ( t1.isRerootable() ) {
1614                 return false;
1615             }
1616             if ( !t1.getType().equals( "gene_tree" ) ) {
1617                 return false;
1618             }
1619             if ( t2.getNumberOfExternalNodes() != 2 ) {
1620                 return false;
1621             }
1622             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1623                 return false;
1624             }
1625             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1626                 return false;
1627             }
1628             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1629                 return false;
1630             }
1631             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1632                 return false;
1633             }
1634             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1635                 return false;
1636             }
1637             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1638                 return false;
1639             }
1640             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1641                     .startsWith( "actgtgggggt" ) ) {
1642                 return false;
1643             }
1644             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1645                     .startsWith( "ctgtgatgcat" ) ) {
1646                 return false;
1647             }
1648             if ( t3.getNumberOfExternalNodes() != 4 ) {
1649                 return false;
1650             }
1651             if ( !t1.getName().equals( "t1" ) ) {
1652                 return false;
1653             }
1654             if ( !t2.getName().equals( "t2" ) ) {
1655                 return false;
1656             }
1657             if ( !t3.getName().equals( "t3" ) ) {
1658                 return false;
1659             }
1660             if ( !t4.getName().equals( "t4" ) ) {
1661                 return false;
1662             }
1663             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1664                 return false;
1665             }
1666             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1667                 return false;
1668             }
1669             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1670                 return false;
1671             }
1672             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1673                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1674                 return false;
1675             }
1676             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1677                 return false;
1678             }
1679             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1680                 return false;
1681             }
1682             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1683                 return false;
1684             }
1685             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1686                     .equals( "apoptosis" ) ) {
1687                 return false;
1688             }
1689             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1690                     .equals( "GO:0006915" ) ) {
1691                 return false;
1692             }
1693             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1694                     .equals( "UniProtKB" ) ) {
1695                 return false;
1696             }
1697             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1698                     .equals( "experimental" ) ) {
1699                 return false;
1700             }
1701             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1702                     .equals( "function" ) ) {
1703                 return false;
1704             }
1705             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1706                     .getValue() != 1 ) {
1707                 return false;
1708             }
1709             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1710                     .getType().equals( "ml" ) ) {
1711                 return false;
1712             }
1713             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1714                     .equals( "apoptosis" ) ) {
1715                 return false;
1716             }
1717             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1718                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1719                 return false;
1720             }
1721             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1722                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1723                 return false;
1724             }
1725             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1726                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1727                 return false;
1728             }
1729             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1730                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1731                 return false;
1732             }
1733             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1734                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1735                 return false;
1736             }
1737             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1738                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1739                 return false;
1740             }
1741             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1742                     .equals( "GO:0005829" ) ) {
1743                 return false;
1744             }
1745             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1746                     .equals( "intracellular organelle" ) ) {
1747                 return false;
1748             }
1749             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1750                 return false;
1751             }
1752             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1753                     .equals( "UniProt link" ) ) ) {
1754                 return false;
1755             }
1756             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1757                 return false;
1758             }
1759             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1760             if ( x.size() != 4 ) {
1761                 return false;
1762             }
1763             int c = 0;
1764             for( final Accession acc : x ) {
1765                 if ( c == 0 ) {
1766                     if ( !acc.getSource().equals( "KEGG" ) ) {
1767                         return false;
1768                     }
1769                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1770                         return false;
1771                     }
1772                 }
1773                 c++;
1774             }
1775         }
1776         catch ( final Exception e ) {
1777             e.printStackTrace( System.out );
1778             return false;
1779         }
1780         return true;
1781     }
1782
1783     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1784         try {
1785             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1786             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1787             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1788                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1789             }
1790             else {
1791                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1792             }
1793             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1794                                                               xml_parser );
1795             if ( xml_parser.getErrorCount() > 0 ) {
1796                 System.out.println( xml_parser.getErrorMessages().toString() );
1797                 return false;
1798             }
1799             if ( phylogenies_0.length != 4 ) {
1800                 return false;
1801             }
1802             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1803             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1804             if ( phylogenies_t1.length != 1 ) {
1805                 return false;
1806             }
1807             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1808             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1809                 return false;
1810             }
1811             if ( !t1_rt.isRooted() ) {
1812                 return false;
1813             }
1814             if ( t1_rt.isRerootable() ) {
1815                 return false;
1816             }
1817             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1818                 return false;
1819             }
1820             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1821             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1822             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1823             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1824                 return false;
1825             }
1826             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1827                 return false;
1828             }
1829             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1830                 return false;
1831             }
1832             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1833                 return false;
1834             }
1835             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1836                     .startsWith( "actgtgggggt" ) ) {
1837                 return false;
1838             }
1839             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1840                     .startsWith( "ctgtgatgcat" ) ) {
1841                 return false;
1842             }
1843             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1844             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1845             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1846             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1847             if ( phylogenies_1.length != 1 ) {
1848                 return false;
1849             }
1850             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1851             if ( !t3_rt.getName().equals( "t3" ) ) {
1852                 return false;
1853             }
1854             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1855                 return false;
1856             }
1857             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1858                 return false;
1859             }
1860             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1861                 return false;
1862             }
1863             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1864                 return false;
1865             }
1866             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1867                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1868                 return false;
1869             }
1870             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1871                 return false;
1872             }
1873             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1874                 return false;
1875             }
1876             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1877                     .equals( "UniProtKB" ) ) {
1878                 return false;
1879             }
1880             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1881                     .equals( "apoptosis" ) ) {
1882                 return false;
1883             }
1884             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1885                     .equals( "GO:0006915" ) ) {
1886                 return false;
1887             }
1888             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1889                     .equals( "UniProtKB" ) ) {
1890                 return false;
1891             }
1892             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1893                     .equals( "experimental" ) ) {
1894                 return false;
1895             }
1896             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1897                     .equals( "function" ) ) {
1898                 return false;
1899             }
1900             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1901                     .getValue() != 1 ) {
1902                 return false;
1903             }
1904             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1905                     .getType().equals( "ml" ) ) {
1906                 return false;
1907             }
1908             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1909                     .equals( "apoptosis" ) ) {
1910                 return false;
1911             }
1912             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1913                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1914                 return false;
1915             }
1916             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1917                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1918                 return false;
1919             }
1920             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1921                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1922                 return false;
1923             }
1924             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1925                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1926                 return false;
1927             }
1928             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1929                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1930                 return false;
1931             }
1932             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1933                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1934                 return false;
1935             }
1936             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1937                     .equals( "GO:0005829" ) ) {
1938                 return false;
1939             }
1940             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1941                     .equals( "intracellular organelle" ) ) {
1942                 return false;
1943             }
1944             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1945                 return false;
1946             }
1947             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1948                     .equals( "UniProt link" ) ) ) {
1949                 return false;
1950             }
1951             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1952                 return false;
1953             }
1954             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1955                 return false;
1956             }
1957             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1958                     .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." ) ) ) {
1959                 return false;
1960             }
1961             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1962                 return false;
1963             }
1964             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1965                 return false;
1966             }
1967             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1968                 return false;
1969             }
1970             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1971                 return false;
1972             }
1973             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1974                     .equals( "ncbi" ) ) {
1975                 return false;
1976             }
1977             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1978                 return false;
1979             }
1980             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1981                     .getName().equals( "B" ) ) {
1982                 return false;
1983             }
1984             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1985                     .getFrom() != 21 ) {
1986                 return false;
1987             }
1988             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1989                 return false;
1990             }
1991             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1992                     .getLength() != 24 ) {
1993                 return false;
1994             }
1995             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1996                     .getConfidence() != 2144 ) {
1997                 return false;
1998             }
1999             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2000                     .equals( "pfam" ) ) {
2001                 return false;
2002             }
2003             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2004                 return false;
2005             }
2006             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2007                 return false;
2008             }
2009             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2010                 return false;
2011             }
2012             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2013                 return false;
2014             }
2015             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2016             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2017                 return false;
2018             }
2019             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2020                 return false;
2021             }
2022             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2023                 return false;
2024             }
2025             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2026                 return false;
2027             }
2028             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2029                 return false;
2030             }
2031             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2032                 return false;
2033             }
2034             if ( taxbb.getSynonyms().size() != 2 ) {
2035                 return false;
2036             }
2037             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2038                 return false;
2039             }
2040             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2041                 return false;
2042             }
2043             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2044                 return false;
2045             }
2046             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2047                 return false;
2048             }
2049             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2050                 return false;
2051             }
2052             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2053                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2054                 return false;
2055             }
2056             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2057                 return false;
2058             }
2059             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2060                 return false;
2061             }
2062             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2063                 return false;
2064             }
2065             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2066                 return false;
2067             }
2068             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2069                 return false;
2070             }
2071             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2072                 return false;
2073             }
2074             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2075                 return false;
2076             }
2077             //
2078             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2079                 return false;
2080             }
2081             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2082                     .equalsIgnoreCase( "435" ) ) {
2083                 return false;
2084             }
2085             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2086                 return false;
2087             }
2088             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2089                     .equalsIgnoreCase( "443.7" ) ) {
2090                 return false;
2091             }
2092             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2093                 return false;
2094             }
2095             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2096                 return false;
2097             }
2098             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2099                     .equalsIgnoreCase( "433" ) ) {
2100                 return false;
2101             }
2102             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2103                     .getCrossReferences();
2104             if ( x.size() != 4 ) {
2105                 return false;
2106             }
2107             int c = 0;
2108             for( final Accession acc : x ) {
2109                 if ( c == 0 ) {
2110                     if ( !acc.getSource().equals( "KEGG" ) ) {
2111                         return false;
2112                     }
2113                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2114                         return false;
2115                     }
2116                 }
2117                 c++;
2118             }
2119         }
2120         catch ( final Exception e ) {
2121             e.printStackTrace( System.out );
2122             return false;
2123         }
2124         return true;
2125     }
2126
2127     private static boolean testBasicPhyloXMLparsingValidating() {
2128         try {
2129             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2130             PhyloXmlParser xml_parser = null;
2131             try {
2132                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2133             }
2134             catch ( final Exception e ) {
2135                 // Do nothing -- means were not running from jar.
2136             }
2137             if ( xml_parser == null ) {
2138                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2139                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2140                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2141                 }
2142                 else {
2143                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2144                 }
2145             }
2146             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2147                                                               xml_parser );
2148             if ( xml_parser.getErrorCount() > 0 ) {
2149                 System.out.println( xml_parser.getErrorMessages().toString() );
2150                 return false;
2151             }
2152             if ( phylogenies_0.length != 4 ) {
2153                 return false;
2154             }
2155             final Phylogeny t1 = phylogenies_0[ 0 ];
2156             final Phylogeny t2 = phylogenies_0[ 1 ];
2157             final Phylogeny t3 = phylogenies_0[ 2 ];
2158             final Phylogeny t4 = phylogenies_0[ 3 ];
2159             if ( !t1.getName().equals( "t1" ) ) {
2160                 return false;
2161             }
2162             if ( !t2.getName().equals( "t2" ) ) {
2163                 return false;
2164             }
2165             if ( !t3.getName().equals( "t3" ) ) {
2166                 return false;
2167             }
2168             if ( !t4.getName().equals( "t4" ) ) {
2169                 return false;
2170             }
2171             if ( t1.getNumberOfExternalNodes() != 1 ) {
2172                 return false;
2173             }
2174             if ( t2.getNumberOfExternalNodes() != 2 ) {
2175                 return false;
2176             }
2177             if ( t3.getNumberOfExternalNodes() != 4 ) {
2178                 return false;
2179             }
2180             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2181             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2182             if ( xml_parser.getErrorCount() > 0 ) {
2183                 System.out.println( "errors:" );
2184                 System.out.println( xml_parser.getErrorMessages().toString() );
2185                 return false;
2186             }
2187             if ( phylogenies_1.length != 4 ) {
2188                 return false;
2189             }
2190             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2191                                                               xml_parser );
2192             if ( xml_parser.getErrorCount() > 0 ) {
2193                 System.out.println( "errors:" );
2194                 System.out.println( xml_parser.getErrorMessages().toString() );
2195                 return false;
2196             }
2197             if ( phylogenies_2.length != 1 ) {
2198                 return false;
2199             }
2200             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2201                 return false;
2202             }
2203             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2204                                                               xml_parser );
2205             if ( xml_parser.getErrorCount() > 0 ) {
2206                 System.out.println( xml_parser.getErrorMessages().toString() );
2207                 return false;
2208             }
2209             if ( phylogenies_3.length != 2 ) {
2210                 return false;
2211             }
2212             final Phylogeny a = phylogenies_3[ 0 ];
2213             if ( !a.getName().equals( "tree 4" ) ) {
2214                 return false;
2215             }
2216             if ( a.getNumberOfExternalNodes() != 3 ) {
2217                 return false;
2218             }
2219             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2220                 return false;
2221             }
2222             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2223                 return false;
2224             }
2225             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2226                                                               xml_parser );
2227             if ( xml_parser.getErrorCount() > 0 ) {
2228                 System.out.println( xml_parser.getErrorMessages().toString() );
2229                 return false;
2230             }
2231             if ( phylogenies_4.length != 1 ) {
2232                 return false;
2233             }
2234             final Phylogeny s = phylogenies_4[ 0 ];
2235             if ( s.getNumberOfExternalNodes() != 6 ) {
2236                 return false;
2237             }
2238             s.getNode( "first" );
2239             s.getNode( "<>" );
2240             s.getNode( "\"<a'b&c'd\">\"" );
2241             s.getNode( "'''\"" );
2242             s.getNode( "\"\"\"" );
2243             s.getNode( "dick & doof" );
2244         }
2245         catch ( final Exception e ) {
2246             e.printStackTrace( System.out );
2247             return false;
2248         }
2249         return true;
2250     }
2251
2252     private static boolean testBasicProtein() {
2253         try {
2254             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2255             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2256             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2257             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2258             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2259             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2260             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2261             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2262             p0.addProteinDomain( y );
2263             p0.addProteinDomain( e );
2264             p0.addProteinDomain( b );
2265             p0.addProteinDomain( c );
2266             p0.addProteinDomain( d );
2267             p0.addProteinDomain( a );
2268             p0.addProteinDomain( x );
2269             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2270                 return false;
2271             }
2272             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2273                 return false;
2274             }
2275             //
2276             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2277             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2278             aa0.addProteinDomain( a1 );
2279             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2280                 return false;
2281             }
2282             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2283                 return false;
2284             }
2285             //
2286             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2287             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2288             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2289             aa1.addProteinDomain( a11 );
2290             aa1.addProteinDomain( a12 );
2291             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2292                 return false;
2293             }
2294             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2295                 return false;
2296             }
2297             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2298             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2299                 return false;
2300             }
2301             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2302                 return false;
2303             }
2304             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2305                 return false;
2306             }
2307             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2308             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2309                 return false;
2310             }
2311             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2312                 return false;
2313             }
2314             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2315                 return false;
2316             }
2317             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2318                 return false;
2319             }
2320             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2321             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2322                 return false;
2323             }
2324             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2325                 return false;
2326             }
2327             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2328                 return false;
2329             }
2330             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2331                 return false;
2332             }
2333             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2334             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2335                 return false;
2336             }
2337             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2338                 return false;
2339             }
2340             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2341                 return false;
2342             }
2343             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2344                 return false;
2345             }
2346             //
2347             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2348             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2349             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2350             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2351             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2352             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2353             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2354             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2355             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2356             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2357             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2358             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2359             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2360             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2361             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2362             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2363             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2364             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2365             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2366             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2367             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2368             p00.addProteinDomain( y0 );
2369             p00.addProteinDomain( e0 );
2370             p00.addProteinDomain( b0 );
2371             p00.addProteinDomain( c0 );
2372             p00.addProteinDomain( d0 );
2373             p00.addProteinDomain( a0 );
2374             p00.addProteinDomain( x0 );
2375             p00.addProteinDomain( y1 );
2376             p00.addProteinDomain( y2 );
2377             p00.addProteinDomain( y3 );
2378             p00.addProteinDomain( e1 );
2379             p00.addProteinDomain( e2 );
2380             p00.addProteinDomain( e3 );
2381             p00.addProteinDomain( e4 );
2382             p00.addProteinDomain( e5 );
2383             p00.addProteinDomain( z0 );
2384             p00.addProteinDomain( z1 );
2385             p00.addProteinDomain( z2 );
2386             p00.addProteinDomain( zz0 );
2387             p00.addProteinDomain( zz1 );
2388             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2389                 return false;
2390             }
2391             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2392                 return false;
2393             }
2394             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2395                 return false;
2396             }
2397             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2398                 return false;
2399             }
2400             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" ) ) {
2401                 return false;
2402             }
2403             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2404             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2405             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2406             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2407             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2408             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2409             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2410             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2411             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2412             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2413             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2414             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2415             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2416             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2417             p.addProteinDomain( B15 );
2418             p.addProteinDomain( C50 );
2419             p.addProteinDomain( A60 );
2420             p.addProteinDomain( A30 );
2421             p.addProteinDomain( C70 );
2422             p.addProteinDomain( B35 );
2423             p.addProteinDomain( B40 );
2424             p.addProteinDomain( A0 );
2425             p.addProteinDomain( A10 );
2426             p.addProteinDomain( A20 );
2427             p.addProteinDomain( B25 );
2428             p.addProteinDomain( D80 );
2429             List<String> domains_ids = new ArrayList<String>();
2430             domains_ids.add( "A" );
2431             domains_ids.add( "B" );
2432             domains_ids.add( "C" );
2433             if ( !p.contains( domains_ids, false ) ) {
2434                 return false;
2435             }
2436             if ( !p.contains( domains_ids, true ) ) {
2437                 return false;
2438             }
2439             domains_ids.add( "X" );
2440             if ( p.contains( domains_ids, false ) ) {
2441                 return false;
2442             }
2443             if ( p.contains( domains_ids, true ) ) {
2444                 return false;
2445             }
2446             domains_ids = new ArrayList<String>();
2447             domains_ids.add( "A" );
2448             domains_ids.add( "C" );
2449             domains_ids.add( "D" );
2450             if ( !p.contains( domains_ids, false ) ) {
2451                 return false;
2452             }
2453             if ( !p.contains( domains_ids, true ) ) {
2454                 return false;
2455             }
2456             domains_ids = new ArrayList<String>();
2457             domains_ids.add( "A" );
2458             domains_ids.add( "D" );
2459             domains_ids.add( "C" );
2460             if ( !p.contains( domains_ids, false ) ) {
2461                 return false;
2462             }
2463             if ( p.contains( domains_ids, true ) ) {
2464                 return false;
2465             }
2466             domains_ids = new ArrayList<String>();
2467             domains_ids.add( "A" );
2468             domains_ids.add( "A" );
2469             domains_ids.add( "B" );
2470             if ( !p.contains( domains_ids, false ) ) {
2471                 return false;
2472             }
2473             if ( !p.contains( domains_ids, true ) ) {
2474                 return false;
2475             }
2476             domains_ids = new ArrayList<String>();
2477             domains_ids.add( "A" );
2478             domains_ids.add( "A" );
2479             domains_ids.add( "A" );
2480             domains_ids.add( "B" );
2481             domains_ids.add( "B" );
2482             if ( !p.contains( domains_ids, false ) ) {
2483                 return false;
2484             }
2485             if ( !p.contains( domains_ids, true ) ) {
2486                 return false;
2487             }
2488             domains_ids = new ArrayList<String>();
2489             domains_ids.add( "A" );
2490             domains_ids.add( "A" );
2491             domains_ids.add( "B" );
2492             domains_ids.add( "A" );
2493             domains_ids.add( "B" );
2494             domains_ids.add( "B" );
2495             domains_ids.add( "A" );
2496             domains_ids.add( "B" );
2497             domains_ids.add( "C" );
2498             domains_ids.add( "A" );
2499             domains_ids.add( "C" );
2500             domains_ids.add( "D" );
2501             if ( !p.contains( domains_ids, false ) ) {
2502                 return false;
2503             }
2504             if ( p.contains( domains_ids, true ) ) {
2505                 return false;
2506             }
2507         }
2508         catch ( final Exception e ) {
2509             e.printStackTrace( System.out );
2510             return false;
2511         }
2512         return true;
2513     }
2514
2515     private static boolean testBasicTable() {
2516         try {
2517             final BasicTable<String> t0 = new BasicTable<String>();
2518             if ( t0.getNumberOfColumns() != 0 ) {
2519                 return false;
2520             }
2521             if ( t0.getNumberOfRows() != 0 ) {
2522                 return false;
2523             }
2524             t0.setValue( 3, 2, "23" );
2525             t0.setValue( 10, 1, "error" );
2526             t0.setValue( 10, 1, "110" );
2527             t0.setValue( 9, 1, "19" );
2528             t0.setValue( 1, 10, "101" );
2529             t0.setValue( 10, 10, "1010" );
2530             t0.setValue( 100, 10, "10100" );
2531             t0.setValue( 0, 0, "00" );
2532             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2533                 return false;
2534             }
2535             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2536                 return false;
2537             }
2538             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2539                 return false;
2540             }
2541             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2542                 return false;
2543             }
2544             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2545                 return false;
2546             }
2547             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2548                 return false;
2549             }
2550             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2551                 return false;
2552             }
2553             if ( t0.getNumberOfColumns() != 101 ) {
2554                 return false;
2555             }
2556             if ( t0.getNumberOfRows() != 11 ) {
2557                 return false;
2558             }
2559             if ( t0.getValueAsString( 49, 4 ) != null ) {
2560                 return false;
2561             }
2562             final String l = ForesterUtil.getLineSeparator();
2563             final StringBuffer source = new StringBuffer();
2564             source.append( "" + l );
2565             source.append( "# 1 1 1 1 1 1 1 1" + l );
2566             source.append( " 00 01 02 03" + l );
2567             source.append( "   10 11 12 13  " + l );
2568             source.append( "20 21 22 23 " + l );
2569             source.append( "    30  31    32 33" + l );
2570             source.append( "40 41 42 43" + l );
2571             source.append( "  # 1 1 1 1 1 " + l );
2572             source.append( "50 51 52 53 54" + l );
2573             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2574             if ( t1.getNumberOfColumns() != 5 ) {
2575                 return false;
2576             }
2577             if ( t1.getNumberOfRows() != 6 ) {
2578                 return false;
2579             }
2580             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2581                 return false;
2582             }
2583             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2584                 return false;
2585             }
2586             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2587                 return false;
2588             }
2589             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2590                 return false;
2591             }
2592             final StringBuffer source1 = new StringBuffer();
2593             source1.append( "" + l );
2594             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2595             source1.append( " 00; 01 ;02;03" + l );
2596             source1.append( "   10; 11; 12; 13  " + l );
2597             source1.append( "20; 21; 22; 23 " + l );
2598             source1.append( "    30;  31;    32; 33" + l );
2599             source1.append( "40;41;42;43" + l );
2600             source1.append( "  # 1 1 1 1 1 " + l );
2601             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2602             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2603             if ( t2.getNumberOfColumns() != 5 ) {
2604                 return false;
2605             }
2606             if ( t2.getNumberOfRows() != 6 ) {
2607                 return false;
2608             }
2609             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2610                 return false;
2611             }
2612             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2613                 return false;
2614             }
2615             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2616                 return false;
2617             }
2618             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2619                 return false;
2620             }
2621             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2622                 return false;
2623             }
2624             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2625                 return false;
2626             }
2627             final StringBuffer source2 = new StringBuffer();
2628             source2.append( "" + l );
2629             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2630             source2.append( " 00; 01 ;02;03" + l );
2631             source2.append( "   10; 11; 12; 13  " + l );
2632             source2.append( "20; 21; 22; 23 " + l );
2633             source2.append( "                     " + l );
2634             source2.append( "    30;  31;    32; 33" + l );
2635             source2.append( "40;41;42;43" + l );
2636             source2.append( "  comment: 1 1 1 1 1 " + l );
2637             source2.append( ";;;50  ;   52; 53;;54   " + l );
2638             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2639                                                                         ';',
2640                                                                         false,
2641                                                                         false,
2642                                                                         "comment:",
2643                                                                         false );
2644             if ( tl.size() != 2 ) {
2645                 return false;
2646             }
2647             final BasicTable<String> t3 = tl.get( 0 );
2648             final BasicTable<String> t4 = tl.get( 1 );
2649             if ( t3.getNumberOfColumns() != 4 ) {
2650                 return false;
2651             }
2652             if ( t3.getNumberOfRows() != 3 ) {
2653                 return false;
2654             }
2655             if ( t4.getNumberOfColumns() != 4 ) {
2656                 return false;
2657             }
2658             if ( t4.getNumberOfRows() != 3 ) {
2659                 return false;
2660             }
2661             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2662                 return false;
2663             }
2664             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2665                 return false;
2666             }
2667         }
2668         catch ( final Exception e ) {
2669             e.printStackTrace( System.out );
2670             return false;
2671         }
2672         return true;
2673     }
2674
2675     private static boolean testBasicTolXMLparsing() {
2676         try {
2677             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2678             final TolParser parser = new TolParser();
2679             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2680             if ( parser.getErrorCount() > 0 ) {
2681                 System.out.println( parser.getErrorMessages().toString() );
2682                 return false;
2683             }
2684             if ( phylogenies_0.length != 1 ) {
2685                 return false;
2686             }
2687             final Phylogeny t1 = phylogenies_0[ 0 ];
2688             if ( t1.getNumberOfExternalNodes() != 5 ) {
2689                 return false;
2690             }
2691             if ( !t1.isRooted() ) {
2692                 return false;
2693             }
2694             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2695                 return false;
2696             }
2697             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2698                 return false;
2699             }
2700             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2701                 return false;
2702             }
2703             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2704                 return false;
2705             }
2706             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2707             if ( parser.getErrorCount() > 0 ) {
2708                 System.out.println( parser.getErrorMessages().toString() );
2709                 return false;
2710             }
2711             if ( phylogenies_1.length != 1 ) {
2712                 return false;
2713             }
2714             final Phylogeny t2 = phylogenies_1[ 0 ];
2715             if ( t2.getNumberOfExternalNodes() != 664 ) {
2716                 return false;
2717             }
2718             if ( !t2.isRooted() ) {
2719                 return false;
2720             }
2721             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2722                 return false;
2723             }
2724             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2725                 return false;
2726             }
2727             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2728                 return false;
2729             }
2730             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2731                 return false;
2732             }
2733             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2734                 return false;
2735             }
2736             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2737                     .equals( "Aquifex" ) ) {
2738                 return false;
2739             }
2740             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2741             if ( parser.getErrorCount() > 0 ) {
2742                 System.out.println( parser.getErrorMessages().toString() );
2743                 return false;
2744             }
2745             if ( phylogenies_2.length != 1 ) {
2746                 return false;
2747             }
2748             final Phylogeny t3 = phylogenies_2[ 0 ];
2749             if ( t3.getNumberOfExternalNodes() != 184 ) {
2750                 return false;
2751             }
2752             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2753                 return false;
2754             }
2755             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2756                 return false;
2757             }
2758             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2759                 return false;
2760             }
2761             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2762             if ( parser.getErrorCount() > 0 ) {
2763                 System.out.println( parser.getErrorMessages().toString() );
2764                 return false;
2765             }
2766             if ( phylogenies_3.length != 1 ) {
2767                 return false;
2768             }
2769             final Phylogeny t4 = phylogenies_3[ 0 ];
2770             if ( t4.getNumberOfExternalNodes() != 1 ) {
2771                 return false;
2772             }
2773             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2774                 return false;
2775             }
2776             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2777                 return false;
2778             }
2779             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2780                 return false;
2781             }
2782             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2783             if ( parser.getErrorCount() > 0 ) {
2784                 System.out.println( parser.getErrorMessages().toString() );
2785                 return false;
2786             }
2787             if ( phylogenies_4.length != 1 ) {
2788                 return false;
2789             }
2790             final Phylogeny t5 = phylogenies_4[ 0 ];
2791             if ( t5.getNumberOfExternalNodes() != 13 ) {
2792                 return false;
2793             }
2794             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2795                 return false;
2796             }
2797             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2798                 return false;
2799             }
2800             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2801                 return false;
2802             }
2803         }
2804         catch ( final Exception e ) {
2805             e.printStackTrace( System.out );
2806             return false;
2807         }
2808         return true;
2809     }
2810
2811     private static boolean testBasicTreeMethods() {
2812         try {
2813             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2814             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2815             if ( t2.getNumberOfExternalNodes() != 4 ) {
2816                 return false;
2817             }
2818             if ( t2.getHeight() != 8.5 ) {
2819                 return false;
2820             }
2821             if ( !t2.isCompletelyBinary() ) {
2822                 return false;
2823             }
2824             if ( t2.isEmpty() ) {
2825                 return false;
2826             }
2827             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2828             if ( t3.getNumberOfExternalNodes() != 5 ) {
2829                 return false;
2830             }
2831             if ( t3.getHeight() != 11 ) {
2832                 return false;
2833             }
2834             if ( t3.isCompletelyBinary() ) {
2835                 return false;
2836             }
2837             final PhylogenyNode n = t3.getNode( "ABC" );
2838             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 ];
2839             if ( t4.getNumberOfExternalNodes() != 9 ) {
2840                 return false;
2841             }
2842             if ( t4.getHeight() != 11 ) {
2843                 return false;
2844             }
2845             if ( t4.isCompletelyBinary() ) {
2846                 return false;
2847             }
2848             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)" );
2849             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2850             if ( t5.getNumberOfExternalNodes() != 8 ) {
2851                 return false;
2852             }
2853             if ( t5.getHeight() != 15 ) {
2854                 return false;
2855             }
2856             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)" );
2857             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2858             if ( t6.getHeight() != 15 ) {
2859                 return false;
2860             }
2861             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)" );
2862             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2863             if ( t7.getHeight() != 15 ) {
2864                 return false;
2865             }
2866             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)" );
2867             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2868             if ( t8.getNumberOfExternalNodes() != 10 ) {
2869                 return false;
2870             }
2871             if ( t8.getHeight() != 15 ) {
2872                 return false;
2873             }
2874             final char[] a9 = new char[] { 'a' };
2875             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2876             if ( t9.getHeight() != 0 ) {
2877                 return false;
2878             }
2879             final char[] a10 = new char[] { 'a', ':', '6' };
2880             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2881             if ( t10.getHeight() != 6 ) {
2882                 return false;
2883             }
2884         }
2885         catch ( final Exception e ) {
2886             e.printStackTrace( System.out );
2887             return false;
2888         }
2889         return true;
2890     }
2891
2892     private static boolean testConfidenceAssessor() {
2893         try {
2894             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2895             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2896             final Phylogeny[] ev0 = factory
2897                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2898                              new NHXParser() );
2899             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2900             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2901                 return false;
2902             }
2903             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2904                 return false;
2905             }
2906             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2907             final Phylogeny[] ev1 = factory
2908                     .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)));",
2909                              new NHXParser() );
2910             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2911             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2912                 return false;
2913             }
2914             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2915                 return false;
2916             }
2917             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2918             final Phylogeny[] ev_b = factory
2919                     .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",
2920                              new NHXParser() );
2921             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2922             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2923                 return false;
2924             }
2925             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2926                 return false;
2927             }
2928             //
2929             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2930             final Phylogeny[] ev1x = factory
2931                     .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)));",
2932                              new NHXParser() );
2933             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2934             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2935                 return false;
2936             }
2937             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2938                 return false;
2939             }
2940             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2941             final Phylogeny[] ev_bx = factory
2942                     .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",
2943                              new NHXParser() );
2944             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2945             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2946                 return false;
2947             }
2948             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2949                 return false;
2950             }
2951             //
2952             final Phylogeny[] t2 = factory
2953                     .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);",
2954                              new NHXParser() );
2955             final Phylogeny[] ev2 = factory
2956                     .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);",
2957                              new NHXParser() );
2958             for( final Phylogeny target : t2 ) {
2959                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2960             }
2961             //
2962             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2963                                                  new NHXParser() )[ 0 ];
2964             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2965             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2966             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2967                 return false;
2968             }
2969             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2970                 return false;
2971             }
2972             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2973                 return false;
2974             }
2975         }
2976         catch ( final Exception e ) {
2977             e.printStackTrace();
2978             return false;
2979         }
2980         return true;
2981     }
2982
2983     private static boolean testCopyOfNodeData() {
2984         try {
2985             final PhylogenyNode n1 = PhylogenyNode
2986                     .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]" );
2987             final PhylogenyNode n2 = n1.copyNodeData();
2988             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2989                 return false;
2990             }
2991         }
2992         catch ( final Exception e ) {
2993             e.printStackTrace();
2994             return false;
2995         }
2996         return true;
2997     }
2998
2999     private static boolean testCreateBalancedPhylogeny() {
3000         try {
3001             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3002             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3003                 return false;
3004             }
3005             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3006                 return false;
3007             }
3008             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3009             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3010                 return false;
3011             }
3012             if ( p1.getNumberOfExternalNodes() != 100 ) {
3013                 return false;
3014             }
3015         }
3016         catch ( final Exception e ) {
3017             e.printStackTrace();
3018             return false;
3019         }
3020         return true;
3021     }
3022
3023     private static boolean testCreateUriForSeqWeb() {
3024         try {
3025             final PhylogenyNode n = new PhylogenyNode();
3026             n.setName( "tr|B3RJ64" );
3027             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3028                 return false;
3029             }
3030             n.setName( "B0LM41_HUMAN" );
3031             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3032                 return false;
3033             }
3034             n.setName( "NP_001025424" );
3035             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3036                 return false;
3037             }
3038             n.setName( "_NM_001030253-" );
3039             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3040                 return false;
3041             }
3042             n.setName( "XM_002122186" );
3043             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3044                 return false;
3045             }
3046             n.setName( "dgh_AAA34956_gdg" );
3047             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3048                 return false;
3049             }
3050             n.setName( "AAA34956" );
3051             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3052                 return false;
3053             }
3054             n.setName( "GI:394892" );
3055             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3056                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3057                 return false;
3058             }
3059             n.setName( "gi_394892" );
3060             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3061                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3062                 return false;
3063             }
3064             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3065             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3066                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3067                 return false;
3068             }
3069             n.setName( "P12345" );
3070             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3071                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3072                 return false;
3073             }
3074             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3075             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3076                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3077                 return false;
3078             }
3079         }
3080         catch ( final Exception e ) {
3081             e.printStackTrace( System.out );
3082             return false;
3083         }
3084         return true;
3085     }
3086
3087     private static boolean testDataObjects() {
3088         try {
3089             final Confidence s0 = new Confidence();
3090             final Confidence s1 = new Confidence();
3091             if ( !s0.isEqual( s1 ) ) {
3092                 return false;
3093             }
3094             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3095             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3096             if ( s2.isEqual( s1 ) ) {
3097                 return false;
3098             }
3099             if ( !s2.isEqual( s3 ) ) {
3100                 return false;
3101             }
3102             final Confidence s4 = ( Confidence ) s3.copy();
3103             if ( !s4.isEqual( s3 ) ) {
3104                 return false;
3105             }
3106             s3.asSimpleText();
3107             s3.asText();
3108             // Taxonomy
3109             // ----------
3110             final Taxonomy t1 = new Taxonomy();
3111             final Taxonomy t2 = new Taxonomy();
3112             final Taxonomy t3 = new Taxonomy();
3113             final Taxonomy t4 = new Taxonomy();
3114             final Taxonomy t5 = new Taxonomy();
3115             t1.setIdentifier( new Identifier( "ecoli" ) );
3116             t1.setTaxonomyCode( "ECOLI" );
3117             t1.setScientificName( "E. coli" );
3118             t1.setCommonName( "coli" );
3119             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3120             if ( !t1.isEqual( t0 ) ) {
3121                 return false;
3122             }
3123             t2.setIdentifier( new Identifier( "ecoli" ) );
3124             t2.setTaxonomyCode( "OTHER" );
3125             t2.setScientificName( "what" );
3126             t2.setCommonName( "something" );
3127             if ( !t1.isEqual( t2 ) ) {
3128                 return false;
3129             }
3130             t2.setIdentifier( new Identifier( "nemve" ) );
3131             if ( t1.isEqual( t2 ) ) {
3132                 return false;
3133             }
3134             t1.setIdentifier( null );
3135             t3.setTaxonomyCode( "ECOLI" );
3136             t3.setScientificName( "what" );
3137             t3.setCommonName( "something" );
3138             if ( !t1.isEqual( t3 ) ) {
3139                 return false;
3140             }
3141             t1.setIdentifier( null );
3142             t1.setTaxonomyCode( "" );
3143             t4.setScientificName( "E. ColI" );
3144             t4.setCommonName( "something" );
3145             if ( !t1.isEqual( t4 ) ) {
3146                 return false;
3147             }
3148             t4.setScientificName( "B. subtilis" );
3149             t4.setCommonName( "something" );
3150             if ( t1.isEqual( t4 ) ) {
3151                 return false;
3152             }
3153             t1.setIdentifier( null );
3154             t1.setTaxonomyCode( "" );
3155             t1.setScientificName( "" );
3156             t5.setCommonName( "COLI" );
3157             if ( !t1.isEqual( t5 ) ) {
3158                 return false;
3159             }
3160             t5.setCommonName( "vibrio" );
3161             if ( t1.isEqual( t5 ) ) {
3162                 return false;
3163             }
3164             // Identifier
3165             // ----------
3166             final Identifier id0 = new Identifier( "123", "pfam" );
3167             final Identifier id1 = ( Identifier ) id0.copy();
3168             if ( !id1.isEqual( id1 ) ) {
3169                 return false;
3170             }
3171             if ( !id1.isEqual( id0 ) ) {
3172                 return false;
3173             }
3174             if ( !id0.isEqual( id1 ) ) {
3175                 return false;
3176             }
3177             id1.asSimpleText();
3178             id1.asText();
3179             // ProteinDomain
3180             // ---------------
3181             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3182             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3183             if ( !pd1.isEqual( pd1 ) ) {
3184                 return false;
3185             }
3186             if ( !pd1.isEqual( pd0 ) ) {
3187                 return false;
3188             }
3189             pd1.asSimpleText();
3190             pd1.asText();
3191             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3192             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3193             if ( !pd3.isEqual( pd3 ) ) {
3194                 return false;
3195             }
3196             if ( !pd2.isEqual( pd3 ) ) {
3197                 return false;
3198             }
3199             if ( !pd0.isEqual( pd3 ) ) {
3200                 return false;
3201             }
3202             pd3.asSimpleText();
3203             pd3.asText();
3204             // DomainArchitecture
3205             // ------------------
3206             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3207             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3208             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3209             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3210             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3211             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3212             domains0.add( d2 );
3213             domains0.add( d0 );
3214             domains0.add( d3 );
3215             domains0.add( d1 );
3216             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3217             if ( ds0.getNumberOfDomains() != 4 ) {
3218                 return false;
3219             }
3220             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3221             if ( !ds0.isEqual( ds0 ) ) {
3222                 return false;
3223             }
3224             if ( !ds0.isEqual( ds1 ) ) {
3225                 return false;
3226             }
3227             if ( ds1.getNumberOfDomains() != 4 ) {
3228                 return false;
3229             }
3230             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3231             domains1.add( d1 );
3232             domains1.add( d2 );
3233             domains1.add( d4 );
3234             domains1.add( d0 );
3235             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3236             if ( ds0.isEqual( ds2 ) ) {
3237                 return false;
3238             }
3239             ds1.asSimpleText();
3240             ds1.asText();
3241             ds1.toNHX();
3242             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3243             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3244                 System.out.println( ds3.toNHX() );
3245                 return false;
3246             }
3247             if ( ds3.getNumberOfDomains() != 3 ) {
3248                 return false;
3249             }
3250             // Event
3251             // -----
3252             final Event e1 = new Event( Event.EventType.fusion );
3253             if ( e1.isDuplication() ) {
3254                 return false;
3255             }
3256             if ( !e1.isFusion() ) {
3257                 return false;
3258             }
3259             if ( !e1.asText().toString().equals( "fusion" ) ) {
3260                 return false;
3261             }
3262             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3263                 return false;
3264             }
3265             final Event e11 = new Event( Event.EventType.fusion );
3266             if ( !e11.isEqual( e1 ) ) {
3267                 return false;
3268             }
3269             if ( !e11.toNHX().toString().equals( "" ) ) {
3270                 return false;
3271             }
3272             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3273             if ( e2.isDuplication() ) {
3274                 return false;
3275             }
3276             if ( !e2.isSpeciationOrDuplication() ) {
3277                 return false;
3278             }
3279             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3280                 return false;
3281             }
3282             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3283                 return false;
3284             }
3285             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3286                 return false;
3287             }
3288             if ( e11.isEqual( e2 ) ) {
3289                 return false;
3290             }
3291             final Event e2c = ( Event ) e2.copy();
3292             if ( !e2c.isEqual( e2 ) ) {
3293                 return false;
3294             }
3295             Event e3 = new Event( 1, 2, 3 );
3296             if ( e3.isDuplication() ) {
3297                 return false;
3298             }
3299             if ( e3.isSpeciation() ) {
3300                 return false;
3301             }
3302             if ( e3.isGeneLoss() ) {
3303                 return false;
3304             }
3305             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3306                 return false;
3307             }
3308             final Event e3c = ( Event ) e3.copy();
3309             final Event e3cc = ( Event ) e3c.copy();
3310             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3311                 return false;
3312             }
3313             e3 = null;
3314             if ( !e3c.isEqual( e3cc ) ) {
3315                 return false;
3316             }
3317             Event e4 = new Event( 1, 2, 3 );
3318             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3319                 return false;
3320             }
3321             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3322                 return false;
3323             }
3324             final Event e4c = ( Event ) e4.copy();
3325             e4 = null;
3326             final Event e4cc = ( Event ) e4c.copy();
3327             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3328                 return false;
3329             }
3330             if ( !e4c.isEqual( e4cc ) ) {
3331                 return false;
3332             }
3333             final Event e5 = new Event();
3334             if ( !e5.isUnassigned() ) {
3335                 return false;
3336             }
3337             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3338                 return false;
3339             }
3340             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3341                 return false;
3342             }
3343             final Event e6 = new Event( 1, 0, 0 );
3344             if ( !e6.asText().toString().equals( "duplication" ) ) {
3345                 return false;
3346             }
3347             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3348                 return false;
3349             }
3350             final Event e7 = new Event( 0, 1, 0 );
3351             if ( !e7.asText().toString().equals( "speciation" ) ) {
3352                 return false;
3353             }
3354             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3355                 return false;
3356             }
3357             final Event e8 = new Event( 0, 0, 1 );
3358             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3359                 return false;
3360             }
3361             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3362                 return false;
3363             }
3364         }
3365         catch ( final Exception e ) {
3366             e.printStackTrace( System.out );
3367             return false;
3368         }
3369         return true;
3370     }
3371
3372     private static boolean testDeletionOfExternalNodes() {
3373         try {
3374             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3375             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3376             final PhylogenyWriter w = new PhylogenyWriter();
3377             if ( t0.isEmpty() ) {
3378                 return false;
3379             }
3380             if ( t0.getNumberOfExternalNodes() != 1 ) {
3381                 return false;
3382             }
3383             t0.deleteSubtree( t0.getNode( "A" ), false );
3384             if ( t0.getNumberOfExternalNodes() != 0 ) {
3385                 return false;
3386             }
3387             if ( !t0.isEmpty() ) {
3388                 return false;
3389             }
3390             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3391             if ( t1.getNumberOfExternalNodes() != 2 ) {
3392                 return false;
3393             }
3394             t1.deleteSubtree( t1.getNode( "A" ), false );
3395             if ( t1.getNumberOfExternalNodes() != 1 ) {
3396                 return false;
3397             }
3398             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3399                 return false;
3400             }
3401             t1.deleteSubtree( t1.getNode( "B" ), false );
3402             if ( t1.getNumberOfExternalNodes() != 1 ) {
3403                 return false;
3404             }
3405             t1.deleteSubtree( t1.getNode( "r" ), false );
3406             if ( !t1.isEmpty() ) {
3407                 return false;
3408             }
3409             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3410             if ( t2.getNumberOfExternalNodes() != 3 ) {
3411                 return false;
3412             }
3413             t2.deleteSubtree( t2.getNode( "B" ), false );
3414             if ( t2.getNumberOfExternalNodes() != 2 ) {
3415                 return false;
3416             }
3417             t2.toNewHampshireX();
3418             PhylogenyNode n = t2.getNode( "A" );
3419             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3420                 return false;
3421             }
3422             t2.deleteSubtree( t2.getNode( "A" ), false );
3423             if ( t2.getNumberOfExternalNodes() != 2 ) {
3424                 return false;
3425             }
3426             t2.deleteSubtree( t2.getNode( "C" ), true );
3427             if ( t2.getNumberOfExternalNodes() != 1 ) {
3428                 return false;
3429             }
3430             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3431             if ( t3.getNumberOfExternalNodes() != 4 ) {
3432                 return false;
3433             }
3434             t3.deleteSubtree( t3.getNode( "B" ), true );
3435             if ( t3.getNumberOfExternalNodes() != 3 ) {
3436                 return false;
3437             }
3438             n = t3.getNode( "A" );
3439             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3440                 return false;
3441             }
3442             n = n.getNextExternalNode();
3443             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3444                 return false;
3445             }
3446             t3.deleteSubtree( t3.getNode( "A" ), true );
3447             if ( t3.getNumberOfExternalNodes() != 2 ) {
3448                 return false;
3449             }
3450             n = t3.getNode( "C" );
3451             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3452                 return false;
3453             }
3454             t3.deleteSubtree( t3.getNode( "C" ), true );
3455             if ( t3.getNumberOfExternalNodes() != 1 ) {
3456                 return false;
3457             }
3458             t3.deleteSubtree( t3.getNode( "D" ), true );
3459             if ( t3.getNumberOfExternalNodes() != 0 ) {
3460                 return false;
3461             }
3462             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3463             if ( t4.getNumberOfExternalNodes() != 6 ) {
3464                 return false;
3465             }
3466             t4.deleteSubtree( t4.getNode( "B2" ), true );
3467             if ( t4.getNumberOfExternalNodes() != 5 ) {
3468                 return false;
3469             }
3470             String s = w.toNewHampshire( t4, true ).toString();
3471             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3472                 return false;
3473             }
3474             t4.deleteSubtree( t4.getNode( "B11" ), true );
3475             if ( t4.getNumberOfExternalNodes() != 4 ) {
3476                 return false;
3477             }
3478             t4.deleteSubtree( t4.getNode( "C" ), true );
3479             if ( t4.getNumberOfExternalNodes() != 3 ) {
3480                 return false;
3481             }
3482             n = t4.getNode( "A" );
3483             n = n.getNextExternalNode();
3484             if ( !n.getName().equals( "B12" ) ) {
3485                 return false;
3486             }
3487             n = n.getNextExternalNode();
3488             if ( !n.getName().equals( "D" ) ) {
3489                 return false;
3490             }
3491             s = w.toNewHampshire( t4, true ).toString();
3492             if ( !s.equals( "((A,B12),D);" ) ) {
3493                 return false;
3494             }
3495             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3496             t5.deleteSubtree( t5.getNode( "A" ), true );
3497             if ( t5.getNumberOfExternalNodes() != 5 ) {
3498                 return false;
3499             }
3500             s = w.toNewHampshire( t5, true ).toString();
3501             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3502                 return false;
3503             }
3504             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3505             t6.deleteSubtree( t6.getNode( "B11" ), true );
3506             if ( t6.getNumberOfExternalNodes() != 5 ) {
3507                 return false;
3508             }
3509             s = w.toNewHampshire( t6, false ).toString();
3510             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3511                 return false;
3512             }
3513             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3514             t7.deleteSubtree( t7.getNode( "B12" ), true );
3515             if ( t7.getNumberOfExternalNodes() != 5 ) {
3516                 return false;
3517             }
3518             s = w.toNewHampshire( t7, true ).toString();
3519             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3520                 return false;
3521             }
3522             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3523             t8.deleteSubtree( t8.getNode( "B2" ), true );
3524             if ( t8.getNumberOfExternalNodes() != 5 ) {
3525                 return false;
3526             }
3527             s = w.toNewHampshire( t8, false ).toString();
3528             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3529                 return false;
3530             }
3531             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3532             t9.deleteSubtree( t9.getNode( "C" ), true );
3533             if ( t9.getNumberOfExternalNodes() != 5 ) {
3534                 return false;
3535             }
3536             s = w.toNewHampshire( t9, true ).toString();
3537             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3538                 return false;
3539             }
3540             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3541             t10.deleteSubtree( t10.getNode( "D" ), true );
3542             if ( t10.getNumberOfExternalNodes() != 5 ) {
3543                 return false;
3544             }
3545             s = w.toNewHampshire( t10, true ).toString();
3546             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3547                 return false;
3548             }
3549             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3550             t11.deleteSubtree( t11.getNode( "A" ), true );
3551             if ( t11.getNumberOfExternalNodes() != 2 ) {
3552                 return false;
3553             }
3554             s = w.toNewHampshire( t11, true ).toString();
3555             if ( !s.equals( "(B,C);" ) ) {
3556                 return false;
3557             }
3558             t11.deleteSubtree( t11.getNode( "C" ), true );
3559             if ( t11.getNumberOfExternalNodes() != 1 ) {
3560                 return false;
3561             }
3562             s = w.toNewHampshire( t11, false ).toString();
3563             if ( !s.equals( "B;" ) ) {
3564                 return false;
3565             }
3566             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3567             t12.deleteSubtree( t12.getNode( "B2" ), true );
3568             if ( t12.getNumberOfExternalNodes() != 8 ) {
3569                 return false;
3570             }
3571             s = w.toNewHampshire( t12, true ).toString();
3572             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3573                 return false;
3574             }
3575             t12.deleteSubtree( t12.getNode( "B3" ), true );
3576             if ( t12.getNumberOfExternalNodes() != 7 ) {
3577                 return false;
3578             }
3579             s = w.toNewHampshire( t12, true ).toString();
3580             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3581                 return false;
3582             }
3583             t12.deleteSubtree( t12.getNode( "C3" ), true );
3584             if ( t12.getNumberOfExternalNodes() != 6 ) {
3585                 return false;
3586             }
3587             s = w.toNewHampshire( t12, true ).toString();
3588             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3589                 return false;
3590             }
3591             t12.deleteSubtree( t12.getNode( "A1" ), true );
3592             if ( t12.getNumberOfExternalNodes() != 5 ) {
3593                 return false;
3594             }
3595             s = w.toNewHampshire( t12, true ).toString();
3596             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3597                 return false;
3598             }
3599             t12.deleteSubtree( t12.getNode( "B1" ), true );
3600             if ( t12.getNumberOfExternalNodes() != 4 ) {
3601                 return false;
3602             }
3603             s = w.toNewHampshire( t12, true ).toString();
3604             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3605                 return false;
3606             }
3607             t12.deleteSubtree( t12.getNode( "A3" ), true );
3608             if ( t12.getNumberOfExternalNodes() != 3 ) {
3609                 return false;
3610             }
3611             s = w.toNewHampshire( t12, true ).toString();
3612             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3613                 return false;
3614             }
3615             t12.deleteSubtree( t12.getNode( "A2" ), true );
3616             if ( t12.getNumberOfExternalNodes() != 2 ) {
3617                 return false;
3618             }
3619             s = w.toNewHampshire( t12, true ).toString();
3620             if ( !s.equals( "(C1,C2);" ) ) {
3621                 return false;
3622             }
3623             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3624             t13.deleteSubtree( t13.getNode( "D" ), true );
3625             if ( t13.getNumberOfExternalNodes() != 4 ) {
3626                 return false;
3627             }
3628             s = w.toNewHampshire( t13, true ).toString();
3629             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3630                 return false;
3631             }
3632             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3633             t14.deleteSubtree( t14.getNode( "E" ), true );
3634             if ( t14.getNumberOfExternalNodes() != 5 ) {
3635                 return false;
3636             }
3637             s = w.toNewHampshire( t14, true ).toString();
3638             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3639                 return false;
3640             }
3641             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3642             t15.deleteSubtree( t15.getNode( "B2" ), true );
3643             if ( t15.getNumberOfExternalNodes() != 11 ) {
3644                 return false;
3645             }
3646             t15.deleteSubtree( t15.getNode( "B1" ), true );
3647             if ( t15.getNumberOfExternalNodes() != 10 ) {
3648                 return false;
3649             }
3650             t15.deleteSubtree( t15.getNode( "B3" ), true );
3651             if ( t15.getNumberOfExternalNodes() != 9 ) {
3652                 return false;
3653             }
3654             t15.deleteSubtree( t15.getNode( "B4" ), true );
3655             if ( t15.getNumberOfExternalNodes() != 8 ) {
3656                 return false;
3657             }
3658             t15.deleteSubtree( t15.getNode( "A1" ), true );
3659             if ( t15.getNumberOfExternalNodes() != 7 ) {
3660                 return false;
3661             }
3662             t15.deleteSubtree( t15.getNode( "C4" ), true );
3663             if ( t15.getNumberOfExternalNodes() != 6 ) {
3664                 return false;
3665             }
3666         }
3667         catch ( final Exception e ) {
3668             e.printStackTrace( System.out );
3669             return false;
3670         }
3671         return true;
3672     }
3673
3674     private static boolean testDescriptiveStatistics() {
3675         try {
3676             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3677             dss1.addValue( 82 );
3678             dss1.addValue( 78 );
3679             dss1.addValue( 70 );
3680             dss1.addValue( 58 );
3681             dss1.addValue( 42 );
3682             if ( dss1.getN() != 5 ) {
3683                 return false;
3684             }
3685             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3686                 return false;
3687             }
3688             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3689                 return false;
3690             }
3691             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3692                 return false;
3693             }
3694             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3695                 return false;
3696             }
3697             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3698                 return false;
3699             }
3700             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3701                 return false;
3702             }
3703             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3704                 return false;
3705             }
3706             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3707                 return false;
3708             }
3709             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3710                 return false;
3711             }
3712             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3713                 return false;
3714             }
3715             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3716                 return false;
3717             }
3718             dss1.addValue( 123 );
3719             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3720                 return false;
3721             }
3722             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3723                 return false;
3724             }
3725             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3726                 return false;
3727             }
3728             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3729             dss2.addValue( -1.85 );
3730             dss2.addValue( 57.5 );
3731             dss2.addValue( 92.78 );
3732             dss2.addValue( 57.78 );
3733             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3734                 return false;
3735             }
3736             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3737                 return false;
3738             }
3739             final double[] a = dss2.getDataAsDoubleArray();
3740             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3741                 return false;
3742             }
3743             dss2.addValue( -100 );
3744             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3745                 return false;
3746             }
3747             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3748                 return false;
3749             }
3750             final double[] ds = new double[ 14 ];
3751             ds[ 0 ] = 34;
3752             ds[ 1 ] = 23;
3753             ds[ 2 ] = 1;
3754             ds[ 3 ] = 32;
3755             ds[ 4 ] = 11;
3756             ds[ 5 ] = 2;
3757             ds[ 6 ] = 12;
3758             ds[ 7 ] = 33;
3759             ds[ 8 ] = 13;
3760             ds[ 9 ] = 22;
3761             ds[ 10 ] = 21;
3762             ds[ 11 ] = 35;
3763             ds[ 12 ] = 24;
3764             ds[ 13 ] = 31;
3765             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3766             if ( bins.length != 4 ) {
3767                 return false;
3768             }
3769             if ( bins[ 0 ] != 2 ) {
3770                 return false;
3771             }
3772             if ( bins[ 1 ] != 3 ) {
3773                 return false;
3774             }
3775             if ( bins[ 2 ] != 4 ) {
3776                 return false;
3777             }
3778             if ( bins[ 3 ] != 5 ) {
3779                 return false;
3780             }
3781             final double[] ds1 = new double[ 9 ];
3782             ds1[ 0 ] = 10.0;
3783             ds1[ 1 ] = 19.0;
3784             ds1[ 2 ] = 9.999;
3785             ds1[ 3 ] = 0.0;
3786             ds1[ 4 ] = 39.9;
3787             ds1[ 5 ] = 39.999;
3788             ds1[ 6 ] = 30.0;
3789             ds1[ 7 ] = 19.999;
3790             ds1[ 8 ] = 30.1;
3791             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3792             if ( bins1.length != 4 ) {
3793                 return false;
3794             }
3795             if ( bins1[ 0 ] != 2 ) {
3796                 return false;
3797             }
3798             if ( bins1[ 1 ] != 3 ) {
3799                 return false;
3800             }
3801             if ( bins1[ 2 ] != 0 ) {
3802                 return false;
3803             }
3804             if ( bins1[ 3 ] != 4 ) {
3805                 return false;
3806             }
3807             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3808             if ( bins1_1.length != 3 ) {
3809                 return false;
3810             }
3811             if ( bins1_1[ 0 ] != 3 ) {
3812                 return false;
3813             }
3814             if ( bins1_1[ 1 ] != 2 ) {
3815                 return false;
3816             }
3817             if ( bins1_1[ 2 ] != 4 ) {
3818                 return false;
3819             }
3820             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3821             if ( bins1_2.length != 3 ) {
3822                 return false;
3823             }
3824             if ( bins1_2[ 0 ] != 2 ) {
3825                 return false;
3826             }
3827             if ( bins1_2[ 1 ] != 2 ) {
3828                 return false;
3829             }
3830             if ( bins1_2[ 2 ] != 2 ) {
3831                 return false;
3832             }
3833             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3834             dss3.addValue( 1 );
3835             dss3.addValue( 1 );
3836             dss3.addValue( 1 );
3837             dss3.addValue( 2 );
3838             dss3.addValue( 3 );
3839             dss3.addValue( 4 );
3840             dss3.addValue( 5 );
3841             dss3.addValue( 5 );
3842             dss3.addValue( 5 );
3843             dss3.addValue( 6 );
3844             dss3.addValue( 7 );
3845             dss3.addValue( 8 );
3846             dss3.addValue( 9 );
3847             dss3.addValue( 10 );
3848             dss3.addValue( 10 );
3849             dss3.addValue( 10 );
3850             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3851             histo.toStringBuffer( 10, '=', 40, 5 );
3852             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3853         }
3854         catch ( final Exception e ) {
3855             e.printStackTrace( System.out );
3856             return false;
3857         }
3858         return true;
3859     }
3860
3861     private static boolean testDir( final String file ) {
3862         try {
3863             final File f = new File( file );
3864             if ( !f.exists() ) {
3865                 return false;
3866             }
3867             if ( !f.isDirectory() ) {
3868                 return false;
3869             }
3870             if ( !f.canRead() ) {
3871                 return false;
3872             }
3873         }
3874         catch ( final Exception e ) {
3875             return false;
3876         }
3877         return true;
3878     }
3879
3880     private static boolean testEbiEntryRetrieval() {
3881         try {
3882             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3883             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3884                 System.out.println( entry.getAccession() );
3885                 return false;
3886             }
3887             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3888                 System.out.println( entry.getTaxonomyScientificName() );
3889                 return false;
3890             }
3891             if ( !entry.getSequenceName()
3892                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3893                 System.out.println( entry.getSequenceName() );
3894                 return false;
3895             }
3896             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
3897             //     System.out.println( entry.getSequenceSymbol() );
3898             //     return false;
3899             // }
3900             if ( !entry.getGeneName().equals( "treX-like" ) ) {
3901                 System.out.println( entry.getGeneName() );
3902                 return false;
3903             }
3904             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
3905                 System.out.println( entry.getTaxonomyIdentifier() );
3906                 return false;
3907             }
3908             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
3909                 System.out.println( entry.getAnnotations().first().getRefValue() );
3910                 return false;
3911             }
3912             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
3913                 System.out.println( entry.getAnnotations().first().getRefSource() );
3914                 return false;
3915             }
3916             if ( entry.getCrossReferences().size() != 5 ) {
3917                 return false;
3918             }
3919             //
3920             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
3921             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
3922                 return false;
3923             }
3924             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
3925                 System.out.println( entry1.getTaxonomyScientificName() );
3926                 return false;
3927             }
3928             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
3929                 System.out.println( entry1.getSequenceName() );
3930                 return false;
3931             }
3932             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
3933                 System.out.println( entry1.getTaxonomyIdentifier() );
3934                 return false;
3935             }
3936             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
3937                 System.out.println( entry1.getGeneName() );
3938                 return false;
3939             }
3940             if ( entry1.getCrossReferences().size() != 6 ) {
3941                 return false;
3942             }
3943             //
3944             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
3945             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
3946                 return false;
3947             }
3948             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3949                 System.out.println( entry2.getTaxonomyScientificName() );
3950                 return false;
3951             }
3952             if ( !entry2.getSequenceName()
3953                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
3954                 System.out.println( entry2.getSequenceName() );
3955                 return false;
3956             }
3957             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
3958                 System.out.println( entry2.getTaxonomyIdentifier() );
3959                 return false;
3960             }
3961             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
3962                 System.out.println( entry2.getGeneName() );
3963                 return false;
3964             }
3965             if ( entry2.getCrossReferences().size() != 3 ) {
3966                 return false;
3967             }
3968             //
3969             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
3970             if ( !entry3.getAccession().equals( "HM043801" ) ) {
3971                 return false;
3972             }
3973             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
3974                 System.out.println( entry3.getTaxonomyScientificName() );
3975                 return false;
3976             }
3977             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
3978                 System.out.println( entry3.getSequenceName() );
3979                 return false;
3980             }
3981             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
3982                 System.out.println( entry3.getTaxonomyIdentifier() );
3983                 return false;
3984             }
3985             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
3986                 System.out.println( entry3.getSequenceSymbol() );
3987                 return false;
3988             }
3989             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
3990                 return false;
3991             }
3992             if ( entry3.getCrossReferences().size() != 8 ) {
3993                 return false;
3994             }
3995             //
3996             //
3997             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
3998             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
3999                 return false;
4000             }
4001             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4002                 System.out.println( entry4.getTaxonomyScientificName() );
4003                 return false;
4004             }
4005             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4006                 System.out.println( entry4.getSequenceName() );
4007                 return false;
4008             }
4009             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4010                 System.out.println( entry4.getTaxonomyIdentifier() );
4011                 return false;
4012             }
4013             if ( !entry4.getGeneName().equals( "ras" ) ) {
4014                 System.out.println( entry4.getGeneName() );
4015                 return false;
4016             }
4017             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
4018             //     System.out.println( entry4.getChromosome() );
4019             //     return false;
4020             // }
4021             // if ( !entry4.getMap().equals( "ras" ) ) {
4022             //     System.out.println( entry4.getMap() );
4023             //     return false;
4024             // }
4025             //TODO FIXME gi...
4026             //
4027             //TODO fails:
4028             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
4029             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
4030             //                return false;
4031             //            }
4032             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4033             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4034                 return false;
4035             }
4036             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4037                 System.out.println( entry5.getTaxonomyScientificName() );
4038                 return false;
4039             }
4040             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4041                 System.out.println( entry5.getSequenceName() );
4042                 return false;
4043             }
4044             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4045                 System.out.println( entry5.getTaxonomyIdentifier() );
4046                 return false;
4047             }
4048         }
4049         catch ( final IOException e ) {
4050             System.out.println();
4051             System.out.println( "the following might be due to absence internet connection:" );
4052             e.printStackTrace( System.out );
4053             return true;
4054         }
4055         catch ( final Exception e ) {
4056             e.printStackTrace();
4057             return false;
4058         }
4059         return true;
4060     }
4061
4062     private static boolean testExternalNodeRelatedMethods() {
4063         try {
4064             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4065             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4066             PhylogenyNode n = t1.getNode( "A" );
4067             n = n.getNextExternalNode();
4068             if ( !n.getName().equals( "B" ) ) {
4069                 return false;
4070             }
4071             n = n.getNextExternalNode();
4072             if ( !n.getName().equals( "C" ) ) {
4073                 return false;
4074             }
4075             n = n.getNextExternalNode();
4076             if ( !n.getName().equals( "D" ) ) {
4077                 return false;
4078             }
4079             n = t1.getNode( "B" );
4080             while ( !n.isLastExternalNode() ) {
4081                 n = n.getNextExternalNode();
4082             }
4083             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4084             n = t2.getNode( "A" );
4085             n = n.getNextExternalNode();
4086             if ( !n.getName().equals( "B" ) ) {
4087                 return false;
4088             }
4089             n = n.getNextExternalNode();
4090             if ( !n.getName().equals( "C" ) ) {
4091                 return false;
4092             }
4093             n = n.getNextExternalNode();
4094             if ( !n.getName().equals( "D" ) ) {
4095                 return false;
4096             }
4097             n = t2.getNode( "B" );
4098             while ( !n.isLastExternalNode() ) {
4099                 n = n.getNextExternalNode();
4100             }
4101             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4102             n = t3.getNode( "A" );
4103             n = n.getNextExternalNode();
4104             if ( !n.getName().equals( "B" ) ) {
4105                 return false;
4106             }
4107             n = n.getNextExternalNode();
4108             if ( !n.getName().equals( "C" ) ) {
4109                 return false;
4110             }
4111             n = n.getNextExternalNode();
4112             if ( !n.getName().equals( "D" ) ) {
4113                 return false;
4114             }
4115             n = n.getNextExternalNode();
4116             if ( !n.getName().equals( "E" ) ) {
4117                 return false;
4118             }
4119             n = n.getNextExternalNode();
4120             if ( !n.getName().equals( "F" ) ) {
4121                 return false;
4122             }
4123             n = n.getNextExternalNode();
4124             if ( !n.getName().equals( "G" ) ) {
4125                 return false;
4126             }
4127             n = n.getNextExternalNode();
4128             if ( !n.getName().equals( "H" ) ) {
4129                 return false;
4130             }
4131             n = t3.getNode( "B" );
4132             while ( !n.isLastExternalNode() ) {
4133                 n = n.getNextExternalNode();
4134             }
4135             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4136             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4137                 final PhylogenyNode node = iter.next();
4138             }
4139             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4140             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4141                 final PhylogenyNode node = iter.next();
4142             }
4143             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4144             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4145             if ( !iter.next().getName().equals( "A" ) ) {
4146                 return false;
4147             }
4148             if ( !iter.next().getName().equals( "B" ) ) {
4149                 return false;
4150             }
4151             if ( !iter.next().getName().equals( "C" ) ) {
4152                 return false;
4153             }
4154             if ( !iter.next().getName().equals( "D" ) ) {
4155                 return false;
4156             }
4157             if ( !iter.next().getName().equals( "E" ) ) {
4158                 return false;
4159             }
4160             if ( !iter.next().getName().equals( "F" ) ) {
4161                 return false;
4162             }
4163             if ( iter.hasNext() ) {
4164                 return false;
4165             }
4166         }
4167         catch ( final Exception e ) {
4168             e.printStackTrace( System.out );
4169             return false;
4170         }
4171         return true;
4172     }
4173
4174     private static boolean testExtractSNFromNodeName() {
4175         try {
4176             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4177                 return false;
4178             }
4179             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4180                 return false;
4181             }
4182             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4183                 return false;
4184             }
4185             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4186                     .equals( "Mus musculus musculus" ) ) {
4187                 return false;
4188             }
4189             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4190                     .equals( "Mus musculus musculus" ) ) {
4191                 return false;
4192             }
4193             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4194                     .equals( "Mus musculus musculus" ) ) {
4195                 return false;
4196             }
4197             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4198                     .equals( "Mus musculus musculus" ) ) {
4199                 return false;
4200             }
4201             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4202                 return false;
4203             }
4204             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4205                     .equals( "Mus musculus musculus" ) ) {
4206                 return false;
4207             }
4208             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4209                     .equals( "Mus musculus musculus" ) ) {
4210                 return false;
4211             }
4212             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4213                 return false;
4214             }
4215             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4216                 return false;
4217             }
4218             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4219                 return false;
4220             }
4221             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4222                 return false;
4223             }
4224             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4225                     .equals( "Mus musculus musculus" ) ) {
4226                 return false;
4227             }
4228             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4229                 return false;
4230             }
4231             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4232                 return false;
4233             }
4234             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4235                 return false;
4236             }
4237             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4238                 return false;
4239             }
4240             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4241                 return false;
4242             }
4243             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4244                 return false;
4245             }
4246             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4247                 return false;
4248             }
4249             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4250                 return false;
4251             }
4252             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4253                     .equals( "Mus musculus" ) ) {
4254                 return false;
4255             }
4256             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4257                     .equals( "Mus musculus" ) ) {
4258                 return false;
4259             }
4260             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4261                 return false;
4262             }
4263             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4264                     .equals( "Mus musculus musculus" ) ) {
4265                 return false;
4266             }
4267             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4268                     .equals( "Mus musculus musculus" ) ) {
4269                 return false;
4270             }
4271             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4272                     .equals( "Mus musculus musculus" ) ) {
4273                 return false;
4274             }
4275             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4276                 return false;
4277             }
4278             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4279                     .equals( "Pilostyles mexicana" ) ) {
4280                 return false;
4281             }
4282             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4283                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4284                 return false;
4285             }
4286             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4287                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4288                 return false;
4289             }
4290             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4291                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4292                 return false;
4293             }
4294             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4295                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4296                 return false;
4297             }
4298             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4299                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4300                 return false;
4301             }
4302             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4303                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4304                 return false;
4305             }
4306             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4307                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4308                 return false;
4309             }
4310             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4311                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4312                 return false;
4313             }
4314             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4315                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4316                 return false;
4317             }
4318             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4319                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4320                 return false;
4321             }
4322             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4323                     .equals( "Escherichia coli (strain K12)" ) ) {
4324                 return false;
4325             }
4326             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4327                     .equals( "Escherichia coli (strain K12)" ) ) {
4328                 return false;
4329             }
4330             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4331                     .equals( "Escherichia coli (str. K12)" ) ) {
4332                 return false;
4333             }
4334             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4335                     .equals( "Escherichia coli (str. K12)" ) ) {
4336                 return false;
4337             }
4338             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4339                     .equals( "Escherichia coli (str. K12)" ) ) {
4340                 return false;
4341             }
4342             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4343                     .equals( "Escherichia coli (var. K12)" ) ) {
4344                 return false;
4345             }
4346             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4347                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4348                 return false;
4349             }
4350             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4351                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4352                 return false;
4353             }
4354             if ( !ParserUtils
4355                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4356                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4357                 return false;
4358             }
4359             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4360                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4361                 return false;
4362             }
4363             if ( !ParserUtils
4364                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4365                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4366                 return false;
4367             }
4368             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4369                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4370                 return false;
4371             }
4372             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4373                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4374                 return false;
4375             }
4376             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4377                 return false;
4378             }
4379             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4380                 return false;
4381             }
4382             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4383                 return false;
4384             }
4385             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4386                     .equals( "Macrocera sp." ) ) {
4387                 return false;
4388             }
4389             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4390                 return false;
4391             }
4392             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4393                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4394                 return false;
4395             }
4396             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4397                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4398                 return false;
4399             }
4400             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4401                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4402                 return false;
4403             }
4404             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4405                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4406                 return false;
4407             }
4408         }
4409         catch ( final Exception e ) {
4410             e.printStackTrace( System.out );
4411             return false;
4412         }
4413         return true;
4414     }
4415
4416     private static boolean testExtractTaxonomyCodeFromNodeName() {
4417         try {
4418             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4419                 return false;
4420             }
4421             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4422                     .equals( "SOYBN" ) ) {
4423                 return false;
4424             }
4425             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4426                     .equals( "ARATH" ) ) {
4427                 return false;
4428             }
4429             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4430                     .equals( "ARATH" ) ) {
4431                 return false;
4432             }
4433             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4434                 return false;
4435             }
4436             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4437                 return false;
4438             }
4439             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4440                 return false;
4441             }
4442             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4443                     .equals( "SOYBN" ) ) {
4444                 return false;
4445             }
4446             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4447                     .equals( "SOYBN" ) ) {
4448                 return false;
4449             }
4450             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4451                     .equals( "SOYBN" ) ) {
4452                 return false;
4453             }
4454             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4455                     .equals( "SOYBN" ) ) {
4456                 return false;
4457             }
4458             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4459                     .equals( "SOYBN" ) ) {
4460                 return false;
4461             }
4462             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4463                     .equals( "SOYBN" ) ) {
4464                 return false;
4465             }
4466             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4467                     .equals( "SOYBN" ) ) {
4468                 return false;
4469             }
4470             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4471                     .equals( "SOYBN" ) ) {
4472                 return false;
4473             }
4474             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4475                 return false;
4476             }
4477             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4478                     .equals( "SOYBN" ) ) {
4479                 return false;
4480             }
4481             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4482                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4483                 return false;
4484             }
4485             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4486                     .equals( "9YX45" ) ) {
4487                 return false;
4488             }
4489             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4490                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4491                     .equals( "MOUSE" ) ) {
4492                 return false;
4493             }
4494             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4495                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4496                     .equals( "MOUSE" ) ) {
4497                 return false;
4498             }
4499             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4500                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4501                     .equals( "MOUSE" ) ) {
4502                 return false;
4503             }
4504             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4505                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4506                 return false;
4507             }
4508             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4509                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4510                 return false;
4511             }
4512             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4513                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4514                 return false;
4515             }
4516             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4517                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4518                 return false;
4519             }
4520             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4521                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4522                 return false;
4523             }
4524             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4525                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4526                 return false;
4527             }
4528             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4529                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4530                 return false;
4531             }
4532             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4533                     .equals( "RAT" ) ) {
4534                 return false;
4535             }
4536             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4537                     .equals( "PIG" ) ) {
4538                 return false;
4539             }
4540             if ( !ParserUtils
4541                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4542                     .equals( "MOUSE" ) ) {
4543                 return false;
4544             }
4545             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4546                     .equals( "MOUSE" ) ) {
4547                 return false;
4548             }
4549             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4550                 return false;
4551             }
4552         }
4553         catch ( final Exception e ) {
4554             e.printStackTrace( System.out );
4555             return false;
4556         }
4557         return true;
4558     }
4559
4560     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4561         try {
4562             PhylogenyNode n = new PhylogenyNode();
4563             n.setName( "tr|B3RJ64" );
4564             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4565                 return false;
4566             }
4567             n.setName( "tr.B3RJ64" );
4568             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4569                 return false;
4570             }
4571             n.setName( "tr=B3RJ64" );
4572             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4573                 return false;
4574             }
4575             n.setName( "tr-B3RJ64" );
4576             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4577                 return false;
4578             }
4579             n.setName( "tr/B3RJ64" );
4580             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4581                 return false;
4582             }
4583             n.setName( "tr\\B3RJ64" );
4584             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4585                 return false;
4586             }
4587             n.setName( "tr_B3RJ64" );
4588             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4589                 return false;
4590             }
4591             n.setName( " tr|B3RJ64 " );
4592             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4593                 return false;
4594             }
4595             n.setName( "-tr|B3RJ64-" );
4596             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4597                 return false;
4598             }
4599             n.setName( "-tr=B3RJ64-" );
4600             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4601                 return false;
4602             }
4603             n.setName( "_tr=B3RJ64_" );
4604             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4605                 return false;
4606             }
4607             n.setName( " tr_tr|B3RJ64_sp|123 " );
4608             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4609                 return false;
4610             }
4611             n.setName( "B3RJ64" );
4612             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4613                 return false;
4614             }
4615             n.setName( "sp|B3RJ64" );
4616             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4617                 return false;
4618             }
4619             n.setName( "sp|B3RJ64C" );
4620             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4621                 return false;
4622             }
4623             n.setName( "sp B3RJ64" );
4624             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4625                 return false;
4626             }
4627             n.setName( "sp|B3RJ6X" );
4628             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4629                 return false;
4630             }
4631             n.setName( "sp|B3RJ6" );
4632             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4633                 return false;
4634             }
4635             n.setName( "K1PYK7_CRAGI" );
4636             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4637                 return false;
4638             }
4639             n.setName( "K1PYK7_PEA" );
4640             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4641                 return false;
4642             }
4643             n.setName( "K1PYK7_RAT" );
4644             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4645                 return false;
4646             }
4647             n.setName( "K1PYK7_PIG" );
4648             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4649                 return false;
4650             }
4651             n.setName( "~K1PYK7_PIG~" );
4652             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4653                 return false;
4654             }
4655             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4656             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4657                 return false;
4658             }
4659             n.setName( "K1PYKX_CRAGI" );
4660             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4661                 return false;
4662             }
4663             n.setName( "XXXXX_CRAGI" );
4664             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4665                 return false;
4666             }
4667             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4668             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4669                 return false;
4670             }
4671             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4672             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4673                 return false;
4674             }
4675             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4676             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4677                 return false;
4678             }
4679             n = new PhylogenyNode();
4680             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4681             seq.setSymbol( "K1PYK7_CRAGI" );
4682             n.getNodeData().addSequence( seq );
4683             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4684                 return false;
4685             }
4686             seq.setSymbol( "tr|B3RJ64" );
4687             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4688                 return false;
4689             }
4690             n = new PhylogenyNode();
4691             seq = new org.forester.phylogeny.data.Sequence();
4692             seq.setName( "K1PYK7_CRAGI" );
4693             n.getNodeData().addSequence( seq );
4694             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4695                 return false;
4696             }
4697             seq.setName( "tr|B3RJ64" );
4698             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4699                 return false;
4700             }
4701             n = new PhylogenyNode();
4702             seq = new org.forester.phylogeny.data.Sequence();
4703             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4704             n.getNodeData().addSequence( seq );
4705             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4706                 return false;
4707             }
4708             n = new PhylogenyNode();
4709             seq = new org.forester.phylogeny.data.Sequence();
4710             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4711             n.getNodeData().addSequence( seq );
4712             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4713                 return false;
4714             }
4715             //
4716             n = new PhylogenyNode();
4717             n.setName( "ACP19736" );
4718             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4719                 return false;
4720             }
4721             n = new PhylogenyNode();
4722             n.setName( "|ACP19736|" );
4723             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4724                 return false;
4725             }
4726         }
4727         catch ( final Exception e ) {
4728             e.printStackTrace( System.out );
4729             return false;
4730         }
4731         return true;
4732     }
4733
4734     private static boolean testFastaParser() {
4735         try {
4736             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4737                 return false;
4738             }
4739             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4740                 return false;
4741             }
4742             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4743             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4744                 return false;
4745             }
4746             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4747                 return false;
4748             }
4749             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4750                 return false;
4751             }
4752             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4753                 return false;
4754             }
4755             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4756                 return false;
4757             }
4758             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4759                 return false;
4760             }
4761         }
4762         catch ( final Exception e ) {
4763             e.printStackTrace();
4764             return false;
4765         }
4766         return true;
4767     }
4768
4769     private static boolean testGenbankAccessorParsing() {
4770         //The format for GenBank Accession numbers are:
4771         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4772         //Protein:    3 letters + 5 numerals
4773         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4774         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4775             return false;
4776         }
4777         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4778             return false;
4779         }
4780         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4781             return false;
4782         }
4783         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4784             return false;
4785         }
4786         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4787             return false;
4788         }
4789         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4790             return false;
4791         }
4792         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4793             return false;
4794         }
4795         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4796             return false;
4797         }
4798         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4799             return false;
4800         }
4801         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4802             return false;
4803         }
4804         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4805             return false;
4806         }
4807         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4808             return false;
4809         }
4810         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4811             return false;
4812         }
4813         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4814             return false;
4815         }
4816         return true;
4817     }
4818
4819     private static boolean testGeneralMsaParser() {
4820         try {
4821             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4822             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4823             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4824             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4825             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4826             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4827             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4828             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4829             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4830                 return false;
4831             }
4832             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4833                 return false;
4834             }
4835             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4836                 return false;
4837             }
4838             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4839                 return false;
4840             }
4841             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4842                 return false;
4843             }
4844             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4845                 return false;
4846             }
4847             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4848                 return false;
4849             }
4850             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4851                 return false;
4852             }
4853             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4854                 return false;
4855             }
4856             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4857                 return false;
4858             }
4859             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4860                 return false;
4861             }
4862             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4863                 return false;
4864             }
4865             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4866             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4867                 return false;
4868             }
4869             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4870                 return false;
4871             }
4872             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4873                 return false;
4874             }
4875             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4876             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4877                 return false;
4878             }
4879             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4880                 return false;
4881             }
4882             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4883                 return false;
4884             }
4885             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4886             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4887                 return false;
4888             }
4889             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4890                 return false;
4891             }
4892             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4893                 return false;
4894             }
4895         }
4896         catch ( final Exception e ) {
4897             e.printStackTrace();
4898             return false;
4899         }
4900         return true;
4901     }
4902
4903     private static boolean testGeneralTable() {
4904         try {
4905             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4906             t0.setValue( 3, 2, "23" );
4907             t0.setValue( 10, 1, "error" );
4908             t0.setValue( 10, 1, "110" );
4909             t0.setValue( 9, 1, "19" );
4910             t0.setValue( 1, 10, "101" );
4911             t0.setValue( 10, 10, "1010" );
4912             t0.setValue( 100, 10, "10100" );
4913             t0.setValue( 0, 0, "00" );
4914             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4915                 return false;
4916             }
4917             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4918                 return false;
4919             }
4920             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4921                 return false;
4922             }
4923             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4924                 return false;
4925             }
4926             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4927                 return false;
4928             }
4929             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4930                 return false;
4931             }
4932             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4933                 return false;
4934             }
4935             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4936                 return false;
4937             }
4938             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4939                 return false;
4940             }
4941             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4942             t1.setValue( "3", "2", "23" );
4943             t1.setValue( "10", "1", "error" );
4944             t1.setValue( "10", "1", "110" );
4945             t1.setValue( "9", "1", "19" );
4946             t1.setValue( "1", "10", "101" );
4947             t1.setValue( "10", "10", "1010" );
4948             t1.setValue( "100", "10", "10100" );
4949             t1.setValue( "0", "0", "00" );
4950             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4951             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4952                 return false;
4953             }
4954             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4955                 return false;
4956             }
4957             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4958                 return false;
4959             }
4960             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4961                 return false;
4962             }
4963             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4964                 return false;
4965             }
4966             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4967                 return false;
4968             }
4969             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4970                 return false;
4971             }
4972             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4973                 return false;
4974             }
4975             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4976                 return false;
4977             }
4978             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4979                 return false;
4980             }
4981         }
4982         catch ( final Exception e ) {
4983             e.printStackTrace( System.out );
4984             return false;
4985         }
4986         return true;
4987     }
4988
4989     private static boolean testGetDistance() {
4990         try {
4991             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4992             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",
4993                                                  new NHXParser() )[ 0 ];
4994             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4995                 return false;
4996             }
4997             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4998                 return false;
4999             }
5000             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5001                 return false;
5002             }
5003             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5004                 return false;
5005             }
5006             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5007                 return false;
5008             }
5009             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5010                 return false;
5011             }
5012             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5013                 return false;
5014             }
5015             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5016                 return false;
5017             }
5018             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5019                 return false;
5020             }
5021             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5022                 return false;
5023             }
5024             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5025                 return false;
5026             }
5027             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5028                 return false;
5029             }
5030             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5031                 return false;
5032             }
5033             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5034                 return false;
5035             }
5036             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5037                 return false;
5038             }
5039             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5040                 return false;
5041             }
5042             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5043                 return false;
5044             }
5045             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5046                 return false;
5047             }
5048             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5049                 return false;
5050             }
5051             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5052                 return false;
5053             }
5054             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5055                 return false;
5056             }
5057             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5058                 return false;
5059             }
5060             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5061                 return false;
5062             }
5063             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5064                 return false;
5065             }
5066             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5067                 return false;
5068             }
5069             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5070                 return false;
5071             }
5072             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5073                 return false;
5074             }
5075             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5076                 return false;
5077             }
5078             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5079                 return false;
5080             }
5081             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5082                 return false;
5083             }
5084             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5085                 return false;
5086             }
5087             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",
5088                                                  new NHXParser() )[ 0 ];
5089             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5090                 return false;
5091             }
5092             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5093                 return false;
5094             }
5095             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5096                 return false;
5097             }
5098             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5099                 return false;
5100             }
5101             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5102                 return false;
5103             }
5104             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5105                 return false;
5106             }
5107             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5108                 return false;
5109             }
5110             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5111                 return false;
5112             }
5113             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5114                 return false;
5115             }
5116             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5117                 return false;
5118             }
5119             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5120                 return false;
5121             }
5122         }
5123         catch ( final Exception e ) {
5124             e.printStackTrace( System.out );
5125             return false;
5126         }
5127         return true;
5128     }
5129
5130     private static boolean testGetLCA() {
5131         try {
5132             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5133             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5134                                                  new NHXParser() )[ 0 ];
5135             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5136             if ( !A.getName().equals( "A" ) ) {
5137                 return false;
5138             }
5139             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5140             if ( !gh.getName().equals( "gh" ) ) {
5141                 return false;
5142             }
5143             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5144             if ( !ab.getName().equals( "ab" ) ) {
5145                 return false;
5146             }
5147             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5148             if ( !ab2.getName().equals( "ab" ) ) {
5149                 return false;
5150             }
5151             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5152             if ( !gh2.getName().equals( "gh" ) ) {
5153                 return false;
5154             }
5155             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5156             if ( !gh3.getName().equals( "gh" ) ) {
5157                 return false;
5158             }
5159             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5160             if ( !abc.getName().equals( "abc" ) ) {
5161                 return false;
5162             }
5163             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5164             if ( !abc2.getName().equals( "abc" ) ) {
5165                 return false;
5166             }
5167             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5168             if ( !abcd.getName().equals( "abcd" ) ) {
5169                 return false;
5170             }
5171             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5172             if ( !abcd2.getName().equals( "abcd" ) ) {
5173                 return false;
5174             }
5175             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5176             if ( !abcdef.getName().equals( "abcdef" ) ) {
5177                 return false;
5178             }
5179             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5180             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5181                 return false;
5182             }
5183             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5184             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5185                 return false;
5186             }
5187             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5188             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5189                 return false;
5190             }
5191             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5192             if ( !abcde.getName().equals( "abcde" ) ) {
5193                 return false;
5194             }
5195             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5196             if ( !abcde2.getName().equals( "abcde" ) ) {
5197                 return false;
5198             }
5199             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5200             if ( !r.getName().equals( "abcdefgh" ) ) {
5201                 return false;
5202             }
5203             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5204             if ( !r2.getName().equals( "abcdefgh" ) ) {
5205                 return false;
5206             }
5207             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5208             if ( !r3.getName().equals( "abcdefgh" ) ) {
5209                 return false;
5210             }
5211             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5212             if ( !abcde3.getName().equals( "abcde" ) ) {
5213                 return false;
5214             }
5215             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5216             if ( !abcde4.getName().equals( "abcde" ) ) {
5217                 return false;
5218             }
5219             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5220             if ( !ab3.getName().equals( "ab" ) ) {
5221                 return false;
5222             }
5223             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5224             if ( !ab4.getName().equals( "ab" ) ) {
5225                 return false;
5226             }
5227             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5228             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5229             if ( !cd.getName().equals( "cd" ) ) {
5230                 return false;
5231             }
5232             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5233             if ( !cd2.getName().equals( "cd" ) ) {
5234                 return false;
5235             }
5236             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5237             if ( !cde.getName().equals( "cde" ) ) {
5238                 return false;
5239             }
5240             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5241             if ( !cde2.getName().equals( "cde" ) ) {
5242                 return false;
5243             }
5244             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5245             if ( !cdef.getName().equals( "cdef" ) ) {
5246                 return false;
5247             }
5248             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5249             if ( !cdef2.getName().equals( "cdef" ) ) {
5250                 return false;
5251             }
5252             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5253             if ( !cdef3.getName().equals( "cdef" ) ) {
5254                 return false;
5255             }
5256             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5257             if ( !rt.getName().equals( "r" ) ) {
5258                 return false;
5259             }
5260             final Phylogeny p3 = factory
5261                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5262                              new NHXParser() )[ 0 ];
5263             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5264             if ( !bc_3.getName().equals( "bc" ) ) {
5265                 return false;
5266             }
5267             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5268             if ( !ac_3.getName().equals( "abc" ) ) {
5269                 return false;
5270             }
5271             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5272             if ( !ad_3.getName().equals( "abcde" ) ) {
5273                 return false;
5274             }
5275             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5276             if ( !af_3.getName().equals( "abcdef" ) ) {
5277                 return false;
5278             }
5279             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5280             if ( !ag_3.getName().equals( "" ) ) {
5281                 return false;
5282             }
5283             if ( !ag_3.isRoot() ) {
5284                 return false;
5285             }
5286             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5287             if ( !al_3.getName().equals( "" ) ) {
5288                 return false;
5289             }
5290             if ( !al_3.isRoot() ) {
5291                 return false;
5292             }
5293             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5294             if ( !kl_3.getName().equals( "" ) ) {
5295                 return false;
5296             }
5297             if ( !kl_3.isRoot() ) {
5298                 return false;
5299             }
5300             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5301             if ( !fl_3.getName().equals( "" ) ) {
5302                 return false;
5303             }
5304             if ( !fl_3.isRoot() ) {
5305                 return false;
5306             }
5307             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5308             if ( !gk_3.getName().equals( "ghijk" ) ) {
5309                 return false;
5310             }
5311             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5312             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5313             if ( !r_4.getName().equals( "r" ) ) {
5314                 return false;
5315             }
5316             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5317             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5318             if ( !r_5.getName().equals( "root" ) ) {
5319                 return false;
5320             }
5321             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5322             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5323             if ( !r_6.getName().equals( "rot" ) ) {
5324                 return false;
5325             }
5326             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5327             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5328             if ( !r_7.getName().equals( "rott" ) ) {
5329                 return false;
5330             }
5331         }
5332         catch ( final Exception e ) {
5333             e.printStackTrace( System.out );
5334             return false;
5335         }
5336         return true;
5337     }
5338
5339     private static boolean testGetLCA2() {
5340         try {
5341             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5342             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5343             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5344             PhylogenyMethods.preOrderReId( p_a );
5345             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5346                                                                                               p_a.getNode( "a" ) );
5347             if ( !p_a_1.getName().equals( "a" ) ) {
5348                 return false;
5349             }
5350             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5351             PhylogenyMethods.preOrderReId( p_b );
5352             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5353                                                                                               p_b.getNode( "a" ) );
5354             if ( !p_b_1.getName().equals( "b" ) ) {
5355                 return false;
5356             }
5357             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5358                                                                                               p_b.getNode( "b" ) );
5359             if ( !p_b_2.getName().equals( "b" ) ) {
5360                 return false;
5361             }
5362             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5363             PhylogenyMethods.preOrderReId( p_c );
5364             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5365                                                                                               p_c.getNode( "a" ) );
5366             if ( !p_c_1.getName().equals( "b" ) ) {
5367                 return false;
5368             }
5369             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5370                                                                                               p_c.getNode( "c" ) );
5371             if ( !p_c_2.getName().equals( "c" ) ) {
5372                 System.out.println( p_c_2.getName() );
5373                 System.exit( -1 );
5374                 return false;
5375             }
5376             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5377                                                                                               p_c.getNode( "b" ) );
5378             if ( !p_c_3.getName().equals( "b" ) ) {
5379                 return false;
5380             }
5381             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5382                                                                                               p_c.getNode( "a" ) );
5383             if ( !p_c_4.getName().equals( "c" ) ) {
5384                 return false;
5385             }
5386             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5387                                                  new NHXParser() )[ 0 ];
5388             PhylogenyMethods.preOrderReId( p1 );
5389             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5390                                                                                           p1.getNode( "A" ) );
5391             if ( !A.getName().equals( "A" ) ) {
5392                 return false;
5393             }
5394             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5395                                                                                            p1.getNode( "gh" ) );
5396             if ( !gh.getName().equals( "gh" ) ) {
5397                 return false;
5398             }
5399             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5400                                                                                            p1.getNode( "B" ) );
5401             if ( !ab.getName().equals( "ab" ) ) {
5402                 return false;
5403             }
5404             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5405                                                                                             p1.getNode( "A" ) );
5406             if ( !ab2.getName().equals( "ab" ) ) {
5407                 return false;
5408             }
5409             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5410                                                                                             p1.getNode( "G" ) );
5411             if ( !gh2.getName().equals( "gh" ) ) {
5412                 return false;
5413             }
5414             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5415                                                                                             p1.getNode( "H" ) );
5416             if ( !gh3.getName().equals( "gh" ) ) {
5417                 return false;
5418             }
5419             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5420                                                                                             p1.getNode( "A" ) );
5421             if ( !abc.getName().equals( "abc" ) ) {
5422                 return false;
5423             }
5424             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5425                                                                                              p1.getNode( "C" ) );
5426             if ( !abc2.getName().equals( "abc" ) ) {
5427                 return false;
5428             }
5429             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5430                                                                                              p1.getNode( "D" ) );
5431             if ( !abcd.getName().equals( "abcd" ) ) {
5432                 return false;
5433             }
5434             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5435                                                                                               p1.getNode( "A" ) );
5436             if ( !abcd2.getName().equals( "abcd" ) ) {
5437                 return false;
5438             }
5439             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5440                                                                                                p1.getNode( "F" ) );
5441             if ( !abcdef.getName().equals( "abcdef" ) ) {
5442                 return false;
5443             }
5444             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5445                                                                                                 p1.getNode( "A" ) );
5446             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5447                 return false;
5448             }
5449             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5450                                                                                                 p1.getNode( "F" ) );
5451             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5452                 return false;
5453             }
5454             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5455                                                                                                 p1.getNode( "ab" ) );
5456             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5457                 return false;
5458             }
5459             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5460                                                                                               p1.getNode( "E" ) );
5461             if ( !abcde.getName().equals( "abcde" ) ) {
5462                 return false;
5463             }
5464             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5465                                                                                                p1.getNode( "A" ) );
5466             if ( !abcde2.getName().equals( "abcde" ) ) {
5467                 return false;
5468             }
5469             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5470                                                                                           p1.getNode( "abcdefgh" ) );
5471             if ( !r.getName().equals( "abcdefgh" ) ) {
5472                 return false;
5473             }
5474             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5475                                                                                            p1.getNode( "H" ) );
5476             if ( !r2.getName().equals( "abcdefgh" ) ) {
5477                 return false;
5478             }
5479             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5480                                                                                            p1.getNode( "A" ) );
5481             if ( !r3.getName().equals( "abcdefgh" ) ) {
5482                 return false;
5483             }
5484             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5485                                                                                                p1.getNode( "abcde" ) );
5486             if ( !abcde3.getName().equals( "abcde" ) ) {
5487                 return false;
5488             }
5489             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5490                                                                                                p1.getNode( "E" ) );
5491             if ( !abcde4.getName().equals( "abcde" ) ) {
5492                 return false;
5493             }
5494             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5495                                                                                             p1.getNode( "B" ) );
5496             if ( !ab3.getName().equals( "ab" ) ) {
5497                 return false;
5498             }
5499             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5500                                                                                             p1.getNode( "ab" ) );
5501             if ( !ab4.getName().equals( "ab" ) ) {
5502                 return false;
5503             }
5504             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5505             PhylogenyMethods.preOrderReId( p2 );
5506             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5507                                                                                            p2.getNode( "d" ) );
5508             if ( !cd.getName().equals( "cd" ) ) {
5509                 return false;
5510             }
5511             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5512                                                                                             p2.getNode( "c" ) );
5513             if ( !cd2.getName().equals( "cd" ) ) {
5514                 return false;
5515             }
5516             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5517                                                                                             p2.getNode( "e" ) );
5518             if ( !cde.getName().equals( "cde" ) ) {
5519                 return false;
5520             }
5521             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5522                                                                                              p2.getNode( "c" ) );
5523             if ( !cde2.getName().equals( "cde" ) ) {
5524                 return false;
5525             }
5526             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5527                                                                                              p2.getNode( "f" ) );
5528             if ( !cdef.getName().equals( "cdef" ) ) {
5529                 return false;
5530             }
5531             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5532                                                                                               p2.getNode( "f" ) );
5533             if ( !cdef2.getName().equals( "cdef" ) ) {
5534                 return false;
5535             }
5536             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5537                                                                                               p2.getNode( "d" ) );
5538             if ( !cdef3.getName().equals( "cdef" ) ) {
5539                 return false;
5540             }
5541             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5542                                                                                            p2.getNode( "a" ) );
5543             if ( !rt.getName().equals( "r" ) ) {
5544                 return false;
5545             }
5546             final Phylogeny p3 = factory
5547                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5548                              new NHXParser() )[ 0 ];
5549             PhylogenyMethods.preOrderReId( p3 );
5550             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5551                                                                                              p3.getNode( "c" ) );
5552             if ( !bc_3.getName().equals( "bc" ) ) {
5553                 return false;
5554             }
5555             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5556                                                                                              p3.getNode( "c" ) );
5557             if ( !ac_3.getName().equals( "abc" ) ) {
5558                 return false;
5559             }
5560             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5561                                                                                              p3.getNode( "d" ) );
5562             if ( !ad_3.getName().equals( "abcde" ) ) {
5563                 return false;
5564             }
5565             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5566                                                                                              p3.getNode( "f" ) );
5567             if ( !af_3.getName().equals( "abcdef" ) ) {
5568                 return false;
5569             }
5570             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5571                                                                                              p3.getNode( "g" ) );
5572             if ( !ag_3.getName().equals( "" ) ) {
5573                 return false;
5574             }
5575             if ( !ag_3.isRoot() ) {
5576                 return false;
5577             }
5578             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5579                                                                                              p3.getNode( "l" ) );
5580             if ( !al_3.getName().equals( "" ) ) {
5581                 return false;
5582             }
5583             if ( !al_3.isRoot() ) {
5584                 return false;
5585             }
5586             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5587                                                                                              p3.getNode( "l" ) );
5588             if ( !kl_3.getName().equals( "" ) ) {
5589                 return false;
5590             }
5591             if ( !kl_3.isRoot() ) {
5592                 return false;
5593             }
5594             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5595                                                                                              p3.getNode( "l" ) );
5596             if ( !fl_3.getName().equals( "" ) ) {
5597                 return false;
5598             }
5599             if ( !fl_3.isRoot() ) {
5600                 return false;
5601             }
5602             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5603                                                                                              p3.getNode( "k" ) );
5604             if ( !gk_3.getName().equals( "ghijk" ) ) {
5605                 return false;
5606             }
5607             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5608             PhylogenyMethods.preOrderReId( p4 );
5609             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5610                                                                                             p4.getNode( "c" ) );
5611             if ( !r_4.getName().equals( "r" ) ) {
5612                 return false;
5613             }
5614             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5615             PhylogenyMethods.preOrderReId( p5 );
5616             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5617                                                                                             p5.getNode( "c" ) );
5618             if ( !r_5.getName().equals( "root" ) ) {
5619                 return false;
5620             }
5621             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5622             PhylogenyMethods.preOrderReId( p6 );
5623             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5624                                                                                             p6.getNode( "a" ) );
5625             if ( !r_6.getName().equals( "rot" ) ) {
5626                 return false;
5627             }
5628             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5629             PhylogenyMethods.preOrderReId( p7 );
5630             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5631                                                                                             p7.getNode( "e" ) );
5632             if ( !r_7.getName().equals( "rott" ) ) {
5633                 return false;
5634             }
5635             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5636                                                                                              p7.getNode( "a" ) );
5637             if ( !r_71.getName().equals( "rott" ) ) {
5638                 return false;
5639             }
5640             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5641                                                                                              p7.getNode( "rott" ) );
5642             if ( !r_72.getName().equals( "rott" ) ) {
5643                 return false;
5644             }
5645             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5646                                                                                              p7.getNode( "a" ) );
5647             if ( !r_73.getName().equals( "rott" ) ) {
5648                 return false;
5649             }
5650             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5651                                                                                              p7.getNode( "rott" ) );
5652             if ( !r_74.getName().equals( "rott" ) ) {
5653                 return false;
5654             }
5655             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5656                                                                                              p7.getNode( "e" ) );
5657             if ( !r_75.getName().equals( "e" ) ) {
5658                 return false;
5659             }
5660         }
5661         catch ( final Exception e ) {
5662             e.printStackTrace( System.out );
5663             return false;
5664         }
5665         return true;
5666     }
5667
5668     private static boolean testHmmscanOutputParser() {
5669         final String test_dir = Test.PATH_TO_TEST_DATA;
5670         try {
5671             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5672                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5673             parser1.parse();
5674             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5675                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5676             final List<Protein> proteins = parser2.parse();
5677             if ( parser2.getProteinsEncountered() != 4 ) {
5678                 return false;
5679             }
5680             if ( proteins.size() != 4 ) {
5681                 return false;
5682             }
5683             if ( parser2.getDomainsEncountered() != 69 ) {
5684                 return false;
5685             }
5686             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5687                 return false;
5688             }
5689             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5690                 return false;
5691             }
5692             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5693                 return false;
5694             }
5695             final Protein p1 = proteins.get( 0 );
5696             if ( p1.getNumberOfProteinDomains() != 15 ) {
5697                 return false;
5698             }
5699             if ( p1.getLength() != 850 ) {
5700                 return false;
5701             }
5702             final Protein p2 = proteins.get( 1 );
5703             if ( p2.getNumberOfProteinDomains() != 51 ) {
5704                 return false;
5705             }
5706             if ( p2.getLength() != 1291 ) {
5707                 return false;
5708             }
5709             final Protein p3 = proteins.get( 2 );
5710             if ( p3.getNumberOfProteinDomains() != 2 ) {
5711                 return false;
5712             }
5713             final Protein p4 = proteins.get( 3 );
5714             if ( p4.getNumberOfProteinDomains() != 1 ) {
5715                 return false;
5716             }
5717             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5718                 return false;
5719             }
5720             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5721                 return false;
5722             }
5723             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5724                 return false;
5725             }
5726             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5727                 return false;
5728             }
5729             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5730                 return false;
5731             }
5732             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5733                 return false;
5734             }
5735             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5736                 return false;
5737             }
5738         }
5739         catch ( final Exception e ) {
5740             e.printStackTrace( System.out );
5741             return false;
5742         }
5743         return true;
5744     }
5745
5746     private static boolean testLastExternalNodeMethods() {
5747         try {
5748             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5749             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5750             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5751             final PhylogenyNode n1 = t0.getNode( "A" );
5752             if ( n1.isLastExternalNode() ) {
5753                 return false;
5754             }
5755             final PhylogenyNode n2 = t0.getNode( "B" );
5756             if ( n2.isLastExternalNode() ) {
5757                 return false;
5758             }
5759             final PhylogenyNode n3 = t0.getNode( "C" );
5760             if ( n3.isLastExternalNode() ) {
5761                 return false;
5762             }
5763             final PhylogenyNode n4 = t0.getNode( "D" );
5764             if ( !n4.isLastExternalNode() ) {
5765                 return false;
5766             }
5767         }
5768         catch ( final Exception e ) {
5769             e.printStackTrace( System.out );
5770             return false;
5771         }
5772         return true;
5773     }
5774
5775     private static boolean testLevelOrderIterator() {
5776         try {
5777             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5778             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5779             PhylogenyNodeIterator it0;
5780             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5781                 it0.next();
5782             }
5783             for( it0.reset(); it0.hasNext(); ) {
5784                 it0.next();
5785             }
5786             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5787             if ( !it.next().getName().equals( "r" ) ) {
5788                 return false;
5789             }
5790             if ( !it.next().getName().equals( "ab" ) ) {
5791                 return false;
5792             }
5793             if ( !it.next().getName().equals( "cd" ) ) {
5794                 return false;
5795             }
5796             if ( !it.next().getName().equals( "A" ) ) {
5797                 return false;
5798             }
5799             if ( !it.next().getName().equals( "B" ) ) {
5800                 return false;
5801             }
5802             if ( !it.next().getName().equals( "C" ) ) {
5803                 return false;
5804             }
5805             if ( !it.next().getName().equals( "D" ) ) {
5806                 return false;
5807             }
5808             if ( it.hasNext() ) {
5809                 return false;
5810             }
5811             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",
5812                                                  new NHXParser() )[ 0 ];
5813             PhylogenyNodeIterator it2;
5814             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5815                 it2.next();
5816             }
5817             for( it2.reset(); it2.hasNext(); ) {
5818                 it2.next();
5819             }
5820             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5821             if ( !it3.next().getName().equals( "r" ) ) {
5822                 return false;
5823             }
5824             if ( !it3.next().getName().equals( "abc" ) ) {
5825                 return false;
5826             }
5827             if ( !it3.next().getName().equals( "defg" ) ) {
5828                 return false;
5829             }
5830             if ( !it3.next().getName().equals( "A" ) ) {
5831                 return false;
5832             }
5833             if ( !it3.next().getName().equals( "B" ) ) {
5834                 return false;
5835             }
5836             if ( !it3.next().getName().equals( "C" ) ) {
5837                 return false;
5838             }
5839             if ( !it3.next().getName().equals( "D" ) ) {
5840                 return false;
5841             }
5842             if ( !it3.next().getName().equals( "E" ) ) {
5843                 return false;
5844             }
5845             if ( !it3.next().getName().equals( "F" ) ) {
5846                 return false;
5847             }
5848             if ( !it3.next().getName().equals( "G" ) ) {
5849                 return false;
5850             }
5851             if ( !it3.next().getName().equals( "1" ) ) {
5852                 return false;
5853             }
5854             if ( !it3.next().getName().equals( "2" ) ) {
5855                 return false;
5856             }
5857             if ( !it3.next().getName().equals( "3" ) ) {
5858                 return false;
5859             }
5860             if ( !it3.next().getName().equals( "4" ) ) {
5861                 return false;
5862             }
5863             if ( !it3.next().getName().equals( "5" ) ) {
5864                 return false;
5865             }
5866             if ( !it3.next().getName().equals( "6" ) ) {
5867                 return false;
5868             }
5869             if ( !it3.next().getName().equals( "f1" ) ) {
5870                 return false;
5871             }
5872             if ( !it3.next().getName().equals( "f2" ) ) {
5873                 return false;
5874             }
5875             if ( !it3.next().getName().equals( "f3" ) ) {
5876                 return false;
5877             }
5878             if ( !it3.next().getName().equals( "a" ) ) {
5879                 return false;
5880             }
5881             if ( !it3.next().getName().equals( "b" ) ) {
5882                 return false;
5883             }
5884             if ( !it3.next().getName().equals( "f21" ) ) {
5885                 return false;
5886             }
5887             if ( !it3.next().getName().equals( "X" ) ) {
5888                 return false;
5889             }
5890             if ( !it3.next().getName().equals( "Y" ) ) {
5891                 return false;
5892             }
5893             if ( !it3.next().getName().equals( "Z" ) ) {
5894                 return false;
5895             }
5896             if ( it3.hasNext() ) {
5897                 return false;
5898             }
5899             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5900             PhylogenyNodeIterator it4;
5901             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5902                 it4.next();
5903             }
5904             for( it4.reset(); it4.hasNext(); ) {
5905                 it4.next();
5906             }
5907             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5908             if ( !it5.next().getName().equals( "r" ) ) {
5909                 return false;
5910             }
5911             if ( !it5.next().getName().equals( "A" ) ) {
5912                 return false;
5913             }
5914             if ( !it5.next().getName().equals( "B" ) ) {
5915                 return false;
5916             }
5917             if ( !it5.next().getName().equals( "C" ) ) {
5918                 return false;
5919             }
5920             if ( !it5.next().getName().equals( "D" ) ) {
5921                 return false;
5922             }
5923             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5924             PhylogenyNodeIterator it6;
5925             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5926                 it6.next();
5927             }
5928             for( it6.reset(); it6.hasNext(); ) {
5929                 it6.next();
5930             }
5931             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5932             if ( !it7.next().getName().equals( "A" ) ) {
5933                 return false;
5934             }
5935             if ( it.hasNext() ) {
5936                 return false;
5937             }
5938         }
5939         catch ( final Exception e ) {
5940             e.printStackTrace( System.out );
5941             return false;
5942         }
5943         return true;
5944     }
5945
5946     private static boolean testMafft( final String path ) {
5947         try {
5948             final List<String> opts = new ArrayList<String>();
5949             opts.add( "--maxiterate" );
5950             opts.add( "1000" );
5951             opts.add( "--localpair" );
5952             opts.add( "--quiet" );
5953             Msa msa = null;
5954             final MsaInferrer mafft = Mafft.createInstance( path );
5955             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5956             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5957                 return false;
5958             }
5959             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5960                 return false;
5961             }
5962         }
5963         catch ( final Exception e ) {
5964             e.printStackTrace( System.out );
5965             return false;
5966         }
5967         return true;
5968     }
5969
5970     private static boolean testMidpointrooting() {
5971         try {
5972             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5973             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5974             PhylogenyMethods.midpointRoot( t0 );
5975             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5976                 return false;
5977             }
5978             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5979                 return false;
5980             }
5981             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5982                            1 ) ) {
5983                 return false;
5984             }
5985             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",
5986                                                  new NHXParser() )[ 0 ];
5987             if ( !t1.isRooted() ) {
5988                 return false;
5989             }
5990             PhylogenyMethods.midpointRoot( t1 );
5991             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5992                 return false;
5993             }
5994             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5995                 return false;
5996             }
5997             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5998                 return false;
5999             }
6000             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6001                 return false;
6002             }
6003             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6004                 return false;
6005             }
6006             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6007                 return false;
6008             }
6009             t1.reRoot( t1.getNode( "A" ) );
6010             PhylogenyMethods.midpointRoot( t1 );
6011             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6012                 return false;
6013             }
6014             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6015                 return false;
6016             }
6017             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6018                 return false;
6019             }
6020             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6021                 return false;
6022             }
6023             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6024                 System.exit( -1 );
6025                 return false;
6026             }
6027             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6028                 return false;
6029             }
6030         }
6031         catch ( final Exception e ) {
6032             e.printStackTrace( System.out );
6033             return false;
6034         }
6035         return true;
6036     }
6037
6038     private static boolean testMsaQualityMethod() {
6039         try {
6040             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6041             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6042             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6043             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6044             final List<Sequence> l = new ArrayList<Sequence>();
6045             l.add( s0 );
6046             l.add( s1 );
6047             l.add( s2 );
6048             l.add( s3 );
6049             final Msa msa = BasicMsa.createInstance( l );
6050             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6051                 return false;
6052             }
6053             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6054                 return false;
6055             }
6056             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6057                 return false;
6058             }
6059             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6060                 return false;
6061             }
6062             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6063                 return false;
6064             }
6065             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6066                 return false;
6067             }
6068             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6069                 return false;
6070             }
6071         }
6072         catch ( final Exception e ) {
6073             e.printStackTrace( System.out );
6074             return false;
6075         }
6076         return true;
6077     }
6078
6079     private static boolean testNextNodeWithCollapsing() {
6080         try {
6081             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6082             PhylogenyNode n;
6083             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6084             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6085             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6086             t0.getNode( "cd" ).setCollapse( true );
6087             t0.getNode( "cde" ).setCollapse( true );
6088             n = t0.getFirstExternalNode();
6089             while ( n != null ) {
6090                 ext.add( n );
6091                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6092             }
6093             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6094                 return false;
6095             }
6096             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6097                 return false;
6098             }
6099             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6100                 return false;
6101             }
6102             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6103                 return false;
6104             }
6105             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6106                 return false;
6107             }
6108             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6109                 return false;
6110             }
6111             ext.clear();
6112             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6113             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6114             t1.getNode( "ab" ).setCollapse( true );
6115             t1.getNode( "cd" ).setCollapse( true );
6116             t1.getNode( "cde" ).setCollapse( true );
6117             n = t1.getNode( "ab" );
6118             ext = new ArrayList<PhylogenyNode>();
6119             while ( n != null ) {
6120                 ext.add( n );
6121                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6122             }
6123             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6124                 return false;
6125             }
6126             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6127                 return false;
6128             }
6129             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6130                 return false;
6131             }
6132             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6133                 return false;
6134             }
6135             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6136                 return false;
6137             }
6138             //
6139             //
6140             ext.clear();
6141             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6142             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6143             t2.getNode( "ab" ).setCollapse( true );
6144             t2.getNode( "cd" ).setCollapse( true );
6145             t2.getNode( "cde" ).setCollapse( true );
6146             t2.getNode( "c" ).setCollapse( true );
6147             t2.getNode( "d" ).setCollapse( true );
6148             t2.getNode( "e" ).setCollapse( true );
6149             t2.getNode( "gh" ).setCollapse( true );
6150             n = t2.getNode( "ab" );
6151             ext = new ArrayList<PhylogenyNode>();
6152             while ( n != null ) {
6153                 ext.add( n );
6154                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6155             }
6156             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6157                 return false;
6158             }
6159             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6160                 return false;
6161             }
6162             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6163                 return false;
6164             }
6165             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6166                 return false;
6167             }
6168             //
6169             //
6170             ext.clear();
6171             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6172             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6173             t3.getNode( "ab" ).setCollapse( true );
6174             t3.getNode( "cd" ).setCollapse( true );
6175             t3.getNode( "cde" ).setCollapse( true );
6176             t3.getNode( "c" ).setCollapse( true );
6177             t3.getNode( "d" ).setCollapse( true );
6178             t3.getNode( "e" ).setCollapse( true );
6179             t3.getNode( "gh" ).setCollapse( true );
6180             t3.getNode( "fgh" ).setCollapse( true );
6181             n = t3.getNode( "ab" );
6182             ext = new ArrayList<PhylogenyNode>();
6183             while ( n != null ) {
6184                 ext.add( n );
6185                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6186             }
6187             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6188                 return false;
6189             }
6190             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6191                 return false;
6192             }
6193             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6194                 return false;
6195             }
6196             //
6197             //
6198             ext.clear();
6199             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6200             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6201             t4.getNode( "ab" ).setCollapse( true );
6202             t4.getNode( "cd" ).setCollapse( true );
6203             t4.getNode( "cde" ).setCollapse( true );
6204             t4.getNode( "c" ).setCollapse( true );
6205             t4.getNode( "d" ).setCollapse( true );
6206             t4.getNode( "e" ).setCollapse( true );
6207             t4.getNode( "gh" ).setCollapse( true );
6208             t4.getNode( "fgh" ).setCollapse( true );
6209             t4.getNode( "abcdefgh" ).setCollapse( true );
6210             n = t4.getNode( "abcdefgh" );
6211             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6212                 return false;
6213             }
6214             //
6215             //
6216             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6217             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6218             ext.clear();
6219             n = t5.getFirstExternalNode();
6220             while ( n != null ) {
6221                 ext.add( n );
6222                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6223             }
6224             if ( ext.size() != 8 ) {
6225                 return false;
6226             }
6227             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6228                 return false;
6229             }
6230             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6231                 return false;
6232             }
6233             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6234                 return false;
6235             }
6236             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6237                 return false;
6238             }
6239             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6240                 return false;
6241             }
6242             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6243                 return false;
6244             }
6245             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6246                 return false;
6247             }
6248             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6249                 return false;
6250             }
6251             //
6252             //
6253             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6254             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6255             ext.clear();
6256             t6.getNode( "ab" ).setCollapse( true );
6257             n = t6.getNode( "ab" );
6258             while ( n != null ) {
6259                 ext.add( n );
6260                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6261             }
6262             if ( ext.size() != 7 ) {
6263                 return false;
6264             }
6265             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6266                 return false;
6267             }
6268             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6269                 return false;
6270             }
6271             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6272                 return false;
6273             }
6274             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6275                 return false;
6276             }
6277             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6278                 return false;
6279             }
6280             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6281                 return false;
6282             }
6283             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6284                 return false;
6285             }
6286             //
6287             //
6288             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6289             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6290             ext.clear();
6291             t7.getNode( "cd" ).setCollapse( true );
6292             n = t7.getNode( "a" );
6293             while ( n != null ) {
6294                 ext.add( n );
6295                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6296             }
6297             if ( ext.size() != 7 ) {
6298                 return false;
6299             }
6300             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6301                 return false;
6302             }
6303             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6304                 return false;
6305             }
6306             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6307                 return false;
6308             }
6309             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6310                 return false;
6311             }
6312             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6313                 return false;
6314             }
6315             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6316                 return false;
6317             }
6318             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6319                 return false;
6320             }
6321             //
6322             //
6323             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6324             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6325             ext.clear();
6326             t8.getNode( "cd" ).setCollapse( true );
6327             t8.getNode( "c" ).setCollapse( true );
6328             t8.getNode( "d" ).setCollapse( true );
6329             n = t8.getNode( "a" );
6330             while ( n != null ) {
6331                 ext.add( n );
6332                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6333             }
6334             if ( ext.size() != 7 ) {
6335                 return false;
6336             }
6337             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6338                 return false;
6339             }
6340             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6341                 return false;
6342             }
6343             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6344                 System.out.println( "2 fail" );
6345                 return false;
6346             }
6347             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6348                 return false;
6349             }
6350             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6351                 return false;
6352             }
6353             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6354                 return false;
6355             }
6356             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6357                 return false;
6358             }
6359             //
6360             //
6361             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6362             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6363             ext.clear();
6364             t9.getNode( "gh" ).setCollapse( true );
6365             n = t9.getNode( "a" );
6366             while ( n != null ) {
6367                 ext.add( n );
6368                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6369             }
6370             if ( ext.size() != 7 ) {
6371                 return false;
6372             }
6373             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6374                 return false;
6375             }
6376             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6377                 return false;
6378             }
6379             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6380                 return false;
6381             }
6382             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6383                 return false;
6384             }
6385             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6386                 return false;
6387             }
6388             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6389                 return false;
6390             }
6391             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6392                 return false;
6393             }
6394             //
6395             //
6396             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6397             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6398             ext.clear();
6399             t10.getNode( "gh" ).setCollapse( true );
6400             t10.getNode( "g" ).setCollapse( true );
6401             t10.getNode( "h" ).setCollapse( true );
6402             n = t10.getNode( "a" );
6403             while ( n != null ) {
6404                 ext.add( n );
6405                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6406             }
6407             if ( ext.size() != 7 ) {
6408                 return false;
6409             }
6410             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6411                 return false;
6412             }
6413             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6414                 return false;
6415             }
6416             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6417                 return false;
6418             }
6419             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6420                 return false;
6421             }
6422             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6423                 return false;
6424             }
6425             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6426                 return false;
6427             }
6428             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6429                 return false;
6430             }
6431             //
6432             //
6433             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6434             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6435             ext.clear();
6436             t11.getNode( "gh" ).setCollapse( true );
6437             t11.getNode( "fgh" ).setCollapse( true );
6438             n = t11.getNode( "a" );
6439             while ( n != null ) {
6440                 ext.add( n );
6441                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6442             }
6443             if ( ext.size() != 6 ) {
6444                 return false;
6445             }
6446             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6447                 return false;
6448             }
6449             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6450                 return false;
6451             }
6452             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6453                 return false;
6454             }
6455             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6456                 return false;
6457             }
6458             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6459                 return false;
6460             }
6461             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6462                 return false;
6463             }
6464             //
6465             //
6466             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6467             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6468             ext.clear();
6469             t12.getNode( "gh" ).setCollapse( true );
6470             t12.getNode( "fgh" ).setCollapse( true );
6471             t12.getNode( "g" ).setCollapse( true );
6472             t12.getNode( "h" ).setCollapse( true );
6473             t12.getNode( "f" ).setCollapse( true );
6474             n = t12.getNode( "a" );
6475             while ( n != null ) {
6476                 ext.add( n );
6477                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6478             }
6479             if ( ext.size() != 6 ) {
6480                 return false;
6481             }
6482             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6483                 return false;
6484             }
6485             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6486                 return false;
6487             }
6488             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6489                 return false;
6490             }
6491             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6492                 return false;
6493             }
6494             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6495                 return false;
6496             }
6497             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6498                 return false;
6499             }
6500             //
6501             //
6502             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6503             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6504             ext.clear();
6505             t13.getNode( "ab" ).setCollapse( true );
6506             t13.getNode( "b" ).setCollapse( true );
6507             t13.getNode( "fgh" ).setCollapse( true );
6508             t13.getNode( "gh" ).setCollapse( true );
6509             n = t13.getNode( "ab" );
6510             while ( n != null ) {
6511                 ext.add( n );
6512                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6513             }
6514             if ( ext.size() != 5 ) {
6515                 return false;
6516             }
6517             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6518                 return false;
6519             }
6520             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6521                 return false;
6522             }
6523             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6524                 return false;
6525             }
6526             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6527                 return false;
6528             }
6529             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6530                 return false;
6531             }
6532             //
6533             //
6534             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6535             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6536             ext.clear();
6537             t14.getNode( "ab" ).setCollapse( true );
6538             t14.getNode( "a" ).setCollapse( true );
6539             t14.getNode( "fgh" ).setCollapse( true );
6540             t14.getNode( "gh" ).setCollapse( true );
6541             n = t14.getNode( "ab" );
6542             while ( n != null ) {
6543                 ext.add( n );
6544                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6545             }
6546             if ( ext.size() != 5 ) {
6547                 return false;
6548             }
6549             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6550                 return false;
6551             }
6552             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6553                 return false;
6554             }
6555             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6556                 return false;
6557             }
6558             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6559                 return false;
6560             }
6561             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6562                 return false;
6563             }
6564             //
6565             //
6566             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" );
6567             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6568             ext.clear();
6569             t15.getNode( "ab" ).setCollapse( true );
6570             t15.getNode( "a" ).setCollapse( true );
6571             t15.getNode( "fgh" ).setCollapse( true );
6572             t15.getNode( "gh" ).setCollapse( true );
6573             n = t15.getNode( "ab" );
6574             while ( n != null ) {
6575                 ext.add( n );
6576                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6577             }
6578             if ( ext.size() != 6 ) {
6579                 return false;
6580             }
6581             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6582                 return false;
6583             }
6584             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6585                 return false;
6586             }
6587             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6588                 return false;
6589             }
6590             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6591                 return false;
6592             }
6593             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6594                 return false;
6595             }
6596             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6597                 return false;
6598             }
6599             //
6600             //
6601             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" );
6602             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6603             ext.clear();
6604             t16.getNode( "ab" ).setCollapse( true );
6605             t16.getNode( "a" ).setCollapse( true );
6606             t16.getNode( "fgh" ).setCollapse( true );
6607             t16.getNode( "gh" ).setCollapse( true );
6608             t16.getNode( "cd" ).setCollapse( true );
6609             t16.getNode( "cde" ).setCollapse( true );
6610             t16.getNode( "d" ).setCollapse( true );
6611             t16.getNode( "x" ).setCollapse( true );
6612             n = t16.getNode( "ab" );
6613             while ( n != null ) {
6614                 ext.add( n );
6615                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6616             }
6617             if ( ext.size() != 4 ) {
6618                 return false;
6619             }
6620             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6621                 return false;
6622             }
6623             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6624                 return false;
6625             }
6626             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6627                 return false;
6628             }
6629             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6630                 return false;
6631             }
6632         }
6633         catch ( final Exception e ) {
6634             e.printStackTrace( System.out );
6635             return false;
6636         }
6637         return true;
6638     }
6639
6640     private static boolean testNexusCharactersParsing() {
6641         try {
6642             final NexusCharactersParser parser = new NexusCharactersParser();
6643             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6644             parser.parse();
6645             String[] labels = parser.getCharStateLabels();
6646             if ( labels.length != 7 ) {
6647                 return false;
6648             }
6649             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6650                 return false;
6651             }
6652             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6653                 return false;
6654             }
6655             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6656                 return false;
6657             }
6658             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6659                 return false;
6660             }
6661             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6662                 return false;
6663             }
6664             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6665                 return false;
6666             }
6667             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6668                 return false;
6669             }
6670             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6671             parser.parse();
6672             labels = parser.getCharStateLabels();
6673             if ( labels.length != 7 ) {
6674                 return false;
6675             }
6676             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6677                 return false;
6678             }
6679             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6680                 return false;
6681             }
6682             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6683                 return false;
6684             }
6685             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6686                 return false;
6687             }
6688             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6689                 return false;
6690             }
6691             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6692                 return false;
6693             }
6694             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6695                 return false;
6696             }
6697         }
6698         catch ( final Exception e ) {
6699             e.printStackTrace( System.out );
6700             return false;
6701         }
6702         return true;
6703     }
6704
6705     private static boolean testNexusMatrixParsing() {
6706         try {
6707             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
6708             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
6709             parser.parse();
6710             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
6711             if ( m.getNumberOfCharacters() != 9 ) {
6712                 return false;
6713             }
6714             if ( m.getNumberOfIdentifiers() != 5 ) {
6715                 return false;
6716             }
6717             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
6718                 return false;
6719             }
6720             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
6721                 return false;
6722             }
6723             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
6724                 return false;
6725             }
6726             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
6727                 return false;
6728             }
6729             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
6730                 return false;
6731             }
6732             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6733                 return false;
6734             }
6735             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
6736                 return false;
6737             }
6738             //            if ( labels.length != 7 ) {
6739             //                return false;
6740             //            }
6741             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6742             //                return false;
6743             //            }
6744             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6745             //                return false;
6746             //            }
6747             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6748             //                return false;
6749             //            }
6750             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6751             //                return false;
6752             //            }
6753             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6754             //                return false;
6755             //            }
6756             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6757             //                return false;
6758             //            }
6759             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6760             //                return false;
6761             //            }
6762             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6763             //            parser.parse();
6764             //            labels = parser.getCharStateLabels();
6765             //            if ( labels.length != 7 ) {
6766             //                return false;
6767             //            }
6768             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6769             //                return false;
6770             //            }
6771             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6772             //                return false;
6773             //            }
6774             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6775             //                return false;
6776             //            }
6777             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6778             //                return false;
6779             //            }
6780             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6781             //                return false;
6782             //            }
6783             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6784             //                return false;
6785             //            }
6786             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6787             //                return false;
6788             //            }
6789         }
6790         catch ( final Exception e ) {
6791             e.printStackTrace( System.out );
6792             return false;
6793         }
6794         return true;
6795     }
6796
6797     private static boolean testNexusTreeParsing() {
6798         try {
6799             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6800             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6801             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
6802             if ( phylogenies.length != 1 ) {
6803                 return false;
6804             }
6805             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
6806                 return false;
6807             }
6808             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6809                 return false;
6810             }
6811             phylogenies = null;
6812             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
6813             if ( phylogenies.length != 1 ) {
6814                 return false;
6815             }
6816             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6817                 return false;
6818             }
6819             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
6820                 return false;
6821             }
6822             phylogenies = null;
6823             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
6824             if ( phylogenies.length != 1 ) {
6825                 return false;
6826             }
6827             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6828                 return false;
6829             }
6830             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6831                 return false;
6832             }
6833             if ( phylogenies[ 0 ].isRooted() ) {
6834                 return false;
6835             }
6836             phylogenies = null;
6837             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
6838             if ( phylogenies.length != 18 ) {
6839                 return false;
6840             }
6841             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6842                 return false;
6843             }
6844             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
6845                 return false;
6846             }
6847             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
6848                 return false;
6849             }
6850             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
6851                 return false;
6852             }
6853             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6854                 return false;
6855             }
6856             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
6857                 return false;
6858             }
6859             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
6860                 return false;
6861             }
6862             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
6863                 return false;
6864             }
6865             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
6866                 return false;
6867             }
6868             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
6869                 return false;
6870             }
6871             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
6872                 return false;
6873             }
6874             if ( phylogenies[ 8 ].isRooted() ) {
6875                 return false;
6876             }
6877             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
6878                 return false;
6879             }
6880             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
6881                 return false;
6882             }
6883             if ( !phylogenies[ 9 ].isRooted() ) {
6884                 return false;
6885             }
6886             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
6887                 return false;
6888             }
6889             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
6890                 return false;
6891             }
6892             if ( !phylogenies[ 10 ].isRooted() ) {
6893                 return false;
6894             }
6895             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
6896                 return false;
6897             }
6898             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
6899                 return false;
6900             }
6901             if ( phylogenies[ 11 ].isRooted() ) {
6902                 return false;
6903             }
6904             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
6905                 return false;
6906             }
6907             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
6908                 return false;
6909             }
6910             if ( !phylogenies[ 12 ].isRooted() ) {
6911                 return false;
6912             }
6913             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
6914                 return false;
6915             }
6916             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
6917                 return false;
6918             }
6919             if ( !phylogenies[ 13 ].isRooted() ) {
6920                 return false;
6921             }
6922             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
6923                 return false;
6924             }
6925             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
6926                 return false;
6927             }
6928             if ( !phylogenies[ 14 ].isRooted() ) {
6929                 return false;
6930             }
6931             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
6932                 return false;
6933             }
6934             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
6935                 return false;
6936             }
6937             if ( phylogenies[ 15 ].isRooted() ) {
6938                 return false;
6939             }
6940             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
6941                 return false;
6942             }
6943             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
6944                 return false;
6945             }
6946             if ( !phylogenies[ 16 ].isRooted() ) {
6947                 return false;
6948             }
6949             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
6950                 return false;
6951             }
6952             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
6953                 return false;
6954             }
6955             if ( phylogenies[ 17 ].isRooted() ) {
6956                 return false;
6957             }
6958             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
6959                 return false;
6960             }
6961             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
6962             phylogenies = null;
6963             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
6964             if ( phylogenies.length != 9 ) {
6965                 return false;
6966             }
6967             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
6968                     .getDistanceToParent() ) ) {
6969                 return false;
6970             }
6971             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
6972                     .getDistanceToParent() ) ) {
6973                 return false;
6974             }
6975             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
6976                 return false;
6977             }
6978             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
6979                 return false;
6980             }
6981             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
6982                 return false;
6983             }
6984             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
6985                 return false;
6986             }
6987             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
6988                 return false;
6989             }
6990         }
6991         catch ( final Exception e ) {
6992             e.printStackTrace( System.out );
6993             return false;
6994         }
6995         return true;
6996     }
6997
6998     private static boolean testNexusTreeParsingIterating() {
6999         try {
7000             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7001             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7002             if ( !p.hasNext() ) {
7003                 return false;
7004             }
7005             Phylogeny phy = p.next();
7006             if ( phy == null ) {
7007                 return false;
7008             }
7009             if ( phy.getNumberOfExternalNodes() != 25 ) {
7010                 return false;
7011             }
7012             if ( !phy.getName().equals( "" ) ) {
7013                 return false;
7014             }
7015             if ( p.hasNext() ) {
7016                 return false;
7017             }
7018             phy = p.next();
7019             if ( phy != null ) {
7020                 return false;
7021             }
7022             //
7023             p.reset();
7024             if ( !p.hasNext() ) {
7025                 return false;
7026             }
7027             phy = p.next();
7028             if ( phy == null ) {
7029                 return false;
7030             }
7031             if ( phy.getNumberOfExternalNodes() != 25 ) {
7032                 return false;
7033             }
7034             if ( !phy.getName().equals( "" ) ) {
7035                 return false;
7036             }
7037             if ( p.hasNext() ) {
7038                 return false;
7039             }
7040             phy = p.next();
7041             if ( phy != null ) {
7042                 return false;
7043             }
7044             ////
7045             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7046             if ( !p.hasNext() ) {
7047                 return false;
7048             }
7049             phy = p.next();
7050             if ( phy == null ) {
7051                 return false;
7052             }
7053             if ( phy.getNumberOfExternalNodes() != 10 ) {
7054                 return false;
7055             }
7056             if ( !phy.getName().equals( "name" ) ) {
7057                 return false;
7058             }
7059             if ( p.hasNext() ) {
7060                 return false;
7061             }
7062             phy = p.next();
7063             if ( phy != null ) {
7064                 return false;
7065             }
7066             //
7067             p.reset();
7068             if ( !p.hasNext() ) {
7069                 return false;
7070             }
7071             phy = p.next();
7072             if ( phy == null ) {
7073                 return false;
7074             }
7075             if ( phy.getNumberOfExternalNodes() != 10 ) {
7076                 return false;
7077             }
7078             if ( !phy.getName().equals( "name" ) ) {
7079                 return false;
7080             }
7081             if ( p.hasNext() ) {
7082                 return false;
7083             }
7084             phy = p.next();
7085             if ( phy != null ) {
7086                 return false;
7087             }
7088             //
7089             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7090             if ( !p.hasNext() ) {
7091                 return false;
7092             }
7093             phy = p.next();
7094             if ( phy == null ) {
7095                 return false;
7096             }
7097             if ( phy.getNumberOfExternalNodes() != 3 ) {
7098                 return false;
7099             }
7100             if ( !phy.getName().equals( "" ) ) {
7101                 return false;
7102             }
7103             if ( phy.isRooted() ) {
7104                 return false;
7105             }
7106             if ( p.hasNext() ) {
7107                 return false;
7108             }
7109             phy = p.next();
7110             if ( phy != null ) {
7111                 return false;
7112             }
7113             //
7114             p.reset();
7115             if ( !p.hasNext() ) {
7116                 return false;
7117             }
7118             phy = p.next();
7119             if ( phy == null ) {
7120                 return false;
7121             }
7122             if ( phy.getNumberOfExternalNodes() != 3 ) {
7123                 return false;
7124             }
7125             if ( !phy.getName().equals( "" ) ) {
7126                 return false;
7127             }
7128             if ( p.hasNext() ) {
7129                 return false;
7130             }
7131             phy = p.next();
7132             if ( phy != null ) {
7133                 return false;
7134             }
7135             //
7136             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7137             if ( !p.hasNext() ) {
7138                 return false;
7139             }
7140             //0
7141             phy = p.next();
7142             if ( phy == null ) {
7143                 return false;
7144             }
7145             if ( phy.getNumberOfExternalNodes() != 10 ) {
7146                 return false;
7147             }
7148             if ( !phy.getName().equals( "tree 0" ) ) {
7149                 return false;
7150             }
7151             //1
7152             if ( !p.hasNext() ) {
7153                 return false;
7154             }
7155             phy = p.next();
7156             if ( phy == null ) {
7157                 return false;
7158             }
7159             if ( phy.getNumberOfExternalNodes() != 10 ) {
7160                 return false;
7161             }
7162             if ( !phy.getName().equals( "tree 1" ) ) {
7163                 return false;
7164             }
7165             //2
7166             if ( !p.hasNext() ) {
7167                 return false;
7168             }
7169             phy = p.next();
7170             if ( phy == null ) {
7171                 return false;
7172             }
7173             if ( phy.getNumberOfExternalNodes() != 3 ) {
7174                 System.out.println( phy.toString() );
7175                 return false;
7176             }
7177             if ( !phy.getName().equals( "" ) ) {
7178                 return false;
7179             }
7180             if ( phy.isRooted() ) {
7181                 return false;
7182             }
7183             //3
7184             if ( !p.hasNext() ) {
7185                 return false;
7186             }
7187             phy = p.next();
7188             if ( phy == null ) {
7189                 return false;
7190             }
7191             if ( phy.getNumberOfExternalNodes() != 4 ) {
7192                 return false;
7193             }
7194             if ( !phy.getName().equals( "" ) ) {
7195                 return false;
7196             }
7197             if ( !phy.isRooted() ) {
7198                 return false;
7199             }
7200             //4
7201             if ( !p.hasNext() ) {
7202                 return false;
7203             }
7204             phy = p.next();
7205             if ( phy == null ) {
7206                 return false;
7207             }
7208             if ( phy.getNumberOfExternalNodes() != 5 ) {
7209                 System.out.println( phy.getNumberOfExternalNodes() );
7210                 return false;
7211             }
7212             if ( !phy.getName().equals( "" ) ) {
7213                 return false;
7214             }
7215             if ( !phy.isRooted() ) {
7216                 return false;
7217             }
7218             //5
7219             if ( !p.hasNext() ) {
7220                 return false;
7221             }
7222             phy = p.next();
7223             if ( phy == null ) {
7224                 return false;
7225             }
7226             if ( phy.getNumberOfExternalNodes() != 3 ) {
7227                 return false;
7228             }
7229             if ( !phy.getName().equals( "" ) ) {
7230                 return false;
7231             }
7232             if ( phy.isRooted() ) {
7233                 return false;
7234             }
7235             //6
7236             if ( !p.hasNext() ) {
7237                 return false;
7238             }
7239             phy = p.next();
7240             if ( phy == null ) {
7241                 return false;
7242             }
7243             if ( phy.getNumberOfExternalNodes() != 2 ) {
7244                 return false;
7245             }
7246             if ( !phy.getName().equals( "" ) ) {
7247                 return false;
7248             }
7249             if ( !phy.isRooted() ) {
7250                 return false;
7251             }
7252             //7
7253             if ( !p.hasNext() ) {
7254                 return false;
7255             }
7256             phy = p.next();
7257             if ( phy.getNumberOfExternalNodes() != 3 ) {
7258                 return false;
7259             }
7260             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7261                 return false;
7262             }
7263             if ( !phy.isRooted() ) {
7264                 return false;
7265             }
7266             //8
7267             if ( !p.hasNext() ) {
7268                 return false;
7269             }
7270             phy = p.next();
7271             if ( phy.getNumberOfExternalNodes() != 3 ) {
7272                 return false;
7273             }
7274             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7275                 return false;
7276             }
7277             if ( !phy.getName().equals( "tree 8" ) ) {
7278                 return false;
7279             }
7280             //9
7281             if ( !p.hasNext() ) {
7282                 return false;
7283             }
7284             phy = p.next();
7285             if ( phy.getNumberOfExternalNodes() != 3 ) {
7286                 return false;
7287             }
7288             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7289                 return false;
7290             }
7291             if ( !phy.getName().equals( "tree 9" ) ) {
7292                 return false;
7293             }
7294             //10
7295             if ( !p.hasNext() ) {
7296                 return false;
7297             }
7298             phy = p.next();
7299             if ( phy.getNumberOfExternalNodes() != 3 ) {
7300                 return false;
7301             }
7302             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7303                 return false;
7304             }
7305             if ( !phy.getName().equals( "tree 10" ) ) {
7306                 return false;
7307             }
7308             if ( !phy.isRooted() ) {
7309                 return false;
7310             }
7311             //11
7312             if ( !p.hasNext() ) {
7313                 return false;
7314             }
7315             phy = p.next();
7316             if ( phy.getNumberOfExternalNodes() != 3 ) {
7317                 return false;
7318             }
7319             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7320                 return false;
7321             }
7322             if ( !phy.getName().equals( "tree 11" ) ) {
7323                 return false;
7324             }
7325             if ( phy.isRooted() ) {
7326                 return false;
7327             }
7328             //12
7329             if ( !p.hasNext() ) {
7330                 return false;
7331             }
7332             phy = p.next();
7333             if ( phy.getNumberOfExternalNodes() != 3 ) {
7334                 return false;
7335             }
7336             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7337                 return false;
7338             }
7339             if ( !phy.getName().equals( "tree 12" ) ) {
7340                 return false;
7341             }
7342             if ( !phy.isRooted() ) {
7343                 return false;
7344             }
7345             //13
7346             if ( !p.hasNext() ) {
7347                 return false;
7348             }
7349             phy = p.next();
7350             if ( phy.getNumberOfExternalNodes() != 3 ) {
7351                 return false;
7352             }
7353             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7354                 return false;
7355             }
7356             if ( !phy.getName().equals( "tree 13" ) ) {
7357                 return false;
7358             }
7359             if ( !phy.isRooted() ) {
7360                 return false;
7361             }
7362             //14
7363             if ( !p.hasNext() ) {
7364                 return false;
7365             }
7366             phy = p.next();
7367             if ( phy.getNumberOfExternalNodes() != 10 ) {
7368                 System.out.println( phy.getNumberOfExternalNodes() );
7369                 return false;
7370             }
7371             if ( !phy
7372                     .toNewHampshire()
7373                     .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;" ) ) {
7374                 System.out.println( phy.toNewHampshire() );
7375                 return false;
7376             }
7377             if ( !phy.getName().equals( "tree 14" ) ) {
7378                 return false;
7379             }
7380             if ( !phy.isRooted() ) {
7381                 return false;
7382             }
7383             //15
7384             if ( !p.hasNext() ) {
7385                 return false;
7386             }
7387             phy = p.next();
7388             if ( phy.getNumberOfExternalNodes() != 10 ) {
7389                 System.out.println( phy.getNumberOfExternalNodes() );
7390                 return false;
7391             }
7392             if ( !phy
7393                     .toNewHampshire()
7394                     .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;" ) ) {
7395                 System.out.println( phy.toNewHampshire() );
7396                 return false;
7397             }
7398             if ( !phy.getName().equals( "tree 15" ) ) {
7399                 return false;
7400             }
7401             if ( phy.isRooted() ) {
7402                 return false;
7403             }
7404             //16
7405             if ( !p.hasNext() ) {
7406                 return false;
7407             }
7408             phy = p.next();
7409             if ( phy.getNumberOfExternalNodes() != 10 ) {
7410                 System.out.println( phy.getNumberOfExternalNodes() );
7411                 return false;
7412             }
7413             if ( !phy
7414                     .toNewHampshire()
7415                     .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;" ) ) {
7416                 System.out.println( phy.toNewHampshire() );
7417                 return false;
7418             }
7419             if ( !phy.getName().equals( "tree 16" ) ) {
7420                 return false;
7421             }
7422             if ( !phy.isRooted() ) {
7423                 return false;
7424             }
7425             //17
7426             if ( !p.hasNext() ) {
7427                 return false;
7428             }
7429             phy = p.next();
7430             if ( phy.getNumberOfExternalNodes() != 10 ) {
7431                 System.out.println( phy.getNumberOfExternalNodes() );
7432                 return false;
7433             }
7434             if ( !phy
7435                     .toNewHampshire()
7436                     .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;" ) ) {
7437                 System.out.println( phy.toNewHampshire() );
7438                 return false;
7439             }
7440             if ( !phy.getName().equals( "tree 17" ) ) {
7441                 return false;
7442             }
7443             if ( phy.isRooted() ) {
7444                 return false;
7445             }
7446             //
7447             if ( p.hasNext() ) {
7448                 return false;
7449             }
7450             phy = p.next();
7451             if ( phy != null ) {
7452                 return false;
7453             }
7454             p.reset();
7455             //0
7456             if ( !p.hasNext() ) {
7457                 return false;
7458             }
7459             phy = p.next();
7460             if ( phy == null ) {
7461                 return false;
7462             }
7463             if ( phy.getNumberOfExternalNodes() != 10 ) {
7464                 return false;
7465             }
7466             if ( !phy.getName().equals( "tree 0" ) ) {
7467                 return false;
7468             }
7469             //1
7470             if ( !p.hasNext() ) {
7471                 return false;
7472             }
7473             phy = p.next();
7474             if ( phy == null ) {
7475                 return false;
7476             }
7477             if ( phy.getNumberOfExternalNodes() != 10 ) {
7478                 return false;
7479             }
7480             if ( !phy.getName().equals( "tree 1" ) ) {
7481                 return false;
7482             }
7483             //2
7484             if ( !p.hasNext() ) {
7485                 return false;
7486             }
7487             phy = p.next();
7488             if ( phy == null ) {
7489                 return false;
7490             }
7491             if ( phy.getNumberOfExternalNodes() != 3 ) {
7492                 return false;
7493             }
7494             if ( !phy.getName().equals( "" ) ) {
7495                 return false;
7496             }
7497             if ( phy.isRooted() ) {
7498                 return false;
7499             }
7500             //3
7501             if ( !p.hasNext() ) {
7502                 return false;
7503             }
7504             phy = p.next();
7505             if ( phy == null ) {
7506                 return false;
7507             }
7508             if ( phy.getNumberOfExternalNodes() != 4 ) {
7509                 return false;
7510             }
7511             if ( !phy.getName().equals( "" ) ) {
7512                 return false;
7513             }
7514             if ( !phy.isRooted() ) {
7515                 return false;
7516             }
7517             //4
7518             if ( !p.hasNext() ) {
7519                 return false;
7520             }
7521             phy = p.next();
7522             if ( phy == null ) {
7523                 return false;
7524             }
7525             if ( phy.getNumberOfExternalNodes() != 5 ) {
7526                 System.out.println( phy.getNumberOfExternalNodes() );
7527                 return false;
7528             }
7529             if ( !phy.getName().equals( "" ) ) {
7530                 return false;
7531             }
7532             if ( !phy.isRooted() ) {
7533                 return false;
7534             }
7535             //5
7536             if ( !p.hasNext() ) {
7537                 return false;
7538             }
7539             phy = p.next();
7540             if ( phy == null ) {
7541                 return false;
7542             }
7543             if ( phy.getNumberOfExternalNodes() != 3 ) {
7544                 return false;
7545             }
7546             if ( !phy.getName().equals( "" ) ) {
7547                 return false;
7548             }
7549             if ( phy.isRooted() ) {
7550                 return false;
7551             }
7552             //
7553             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7554             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7555             // 0
7556             if ( !p2.hasNext() ) {
7557                 return false;
7558             }
7559             phy = p2.next();
7560             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7561                 return false;
7562             }
7563             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7564                 return false;
7565             }
7566             // 1
7567             if ( !p2.hasNext() ) {
7568                 return false;
7569             }
7570             phy = p2.next();
7571             // 2
7572             if ( !p2.hasNext() ) {
7573                 return false;
7574             }
7575             phy = p2.next();
7576             // 3
7577             if ( !p2.hasNext() ) {
7578                 return false;
7579             }
7580             phy = p2.next();
7581             // 4
7582             if ( !p2.hasNext() ) {
7583                 return false;
7584             }
7585             phy = p2.next();
7586             // 5
7587             if ( !p2.hasNext() ) {
7588                 return false;
7589             }
7590             phy = p2.next();
7591             // 6
7592             if ( !p2.hasNext() ) {
7593                 return false;
7594             }
7595             phy = p2.next();
7596             // 7
7597             if ( !p2.hasNext() ) {
7598                 return false;
7599             }
7600             phy = p2.next();
7601             // 8
7602             if ( !p2.hasNext() ) {
7603                 return false;
7604             }
7605             phy = p2.next();
7606             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7607                 return false;
7608             }
7609             if ( p2.hasNext() ) {
7610                 return false;
7611             }
7612             phy = p2.next();
7613             if ( phy != null ) {
7614                 return false;
7615             }
7616             // 0
7617             p2.reset();
7618             if ( !p2.hasNext() ) {
7619                 return false;
7620             }
7621             phy = p2.next();
7622             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7623                 return false;
7624             }
7625             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7626                 return false;
7627             }
7628         }
7629         catch ( final Exception e ) {
7630             e.printStackTrace( System.out );
7631             return false;
7632         }
7633         return true;
7634     }
7635
7636     private static boolean testNexusTreeParsingTranslating() {
7637         try {
7638             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7639             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7640             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7641             if ( phylogenies.length != 1 ) {
7642                 return false;
7643             }
7644             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7645                 return false;
7646             }
7647             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7648                 return false;
7649             }
7650             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7651                 return false;
7652             }
7653             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7654                 return false;
7655             }
7656             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7657                     .equals( "Aranaeus" ) ) {
7658                 return false;
7659             }
7660             phylogenies = null;
7661             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7662             if ( phylogenies.length != 3 ) {
7663                 return false;
7664             }
7665             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7666                 return false;
7667             }
7668             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7669                 return false;
7670             }
7671             if ( phylogenies[ 0 ].isRooted() ) {
7672                 return false;
7673             }
7674             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7675                 return false;
7676             }
7677             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7678                 return false;
7679             }
7680             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7681                     .equals( "Aranaeus" ) ) {
7682                 return false;
7683             }
7684             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7685                 return false;
7686             }
7687             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7688                 return false;
7689             }
7690             if ( phylogenies[ 1 ].isRooted() ) {
7691                 return false;
7692             }
7693             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7694                 return false;
7695             }
7696             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7697                 return false;
7698             }
7699             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7700                     .equals( "Aranaeus" ) ) {
7701                 return false;
7702             }
7703             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7704                 return false;
7705             }
7706             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7707                 return false;
7708             }
7709             if ( !phylogenies[ 2 ].isRooted() ) {
7710                 return false;
7711             }
7712             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7713                 return false;
7714             }
7715             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7716                 return false;
7717             }
7718             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7719                     .equals( "Aranaeus" ) ) {
7720                 return false;
7721             }
7722             phylogenies = null;
7723             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
7724             if ( phylogenies.length != 3 ) {
7725                 return false;
7726             }
7727             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7728                 return false;
7729             }
7730             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7731                 return false;
7732             }
7733             if ( phylogenies[ 0 ].isRooted() ) {
7734                 return false;
7735             }
7736             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7737                 return false;
7738             }
7739             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7740                 return false;
7741             }
7742             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7743                     .equals( "Aranaeus" ) ) {
7744                 return false;
7745             }
7746             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7747                 return false;
7748             }
7749             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7750                 return false;
7751             }
7752             if ( phylogenies[ 1 ].isRooted() ) {
7753                 return false;
7754             }
7755             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7756                 return false;
7757             }
7758             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7759                 return false;
7760             }
7761             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7762                     .equals( "Aranaeus" ) ) {
7763                 return false;
7764             }
7765             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7766                 return false;
7767             }
7768             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7769                 return false;
7770             }
7771             if ( !phylogenies[ 2 ].isRooted() ) {
7772                 return false;
7773             }
7774             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7775                 return false;
7776             }
7777             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7778                 return false;
7779             }
7780             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7781                     .equals( "Aranaeus" ) ) {
7782                 return false;
7783             }
7784             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
7785             if ( phylogenies.length != 3 ) {
7786                 return false;
7787             }
7788             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
7789                            0.00100049 ) ) {
7790                 return false;
7791             }
7792         }
7793         catch ( final Exception e ) {
7794             e.printStackTrace( System.out );
7795             return false;
7796         }
7797         return true;
7798     }
7799
7800     private static boolean testNHParsing() {
7801         try {
7802             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7803             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
7804             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
7805                 return false;
7806             }
7807             final NHXParser nhxp = new NHXParser();
7808             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
7809             nhxp.setReplaceUnderscores( true );
7810             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
7811             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
7812                 return false;
7813             }
7814             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
7815                 return false;
7816             }
7817             final Phylogeny p1b = factory
7818                     .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 ",
7819                              new NHXParser() )[ 0 ];
7820             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
7821                 return false;
7822             }
7823             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
7824                 return false;
7825             }
7826             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
7827             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
7828             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
7829             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
7830             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
7831             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
7832             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
7833             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
7834             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
7835             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
7836             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
7837                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
7838                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
7839                                                     new NHXParser() );
7840             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
7841                 return false;
7842             }
7843             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
7844                 return false;
7845             }
7846             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
7847                 return false;
7848             }
7849             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
7850                 return false;
7851             }
7852             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
7853             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
7854             final String p16_S = "((A,B),C)";
7855             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
7856             if ( p16.length != 1 ) {
7857                 return false;
7858             }
7859             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
7860                 return false;
7861             }
7862             final String p17_S = "(C,(A,B))";
7863             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
7864             if ( p17.length != 1 ) {
7865                 return false;
7866             }
7867             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
7868                 return false;
7869             }
7870             final String p18_S = "((A,B),(C,D))";
7871             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
7872             if ( p18.length != 1 ) {
7873                 return false;
7874             }
7875             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
7876                 return false;
7877             }
7878             final String p19_S = "(((A,B),C),D)";
7879             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
7880             if ( p19.length != 1 ) {
7881                 return false;
7882             }
7883             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
7884                 return false;
7885             }
7886             final String p20_S = "(A,(B,(C,D)))";
7887             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
7888             if ( p20.length != 1 ) {
7889                 return false;
7890             }
7891             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
7892                 return false;
7893             }
7894             final String p21_S = "(A,(B,(C,(D,E))))";
7895             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
7896             if ( p21.length != 1 ) {
7897                 return false;
7898             }
7899             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
7900                 return false;
7901             }
7902             final String p22_S = "((((A,B),C),D),E)";
7903             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
7904             if ( p22.length != 1 ) {
7905                 return false;
7906             }
7907             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
7908                 return false;
7909             }
7910             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7911             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
7912             if ( p23.length != 1 ) {
7913                 System.out.println( "xl=" + p23.length );
7914                 System.exit( -1 );
7915                 return false;
7916             }
7917             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
7918                 return false;
7919             }
7920             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7921             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
7922             if ( p24.length != 1 ) {
7923                 return false;
7924             }
7925             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
7926                 return false;
7927             }
7928             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7929             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7930             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
7931             if ( p241.length != 2 ) {
7932                 return false;
7933             }
7934             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
7935                 return false;
7936             }
7937             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
7938                 return false;
7939             }
7940             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
7941                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
7942                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
7943                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
7944                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
7945                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
7946                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
7947                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
7948             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
7949             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
7950                 return false;
7951             }
7952             final String p26_S = "(A,B)ab";
7953             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
7954             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
7955                 return false;
7956             }
7957             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7958             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
7959             if ( p27s.length != 1 ) {
7960                 System.out.println( "xxl=" + p27s.length );
7961                 System.exit( -1 );
7962                 return false;
7963             }
7964             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7965                 System.out.println( p27s[ 0 ].toNewHampshireX() );
7966                 System.exit( -1 );
7967                 return false;
7968             }
7969             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
7970                                                     new NHXParser() );
7971             if ( p27.length != 1 ) {
7972                 System.out.println( "yl=" + p27.length );
7973                 System.exit( -1 );
7974                 return false;
7975             }
7976             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7977                 System.out.println( p27[ 0 ].toNewHampshireX() );
7978                 System.exit( -1 );
7979                 return false;
7980             }
7981             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7982             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7983             final String p28_S3 = "(A,B)ab";
7984             final String p28_S4 = "((((A,B),C),D),;E;)";
7985             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
7986                                                     new NHXParser() );
7987             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
7988                 return false;
7989             }
7990             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
7991                 return false;
7992             }
7993             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
7994                 return false;
7995             }
7996             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
7997                 return false;
7998             }
7999             if ( p28.length != 4 ) {
8000                 return false;
8001             }
8002             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";
8003             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8004             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8005                 return false;
8006             }
8007             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";
8008             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8009             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8010                 return false;
8011             }
8012             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8013             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8014             if ( ( p32.length != 0 ) ) {
8015                 return false;
8016             }
8017             final String p33_S = "A";
8018             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8019             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8020                 return false;
8021             }
8022             final String p34_S = "B;";
8023             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8024             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8025                 return false;
8026             }
8027             final String p35_S = "B:0.2";
8028             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8029             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8030                 return false;
8031             }
8032             final String p36_S = "(A)";
8033             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8034             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8035                 return false;
8036             }
8037             final String p37_S = "((A))";
8038             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8039             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8040                 return false;
8041             }
8042             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8043             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8044             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8045                 return false;
8046             }
8047             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8048             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8049             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8050                 return false;
8051             }
8052             final String p40_S = "(A,B,C)";
8053             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8054             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8055                 return false;
8056             }
8057             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8058             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8059             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8060                 return false;
8061             }
8062             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8063             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8064             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8065                 return false;
8066             }
8067             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)";
8068             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8069             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8070                 return false;
8071             }
8072             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)))";
8073             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8074             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8075                 return false;
8076             }
8077             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8078             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8079             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8080                 return false;
8081             }
8082             final String p46_S = "";
8083             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8084             if ( p46.length != 0 ) {
8085                 return false;
8086             }
8087             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8088             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8089                 return false;
8090             }
8091             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8092             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8093                 return false;
8094             }
8095             final Phylogeny p49 = factory
8096                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8097                              new NHXParser() )[ 0 ];
8098             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8099                 return false;
8100             }
8101             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8102             if ( p50.getNode( "A" ) == null ) {
8103                 return false;
8104             }
8105             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8106                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8107                 return false;
8108             }
8109             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8110                 return false;
8111             }
8112             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8113                     .equals( "((A,B)88:2.0,C);" ) ) {
8114                 return false;
8115             }
8116             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8117             if ( p51.getNode( "A(A" ) == null ) {
8118                 return false;
8119             }
8120             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8121             if ( p52.getNode( "A(A" ) == null ) {
8122                 return false;
8123             }
8124             final Phylogeny p53 = factory
8125                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8126                              new NHXParser() )[ 0 ];
8127             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8128                 return false;
8129             }
8130             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8131             if ( p54.getNode( "A" ) == null ) {
8132                 return false;
8133             }
8134             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8135                 return false;
8136             }
8137             final Phylogeny p55 = factory
8138                     .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);" ),
8139                              new NHXParser() )[ 0 ];
8140             if ( !p55
8141                     .toNewHampshire()
8142                     .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);" ) ) {
8143                 System.out.println( p55.toNewHampshire() );
8144                 return false;
8145             }
8146             final Phylogeny p56 = factory
8147                     .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);" ),
8148                              new NHXParser() )[ 0 ];
8149             if ( !p56
8150                     .toNewHampshire()
8151                     .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);" ) ) {
8152                 System.out.println( p56.toNewHampshire() );
8153                 return false;
8154             }
8155             final Phylogeny p57 = factory
8156                     .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);" ),
8157                              new NHXParser() )[ 0 ];
8158             if ( !p57
8159                     .toNewHampshire()
8160                     .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);" ) ) {
8161                 System.out.println( p56.toNewHampshire() );
8162                 return false;
8163             }
8164             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8165             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8166             if ( !p58.toNewHampshire().equals( s58 ) ) {
8167                 System.out.println( p58.toNewHampshire() );
8168                 return false;
8169             }
8170             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8171             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8172             if ( !p59.toNewHampshire().equals( s59 ) ) {
8173                 System.out.println( p59.toNewHampshire() );
8174                 return false;
8175             }
8176             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8177             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8178             if ( !p60.toNewHampshire().equals( s60 ) ) {
8179                 System.out.println( p60.toNewHampshire() );
8180                 return false;
8181             }
8182             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8183             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8184             if ( !p61.toNewHampshire()
8185                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8186                 System.out.println( p61.toNewHampshire() );
8187                 return false;
8188             }
8189         }
8190         catch ( final Exception e ) {
8191             e.printStackTrace( System.out );
8192             return false;
8193         }
8194         return true;
8195     }
8196
8197     private static boolean testNHParsingIter() {
8198         try {
8199             final String p0_str = "(A,B);";
8200             final NHXParser p = new NHXParser();
8201             p.setSource( p0_str );
8202             if ( !p.hasNext() ) {
8203                 return false;
8204             }
8205             final Phylogeny p0 = p.next();
8206             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8207                 System.out.println( p0.toNewHampshire() );
8208                 return false;
8209             }
8210             if ( p.hasNext() ) {
8211                 return false;
8212             }
8213             if ( p.next() != null ) {
8214                 return false;
8215             }
8216             //
8217             final String p00_str = "(A,B)root;";
8218             p.setSource( p00_str );
8219             final Phylogeny p00 = p.next();
8220             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8221                 System.out.println( p00.toNewHampshire() );
8222                 return false;
8223             }
8224             //
8225             final String p000_str = "A;";
8226             p.setSource( p000_str );
8227             final Phylogeny p000 = p.next();
8228             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8229                 System.out.println( p000.toNewHampshire() );
8230                 return false;
8231             }
8232             //
8233             final String p0000_str = "A";
8234             p.setSource( p0000_str );
8235             final Phylogeny p0000 = p.next();
8236             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8237                 System.out.println( p0000.toNewHampshire() );
8238                 return false;
8239             }
8240             //
8241             p.setSource( "(A)" );
8242             final Phylogeny p00000 = p.next();
8243             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8244                 System.out.println( p00000.toNewHampshire() );
8245                 return false;
8246             }
8247             //
8248             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8249             p.setSource( p1_str );
8250             if ( !p.hasNext() ) {
8251                 return false;
8252             }
8253             final Phylogeny p1_0 = p.next();
8254             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8255                 System.out.println( p1_0.toNewHampshire() );
8256                 return false;
8257             }
8258             if ( !p.hasNext() ) {
8259                 return false;
8260             }
8261             final Phylogeny p1_1 = p.next();
8262             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8263                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8264                 return false;
8265             }
8266             if ( !p.hasNext() ) {
8267                 return false;
8268             }
8269             final Phylogeny p1_2 = p.next();
8270             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8271                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8272                 return false;
8273             }
8274             if ( !p.hasNext() ) {
8275                 return false;
8276             }
8277             final Phylogeny p1_3 = p.next();
8278             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8279                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8280                 return false;
8281             }
8282             if ( p.hasNext() ) {
8283                 return false;
8284             }
8285             if ( p.next() != null ) {
8286                 return false;
8287             }
8288             //
8289             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8290             p.setSource( p2_str );
8291             if ( !p.hasNext() ) {
8292                 return false;
8293             }
8294             Phylogeny p2_0 = p.next();
8295             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8296                 System.out.println( p2_0.toNewHampshire() );
8297                 return false;
8298             }
8299             if ( !p.hasNext() ) {
8300                 return false;
8301             }
8302             Phylogeny p2_1 = p.next();
8303             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8304                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8305                 return false;
8306             }
8307             if ( !p.hasNext() ) {
8308                 return false;
8309             }
8310             Phylogeny p2_2 = p.next();
8311             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8312                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8313                 return false;
8314             }
8315             if ( !p.hasNext() ) {
8316                 return false;
8317             }
8318             Phylogeny p2_3 = p.next();
8319             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8320                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8321                 return false;
8322             }
8323             if ( !p.hasNext() ) {
8324                 return false;
8325             }
8326             Phylogeny p2_4 = p.next();
8327             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8328                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8329                 return false;
8330             }
8331             if ( p.hasNext() ) {
8332                 return false;
8333             }
8334             if ( p.next() != null ) {
8335                 return false;
8336             }
8337             ////
8338             p.reset();
8339             if ( !p.hasNext() ) {
8340                 return false;
8341             }
8342             p2_0 = p.next();
8343             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8344                 System.out.println( p2_0.toNewHampshire() );
8345                 return false;
8346             }
8347             if ( !p.hasNext() ) {
8348                 return false;
8349             }
8350             p2_1 = p.next();
8351             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8352                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8353                 return false;
8354             }
8355             if ( !p.hasNext() ) {
8356                 return false;
8357             }
8358             p2_2 = p.next();
8359             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8360                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8361                 return false;
8362             }
8363             if ( !p.hasNext() ) {
8364                 return false;
8365             }
8366             p2_3 = p.next();
8367             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8368                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8369                 return false;
8370             }
8371             if ( !p.hasNext() ) {
8372                 return false;
8373             }
8374             p2_4 = p.next();
8375             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8376                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8377                 return false;
8378             }
8379             if ( p.hasNext() ) {
8380                 return false;
8381             }
8382             if ( p.next() != null ) {
8383                 return false;
8384             }
8385             //
8386             final String p3_str = "((A,B),C)abc";
8387             p.setSource( p3_str );
8388             if ( !p.hasNext() ) {
8389                 return false;
8390             }
8391             final Phylogeny p3_0 = p.next();
8392             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8393                 return false;
8394             }
8395             if ( p.hasNext() ) {
8396                 return false;
8397             }
8398             if ( p.next() != null ) {
8399                 return false;
8400             }
8401             //
8402             final String p4_str = "((A,B)ab,C)abc";
8403             p.setSource( p4_str );
8404             if ( !p.hasNext() ) {
8405                 return false;
8406             }
8407             final Phylogeny p4_0 = p.next();
8408             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8409                 return false;
8410             }
8411             if ( p.hasNext() ) {
8412                 return false;
8413             }
8414             if ( p.next() != null ) {
8415                 return false;
8416             }
8417             //
8418             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8419             p.setSource( p5_str );
8420             if ( !p.hasNext() ) {
8421                 return false;
8422             }
8423             final Phylogeny p5_0 = p.next();
8424             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8425                 return false;
8426             }
8427             if ( p.hasNext() ) {
8428                 return false;
8429             }
8430             if ( p.next() != null ) {
8431                 return false;
8432             }
8433             //
8434             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8435             p.setSource( p6_str );
8436             if ( !p.hasNext() ) {
8437                 return false;
8438             }
8439             Phylogeny p6_0 = p.next();
8440             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8441                 return false;
8442             }
8443             if ( p.hasNext() ) {
8444                 return false;
8445             }
8446             if ( p.next() != null ) {
8447                 return false;
8448             }
8449             p.reset();
8450             if ( !p.hasNext() ) {
8451                 return false;
8452             }
8453             p6_0 = p.next();
8454             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8455                 return false;
8456             }
8457             if ( p.hasNext() ) {
8458                 return false;
8459             }
8460             if ( p.next() != null ) {
8461                 return false;
8462             }
8463             //
8464             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8465             p.setSource( p7_str );
8466             if ( !p.hasNext() ) {
8467                 return false;
8468             }
8469             Phylogeny p7_0 = p.next();
8470             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8471                 return false;
8472             }
8473             if ( p.hasNext() ) {
8474                 return false;
8475             }
8476             if ( p.next() != null ) {
8477                 return false;
8478             }
8479             p.reset();
8480             if ( !p.hasNext() ) {
8481                 return false;
8482             }
8483             p7_0 = p.next();
8484             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8485                 return false;
8486             }
8487             if ( p.hasNext() ) {
8488                 return false;
8489             }
8490             if ( p.next() != null ) {
8491                 return false;
8492             }
8493             //
8494             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8495             p.setSource( p8_str );
8496             if ( !p.hasNext() ) {
8497                 return false;
8498             }
8499             Phylogeny p8_0 = p.next();
8500             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8501                 return false;
8502             }
8503             if ( !p.hasNext() ) {
8504                 return false;
8505             }
8506             if ( !p.hasNext() ) {
8507                 return false;
8508             }
8509             Phylogeny p8_1 = p.next();
8510             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8511                 return false;
8512             }
8513             if ( p.hasNext() ) {
8514                 return false;
8515             }
8516             if ( p.next() != null ) {
8517                 return false;
8518             }
8519             p.reset();
8520             if ( !p.hasNext() ) {
8521                 return false;
8522             }
8523             p8_0 = p.next();
8524             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8525                 return false;
8526             }
8527             if ( !p.hasNext() ) {
8528                 return false;
8529             }
8530             p8_1 = p.next();
8531             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8532                 return false;
8533             }
8534             if ( p.hasNext() ) {
8535                 return false;
8536             }
8537             if ( p.next() != null ) {
8538                 return false;
8539             }
8540             p.reset();
8541             //
8542             p.setSource( "" );
8543             if ( p.hasNext() ) {
8544                 return false;
8545             }
8546             //
8547             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8548             if ( !p.hasNext() ) {
8549                 return false;
8550             }
8551             Phylogeny p_27 = p.next();
8552             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8553                 System.out.println( p_27.toNewHampshireX() );
8554                 System.exit( -1 );
8555                 return false;
8556             }
8557             if ( p.hasNext() ) {
8558                 return false;
8559             }
8560             if ( p.next() != null ) {
8561                 return false;
8562             }
8563             p.reset();
8564             if ( !p.hasNext() ) {
8565                 return false;
8566             }
8567             p_27 = p.next();
8568             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8569                 System.out.println( p_27.toNewHampshireX() );
8570                 System.exit( -1 );
8571                 return false;
8572             }
8573             if ( p.hasNext() ) {
8574                 return false;
8575             }
8576             if ( p.next() != null ) {
8577                 return false;
8578             }
8579             //
8580             final String p30_str = "(A,B);(C,D)";
8581             final NHXParser p30 = new NHXParser();
8582             p30.setSource( p30_str );
8583             if ( !p30.hasNext() ) {
8584                 return false;
8585             }
8586             Phylogeny phy30 = p30.next();
8587             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8588                 System.out.println( phy30.toNewHampshire() );
8589                 return false;
8590             }
8591             if ( !p30.hasNext() ) {
8592                 return false;
8593             }
8594             Phylogeny phy301 = p30.next();
8595             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8596                 System.out.println( phy301.toNewHampshire() );
8597                 return false;
8598             }
8599             if ( p30.hasNext() ) {
8600                 return false;
8601             }
8602             if ( p30.hasNext() ) {
8603                 return false;
8604             }
8605             if ( p30.next() != null ) {
8606                 return false;
8607             }
8608             if ( p30.next() != null ) {
8609                 return false;
8610             }
8611             p30.reset();
8612             if ( !p30.hasNext() ) {
8613                 return false;
8614             }
8615             phy30 = p30.next();
8616             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8617                 System.out.println( phy30.toNewHampshire() );
8618                 return false;
8619             }
8620             if ( !p30.hasNext() ) {
8621                 return false;
8622             }
8623             phy301 = p30.next();
8624             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8625                 System.out.println( phy301.toNewHampshire() );
8626                 return false;
8627             }
8628             if ( p30.hasNext() ) {
8629                 return false;
8630             }
8631             if ( p30.hasNext() ) {
8632                 return false;
8633             }
8634             if ( p30.next() != null ) {
8635                 return false;
8636             }
8637             if ( p30.next() != null ) {
8638                 return false;
8639             }
8640         }
8641         catch ( final Exception e ) {
8642             e.printStackTrace( System.out );
8643             return false;
8644         }
8645         return true;
8646     }
8647
8648     private static boolean testNHXconversion() {
8649         try {
8650             final PhylogenyNode n1 = new PhylogenyNode();
8651             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8652             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8653             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8654             final PhylogenyNode n5 = PhylogenyNode
8655                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8656             final PhylogenyNode n6 = PhylogenyNode
8657                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8658             if ( !n1.toNewHampshireX().equals( "" ) ) {
8659                 return false;
8660             }
8661             if ( !n2.toNewHampshireX().equals( "" ) ) {
8662                 return false;
8663             }
8664             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8665                 return false;
8666             }
8667             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8668                 return false;
8669             }
8670             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8671                 return false;
8672             }
8673             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8674                 System.out.println( n6.toNewHampshireX() );
8675                 return false;
8676             }
8677             final PhylogenyNode n7 = new PhylogenyNode();
8678             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
8679             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8680                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
8681                 System.out.println( n7
8682                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
8683                 return false;
8684             }
8685         }
8686         catch ( final Exception e ) {
8687             e.printStackTrace( System.out );
8688             return false;
8689         }
8690         return true;
8691     }
8692
8693     private static boolean testNHXNodeParsing() {
8694         try {
8695             final PhylogenyNode n1 = new PhylogenyNode();
8696             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8697             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8698             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8699             final PhylogenyNode n5 = PhylogenyNode
8700                     .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]" );
8701             if ( !n3.getName().equals( "n3" ) ) {
8702                 return false;
8703             }
8704             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8705                 return false;
8706             }
8707             if ( n3.isDuplication() ) {
8708                 return false;
8709             }
8710             if ( n3.isHasAssignedEvent() ) {
8711                 return false;
8712             }
8713             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
8714                 return false;
8715             }
8716             if ( !n4.getName().equals( "n4" ) ) {
8717                 return false;
8718             }
8719             if ( n4.getDistanceToParent() != 0.01 ) {
8720                 return false;
8721             }
8722             if ( !n5.getName().equals( "n5" ) ) {
8723                 return false;
8724             }
8725             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
8726                 return false;
8727             }
8728             if ( n5.getDistanceToParent() != 0.1 ) {
8729                 return false;
8730             }
8731             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
8732                 return false;
8733             }
8734             if ( !n5.isDuplication() ) {
8735                 return false;
8736             }
8737             if ( !n5.isHasAssignedEvent() ) {
8738                 return false;
8739             }
8740             final PhylogenyNode n8 = PhylogenyNode
8741                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
8742                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8743             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8744                 return false;
8745             }
8746             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
8747                 return false;
8748             }
8749             final PhylogenyNode n9 = PhylogenyNode
8750                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
8751                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8752             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
8753                 return false;
8754             }
8755             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
8756                 return false;
8757             }
8758             final PhylogenyNode n10 = PhylogenyNode
8759                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8760             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
8761                 return false;
8762             }
8763             final PhylogenyNode n20 = PhylogenyNode
8764                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8765             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8766                 return false;
8767             }
8768             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
8769                 return false;
8770             }
8771             final PhylogenyNode n20x = PhylogenyNode
8772                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8773             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
8774                 return false;
8775             }
8776             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
8777                 return false;
8778             }
8779             final PhylogenyNode n20xx = PhylogenyNode
8780                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8781             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
8782                 return false;
8783             }
8784             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
8785                 return false;
8786             }
8787             final PhylogenyNode n20xxx = PhylogenyNode
8788                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8789             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
8790                 return false;
8791             }
8792             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
8793                 return false;
8794             }
8795             final PhylogenyNode n20xxxx = PhylogenyNode
8796                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8797             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
8798                 return false;
8799             }
8800             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
8801                 return false;
8802             }
8803             final PhylogenyNode n21 = PhylogenyNode
8804                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8805             if ( !n21.getName().equals( "N21_PIG" ) ) {
8806                 return false;
8807             }
8808             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
8809                 return false;
8810             }
8811             final PhylogenyNode n21x = PhylogenyNode
8812                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8813             if ( !n21x.getName().equals( "n21_PIG" ) ) {
8814                 return false;
8815             }
8816             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
8817                 return false;
8818             }
8819             final PhylogenyNode n22 = PhylogenyNode
8820                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8821             if ( !n22.getName().equals( "n22/PIG" ) ) {
8822                 return false;
8823             }
8824             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
8825                 return false;
8826             }
8827             final PhylogenyNode n23 = PhylogenyNode
8828                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8829             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
8830                 return false;
8831             }
8832             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
8833                 return false;
8834             }
8835             final PhylogenyNode a = PhylogenyNode
8836                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8837             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8838                 return false;
8839             }
8840             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
8841                 return false;
8842             }
8843             final PhylogenyNode c1 = PhylogenyNode
8844                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
8845                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8846             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
8847                 return false;
8848             }
8849             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
8850                 return false;
8851             }
8852             final PhylogenyNode c2 = PhylogenyNode
8853                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
8854                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8855             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
8856                 return false;
8857             }
8858             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
8859                 return false;
8860             }
8861             final PhylogenyNode e3 = PhylogenyNode
8862                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8863             if ( !e3.getName().equals( "n10_RAT~" ) ) {
8864                 return false;
8865             }
8866             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
8867                 return false;
8868             }
8869             final PhylogenyNode n11 = PhylogenyNode
8870                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
8871                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8872             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
8873                 return false;
8874             }
8875             if ( n11.getDistanceToParent() != 0.4 ) {
8876                 return false;
8877             }
8878             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
8879                 return false;
8880             }
8881             final PhylogenyNode n12 = PhylogenyNode
8882                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
8883                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8884             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
8885                 return false;
8886             }
8887             if ( n12.getDistanceToParent() != 0.4 ) {
8888                 return false;
8889             }
8890             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
8891                 return false;
8892             }
8893             final PhylogenyNode o = PhylogenyNode
8894                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8895             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
8896                 return false;
8897             }
8898             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
8899                 return false;
8900             }
8901             if ( n1.getName().compareTo( "" ) != 0 ) {
8902                 return false;
8903             }
8904             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8905                 return false;
8906             }
8907             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8908                 return false;
8909             }
8910             if ( n2.getName().compareTo( "" ) != 0 ) {
8911                 return false;
8912             }
8913             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8914                 return false;
8915             }
8916             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8917                 return false;
8918             }
8919             final PhylogenyNode n00 = PhylogenyNode
8920                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
8921             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
8922                 return false;
8923             }
8924             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
8925                 return false;
8926             }
8927             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
8928             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
8929                 return false;
8930             }
8931             final PhylogenyNode n13 = PhylogenyNode
8932                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8933             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
8934                 return false;
8935             }
8936             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
8937                 return false;
8938             }
8939             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8940                 return false;
8941             }
8942             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8943                 return false;
8944             }
8945             final PhylogenyNode n14 = PhylogenyNode
8946                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8947             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
8948                 return false;
8949             }
8950             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
8951                 return false;
8952             }
8953             final PhylogenyNode n15 = PhylogenyNode
8954                     .createInstanceFromNhxString( "something_wicked[123]",
8955                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8956             if ( !n15.getName().equals( "something_wicked" ) ) {
8957                 return false;
8958             }
8959             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
8960                 return false;
8961             }
8962             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
8963                 return false;
8964             }
8965             final PhylogenyNode n16 = PhylogenyNode
8966                     .createInstanceFromNhxString( "something_wicked2[9]",
8967                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8968             if ( !n16.getName().equals( "something_wicked2" ) ) {
8969                 return false;
8970             }
8971             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
8972                 return false;
8973             }
8974             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
8975                 return false;
8976             }
8977             final PhylogenyNode n17 = PhylogenyNode
8978                     .createInstanceFromNhxString( "something_wicked3[a]",
8979                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8980             if ( !n17.getName().equals( "something_wicked3" ) ) {
8981                 return false;
8982             }
8983             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
8984                 return false;
8985             }
8986             final PhylogenyNode n18 = PhylogenyNode
8987                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8988             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
8989                 return false;
8990             }
8991             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
8992                 return false;
8993             }
8994             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
8995                 return false;
8996             }
8997             final PhylogenyNode n19 = PhylogenyNode
8998                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8999             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9000                 return false;
9001             }
9002             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9003                 return false;
9004             }
9005             final PhylogenyNode n30 = PhylogenyNode
9006                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9007                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9008             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9009                 return false;
9010             }
9011             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9012                 return false;
9013             }
9014             final PhylogenyNode n31 = PhylogenyNode
9015                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9016                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9017             if ( n31.getNodeData().isHasTaxonomy() ) {
9018                 return false;
9019             }
9020             final PhylogenyNode n32 = PhylogenyNode
9021                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9022             if ( n32.getNodeData().isHasTaxonomy() ) {
9023                 return false;
9024             }
9025             final PhylogenyNode n40 = PhylogenyNode
9026                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9027             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9028                 return false;
9029             }
9030             final PhylogenyNode n41 = PhylogenyNode
9031                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9032             if ( n41.getNodeData().isHasTaxonomy() ) {
9033                 return false;
9034             }
9035             final PhylogenyNode n42 = PhylogenyNode
9036                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9037             if ( n42.getNodeData().isHasTaxonomy() ) {
9038                 return false;
9039             }
9040             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9041                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9042             if ( n43.getNodeData().isHasTaxonomy() ) {
9043                 return false;
9044             }
9045             final PhylogenyNode n44 = PhylogenyNode
9046                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9047             if ( n44.getNodeData().isHasTaxonomy() ) {
9048                 return false;
9049             }
9050         }
9051         catch ( final Exception e ) {
9052             e.printStackTrace( System.out );
9053             return false;
9054         }
9055         return true;
9056     }
9057
9058     private static boolean testNHXParsing() {
9059         try {
9060             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9061             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9062             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9063                 return false;
9064             }
9065             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]";
9066             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9067             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9068                 return false;
9069             }
9070             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]";
9071             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9072             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9073                 return false;
9074             }
9075             final Phylogeny[] p3 = factory
9076                     .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]",
9077                              new NHXParser() );
9078             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9079                 return false;
9080             }
9081             final Phylogeny[] p4 = factory
9082                     .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(]",
9083                              new NHXParser() );
9084             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9085                 return false;
9086             }
9087             final Phylogeny[] p5 = factory
9088                     .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(((]",
9089                              new NHXParser() );
9090             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9091                 return false;
9092             }
9093             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)";
9094             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)";
9095             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9096             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9097                 return false;
9098             }
9099             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)))";
9100             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)))";
9101             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9102             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9103                 return false;
9104             }
9105             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])   ))[,,, ])))))))";
9106             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9107             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9108             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9109                 return false;
9110             }
9111             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9112             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9113                 return false;
9114             }
9115             final Phylogeny p10 = factory
9116                     .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]",
9117                              new NHXParser() )[ 0 ];
9118             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9119                 return false;
9120             }
9121             final Phylogeny p11 = factory
9122                     .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]",
9123                              new NHXParser() )[ 0 ];
9124             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9125                 return false;
9126             }
9127         }
9128         catch ( final Exception e ) {
9129             e.printStackTrace( System.out );
9130             return false;
9131         }
9132         return true;
9133     }
9134
9135     private static boolean testNHXParsingMB() {
9136         try {
9137             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9138             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9139                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9140                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9141                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9142                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9143                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9144                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9145                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9146                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9147             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9148                 return false;
9149             }
9150             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9151                 return false;
9152             }
9153             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9154                            0.1100000000000000e+00 ) ) {
9155                 return false;
9156             }
9157             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9158                 return false;
9159             }
9160             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9161                 return false;
9162             }
9163             final Phylogeny p2 = factory
9164                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9165                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9166                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9167                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9168                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9169                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9170                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9171                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9172                                      + "7.369400000000000e-02}])",
9173                              new NHXParser() )[ 0 ];
9174             if ( p2.getNode( "1" ) == null ) {
9175                 return false;
9176             }
9177             if ( p2.getNode( "2" ) == null ) {
9178                 return false;
9179             }
9180         }
9181         catch ( final Exception e ) {
9182             e.printStackTrace( System.out );
9183             System.exit( -1 );
9184             return false;
9185         }
9186         return true;
9187     }
9188
9189     private static boolean testNHXParsingQuotes() {
9190         try {
9191             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9192             final NHXParser p = new NHXParser();
9193             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9194             if ( phylogenies_0.length != 5 ) {
9195                 return false;
9196             }
9197             final Phylogeny phy = phylogenies_0[ 4 ];
9198             if ( phy.getNumberOfExternalNodes() != 7 ) {
9199                 return false;
9200             }
9201             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9202                 return false;
9203             }
9204             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9205                 return false;
9206             }
9207             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9208                     .getScientificName().equals( "hsapiens" ) ) {
9209                 return false;
9210             }
9211             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9212                 return false;
9213             }
9214             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9215                 return false;
9216             }
9217             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9218                 return false;
9219             }
9220             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9221                 return false;
9222             }
9223             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9224                 return false;
9225             }
9226             final NHXParser p1p = new NHXParser();
9227             p1p.setIgnoreQuotes( true );
9228             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9229             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9230                 return false;
9231             }
9232             final NHXParser p2p = new NHXParser();
9233             p1p.setIgnoreQuotes( false );
9234             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9235             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9236                 return false;
9237             }
9238             final NHXParser p3p = new NHXParser();
9239             p3p.setIgnoreQuotes( false );
9240             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9241             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9242                 return false;
9243             }
9244             final NHXParser p4p = new NHXParser();
9245             p4p.setIgnoreQuotes( false );
9246             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9247             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9248                 return false;
9249             }
9250             final Phylogeny p10 = factory
9251                     .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]",
9252                              new NHXParser() )[ 0 ];
9253             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]";
9254             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9255                 return false;
9256             }
9257             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9258             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9259                 return false;
9260             }
9261             final Phylogeny p12 = factory
9262                     .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]",
9263                              new NHXParser() )[ 0 ];
9264             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]";
9265             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9266                 return false;
9267             }
9268             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9269             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9270                 return false;
9271             }
9272             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;";
9273             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9274                 return false;
9275             }
9276             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9277             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9278                 return false;
9279             }
9280         }
9281         catch ( final Exception e ) {
9282             e.printStackTrace( System.out );
9283             return false;
9284         }
9285         return true;
9286     }
9287
9288     private static boolean testNodeRemoval() {
9289         try {
9290             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9291             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9292             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9293             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9294                 return false;
9295             }
9296             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9297             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9298             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9299                 return false;
9300             }
9301             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9302             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9303             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9304                 return false;
9305             }
9306         }
9307         catch ( final Exception e ) {
9308             e.printStackTrace( System.out );
9309             return false;
9310         }
9311         return true;
9312     }
9313
9314     private static boolean testPhylogenyBranch() {
9315         try {
9316             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9317             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9318             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9319             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9320             if ( !a1b1.equals( a1b1 ) ) {
9321                 return false;
9322             }
9323             if ( !a1b1.equals( b1a1 ) ) {
9324                 return false;
9325             }
9326             if ( !b1a1.equals( a1b1 ) ) {
9327                 return false;
9328             }
9329             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9330             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9331             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9332             if ( a1_b1.equals( b1_a1 ) ) {
9333                 return false;
9334             }
9335             if ( a1_b1.equals( a1_b1_ ) ) {
9336                 return false;
9337             }
9338             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9339             if ( !a1_b1.equals( b1_a1_ ) ) {
9340                 return false;
9341             }
9342             if ( a1_b1_.equals( b1_a1_ ) ) {
9343                 return false;
9344             }
9345             if ( !a1_b1_.equals( b1_a1 ) ) {
9346                 return false;
9347             }
9348         }
9349         catch ( final Exception e ) {
9350             e.printStackTrace( System.out );
9351             return false;
9352         }
9353         return true;
9354     }
9355
9356     private static boolean testPhyloXMLparsingOfDistributionElement() {
9357         try {
9358             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9359             PhyloXmlParser xml_parser = null;
9360             try {
9361                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9362             }
9363             catch ( final Exception e ) {
9364                 // Do nothing -- means were not running from jar.
9365             }
9366             if ( xml_parser == null ) {
9367                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9368                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9369                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9370                 }
9371                 else {
9372                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9373                 }
9374             }
9375             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9376                                                               xml_parser );
9377             if ( xml_parser.getErrorCount() > 0 ) {
9378                 System.out.println( xml_parser.getErrorMessages().toString() );
9379                 return false;
9380             }
9381             if ( phylogenies_0.length != 1 ) {
9382                 return false;
9383             }
9384             final Phylogeny t1 = phylogenies_0[ 0 ];
9385             PhylogenyNode n = null;
9386             Distribution d = null;
9387             n = t1.getNode( "root node" );
9388             if ( !n.getNodeData().isHasDistribution() ) {
9389                 return false;
9390             }
9391             if ( n.getNodeData().getDistributions().size() != 1 ) {
9392                 return false;
9393             }
9394             d = n.getNodeData().getDistribution();
9395             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9396                 return false;
9397             }
9398             if ( d.getPoints().size() != 1 ) {
9399                 return false;
9400             }
9401             if ( d.getPolygons() != null ) {
9402                 return false;
9403             }
9404             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9405                 return false;
9406             }
9407             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9408                 return false;
9409             }
9410             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9411                 return false;
9412             }
9413             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9414                 return false;
9415             }
9416             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9417                 return false;
9418             }
9419             n = t1.getNode( "node a" );
9420             if ( !n.getNodeData().isHasDistribution() ) {
9421                 return false;
9422             }
9423             if ( n.getNodeData().getDistributions().size() != 2 ) {
9424                 return false;
9425             }
9426             d = n.getNodeData().getDistribution( 1 );
9427             if ( !d.getDesc().equals( "San Diego" ) ) {
9428                 return false;
9429             }
9430             if ( d.getPoints().size() != 1 ) {
9431                 return false;
9432             }
9433             if ( d.getPolygons() != null ) {
9434                 return false;
9435             }
9436             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9437                 return false;
9438             }
9439             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9440                 return false;
9441             }
9442             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9443                 return false;
9444             }
9445             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9446                 return false;
9447             }
9448             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9449                 return false;
9450             }
9451             n = t1.getNode( "node bb" );
9452             if ( !n.getNodeData().isHasDistribution() ) {
9453                 return false;
9454             }
9455             if ( n.getNodeData().getDistributions().size() != 1 ) {
9456                 return false;
9457             }
9458             d = n.getNodeData().getDistribution( 0 );
9459             if ( d.getPoints().size() != 3 ) {
9460                 return false;
9461             }
9462             if ( d.getPolygons().size() != 2 ) {
9463                 return false;
9464             }
9465             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9466                 return false;
9467             }
9468             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9469                 return false;
9470             }
9471             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9472                 return false;
9473             }
9474             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9475                 return false;
9476             }
9477             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9478                 return false;
9479             }
9480             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9481                 return false;
9482             }
9483             Polygon p = d.getPolygons().get( 0 );
9484             if ( p.getPoints().size() != 3 ) {
9485                 return false;
9486             }
9487             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9488                 return false;
9489             }
9490             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9491                 return false;
9492             }
9493             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9494                 return false;
9495             }
9496             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9497                 return false;
9498             }
9499             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9500                 return false;
9501             }
9502             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9503                 return false;
9504             }
9505             p = d.getPolygons().get( 1 );
9506             if ( p.getPoints().size() != 3 ) {
9507                 return false;
9508             }
9509             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9510                 return false;
9511             }
9512             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9513                 return false;
9514             }
9515             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9516                 return false;
9517             }
9518             // Roundtrip:
9519             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9520             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9521             if ( rt.length != 1 ) {
9522                 return false;
9523             }
9524             final Phylogeny t1_rt = rt[ 0 ];
9525             n = t1_rt.getNode( "root node" );
9526             if ( !n.getNodeData().isHasDistribution() ) {
9527                 return false;
9528             }
9529             if ( n.getNodeData().getDistributions().size() != 1 ) {
9530                 return false;
9531             }
9532             d = n.getNodeData().getDistribution();
9533             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9534                 return false;
9535             }
9536             if ( d.getPoints().size() != 1 ) {
9537                 return false;
9538             }
9539             if ( d.getPolygons() != null ) {
9540                 return false;
9541             }
9542             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9543                 return false;
9544             }
9545             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9546                 return false;
9547             }
9548             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9549                 return false;
9550             }
9551             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9552                 return false;
9553             }
9554             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9555                 return false;
9556             }
9557             n = t1_rt.getNode( "node a" );
9558             if ( !n.getNodeData().isHasDistribution() ) {
9559                 return false;
9560             }
9561             if ( n.getNodeData().getDistributions().size() != 2 ) {
9562                 return false;
9563             }
9564             d = n.getNodeData().getDistribution( 1 );
9565             if ( !d.getDesc().equals( "San Diego" ) ) {
9566                 return false;
9567             }
9568             if ( d.getPoints().size() != 1 ) {
9569                 return false;
9570             }
9571             if ( d.getPolygons() != null ) {
9572                 return false;
9573             }
9574             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9575                 return false;
9576             }
9577             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9578                 return false;
9579             }
9580             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9581                 return false;
9582             }
9583             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9584                 return false;
9585             }
9586             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9587                 return false;
9588             }
9589             n = t1_rt.getNode( "node bb" );
9590             if ( !n.getNodeData().isHasDistribution() ) {
9591                 return false;
9592             }
9593             if ( n.getNodeData().getDistributions().size() != 1 ) {
9594                 return false;
9595             }
9596             d = n.getNodeData().getDistribution( 0 );
9597             if ( d.getPoints().size() != 3 ) {
9598                 return false;
9599             }
9600             if ( d.getPolygons().size() != 2 ) {
9601                 return false;
9602             }
9603             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9604                 return false;
9605             }
9606             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9607                 return false;
9608             }
9609             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9610                 return false;
9611             }
9612             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9613                 return false;
9614             }
9615             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9616                 return false;
9617             }
9618             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9619                 return false;
9620             }
9621             p = d.getPolygons().get( 0 );
9622             if ( p.getPoints().size() != 3 ) {
9623                 return false;
9624             }
9625             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9626                 return false;
9627             }
9628             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9629                 return false;
9630             }
9631             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9632                 return false;
9633             }
9634             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9635                 return false;
9636             }
9637             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9638                 return false;
9639             }
9640             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9641                 return false;
9642             }
9643             p = d.getPolygons().get( 1 );
9644             if ( p.getPoints().size() != 3 ) {
9645                 return false;
9646             }
9647             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9648                 return false;
9649             }
9650             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9651                 return false;
9652             }
9653             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9654                 return false;
9655             }
9656         }
9657         catch ( final Exception e ) {
9658             e.printStackTrace( System.out );
9659             return false;
9660         }
9661         return true;
9662     }
9663
9664     private static boolean testPostOrderIterator() {
9665         try {
9666             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9667             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9668             PhylogenyNodeIterator it0;
9669             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9670                 it0.next();
9671             }
9672             for( it0.reset(); it0.hasNext(); ) {
9673                 it0.next();
9674             }
9675             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9676             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9677             if ( !it.next().getName().equals( "A" ) ) {
9678                 return false;
9679             }
9680             if ( !it.next().getName().equals( "B" ) ) {
9681                 return false;
9682             }
9683             if ( !it.next().getName().equals( "ab" ) ) {
9684                 return false;
9685             }
9686             if ( !it.next().getName().equals( "C" ) ) {
9687                 return false;
9688             }
9689             if ( !it.next().getName().equals( "D" ) ) {
9690                 return false;
9691             }
9692             if ( !it.next().getName().equals( "cd" ) ) {
9693                 return false;
9694             }
9695             if ( !it.next().getName().equals( "abcd" ) ) {
9696                 return false;
9697             }
9698             if ( !it.next().getName().equals( "E" ) ) {
9699                 return false;
9700             }
9701             if ( !it.next().getName().equals( "F" ) ) {
9702                 return false;
9703             }
9704             if ( !it.next().getName().equals( "ef" ) ) {
9705                 return false;
9706             }
9707             if ( !it.next().getName().equals( "G" ) ) {
9708                 return false;
9709             }
9710             if ( !it.next().getName().equals( "H" ) ) {
9711                 return false;
9712             }
9713             if ( !it.next().getName().equals( "gh" ) ) {
9714                 return false;
9715             }
9716             if ( !it.next().getName().equals( "efgh" ) ) {
9717                 return false;
9718             }
9719             if ( !it.next().getName().equals( "r" ) ) {
9720                 return false;
9721             }
9722             if ( it.hasNext() ) {
9723                 return false;
9724             }
9725         }
9726         catch ( final Exception e ) {
9727             e.printStackTrace( System.out );
9728             return false;
9729         }
9730         return true;
9731     }
9732
9733     private static boolean testPreOrderIterator() {
9734         try {
9735             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9736             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9737             PhylogenyNodeIterator it0;
9738             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
9739                 it0.next();
9740             }
9741             for( it0.reset(); it0.hasNext(); ) {
9742                 it0.next();
9743             }
9744             PhylogenyNodeIterator it = t0.iteratorPreorder();
9745             if ( !it.next().getName().equals( "r" ) ) {
9746                 return false;
9747             }
9748             if ( !it.next().getName().equals( "ab" ) ) {
9749                 return false;
9750             }
9751             if ( !it.next().getName().equals( "A" ) ) {
9752                 return false;
9753             }
9754             if ( !it.next().getName().equals( "B" ) ) {
9755                 return false;
9756             }
9757             if ( !it.next().getName().equals( "cd" ) ) {
9758                 return false;
9759             }
9760             if ( !it.next().getName().equals( "C" ) ) {
9761                 return false;
9762             }
9763             if ( !it.next().getName().equals( "D" ) ) {
9764                 return false;
9765             }
9766             if ( it.hasNext() ) {
9767                 return false;
9768             }
9769             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9770             it = t1.iteratorPreorder();
9771             if ( !it.next().getName().equals( "r" ) ) {
9772                 return false;
9773             }
9774             if ( !it.next().getName().equals( "abcd" ) ) {
9775                 return false;
9776             }
9777             if ( !it.next().getName().equals( "ab" ) ) {
9778                 return false;
9779             }
9780             if ( !it.next().getName().equals( "A" ) ) {
9781                 return false;
9782             }
9783             if ( !it.next().getName().equals( "B" ) ) {
9784                 return false;
9785             }
9786             if ( !it.next().getName().equals( "cd" ) ) {
9787                 return false;
9788             }
9789             if ( !it.next().getName().equals( "C" ) ) {
9790                 return false;
9791             }
9792             if ( !it.next().getName().equals( "D" ) ) {
9793                 return false;
9794             }
9795             if ( !it.next().getName().equals( "efgh" ) ) {
9796                 return false;
9797             }
9798             if ( !it.next().getName().equals( "ef" ) ) {
9799                 return false;
9800             }
9801             if ( !it.next().getName().equals( "E" ) ) {
9802                 return false;
9803             }
9804             if ( !it.next().getName().equals( "F" ) ) {
9805                 return false;
9806             }
9807             if ( !it.next().getName().equals( "gh" ) ) {
9808                 return false;
9809             }
9810             if ( !it.next().getName().equals( "G" ) ) {
9811                 return false;
9812             }
9813             if ( !it.next().getName().equals( "H" ) ) {
9814                 return false;
9815             }
9816             if ( it.hasNext() ) {
9817                 return false;
9818             }
9819         }
9820         catch ( final Exception e ) {
9821             e.printStackTrace( System.out );
9822             return false;
9823         }
9824         return true;
9825     }
9826
9827     private static boolean testPropertiesMap() {
9828         try {
9829             final PropertiesMap pm = new PropertiesMap();
9830             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9831             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9832             final Property p2 = new Property( "something:else",
9833                                               "?",
9834                                               "improbable:research",
9835                                               "xsd:decimal",
9836                                               AppliesTo.NODE );
9837             pm.addProperty( p0 );
9838             pm.addProperty( p1 );
9839             pm.addProperty( p2 );
9840             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
9841                 return false;
9842             }
9843             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
9844                 return false;
9845             }
9846             if ( pm.getProperties().size() != 3 ) {
9847                 return false;
9848             }
9849             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
9850                 return false;
9851             }
9852             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9853                 return false;
9854             }
9855             if ( pm.getProperties().size() != 3 ) {
9856                 return false;
9857             }
9858             pm.removeProperty( "dimensions:diameter" );
9859             if ( pm.getProperties().size() != 2 ) {
9860                 return false;
9861             }
9862             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
9863                 return false;
9864             }
9865             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9866                 return false;
9867             }
9868         }
9869         catch ( final Exception e ) {
9870             e.printStackTrace( System.out );
9871             return false;
9872         }
9873         return true;
9874     }
9875
9876     private static boolean testProteinId() {
9877         try {
9878             final ProteinId id1 = new ProteinId( "a" );
9879             final ProteinId id2 = new ProteinId( "a" );
9880             final ProteinId id3 = new ProteinId( "A" );
9881             final ProteinId id4 = new ProteinId( "b" );
9882             if ( !id1.equals( id1 ) ) {
9883                 return false;
9884             }
9885             if ( id1.getId().equals( "x" ) ) {
9886                 return false;
9887             }
9888             if ( id1.getId().equals( null ) ) {
9889                 return false;
9890             }
9891             if ( !id1.equals( id2 ) ) {
9892                 return false;
9893             }
9894             if ( id1.equals( id3 ) ) {
9895                 return false;
9896             }
9897             if ( id1.hashCode() != id1.hashCode() ) {
9898                 return false;
9899             }
9900             if ( id1.hashCode() != id2.hashCode() ) {
9901                 return false;
9902             }
9903             if ( id1.hashCode() == id3.hashCode() ) {
9904                 return false;
9905             }
9906             if ( id1.compareTo( id1 ) != 0 ) {
9907                 return false;
9908             }
9909             if ( id1.compareTo( id2 ) != 0 ) {
9910                 return false;
9911             }
9912             if ( id1.compareTo( id3 ) != 0 ) {
9913                 return false;
9914             }
9915             if ( id1.compareTo( id4 ) >= 0 ) {
9916                 return false;
9917             }
9918             if ( id4.compareTo( id1 ) <= 0 ) {
9919                 return false;
9920             }
9921             if ( !id4.getId().equals( "b" ) ) {
9922                 return false;
9923             }
9924             final ProteinId id5 = new ProteinId( " C " );
9925             if ( !id5.getId().equals( "C" ) ) {
9926                 return false;
9927             }
9928             if ( id5.equals( id1 ) ) {
9929                 return false;
9930             }
9931         }
9932         catch ( final Exception e ) {
9933             e.printStackTrace( System.out );
9934             return false;
9935         }
9936         return true;
9937     }
9938
9939     private static boolean testReIdMethods() {
9940         try {
9941             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9942             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
9943             final long count = PhylogenyNode.getNodeCount();
9944             p.levelOrderReID();
9945             if ( p.getNode( "r" ).getId() != count ) {
9946                 return false;
9947             }
9948             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
9949                 return false;
9950             }
9951             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
9952                 return false;
9953             }
9954             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
9955                 return false;
9956             }
9957             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
9958                 return false;
9959             }
9960             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
9961                 return false;
9962             }
9963             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
9964                 return false;
9965             }
9966             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
9967                 return false;
9968             }
9969             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
9970                 return false;
9971             }
9972             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
9973                 return false;
9974             }
9975             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
9976                 return false;
9977             }
9978             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
9979                 return false;
9980             }
9981             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
9982                 return false;
9983             }
9984             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
9985                 return false;
9986             }
9987             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
9988                 return false;
9989             }
9990         }
9991         catch ( final Exception e ) {
9992             e.printStackTrace( System.out );
9993             return false;
9994         }
9995         return true;
9996     }
9997
9998     private static boolean testRerooting() {
9999         try {
10000             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10001             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",
10002                                                  new NHXParser() )[ 0 ];
10003             if ( !t1.isRooted() ) {
10004                 return false;
10005             }
10006             t1.reRoot( t1.getNode( "D" ) );
10007             t1.reRoot( t1.getNode( "CD" ) );
10008             t1.reRoot( t1.getNode( "A" ) );
10009             t1.reRoot( t1.getNode( "B" ) );
10010             t1.reRoot( t1.getNode( "AB" ) );
10011             t1.reRoot( t1.getNode( "D" ) );
10012             t1.reRoot( t1.getNode( "C" ) );
10013             t1.reRoot( t1.getNode( "CD" ) );
10014             t1.reRoot( t1.getNode( "A" ) );
10015             t1.reRoot( t1.getNode( "B" ) );
10016             t1.reRoot( t1.getNode( "AB" ) );
10017             t1.reRoot( t1.getNode( "D" ) );
10018             t1.reRoot( t1.getNode( "D" ) );
10019             t1.reRoot( t1.getNode( "C" ) );
10020             t1.reRoot( t1.getNode( "A" ) );
10021             t1.reRoot( t1.getNode( "B" ) );
10022             t1.reRoot( t1.getNode( "AB" ) );
10023             t1.reRoot( t1.getNode( "C" ) );
10024             t1.reRoot( t1.getNode( "D" ) );
10025             t1.reRoot( t1.getNode( "CD" ) );
10026             t1.reRoot( t1.getNode( "D" ) );
10027             t1.reRoot( t1.getNode( "A" ) );
10028             t1.reRoot( t1.getNode( "B" ) );
10029             t1.reRoot( t1.getNode( "AB" ) );
10030             t1.reRoot( t1.getNode( "C" ) );
10031             t1.reRoot( t1.getNode( "D" ) );
10032             t1.reRoot( t1.getNode( "CD" ) );
10033             t1.reRoot( t1.getNode( "D" ) );
10034             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10035                 return false;
10036             }
10037             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10038                 return false;
10039             }
10040             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10041                 return false;
10042             }
10043             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10044                 return false;
10045             }
10046             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10047                 return false;
10048             }
10049             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10050                 return false;
10051             }
10052             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",
10053                                                  new NHXParser() )[ 0 ];
10054             t2.reRoot( t2.getNode( "A" ) );
10055             t2.reRoot( t2.getNode( "D" ) );
10056             t2.reRoot( t2.getNode( "ABC" ) );
10057             t2.reRoot( t2.getNode( "A" ) );
10058             t2.reRoot( t2.getNode( "B" ) );
10059             t2.reRoot( t2.getNode( "D" ) );
10060             t2.reRoot( t2.getNode( "C" ) );
10061             t2.reRoot( t2.getNode( "ABC" ) );
10062             t2.reRoot( t2.getNode( "A" ) );
10063             t2.reRoot( t2.getNode( "B" ) );
10064             t2.reRoot( t2.getNode( "AB" ) );
10065             t2.reRoot( t2.getNode( "AB" ) );
10066             t2.reRoot( t2.getNode( "D" ) );
10067             t2.reRoot( t2.getNode( "C" ) );
10068             t2.reRoot( t2.getNode( "B" ) );
10069             t2.reRoot( t2.getNode( "AB" ) );
10070             t2.reRoot( t2.getNode( "D" ) );
10071             t2.reRoot( t2.getNode( "D" ) );
10072             t2.reRoot( t2.getNode( "ABC" ) );
10073             t2.reRoot( t2.getNode( "A" ) );
10074             t2.reRoot( t2.getNode( "B" ) );
10075             t2.reRoot( t2.getNode( "AB" ) );
10076             t2.reRoot( t2.getNode( "D" ) );
10077             t2.reRoot( t2.getNode( "C" ) );
10078             t2.reRoot( t2.getNode( "ABC" ) );
10079             t2.reRoot( t2.getNode( "A" ) );
10080             t2.reRoot( t2.getNode( "B" ) );
10081             t2.reRoot( t2.getNode( "AB" ) );
10082             t2.reRoot( t2.getNode( "D" ) );
10083             t2.reRoot( t2.getNode( "D" ) );
10084             t2.reRoot( t2.getNode( "C" ) );
10085             t2.reRoot( t2.getNode( "A" ) );
10086             t2.reRoot( t2.getNode( "B" ) );
10087             t2.reRoot( t2.getNode( "AB" ) );
10088             t2.reRoot( t2.getNode( "C" ) );
10089             t2.reRoot( t2.getNode( "D" ) );
10090             t2.reRoot( t2.getNode( "ABC" ) );
10091             t2.reRoot( t2.getNode( "D" ) );
10092             t2.reRoot( t2.getNode( "A" ) );
10093             t2.reRoot( t2.getNode( "B" ) );
10094             t2.reRoot( t2.getNode( "AB" ) );
10095             t2.reRoot( t2.getNode( "C" ) );
10096             t2.reRoot( t2.getNode( "D" ) );
10097             t2.reRoot( t2.getNode( "ABC" ) );
10098             t2.reRoot( t2.getNode( "D" ) );
10099             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10100                 return false;
10101             }
10102             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10103                 return false;
10104             }
10105             t2.reRoot( t2.getNode( "ABC" ) );
10106             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10107                 return false;
10108             }
10109             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10110                 return false;
10111             }
10112             t2.reRoot( t2.getNode( "AB" ) );
10113             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10114                 return false;
10115             }
10116             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10117                 return false;
10118             }
10119             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10120                 return false;
10121             }
10122             t2.reRoot( t2.getNode( "AB" ) );
10123             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10124                 return false;
10125             }
10126             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10127                 return false;
10128             }
10129             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10130                 return false;
10131             }
10132             t2.reRoot( t2.getNode( "D" ) );
10133             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10134                 return false;
10135             }
10136             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10137                 return false;
10138             }
10139             t2.reRoot( t2.getNode( "ABC" ) );
10140             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10141                 return false;
10142             }
10143             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10144                 return false;
10145             }
10146             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10147                                                  new NHXParser() )[ 0 ];
10148             t3.reRoot( t3.getNode( "B" ) );
10149             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10150                 return false;
10151             }
10152             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10153                 return false;
10154             }
10155             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10156                 return false;
10157             }
10158             t3.reRoot( t3.getNode( "B" ) );
10159             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10160                 return false;
10161             }
10162             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10163                 return false;
10164             }
10165             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10166                 return false;
10167             }
10168             t3.reRoot( t3.getRoot() );
10169             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10170                 return false;
10171             }
10172             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10173                 return false;
10174             }
10175             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10176                 return false;
10177             }
10178         }
10179         catch ( final Exception e ) {
10180             e.printStackTrace( System.out );
10181             return false;
10182         }
10183         return true;
10184     }
10185
10186     private static boolean testSDIse() {
10187         try {
10188             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10189             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10190             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10191             gene1.setRooted( true );
10192             species1.setRooted( true );
10193             final SDI sdi = new SDI( gene1, species1 );
10194             if ( !gene1.getRoot().isDuplication() ) {
10195                 return false;
10196             }
10197             final Phylogeny species2 = factory
10198                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10199                              new NHXParser() )[ 0 ];
10200             final Phylogeny gene2 = factory
10201                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10202                              new NHXParser() )[ 0 ];
10203             species2.setRooted( true );
10204             gene2.setRooted( true );
10205             final SDI sdi2 = new SDI( gene2, species2 );
10206             if ( sdi2.getDuplicationsSum() != 0 ) {
10207                 return false;
10208             }
10209             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10210                 return false;
10211             }
10212             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10213                 return false;
10214             }
10215             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10216                 return false;
10217             }
10218             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10219                 return false;
10220             }
10221             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10222                 return false;
10223             }
10224             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10225                 return false;
10226             }
10227             final Phylogeny species3 = factory
10228                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10229                              new NHXParser() )[ 0 ];
10230             final Phylogeny gene3 = factory
10231                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10232                              new NHXParser() )[ 0 ];
10233             species3.setRooted( true );
10234             gene3.setRooted( true );
10235             final SDI sdi3 = new SDI( gene3, species3 );
10236             if ( sdi3.getDuplicationsSum() != 1 ) {
10237                 return false;
10238             }
10239             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10240                 return false;
10241             }
10242             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10243                 return false;
10244             }
10245             final Phylogeny species4 = factory
10246                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10247                              new NHXParser() )[ 0 ];
10248             final Phylogeny gene4 = factory
10249                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10250                              new NHXParser() )[ 0 ];
10251             species4.setRooted( true );
10252             gene4.setRooted( true );
10253             final SDI sdi4 = new SDI( gene4, species4 );
10254             if ( sdi4.getDuplicationsSum() != 1 ) {
10255                 return false;
10256             }
10257             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10258                 return false;
10259             }
10260             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10261                 return false;
10262             }
10263             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10264                 return false;
10265             }
10266             if ( species4.getNumberOfExternalNodes() != 6 ) {
10267                 return false;
10268             }
10269             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10270                 return false;
10271             }
10272             final Phylogeny species5 = factory
10273                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10274                              new NHXParser() )[ 0 ];
10275             final Phylogeny gene5 = factory
10276                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10277                              new NHXParser() )[ 0 ];
10278             species5.setRooted( true );
10279             gene5.setRooted( true );
10280             final SDI sdi5 = new SDI( gene5, species5 );
10281             if ( sdi5.getDuplicationsSum() != 2 ) {
10282                 return false;
10283             }
10284             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10285                 return false;
10286             }
10287             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10288                 return false;
10289             }
10290             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10291                 return false;
10292             }
10293             if ( species5.getNumberOfExternalNodes() != 6 ) {
10294                 return false;
10295             }
10296             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10297                 return false;
10298             }
10299             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10300             // Conjecture for Comparing Molecular Phylogenies"
10301             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10302             final Phylogeny species6 = factory
10303                     .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,"
10304                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10305                              new NHXParser() )[ 0 ];
10306             final Phylogeny gene6 = factory
10307                     .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,"
10308                                      + "((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,"
10309                                      + "(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;",
10310                              new NHXParser() )[ 0 ];
10311             species6.setRooted( true );
10312             gene6.setRooted( true );
10313             final SDI sdi6 = new SDI( gene6, species6 );
10314             if ( sdi6.getDuplicationsSum() != 3 ) {
10315                 return false;
10316             }
10317             if ( !gene6.getNode( "r" ).isDuplication() ) {
10318                 return false;
10319             }
10320             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10321                 return false;
10322             }
10323             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10324                 return false;
10325             }
10326             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10327                 return false;
10328             }
10329             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10330                 return false;
10331             }
10332             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10333                 return false;
10334             }
10335             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10336                 return false;
10337             }
10338             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10339                 return false;
10340             }
10341             sdi6.computeMappingCostL();
10342             if ( sdi6.computeMappingCostL() != 17 ) {
10343                 return false;
10344             }
10345             if ( species6.getNumberOfExternalNodes() != 9 ) {
10346                 return false;
10347             }
10348             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10349                 return false;
10350             }
10351             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10352                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10353                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10354                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10355                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10356             species7.setRooted( true );
10357             final Phylogeny gene7_1 = Test
10358                     .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])" );
10359             gene7_1.setRooted( true );
10360             final SDI sdi7 = new SDI( gene7_1, species7 );
10361             if ( sdi7.getDuplicationsSum() != 0 ) {
10362                 return false;
10363             }
10364             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10365                 return false;
10366             }
10367             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10368                 return false;
10369             }
10370             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10371                 return false;
10372             }
10373             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10374                 return false;
10375             }
10376             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10377                 return false;
10378             }
10379             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10380                 return false;
10381             }
10382             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10383                 return false;
10384             }
10385             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10386                 return false;
10387             }
10388             final Phylogeny gene7_2 = Test
10389                     .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])" );
10390             gene7_2.setRooted( true );
10391             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10392             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10393                 return false;
10394             }
10395             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10396                 return false;
10397             }
10398             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10399                 return false;
10400             }
10401             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10402                 return false;
10403             }
10404             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10405                 return false;
10406             }
10407             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10408                 return false;
10409             }
10410             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10411                 return false;
10412             }
10413             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10414                 return false;
10415             }
10416             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10417                 return false;
10418             }
10419             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10420                 return false;
10421             }
10422         }
10423         catch ( final Exception e ) {
10424             return false;
10425         }
10426         return true;
10427     }
10428
10429     private static boolean testSDIunrooted() {
10430         try {
10431             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10432             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10433             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10434             final Iterator<PhylogenyBranch> iter = l.iterator();
10435             PhylogenyBranch br = iter.next();
10436             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10437                 return false;
10438             }
10439             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10440                 return false;
10441             }
10442             br = iter.next();
10443             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10444                 return false;
10445             }
10446             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10447                 return false;
10448             }
10449             br = iter.next();
10450             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10451                 return false;
10452             }
10453             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10454                 return false;
10455             }
10456             br = iter.next();
10457             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10458                 return false;
10459             }
10460             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10461                 return false;
10462             }
10463             br = iter.next();
10464             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10465                 return false;
10466             }
10467             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10468                 return false;
10469             }
10470             br = iter.next();
10471             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10472                 return false;
10473             }
10474             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10475                 return false;
10476             }
10477             br = iter.next();
10478             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10479                 return false;
10480             }
10481             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10482                 return false;
10483             }
10484             br = iter.next();
10485             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10486                 return false;
10487             }
10488             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10489                 return false;
10490             }
10491             br = iter.next();
10492             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10493                 return false;
10494             }
10495             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10496                 return false;
10497             }
10498             br = iter.next();
10499             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10500                 return false;
10501             }
10502             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10503                 return false;
10504             }
10505             br = iter.next();
10506             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10507                 return false;
10508             }
10509             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10510                 return false;
10511             }
10512             br = iter.next();
10513             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10514                 return false;
10515             }
10516             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10517                 return false;
10518             }
10519             br = iter.next();
10520             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10521                 return false;
10522             }
10523             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10524                 return false;
10525             }
10526             br = iter.next();
10527             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10528                 return false;
10529             }
10530             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10531                 return false;
10532             }
10533             br = iter.next();
10534             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10535                 return false;
10536             }
10537             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10538                 return false;
10539             }
10540             if ( iter.hasNext() ) {
10541                 return false;
10542             }
10543             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10544             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10545             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10546             br = iter1.next();
10547             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10548                 return false;
10549             }
10550             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10551                 return false;
10552             }
10553             br = iter1.next();
10554             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10555                 return false;
10556             }
10557             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10558                 return false;
10559             }
10560             br = iter1.next();
10561             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10562                 return false;
10563             }
10564             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10565                 return false;
10566             }
10567             if ( iter1.hasNext() ) {
10568                 return false;
10569             }
10570             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10571             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10572             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10573             br = iter2.next();
10574             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10575                 return false;
10576             }
10577             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10578                 return false;
10579             }
10580             br = iter2.next();
10581             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10582                 return false;
10583             }
10584             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10585                 return false;
10586             }
10587             br = iter2.next();
10588             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10589                 return false;
10590             }
10591             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10592                 return false;
10593             }
10594             if ( iter2.hasNext() ) {
10595                 return false;
10596             }
10597             final Phylogeny species0 = factory
10598                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10599                              new NHXParser() )[ 0 ];
10600             final Phylogeny gene1 = factory
10601                     .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])",
10602                              new NHXParser() )[ 0 ];
10603             species0.setRooted( true );
10604             gene1.setRooted( true );
10605             final SDIR sdi_unrooted = new SDIR();
10606             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10607             if ( sdi_unrooted.getCount() != 1 ) {
10608                 return false;
10609             }
10610             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10611                 return false;
10612             }
10613             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10614                 return false;
10615             }
10616             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10617                 return false;
10618             }
10619             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10620                 return false;
10621             }
10622             final Phylogeny gene2 = factory
10623                     .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])",
10624                              new NHXParser() )[ 0 ];
10625             gene2.setRooted( true );
10626             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10627             if ( sdi_unrooted.getCount() != 1 ) {
10628                 return false;
10629             }
10630             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10631                 return false;
10632             }
10633             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10634                 return false;
10635             }
10636             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10637                 return false;
10638             }
10639             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10640                 return false;
10641             }
10642             final Phylogeny species6 = factory
10643                     .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,"
10644                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10645                              new NHXParser() )[ 0 ];
10646             final Phylogeny gene6 = factory
10647                     .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],"
10648                                      + "(((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],"
10649                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10650                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10651                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10652                              new NHXParser() )[ 0 ];
10653             species6.setRooted( true );
10654             gene6.setRooted( true );
10655             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10656             if ( sdi_unrooted.getCount() != 1 ) {
10657                 return false;
10658             }
10659             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10660                 return false;
10661             }
10662             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10663                 return false;
10664             }
10665             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10666                 return false;
10667             }
10668             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10669                 return false;
10670             }
10671             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10672                 return false;
10673             }
10674             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10675                 return false;
10676             }
10677             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10678                 return false;
10679             }
10680             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
10681                 return false;
10682             }
10683             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10684                 return false;
10685             }
10686             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
10687                 return false;
10688             }
10689             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
10690                 return false;
10691             }
10692             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10693                 return false;
10694             }
10695             p6 = null;
10696             final Phylogeny species7 = factory
10697                     .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,"
10698                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10699                              new NHXParser() )[ 0 ];
10700             final Phylogeny gene7 = factory
10701                     .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],"
10702                                      + "(((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],"
10703                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10704                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10705                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10706                              new NHXParser() )[ 0 ];
10707             species7.setRooted( true );
10708             gene7.setRooted( true );
10709             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
10710             if ( sdi_unrooted.getCount() != 1 ) {
10711                 return false;
10712             }
10713             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10714                 return false;
10715             }
10716             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10717                 return false;
10718             }
10719             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10720                 return false;
10721             }
10722             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
10723                 return false;
10724             }
10725             if ( !p7[ 0 ].getRoot().isDuplication() ) {
10726                 return false;
10727             }
10728             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10729                 return false;
10730             }
10731             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10732                 return false;
10733             }
10734             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
10735                 return false;
10736             }
10737             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10738                 return false;
10739             }
10740             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
10741                 return false;
10742             }
10743             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
10744                 return false;
10745             }
10746             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10747                 return false;
10748             }
10749             p7 = null;
10750             final Phylogeny species8 = factory
10751                     .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,"
10752                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10753                              new NHXParser() )[ 0 ];
10754             final Phylogeny gene8 = factory
10755                     .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],"
10756                                      + "(((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],"
10757                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10758                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10759                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10760                              new NHXParser() )[ 0 ];
10761             species8.setRooted( true );
10762             gene8.setRooted( true );
10763             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
10764             if ( sdi_unrooted.getCount() != 1 ) {
10765                 return false;
10766             }
10767             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10768                 return false;
10769             }
10770             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10771                 return false;
10772             }
10773             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10774                 return false;
10775             }
10776             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10777                 return false;
10778             }
10779             if ( !p8[ 0 ].getRoot().isDuplication() ) {
10780                 return false;
10781             }
10782             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10783                 return false;
10784             }
10785             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10786                 return false;
10787             }
10788             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
10789                 return false;
10790             }
10791             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10792                 return false;
10793             }
10794             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
10795                 return false;
10796             }
10797             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
10798                 return false;
10799             }
10800             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10801                 return false;
10802             }
10803             p8 = null;
10804         }
10805         catch ( final Exception e ) {
10806             e.printStackTrace( System.out );
10807             return false;
10808         }
10809         return true;
10810     }
10811
10812     private static boolean testSequenceDbWsTools1() {
10813         try {
10814             final PhylogenyNode n = new PhylogenyNode();
10815             n.setName( "NP_001025424" );
10816             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
10817             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10818                     || !acc.getValue().equals( "NP_001025424" ) ) {
10819                 return false;
10820             }
10821             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
10822             acc = SequenceDbWsTools.obtainSeqAccession( n );
10823             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10824                     || !acc.getValue().equals( "NP_001025424" ) ) {
10825                 return false;
10826             }
10827             n.setName( "NP_001025424.1" );
10828             acc = SequenceDbWsTools.obtainSeqAccession( n );
10829             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10830                     || !acc.getValue().equals( "NP_001025424" ) ) {
10831                 return false;
10832             }
10833             n.setName( "NM_001030253" );
10834             acc = SequenceDbWsTools.obtainSeqAccession( n );
10835             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10836                     || !acc.getValue().equals( "NM_001030253" ) ) {
10837                 return false;
10838             }
10839             n.setName( "BCL2_HUMAN" );
10840             acc = SequenceDbWsTools.obtainSeqAccession( n );
10841             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10842                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
10843                 System.out.println( acc.toString() );
10844                 return false;
10845             }
10846             n.setName( "P10415" );
10847             acc = SequenceDbWsTools.obtainSeqAccession( n );
10848             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10849                     || !acc.getValue().equals( "P10415" ) ) {
10850                 System.out.println( acc.toString() );
10851                 return false;
10852             }
10853             n.setName( " P10415 " );
10854             acc = SequenceDbWsTools.obtainSeqAccession( n );
10855             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10856                     || !acc.getValue().equals( "P10415" ) ) {
10857                 System.out.println( acc.toString() );
10858                 return false;
10859             }
10860             n.setName( "_P10415|" );
10861             acc = SequenceDbWsTools.obtainSeqAccession( n );
10862             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10863                     || !acc.getValue().equals( "P10415" ) ) {
10864                 System.out.println( acc.toString() );
10865                 return false;
10866             }
10867             n.setName( "AY695820" );
10868             acc = SequenceDbWsTools.obtainSeqAccession( n );
10869             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10870                     || !acc.getValue().equals( "AY695820" ) ) {
10871                 System.out.println( acc.toString() );
10872                 return false;
10873             }
10874             n.setName( "_AY695820_" );
10875             acc = SequenceDbWsTools.obtainSeqAccession( n );
10876             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10877                     || !acc.getValue().equals( "AY695820" ) ) {
10878                 System.out.println( acc.toString() );
10879                 return false;
10880             }
10881             n.setName( "AAA59452" );
10882             acc = SequenceDbWsTools.obtainSeqAccession( n );
10883             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10884                     || !acc.getValue().equals( "AAA59452" ) ) {
10885                 System.out.println( acc.toString() );
10886                 return false;
10887             }
10888             n.setName( "_AAA59452_" );
10889             acc = SequenceDbWsTools.obtainSeqAccession( n );
10890             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10891                     || !acc.getValue().equals( "AAA59452" ) ) {
10892                 System.out.println( acc.toString() );
10893                 return false;
10894             }
10895             n.setName( "AAA59452.1" );
10896             acc = SequenceDbWsTools.obtainSeqAccession( n );
10897             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10898                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10899                 System.out.println( acc.toString() );
10900                 return false;
10901             }
10902             n.setName( "_AAA59452.1_" );
10903             acc = SequenceDbWsTools.obtainSeqAccession( n );
10904             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10905                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10906                 System.out.println( acc.toString() );
10907                 return false;
10908             }
10909             n.setName( "GI:94894583" );
10910             acc = SequenceDbWsTools.obtainSeqAccession( n );
10911             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10912                     || !acc.getValue().equals( "94894583" ) ) {
10913                 System.out.println( acc.toString() );
10914                 return false;
10915             }
10916             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10917             acc = SequenceDbWsTools.obtainSeqAccession( n );
10918             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10919                     || !acc.getValue().equals( "71845847" ) ) {
10920                 System.out.println( acc.toString() );
10921                 return false;
10922             }
10923             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10924             acc = SequenceDbWsTools.obtainSeqAccession( n );
10925             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10926                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
10927                 System.out.println( acc.toString() );
10928                 return false;
10929             }
10930         }
10931         catch ( final Exception e ) {
10932             return false;
10933         }
10934         return true;
10935     }
10936
10937     private static boolean testSequenceDbWsTools2() {
10938         try {
10939             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
10940             SequenceDbWsTools.obtainSeqInformation( n1 );
10941             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
10942                 return false;
10943             }
10944             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10945                 return false;
10946             }
10947             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10948                 return false;
10949             }
10950             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
10951                 return false;
10952             }
10953             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
10954             SequenceDbWsTools.obtainSeqInformation( n2 );
10955             if ( !n2.getNodeData().getSequence().getName()
10956                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
10957                 return false;
10958             }
10959             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10960                 return false;
10961             }
10962             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10963                 return false;
10964             }
10965             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
10966                 return false;
10967             }
10968             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
10969             SequenceDbWsTools.obtainSeqInformation( n3 );
10970             if ( !n3.getNodeData().getSequence().getName()
10971                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
10972                 return false;
10973             }
10974             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
10975                 return false;
10976             }
10977             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10978                 return false;
10979             }
10980             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
10981                 return false;
10982             }
10983         }
10984         catch ( final IOException e ) {
10985             System.out.println();
10986             System.out.println( "the following might be due to absence internet connection:" );
10987             e.printStackTrace( System.out );
10988             return true;
10989         }
10990         catch ( final Exception e ) {
10991             e.printStackTrace();
10992             return false;
10993         }
10994         return true;
10995     }
10996
10997     private static boolean testSequenceIdParsing() {
10998         try {
10999             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11000             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11001                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11002                 if ( id != null ) {
11003                     System.out.println( "value   =" + id.getValue() );
11004                     System.out.println( "provider=" + id.getSource() );
11005                 }
11006                 return false;
11007             }
11008             //
11009             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11010             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11011                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11012                 if ( id != null ) {
11013                     System.out.println( "value   =" + id.getValue() );
11014                     System.out.println( "provider=" + id.getSource() );
11015                 }
11016                 return false;
11017             }
11018             //
11019             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11020             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11021                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11022                 if ( id != null ) {
11023                     System.out.println( "value   =" + id.getValue() );
11024                     System.out.println( "provider=" + id.getSource() );
11025                 }
11026                 return false;
11027             }
11028             // 
11029             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11030             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11031                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11032                 if ( id != null ) {
11033                     System.out.println( "value   =" + id.getValue() );
11034                     System.out.println( "provider=" + id.getSource() );
11035                 }
11036                 return false;
11037             }
11038             // 
11039             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11040             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11041                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11042                 if ( id != null ) {
11043                     System.out.println( "value   =" + id.getValue() );
11044                     System.out.println( "provider=" + id.getSource() );
11045                 }
11046                 return false;
11047             }
11048             // 
11049             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11050             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11051                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11052                 if ( id != null ) {
11053                     System.out.println( "value   =" + id.getValue() );
11054                     System.out.println( "provider=" + id.getSource() );
11055                 }
11056                 return false;
11057             }
11058             // 
11059             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11060             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11061                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11062                 if ( id != null ) {
11063                     System.out.println( "value   =" + id.getValue() );
11064                     System.out.println( "provider=" + id.getSource() );
11065                 }
11066                 return false;
11067             }
11068             // 
11069             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11070             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11071                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11072                 if ( id != null ) {
11073                     System.out.println( "value   =" + id.getValue() );
11074                     System.out.println( "provider=" + id.getSource() );
11075                 }
11076                 return false;
11077             }
11078             // 
11079             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11080             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11081                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11082                 if ( id != null ) {
11083                     System.out.println( "value   =" + id.getValue() );
11084                     System.out.println( "provider=" + id.getSource() );
11085                 }
11086                 return false;
11087             }
11088             // 
11089             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11090             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11091                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11092                 if ( id != null ) {
11093                     System.out.println( "value   =" + id.getValue() );
11094                     System.out.println( "provider=" + id.getSource() );
11095                 }
11096                 return false;
11097             }
11098             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11099             if ( id != null ) {
11100                 System.out.println( "value   =" + id.getValue() );
11101                 System.out.println( "provider=" + id.getSource() );
11102                 return false;
11103             }
11104         }
11105         catch ( final Exception e ) {
11106             e.printStackTrace( System.out );
11107             return false;
11108         }
11109         return true;
11110     }
11111
11112     private static boolean testSequenceWriter() {
11113         try {
11114             final String n = ForesterUtil.LINE_SEPARATOR;
11115             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11116                 return false;
11117             }
11118             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11119                 return false;
11120             }
11121             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11122                 return false;
11123             }
11124             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11125                 return false;
11126             }
11127             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11128                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11129                 return false;
11130             }
11131             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11132                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11133                 return false;
11134             }
11135         }
11136         catch ( final Exception e ) {
11137             e.printStackTrace();
11138             return false;
11139         }
11140         return true;
11141     }
11142
11143     private static boolean testSpecies() {
11144         try {
11145             final Species s1 = new BasicSpecies( "a" );
11146             final Species s2 = new BasicSpecies( "a" );
11147             final Species s3 = new BasicSpecies( "A" );
11148             final Species s4 = new BasicSpecies( "b" );
11149             if ( !s1.equals( s1 ) ) {
11150                 return false;
11151             }
11152             if ( s1.getSpeciesId().equals( "x" ) ) {
11153                 return false;
11154             }
11155             if ( s1.getSpeciesId().equals( null ) ) {
11156                 return false;
11157             }
11158             if ( !s1.equals( s2 ) ) {
11159                 return false;
11160             }
11161             if ( s1.equals( s3 ) ) {
11162                 return false;
11163             }
11164             if ( s1.hashCode() != s1.hashCode() ) {
11165                 return false;
11166             }
11167             if ( s1.hashCode() != s2.hashCode() ) {
11168                 return false;
11169             }
11170             if ( s1.hashCode() == s3.hashCode() ) {
11171                 return false;
11172             }
11173             if ( s1.compareTo( s1 ) != 0 ) {
11174                 return false;
11175             }
11176             if ( s1.compareTo( s2 ) != 0 ) {
11177                 return false;
11178             }
11179             if ( s1.compareTo( s3 ) != 0 ) {
11180                 return false;
11181             }
11182             if ( s1.compareTo( s4 ) >= 0 ) {
11183                 return false;
11184             }
11185             if ( s4.compareTo( s1 ) <= 0 ) {
11186                 return false;
11187             }
11188             if ( !s4.getSpeciesId().equals( "b" ) ) {
11189                 return false;
11190             }
11191             final Species s5 = new BasicSpecies( " C " );
11192             if ( !s5.getSpeciesId().equals( "C" ) ) {
11193                 return false;
11194             }
11195             if ( s5.equals( s1 ) ) {
11196                 return false;
11197             }
11198         }
11199         catch ( final Exception e ) {
11200             e.printStackTrace( System.out );
11201             return false;
11202         }
11203         return true;
11204     }
11205
11206     private static boolean testSplit() {
11207         try {
11208             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11209             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11210             //Archaeopteryx.createApplication( p0 );
11211             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11212             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11213             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11214             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11215             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11216             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11217             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11218             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11219             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11220             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11221             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11222             // System.out.println( s0.toString() );
11223             //
11224             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11225             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11226             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11227             if ( s0.match( query_nodes ) ) {
11228                 return false;
11229             }
11230             query_nodes = new HashSet<PhylogenyNode>();
11231             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11232             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11233             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11234             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11235             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11236             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11237             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11238             if ( !s0.match( query_nodes ) ) {
11239                 return false;
11240             }
11241             //
11242             query_nodes = new HashSet<PhylogenyNode>();
11243             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11244             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11245             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11246             if ( !s0.match( query_nodes ) ) {
11247                 return false;
11248             }
11249             //
11250             query_nodes = new HashSet<PhylogenyNode>();
11251             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11252             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11253             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11254             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11255             if ( !s0.match( query_nodes ) ) {
11256                 return false;
11257             }
11258             //
11259             query_nodes = new HashSet<PhylogenyNode>();
11260             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11261             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11262             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11263             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11264             if ( !s0.match( query_nodes ) ) {
11265                 return false;
11266             }
11267             //
11268             query_nodes = new HashSet<PhylogenyNode>();
11269             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11270             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11271             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11272             if ( !s0.match( query_nodes ) ) {
11273                 return false;
11274             }
11275             //
11276             query_nodes = new HashSet<PhylogenyNode>();
11277             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11278             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11279             if ( !s0.match( query_nodes ) ) {
11280                 return false;
11281             }
11282             //
11283             query_nodes = new HashSet<PhylogenyNode>();
11284             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11285             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11286             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11287             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11288             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11289             if ( !s0.match( query_nodes ) ) {
11290                 return false;
11291             }
11292             //
11293             query_nodes = new HashSet<PhylogenyNode>();
11294             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11295             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11296             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11297             if ( !s0.match( query_nodes ) ) {
11298                 return false;
11299             }
11300             //
11301             query_nodes = new HashSet<PhylogenyNode>();
11302             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11303             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11304             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11305             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11306             if ( !s0.match( query_nodes ) ) {
11307                 return false;
11308             }
11309             //
11310             query_nodes = new HashSet<PhylogenyNode>();
11311             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11312             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11313             if ( s0.match( query_nodes ) ) {
11314                 return false;
11315             }
11316             //
11317             query_nodes = new HashSet<PhylogenyNode>();
11318             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11319             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11320             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11321             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11322             if ( s0.match( query_nodes ) ) {
11323                 return false;
11324             }
11325             //
11326             query_nodes = new HashSet<PhylogenyNode>();
11327             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11328             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11329             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11330             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11331             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11332             if ( s0.match( query_nodes ) ) {
11333                 return false;
11334             }
11335             //
11336             query_nodes = new HashSet<PhylogenyNode>();
11337             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11338             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11339             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11340             if ( s0.match( query_nodes ) ) {
11341                 return false;
11342             }
11343             //
11344             query_nodes = new HashSet<PhylogenyNode>();
11345             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11346             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11347             if ( s0.match( query_nodes ) ) {
11348                 return false;
11349             }
11350             //
11351             query_nodes = new HashSet<PhylogenyNode>();
11352             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11353             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11354             if ( s0.match( query_nodes ) ) {
11355                 return false;
11356             }
11357             //
11358             query_nodes = new HashSet<PhylogenyNode>();
11359             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11360             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11361             if ( s0.match( query_nodes ) ) {
11362                 return false;
11363             }
11364             //
11365             query_nodes = new HashSet<PhylogenyNode>();
11366             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11367             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11368             if ( s0.match( query_nodes ) ) {
11369                 return false;
11370             }
11371             //
11372             query_nodes = new HashSet<PhylogenyNode>();
11373             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11374             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11375             if ( s0.match( query_nodes ) ) {
11376                 return false;
11377             }
11378             //
11379             query_nodes = new HashSet<PhylogenyNode>();
11380             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11381             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11382             if ( s0.match( query_nodes ) ) {
11383                 return false;
11384             }
11385             //
11386             query_nodes = new HashSet<PhylogenyNode>();
11387             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11388             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11389             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11390             if ( s0.match( query_nodes ) ) {
11391                 return false;
11392             }
11393             //
11394             query_nodes = new HashSet<PhylogenyNode>();
11395             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11396             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11397             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11398             if ( s0.match( query_nodes ) ) {
11399                 return false;
11400             }
11401             //
11402             query_nodes = new HashSet<PhylogenyNode>();
11403             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11404             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11405             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11406             if ( s0.match( query_nodes ) ) {
11407                 return false;
11408             }
11409             //
11410             query_nodes = new HashSet<PhylogenyNode>();
11411             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11412             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11413             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11414             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11415             if ( s0.match( query_nodes ) ) {
11416                 return false;
11417             }
11418             /////////
11419             //            query_nodes = new HashSet<PhylogenyNode>();
11420             //            query_nodes.add( new PhylogenyNode( "X" ) );
11421             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11422             //            query_nodes.add( new PhylogenyNode( "A" ) );
11423             //            query_nodes.add( new PhylogenyNode( "B" ) );
11424             //            query_nodes.add( new PhylogenyNode( "C" ) );
11425             //            query_nodes.add( new PhylogenyNode( "D" ) );
11426             //            query_nodes.add( new PhylogenyNode( "E" ) );
11427             //            query_nodes.add( new PhylogenyNode( "F" ) );
11428             //            query_nodes.add( new PhylogenyNode( "G" ) );
11429             //            if ( !s0.match( query_nodes ) ) {
11430             //                return false;
11431             //            }
11432             //            query_nodes = new HashSet<PhylogenyNode>();
11433             //            query_nodes.add( new PhylogenyNode( "X" ) );
11434             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11435             //            query_nodes.add( new PhylogenyNode( "A" ) );
11436             //            query_nodes.add( new PhylogenyNode( "B" ) );
11437             //            query_nodes.add( new PhylogenyNode( "C" ) );
11438             //            if ( !s0.match( query_nodes ) ) {
11439             //                return false;
11440             //            }
11441             //            //
11442             //            query_nodes = new HashSet<PhylogenyNode>();
11443             //            query_nodes.add( new PhylogenyNode( "X" ) );
11444             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11445             //            query_nodes.add( new PhylogenyNode( "D" ) );
11446             //            query_nodes.add( new PhylogenyNode( "E" ) );
11447             //            query_nodes.add( new PhylogenyNode( "F" ) );
11448             //            query_nodes.add( new PhylogenyNode( "G" ) );
11449             //            if ( !s0.match( query_nodes ) ) {
11450             //                return false;
11451             //            }
11452             //            //
11453             //            query_nodes = new HashSet<PhylogenyNode>();
11454             //            query_nodes.add( new PhylogenyNode( "X" ) );
11455             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11456             //            query_nodes.add( new PhylogenyNode( "A" ) );
11457             //            query_nodes.add( new PhylogenyNode( "B" ) );
11458             //            query_nodes.add( new PhylogenyNode( "C" ) );
11459             //            query_nodes.add( new PhylogenyNode( "D" ) );
11460             //            if ( !s0.match( query_nodes ) ) {
11461             //                return false;
11462             //            }
11463             //            //
11464             //            query_nodes = new HashSet<PhylogenyNode>();
11465             //            query_nodes.add( new PhylogenyNode( "X" ) );
11466             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11467             //            query_nodes.add( new PhylogenyNode( "E" ) );
11468             //            query_nodes.add( new PhylogenyNode( "F" ) );
11469             //            query_nodes.add( new PhylogenyNode( "G" ) );
11470             //            if ( !s0.match( query_nodes ) ) {
11471             //                return false;
11472             //            }
11473             //            //
11474             //            query_nodes = new HashSet<PhylogenyNode>();
11475             //            query_nodes.add( new PhylogenyNode( "X" ) );
11476             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11477             //            query_nodes.add( new PhylogenyNode( "F" ) );
11478             //            query_nodes.add( new PhylogenyNode( "G" ) );
11479             //            if ( !s0.match( query_nodes ) ) {
11480             //                return false;
11481             //            }
11482             //
11483             query_nodes = new HashSet<PhylogenyNode>();
11484             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11485             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11486             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11487             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11488             if ( s0.match( query_nodes ) ) {
11489                 return false;
11490             }
11491             //
11492             query_nodes = new HashSet<PhylogenyNode>();
11493             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11494             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11495             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11496             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11497             if ( s0.match( query_nodes ) ) {
11498                 return false;
11499             }
11500             ///////////////////////////
11501             //
11502             query_nodes = new HashSet<PhylogenyNode>();
11503             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11504             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11505             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11506             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11507             if ( s0.match( query_nodes ) ) {
11508                 return false;
11509             }
11510             //
11511             query_nodes = new HashSet<PhylogenyNode>();
11512             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11513             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11514             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11515             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11516             if ( s0.match( query_nodes ) ) {
11517                 return false;
11518             }
11519             //
11520             query_nodes = new HashSet<PhylogenyNode>();
11521             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11522             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11523             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11524             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11525             if ( s0.match( query_nodes ) ) {
11526                 return false;
11527             }
11528             //
11529             query_nodes = new HashSet<PhylogenyNode>();
11530             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11531             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11532             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11533             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11534             if ( s0.match( query_nodes ) ) {
11535                 return false;
11536             }
11537             //
11538             query_nodes = new HashSet<PhylogenyNode>();
11539             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11540             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11541             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11542             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11543             if ( s0.match( query_nodes ) ) {
11544                 return false;
11545             }
11546             //
11547             query_nodes = new HashSet<PhylogenyNode>();
11548             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11549             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11550             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11551             if ( s0.match( query_nodes ) ) {
11552                 return false;
11553             }
11554             //
11555             query_nodes = new HashSet<PhylogenyNode>();
11556             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11557             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11558             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11559             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11560             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11561             if ( s0.match( query_nodes ) ) {
11562                 return false;
11563             }
11564             //
11565             query_nodes = new HashSet<PhylogenyNode>();
11566             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11567             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11568             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11569             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11570             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11571             if ( s0.match( query_nodes ) ) {
11572                 return false;
11573             }
11574             //
11575             query_nodes = new HashSet<PhylogenyNode>();
11576             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11577             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11578             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11579             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11580             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11581             if ( s0.match( query_nodes ) ) {
11582                 return false;
11583             }
11584             //
11585             query_nodes = new HashSet<PhylogenyNode>();
11586             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11587             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11589             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11590             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11591             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11592             if ( s0.match( query_nodes ) ) {
11593                 return false;
11594             }
11595         }
11596         catch ( final Exception e ) {
11597             e.printStackTrace();
11598             return false;
11599         }
11600         return true;
11601     }
11602
11603     private static boolean testSplitStrict() {
11604         try {
11605             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11606             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11607             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11608             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11609             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11610             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11611             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11612             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11613             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11614             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11615             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11616             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11617             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11618             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11619             if ( s0.match( query_nodes ) ) {
11620                 return false;
11621             }
11622             query_nodes = new HashSet<PhylogenyNode>();
11623             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11624             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11625             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11626             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11627             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11628             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11629             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11630             if ( !s0.match( query_nodes ) ) {
11631                 return false;
11632             }
11633             //
11634             query_nodes = new HashSet<PhylogenyNode>();
11635             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11636             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11637             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11638             if ( !s0.match( query_nodes ) ) {
11639                 return false;
11640             }
11641             //
11642             query_nodes = new HashSet<PhylogenyNode>();
11643             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11644             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11645             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11646             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11647             if ( !s0.match( query_nodes ) ) {
11648                 return false;
11649             }
11650             //
11651             query_nodes = new HashSet<PhylogenyNode>();
11652             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11653             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11654             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11655             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11656             if ( !s0.match( query_nodes ) ) {
11657                 return false;
11658             }
11659             //
11660             query_nodes = new HashSet<PhylogenyNode>();
11661             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11662             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11663             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11664             if ( !s0.match( query_nodes ) ) {
11665                 return false;
11666             }
11667             //
11668             query_nodes = new HashSet<PhylogenyNode>();
11669             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11670             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11671             if ( !s0.match( query_nodes ) ) {
11672                 return false;
11673             }
11674             //
11675             query_nodes = new HashSet<PhylogenyNode>();
11676             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11677             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11678             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11679             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11680             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11681             if ( !s0.match( query_nodes ) ) {
11682                 return false;
11683             }
11684             //
11685             query_nodes = new HashSet<PhylogenyNode>();
11686             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11688             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11689             if ( !s0.match( query_nodes ) ) {
11690                 return false;
11691             }
11692             //
11693             query_nodes = new HashSet<PhylogenyNode>();
11694             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11695             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11696             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11697             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11698             if ( !s0.match( query_nodes ) ) {
11699                 return false;
11700             }
11701             //
11702             query_nodes = new HashSet<PhylogenyNode>();
11703             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11704             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11705             if ( s0.match( query_nodes ) ) {
11706                 return false;
11707             }
11708             //
11709             query_nodes = new HashSet<PhylogenyNode>();
11710             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11711             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11712             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11713             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11714             if ( s0.match( query_nodes ) ) {
11715                 return false;
11716             }
11717             //
11718             query_nodes = new HashSet<PhylogenyNode>();
11719             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11720             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11721             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11724             if ( s0.match( query_nodes ) ) {
11725                 return false;
11726             }
11727             //
11728             query_nodes = new HashSet<PhylogenyNode>();
11729             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11730             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11731             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11732             if ( s0.match( query_nodes ) ) {
11733                 return false;
11734             }
11735             //
11736             query_nodes = new HashSet<PhylogenyNode>();
11737             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11738             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11739             if ( s0.match( query_nodes ) ) {
11740                 return false;
11741             }
11742             //
11743             query_nodes = new HashSet<PhylogenyNode>();
11744             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11745             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
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( "C" ) );
11753             if ( s0.match( query_nodes ) ) {
11754                 return false;
11755             }
11756             //
11757             query_nodes = new HashSet<PhylogenyNode>();
11758             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11759             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11760             if ( s0.match( query_nodes ) ) {
11761                 return false;
11762             }
11763             //
11764             query_nodes = new HashSet<PhylogenyNode>();
11765             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11766             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11767             if ( s0.match( query_nodes ) ) {
11768                 return false;
11769             }
11770             //
11771             query_nodes = new HashSet<PhylogenyNode>();
11772             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11773             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11774             if ( s0.match( query_nodes ) ) {
11775                 return false;
11776             }
11777             //
11778             query_nodes = new HashSet<PhylogenyNode>();
11779             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11780             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11781             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11782             if ( s0.match( query_nodes ) ) {
11783                 return false;
11784             }
11785             //
11786             query_nodes = new HashSet<PhylogenyNode>();
11787             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11788             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11789             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11790             if ( s0.match( query_nodes ) ) {
11791                 return false;
11792             }
11793             //
11794             query_nodes = new HashSet<PhylogenyNode>();
11795             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11796             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11797             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11798             if ( s0.match( query_nodes ) ) {
11799                 return false;
11800             }
11801             //
11802             query_nodes = new HashSet<PhylogenyNode>();
11803             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11804             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11805             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11806             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11807             if ( s0.match( query_nodes ) ) {
11808                 return false;
11809             }
11810         }
11811         catch ( final Exception e ) {
11812             e.printStackTrace();
11813             return false;
11814         }
11815         return true;
11816     }
11817
11818     private static boolean testSubtreeDeletion() {
11819         try {
11820             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11821             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11822             t1.deleteSubtree( t1.getNode( "A" ), false );
11823             if ( t1.getNumberOfExternalNodes() != 5 ) {
11824                 return false;
11825             }
11826             t1.toNewHampshireX();
11827             t1.deleteSubtree( t1.getNode( "E" ), false );
11828             if ( t1.getNumberOfExternalNodes() != 4 ) {
11829                 return false;
11830             }
11831             t1.toNewHampshireX();
11832             t1.deleteSubtree( t1.getNode( "F" ), false );
11833             if ( t1.getNumberOfExternalNodes() != 3 ) {
11834                 return false;
11835             }
11836             t1.toNewHampshireX();
11837             t1.deleteSubtree( t1.getNode( "D" ), false );
11838             t1.toNewHampshireX();
11839             if ( t1.getNumberOfExternalNodes() != 3 ) {
11840                 return false;
11841             }
11842             t1.deleteSubtree( t1.getNode( "def" ), false );
11843             t1.toNewHampshireX();
11844             if ( t1.getNumberOfExternalNodes() != 2 ) {
11845                 return false;
11846             }
11847             t1.deleteSubtree( t1.getNode( "B" ), false );
11848             t1.toNewHampshireX();
11849             if ( t1.getNumberOfExternalNodes() != 1 ) {
11850                 return false;
11851             }
11852             t1.deleteSubtree( t1.getNode( "C" ), false );
11853             t1.toNewHampshireX();
11854             if ( t1.getNumberOfExternalNodes() != 1 ) {
11855                 return false;
11856             }
11857             t1.deleteSubtree( t1.getNode( "abc" ), false );
11858             t1.toNewHampshireX();
11859             if ( t1.getNumberOfExternalNodes() != 1 ) {
11860                 return false;
11861             }
11862             t1.deleteSubtree( t1.getNode( "r" ), false );
11863             if ( t1.getNumberOfExternalNodes() != 0 ) {
11864                 return false;
11865             }
11866             if ( !t1.isEmpty() ) {
11867                 return false;
11868             }
11869             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11870             t2.deleteSubtree( t2.getNode( "A" ), false );
11871             t2.toNewHampshireX();
11872             if ( t2.getNumberOfExternalNodes() != 5 ) {
11873                 return false;
11874             }
11875             t2.deleteSubtree( t2.getNode( "abc" ), false );
11876             t2.toNewHampshireX();
11877             if ( t2.getNumberOfExternalNodes() != 3 ) {
11878                 return false;
11879             }
11880             t2.deleteSubtree( t2.getNode( "def" ), false );
11881             t2.toNewHampshireX();
11882             if ( t2.getNumberOfExternalNodes() != 1 ) {
11883                 return false;
11884             }
11885         }
11886         catch ( final Exception e ) {
11887             e.printStackTrace( System.out );
11888             return false;
11889         }
11890         return true;
11891     }
11892
11893     private static boolean testSupportCount() {
11894         try {
11895             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11896             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
11897             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
11898                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
11899                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
11900                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
11901                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
11902                                                               new NHXParser() );
11903             SupportCount.count( t0_1, phylogenies_1, true, false );
11904             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
11905             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
11906                                                                       + "(((((A,B),C),D),E),((F,G),X))"
11907                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
11908                                                                       + "(((((A,B),C),D),E),(F,G))"
11909                                                                       + "(((((A,B),C),D),E),(F,G))"
11910                                                                       + "(((((A,B),C),D),E),(F,G))"
11911                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
11912                                                                       + "(((((A,B),C),D),E),(F,G))"
11913                                                                       + "((((((A,B),C),D),E),F),G)"
11914                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
11915                                                               new NHXParser() );
11916             SupportCount.count( t0_2, phylogenies_2, true, false );
11917             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
11918             while ( it.hasNext() ) {
11919                 final PhylogenyNode n = it.next();
11920                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
11921                     return false;
11922                 }
11923             }
11924             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
11925             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
11926                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
11927             SupportCount.count( t0_3, phylogenies_3, true, false );
11928             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
11929             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
11930                 return false;
11931             }
11932             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
11933                 return false;
11934             }
11935             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
11936                 return false;
11937             }
11938             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
11939                 return false;
11940             }
11941             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
11942                 return false;
11943             }
11944             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
11945                 return false;
11946             }
11947             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
11948                 return false;
11949             }
11950             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
11951                 return false;
11952             }
11953             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
11954                 return false;
11955             }
11956             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
11957                 return false;
11958             }
11959             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11960             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
11961                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
11962             SupportCount.count( t0_4, phylogenies_4, true, false );
11963             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
11964             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
11965                 return false;
11966             }
11967             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
11968                 return false;
11969             }
11970             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
11971                 return false;
11972             }
11973             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
11974                 return false;
11975             }
11976             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
11977                 return false;
11978             }
11979             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
11980                 return false;
11981             }
11982             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
11983                 return false;
11984             }
11985             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
11986                 return false;
11987             }
11988             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
11989                 return false;
11990             }
11991             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
11992                 return false;
11993             }
11994             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11995             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11996             double d = SupportCount.compare( b1, a, true, true, true );
11997             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
11998                 return false;
11999             }
12000             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12001             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12002             d = SupportCount.compare( b2, a, true, true, true );
12003             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12004                 return false;
12005             }
12006             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12007             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12008             d = SupportCount.compare( b3, a, true, true, true );
12009             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12010                 return false;
12011             }
12012             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12013             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12014             d = SupportCount.compare( b4, a, true, true, false );
12015             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12016                 return false;
12017             }
12018         }
12019         catch ( final Exception e ) {
12020             e.printStackTrace( System.out );
12021             return false;
12022         }
12023         return true;
12024     }
12025
12026     private static boolean testSupportTransfer() {
12027         try {
12028             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12029             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)",
12030                                                  new NHXParser() )[ 0 ];
12031             final Phylogeny p2 = factory
12032                     .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 ];
12033             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12034                 return false;
12035             }
12036             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12037                 return false;
12038             }
12039             support_transfer.moveBranchLengthsToBootstrap( p1 );
12040             support_transfer.transferSupportValues( p1, p2 );
12041             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12042                 return false;
12043             }
12044             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12045                 return false;
12046             }
12047             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12048                 return false;
12049             }
12050             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12051                 return false;
12052             }
12053             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12054                 return false;
12055             }
12056             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12057                 return false;
12058             }
12059             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12060                 return false;
12061             }
12062             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12063                 return false;
12064             }
12065         }
12066         catch ( final Exception e ) {
12067             e.printStackTrace( System.out );
12068             return false;
12069         }
12070         return true;
12071     }
12072
12073     private static boolean testTaxonomyExtraction() {
12074         try {
12075             final PhylogenyNode n0 = PhylogenyNode
12076                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12077             if ( n0.getNodeData().isHasTaxonomy() ) {
12078                 return false;
12079             }
12080             final PhylogenyNode n1 = PhylogenyNode
12081                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12082             if ( n1.getNodeData().isHasTaxonomy() ) {
12083                 System.out.println( n1.toString() );
12084                 return false;
12085             }
12086             final PhylogenyNode n2x = PhylogenyNode
12087                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12088             if ( n2x.getNodeData().isHasTaxonomy() ) {
12089                 return false;
12090             }
12091             final PhylogenyNode n3 = PhylogenyNode
12092                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12093             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12094                 System.out.println( n3.toString() );
12095                 return false;
12096             }
12097             final PhylogenyNode n4 = PhylogenyNode
12098                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12099             if ( n4.getNodeData().isHasTaxonomy() ) {
12100                 System.out.println( n4.toString() );
12101                 return false;
12102             }
12103             final PhylogenyNode n5 = PhylogenyNode
12104                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12105             if ( n5.getNodeData().isHasTaxonomy() ) {
12106                 System.out.println( n5.toString() );
12107                 return false;
12108             }
12109             final PhylogenyNode n6 = PhylogenyNode
12110                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12111             if ( n6.getNodeData().isHasTaxonomy() ) {
12112                 System.out.println( n6.toString() );
12113                 return false;
12114             }
12115             final PhylogenyNode n7 = PhylogenyNode
12116                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12117             if ( n7.getNodeData().isHasTaxonomy() ) {
12118                 System.out.println( n7.toString() );
12119                 return false;
12120             }
12121             final PhylogenyNode n8 = PhylogenyNode
12122                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12123             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12124                 System.out.println( n8.toString() );
12125                 return false;
12126             }
12127             final PhylogenyNode n9 = PhylogenyNode
12128                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12129             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12130                 System.out.println( n9.toString() );
12131                 return false;
12132             }
12133             final PhylogenyNode n10x = PhylogenyNode
12134                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12135             if ( n10x.getNodeData().isHasTaxonomy() ) {
12136                 System.out.println( n10x.toString() );
12137                 return false;
12138             }
12139             final PhylogenyNode n10xx = PhylogenyNode
12140                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12141             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12142                 System.out.println( n10xx.toString() );
12143                 return false;
12144             }
12145             final PhylogenyNode n10 = PhylogenyNode
12146                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12147             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12148                 System.out.println( n10.toString() );
12149                 return false;
12150             }
12151             final PhylogenyNode n11 = PhylogenyNode
12152                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12153             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12154                 System.out.println( n11.toString() );
12155                 return false;
12156             }
12157             final PhylogenyNode n12 = PhylogenyNode
12158                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12159                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12160             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12161                 System.out.println( n12.toString() );
12162                 return false;
12163             }
12164             final PhylogenyNode n13 = PhylogenyNode
12165                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12166             if ( n13.getNodeData().isHasTaxonomy() ) {
12167                 System.out.println( n13.toString() );
12168                 return false;
12169             }
12170             final PhylogenyNode n14 = PhylogenyNode
12171                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12172             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12173                 System.out.println( n14.toString() );
12174                 return false;
12175             }
12176             final PhylogenyNode n15 = PhylogenyNode
12177                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12178             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12179                 System.out.println( n15.toString() );
12180                 return false;
12181             }
12182             final PhylogenyNode n16 = PhylogenyNode
12183                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12184             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12185                 System.out.println( n16.toString() );
12186                 return false;
12187             }
12188             final PhylogenyNode n17 = PhylogenyNode
12189                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12190             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12191                 System.out.println( n17.toString() );
12192                 return false;
12193             }
12194             //
12195             final PhylogenyNode n18 = PhylogenyNode
12196                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12197             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12198                 System.out.println( n18.toString() );
12199                 return false;
12200             }
12201             final PhylogenyNode n19 = PhylogenyNode
12202                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12203                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12204             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12205                 System.out.println( n19.toString() );
12206                 return false;
12207             }
12208             final PhylogenyNode n20 = PhylogenyNode
12209                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12210             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12211                 System.out.println( n20.toString() );
12212                 return false;
12213             }
12214             final PhylogenyNode n21 = PhylogenyNode
12215                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12216                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12217             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12218                 System.out.println( n21.toString() );
12219                 return false;
12220             }
12221             final PhylogenyNode n22 = PhylogenyNode
12222                     .createInstanceFromNhxString( "NEMVE_Nematostella_vectensis",
12223                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12224             if ( !n22.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12225                 System.out.println( n22.toString() );
12226                 return false;
12227             }
12228             final PhylogenyNode n23 = PhylogenyNode
12229                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12230                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12231             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12232                 System.out.println( n23.toString() );
12233                 return false;
12234             }
12235             final PhylogenyNode n24 = PhylogenyNode
12236                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12237             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12238                 System.out.println( n24.toString() );
12239                 return false;
12240             }
12241             //
12242             final PhylogenyNode n25 = PhylogenyNode
12243                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12244                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12245             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12246                 System.out.println( n25.toString() );
12247                 return false;
12248             }
12249             final PhylogenyNode n26 = PhylogenyNode
12250                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12251                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12252             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12253                 System.out.println( n26.toString() );
12254                 return false;
12255             }
12256             final PhylogenyNode n27 = PhylogenyNode
12257                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12258             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12259                 System.out.println( n27.toString() );
12260                 return false;
12261             }
12262         }
12263         catch ( final Exception e ) {
12264             e.printStackTrace( System.out );
12265             return false;
12266         }
12267         return true;
12268     }
12269
12270     private static boolean testTreeCopy() {
12271         try {
12272             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12273             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12274             final Phylogeny t1 = t0.copy();
12275             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12276                 return false;
12277             }
12278             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12279                 return false;
12280             }
12281             t0.deleteSubtree( t0.getNode( "c" ), true );
12282             t0.deleteSubtree( t0.getNode( "a" ), true );
12283             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12284             t0.getNode( "b" ).setName( "Bee" );
12285             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12286                 return false;
12287             }
12288             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12289                 return false;
12290             }
12291             t0.deleteSubtree( t0.getNode( "e" ), true );
12292             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12293             t0.deleteSubtree( t0.getNode( "d" ), true );
12294             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12295                 return false;
12296             }
12297         }
12298         catch ( final Exception e ) {
12299             e.printStackTrace();
12300             return false;
12301         }
12302         return true;
12303     }
12304
12305     private static boolean testTreeMethods() {
12306         try {
12307             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12308             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12309             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12310             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12311                 System.out.println( t0.toNewHampshireX() );
12312                 return false;
12313             }
12314             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12315             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12316             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12317                 return false;
12318             }
12319             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12320                 return false;
12321             }
12322             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12323                 return false;
12324             }
12325         }
12326         catch ( final Exception e ) {
12327             e.printStackTrace( System.out );
12328             return false;
12329         }
12330         return true;
12331     }
12332
12333     private static boolean testUniprotEntryRetrieval() {
12334         try {
12335             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
12336             if ( !entry.getAccession().equals( "P12345" ) ) {
12337                 return false;
12338             }
12339             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12340                 return false;
12341             }
12342             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12343                 return false;
12344             }
12345             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12346                 return false;
12347             }
12348             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12349                 return false;
12350             }
12351             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12352                 return false;
12353             }
12354         }
12355         catch ( final IOException e ) {
12356             System.out.println();
12357             System.out.println( "the following might be due to absence internet connection:" );
12358             e.printStackTrace( System.out );
12359             return true;
12360         }
12361         catch ( final Exception e ) {
12362             return false;
12363         }
12364         return true;
12365     }
12366
12367     private static boolean testUniprotTaxonomySearch() {
12368         try {
12369             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12370                                                                                                  10 );
12371             if ( results.size() != 1 ) {
12372                 return false;
12373             }
12374             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12375                 return false;
12376             }
12377             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12378                 return false;
12379             }
12380             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12381                 return false;
12382             }
12383             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12384                 return false;
12385             }
12386             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12387                 return false;
12388             }
12389             results = null;
12390             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12391             if ( results.size() != 1 ) {
12392                 return false;
12393             }
12394             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12395                 return false;
12396             }
12397             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12398                 return false;
12399             }
12400             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12401                 return false;
12402             }
12403             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12404                 return false;
12405             }
12406             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12407                 return false;
12408             }
12409             results = null;
12410             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12411             if ( results.size() != 1 ) {
12412                 return false;
12413             }
12414             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12415                 return false;
12416             }
12417             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12418                 return false;
12419             }
12420             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12421                 return false;
12422             }
12423             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12424                 return false;
12425             }
12426             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12427                 return false;
12428             }
12429             results = null;
12430             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12431             if ( results.size() != 1 ) {
12432                 return false;
12433             }
12434             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12435                 return false;
12436             }
12437             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12438                 return false;
12439             }
12440             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12441                 return false;
12442             }
12443             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12444                 return false;
12445             }
12446             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12447                 return false;
12448             }
12449             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12450                 return false;
12451             }
12452             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12453                 return false;
12454             }
12455             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12456                     .equals( "Nematostella vectensis" ) ) {
12457                 System.out.println( results.get( 0 ).getLineage() );
12458                 return false;
12459             }
12460             //
12461             results = null;
12462             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12463             if ( results.size() != 1 ) {
12464                 return false;
12465             }
12466             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12467                 return false;
12468             }
12469             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12470                 return false;
12471             }
12472             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12473                 return false;
12474             }
12475             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12476                 return false;
12477             }
12478             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12479                 return false;
12480             }
12481             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12482                     .equals( "Xenopus tropicalis" ) ) {
12483                 System.out.println( results.get( 0 ).getLineage() );
12484                 return false;
12485             }
12486             //
12487             results = null;
12488             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12489             if ( results.size() != 1 ) {
12490                 return false;
12491             }
12492             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12493                 return false;
12494             }
12495             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12496                 return false;
12497             }
12498             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12499                 return false;
12500             }
12501             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12502                 return false;
12503             }
12504             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12505                 return false;
12506             }
12507             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12508                     .equals( "Xenopus tropicalis" ) ) {
12509                 System.out.println( results.get( 0 ).getLineage() );
12510                 return false;
12511             }
12512             //
12513             results = null;
12514             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12515             if ( results.size() != 1 ) {
12516                 return false;
12517             }
12518             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12519                 return false;
12520             }
12521             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12522                 return false;
12523             }
12524             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12525                 return false;
12526             }
12527             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12528                 return false;
12529             }
12530             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12531                 return false;
12532             }
12533             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12534                     .equals( "Xenopus tropicalis" ) ) {
12535                 System.out.println( results.get( 0 ).getLineage() );
12536                 return false;
12537             }
12538         }
12539         catch ( final IOException e ) {
12540             System.out.println();
12541             System.out.println( "the following might be due to absence internet connection:" );
12542             e.printStackTrace( System.out );
12543             return true;
12544         }
12545         catch ( final Exception e ) {
12546             return false;
12547         }
12548         return true;
12549     }
12550
12551     private static boolean testWabiTxSearch() {
12552         try {
12553             String result = "";
12554             result = TxSearch.searchSimple( "nematostella" );
12555             result = TxSearch.getTxId( "nematostella" );
12556             if ( !result.equals( "45350" ) ) {
12557                 return false;
12558             }
12559             result = TxSearch.getTxName( "45350" );
12560             if ( !result.equals( "Nematostella" ) ) {
12561                 return false;
12562             }
12563             result = TxSearch.getTxId( "nematostella vectensis" );
12564             if ( !result.equals( "45351" ) ) {
12565                 return false;
12566             }
12567             result = TxSearch.getTxName( "45351" );
12568             if ( !result.equals( "Nematostella vectensis" ) ) {
12569                 return false;
12570             }
12571             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
12572             if ( !result.equals( "536089" ) ) {
12573                 return false;
12574             }
12575             result = TxSearch.getTxName( "536089" );
12576             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
12577                 return false;
12578             }
12579             final List<String> queries = new ArrayList<String>();
12580             queries.add( "Campylobacter coli" );
12581             queries.add( "Escherichia coli" );
12582             queries.add( "Arabidopsis" );
12583             queries.add( "Trichoplax" );
12584             queries.add( "Samanea saman" );
12585             queries.add( "Kluyveromyces marxianus" );
12586             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
12587             queries.add( "Bornavirus parrot/PDD/2008" );
12588             final List<RANKS> ranks = new ArrayList<RANKS>();
12589             ranks.add( RANKS.SUPERKINGDOM );
12590             ranks.add( RANKS.KINGDOM );
12591             ranks.add( RANKS.FAMILY );
12592             ranks.add( RANKS.GENUS );
12593             ranks.add( RANKS.TRIBE );
12594             result = TxSearch.searchLineage( queries, ranks );
12595             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12596             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12597         }
12598         catch ( final Exception e ) {
12599             System.out.println();
12600             System.out.println( "the following might be due to absence internet connection:" );
12601             e.printStackTrace( System.out );
12602             return false;
12603         }
12604         return true;
12605     }
12606 }