in progress...
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24
25 package org.forester.test;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.StringWriter;
32 import java.io.Writer;
33 import java.net.URL;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.HashSet;
37 import java.util.Iterator;
38 import java.util.List;
39 import java.util.Locale;
40 import java.util.Set;
41 import java.util.SortedSet;
42
43 import org.forester.application.support_transfer;
44 import org.forester.archaeopteryx.AptxUtil;
45 import org.forester.archaeopteryx.TreePanelUtil;
46 import org.forester.archaeopteryx.webservices.WebserviceUtil;
47 import org.forester.clade_analysis.CladeAnalysisTest;
48 import org.forester.development.DevelopmentTools;
49 import org.forester.evoinference.TestPhylogenyReconstruction;
50 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
51 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
52 import org.forester.go.TestGo;
53 import org.forester.io.parsers.FastaParser;
54 import org.forester.io.parsers.GeneralMsaParser;
55 import org.forester.io.parsers.HmmscanPerDomainTableParser;
56 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
57 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
58 import org.forester.io.parsers.nexus.NexusCharactersParser;
59 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
60 import org.forester.io.parsers.nhx.NHXParser;
61 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
62 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
63 import org.forester.io.parsers.tol.TolParser;
64 import org.forester.io.parsers.util.ParserUtils;
65 import org.forester.io.writers.PhylogenyWriter;
66 import org.forester.io.writers.SequenceWriter;
67 import org.forester.msa.BasicMsa;
68 import org.forester.msa.DeleteableMsa;
69 import org.forester.msa.Mafft;
70 import org.forester.msa.Msa;
71 import org.forester.msa.Msa.MSA_FORMAT;
72 import org.forester.msa.MsaInferrer;
73 import org.forester.msa.MsaMethods;
74 import org.forester.pccx.TestPccx;
75 import org.forester.phylogeny.Phylogeny;
76 import org.forester.phylogeny.PhylogenyBranch;
77 import org.forester.phylogeny.PhylogenyMethods;
78 import org.forester.phylogeny.PhylogenyNode;
79 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
80 import org.forester.phylogeny.data.Accession;
81 import org.forester.phylogeny.data.Accession.Source;
82 import org.forester.phylogeny.data.BinaryCharacters;
83 import org.forester.phylogeny.data.BranchWidth;
84 import org.forester.phylogeny.data.Confidence;
85 import org.forester.phylogeny.data.Distribution;
86 import org.forester.phylogeny.data.DomainArchitecture;
87 import org.forester.phylogeny.data.Event;
88 import org.forester.phylogeny.data.Identifier;
89 import org.forester.phylogeny.data.PhylogenyData;
90 import org.forester.phylogeny.data.PhylogenyDataUtil;
91 import org.forester.phylogeny.data.Polygon;
92 import org.forester.phylogeny.data.PropertiesList;
93 import org.forester.phylogeny.data.Property;
94 import org.forester.phylogeny.data.Property.AppliesTo;
95 import org.forester.phylogeny.data.ProteinDomain;
96 import org.forester.phylogeny.data.Taxonomy;
97 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
98 import org.forester.phylogeny.factories.PhylogenyFactory;
99 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
100 import org.forester.protein.BasicDomain;
101 import org.forester.protein.BasicProtein;
102 import org.forester.protein.Domain;
103 import org.forester.protein.Protein;
104 import org.forester.protein.ProteinId;
105 import org.forester.rio.TestRIO;
106 import org.forester.sdi.SDI;
107 import org.forester.sdi.SDIR;
108 import org.forester.sdi.TestGSDI;
109 import org.forester.sequence.BasicSequence;
110 import org.forester.sequence.MolecularSequence;
111 import org.forester.species.BasicSpecies;
112 import org.forester.species.Species;
113 import org.forester.surfacing.TestSurfacing;
114 import org.forester.tools.ConfidenceAssessor;
115 import org.forester.tools.SupportCount;
116 import org.forester.tools.TreeSplitMatrix;
117 import org.forester.util.AsciiHistogram;
118 import org.forester.util.BasicDescriptiveStatistics;
119 import org.forester.util.BasicTable;
120 import org.forester.util.BasicTableParser;
121 import org.forester.util.DescriptiveStatistics;
122 import org.forester.util.ForesterConstants;
123 import org.forester.util.ForesterUtil;
124 import org.forester.util.GeneralTable;
125 import org.forester.util.SequenceAccessionTools;
126 import org.forester.ws.seqdb.SequenceDatabaseEntry;
127 import org.forester.ws.seqdb.SequenceDbWsTools;
128 import org.forester.ws.seqdb.UniProtTaxonomy;
129
130 @SuppressWarnings( "unused")
131 public final class Test {
132
133     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
134             + ForesterUtil.getFileSeparator() + "resources" + ForesterUtil.getFileSeparator();
135     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
136             + ForesterUtil.getFileSeparator() + "test_data" + ForesterUtil.getFileSeparator();
137     private final static boolean PERFORM_DB_TESTS          = false;
138     private static final boolean PERFORM_WEB_TREE_ACCESS   = false;
139     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
140             + ForesterConstants.PHYLO_XML_VERSION + "/" + ForesterConstants.PHYLO_XML_XSD;
141     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
142             + ForesterConstants.PHYLO_XML_VERSION + "/" + ForesterConstants.PHYLO_XML_XSD;
143     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
144     private final static double  ZERO_DIFF                 = 1.0E-9;
145
146     private static boolean isEqual( final double a, final double b ) {
147         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
148     }
149
150     public static void main( final String[] args ) {
151         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
152         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
153                 + "]" );
154         Locale.setDefault( Locale.US );
155         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
156         int failed = 0;
157         int succeeded = 0;
158         System.out.print( "[Test if directory with files for testing exists/is readable: " );
159         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
160             System.out.println( "OK.]" );
161         }
162         else {
163             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
164             System.out.println( "Testing aborted." );
165             System.exit( -1 );
166         }
167         System.out.print( "[Test if resources directory exists/is readable: " );
168         if ( testDir( PATH_TO_RESOURCES ) ) {
169             System.out.println( "OK.]" );
170         }
171         else {
172             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
173             System.out.println( "Testing aborted." );
174             System.exit( -1 );
175         }
176         final long start_time = new Date().getTime();
177         System.out.print( "Basic node methods: " );
178         if ( Test.testBasicNodeMethods() ) {
179             System.out.println( "OK." );
180             succeeded++;
181         }
182         else {
183             System.out.println( "failed." );
184             failed++;
185         }
186         System.out.print( "Protein id: " );
187         if ( !testProteinId() ) {
188             System.out.println( "failed." );
189             failed++;
190         }
191         else {
192             succeeded++;
193         }
194         System.out.println( "OK." );
195         System.out.print( "Species: " );
196         if ( !testSpecies() ) {
197             System.out.println( "failed." );
198             failed++;
199         }
200         else {
201             succeeded++;
202         }
203         System.out.println( "OK." );
204         System.out.print( "Basic domain: " );
205         if ( !testBasicDomain() ) {
206             System.out.println( "failed." );
207             failed++;
208         }
209         else {
210             succeeded++;
211         }
212         System.out.println( "OK." );
213         System.out.print( "Basic protein: " );
214         if ( !testBasicProtein() ) {
215             System.out.println( "failed." );
216             failed++;
217         }
218         else {
219             succeeded++;
220         }
221         System.out.println( "OK." );
222         
223         System.out.print( "Common prefix: " );
224         if ( !testCommonPrefix() ) {
225             System.out.println( "failed." );
226             failed++;
227         }
228         else {
229             succeeded++;
230         }
231         System.out.println( "OK." );
232         
233         System.out.print( "Common prefix sep: " );
234         if ( !testCommonPrefixSep() ) {
235             System.out.println( "failed." );
236             failed++;
237         }
238         else {
239             succeeded++;
240         }
241         System.out.println( "OK." );
242         
243        
244         System.out.print( "Sequence writer: " );
245         if ( testSequenceWriter() ) {
246             System.out.println( "OK." );
247             succeeded++;
248         }
249         else {
250             System.out.println( "failed." );
251             failed++;
252         }
253         System.out.print( "Sequence id parsing: " );
254         if ( testSequenceIdParsing() ) {
255             System.out.println( "OK." );
256             succeeded++;
257         }
258         else {
259             System.out.println( "failed." );
260             failed++;
261         }
262         System.out.print( "UniProtKB id extraction: " );
263         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
264             System.out.println( "OK." );
265             succeeded++;
266         }
267         else {
268             System.out.println( "failed." );
269             failed++;
270         }
271         System.out.print( "Sequence DB tools 1: " );
272         if ( testSequenceDbWsTools1() ) {
273             System.out.println( "OK." );
274             succeeded++;
275         }
276         else {
277             System.out.println( "failed." );
278             failed++;
279         }
280         System.out.print( "Hmmscan output parser: " );
281         if ( testHmmscanOutputParser() ) {
282             System.out.println( "OK." );
283             succeeded++;
284         }
285         else {
286             System.out.println( "failed." );
287             failed++;
288         }
289         System.out.print( "Overlap removal: " );
290         if ( !org.forester.test.Test.testOverlapRemoval() ) {
291             System.out.println( "failed." );
292             failed++;
293         }
294         else {
295             succeeded++;
296         }
297         System.out.println( "OK." );
298         System.out.print( "Engulfing overlap removal: " );
299         if ( !Test.testEngulfingOverlapRemoval() ) {
300             System.out.println( "failed." );
301             failed++;
302         }
303         else {
304             succeeded++;
305         }
306         System.out.println( "OK." );
307         System.out.print( "Taxonomy data extraction: " );
308         if ( Test.testExtractTaxonomyDataFromNodeName() ) {
309             System.out.println( "OK." );
310             succeeded++;
311         }
312         else {
313             System.out.println( "failed." );
314             failed++;
315         }
316         System.out.print( "Taxonomy code extraction: " );
317         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
318             System.out.println( "OK." );
319             succeeded++;
320         }
321         else {
322             System.out.println( "failed." );
323             failed++;
324         }
325         System.out.print( "SN extraction: " );
326         if ( Test.testExtractSNFromNodeName() ) {
327             System.out.println( "OK." );
328             succeeded++;
329         }
330         else {
331             System.out.println( "failed." );
332             failed++;
333         }
334         System.out.print( "Taxonomy extraction (general): " );
335         if ( Test.testTaxonomyExtraction() ) {
336             System.out.println( "OK." );
337             succeeded++;
338         }
339         else {
340             System.out.println( "failed." );
341             failed++;
342         }
343         System.out.print( "Uri for Aptx web sequence accession: " );
344         if ( Test.testCreateUriForSeqWeb() ) {
345             System.out.println( "OK." );
346             succeeded++;
347         }
348         else {
349             System.out.println( "failed." );
350             failed++;
351         }
352         System.out.print( "Basic node construction and parsing of NHX (node level): " );
353         if ( Test.testNHXNodeParsing() ) {
354             System.out.println( "OK." );
355             succeeded++;
356         }
357         else {
358             System.out.println( "failed." );
359             failed++;
360         }
361         System.out.print( "Node construction and parsing of NHX (node level): " );
362         if ( Test.testNHXNodeParsing2() ) {
363             System.out.println( "OK." );
364             succeeded++;
365         }
366         else {
367             System.out.println( "failed." );
368             failed++;
369         }
370         System.out.print( "NHX parsing iterating: " );
371         if ( Test.testNHParsingIter() ) {
372             System.out.println( "OK." );
373             succeeded++;
374         }
375         else {
376             System.out.println( "failed." );
377             failed++;
378         }
379         System.out.print( "NH parsing: " );
380         if ( Test.testNHParsing() ) {
381             System.out.println( "OK." );
382             succeeded++;
383         }
384         else {
385             System.out.println( "failed." );
386             failed++;
387         }
388         System.out.print( "NH parsing - special chars: " );
389         if ( Test.testNHParsingSpecialChars() ) {
390             System.out.println( "OK." );
391             succeeded++;
392         }
393         else {
394             System.out.println( "failed." );
395             failed++;
396         }
397         System.out.print( "Conversion to NHX (node level): " );
398         if ( Test.testNHXconversion() ) {
399             System.out.println( "OK." );
400             succeeded++;
401         }
402         else {
403             System.out.println( "failed." );
404             failed++;
405         }
406         System.out.print( "NHX parsing: " );
407         if ( Test.testNHXParsing() ) {
408             System.out.println( "OK." );
409             succeeded++;
410         }
411         else {
412             System.out.println( "failed." );
413             failed++;
414         }
415         System.out.print( "NHX parsing with quotes: " );
416         if ( Test.testNHXParsingQuotes() ) {
417             System.out.println( "OK." );
418             succeeded++;
419         }
420         else {
421             System.out.println( "failed." );
422             failed++;
423         }
424         System.out.print( "NHX parsing (MrBayes): " );
425         if ( Test.testNHXParsingMB() ) {
426             System.out.println( "OK." );
427             succeeded++;
428         }
429         else {
430             System.out.println( "failed." );
431             failed++;
432         }
433         System.out.print( "Nexus characters parsing: " );
434         if ( Test.testNexusCharactersParsing() ) {
435             System.out.println( "OK." );
436             succeeded++;
437         }
438         else {
439             System.out.println( "failed." );
440             failed++;
441         }
442         System.out.print( "Nexus tree parsing iterating: " );
443         if ( Test.testNexusTreeParsingIterating() ) {
444             System.out.println( "OK." );
445             succeeded++;
446         }
447         else {
448             System.out.println( "failed." );
449             failed++;
450         }
451         System.out.print( "Nexus tree parsing: " );
452         if ( Test.testNexusTreeParsing() ) {
453             System.out.println( "OK." );
454             succeeded++;
455         }
456         else {
457             System.out.println( "failed." );
458             failed++;
459         }
460         System.out.print( "Nexus tree parsing (translating): " );
461         if ( Test.testNexusTreeParsingTranslating() ) {
462             System.out.println( "OK." );
463             succeeded++;
464         }
465         else {
466             System.out.println( "failed." );
467             failed++;
468         }
469         System.out.print( "Nexus matrix parsing: " );
470         if ( Test.testNexusMatrixParsing() ) {
471             System.out.println( "OK." );
472             succeeded++;
473         }
474         else {
475             System.out.println( "failed." );
476             failed++;
477         }
478         System.out.print( "Basic phyloXML parsing: " );
479         if ( Test.testBasicPhyloXMLparsing() ) {
480             System.out.println( "OK." );
481             succeeded++;
482         }
483         else {
484             System.out.println( "failed." );
485             failed++;
486         }
487         System.out.print( "Basic phyloXML parsing (validating against schema): " );
488         if ( testBasicPhyloXMLparsingValidating() ) {
489             System.out.println( "OK." );
490             succeeded++;
491         }
492         else {
493             System.out.println( "failed." );
494             failed++;
495         }
496         System.out.print( "phyloXML parsing (validating against schema): " );
497         if ( testPhyloXMLparsingValidating() ) {
498             System.out.println( "OK." );
499             succeeded++;
500         }
501         else {
502             System.out.println( "failed." );
503             failed++;
504         }
505         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
506         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
507             System.out.println( "OK." );
508             succeeded++;
509         }
510         else {
511             System.out.println( "failed." );
512             failed++;
513         }
514         System.out.print( "phyloXML Distribution Element: " );
515         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
516             System.out.println( "OK." );
517             succeeded++;
518         }
519         else {
520             System.out.println( "failed." );
521             failed++;
522         }
523         System.out.print( "Tol XML parsing: " );
524         if ( Test.testBasicTolXMLparsing() ) {
525             System.out.println( "OK." );
526             succeeded++;
527         }
528         else {
529             System.out.println( "failed." );
530             failed++;
531         }
532         System.out.print( "UTF-8 parsing from file: " );
533         if ( Test.testUTF8ParsingFromFile() ) {
534             System.out.println( "OK." );
535             succeeded++;
536         }
537         else {
538             System.out.println( "failed." );
539             failed++;
540         }
541         System.out.print( "Copying of node data: " );
542         if ( Test.testCopyOfNodeData() ) {
543             System.out.println( "OK." );
544             succeeded++;
545         }
546         else {
547             System.out.println( "failed." );
548             failed++;
549         }
550         System.out.print( "Tree copy: " );
551         if ( Test.testTreeCopy() ) {
552             System.out.println( "OK." );
553             succeeded++;
554         }
555         else {
556             System.out.println( "failed." );
557             failed++;
558         }
559         System.out.print( "Basic tree methods: " );
560         if ( Test.testBasicTreeMethods() ) {
561             System.out.println( "OK." );
562             succeeded++;
563         }
564         else {
565             System.out.println( "failed." );
566             failed++;
567         }
568         System.out.print( "Tree methods: " );
569         if ( Test.testTreeMethods() ) {
570             System.out.println( "OK." );
571             succeeded++;
572         }
573         else {
574             System.out.println( "failed." );
575             failed++;
576         }
577         System.out.print( "Phylogeny methods:" );
578         if ( Test.testPhylogenyMethods() ) {
579             System.out.println( "OK." );
580             succeeded++;
581         }
582         else {
583             System.out.println( "failed." );
584             failed++;
585         }
586         System.out.print( "Postorder Iterator: " );
587         if ( Test.testPostOrderIterator() ) {
588             System.out.println( "OK." );
589             succeeded++;
590         }
591         else {
592             System.out.println( "failed." );
593             failed++;
594         }
595         System.out.print( "Preorder Iterator: " );
596         if ( Test.testPreOrderIterator() ) {
597             System.out.println( "OK." );
598             succeeded++;
599         }
600         else {
601             System.out.println( "failed." );
602             failed++;
603         }
604         System.out.print( "Levelorder Iterator: " );
605         if ( Test.testLevelOrderIterator() ) {
606             System.out.println( "OK." );
607             succeeded++;
608         }
609         else {
610             System.out.println( "failed." );
611             failed++;
612         }
613         System.out.print( "Re-id methods: " );
614         if ( Test.testReIdMethods() ) {
615             System.out.println( "OK." );
616             succeeded++;
617         }
618         else {
619             System.out.println( "failed." );
620             failed++;
621         }
622         System.out.print( "Methods on last external nodes: " );
623         if ( Test.testLastExternalNodeMethods() ) {
624             System.out.println( "OK." );
625             succeeded++;
626         }
627         else {
628             System.out.println( "failed." );
629             failed++;
630         }
631         System.out.print( "Methods on external nodes: " );
632         if ( Test.testExternalNodeRelatedMethods() ) {
633             System.out.println( "OK." );
634             succeeded++;
635         }
636         else {
637             System.out.println( "failed." );
638             failed++;
639         }
640         System.out.print( "Deletion of external nodes: " );
641         if ( Test.testDeletionOfExternalNodes() ) {
642             System.out.println( "OK." );
643             succeeded++;
644         }
645         else {
646             System.out.println( "failed." );
647             failed++;
648         }
649         System.out.print( "Subtree deletion: " );
650         if ( Test.testSubtreeDeletion() ) {
651             System.out.println( "OK." );
652             succeeded++;
653         }
654         else {
655             System.out.println( "failed." );
656             failed++;
657         }
658         System.out.print( "Phylogeny branch: " );
659         if ( Test.testPhylogenyBranch() ) {
660             System.out.println( "OK." );
661             succeeded++;
662         }
663         else {
664             System.out.println( "failed." );
665             failed++;
666         }
667         System.out.print( "Rerooting: " );
668         if ( Test.testRerooting() ) {
669             System.out.println( "OK." );
670             succeeded++;
671         }
672         else {
673             System.out.println( "failed." );
674             failed++;
675         }
676         System.out.print( "Mipoint rooting: " );
677         if ( Test.testMidpointrooting() ) {
678             System.out.println( "OK." );
679             succeeded++;
680         }
681         else {
682             System.out.println( "failed." );
683             failed++;
684         }
685         System.out.print( "Node removal: " );
686         if ( Test.testNodeRemoval() ) {
687             System.out.println( "OK." );
688             succeeded++;
689         }
690         else {
691             System.out.println( "failed." );
692             failed++;
693         }
694         System.out.print( "Support count: " );
695         if ( Test.testSupportCount() ) {
696             System.out.println( "OK." );
697             succeeded++;
698         }
699         else {
700             System.out.println( "failed." );
701             failed++;
702         }
703         System.out.print( "Support transfer: " );
704         if ( Test.testSupportTransfer() ) {
705             System.out.println( "OK." );
706             succeeded++;
707         }
708         else {
709             System.out.println( "failed." );
710             failed++;
711         }
712         System.out.print( "Finding of LCA: " );
713         if ( Test.testGetLCA() ) {
714             System.out.println( "OK." );
715             succeeded++;
716         }
717         else {
718             System.out.println( "failed." );
719             failed++;
720         }
721         System.out.print( "Finding of LCA 2: " );
722         if ( Test.testGetLCA2() ) {
723             System.out.println( "OK." );
724             succeeded++;
725         }
726         else {
727             System.out.println( "failed." );
728             failed++;
729         }
730         System.out.print( "Calculation of distance between nodes: " );
731         if ( Test.testGetDistance() ) {
732             System.out.println( "OK." );
733             succeeded++;
734         }
735         else {
736             System.out.println( "failed." );
737             failed++;
738         }
739         System.out.print( "Descriptive statistics: " );
740         if ( Test.testDescriptiveStatistics() ) {
741             System.out.println( "OK." );
742             succeeded++;
743         }
744         else {
745             System.out.println( "failed." );
746             failed++;
747         }
748         System.out.print( "Data objects and methods: " );
749         if ( Test.testDataObjects() ) {
750             System.out.println( "OK." );
751             succeeded++;
752         }
753         else {
754             System.out.println( "failed." );
755             failed++;
756         }
757         System.out.print( "Properties map: " );
758         if ( Test.testPropertiesMap() ) {
759             System.out.println( "OK." );
760             succeeded++;
761         }
762         else {
763             System.out.println( "failed." );
764             failed++;
765         }
766         System.out.print( "SDIse: " );
767         if ( Test.testSDIse() ) {
768             System.out.println( "OK." );
769             succeeded++;
770         }
771         else {
772             System.out.println( "failed." );
773             failed++;
774         }
775         System.out.print( "SDIunrooted: " );
776         if ( Test.testSDIunrooted() ) {
777             System.out.println( "OK." );
778             succeeded++;
779         }
780         else {
781             System.out.println( "failed." );
782             failed++;
783         }
784         System.out.print( "GSDI: " );
785         if ( TestGSDI.test() ) {
786             System.out.println( "OK." );
787             succeeded++;
788         }
789         else {
790             System.out.println( "failed." );
791             failed++;
792         }
793         System.out.print( "RIO: " );
794         if ( TestRIO.test() ) {
795             System.out.println( "OK." );
796             succeeded++;
797         }
798         else {
799             System.out.println( "failed." );
800             failed++;
801         }
802         System.out.print( "Clade analyis: " );
803         if ( CladeAnalysisTest.test() ) {
804             System.out.println( "OK." );
805             succeeded++;
806         }
807         else {
808             System.out.println( "failed." );
809             failed++;
810         }
811         System.out.print( "Phylogeny reconstruction:" );
812         System.out.println();
813         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
814             System.out.println( "OK." );
815             succeeded++;
816         }
817         else {
818             System.out.println( "failed." );
819             failed++;
820         }
821         System.out.print( "Analysis of domain architectures: " );
822         System.out.println();
823         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
824             System.out.println( "OK." );
825             succeeded++;
826         }
827         else {
828             System.out.println( "failed." );
829             failed++;
830         }
831         System.out.print( "GO: " );
832         System.out.println();
833         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
834             System.out.println( "OK." );
835             succeeded++;
836         }
837         else {
838             System.out.println( "failed." );
839             failed++;
840         }
841         System.out.print( "Modeling tools: " );
842         if ( TestPccx.test() ) {
843             System.out.println( "OK." );
844             succeeded++;
845         }
846         else {
847             System.out.println( "failed." );
848             failed++;
849         }
850         System.out.print( "Split Matrix strict: " );
851         if ( Test.testSplitStrict() ) {
852             System.out.println( "OK." );
853             succeeded++;
854         }
855         else {
856             System.out.println( "failed." );
857             failed++;
858         }
859         System.out.print( "Split Matrix: " );
860         if ( Test.testSplit() ) {
861             System.out.println( "OK." );
862             succeeded++;
863         }
864         else {
865             System.out.println( "failed." );
866             failed++;
867         }
868         System.out.print( "Confidence Assessor: " );
869         if ( Test.testConfidenceAssessor() ) {
870             System.out.println( "OK." );
871             succeeded++;
872         }
873         else {
874             System.out.println( "failed." );
875             failed++;
876         }
877         System.out.print( "Basic table: " );
878         if ( Test.testBasicTable() ) {
879             System.out.println( "OK." );
880             succeeded++;
881         }
882         else {
883             System.out.println( "failed." );
884             failed++;
885         }
886         System.out.print( "General table: " );
887         if ( Test.testGeneralTable() ) {
888             System.out.println( "OK." );
889             succeeded++;
890         }
891         else {
892             System.out.println( "failed." );
893             failed++;
894         }
895         System.out.print( "Amino acid sequence: " );
896         if ( Test.testAminoAcidSequence() ) {
897             System.out.println( "OK." );
898             succeeded++;
899         }
900         else {
901             System.out.println( "failed." );
902             failed++;
903         }
904         System.out.print( "General MSA parser: " );
905         if ( Test.testGeneralMsaParser() ) {
906             System.out.println( "OK." );
907             succeeded++;
908         }
909         else {
910             System.out.println( "failed." );
911             failed++;
912         }
913         System.out.print( "Fasta parser for msa: " );
914         if ( Test.testFastaParser() ) {
915             System.out.println( "OK." );
916             succeeded++;
917         }
918         else {
919             System.out.println( "failed." );
920             failed++;
921         }
922         System.out.print( "Creation of balanced phylogeny: " );
923         if ( Test.testCreateBalancedPhylogeny() ) {
924             System.out.println( "OK." );
925             succeeded++;
926         }
927         else {
928             System.out.println( "failed." );
929             failed++;
930         }
931         System.out.print( "Genbank accessor parsing: " );
932         if ( Test.testGenbankAccessorParsing() ) {
933             System.out.println( "OK." );
934             succeeded++;
935         }
936         else {
937             System.out.println( "failed." );
938             failed++;
939         }
940         String path = "";
941         final String os = ForesterUtil.OS_NAME.toLowerCase();
942         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
943             path = "/usr/local/bin/mafft";
944         }
945         else if ( os.indexOf( "win" ) >= 0 ) {
946             path = "C:\\Program Files\\mafft-win\\mafft.bat";
947         }
948         else {
949             path = "mafft";
950             if ( !MsaInferrer.isInstalled( path ) ) {
951                 path = "/usr/bin/mafft";
952             }
953             if ( !MsaInferrer.isInstalled( path ) ) {
954                 path = "/usr/local/bin/mafft";
955             }
956         }
957         if ( MsaInferrer.isInstalled( path ) ) {
958             System.out.print( "MAFFT (external program): " );
959             if ( Test.testMafft( path ) ) {
960                 System.out.println( "OK." );
961                 succeeded++;
962             }
963             else {
964                 System.out.println( "failed [will not count towards failed tests]" );
965             }
966         }
967         System.out.print( "Next nodes with collapsed: " );
968         if ( Test.testNextNodeWithCollapsing() ) {
969             System.out.println( "OK." );
970             succeeded++;
971         }
972         else {
973             System.out.println( "failed." );
974             failed++;
975         }
976         System.out.print( "Simple MSA quality: " );
977         if ( Test.testMsaQualityMethod() ) {
978             System.out.println( "OK." );
979             succeeded++;
980         }
981         else {
982             System.out.println( "failed." );
983             failed++;
984         }
985         System.out.print( "Deleteable MSA: " );
986         if ( Test.testDeleteableMsa() ) {
987             System.out.println( "OK." );
988             succeeded++;
989         }
990         else {
991             System.out.println( "failed." );
992             failed++;
993         }
994         System.out.print( "MSA entropy: " );
995         if ( Test.testMsaEntropy() ) {
996             System.out.println( "OK." );
997             succeeded++;
998         }
999         else {
1000             System.out.println( "failed." );
1001             failed++;
1002         }
1003         if ( PERFORM_DB_TESTS ) {
1004             System.out.print( "Uniprot Entry Retrieval: " );
1005             if ( Test.testUniprotEntryRetrieval() ) {
1006                 System.out.println( "OK." );
1007                 succeeded++;
1008             }
1009             else {
1010                 System.out.println( "failed." );
1011                 failed++;
1012             }
1013             System.out.print( "Ebi Entry Retrieval: " );
1014             if ( Test.testEbiEntryRetrieval() ) {
1015                 System.out.println( "OK." );
1016                 succeeded++;
1017             }
1018             else {
1019                 System.out.println( "failed." );
1020                 failed++;
1021             }
1022             System.out.print( "Sequence DB tools 2: " );
1023             if ( testSequenceDbWsTools2() ) {
1024                 System.out.println( "OK." );
1025                 succeeded++;
1026             }
1027             else {
1028                 System.out.println( "failed." );
1029                 failed++;
1030                 System.exit( -1 );
1031             }
1032             System.out.print( "Uniprot Taxonomy Search: " );
1033             if ( Test.testUniprotTaxonomySearch() ) {
1034                 System.out.println( "OK." );
1035                 succeeded++;
1036             }
1037             else {
1038                 System.out.println( "failed." );
1039                 failed++;
1040             }
1041         }
1042         if ( PERFORM_WEB_TREE_ACCESS ) {
1043             System.out.print( "TreeBase acccess: " );
1044             if ( Test.testTreeBaseReading() ) {
1045                 System.out.println( "OK." );
1046                 succeeded++;
1047             }
1048             else {
1049                 System.out.println( "failed." );
1050                 failed++;
1051             }
1052             System.out.print( "ToL access: " );
1053             if ( Test.testToLReading() ) {
1054                 System.out.println( "OK." );
1055                 succeeded++;
1056             }
1057             else {
1058                 System.out.println( "failed." );
1059                 failed++;
1060             }
1061             System.out.print( "NHX parsing from URL: " );
1062             if ( Test.testNHXparsingFromURL() ) {
1063                 System.out.println( "OK." );
1064                 succeeded++;
1065             }
1066             else {
1067                 System.out.println( "failed." );
1068                 failed++;
1069             }
1070             System.out.print( "NHX parsing from URL 2: " );
1071             if ( Test.testNHXparsingFromURL2() ) {
1072                 System.out.println( "OK." );
1073                 succeeded++;
1074             }
1075             else {
1076                 System.out.println( "failed." );
1077                 failed++;
1078             }
1079             System.out.print( "phyloXML parsing from URL: " );
1080             if ( Test.testPhyloXMLparsingFromURL() ) {
1081                 System.out.println( "OK." );
1082                 succeeded++;
1083             }
1084             else {
1085                 System.out.println( "failed." );
1086                 failed++;
1087             }
1088             System.out.print( "TreeFam access: " );
1089             if ( Test.testTreeFamReading() ) {
1090                 System.out.println( "OK." );
1091                 succeeded++;
1092             }
1093             else {
1094                 System.out.println( "failed." );
1095                 failed++;
1096             }
1097             System.out.print( "Pfam tree access: " );
1098             if ( Test.testPfamTreeReading() ) {
1099                 System.out.println( "OK." );
1100                 succeeded++;
1101             }
1102             else {
1103                 System.out.println( "failed." );
1104                 failed++;
1105             }
1106         }
1107         System.out.println();
1108         final Runtime rt = java.lang.Runtime.getRuntime();
1109         final long free_memory = rt.freeMemory() / 1000000;
1110         final long total_memory = rt.totalMemory() / 1000000;
1111         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1112                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1113         System.out.println();
1114         System.out.println( "Successful tests: " + succeeded );
1115         System.out.println( "Failed     tests: " + failed );
1116         System.out.println();
1117         if ( failed < 1 ) {
1118             System.out.println( "OK." );
1119         }
1120         else {
1121             System.out.println( "Not OK." );
1122         }
1123     }
1124
1125    
1126     private static boolean testEngulfingOverlapRemoval() {
1127         try {
1128             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1129             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1130             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1131             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1132             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1133             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1134             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1135             final List<Boolean> covered = new ArrayList<Boolean>();
1136             covered.add( true ); // 0
1137             covered.add( false ); // 1
1138             covered.add( true ); // 2
1139             covered.add( false ); // 3
1140             covered.add( true ); // 4
1141             covered.add( true ); // 5
1142             covered.add( false ); // 6
1143             covered.add( true ); // 7
1144             covered.add( true ); // 8
1145             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1146                 return false;
1147             }
1148             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1149                 return false;
1150             }
1151             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1152                 return false;
1153             }
1154             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1155                 return false;
1156             }
1157             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1158                 return false;
1159             }
1160             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1161                 return false;
1162             }
1163             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1164                 return false;
1165             }
1166             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1167             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1168             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1169             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1170             abc.addProteinDomain( a );
1171             abc.addProteinDomain( b );
1172             abc.addProteinDomain( c );
1173             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1174             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1175             if ( abc.getNumberOfProteinDomains() != 3 ) {
1176                 return false;
1177             }
1178             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1179                 return false;
1180             }
1181             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1182                 return false;
1183             }
1184             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1185                 return false;
1186             }
1187             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1188                 return false;
1189             }
1190             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1191             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1192             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1193             final Protein def = new BasicProtein( "def", "nemve", 0 );
1194             def.addProteinDomain( d );
1195             def.addProteinDomain( e );
1196             def.addProteinDomain( f );
1197             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1198             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1199             if ( def.getNumberOfProteinDomains() != 3 ) {
1200                 return false;
1201             }
1202             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1203                 return false;
1204             }
1205             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1206                 return false;
1207             }
1208             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1209                 return false;
1210             }
1211             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1212                 return false;
1213             }
1214             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1215                 return false;
1216             }
1217         }
1218         catch ( final Exception e ) {
1219             e.printStackTrace( System.out );
1220             return false;
1221         }
1222         return true;
1223     }
1224
1225     private static final boolean testNHXparsingFromURL2() {
1226         try {
1227             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1228             final Phylogeny phys[] = AptxUtil
1229                     .readPhylogeniesFromUrl( new URL( s ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1230             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1231                 return false;
1232             }
1233             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1234                 System.out.println( phys[ 0 ].toNewHampshire() );
1235                 return false;
1236             }
1237             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1238                 System.out.println( phys[ 1 ].toNewHampshire() );
1239                 return false;
1240             }
1241             final Phylogeny phys2[] = AptxUtil
1242                     .readPhylogeniesFromUrl( new URL( s ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1243             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1244                 return false;
1245             }
1246             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1247                 System.out.println( phys2[ 0 ].toNewHampshire() );
1248                 return false;
1249             }
1250             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1251                 System.out.println( phys2[ 1 ].toNewHampshire() );
1252                 return false;
1253             }
1254             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1255                     + "SwissTree/ST001/consensus_tree.nhx" ),
1256                                                                        false,
1257                                                                        false,
1258                                                                        false,
1259                                                                        TAXONOMY_EXTRACTION.NO,
1260                                                                        false );
1261             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1262                 return false;
1263             }
1264             if ( !phys3[ 0 ].toNewHampshire()
1265                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1266                 System.out.println( phys3[ 0 ].toNewHampshire() );
1267                 return false;
1268             }
1269             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1270                     + "SwissTree/ST001/consensus_tree.nhx" ),
1271                                                                        false,
1272                                                                        false,
1273                                                                        false,
1274                                                                        TAXONOMY_EXTRACTION.NO,
1275                                                                        false );
1276             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1277                 return false;
1278             }
1279             if ( !phys4[ 0 ].toNewHampshire()
1280                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1281                 System.out.println( phys4[ 0 ].toNewHampshire() );
1282                 return false;
1283             }
1284         }
1285         catch ( final Exception e ) {
1286             e.printStackTrace();
1287             return false;
1288         }
1289         return true;
1290     }
1291
1292     private static final boolean testNHXparsingFromURL() {
1293         try {
1294             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1295             final URL u = new URL( s );
1296             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1297             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1298             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1299                 return false;
1300             }
1301             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1302                 System.out.println( phys[ 0 ].toNewHampshire() );
1303                 return false;
1304             }
1305             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1306                 System.out.println( phys[ 1 ].toNewHampshire() );
1307                 return false;
1308             }
1309             final URL u2 = new URL( s );
1310             final Phylogeny[] phys2 = factory.create( u2.openStream(), new NHXParser() );
1311             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1312                 return false;
1313             }
1314             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1315                 System.out.println( phys2[ 0 ].toNewHampshire() );
1316                 return false;
1317             }
1318             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1319             final NHXParser p = new NHXParser();
1320             final URL u3 = new URL( s );
1321             p.setSource( u3 );
1322             if ( !p.hasNext() ) {
1323                 return false;
1324             }
1325             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1326                 return false;
1327             }
1328             if ( !p.hasNext() ) {
1329                 return false;
1330             }
1331             p.reset();
1332             if ( !p.hasNext() ) {
1333                 return false;
1334             }
1335             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1336                 return false;
1337             }
1338             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1339                 return false;
1340             }
1341             p.reset();
1342             if ( !p.hasNext() ) {
1343                 return false;
1344             }
1345             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1346                 return false;
1347             }
1348             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1349                 return false;
1350             }
1351         }
1352         catch ( final Exception e ) {
1353             System.out.println( e.toString() );
1354             e.printStackTrace();
1355             return false;
1356         }
1357         return true;
1358     }
1359
1360     private static boolean testOverlapRemoval() {
1361         try {
1362             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1363             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1364             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1365             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1366             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1367             final List<Boolean> covered = new ArrayList<Boolean>();
1368             covered.add( true ); // 0
1369             covered.add( false ); // 1
1370             covered.add( true ); // 2
1371             covered.add( false ); // 3
1372             covered.add( true ); // 4
1373             covered.add( true ); // 5
1374             covered.add( false ); // 6
1375             covered.add( true ); // 7
1376             covered.add( true ); // 8
1377             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1378                 return false;
1379             }
1380             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1381                 return false;
1382             }
1383             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1384                 return false;
1385             }
1386             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1387                 return false;
1388             }
1389             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1390                 return false;
1391             }
1392             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1393             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1394             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1395             ab.addProteinDomain( a );
1396             ab.addProteinDomain( b );
1397             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1398             if ( ab.getNumberOfProteinDomains() != 2 ) {
1399                 return false;
1400             }
1401             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1402                 return false;
1403             }
1404             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1405                 return false;
1406             }
1407             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1408             if ( ab.getNumberOfProteinDomains() != 2 ) {
1409                 return false;
1410             }
1411             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1412                 return false;
1413             }
1414             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1415             final Domain d = new BasicDomain( "d",
1416                                               ( short ) 10000,
1417                                               ( short ) 10500,
1418                                               ( short ) 1,
1419                                               ( short ) 1,
1420                                               0.0000001,
1421                                               1 );
1422             final Domain e = new BasicDomain( "e",
1423                                               ( short ) 5000,
1424                                               ( short ) 5500,
1425                                               ( short ) 1,
1426                                               ( short ) 1,
1427                                               0.0001,
1428                                               1 );
1429             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1430             cde.addProteinDomain( c );
1431             cde.addProteinDomain( d );
1432             cde.addProteinDomain( e );
1433             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1434             if ( cde.getNumberOfProteinDomains() != 3 ) {
1435                 return false;
1436             }
1437             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1438                 return false;
1439             }
1440             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1441             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1442             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1443             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1444             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1445             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1446             fghi.addProteinDomain( f );
1447             fghi.addProteinDomain( g );
1448             fghi.addProteinDomain( h );
1449             fghi.addProteinDomain( i );
1450             fghi.addProteinDomain( i );
1451             fghi.addProteinDomain( i );
1452             fghi.addProteinDomain( i2 );
1453             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1454             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1455                 return false;
1456             }
1457             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1458                 return false;
1459             }
1460             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1461                 return false;
1462             }
1463             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1464             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1465                 return false;
1466             }
1467             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1468                 return false;
1469             }
1470             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1471             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1472             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1473             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1474             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1475             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1476             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1477             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1478             jklm.addProteinDomain( j );
1479             jklm.addProteinDomain( k );
1480             jklm.addProteinDomain( l );
1481             jklm.addProteinDomain( m );
1482             jklm.addProteinDomain( m0 );
1483             jklm.addProteinDomain( m1 );
1484             jklm.addProteinDomain( m2 );
1485             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1486             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1487                 return false;
1488             }
1489             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1490                 return false;
1491             }
1492             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1493                 return false;
1494             }
1495             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1496             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1497                 return false;
1498             }
1499             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1500                 return false;
1501             }
1502             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1503             final Protein od = new BasicProtein( "od", "varanus", 0 );
1504             od.addProteinDomain( only );
1505             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1506             if ( od.getNumberOfProteinDomains() != 1 ) {
1507                 return false;
1508             }
1509             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1510                 return false;
1511             }
1512         }
1513         catch ( final Exception e ) {
1514             e.printStackTrace( System.out );
1515             return false;
1516         }
1517         return true;
1518     }
1519
1520     private static final boolean testPfamTreeReading() {
1521         try {
1522             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1523             final NHXParser parser = new NHXParser();
1524             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1525             parser.setReplaceUnderscores( false );
1526             parser.setGuessRootedness( true );
1527             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1528             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1529                 return false;
1530             }
1531             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1532                 return false;
1533             }
1534         }
1535         catch ( final Exception e ) {
1536             e.printStackTrace();
1537             return false;
1538         }
1539         return true;
1540     }
1541
1542     private static final boolean testPhyloXMLparsingFromURL() {
1543         try {
1544             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1545             final URL u = new URL( s );
1546             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1547             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1548                 return false;
1549             }
1550             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1551             if ( ( phys2 == null ) || ( phys2.length != 2 ) ) {
1552                 return false;
1553             }
1554         }
1555         catch ( final Exception e ) {
1556             e.printStackTrace();
1557             return false;
1558         }
1559         return true;
1560     }
1561
1562     private static final boolean testToLReading() {
1563         try {
1564             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1565             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, new TolParser() );
1566             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1567                 return false;
1568             }
1569             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1570                 return false;
1571             }
1572             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName()
1573                     .equals( "Protacanthopterygii" ) ) {
1574                 return false;
1575             }
1576             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1577                 return false;
1578             }
1579             //
1580             final URL u2 = new URL( WebserviceUtil.TOL_URL_BASE + "17706" );
1581             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, new TolParser() );
1582             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
1583                 return false;
1584             }
1585             if ( !phys2[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "17706" ) ) {
1586                 return false;
1587             }
1588             if ( phys2[ 0 ].getNumberOfExternalNodes() < 5 ) {
1589                 return false;
1590             }
1591         }
1592         catch ( final Exception e ) {
1593             e.printStackTrace();
1594             return false;
1595         }
1596         return true;
1597     }
1598
1599     private static final boolean testTreeBaseReading() {
1600         try {
1601             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "72557?format=nexus" );
1602             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1603             parser.setReplaceUnderscores( true );
1604             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1605             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1606                 return false;
1607             }
1608             final URL u_1 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2406?format=nexus" );
1609             final NexusPhylogeniesParser parser_1 = new NexusPhylogeniesParser();
1610             final Phylogeny[] phys_1 = ForesterUtil.readPhylogeniesFromUrl( u_1, parser_1 );
1611             if ( ( phys_1 == null ) || ( phys_1.length != 1 ) ) {
1612                 return false;
1613             }
1614             final URL u_2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "422?format=nexus" );
1615             final NexusPhylogeniesParser parser_2 = new NexusPhylogeniesParser();
1616             final Phylogeny[] phys_2 = ForesterUtil.readPhylogeniesFromUrl( u_2, parser_2 );
1617             if ( ( phys_2 == null ) || ( phys_2.length != 1 ) ) {
1618                 return false;
1619             }
1620             final URL u_3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2654?format=nexus" );
1621             final NexusPhylogeniesParser parser_3 = new NexusPhylogeniesParser();
1622             final Phylogeny[] phys_3 = ForesterUtil.readPhylogeniesFromUrl( u_3, parser_3 );
1623             if ( ( phys_3 == null ) || ( phys_3.length != 1 ) ) {
1624                 return false;
1625             }
1626             final URL u_4 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1627             final NexusPhylogeniesParser parser_4 = new NexusPhylogeniesParser();
1628             final Phylogeny[] phys_4 = ForesterUtil.readPhylogeniesFromUrl( u_4, parser_4 );
1629             if ( ( phys_4 == null ) || ( phys_4.length != 1 ) ) {
1630                 return false;
1631             }
1632             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1633             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1634             parser2.setReplaceUnderscores( true );
1635             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, parser2 );
1636             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1637                 return false;
1638             }
1639             final URL u3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14909?format=nexus" );
1640             final NexusPhylogeniesParser parser3 = new NexusPhylogeniesParser();
1641             final Phylogeny[] phys3 = ForesterUtil.readPhylogeniesFromUrl( u3, parser3 );
1642             if ( ( phys3 == null ) || ( phys3.length != 2 ) ) {
1643                 return false;
1644             }
1645             final Phylogeny[] phys4 = ForesterUtil.readPhylogeniesFromUrl(
1646                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1647                                                                                    + "14525?format=nexus" ),
1648                                                                            new NexusPhylogeniesParser() );
1649             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1650                 return false;
1651             }
1652             final Phylogeny[] phys5 = ForesterUtil.readPhylogeniesFromUrl(
1653                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1654                                                                                    + "15632?format=nexus" ),
1655                                                                            new NexusPhylogeniesParser() );
1656             if ( ( phys5 == null ) || ( phys5.length != 1 ) ) {
1657                 return false;
1658             }
1659             final Phylogeny[] phys6 = ForesterUtil.readPhylogeniesFromUrl(
1660                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1661                                                                                    + "10190?format=nexus" ),
1662                                                                            new NexusPhylogeniesParser() );
1663             if ( ( phys6 == null ) || ( phys6.length != 1 ) ) {
1664                 return false;
1665             }
1666             final Phylogeny[] phys7 = ForesterUtil.readPhylogeniesFromUrl(
1667                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1668                                                                                    + "13246?format=nexus" ),
1669                                                                            new NexusPhylogeniesParser() );
1670             if ( ( phys7 == null ) || ( phys7.length != 2 ) ) {
1671                 return false;
1672             }
1673             final Phylogeny[] phys8 = ForesterUtil.readPhylogeniesFromUrl(
1674                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1675                                                                                    + "11662?format=nexus" ),
1676                                                                            new NexusPhylogeniesParser() );
1677             if ( ( phys8 == null ) || ( phys8.length != 2 ) ) {
1678                 return false;
1679             }
1680             final Phylogeny[] phys9 = ForesterUtil.readPhylogeniesFromUrl(
1681                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1682                                                                                    + "562?format=nexus" ),
1683                                                                            new NexusPhylogeniesParser() );
1684             if ( ( phys9 == null ) || ( phys9.length != 4 ) ) {
1685                 return false;
1686             }
1687             final Phylogeny[] phys16424 = ForesterUtil.readPhylogeniesFromUrl(
1688                                                                                new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1689                                                                                        + "16424?format=nexus" ),
1690                                                                                new NexusPhylogeniesParser() );
1691             if ( ( phys16424 == null ) || ( phys16424.length != 1 ) ) {
1692                 return false;
1693             }
1694             final Phylogeny[] phys17878 = ForesterUtil.readPhylogeniesFromUrl(
1695                                                                                new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1696                                                                                        + "17878?format=nexus" ),
1697                                                                                new NexusPhylogeniesParser() );
1698             if ( ( phys17878 == null ) || ( phys17878.length != 17 ) ) {
1699                 return false;
1700             }
1701             final Phylogeny[] phys18804 = ForesterUtil.readPhylogeniesFromUrl(
1702                                                                                new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1703                                                                                        + "18804?format=nexus" ),
1704                                                                                new NexusPhylogeniesParser() );
1705             if ( ( phys18804 == null ) || ( phys18804.length != 2 ) ) {
1706                 return false;
1707             }
1708             final Phylogeny[] phys346 = ForesterUtil.readPhylogeniesFromUrl(
1709                                                                              new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1710                                                                                      + "346?format=nexus" ),
1711                                                                              new NexusPhylogeniesParser() );
1712             if ( ( phys346 == null ) || ( phys346.length != 1 ) ) {
1713                 return false;
1714             }
1715         }
1716         catch ( final Exception e ) {
1717             e.printStackTrace();
1718             return false;
1719         }
1720         return true;
1721     }
1722
1723     private static final boolean testTreeFamReading() {
1724         try {
1725             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1726             final NHXParser parser = new NHXParser();
1727             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1728             parser.setReplaceUnderscores( false );
1729             parser.setGuessRootedness( true );
1730             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1731             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1732                 return false;
1733             }
1734             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1735                 return false;
1736             }
1737         }
1738         catch ( final Exception e ) {
1739             e.printStackTrace();
1740             return false;
1741         }
1742         return true;
1743     }
1744
1745     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1746         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1747         return p;
1748     }
1749
1750     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1751         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1752     }
1753
1754     private static boolean testAminoAcidSequence() {
1755         try {
1756             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1757             if ( aa1.getLength() != 13 ) {
1758                 return false;
1759             }
1760             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1761                 return false;
1762             }
1763             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1764                 return false;
1765             }
1766             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1767                 return false;
1768             }
1769             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1770             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1771                 return false;
1772             }
1773             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1774             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1775                 return false;
1776             }
1777             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1778             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1779                 return false;
1780             }
1781         }
1782         catch ( final Exception e ) {
1783             e.printStackTrace();
1784             return false;
1785         }
1786         return true;
1787     }
1788
1789     private static boolean testBasicDomain() {
1790         try {
1791             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1792             if ( !pd.getDomainId().equals( "id" ) ) {
1793                 return false;
1794             }
1795             if ( pd.getNumber() != 1 ) {
1796                 return false;
1797             }
1798             if ( pd.getTotalCount() != 4 ) {
1799                 return false;
1800             }
1801             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1802                 return false;
1803             }
1804             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1805             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1806             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1807             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1808             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1809             if ( !a1.equals( a1 ) ) {
1810                 return false;
1811             }
1812             if ( !a1.equals( a1_copy ) ) {
1813                 return false;
1814             }
1815             if ( !a1.equals( a1_equal ) ) {
1816                 return false;
1817             }
1818             if ( !a1.equals( a2 ) ) {
1819                 return false;
1820             }
1821             if ( a1.equals( a3 ) ) {
1822                 return false;
1823             }
1824             if ( a1.compareTo( a1 ) != 0 ) {
1825                 return false;
1826             }
1827             if ( a1.compareTo( a1_copy ) != 0 ) {
1828                 return false;
1829             }
1830             if ( a1.compareTo( a1_equal ) != 0 ) {
1831                 return false;
1832             }
1833             if ( a1.compareTo( a2 ) != 0 ) {
1834                 return false;
1835             }
1836             if ( a1.compareTo( a3 ) == 0 ) {
1837                 return false;
1838             }
1839         }
1840         catch ( final Exception e ) {
1841             e.printStackTrace( System.out );
1842             return false;
1843         }
1844         return true;
1845     }
1846
1847     private static boolean testBasicNodeMethods() {
1848         try {
1849             if ( PhylogenyNode.getNodeCount() != 0 ) {
1850                 return false;
1851             }
1852             final PhylogenyNode n1 = new PhylogenyNode();
1853             final PhylogenyNode n2 = PhylogenyNode
1854                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1855             final PhylogenyNode n3 = PhylogenyNode
1856                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1857             final PhylogenyNode n4 = PhylogenyNode
1858                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1859             if ( n1.isHasAssignedEvent() ) {
1860                 return false;
1861             }
1862             if ( PhylogenyNode.getNodeCount() != 4 ) {
1863                 return false;
1864             }
1865             if ( n3.getIndicator() != 0 ) {
1866                 return false;
1867             }
1868             if ( n3.getNumberOfExternalNodes() != 1 ) {
1869                 return false;
1870             }
1871             if ( !n3.isExternal() ) {
1872                 return false;
1873             }
1874             if ( !n3.isRoot() ) {
1875                 return false;
1876             }
1877             if ( !n4.getName().equals( "n4" ) ) {
1878                 return false;
1879             }
1880         }
1881         catch ( final Exception e ) {
1882             e.printStackTrace( System.out );
1883             return false;
1884         }
1885         return true;
1886     }
1887
1888     
1889     private static boolean testCommonPrefix() {
1890         final List<String> l0 = new ArrayList<String>();
1891         l0.add( "abc" );
1892         if ( !ForesterUtil.greatestCommonPrefix( l0 ).equals( "abc" ) ) {
1893             return false;
1894         }
1895         
1896         final List<String> l1 = new ArrayList<String>();
1897         l1.add( "abc" );
1898         l1.add( "abX" );
1899         if ( !ForesterUtil.greatestCommonPrefix( l1 ).equals( "ab" ) ) {
1900             return false;
1901         }
1902         
1903         final List<String> l2 = new ArrayList<String>();
1904         l2.add( "abc" );
1905         l2.add( "abX" );
1906         l2.add( "axy" );
1907         if ( !ForesterUtil.greatestCommonPrefix( l2 ).equals( "a" ) ) {
1908             return false;
1909         }
1910         
1911         final List<String> l3 = new ArrayList<String>();
1912         l3.add( "abXsdfsdfsdfsdfsdfsd" );
1913         l3.add( "abXsdfsdfsdfsdfsdfsd" );
1914         l3.add( "abc" );
1915         l3.add( "abXsdfsdfsdfsdfsdfsd" );
1916         l3.add( "ab" );
1917         l3.add( "abc" );
1918         l3.add( "ab" );
1919         if ( !ForesterUtil.greatestCommonPrefix( l3 ).equals( "ab" ) ) {
1920             return false;
1921         }
1922         
1923         final List<String> l4 = new ArrayList<String>();
1924         l4.add( "abXsdfsdfsdfsdfsdfsd" );
1925         l4.add( "abXsdfsdfsdfsdfsdfsd" );
1926         l4.add( "abc" );
1927         l4.add( "Xsdfsdfsdfsdfsdfsd" );
1928         l4.add( "ab" );
1929         l4.add( "abc" );
1930         if ( !ForesterUtil.greatestCommonPrefix( l4 ).equals( "" ) ) {
1931             return false;
1932         }
1933         
1934         final List<String> l5 = new ArrayList<String>();
1935         l5.add( "" );
1936         if ( !ForesterUtil.greatestCommonPrefix( l5 ).equals( "" ) ) {
1937             return false;
1938         }
1939         
1940         final List<String> l6 = new ArrayList<String>();
1941         l6.add( "abc" );
1942         l6.add( "abX" );
1943         l6.add( "" );
1944         if ( !ForesterUtil.greatestCommonPrefix( l6 ).equals( "" ) ) {
1945             return false;
1946         }
1947         return true;
1948     }
1949     
1950     private static boolean testCommonPrefixSep() {
1951         final List<String> l0 = new ArrayList<String>();
1952         l0.add( "a.b.c" );
1953         if ( !ForesterUtil.greatestCommonPrefix( l0, ".").equals( "a.b.c" ) ) {
1954             return false;
1955         }
1956         
1957         final List<String> l1 = new ArrayList<String>();
1958         l1.add( "a.b.c" );
1959         l1.add( "a.b.X" );
1960         if ( !ForesterUtil.greatestCommonPrefix( l1 , ".").equals( "a.b" ) ) {
1961             return false;
1962         }
1963         
1964         final List<String> l2 = new ArrayList<String>();
1965         l2.add( "a.b.c." );
1966         l2.add( "a.b.X." );
1967         l2.add( "a.x.y." );
1968         if ( !ForesterUtil.greatestCommonPrefix( l2, ".").equals( "a" ) ) {
1969             return false;
1970         }
1971         
1972         final List<String> l3 = new ArrayList<String>();
1973         l3.add( "a/b/X/s/d/f/s/d/f/s/d/f/s/d/f/s/d/f/s/d/" );
1974         l3.add( "a/b/X/s/d/f/s/d/f/s/d/f/s/d/f/s/d/f/s/d" );
1975         l3.add( "a/b/c" );
1976         l3.add( "a/b/X/s/d/f/s/d/f/s/d/f/s/d/f/s/d/f/s/d/" );
1977         l3.add( "a/b/" );
1978         l3.add( "a/b/c/" );
1979         l3.add( "a/b////////" );
1980         if ( !ForesterUtil.greatestCommonPrefix( l3, "/" ).equals( "a/b" ) ) {
1981             return false;
1982         }
1983        
1984         final List<String> l4 = new ArrayList<String>();
1985         l4.add( "a.b.X.s.d.f.s.d.f.s.d.f.s.d.f.s.d.f.s.d" );
1986         l4.add( "a.b.X.s.d.f.s.d.f.s.d.f.s.d.f.s.d.f.s.d" );
1987         l4.add( "a.b.c" );
1988         l4.add( "X.s.d.f.s.d.f.s.d.f.s.d.f.s.d.f.s.d..." );
1989         l4.add( "a.b" );
1990         l4.add( "a.b.c" );
1991         if ( !ForesterUtil.greatestCommonPrefix( l4, "." ).equals( "" ) ) {
1992             return false;
1993         }
1994       
1995         final List<String> l5 = new ArrayList<String>();
1996         l5.add( "" );
1997         if ( !ForesterUtil.greatestCommonPrefix( l5, "_" ).equals( "" ) ) {
1998             return false;
1999         }
2000         
2001         final List<String> l6 = new ArrayList<String>();
2002         l6.add( "_" );
2003         l6.add( "__" );
2004         if ( !ForesterUtil.greatestCommonPrefix( l6, "_" ).equals( "" ) ) {
2005             return false;
2006         }
2007         
2008         final List<String> l7 = new ArrayList<String>();
2009         l7.add( "a,b,c" );
2010         l7.add( "a,b,X" );
2011         l7.add( "" );
2012         l7.add( ",,,,,,,,,," );
2013         if ( !ForesterUtil.greatestCommonPrefix( l7, "," ).equals( "" ) ) {
2014             return false;
2015         }
2016         
2017         final List<String> l8 = new ArrayList<String>();
2018         l8.add( "123.304.403.04" );
2019         l8.add( "123.304.403.04.02" );
2020         l8.add( "123.304.403.03.03" );
2021         if ( !ForesterUtil.greatestCommonPrefix( l8, "." ).equals( "123.304.403" ) ) {
2022             return false;
2023         }
2024         
2025         final List<String> l9 = new ArrayList<String>();
2026         l9.add( "123.304.403.04" );
2027         l9.add( "123.304.403.04.02" );
2028         l9.add( "123.304.402.03.03" );
2029         if ( !ForesterUtil.greatestCommonPrefix( l9, "." ).equals( "123.304" ) ) {
2030             return false;
2031         }
2032         return true;
2033     }
2034
2035     
2036     private static boolean testUTF8ParsingFromFile() {
2037         try {
2038             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2039             final Phylogeny[] phylogenies_xml = ParserBasedPhylogenyFactory.getInstance()
2040                     .create( new File( Test.PATH_TO_TEST_DATA + "chars.xml" ), xml_parser );
2041             if ( xml_parser.getErrorCount() > 0 ) {
2042                 System.out.println( xml_parser.getErrorMessages().toString() );
2043                 return false;
2044             }
2045             if ( phylogenies_xml.length != 1 ) {
2046                 return false;
2047             }
2048             final Phylogeny[] phylogenies_xml2 = ParserBasedPhylogenyFactory.getInstance()
2049                     .create( new StringBuffer( phylogenies_xml[ 0 ].toPhyloXML( 0 ) ), xml_parser );
2050             final Phylogeny[] phylogenies_nh = ParserBasedPhylogenyFactory.getInstance()
2051                     .create( new File( Test.PATH_TO_TEST_DATA + "chars.nh" ), new NHXParser() );
2052             if ( phylogenies_nh.length != 1 ) {
2053                 return false;
2054             }
2055             final Phylogeny[] phylogenies_nex = ParserBasedPhylogenyFactory.getInstance()
2056                     .create( new File( Test.PATH_TO_TEST_DATA + "chars.nex" ), new NexusPhylogeniesParser() );
2057             if ( phylogenies_nex.length != 1 ) {
2058                 return false;
2059             }
2060             final String[] xml_n = phylogenies_xml[ 0 ].getAllExternalNodeNames();
2061             final String[] xml_n2 = phylogenies_xml2[ 0 ].getAllExternalNodeNames();
2062             final String[] nh_n = phylogenies_nh[ 0 ].getAllExternalNodeNames();
2063             final String[] nex_n = phylogenies_nex[ 0 ].getAllExternalNodeNames();
2064             final String n0 = "AQ~!@#$%^&*()_+-=\\{}|;:\"<>?,./";
2065             final String n1 = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ";
2066             final String n2 = "漢字ひらがなカタカナ";
2067             final String n3 = "อักษรไทย";
2068             final String n4 = "繁體字";
2069             final String n5 = "한글";
2070             final String n6 = "देवनागरी";
2071             final String n7 = "chữ Quốc ngữ";
2072             final String n8 = "ру́сский язы́к";
2073             final String n9 = "អក្សរខ្មែរ";
2074             if ( !xml_n[ 0 ].equals( n0 ) ) {
2075                 System.out.println( xml_n[ 0 ] );
2076                 System.out.println( n0 );
2077                 return false;
2078             }
2079             if ( !xml_n2[ 0 ].equals( n0 ) ) {
2080                 System.out.println( xml_n2[ 0 ] );
2081                 System.out.println( n0 );
2082                 return false;
2083             }
2084             if ( !nh_n[ 0 ].equals( n0 ) ) {
2085                 System.out.println( nh_n[ 0 ] );
2086                 System.out.println( n0 );
2087                 return false;
2088             }
2089             if ( !nex_n[ 0 ].equals( n0 ) ) {
2090                 System.out.println( nex_n[ 0 ] );
2091                 System.out.println( n0 );
2092                 return false;
2093             }
2094             if ( !xml_n[ 1 ].equals( n1 ) ) {
2095                 System.out.println( xml_n[ 1 ] );
2096                 System.out.println( n1 );
2097                 return false;
2098             }
2099             if ( !xml_n2[ 1 ].equals( n1 ) ) {
2100                 System.out.println( xml_n2[ 1 ] );
2101                 System.out.println( n1 );
2102                 return false;
2103             }
2104             if ( !nh_n[ 1 ].equals( n1 ) ) {
2105                 System.out.println( nh_n[ 1 ] );
2106                 System.out.println( n1 );
2107                 return false;
2108             }
2109             if ( !nex_n[ 1 ].equals( n1 ) ) {
2110                 System.out.println( nex_n[ 1 ] );
2111                 System.out.println( n1 );
2112                 return false;
2113             }
2114             if ( !xml_n[ 2 ].equals( n2 ) ) {
2115                 System.out.println( xml_n[ 2 ] );
2116                 System.out.println( n2 );
2117                 return false;
2118             }
2119             if ( !xml_n2[ 2 ].equals( n2 ) ) {
2120                 System.out.println( xml_n2[ 2 ] );
2121                 System.out.println( n2 );
2122                 return false;
2123             }
2124             if ( !nh_n[ 2 ].equals( n2 ) ) {
2125                 System.out.println( nh_n[ 2 ] );
2126                 System.out.println( n2 );
2127                 return false;
2128             }
2129             if ( !nex_n[ 2 ].equals( n2 ) ) {
2130                 System.out.println( nex_n[ 2 ] );
2131                 System.out.println( n2 );
2132                 return false;
2133             }
2134             //
2135             if ( !xml_n[ 3 ].equals( n3 ) ) {
2136                 System.out.println( xml_n[ 3 ] );
2137                 System.out.println( n3 );
2138                 return false;
2139             }
2140             if ( !xml_n2[ 3 ].equals( n3 ) ) {
2141                 System.out.println( xml_n2[ 3 ] );
2142                 System.out.println( n3 );
2143                 return false;
2144             }
2145             if ( !nh_n[ 3 ].equals( n3 ) ) {
2146                 System.out.println( nh_n[ 3 ] );
2147                 System.out.println( n3 );
2148                 return false;
2149             }
2150             if ( !nex_n[ 3 ].equals( n3 ) ) {
2151                 System.out.println( nex_n[ 3 ] );
2152                 System.out.println( n3 );
2153                 return false;
2154             }
2155             //
2156             if ( !xml_n[ 4 ].equals( n4 ) ) {
2157                 System.out.println( xml_n[ 4 ] );
2158                 System.out.println( n4 );
2159                 return false;
2160             }
2161             if ( !nh_n[ 4 ].equals( n4 ) ) {
2162                 System.out.println( nh_n[ 4 ] );
2163                 System.out.println( n4 );
2164                 return false;
2165             }
2166             if ( !nex_n[ 4 ].equals( n4 ) ) {
2167                 System.out.println( nex_n[ 4 ] );
2168                 System.out.println( n4 );
2169                 return false;
2170             }
2171             //
2172             if ( !xml_n[ 5 ].equals( n5 ) ) {
2173                 System.out.println( xml_n[ 5 ] );
2174                 System.out.println( n5 );
2175                 return false;
2176             }
2177             if ( !nh_n[ 5 ].equals( n5 ) ) {
2178                 System.out.println( nh_n[ 5 ] );
2179                 System.out.println( n5 );
2180                 return false;
2181             }
2182             if ( !nex_n[ 5 ].equals( n5 ) ) {
2183                 System.out.println( nex_n[ 5 ] );
2184                 System.out.println( n5 );
2185                 return false;
2186             }
2187             //
2188             if ( !xml_n[ 6 ].equals( n6 ) ) {
2189                 System.out.println( xml_n[ 6 ] );
2190                 System.out.println( n6 );
2191                 return false;
2192             }
2193             if ( !nh_n[ 6 ].equals( n6 ) ) {
2194                 System.out.println( nh_n[ 6 ] );
2195                 System.out.println( n6 );
2196                 return false;
2197             }
2198             if ( !nex_n[ 6 ].equals( n6 ) ) {
2199                 System.out.println( nex_n[ 6 ] );
2200                 System.out.println( n6 );
2201                 return false;
2202             }
2203             //
2204             if ( !xml_n[ 7 ].equals( n7 ) ) {
2205                 System.out.println( xml_n[ 7 ] );
2206                 System.out.println( n7 );
2207                 return false;
2208             }
2209             if ( !nh_n[ 7 ].equals( n7 ) ) {
2210                 System.out.println( nh_n[ 7 ] );
2211                 System.out.println( n7 );
2212                 return false;
2213             }
2214             if ( !nex_n[ 7 ].equals( n7 ) ) {
2215                 System.out.println( nex_n[ 7 ] );
2216                 System.out.println( n7 );
2217                 return false;
2218             }
2219             if ( !xml_n[ 8 ].equals( n8 ) ) {
2220                 System.out.println( xml_n[ 8 ] );
2221                 System.out.println( n8 );
2222                 return false;
2223             }
2224             if ( !nh_n[ 8 ].equals( n8 ) ) {
2225                 System.out.println( nh_n[ 8 ] );
2226                 System.out.println( n8 );
2227                 return false;
2228             }
2229             if ( !nex_n[ 8 ].equals( n8 ) ) {
2230                 System.out.println( nex_n[ 8 ] );
2231                 System.out.println( n8 );
2232                 return false;
2233             }
2234             if ( !xml_n[ 9 ].equals( n9 ) ) {
2235                 System.out.println( xml_n[ 9 ] );
2236                 System.out.println( n9 );
2237                 return false;
2238             }
2239             if ( !xml_n2[ 9 ].equals( n9 ) ) {
2240                 System.out.println( xml_n2[ 9 ] );
2241                 System.out.println( n9 );
2242                 return false;
2243             }
2244             if ( !nh_n[ 9 ].equals( n9 ) ) {
2245                 System.out.println( nh_n[ 9 ] );
2246                 System.out.println( n9 );
2247                 return false;
2248             }
2249             if ( !nex_n[ 9 ].equals( n9 ) ) {
2250                 System.out.println( nex_n[ 9 ] );
2251                 System.out.println( n9 );
2252                 return false;
2253             }
2254             if ( !phylogenies_xml[ 0 ].toNewHampshire().equals( phylogenies_nh[ 0 ].toNewHampshire() ) ) {
2255                 System.out.println( phylogenies_xml[ 0 ].toNewHampshire() );
2256                 System.out.println( phylogenies_nh[ 0 ].toNewHampshire() );
2257                 return false;
2258             }
2259             if ( !phylogenies_xml[ 0 ].toNewHampshire().equals( phylogenies_nex[ 0 ].toNewHampshire() ) ) {
2260                 System.out.println( phylogenies_xml[ 0 ].toNewHampshire() );
2261                 System.out.println( phylogenies_nex[ 0 ].toNewHampshire() );
2262                 return false;
2263             }
2264         }
2265         catch ( final Exception e ) {
2266             e.printStackTrace( System.out );
2267             return false;
2268         }
2269         return true;
2270     }
2271
2272     private static boolean testBasicPhyloXMLparsing() {
2273         try {
2274             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2275             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2276             final Phylogeny[] phylogenies_0 = factory
2277                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ), xml_parser );
2278             if ( xml_parser.getErrorCount() > 0 ) {
2279                 System.out.println( xml_parser.getErrorMessages().toString() );
2280                 return false;
2281             }
2282             if ( phylogenies_0.length != 4 ) {
2283                 return false;
2284             }
2285             final Phylogeny t1 = phylogenies_0[ 0 ];
2286             final Phylogeny t2 = phylogenies_0[ 1 ];
2287             final Phylogeny t3 = phylogenies_0[ 2 ];
2288             final Phylogeny t4 = phylogenies_0[ 3 ];
2289             if ( t1.getNumberOfExternalNodes() != 1 ) {
2290                 return false;
2291             }
2292             if ( !t1.isRooted() ) {
2293                 return false;
2294             }
2295             if ( t1.isRerootable() ) {
2296                 return false;
2297             }
2298             if ( !t1.getType().equals( "gene_tree" ) ) {
2299                 return false;
2300             }
2301             if ( t2.getNumberOfExternalNodes() != 2 ) {
2302                 return false;
2303             }
2304             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
2305                 return false;
2306             }
2307             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
2308                 return false;
2309             }
2310             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2311                 return false;
2312             }
2313             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2314                 return false;
2315             }
2316             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2317                 return false;
2318             }
2319             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2320                 return false;
2321             }
2322             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2323                     .startsWith( "actgtgggggt" ) ) {
2324                 return false;
2325             }
2326             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2327                     .startsWith( "ctgtgatgcat" ) ) {
2328                 return false;
2329             }
2330             if ( t3.getNumberOfExternalNodes() != 4 ) {
2331                 return false;
2332             }
2333             if ( !t1.getName().equals( "t1" ) ) {
2334                 return false;
2335             }
2336             if ( !t2.getName().equals( "t2" ) ) {
2337                 return false;
2338             }
2339             if ( !t3.getName().equals( "t3" ) ) {
2340                 return false;
2341             }
2342             if ( !t4.getName().equals( "t4" ) ) {
2343                 return false;
2344             }
2345             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
2346                 return false;
2347             }
2348             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
2349                 return false;
2350             }
2351             if ( !t3.getNode( "root node" ).isDuplication() ) {
2352                 return false;
2353             }
2354             if ( !t3.getNode( "node a" ).isDuplication() ) {
2355                 return false;
2356             }
2357             if ( t3.getNode( "node a" ).isSpeciation() ) {
2358                 return false;
2359             }
2360             if ( t3.getNode( "node bc" ).isDuplication() ) {
2361                 return false;
2362             }
2363             if ( !t3.getNode( "node bc" ).isSpeciation() ) {
2364                 return false;
2365             }
2366             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2367                 return false;
2368             }
2369             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
2370                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2371                 return false;
2372             }
2373             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2374                 return false;
2375             }
2376             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2377                 return false;
2378             }
2379             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2380                     .equals( "UniProtKB" ) ) {
2381                 return false;
2382             }
2383             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2384                     .equals( "apoptosis" ) ) {
2385                 return false;
2386             }
2387             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2388                     .equals( "GO:0006915" ) ) {
2389                 return false;
2390             }
2391             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2392                     .equals( "UniProtKB" ) ) {
2393                 return false;
2394             }
2395             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2396                     .equals( "experimental" ) ) {
2397                 return false;
2398             }
2399             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2400                     .equals( "function" ) ) {
2401                 return false;
2402             }
2403             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2404                     .getValue() != 1 ) {
2405                 return false;
2406             }
2407             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence().getType()
2408                     .equals( "ml" ) ) {
2409                 return false;
2410             }
2411             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2412                     .equals( "apoptosis" ) ) {
2413                 return false;
2414             }
2415             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2416                     .getProperties( "AFFY:expression" ).get( 0 ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2417                 return false;
2418             }
2419             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2420                     .getProperties( "AFFY:expression" ).get( 0 ).getDataType().equals( "xsd:double" ) ) {
2421                 return false;
2422             }
2423             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2424                     .getProperties( "AFFY:expression" ).get( 0 ).getRef().equals( "AFFY:expression" ) ) {
2425                 return false;
2426             }
2427             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2428                     .getProperties( "AFFY:expression" ).get( 0 ).getUnit().equals( "AFFY:x" ) ) {
2429                 return false;
2430             }
2431             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2432                     .getProperties( "AFFY:expression" ).get( 0 ).getValue().equals( "0.2" ) ) {
2433                 return false;
2434             }
2435             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2436                     .getProperties( "MED:disease" ).get( 0 ).getValue().equals( "lymphoma" ) ) {
2437                 return false;
2438             }
2439             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2440                     .equals( "GO:0005829" ) ) {
2441                 return false;
2442             }
2443             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2444                     .equals( "intracellular organelle" ) ) {
2445                 return false;
2446             }
2447             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2448                 return false;
2449             }
2450             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2451                     .equals( "UniProt link" ) ) ) {
2452                 return false;
2453             }
2454             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2455                 return false;
2456             }
2457             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
2458             if ( x.size() != 4 ) {
2459                 return false;
2460             }
2461             int c = 0;
2462             for( final Accession acc : x ) {
2463                 if ( c == 0 ) {
2464                     if ( !acc.getSource().equals( "KEGG" ) ) {
2465                         return false;
2466                     }
2467                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2468                         return false;
2469                     }
2470                 }
2471                 c++;
2472             }
2473         }
2474         catch ( final Exception e ) {
2475             e.printStackTrace( System.out );
2476             return false;
2477         }
2478         return true;
2479     }
2480
2481     private static boolean testBasicPhyloXMLparsingRoundtrip() {
2482         try {
2483             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2484             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2485             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2486                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2487             }
2488             else {
2489                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2490             }
2491             final Phylogeny[] phylogenies_0 = factory
2492                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ), xml_parser );
2493             if ( xml_parser.getErrorCount() > 0 ) {
2494                 System.out.println( xml_parser.getErrorMessages().toString() );
2495                 return false;
2496             }
2497             if ( phylogenies_0.length != 4 ) {
2498                 return false;
2499             }
2500             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
2501             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
2502             if ( phylogenies_t1.length != 1 ) {
2503                 return false;
2504             }
2505             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
2506             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
2507                 return false;
2508             }
2509             if ( !t1_rt.isRooted() ) {
2510                 return false;
2511             }
2512             if ( t1_rt.isRerootable() ) {
2513                 return false;
2514             }
2515             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
2516                 return false;
2517             }
2518             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
2519             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
2520             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
2521             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2522                 return false;
2523             }
2524             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2525                 return false;
2526             }
2527             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2528                 return false;
2529             }
2530             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2531                 return false;
2532             }
2533             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2534                     .startsWith( "actgtgggggt" ) ) {
2535                 return false;
2536             }
2537             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2538                     .startsWith( "ctgtgatgcat" ) ) {
2539                 return false;
2540             }
2541             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
2542             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
2543             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
2544             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
2545             if ( phylogenies_1.length != 1 ) {
2546                 return false;
2547             }
2548             final Phylogeny t3_rt = phylogenies_1[ 0 ];
2549             if ( !t3_rt.getName().equals( "t3" ) ) {
2550                 return false;
2551             }
2552             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
2553                 return false;
2554             }
2555             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
2556                 return false;
2557             }
2558             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
2559                 return false;
2560             }
2561             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2562                 return false;
2563             }
2564             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
2565                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2566                 return false;
2567             }
2568             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2569                 return false;
2570             }
2571             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue()
2572                     .equals( "Q9BZR8" ) ) {
2573                 return false;
2574             }
2575             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2576                     .equals( "UniProtKB" ) ) {
2577                 return false;
2578             }
2579             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2580                     .equals( "apoptosis" ) ) {
2581                 return false;
2582             }
2583             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2584                     .equals( "GO:0006915" ) ) {
2585                 return false;
2586             }
2587             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2588                     .equals( "UniProtKB" ) ) {
2589                 return false;
2590             }
2591             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2592                     .equals( "experimental" ) ) {
2593                 return false;
2594             }
2595             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2596                     .equals( "function" ) ) {
2597                 return false;
2598             }
2599             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2600                     .getValue() != 1 ) {
2601                 return false;
2602             }
2603             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2604                     .getType().equals( "ml" ) ) {
2605                 return false;
2606             }
2607             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2608                     .equals( "apoptosis" ) ) {
2609                 return false;
2610             }
2611             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2612                     .getProperties( "AFFY:expression" ).get( 0 ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2613                 return false;
2614             }
2615             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2616                     .getProperties( "AFFY:expression" ).get( 0 ).getDataType().equals( "xsd:double" ) ) {
2617                 return false;
2618             }
2619             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2620                     .getProperties( "AFFY:expression" ).get( 0 ).getRef().equals( "AFFY:expression" ) ) {
2621                 return false;
2622             }
2623             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2624                     .getProperties( "AFFY:expression" ).get( 0 ).getUnit().equals( "AFFY:x" ) ) {
2625                 return false;
2626             }
2627             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2628                     .getProperties( "AFFY:expression" ).get( 0 ).getValue().equals( "0.2" ) ) {
2629                 return false;
2630             }
2631             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2632                     .getProperties( "MED:disease" ).get( 0 ).getValue().equals( "lymphoma" ) ) {
2633                 return false;
2634             }
2635             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2636                     .equals( "GO:0005829" ) ) {
2637                 return false;
2638             }
2639             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2640                     .equals( "intracellular organelle" ) ) {
2641                 return false;
2642             }
2643             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType()
2644                     .equals( "source" ) ) ) {
2645                 return false;
2646             }
2647             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2648                     .equals( "UniProt link" ) ) ) {
2649                 return false;
2650             }
2651             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2652                 return false;
2653             }
2654             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi()
2655                     .equals( "10.1038/387489a0" ) ) ) {
2656                 return false;
2657             }
2658             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2659                     .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." ) ) ) {
2660                 System.out.println( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription() );
2661                 return false;
2662             }
2663             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2664                 return false;
2665             }
2666             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2667                 return false;
2668             }
2669             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName()
2670                     .equals( "molting animals" ) ) {
2671                 return false;
2672             }
2673             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2674                 return false;
2675             }
2676             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2677                     .equals( "ncbi" ) ) {
2678                 return false;
2679             }
2680             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture()
2681                     .getTotalLength() != 124 ) {
2682                 return false;
2683             }
2684             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2685                     .getName().equals( "B" ) ) {
2686                 return false;
2687             }
2688             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2689                     .getFrom() != 21 ) {
2690                 return false;
2691             }
2692             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2693                     .getTo() != 44 ) {
2694                 return false;
2695             }
2696             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2697                     .getLength() != 24 ) {
2698                 return false;
2699             }
2700             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2701                     .getConfidence() != 0 ) {
2702                 return false;
2703             }
2704             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2705                     .equals( "pfam" ) ) {
2706                 return false;
2707             }
2708             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2709                 return false;
2710             }
2711             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2712                 return false;
2713             }
2714             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2715                 return false;
2716             }
2717             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2718                 return false;
2719             }
2720             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2721             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2722                 return false;
2723             }
2724             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2725                 return false;
2726             }
2727             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2728                 return false;
2729             }
2730             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2731                 return false;
2732             }
2733             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2734                 return false;
2735             }
2736             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2737                 return false;
2738             }
2739             if ( taxbb.getSynonyms().size() != 2 ) {
2740                 return false;
2741             }
2742             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2743                 return false;
2744             }
2745             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2746                 return false;
2747             }
2748             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2749                 return false;
2750             }
2751             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2752                 return false;
2753             }
2754             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2755                 return false;
2756             }
2757             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2758                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2759                 return false;
2760             }
2761             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2762                 return false;
2763             }
2764             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2765                 return false;
2766             }
2767             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2768                 return false;
2769             }
2770             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2771                 return false;
2772             }
2773             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2774                 return false;
2775             }
2776             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2777                 return false;
2778             }
2779             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2780                 return false;
2781             }
2782             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2783                 return false;
2784             }
2785             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2786                     .equalsIgnoreCase( "435" ) ) {
2787                 return false;
2788             }
2789             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString()
2790                     .equalsIgnoreCase( "416" ) ) {
2791                 return false;
2792             }
2793             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2794                     .equalsIgnoreCase( "443.7" ) ) {
2795                 return false;
2796             }
2797             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2798                 return false;
2799             }
2800             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2801                 return false;
2802             }
2803             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2804                     .equalsIgnoreCase( "433" ) ) {
2805                 return false;
2806             }
2807             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2808                     .getCrossReferences();
2809             if ( x.size() != 4 ) {
2810                 return false;
2811             }
2812             int c = 0;
2813             for( final Accession acc : x ) {
2814                 if ( c == 0 ) {
2815                     if ( !acc.getSource().equals( "KEGG" ) ) {
2816                         return false;
2817                     }
2818                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2819                         return false;
2820                     }
2821                 }
2822                 c++;
2823             }
2824         }
2825         catch ( final Exception e ) {
2826             e.printStackTrace( System.out );
2827             return false;
2828         }
2829         return true;
2830     }
2831
2832     private static boolean testBasicPhyloXMLparsingValidating() {
2833         try {
2834             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2835             PhyloXmlParser xml_parser = null;
2836             try {
2837                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2838             }
2839             catch ( final Exception e ) {
2840                 // Do nothing -- means were not running from jar.
2841             }
2842             if ( xml_parser == null ) {
2843                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2844                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2845                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2846                 }
2847                 else {
2848                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2849                 }
2850             }
2851             final Phylogeny[] phylogenies_0 = factory
2852                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ), xml_parser );
2853             if ( xml_parser.getErrorCount() > 0 ) {
2854                 System.out.println( xml_parser.getErrorMessages().toString() );
2855                 return false;
2856             }
2857             if ( phylogenies_0.length != 4 ) {
2858                 return false;
2859             }
2860             final Phylogeny t1 = phylogenies_0[ 0 ];
2861             final Phylogeny t2 = phylogenies_0[ 1 ];
2862             final Phylogeny t3 = phylogenies_0[ 2 ];
2863             final Phylogeny t4 = phylogenies_0[ 3 ];
2864             if ( !t1.getName().equals( "t1" ) ) {
2865                 return false;
2866             }
2867             if ( !t2.getName().equals( "t2" ) ) {
2868                 return false;
2869             }
2870             if ( !t3.getName().equals( "t3" ) ) {
2871                 return false;
2872             }
2873             if ( !t4.getName().equals( "t4" ) ) {
2874                 return false;
2875             }
2876             if ( t1.getNumberOfExternalNodes() != 1 ) {
2877                 return false;
2878             }
2879             if ( t2.getNumberOfExternalNodes() != 2 ) {
2880                 return false;
2881             }
2882             if ( t3.getNumberOfExternalNodes() != 4 ) {
2883                 return false;
2884             }
2885             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2886             final Phylogeny[] phylogenies_1 = factory.create( new File( x2 ), xml_parser );
2887             if ( xml_parser.getErrorCount() > 0 ) {
2888                 System.out.println( "errors:" );
2889                 System.out.println( xml_parser.getErrorMessages().toString() );
2890                 return false;
2891             }
2892             if ( phylogenies_1.length != 4 ) {
2893                 return false;
2894             }
2895             final Phylogeny[] phylogenies_2 = factory
2896                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml" ), xml_parser );
2897             if ( xml_parser.getErrorCount() > 0 ) {
2898                 System.out.println( "errors:" );
2899                 System.out.println( xml_parser.getErrorMessages().toString() );
2900                 return false;
2901             }
2902             if ( phylogenies_2.length != 1 ) {
2903                 return false;
2904             }
2905             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2906                 return false;
2907             }
2908             final Phylogeny[] phylogenies_3 = factory
2909                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml" ), xml_parser );
2910             if ( xml_parser.getErrorCount() > 0 ) {
2911                 System.out.println( xml_parser.getErrorMessages().toString() );
2912                 return false;
2913             }
2914             if ( phylogenies_3.length != 2 ) {
2915                 return false;
2916             }
2917             final Phylogeny a = phylogenies_3[ 0 ];
2918             if ( !a.getName().equals( "tree 4" ) ) {
2919                 return false;
2920             }
2921             if ( a.getNumberOfExternalNodes() != 3 ) {
2922                 return false;
2923             }
2924             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2925                 return false;
2926             }
2927             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2928                 return false;
2929             }
2930             final Phylogeny[] phylogenies_4 = factory
2931                     .create( new File( Test.PATH_TO_TEST_DATA + "special_characters.xml" ), xml_parser );
2932             if ( xml_parser.getErrorCount() > 0 ) {
2933                 System.out.println( xml_parser.getErrorMessages().toString() );
2934                 return false;
2935             }
2936             if ( phylogenies_4.length != 1 ) {
2937                 return false;
2938             }
2939             final Phylogeny s = phylogenies_4[ 0 ];
2940             if ( s.getNumberOfExternalNodes() != 6 ) {
2941                 return false;
2942             }
2943             s.getNode( "first" );
2944             s.getNode( "<>" );
2945             s.getNode( "\"<a'b&c'd\">\"" );
2946             s.getNode( "'''\"" );
2947             s.getNode( "\"\"\"" );
2948             s.getNode( "dick & doof" );
2949         }
2950         catch ( final Exception e ) {
2951             e.printStackTrace( System.out );
2952             return false;
2953         }
2954         return true;
2955     }
2956
2957     private static boolean testPhyloXMLparsingValidating() {
2958         try {
2959             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2960             PhyloXmlParser xml_parser = null;
2961             try {
2962                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2963             }
2964             catch ( final Exception e ) {
2965                 // Do nothing -- means were not running from jar.
2966             }
2967             if ( xml_parser == null ) {
2968                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2969                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2970                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2971                 }
2972                 else {
2973                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2974                 }
2975             }
2976             final Phylogeny[] phylogenies_0 = factory
2977                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_1.xml" ), xml_parser );
2978             if ( xml_parser.getErrorCount() > 0 ) {
2979                 System.out.println( xml_parser.getErrorMessages().toString() );
2980                 return false;
2981             }
2982             if ( phylogenies_0.length != 3 ) {
2983                 return false;
2984             }
2985         }
2986         catch ( final Exception e ) {
2987             e.printStackTrace( System.out );
2988             return false;
2989         }
2990         return true;
2991     }
2992
2993     private static boolean testBasicProtein() {
2994         try {
2995             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2996             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2997             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2998             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2999             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
3000             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
3001             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
3002             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
3003             p0.addProteinDomain( y );
3004             p0.addProteinDomain( e );
3005             p0.addProteinDomain( b );
3006             p0.addProteinDomain( c );
3007             p0.addProteinDomain( d );
3008             p0.addProteinDomain( a );
3009             p0.addProteinDomain( x );
3010             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
3011                 return false;
3012             }
3013             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
3014                 return false;
3015             }
3016             //
3017             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
3018             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
3019             aa0.addProteinDomain( a1 );
3020             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
3021                 return false;
3022             }
3023             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
3024                 return false;
3025             }
3026             //
3027             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
3028             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
3029             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
3030             aa1.addProteinDomain( a11 );
3031             aa1.addProteinDomain( a12 );
3032             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
3033                 return false;
3034             }
3035             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
3036                 return false;
3037             }
3038             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
3039             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
3040                 return false;
3041             }
3042             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
3043                 return false;
3044             }
3045             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
3046                 return false;
3047             }
3048             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
3049             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
3050                 return false;
3051             }
3052             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
3053                 return false;
3054             }
3055             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
3056                 return false;
3057             }
3058             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
3059                 return false;
3060             }
3061             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
3062             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
3063                 return false;
3064             }
3065             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
3066                 return false;
3067             }
3068             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
3069                 return false;
3070             }
3071             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
3072                 return false;
3073             }
3074             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
3075             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
3076                 return false;
3077             }
3078             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
3079                 return false;
3080             }
3081             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
3082                 return false;
3083             }
3084             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
3085                 return false;
3086             }
3087             //
3088             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
3089             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
3090             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
3091             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
3092             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
3093             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
3094             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
3095             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
3096             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
3097             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
3098             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
3099             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
3100             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
3101             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
3102             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
3103             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
3104             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
3105             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
3106             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
3107             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
3108             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
3109             p00.addProteinDomain( y0 );
3110             p00.addProteinDomain( e0 );
3111             p00.addProteinDomain( b0 );
3112             p00.addProteinDomain( c0 );
3113             p00.addProteinDomain( d0 );
3114             p00.addProteinDomain( a0 );
3115             p00.addProteinDomain( x0 );
3116             p00.addProteinDomain( y1 );
3117             p00.addProteinDomain( y2 );
3118             p00.addProteinDomain( y3 );
3119             p00.addProteinDomain( e1 );
3120             p00.addProteinDomain( e2 );
3121             p00.addProteinDomain( e3 );
3122             p00.addProteinDomain( e4 );
3123             p00.addProteinDomain( e5 );
3124             p00.addProteinDomain( z0 );
3125             p00.addProteinDomain( z1 );
3126             p00.addProteinDomain( z2 );
3127             p00.addProteinDomain( zz0 );
3128             p00.addProteinDomain( zz1 );
3129             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
3130                 return false;
3131             }
3132             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
3133                 return false;
3134             }
3135             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
3136                 return false;
3137             }
3138             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
3139                 return false;
3140             }
3141             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" ) ) {
3142                 return false;
3143             }
3144             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
3145             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
3146             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
3147             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
3148             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
3149             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
3150             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
3151             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
3152             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
3153             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
3154             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
3155             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
3156             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
3157             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
3158             p.addProteinDomain( B15 );
3159             p.addProteinDomain( C50 );
3160             p.addProteinDomain( A60 );
3161             p.addProteinDomain( A30 );
3162             p.addProteinDomain( C70 );
3163             p.addProteinDomain( B35 );
3164             p.addProteinDomain( B40 );
3165             p.addProteinDomain( A0 );
3166             p.addProteinDomain( A10 );
3167             p.addProteinDomain( A20 );
3168             p.addProteinDomain( B25 );
3169             p.addProteinDomain( D80 );
3170             List<String> domains_ids = new ArrayList<String>();
3171             domains_ids.add( "A" );
3172             domains_ids.add( "B" );
3173             domains_ids.add( "C" );
3174             if ( !p.contains( domains_ids, false ) ) {
3175                 return false;
3176             }
3177             if ( !p.contains( domains_ids, true ) ) {
3178                 return false;
3179             }
3180             domains_ids.add( "X" );
3181             if ( p.contains( domains_ids, false ) ) {
3182                 return false;
3183             }
3184             if ( p.contains( domains_ids, true ) ) {
3185                 return false;
3186             }
3187             domains_ids = new ArrayList<String>();
3188             domains_ids.add( "A" );
3189             domains_ids.add( "C" );
3190             domains_ids.add( "D" );
3191             if ( !p.contains( domains_ids, false ) ) {
3192                 return false;
3193             }
3194             if ( !p.contains( domains_ids, true ) ) {
3195                 return false;
3196             }
3197             domains_ids = new ArrayList<String>();
3198             domains_ids.add( "A" );
3199             domains_ids.add( "D" );
3200             domains_ids.add( "C" );
3201             if ( !p.contains( domains_ids, false ) ) {
3202                 return false;
3203             }
3204             if ( p.contains( domains_ids, true ) ) {
3205                 return false;
3206             }
3207             domains_ids = new ArrayList<String>();
3208             domains_ids.add( "A" );
3209             domains_ids.add( "A" );
3210             domains_ids.add( "B" );
3211             if ( !p.contains( domains_ids, false ) ) {
3212                 return false;
3213             }
3214             if ( !p.contains( domains_ids, true ) ) {
3215                 return false;
3216             }
3217             domains_ids = new ArrayList<String>();
3218             domains_ids.add( "A" );
3219             domains_ids.add( "A" );
3220             domains_ids.add( "A" );
3221             domains_ids.add( "B" );
3222             domains_ids.add( "B" );
3223             if ( !p.contains( domains_ids, false ) ) {
3224                 return false;
3225             }
3226             if ( !p.contains( domains_ids, true ) ) {
3227                 return false;
3228             }
3229             domains_ids = new ArrayList<String>();
3230             domains_ids.add( "A" );
3231             domains_ids.add( "A" );
3232             domains_ids.add( "B" );
3233             domains_ids.add( "A" );
3234             domains_ids.add( "B" );
3235             domains_ids.add( "B" );
3236             domains_ids.add( "A" );
3237             domains_ids.add( "B" );
3238             domains_ids.add( "C" );
3239             domains_ids.add( "A" );
3240             domains_ids.add( "C" );
3241             domains_ids.add( "D" );
3242             if ( !p.contains( domains_ids, false ) ) {
3243                 return false;
3244             }
3245             if ( p.contains( domains_ids, true ) ) {
3246                 return false;
3247             }
3248         }
3249         catch ( final Exception e ) {
3250             e.printStackTrace( System.out );
3251             return false;
3252         }
3253         return true;
3254     }
3255
3256     private static boolean testBasicTable() {
3257         try {
3258             final BasicTable<String> t0 = new BasicTable<String>();
3259             if ( t0.getNumberOfColumns() != 0 ) {
3260                 return false;
3261             }
3262             if ( t0.getNumberOfRows() != 0 ) {
3263                 return false;
3264             }
3265             t0.setValue( 3, 2, "23" );
3266             t0.setValue( 10, 1, "error" );
3267             t0.setValue( 10, 1, "110" );
3268             t0.setValue( 9, 1, "19" );
3269             t0.setValue( 1, 10, "101" );
3270             t0.setValue( 10, 10, "1010" );
3271             t0.setValue( 100, 10, "10100" );
3272             t0.setValue( 0, 0, "00" );
3273             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3274                 return false;
3275             }
3276             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3277                 return false;
3278             }
3279             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3280                 return false;
3281             }
3282             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3283                 return false;
3284             }
3285             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3286                 return false;
3287             }
3288             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3289                 return false;
3290             }
3291             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3292                 return false;
3293             }
3294             if ( t0.getNumberOfColumns() != 101 ) {
3295                 return false;
3296             }
3297             if ( t0.getNumberOfRows() != 11 ) {
3298                 return false;
3299             }
3300             if ( t0.getValueAsString( 49, 4 ) != null ) {
3301                 return false;
3302             }
3303             final String l = ForesterUtil.getLineSeparator();
3304             final StringBuffer source = new StringBuffer();
3305             source.append( "" + l );
3306             source.append( "# 1 1 1 1 1 1 1 1" + l );
3307             source.append( " 00 01 02 03" + l );
3308             source.append( "   10 11 12 13  " + l );
3309             source.append( "20 21 22 23 " + l );
3310             source.append( "    30  31    32 33" + l );
3311             source.append( "40 41 42 43" + l );
3312             source.append( "  # 1 1 1 1 1 " + l );
3313             source.append( "50 51 52 53 54" + l );
3314             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
3315             if ( t1.getNumberOfColumns() != 5 ) {
3316                 return false;
3317             }
3318             if ( t1.getNumberOfRows() != 6 ) {
3319                 return false;
3320             }
3321             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
3322                 return false;
3323             }
3324             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
3325                 return false;
3326             }
3327             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
3328                 return false;
3329             }
3330             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
3331                 return false;
3332             }
3333             final StringBuffer source1 = new StringBuffer();
3334             source1.append( "" + l );
3335             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3336             source1.append( " 00; 01 ;02;03" + l );
3337             source1.append( "   10; 11; 12; 13  " + l );
3338             source1.append( "20; 21; 22; 23 " + l );
3339             source1.append( "    30;  31;    32; 33" + l );
3340             source1.append( "40;41;42;43" + l );
3341             source1.append( "  # 1 1 1 1 1 " + l );
3342             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
3343             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
3344             if ( t2.getNumberOfColumns() != 5 ) {
3345                 return false;
3346             }
3347             if ( t2.getNumberOfRows() != 6 ) {
3348                 return false;
3349             }
3350             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
3351                 return false;
3352             }
3353             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
3354                 return false;
3355             }
3356             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
3357                 return false;
3358             }
3359             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
3360                 return false;
3361             }
3362             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
3363                 return false;
3364             }
3365             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
3366                 return false;
3367             }
3368             final StringBuffer source2 = new StringBuffer();
3369             source2.append( "" + l );
3370             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3371             source2.append( " 00; 01 ;02;03" + l );
3372             source2.append( "   10; 11; 12; 13  " + l );
3373             source2.append( "20; 21; 22; 23 " + l );
3374             source2.append( "                     " + l );
3375             source2.append( "    30;  31;    32; 33" + l );
3376             source2.append( "40;41;42;43" + l );
3377             source2.append( "  comment: 1 1 1 1 1 " + l );
3378             source2.append( ";;;50  ;   52; 53;;54   " + l );
3379             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
3380                                                                         ';',
3381                                                                         false,
3382                                                                         false,
3383                                                                         "comment:",
3384                                                                         false );
3385             if ( tl.size() != 2 ) {
3386                 return false;
3387             }
3388             final BasicTable<String> t3 = tl.get( 0 );
3389             final BasicTable<String> t4 = tl.get( 1 );
3390             if ( t3.getNumberOfColumns() != 4 ) {
3391                 return false;
3392             }
3393             if ( t3.getNumberOfRows() != 3 ) {
3394                 return false;
3395             }
3396             if ( t4.getNumberOfColumns() != 4 ) {
3397                 return false;
3398             }
3399             if ( t4.getNumberOfRows() != 3 ) {
3400                 return false;
3401             }
3402             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
3403                 return false;
3404             }
3405             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
3406                 return false;
3407             }
3408         }
3409         catch ( final Exception e ) {
3410             e.printStackTrace( System.out );
3411             return false;
3412         }
3413         return true;
3414     }
3415
3416     private static boolean testBasicTolXMLparsing() {
3417         try {
3418             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3419             final TolParser parser = new TolParser();
3420             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
3421             if ( parser.getErrorCount() > 0 ) {
3422                 System.out.println( parser.getErrorMessages().toString() );
3423                 return false;
3424             }
3425             if ( phylogenies_0.length != 1 ) {
3426                 return false;
3427             }
3428             final Phylogeny t1 = phylogenies_0[ 0 ];
3429             if ( t1.getNumberOfExternalNodes() != 5 ) {
3430                 return false;
3431             }
3432             if ( !t1.isRooted() ) {
3433                 return false;
3434             }
3435             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
3436                 return false;
3437             }
3438             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
3439                 return false;
3440             }
3441             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3442                     .equals( "Rhombozoa" ) ) {
3443                 return false;
3444             }
3445             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
3446                 return false;
3447             }
3448             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
3449             if ( parser.getErrorCount() > 0 ) {
3450                 System.out.println( parser.getErrorMessages().toString() );
3451                 return false;
3452             }
3453             if ( phylogenies_1.length != 1 ) {
3454                 return false;
3455             }
3456             final Phylogeny t2 = phylogenies_1[ 0 ];
3457             if ( t2.getNumberOfExternalNodes() != 664 ) {
3458                 return false;
3459             }
3460             if ( !t2.isRooted() ) {
3461                 return false;
3462             }
3463             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
3464                 return false;
3465             }
3466             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
3467                 return false;
3468             }
3469             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3470                 return false;
3471             }
3472             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3473                 return false;
3474             }
3475             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3476                     .equals( "Aquificae" ) ) {
3477                 return false;
3478             }
3479             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3480                     .equals( "Aquifex" ) ) {
3481                 return false;
3482             }
3483             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
3484             if ( parser.getErrorCount() > 0 ) {
3485                 System.out.println( parser.getErrorMessages().toString() );
3486                 return false;
3487             }
3488             if ( phylogenies_2.length != 1 ) {
3489                 return false;
3490             }
3491             final Phylogeny t3 = phylogenies_2[ 0 ];
3492             if ( t3.getNumberOfExternalNodes() != 184 ) {
3493                 return false;
3494             }
3495             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
3496                 return false;
3497             }
3498             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
3499                 return false;
3500             }
3501             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
3502                 return false;
3503             }
3504             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
3505             if ( parser.getErrorCount() > 0 ) {
3506                 System.out.println( parser.getErrorMessages().toString() );
3507                 return false;
3508             }
3509             if ( phylogenies_3.length != 1 ) {
3510                 return false;
3511             }
3512             final Phylogeny t4 = phylogenies_3[ 0 ];
3513             if ( t4.getNumberOfExternalNodes() != 1 ) {
3514                 return false;
3515             }
3516             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
3517                 return false;
3518             }
3519             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
3520                 return false;
3521             }
3522             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
3523                 return false;
3524             }
3525             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
3526             if ( parser.getErrorCount() > 0 ) {
3527                 System.out.println( parser.getErrorMessages().toString() );
3528                 return false;
3529             }
3530             if ( phylogenies_4.length != 1 ) {
3531                 return false;
3532             }
3533             final Phylogeny t5 = phylogenies_4[ 0 ];
3534             if ( t5.getNumberOfExternalNodes() != 13 ) {
3535                 return false;
3536             }
3537             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
3538                 return false;
3539             }
3540             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
3541                 return false;
3542             }
3543             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
3544                 return false;
3545             }
3546         }
3547         catch ( final Exception e ) {
3548             e.printStackTrace( System.out );
3549             return false;
3550         }
3551         return true;
3552     }
3553
3554     private static boolean testBasicTreeMethods() {
3555         try {
3556             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3557             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
3558             if ( t2.getNumberOfExternalNodes() != 4 ) {
3559                 return false;
3560             }
3561             if ( t2.calculateHeight( false ) != 8.5 ) {
3562                 return false;
3563             }
3564             if ( !t2.isCompletelyBinary() ) {
3565                 return false;
3566             }
3567             if ( t2.isEmpty() ) {
3568                 return false;
3569             }
3570             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
3571             if ( t3.getNumberOfExternalNodes() != 5 ) {
3572                 return false;
3573             }
3574             if ( t3.calculateHeight( true ) != 11 ) {
3575                 return false;
3576             }
3577             if ( t3.isCompletelyBinary() ) {
3578                 return false;
3579             }
3580             final PhylogenyNode n = t3.getNode( "ABC" );
3581             final Phylogeny t4 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3,(F,G,H,I))",
3582                                                  new NHXParser() )[ 0 ];
3583             if ( t4.getNumberOfExternalNodes() != 9 ) {
3584                 return false;
3585             }
3586             if ( t4.calculateHeight( false ) != 11 ) {
3587                 return false;
3588             }
3589             if ( t4.isCompletelyBinary() ) {
3590                 return false;
3591             }
3592             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)" );
3593             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
3594             if ( t5.getNumberOfExternalNodes() != 8 ) {
3595                 return false;
3596             }
3597             if ( t5.calculateHeight( false ) != 15 ) {
3598                 return false;
3599             }
3600             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)" );
3601             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
3602             if ( t6.calculateHeight( true ) != 15 ) {
3603                 return false;
3604             }
3605             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)" );
3606             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
3607             if ( t7.calculateHeight( true ) != 15 ) {
3608                 return false;
3609             }
3610             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)" );
3611             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
3612             if ( t8.getNumberOfExternalNodes() != 10 ) {
3613                 return false;
3614             }
3615             if ( t8.calculateHeight( true ) != 15 ) {
3616                 return false;
3617             }
3618             final char[] a9 = new char[] { 'a' };
3619             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
3620             if ( t9.calculateHeight( true ) != 0 ) {
3621                 return false;
3622             }
3623             final char[] a10 = new char[] { 'a', ':', '6' };
3624             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
3625             if ( t10.calculateHeight( true ) != 6 ) {
3626                 return false;
3627             }
3628         }
3629         catch ( final Exception e ) {
3630             e.printStackTrace( System.out );
3631             return false;
3632         }
3633         return true;
3634     }
3635
3636     private static boolean testConfidenceAssessor() {
3637         try {
3638             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3639             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3640             final Phylogeny[] ev0 = factory.create(
3641                                                     "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3642                                                     new NHXParser() );
3643             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3644             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3645                 return false;
3646             }
3647             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3648                 return false;
3649             }
3650             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3651             final Phylogeny[] ev1 = factory.create(
3652                                                     "((((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)));",
3653                                                     new NHXParser() );
3654             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3655             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3656                 return false;
3657             }
3658             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3659                 return false;
3660             }
3661             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3662             final Phylogeny[] ev_b = factory.create(
3663                                                      "((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",
3664                                                      new NHXParser() );
3665             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3666             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3667                 return false;
3668             }
3669             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3670                 return false;
3671             }
3672             //
3673             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3674             final Phylogeny[] ev1x = factory.create(
3675                                                      "((((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)));",
3676                                                      new NHXParser() );
3677             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3678             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3679                 return false;
3680             }
3681             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3682                 return false;
3683             }
3684             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3685             final Phylogeny[] ev_bx = factory.create(
3686                                                       "((((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",
3687                                                       new NHXParser() );
3688             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3689             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3690                 return false;
3691             }
3692             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3693                 return false;
3694             }
3695             final Phylogeny[] t2 = factory.create(
3696                                                    "((((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);",
3697                                                    new NHXParser() );
3698             final Phylogeny[] ev2 = factory.create(
3699                                                     "((((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);",
3700                                                     new NHXParser() );
3701             for( final Phylogeny target : t2 ) {
3702                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3703             }
3704             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3705                                                  new NHXParser() )[ 0 ];
3706             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3707             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3708             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3709                 return false;
3710             }
3711             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3712                 return false;
3713             }
3714             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3715                 return false;
3716             }
3717         }
3718         catch ( final Exception e ) {
3719             e.printStackTrace();
3720             return false;
3721         }
3722         return true;
3723     }
3724
3725     private static boolean testCopyOfNodeData() {
3726         try {
3727             final PhylogenyNode n1 = PhylogenyNode
3728                     .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]" );
3729             final PhylogenyNode n2 = n1.copyNodeData();
3730             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3731                 return false;
3732             }
3733         }
3734         catch ( final Exception e ) {
3735             e.printStackTrace();
3736             return false;
3737         }
3738         return true;
3739     }
3740
3741     private static boolean testCreateBalancedPhylogeny() {
3742         try {
3743             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3744             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3745                 return false;
3746             }
3747             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3748                 return false;
3749             }
3750             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3751             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3752                 return false;
3753             }
3754             if ( p1.getNumberOfExternalNodes() != 100 ) {
3755                 return false;
3756             }
3757         }
3758         catch ( final Exception e ) {
3759             e.printStackTrace();
3760             return false;
3761         }
3762         return true;
3763     }
3764
3765     private static boolean testCreateUriForSeqWeb() {
3766         try {
3767             final PhylogenyNode n = new PhylogenyNode();
3768             n.setName( "tr|B3RJ64" );
3769             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3770                 return false;
3771             }
3772             n.setName( "B0LM41_HUMAN" );
3773             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3774                     .equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3775                 return false;
3776             }
3777             n.setName( "NP_001025424" );
3778             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3779                     .equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3780                 return false;
3781             }
3782             n.setName( "_NM_001030253-" );
3783             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3784                     .equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3785                 return false;
3786             }
3787             n.setName( "XM_002122186" );
3788             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3789                     .equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3790                 return false;
3791             }
3792             n.setName( "dgh_AAA34956_gdg" );
3793             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3794                 return false;
3795             }
3796             n.setName( "AAA34956" );
3797             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3798                 return false;
3799             }
3800             n.setName( "GI:394892" );
3801             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3802                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3803                 return false;
3804             }
3805             n.setName( "gi_394892" );
3806             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3807                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3808                 return false;
3809             }
3810             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3811             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3812                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3813                 return false;
3814             }
3815             n.setName( "P12345" );
3816             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3817                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3818                 return false;
3819             }
3820             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3821             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3822                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3823                 return false;
3824             }
3825         }
3826         catch ( final Exception e ) {
3827             e.printStackTrace( System.out );
3828             return false;
3829         }
3830         return true;
3831     }
3832
3833     private static boolean testDataObjects() {
3834         try {
3835             final Confidence s0 = new Confidence();
3836             final Confidence s1 = new Confidence();
3837             if ( !s0.isEqual( s1 ) ) {
3838                 return false;
3839             }
3840             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3841             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3842             if ( s2.isEqual( s1 ) ) {
3843                 return false;
3844             }
3845             if ( !s2.isEqual( s3 ) ) {
3846                 return false;
3847             }
3848             final Confidence s4 = ( Confidence ) s3.copy();
3849             if ( !s4.isEqual( s3 ) ) {
3850                 return false;
3851             }
3852             s3.asSimpleText();
3853             s3.asText();
3854             // Taxonomy
3855             // ----------
3856             final Taxonomy t1 = new Taxonomy();
3857             final Taxonomy t2 = new Taxonomy();
3858             final Taxonomy t3 = new Taxonomy();
3859             final Taxonomy t4 = new Taxonomy();
3860             final Taxonomy t5 = new Taxonomy();
3861             t1.setIdentifier( new Identifier( "ecoli" ) );
3862             t1.setTaxonomyCode( "ECOLI" );
3863             t1.setScientificName( "E. coli" );
3864             t1.setCommonName( "coli" );
3865             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3866             if ( !t1.isEqual( t0 ) ) {
3867                 return false;
3868             }
3869             t2.setIdentifier( new Identifier( "ecoli" ) );
3870             t2.setTaxonomyCode( "OTHER" );
3871             t2.setScientificName( "what" );
3872             t2.setCommonName( "something" );
3873             if ( !t1.isEqual( t2 ) ) {
3874                 return false;
3875             }
3876             t2.setIdentifier( new Identifier( "nemve" ) );
3877             if ( t1.isEqual( t2 ) ) {
3878                 return false;
3879             }
3880             t1.setIdentifier( null );
3881             t3.setTaxonomyCode( "ECOLI" );
3882             t3.setScientificName( "what" );
3883             t3.setCommonName( "something" );
3884             if ( !t1.isEqual( t3 ) ) {
3885                 return false;
3886             }
3887             t1.setIdentifier( null );
3888             t1.setTaxonomyCode( "" );
3889             t4.setScientificName( "E. ColI" );
3890             t4.setCommonName( "something" );
3891             if ( !t1.isEqual( t4 ) ) {
3892                 return false;
3893             }
3894             t4.setScientificName( "B. subtilis" );
3895             t4.setCommonName( "something" );
3896             if ( t1.isEqual( t4 ) ) {
3897                 return false;
3898             }
3899             t1.setIdentifier( null );
3900             t1.setTaxonomyCode( "" );
3901             t1.setScientificName( "" );
3902             t5.setCommonName( "COLI" );
3903             if ( !t1.isEqual( t5 ) ) {
3904                 return false;
3905             }
3906             t5.setCommonName( "vibrio" );
3907             if ( t1.isEqual( t5 ) ) {
3908                 return false;
3909             }
3910             // Identifier
3911             // ----------
3912             final Identifier id0 = new Identifier( "123", "pfam" );
3913             final Identifier id1 = ( Identifier ) id0.copy();
3914             if ( !id1.isEqual( id1 ) ) {
3915                 return false;
3916             }
3917             if ( !id1.isEqual( id0 ) ) {
3918                 return false;
3919             }
3920             if ( !id0.isEqual( id1 ) ) {
3921                 return false;
3922             }
3923             id1.asSimpleText();
3924             id1.asText();
3925             // ProteinDomain
3926             // ---------------
3927             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3928             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3929             if ( !pd1.isEqual( pd1 ) ) {
3930                 return false;
3931             }
3932             if ( !pd1.isEqual( pd0 ) ) {
3933                 return false;
3934             }
3935             pd1.asSimpleText();
3936             pd1.asText();
3937             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3938             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3939             if ( !pd3.isEqual( pd3 ) ) {
3940                 return false;
3941             }
3942             if ( !pd2.isEqual( pd3 ) ) {
3943                 return false;
3944             }
3945             if ( !pd0.isEqual( pd3 ) ) {
3946                 return false;
3947             }
3948             pd3.asSimpleText();
3949             pd3.asText();
3950             // DomainArchitecture
3951             // ------------------
3952             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3953             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3954             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3955             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3956             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3957             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3958             domains0.add( d2 );
3959             domains0.add( d0 );
3960             domains0.add( d3 );
3961             domains0.add( d1 );
3962             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3963             if ( ds0.getNumberOfDomains() != 4 ) {
3964                 return false;
3965             }
3966             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3967             if ( !ds0.isEqual( ds0 ) ) {
3968                 return false;
3969             }
3970             if ( !ds0.isEqual( ds1 ) ) {
3971                 return false;
3972             }
3973             if ( ds1.getNumberOfDomains() != 4 ) {
3974                 return false;
3975             }
3976             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3977             domains1.add( d1 );
3978             domains1.add( d2 );
3979             domains1.add( d4 );
3980             domains1.add( d0 );
3981             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3982             if ( ds0.isEqual( ds2 ) ) {
3983                 return false;
3984             }
3985             ds1.asSimpleText();
3986             ds1.asText();
3987             ds1.toNHX();
3988             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3989             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3990                 System.out.println( ds3.toNHX() );
3991                 return false;
3992             }
3993             if ( ds3.getNumberOfDomains() != 3 ) {
3994                 return false;
3995             }
3996             // Event
3997             // -----
3998             final Event e1 = new Event( Event.EventType.fusion );
3999             if ( e1.isDuplication() ) {
4000                 return false;
4001             }
4002             if ( !e1.isFusion() ) {
4003                 return false;
4004             }
4005             if ( !e1.asText().toString().equals( "fusion" ) ) {
4006                 return false;
4007             }
4008             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
4009                 return false;
4010             }
4011             final Event e11 = new Event( Event.EventType.fusion );
4012             if ( !e11.isEqual( e1 ) ) {
4013                 return false;
4014             }
4015             if ( !e11.toNHX().toString().equals( "" ) ) {
4016                 return false;
4017             }
4018             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
4019             if ( e2.isDuplication() ) {
4020                 return false;
4021             }
4022             if ( !e2.isSpeciationOrDuplication() ) {
4023                 return false;
4024             }
4025             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
4026                 return false;
4027             }
4028             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
4029                 return false;
4030             }
4031             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
4032                 return false;
4033             }
4034             if ( e11.isEqual( e2 ) ) {
4035                 return false;
4036             }
4037             final Event e2c = ( Event ) e2.copy();
4038             if ( !e2c.isEqual( e2 ) ) {
4039                 return false;
4040             }
4041             Event e3 = new Event( 1, 2, 3 );
4042             if ( e3.isDuplication() ) {
4043                 return false;
4044             }
4045             if ( e3.isSpeciation() ) {
4046                 return false;
4047             }
4048             if ( e3.isGeneLoss() ) {
4049                 return false;
4050             }
4051             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
4052                 return false;
4053             }
4054             final Event e3c = ( Event ) e3.copy();
4055             final Event e3cc = ( Event ) e3c.copy();
4056             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
4057                 return false;
4058             }
4059             e3 = null;
4060             if ( !e3c.isEqual( e3cc ) ) {
4061                 return false;
4062             }
4063             Event e4 = new Event( 1, 2, 3 );
4064             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
4065                 return false;
4066             }
4067             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
4068                 return false;
4069             }
4070             final Event e4c = ( Event ) e4.copy();
4071             e4 = null;
4072             final Event e4cc = ( Event ) e4c.copy();
4073             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
4074                 return false;
4075             }
4076             if ( !e4c.isEqual( e4cc ) ) {
4077                 return false;
4078             }
4079             final Event e5 = new Event();
4080             if ( !e5.isUnassigned() ) {
4081                 return false;
4082             }
4083             if ( !e5.asText().toString().equals( "unassigned" ) ) {
4084                 return false;
4085             }
4086             if ( !e5.asSimpleText().toString().equals( "" ) ) {
4087                 return false;
4088             }
4089             final Event e6 = new Event( 1, 0, 0 );
4090             if ( !e6.asText().toString().equals( "duplication" ) ) {
4091                 return false;
4092             }
4093             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
4094                 return false;
4095             }
4096             final Event e7 = new Event( 0, 1, 0 );
4097             if ( !e7.asText().toString().equals( "speciation" ) ) {
4098                 return false;
4099             }
4100             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
4101                 return false;
4102             }
4103             final Event e8 = new Event( 0, 0, 1 );
4104             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
4105                 return false;
4106             }
4107             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
4108                 return false;
4109             }
4110         }
4111         catch ( final Exception e ) {
4112             e.printStackTrace( System.out );
4113             return false;
4114         }
4115         return true;
4116     }
4117
4118     private static boolean testDeletionOfExternalNodes() {
4119         try {
4120             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4121             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
4122             final PhylogenyWriter w = new PhylogenyWriter();
4123             if ( t0.isEmpty() ) {
4124                 return false;
4125             }
4126             if ( t0.getNumberOfExternalNodes() != 1 ) {
4127                 return false;
4128             }
4129             t0.deleteSubtree( t0.getNode( "A" ), false );
4130             if ( t0.getNumberOfExternalNodes() != 0 ) {
4131                 return false;
4132             }
4133             if ( !t0.isEmpty() ) {
4134                 return false;
4135             }
4136             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
4137             if ( t1.getNumberOfExternalNodes() != 2 ) {
4138                 return false;
4139             }
4140             t1.deleteSubtree( t1.getNode( "A" ), false );
4141             if ( t1.getNumberOfExternalNodes() != 1 ) {
4142                 return false;
4143             }
4144             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
4145                 return false;
4146             }
4147             t1.deleteSubtree( t1.getNode( "B" ), false );
4148             if ( t1.getNumberOfExternalNodes() != 1 ) {
4149                 return false;
4150             }
4151             t1.deleteSubtree( t1.getNode( "r" ), false );
4152             if ( !t1.isEmpty() ) {
4153                 return false;
4154             }
4155             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
4156             if ( t2.getNumberOfExternalNodes() != 3 ) {
4157                 return false;
4158             }
4159             t2.deleteSubtree( t2.getNode( "B" ), false );
4160             if ( t2.getNumberOfExternalNodes() != 2 ) {
4161                 return false;
4162             }
4163             t2.toNewHampshireX();
4164             PhylogenyNode n = t2.getNode( "A" );
4165             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
4166                 return false;
4167             }
4168             t2.deleteSubtree( t2.getNode( "A" ), false );
4169             if ( t2.getNumberOfExternalNodes() != 2 ) {
4170                 return false;
4171             }
4172             t2.deleteSubtree( t2.getNode( "C" ), true );
4173             if ( t2.getNumberOfExternalNodes() != 1 ) {
4174                 return false;
4175             }
4176             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4177             if ( t3.getNumberOfExternalNodes() != 4 ) {
4178                 return false;
4179             }
4180             t3.deleteSubtree( t3.getNode( "B" ), true );
4181             if ( t3.getNumberOfExternalNodes() != 3 ) {
4182                 return false;
4183             }
4184             n = t3.getNode( "A" );
4185             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
4186                 return false;
4187             }
4188             n = n.getNextExternalNode();
4189             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
4190                 return false;
4191             }
4192             t3.deleteSubtree( t3.getNode( "A" ), true );
4193             if ( t3.getNumberOfExternalNodes() != 2 ) {
4194                 return false;
4195             }
4196             n = t3.getNode( "C" );
4197             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
4198                 return false;
4199             }
4200             t3.deleteSubtree( t3.getNode( "C" ), true );
4201             if ( t3.getNumberOfExternalNodes() != 1 ) {
4202                 return false;
4203             }
4204             t3.deleteSubtree( t3.getNode( "D" ), true );
4205             if ( t3.getNumberOfExternalNodes() != 0 ) {
4206                 return false;
4207             }
4208             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4209             if ( t4.getNumberOfExternalNodes() != 6 ) {
4210                 return false;
4211             }
4212             t4.deleteSubtree( t4.getNode( "B2" ), true );
4213             if ( t4.getNumberOfExternalNodes() != 5 ) {
4214                 return false;
4215             }
4216             String s = w.toNewHampshire( t4, true ).toString();
4217             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
4218                 return false;
4219             }
4220             t4.deleteSubtree( t4.getNode( "B11" ), true );
4221             if ( t4.getNumberOfExternalNodes() != 4 ) {
4222                 return false;
4223             }
4224             t4.deleteSubtree( t4.getNode( "C" ), true );
4225             if ( t4.getNumberOfExternalNodes() != 3 ) {
4226                 return false;
4227             }
4228             n = t4.getNode( "A" );
4229             n = n.getNextExternalNode();
4230             if ( !n.getName().equals( "B12" ) ) {
4231                 return false;
4232             }
4233             n = n.getNextExternalNode();
4234             if ( !n.getName().equals( "D" ) ) {
4235                 return false;
4236             }
4237             s = w.toNewHampshire( t4, true ).toString();
4238             if ( !s.equals( "((A,B12),D);" ) ) {
4239                 return false;
4240             }
4241             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4242             t5.deleteSubtree( t5.getNode( "A" ), true );
4243             if ( t5.getNumberOfExternalNodes() != 5 ) {
4244                 return false;
4245             }
4246             s = w.toNewHampshire( t5, true ).toString();
4247             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
4248                 return false;
4249             }
4250             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4251             t6.deleteSubtree( t6.getNode( "B11" ), true );
4252             if ( t6.getNumberOfExternalNodes() != 5 ) {
4253                 return false;
4254             }
4255             s = w.toNewHampshire( t6, false ).toString();
4256             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
4257                 return false;
4258             }
4259             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4260             t7.deleteSubtree( t7.getNode( "B12" ), true );
4261             if ( t7.getNumberOfExternalNodes() != 5 ) {
4262                 return false;
4263             }
4264             s = w.toNewHampshire( t7, true ).toString();
4265             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
4266                 return false;
4267             }
4268             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4269             t8.deleteSubtree( t8.getNode( "B2" ), true );
4270             if ( t8.getNumberOfExternalNodes() != 5 ) {
4271                 return false;
4272             }
4273             s = w.toNewHampshire( t8, false ).toString();
4274             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
4275                 return false;
4276             }
4277             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4278             t9.deleteSubtree( t9.getNode( "C" ), true );
4279             if ( t9.getNumberOfExternalNodes() != 5 ) {
4280                 return false;
4281             }
4282             s = w.toNewHampshire( t9, true ).toString();
4283             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
4284                 return false;
4285             }
4286             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4287             t10.deleteSubtree( t10.getNode( "D" ), true );
4288             if ( t10.getNumberOfExternalNodes() != 5 ) {
4289                 return false;
4290             }
4291             s = w.toNewHampshire( t10, true ).toString();
4292             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
4293                 return false;
4294             }
4295             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
4296             t11.deleteSubtree( t11.getNode( "A" ), true );
4297             if ( t11.getNumberOfExternalNodes() != 2 ) {
4298                 return false;
4299             }
4300             s = w.toNewHampshire( t11, true ).toString();
4301             if ( !s.equals( "(B,C);" ) ) {
4302                 return false;
4303             }
4304             t11.deleteSubtree( t11.getNode( "C" ), true );
4305             if ( t11.getNumberOfExternalNodes() != 1 ) {
4306                 return false;
4307             }
4308             s = w.toNewHampshire( t11, false ).toString();
4309             if ( !s.equals( "B;" ) ) {
4310                 return false;
4311             }
4312             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
4313             t12.deleteSubtree( t12.getNode( "B2" ), true );
4314             if ( t12.getNumberOfExternalNodes() != 8 ) {
4315                 return false;
4316             }
4317             s = w.toNewHampshire( t12, true ).toString();
4318             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
4319                 return false;
4320             }
4321             t12.deleteSubtree( t12.getNode( "B3" ), true );
4322             if ( t12.getNumberOfExternalNodes() != 7 ) {
4323                 return false;
4324             }
4325             s = w.toNewHampshire( t12, true ).toString();
4326             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
4327                 return false;
4328             }
4329             t12.deleteSubtree( t12.getNode( "C3" ), true );
4330             if ( t12.getNumberOfExternalNodes() != 6 ) {
4331                 return false;
4332             }
4333             s = w.toNewHampshire( t12, true ).toString();
4334             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
4335                 return false;
4336             }
4337             t12.deleteSubtree( t12.getNode( "A1" ), true );
4338             if ( t12.getNumberOfExternalNodes() != 5 ) {
4339                 return false;
4340             }
4341             s = w.toNewHampshire( t12, true ).toString();
4342             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
4343                 return false;
4344             }
4345             t12.deleteSubtree( t12.getNode( "B1" ), true );
4346             if ( t12.getNumberOfExternalNodes() != 4 ) {
4347                 return false;
4348             }
4349             s = w.toNewHampshire( t12, true ).toString();
4350             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
4351                 return false;
4352             }
4353             t12.deleteSubtree( t12.getNode( "A3" ), true );
4354             if ( t12.getNumberOfExternalNodes() != 3 ) {
4355                 return false;
4356             }
4357             s = w.toNewHampshire( t12, true ).toString();
4358             if ( !s.equals( "(A2,(C1,C2));" ) ) {
4359                 return false;
4360             }
4361             t12.deleteSubtree( t12.getNode( "A2" ), true );
4362             if ( t12.getNumberOfExternalNodes() != 2 ) {
4363                 return false;
4364             }
4365             s = w.toNewHampshire( t12, true ).toString();
4366             if ( !s.equals( "(C1,C2);" ) ) {
4367                 return false;
4368             }
4369             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
4370             t13.deleteSubtree( t13.getNode( "D" ), true );
4371             if ( t13.getNumberOfExternalNodes() != 4 ) {
4372                 return false;
4373             }
4374             s = w.toNewHampshire( t13, true ).toString();
4375             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
4376                 return false;
4377             }
4378             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
4379             t14.deleteSubtree( t14.getNode( "E" ), true );
4380             if ( t14.getNumberOfExternalNodes() != 5 ) {
4381                 return false;
4382             }
4383             s = w.toNewHampshire( t14, true ).toString();
4384             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
4385                 return false;
4386             }
4387             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
4388             t15.deleteSubtree( t15.getNode( "B2" ), true );
4389             if ( t15.getNumberOfExternalNodes() != 11 ) {
4390                 return false;
4391             }
4392             t15.deleteSubtree( t15.getNode( "B1" ), true );
4393             if ( t15.getNumberOfExternalNodes() != 10 ) {
4394                 return false;
4395             }
4396             t15.deleteSubtree( t15.getNode( "B3" ), true );
4397             if ( t15.getNumberOfExternalNodes() != 9 ) {
4398                 return false;
4399             }
4400             t15.deleteSubtree( t15.getNode( "B4" ), true );
4401             if ( t15.getNumberOfExternalNodes() != 8 ) {
4402                 return false;
4403             }
4404             t15.deleteSubtree( t15.getNode( "A1" ), true );
4405             if ( t15.getNumberOfExternalNodes() != 7 ) {
4406                 return false;
4407             }
4408             t15.deleteSubtree( t15.getNode( "C4" ), true );
4409             if ( t15.getNumberOfExternalNodes() != 6 ) {
4410                 return false;
4411             }
4412         }
4413         catch ( final Exception e ) {
4414             e.printStackTrace( System.out );
4415             return false;
4416         }
4417         return true;
4418     }
4419
4420     private static boolean testDescriptiveStatistics() {
4421         try {
4422             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
4423             dss1.addValue( 82 );
4424             dss1.addValue( 78 );
4425             dss1.addValue( 70 );
4426             dss1.addValue( 58 );
4427             dss1.addValue( 42 );
4428             if ( dss1.getN() != 5 ) {
4429                 return false;
4430             }
4431             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
4432                 return false;
4433             }
4434             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
4435                 return false;
4436             }
4437             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
4438                 return false;
4439             }
4440             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
4441                 return false;
4442             }
4443             if ( !Test.isEqual( dss1.median(), 70 ) ) {
4444                 return false;
4445             }
4446             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
4447                 return false;
4448             }
4449             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
4450                 return false;
4451             }
4452             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
4453                 return false;
4454             }
4455             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
4456                 return false;
4457             }
4458             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
4459                 return false;
4460             }
4461             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
4462                 return false;
4463             }
4464             dss1.addValue( 123 );
4465             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
4466                 return false;
4467             }
4468             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
4469                 return false;
4470             }
4471             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
4472                 return false;
4473             }
4474             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
4475             dss2.addValue( -1.85 );
4476             dss2.addValue( 57.5 );
4477             dss2.addValue( 92.78 );
4478             dss2.addValue( 57.78 );
4479             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
4480                 return false;
4481             }
4482             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
4483                 return false;
4484             }
4485             final double[] a = dss2.getDataAsDoubleArray();
4486             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
4487                 return false;
4488             }
4489             dss2.addValue( -100 );
4490             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
4491                 return false;
4492             }
4493             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
4494                 return false;
4495             }
4496             final double[] ds = new double[ 14 ];
4497             ds[ 0 ] = 34;
4498             ds[ 1 ] = 23;
4499             ds[ 2 ] = 1;
4500             ds[ 3 ] = 32;
4501             ds[ 4 ] = 11;
4502             ds[ 5 ] = 2;
4503             ds[ 6 ] = 12;
4504             ds[ 7 ] = 33;
4505             ds[ 8 ] = 13;
4506             ds[ 9 ] = 22;
4507             ds[ 10 ] = 21;
4508             ds[ 11 ] = 35;
4509             ds[ 12 ] = 24;
4510             ds[ 13 ] = 31;
4511             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
4512             if ( bins.length != 4 ) {
4513                 return false;
4514             }
4515             if ( bins[ 0 ] != 2 ) {
4516                 return false;
4517             }
4518             if ( bins[ 1 ] != 3 ) {
4519                 return false;
4520             }
4521             if ( bins[ 2 ] != 4 ) {
4522                 return false;
4523             }
4524             if ( bins[ 3 ] != 5 ) {
4525                 return false;
4526             }
4527             final double[] ds1 = new double[ 9 ];
4528             ds1[ 0 ] = 10.0;
4529             ds1[ 1 ] = 19.0;
4530             ds1[ 2 ] = 9.999;
4531             ds1[ 3 ] = 0.0;
4532             ds1[ 4 ] = 39.9;
4533             ds1[ 5 ] = 39.999;
4534             ds1[ 6 ] = 30.0;
4535             ds1[ 7 ] = 19.999;
4536             ds1[ 8 ] = 30.1;
4537             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
4538             if ( bins1.length != 4 ) {
4539                 return false;
4540             }
4541             if ( bins1[ 0 ] != 2 ) {
4542                 return false;
4543             }
4544             if ( bins1[ 1 ] != 3 ) {
4545                 return false;
4546             }
4547             if ( bins1[ 2 ] != 0 ) {
4548                 return false;
4549             }
4550             if ( bins1[ 3 ] != 4 ) {
4551                 return false;
4552             }
4553             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
4554             if ( bins1_1.length != 3 ) {
4555                 return false;
4556             }
4557             if ( bins1_1[ 0 ] != 3 ) {
4558                 return false;
4559             }
4560             if ( bins1_1[ 1 ] != 2 ) {
4561                 return false;
4562             }
4563             if ( bins1_1[ 2 ] != 4 ) {
4564                 return false;
4565             }
4566             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
4567             if ( bins1_2.length != 3 ) {
4568                 return false;
4569             }
4570             if ( bins1_2[ 0 ] != 2 ) {
4571                 return false;
4572             }
4573             if ( bins1_2[ 1 ] != 2 ) {
4574                 return false;
4575             }
4576             if ( bins1_2[ 2 ] != 2 ) {
4577                 return false;
4578             }
4579             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
4580             dss3.addValue( 1 );
4581             dss3.addValue( 1 );
4582             dss3.addValue( 1 );
4583             dss3.addValue( 2 );
4584             dss3.addValue( 3 );
4585             dss3.addValue( 4 );
4586             dss3.addValue( 5 );
4587             dss3.addValue( 5 );
4588             dss3.addValue( 5 );
4589             dss3.addValue( 6 );
4590             dss3.addValue( 7 );
4591             dss3.addValue( 8 );
4592             dss3.addValue( 9 );
4593             dss3.addValue( 10 );
4594             dss3.addValue( 10 );
4595             dss3.addValue( 10 );
4596             final AsciiHistogram histo = new AsciiHistogram( dss3 );
4597             histo.toStringBuffer( 10, '=', 40, 5 );
4598             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
4599         }
4600         catch ( final Exception e ) {
4601             e.printStackTrace( System.out );
4602             return false;
4603         }
4604         return true;
4605     }
4606
4607     private static boolean testDir( final String file ) {
4608         try {
4609             final File f = new File( file );
4610             if ( !f.exists() ) {
4611                 return false;
4612             }
4613             if ( !f.isDirectory() ) {
4614                 return false;
4615             }
4616             if ( !f.canRead() ) {
4617                 return false;
4618             }
4619         }
4620         catch ( final Exception e ) {
4621             return false;
4622         }
4623         return true;
4624     }
4625
4626     private static boolean testEbiEntryRetrieval() {
4627         try {
4628             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
4629             if ( !entry.getAccession().equals( "AAK41263" ) ) {
4630                 System.out.println( entry.getAccession() );
4631                 return false;
4632             }
4633             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
4634                 System.out.println( entry.getTaxonomyScientificName() );
4635                 return false;
4636             }
4637             if ( !entry.getSequenceName()
4638                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4639                 System.out.println( entry.getSequenceName() );
4640                 return false;
4641             }
4642             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4643                 System.out.println( entry.getGeneName() );
4644                 return false;
4645             }
4646             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4647                 System.out.println( entry.getTaxonomyIdentifier() );
4648                 return false;
4649             }
4650             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4651                 System.out.println( entry.getAnnotations().first().getRefValue() );
4652                 return false;
4653             }
4654             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4655                 System.out.println( entry.getAnnotations().first().getRefSource() );
4656                 return false;
4657             }
4658             if ( entry.getCrossReferences().size() < 1 ) {
4659                 return false;
4660             }
4661             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4662             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4663                 return false;
4664             }
4665             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4666                 System.out.println( entry1.getTaxonomyScientificName() );
4667                 return false;
4668             }
4669             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4670                 System.out.println( entry1.getSequenceName() );
4671                 return false;
4672             }
4673             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4674                 System.out.println( entry1.getTaxonomyIdentifier() );
4675                 return false;
4676             }
4677             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4678                 System.out.println( entry1.getGeneName() );
4679                 return false;
4680             }
4681             if ( entry1.getCrossReferences().size() < 1 ) {
4682                 return false;
4683             }
4684             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4685             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4686                 return false;
4687             }
4688             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4689                 System.out.println( entry2.getTaxonomyScientificName() );
4690                 return false;
4691             }
4692             if ( !entry2.getSequenceName()
4693                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4694                 System.out.println( entry2.getSequenceName() );
4695                 return false;
4696             }
4697             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4698                 System.out.println( entry2.getTaxonomyIdentifier() );
4699                 return false;
4700             }
4701             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4702                 System.out.println( entry2.getGeneName() );
4703                 return false;
4704             }
4705             if ( entry2.getCrossReferences().size() < 1 ) {
4706                 return false;
4707             }
4708             if ( !entry2.getChromosome().equals( "20" ) ) {
4709                 return false;
4710             }
4711             if ( !entry2.getMap().equals( "20q11.22" ) ) {
4712                 return false;
4713             }
4714             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4715             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4716                 return false;
4717             }
4718             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4719                 System.out.println( entry3.getTaxonomyScientificName() );
4720                 return false;
4721             }
4722             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4723                 System.out.println( entry3.getSequenceName() );
4724                 return false;
4725             }
4726             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4727                 System.out.println( entry3.getTaxonomyIdentifier() );
4728                 return false;
4729             }
4730             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4731                 System.out.println( entry3.getSequenceSymbol() );
4732                 return false;
4733             }
4734             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4735                 return false;
4736             }
4737             if ( entry3.getCrossReferences().size() < 1 ) {
4738                 return false;
4739             }
4740             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4741             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4742                 return false;
4743             }
4744             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4745                 System.out.println( entry4.getTaxonomyScientificName() );
4746                 return false;
4747             }
4748             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4749                 System.out.println( entry4.getSequenceName() );
4750                 return false;
4751             }
4752             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4753                 System.out.println( entry4.getTaxonomyIdentifier() );
4754                 return false;
4755             }
4756             if ( !entry4.getGeneName().equals( "ras" ) ) {
4757                 System.out.println( entry4.getGeneName() );
4758                 return false;
4759             }
4760             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4761             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4762                 return false;
4763             }
4764             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4765                 System.out.println( entry5.getTaxonomyScientificName() );
4766                 return false;
4767             }
4768             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4769                 System.out.println( entry5.getSequenceName() );
4770                 return false;
4771             }
4772             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4773                 System.out.println( entry5.getTaxonomyIdentifier() );
4774                 return false;
4775             }
4776             final SequenceDatabaseEntry entry6 = SequenceDbWsTools.obtainEntry( "M30539" );
4777             if ( !entry6.getAccession().equals( "M30539" ) ) {
4778                 return false;
4779             }
4780             if ( !entry6.getGeneName().equals( "ras" ) ) {
4781                 return false;
4782             }
4783             if ( !entry6.getSequenceName().equals( "Human SK2 c-Ha-ras-1 oncogene-encoded protein gene, exon 1" ) ) {
4784                 return false;
4785             }
4786             if ( !entry6.getTaxonomyIdentifier().equals( "9606" ) ) {
4787                 return false;
4788             }
4789             if ( !entry6.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4790                 return false;
4791             }
4792             if ( entry6.getCrossReferences().size() < 1 ) {
4793                 return false;
4794             }
4795         }
4796         catch ( final IOException e ) {
4797             System.out.println();
4798             System.out.println( "the following might be due to absence internet connection:" );
4799             e.printStackTrace( System.out );
4800             return true;
4801         }
4802         catch ( final Exception e ) {
4803             e.printStackTrace();
4804             return false;
4805         }
4806         return true;
4807     }
4808
4809     private static boolean testExternalNodeRelatedMethods() {
4810         try {
4811             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4812             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4813             PhylogenyNode n = t1.getNode( "A" );
4814             n = n.getNextExternalNode();
4815             if ( !n.getName().equals( "B" ) ) {
4816                 return false;
4817             }
4818             n = n.getNextExternalNode();
4819             if ( !n.getName().equals( "C" ) ) {
4820                 return false;
4821             }
4822             n = n.getNextExternalNode();
4823             if ( !n.getName().equals( "D" ) ) {
4824                 return false;
4825             }
4826             n = t1.getNode( "B" );
4827             while ( !n.isLastExternalNode() ) {
4828                 n = n.getNextExternalNode();
4829             }
4830             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4831             n = t2.getNode( "A" );
4832             n = n.getNextExternalNode();
4833             if ( !n.getName().equals( "B" ) ) {
4834                 return false;
4835             }
4836             n = n.getNextExternalNode();
4837             if ( !n.getName().equals( "C" ) ) {
4838                 return false;
4839             }
4840             n = n.getNextExternalNode();
4841             if ( !n.getName().equals( "D" ) ) {
4842                 return false;
4843             }
4844             n = t2.getNode( "B" );
4845             while ( !n.isLastExternalNode() ) {
4846                 n = n.getNextExternalNode();
4847             }
4848             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4849             n = t3.getNode( "A" );
4850             n = n.getNextExternalNode();
4851             if ( !n.getName().equals( "B" ) ) {
4852                 return false;
4853             }
4854             n = n.getNextExternalNode();
4855             if ( !n.getName().equals( "C" ) ) {
4856                 return false;
4857             }
4858             n = n.getNextExternalNode();
4859             if ( !n.getName().equals( "D" ) ) {
4860                 return false;
4861             }
4862             n = n.getNextExternalNode();
4863             if ( !n.getName().equals( "E" ) ) {
4864                 return false;
4865             }
4866             n = n.getNextExternalNode();
4867             if ( !n.getName().equals( "F" ) ) {
4868                 return false;
4869             }
4870             n = n.getNextExternalNode();
4871             if ( !n.getName().equals( "G" ) ) {
4872                 return false;
4873             }
4874             n = n.getNextExternalNode();
4875             if ( !n.getName().equals( "H" ) ) {
4876                 return false;
4877             }
4878             n = t3.getNode( "B" );
4879             while ( !n.isLastExternalNode() ) {
4880                 n = n.getNextExternalNode();
4881             }
4882             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4883             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4884                 final PhylogenyNode node = iter.next();
4885             }
4886             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4887             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4888                 final PhylogenyNode node = iter.next();
4889             }
4890             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))",
4891                                                  new NHXParser() )[ 0 ];
4892             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4893             if ( !iter.next().getName().equals( "A" ) ) {
4894                 return false;
4895             }
4896             if ( !iter.next().getName().equals( "B" ) ) {
4897                 return false;
4898             }
4899             if ( !iter.next().getName().equals( "C" ) ) {
4900                 return false;
4901             }
4902             if ( !iter.next().getName().equals( "D" ) ) {
4903                 return false;
4904             }
4905             if ( !iter.next().getName().equals( "E" ) ) {
4906                 return false;
4907             }
4908             if ( !iter.next().getName().equals( "F" ) ) {
4909                 return false;
4910             }
4911             if ( iter.hasNext() ) {
4912                 return false;
4913             }
4914         }
4915         catch ( final Exception e ) {
4916             e.printStackTrace( System.out );
4917             return false;
4918         }
4919         return true;
4920     }
4921
4922     private static boolean testExtractSNFromNodeName() {
4923         try {
4924             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4925                 return false;
4926             }
4927             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4928                 return false;
4929             }
4930             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4931                 return false;
4932             }
4933             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4934                     .equals( "Mus musculus musculus" ) ) {
4935                 return false;
4936             }
4937             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4938                     .equals( "Mus musculus musculus" ) ) {
4939                 return false;
4940             }
4941             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4942                     .equals( "Mus musculus musculus" ) ) {
4943                 return false;
4944             }
4945             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4946                     .equals( "Mus musculus musculus" ) ) {
4947                 return false;
4948             }
4949             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4950                 return false;
4951             }
4952             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4953                     .equals( "Mus musculus musculus" ) ) {
4954                 return false;
4955             }
4956             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4957                     .equals( "Mus musculus musculus" ) ) {
4958                 return false;
4959             }
4960             if ( ParserUtils
4961                     .extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4962                 return false;
4963             }
4964             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4965                 return false;
4966             }
4967             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4968                 return false;
4969             }
4970             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4971                 return false;
4972             }
4973             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4974                     .equals( "Mus musculus musculus" ) ) {
4975                 return false;
4976             }
4977             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4978                 return false;
4979             }
4980             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4981                 return false;
4982             }
4983             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4984                 return false;
4985             }
4986             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4987                 return false;
4988             }
4989             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4990                 return false;
4991             }
4992             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4993                 return false;
4994             }
4995             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4996                 return false;
4997             }
4998             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4999                 return false;
5000             }
5001             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
5002                     .equals( "Mus musculus" ) ) {
5003                 return false;
5004             }
5005             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
5006                     .equals( "Mus musculus" ) ) {
5007                 return false;
5008             }
5009             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
5010                 return false;
5011             }
5012             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
5013                     .equals( "Mus musculus musculus" ) ) {
5014                 return false;
5015             }
5016             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
5017                     .equals( "Mus musculus musculus" ) ) {
5018                 return false;
5019             }
5020             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
5021                     .equals( "Mus musculus musculus" ) ) {
5022                 return false;
5023             }
5024             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
5025                 return false;
5026             }
5027             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
5028                     .equals( "Pilostyles mexicana" ) ) {
5029                 return false;
5030             }
5031             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
5032                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
5033                 return false;
5034             }
5035             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
5036                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
5037                 return false;
5038             }
5039             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
5040                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
5041                 return false;
5042             }
5043             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
5044                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
5045                 return false;
5046             }
5047             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
5048                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
5049                 return false;
5050             }
5051             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
5052                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
5053                 return false;
5054             }
5055             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
5056                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
5057                 return false;
5058             }
5059             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
5060                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
5061                 return false;
5062             }
5063             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
5064                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
5065                 return false;
5066             }
5067             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
5068                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
5069                 return false;
5070             }
5071             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
5072                     .equals( "Escherichia coli (strain K12)" ) ) {
5073                 return false;
5074             }
5075             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
5076                     .equals( "Escherichia coli (strain K12)" ) ) {
5077                 return false;
5078             }
5079             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
5080                     .equals( "Escherichia coli (str. K12)" ) ) {
5081                 return false;
5082             }
5083             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
5084                     .equals( "Escherichia coli (str. K12)" ) ) {
5085                 return false;
5086             }
5087             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
5088                     .equals( "Escherichia coli (str. K12)" ) ) {
5089                 return false;
5090             }
5091             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
5092                     .equals( "Escherichia coli (var. K12)" ) ) {
5093                 return false;
5094             }
5095             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
5096                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
5097                 return false;
5098             }
5099             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
5100                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
5101                 return false;
5102             }
5103             if ( !ParserUtils
5104                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
5105                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
5106                 return false;
5107             }
5108             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
5109                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
5110                 return false;
5111             }
5112             if ( !ParserUtils
5113                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
5114                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
5115                 return false;
5116             }
5117             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
5118                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
5119                 return false;
5120             }
5121             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
5122                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
5123                 return false;
5124             }
5125             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
5126                 return false;
5127             }
5128             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
5129                 return false;
5130             }
5131             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
5132                 return false;
5133             }
5134             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
5135                     .equals( "Macrocera sp." ) ) {
5136                 return false;
5137             }
5138             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
5139                 return false;
5140             }
5141             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
5142                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
5143                 return false;
5144             }
5145             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
5146                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
5147                 return false;
5148             }
5149             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
5150                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
5151                 return false;
5152             }
5153             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
5154                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
5155                 return false;
5156             }
5157         }
5158         catch ( final Exception e ) {
5159             e.printStackTrace( System.out );
5160             return false;
5161         }
5162         return true;
5163     }
5164
5165     private static boolean testExtractTaxonomyDataFromNodeName() {
5166         try {
5167             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
5168             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5169                 return false;
5170             }
5171             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
5172             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5173                 return false;
5174             }
5175             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
5176             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5177                 return false;
5178             }
5179             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
5180             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5181                 return false;
5182             }
5183             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
5184             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5185                 return false;
5186             }
5187             n = new PhylogenyNode( "HNRPR_HUMAN" );
5188             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5189                 return false;
5190             }
5191             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
5192             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5193                 return false;
5194             }
5195         }
5196         catch ( final Exception e ) {
5197             e.printStackTrace( System.out );
5198             return false;
5199         }
5200         return true;
5201     }
5202
5203     private static boolean testExtractTaxonomyCodeFromNodeName() {
5204         try {
5205             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE",
5206                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5207                 return false;
5208             }
5209             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5210                     .equals( "SOYBN" ) ) {
5211                 return false;
5212             }
5213             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
5214                     .equals( "ARATH" ) ) {
5215                 return false;
5216             }
5217             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
5218                     .equals( "ARATH" ) ) {
5219                 return false;
5220             }
5221             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE )
5222                     .equals( "RAT" ) ) {
5223                 return false;
5224             }
5225             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE )
5226                     .equals( "RAT" ) ) {
5227                 return false;
5228             }
5229             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1",
5230                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5231                 return false;
5232             }
5233             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5234                     .equals( "SOYBN" ) ) {
5235                 return false;
5236             }
5237             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5238                     .equals( "SOYBN" ) ) {
5239                 return false;
5240             }
5241             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5242                     .equals( "SOYBN" ) ) {
5243                 return false;
5244             }
5245             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5246                     .equals( "SOYBN" ) ) {
5247                 return false;
5248             }
5249             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5250                     .equals( "SOYBN" ) ) {
5251                 return false;
5252             }
5253             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5254                     .equals( "SOYBN" ) ) {
5255                 return false;
5256             }
5257             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
5258                     .equals( "SOYBN" ) ) {
5259                 return false;
5260             }
5261             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
5262                     .equals( "SOYBN" ) ) {
5263                 return false;
5264             }
5265             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx",
5266                                                               TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
5267                 return false;
5268             }
5269             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
5270                     .equals( "SOYBN" ) ) {
5271                 return false;
5272             }
5273             if ( !ParserUtils
5274                     .extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5275                     .equals( "ECOLI" ) ) {
5276                 return false;
5277             }
5278             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blagg_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
5279                     .equals( "9YX45" ) ) {
5280                 return false;
5281             }
5282             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
5283                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5284                     .equals( "MOUSE" ) ) {
5285                 return false;
5286             }
5287             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
5288                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5289                     .equals( "MOUSE" ) ) {
5290                 return false;
5291             }
5292             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
5293                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5294                     .equals( "MOUSE" ) ) {
5295                 return false;
5296             }
5297             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
5298                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5299                 return false;
5300             }
5301             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
5302                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5303                 return false;
5304             }
5305             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5306                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5307                     .equals( "RAT" ) ) {
5308                 return false;
5309             }
5310             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5311                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5312                     .equals( "RAT" ) ) {
5313                 return false;
5314             }
5315             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
5316                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5317                     .equals( "RAT" ) ) {
5318                 return false;
5319             }
5320             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
5321                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5322                 return false;
5323             }
5324             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
5325                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5326                 return false;
5327             }
5328             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5329                     .equals( "RAT" ) ) {
5330                 return false;
5331             }
5332             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5333                     .equals( "PIG" ) ) {
5334                 return false;
5335             }
5336             if ( !ParserUtils
5337                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5338                     .equals( "MOUSE" ) ) {
5339                 return false;
5340             }
5341             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5342                     .equals( "MOUSE" ) ) {
5343                 return false;
5344             }
5345             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ",
5346                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5347                 return false;
5348             }
5349         }
5350         catch ( final Exception e ) {
5351             e.printStackTrace( System.out );
5352             return false;
5353         }
5354         return true;
5355     }
5356
5357     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
5358         try {
5359             PhylogenyNode n = new PhylogenyNode();
5360             n.setName( "tr|B3RJ64" );
5361             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5362                 return false;
5363             }
5364             n.setName( "tr.B3RJ64" );
5365             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5366                 return false;
5367             }
5368             n.setName( "tr=B3RJ64" );
5369             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5370                 return false;
5371             }
5372             n.setName( "tr-B3RJ64" );
5373             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5374                 return false;
5375             }
5376             n.setName( "tr/B3RJ64" );
5377             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5378                 return false;
5379             }
5380             n.setName( "tr\\B3RJ64" );
5381             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5382                 return false;
5383             }
5384             n.setName( "tr_B3RJ64" );
5385             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5386                 return false;
5387             }
5388             n.setName( " tr|B3RJ64 " );
5389             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5390                 return false;
5391             }
5392             n.setName( "-tr|B3RJ64-" );
5393             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5394                 return false;
5395             }
5396             n.setName( "-tr=B3RJ64-" );
5397             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5398                 return false;
5399             }
5400             n.setName( "_tr=B3RJ64_" );
5401             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5402                 return false;
5403             }
5404             n.setName( " tr_tr|B3RJ64_sp|123 " );
5405             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5406                 return false;
5407             }
5408             n.setName( "B3RJ64" );
5409             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5410                 return false;
5411             }
5412             n.setName( "sp|B3RJ64" );
5413             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5414                 return false;
5415             }
5416             n.setName( "sp|B3RJ64C" );
5417             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5418                 return false;
5419             }
5420             n.setName( "sp B3RJ64" );
5421             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5422                 return false;
5423             }
5424             n.setName( "sp|B3RJ6X" );
5425             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5426                 return false;
5427             }
5428             n.setName( "sp|B3RJ6" );
5429             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5430                 return false;
5431             }
5432             n.setName( "K1PYK7_CRAGI" );
5433             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5434                 return false;
5435             }
5436             n.setName( "K1PYK7_PEA" );
5437             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
5438                 return false;
5439             }
5440             n.setName( "K1PYK7_RAT" );
5441             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
5442                 return false;
5443             }
5444             n.setName( "K1PYK7_PIG" );
5445             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5446                 return false;
5447             }
5448             n.setName( "~K1PYK7_PIG~" );
5449             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5450                 return false;
5451             }
5452             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
5453             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5454                 return false;
5455             }
5456             n.setName( "K1PYKX_CRAGI" );
5457             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5458                 return false;
5459             }
5460             n.setName( "XXXXX_CRAGI" );
5461             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
5462                 return false;
5463             }
5464             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
5465             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
5466                 return false;
5467             }
5468             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
5469             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5470                 return false;
5471             }
5472             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
5473             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
5474                 return false;
5475             }
5476             n = new PhylogenyNode();
5477             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
5478             seq.setSymbol( "K1PYK7_CRAGI" );
5479             n.getNodeData().addSequence( seq );
5480             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5481                 return false;
5482             }
5483             seq.setSymbol( "tr|B3RJ64" );
5484             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5485                 return false;
5486             }
5487             n = new PhylogenyNode();
5488             seq = new org.forester.phylogeny.data.Sequence();
5489             seq.setName( "K1PYK7_CRAGI" );
5490             n.getNodeData().addSequence( seq );
5491             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5492                 return false;
5493             }
5494             seq.setName( "tr|B3RJ64" );
5495             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5496                 return false;
5497             }
5498             n = new PhylogenyNode();
5499             seq = new org.forester.phylogeny.data.Sequence();
5500             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
5501             n.getNodeData().addSequence( seq );
5502             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
5503                 return false;
5504             }
5505             n = new PhylogenyNode();
5506             seq = new org.forester.phylogeny.data.Sequence();
5507             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
5508             n.getNodeData().addSequence( seq );
5509             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5510                 return false;
5511             }
5512             //
5513             n = new PhylogenyNode();
5514             n.setName( "ACP19736" );
5515             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5516                 return false;
5517             }
5518             n = new PhylogenyNode();
5519             n.setName( "|ACP19736|" );
5520             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5521                 return false;
5522             }
5523         }
5524         catch ( final Exception e ) {
5525             e.printStackTrace( System.out );
5526             return false;
5527         }
5528         return true;
5529     }
5530
5531     private static boolean testFastaParser() {
5532         try {
5533             final FileInputStream fis1 = new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" );
5534             if ( !FastaParser.isLikelyFasta( fis1 ) ) {
5535                 fis1.close();
5536                 return false;
5537             }
5538             else {
5539                 fis1.close();
5540             }
5541             final FileInputStream fis2 = new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" );
5542             if ( FastaParser.isLikelyFasta( fis2 ) ) {
5543                 fis2.close();
5544                 return false;
5545             }
5546             else {
5547                 fis2.close();
5548             }
5549             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
5550             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
5551                 return false;
5552             }
5553             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
5554                 return false;
5555             }
5556             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
5557                 return false;
5558             }
5559             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
5560                 return false;
5561             }
5562             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
5563                 return false;
5564             }
5565             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
5566                 return false;
5567             }
5568         }
5569         catch ( final Exception e ) {
5570             e.printStackTrace();
5571             return false;
5572         }
5573         return true;
5574     }
5575
5576     private static boolean testGenbankAccessorParsing() {
5577         //The format for GenBank Accession numbers are:
5578         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
5579         //Protein:    3 letters + 5 numerals
5580         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
5581         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
5582             return false;
5583         }
5584         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
5585             return false;
5586         }
5587         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" )
5588                 .equals( "AY423861.24" ) ) {
5589             return false;
5590         }
5591         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
5592             return false;
5593         }
5594         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
5595             return false;
5596         }
5597         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
5598             return false;
5599         }
5600         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
5601             return false;
5602         }
5603         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
5604             return false;
5605         }
5606         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
5607             return false;
5608         }
5609         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
5610             return false;
5611         }
5612         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
5613             return false;
5614         }
5615         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
5616             return false;
5617         }
5618         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
5619             return false;
5620         }
5621         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
5622             return false;
5623         }
5624         return true;
5625     }
5626
5627     private static boolean testGeneralMsaParser() {
5628         try {
5629             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
5630             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
5631             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
5632             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
5633             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
5634             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
5635             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
5636             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
5637             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5638                 return false;
5639             }
5640             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5641                 return false;
5642             }
5643             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5644                 return false;
5645             }
5646             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5647                 return false;
5648             }
5649             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5650                 return false;
5651             }
5652             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5653                 return false;
5654             }
5655             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5656                 return false;
5657             }
5658             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5659                 return false;
5660             }
5661             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5662                 return false;
5663             }
5664             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5665                 return false;
5666             }
5667             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5668                 return false;
5669             }
5670             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5671                 return false;
5672             }
5673             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5674             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5675                 return false;
5676             }
5677             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5678                 return false;
5679             }
5680             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5681                 return false;
5682             }
5683             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5684             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5685                 return false;
5686             }
5687             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5688                 return false;
5689             }
5690             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5691                 return false;
5692             }
5693             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5694             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5695                 return false;
5696             }
5697             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5698                 return false;
5699             }
5700             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5701                 return false;
5702             }
5703         }
5704         catch ( final Exception e ) {
5705             e.printStackTrace();
5706             return false;
5707         }
5708         return true;
5709     }
5710
5711     private static boolean testGeneralTable() {
5712         try {
5713             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5714             t0.setValue( 3, 2, "23" );
5715             t0.setValue( 10, 1, "error" );
5716             t0.setValue( 10, 1, "110" );
5717             t0.setValue( 9, 1, "19" );
5718             t0.setValue( 1, 10, "101" );
5719             t0.setValue( 10, 10, "1010" );
5720             t0.setValue( 100, 10, "10100" );
5721             t0.setValue( 0, 0, "00" );
5722             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5723                 return false;
5724             }
5725             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5726                 return false;
5727             }
5728             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5729                 return false;
5730             }
5731             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5732                 return false;
5733             }
5734             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5735                 return false;
5736             }
5737             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5738                 return false;
5739             }
5740             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5741                 return false;
5742             }
5743             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5744                 return false;
5745             }
5746             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5747                 return false;
5748             }
5749             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5750             t1.setValue( "3", "2", "23" );
5751             t1.setValue( "10", "1", "error" );
5752             t1.setValue( "10", "1", "110" );
5753             t1.setValue( "9", "1", "19" );
5754             t1.setValue( "1", "10", "101" );
5755             t1.setValue( "10", "10", "1010" );
5756             t1.setValue( "100", "10", "10100" );
5757             t1.setValue( "0", "0", "00" );
5758             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5759             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5760                 return false;
5761             }
5762             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5763                 return false;
5764             }
5765             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5766                 return false;
5767             }
5768             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5769                 return false;
5770             }
5771             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5772                 return false;
5773             }
5774             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5775                 return false;
5776             }
5777             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5778                 return false;
5779             }
5780             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5781                 return false;
5782             }
5783             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5784                 return false;
5785             }
5786             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5787                 return false;
5788             }
5789         }
5790         catch ( final Exception e ) {
5791             e.printStackTrace( System.out );
5792             return false;
5793         }
5794         return true;
5795     }
5796
5797     private static boolean testGetDistance() {
5798         try {
5799             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5800             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",
5801                                                  new NHXParser() )[ 0 ];
5802             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5803                 return false;
5804             }
5805             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5806                 return false;
5807             }
5808             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5809                 return false;
5810             }
5811             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5812                 return false;
5813             }
5814             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5815                 return false;
5816             }
5817             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5818                 return false;
5819             }
5820             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5821                 return false;
5822             }
5823             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5824                 return false;
5825             }
5826             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5827                 return false;
5828             }
5829             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5830                 return false;
5831             }
5832             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5833                 return false;
5834             }
5835             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5836                 return false;
5837             }
5838             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5839                 return false;
5840             }
5841             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5842                 return false;
5843             }
5844             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5845                 return false;
5846             }
5847             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5848                 return false;
5849             }
5850             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5851                 return false;
5852             }
5853             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5854                 return false;
5855             }
5856             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5857                 return false;
5858             }
5859             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5860                 return false;
5861             }
5862             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5863                 return false;
5864             }
5865             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5866                 return false;
5867             }
5868             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5869                 return false;
5870             }
5871             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5872                 return false;
5873             }
5874             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5875                 return false;
5876             }
5877             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5878                 return false;
5879             }
5880             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5881                 return false;
5882             }
5883             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5884                 return false;
5885             }
5886             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5887                 return false;
5888             }
5889             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5890                 return false;
5891             }
5892             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5893                 return false;
5894             }
5895             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",
5896                                                  new NHXParser() )[ 0 ];
5897             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5898                 return false;
5899             }
5900             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5901                 return false;
5902             }
5903             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5904                 return false;
5905             }
5906             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5907                 return false;
5908             }
5909             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5910                 return false;
5911             }
5912             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5913                 return false;
5914             }
5915             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5916                 return false;
5917             }
5918             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5919                 return false;
5920             }
5921             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5922                 return false;
5923             }
5924             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5925                 return false;
5926             }
5927             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5928                 return false;
5929             }
5930         }
5931         catch ( final Exception e ) {
5932             e.printStackTrace( System.out );
5933             return false;
5934         }
5935         return true;
5936     }
5937
5938     private static boolean testGetLCA() {
5939         try {
5940             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5941             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5942                                                  new NHXParser() )[ 0 ];
5943             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5944             if ( !A.getName().equals( "A" ) ) {
5945                 return false;
5946             }
5947             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5948             if ( !gh.getName().equals( "gh" ) ) {
5949                 return false;
5950             }
5951             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5952             if ( !ab.getName().equals( "ab" ) ) {
5953                 return false;
5954             }
5955             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5956             if ( !ab2.getName().equals( "ab" ) ) {
5957                 return false;
5958             }
5959             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5960             if ( !gh2.getName().equals( "gh" ) ) {
5961                 return false;
5962             }
5963             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5964             if ( !gh3.getName().equals( "gh" ) ) {
5965                 return false;
5966             }
5967             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5968             if ( !abc.getName().equals( "abc" ) ) {
5969                 return false;
5970             }
5971             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5972             if ( !abc2.getName().equals( "abc" ) ) {
5973                 return false;
5974             }
5975             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5976             if ( !abcd.getName().equals( "abcd" ) ) {
5977                 return false;
5978             }
5979             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5980             if ( !abcd2.getName().equals( "abcd" ) ) {
5981                 return false;
5982             }
5983             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5984             if ( !abcdef.getName().equals( "abcdef" ) ) {
5985                 return false;
5986             }
5987             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5988             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5989                 return false;
5990             }
5991             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5992             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5993                 return false;
5994             }
5995             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5996             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5997                 return false;
5998             }
5999             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
6000             if ( !abcde.getName().equals( "abcde" ) ) {
6001                 return false;
6002             }
6003             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
6004             if ( !abcde2.getName().equals( "abcde" ) ) {
6005                 return false;
6006             }
6007             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
6008             if ( !r.getName().equals( "abcdefgh" ) ) {
6009                 return false;
6010             }
6011             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
6012             if ( !r2.getName().equals( "abcdefgh" ) ) {
6013                 return false;
6014             }
6015             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
6016             if ( !r3.getName().equals( "abcdefgh" ) ) {
6017                 return false;
6018             }
6019             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
6020             if ( !abcde3.getName().equals( "abcde" ) ) {
6021                 return false;
6022             }
6023             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
6024             if ( !abcde4.getName().equals( "abcde" ) ) {
6025                 return false;
6026             }
6027             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
6028             if ( !ab3.getName().equals( "ab" ) ) {
6029                 return false;
6030             }
6031             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
6032             if ( !ab4.getName().equals( "ab" ) ) {
6033                 return false;
6034             }
6035             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
6036             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
6037             if ( !cd.getName().equals( "cd" ) ) {
6038                 return false;
6039             }
6040             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
6041             if ( !cd2.getName().equals( "cd" ) ) {
6042                 return false;
6043             }
6044             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
6045             if ( !cde.getName().equals( "cde" ) ) {
6046                 return false;
6047             }
6048             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
6049             if ( !cde2.getName().equals( "cde" ) ) {
6050                 return false;
6051             }
6052             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
6053             if ( !cdef.getName().equals( "cdef" ) ) {
6054                 return false;
6055             }
6056             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
6057             if ( !cdef2.getName().equals( "cdef" ) ) {
6058                 return false;
6059             }
6060             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
6061             if ( !cdef3.getName().equals( "cdef" ) ) {
6062                 return false;
6063             }
6064             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
6065             if ( !rt.getName().equals( "r" ) ) {
6066                 return false;
6067             }
6068             final Phylogeny p3 = factory.create(
6069                                                  "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
6070                                                  new NHXParser() )[ 0 ];
6071             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
6072             if ( !bc_3.getName().equals( "bc" ) ) {
6073                 return false;
6074             }
6075             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
6076             if ( !ac_3.getName().equals( "abc" ) ) {
6077                 return false;
6078             }
6079             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
6080             if ( !ad_3.getName().equals( "abcde" ) ) {
6081                 return false;
6082             }
6083             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
6084             if ( !af_3.getName().equals( "abcdef" ) ) {
6085                 return false;
6086             }
6087             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
6088             if ( !ag_3.getName().equals( "" ) ) {
6089                 return false;
6090             }
6091             if ( !ag_3.isRoot() ) {
6092                 return false;
6093             }
6094             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
6095             if ( !al_3.getName().equals( "" ) ) {
6096                 return false;
6097             }
6098             if ( !al_3.isRoot() ) {
6099                 return false;
6100             }
6101             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
6102             if ( !kl_3.getName().equals( "" ) ) {
6103                 return false;
6104             }
6105             if ( !kl_3.isRoot() ) {
6106                 return false;
6107             }
6108             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
6109             if ( !fl_3.getName().equals( "" ) ) {
6110                 return false;
6111             }
6112             if ( !fl_3.isRoot() ) {
6113                 return false;
6114             }
6115             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
6116             if ( !gk_3.getName().equals( "ghijk" ) ) {
6117                 return false;
6118             }
6119             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
6120             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
6121             if ( !r_4.getName().equals( "r" ) ) {
6122                 return false;
6123             }
6124             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
6125             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
6126             if ( !r_5.getName().equals( "root" ) ) {
6127                 return false;
6128             }
6129             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
6130             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
6131             if ( !r_6.getName().equals( "rot" ) ) {
6132                 return false;
6133             }
6134             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
6135             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
6136             if ( !r_7.getName().equals( "rott" ) ) {
6137                 return false;
6138             }
6139         }
6140         catch ( final Exception e ) {
6141             e.printStackTrace( System.out );
6142             return false;
6143         }
6144         return true;
6145     }
6146
6147     private static boolean testGetLCA2() {
6148         try {
6149             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6150             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
6151             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
6152             PhylogenyMethods.preOrderReId( p_a );
6153             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
6154                                                                                               p_a.getNode( "a" ) );
6155             if ( !p_a_1.getName().equals( "a" ) ) {
6156                 return false;
6157             }
6158             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
6159             PhylogenyMethods.preOrderReId( p_b );
6160             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
6161                                                                                               p_b.getNode( "a" ) );
6162             if ( !p_b_1.getName().equals( "b" ) ) {
6163                 return false;
6164             }
6165             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
6166                                                                                               p_b.getNode( "b" ) );
6167             if ( !p_b_2.getName().equals( "b" ) ) {
6168                 return false;
6169             }
6170             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
6171             PhylogenyMethods.preOrderReId( p_c );
6172             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
6173                                                                                               p_c.getNode( "a" ) );
6174             if ( !p_c_1.getName().equals( "b" ) ) {
6175                 return false;
6176             }
6177             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
6178                                                                                               p_c.getNode( "c" ) );
6179             if ( !p_c_2.getName().equals( "c" ) ) {
6180                 System.out.println( p_c_2.getName() );
6181                 System.exit( -1 );
6182                 return false;
6183             }
6184             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
6185                                                                                               p_c.getNode( "b" ) );
6186             if ( !p_c_3.getName().equals( "b" ) ) {
6187                 return false;
6188             }
6189             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
6190                                                                                               p_c.getNode( "a" ) );
6191             if ( !p_c_4.getName().equals( "c" ) ) {
6192                 return false;
6193             }
6194             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
6195                                                  new NHXParser() )[ 0 ];
6196             PhylogenyMethods.preOrderReId( p1 );
6197             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6198                                                                                           p1.getNode( "A" ) );
6199             if ( !A.getName().equals( "A" ) ) {
6200                 return false;
6201             }
6202             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
6203                                                                                            p1.getNode( "gh" ) );
6204             if ( !gh.getName().equals( "gh" ) ) {
6205                 return false;
6206             }
6207             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6208                                                                                            p1.getNode( "B" ) );
6209             if ( !ab.getName().equals( "ab" ) ) {
6210                 return false;
6211             }
6212             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
6213                                                                                             p1.getNode( "A" ) );
6214             if ( !ab2.getName().equals( "ab" ) ) {
6215                 return false;
6216             }
6217             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
6218                                                                                             p1.getNode( "G" ) );
6219             if ( !gh2.getName().equals( "gh" ) ) {
6220                 return false;
6221             }
6222             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
6223                                                                                             p1.getNode( "H" ) );
6224             if ( !gh3.getName().equals( "gh" ) ) {
6225                 return false;
6226             }
6227             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
6228                                                                                             p1.getNode( "A" ) );
6229             if ( !abc.getName().equals( "abc" ) ) {
6230                 return false;
6231             }
6232             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6233                                                                                              p1.getNode( "C" ) );
6234             if ( !abc2.getName().equals( "abc" ) ) {
6235                 return false;
6236             }
6237             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6238                                                                                              p1.getNode( "D" ) );
6239             if ( !abcd.getName().equals( "abcd" ) ) {
6240                 return false;
6241             }
6242             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
6243                                                                                               p1.getNode( "A" ) );
6244             if ( !abcd2.getName().equals( "abcd" ) ) {
6245                 return false;
6246             }
6247             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6248                                                                                                p1.getNode( "F" ) );
6249             if ( !abcdef.getName().equals( "abcdef" ) ) {
6250                 return false;
6251             }
6252             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
6253                                                                                                 p1.getNode( "A" ) );
6254             if ( !abcdef2.getName().equals( "abcdef" ) ) {
6255                 return false;
6256             }
6257             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
6258                                                                                                 p1.getNode( "F" ) );
6259             if ( !abcdef3.getName().equals( "abcdef" ) ) {
6260                 return false;
6261             }
6262             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
6263                                                                                                 p1.getNode( "ab" ) );
6264             if ( !abcdef4.getName().equals( "abcdef" ) ) {
6265                 return false;
6266             }
6267             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6268                                                                                               p1.getNode( "E" ) );
6269             if ( !abcde.getName().equals( "abcde" ) ) {
6270                 return false;
6271             }
6272             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6273                                                                                                p1.getNode( "A" ) );
6274             if ( !abcde2.getName().equals( "abcde" ) ) {
6275                 return false;
6276             }
6277             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
6278                                                                                           p1.getNode( "abcdefgh" ) );
6279             if ( !r.getName().equals( "abcdefgh" ) ) {
6280                 return false;
6281             }
6282             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6283                                                                                            p1.getNode( "H" ) );
6284             if ( !r2.getName().equals( "abcdefgh" ) ) {
6285                 return false;
6286             }
6287             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
6288                                                                                            p1.getNode( "A" ) );
6289             if ( !r3.getName().equals( "abcdefgh" ) ) {
6290                 return false;
6291             }
6292             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6293                                                                                                p1.getNode( "abcde" ) );
6294             if ( !abcde3.getName().equals( "abcde" ) ) {
6295                 return false;
6296             }
6297             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
6298                                                                                                p1.getNode( "E" ) );
6299             if ( !abcde4.getName().equals( "abcde" ) ) {
6300                 return false;
6301             }
6302             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
6303                                                                                             p1.getNode( "B" ) );
6304             if ( !ab3.getName().equals( "ab" ) ) {
6305                 return false;
6306             }
6307             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
6308                                                                                             p1.getNode( "ab" ) );
6309             if ( !ab4.getName().equals( "ab" ) ) {
6310                 return false;
6311             }
6312             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
6313             PhylogenyMethods.preOrderReId( p2 );
6314             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6315                                                                                            p2.getNode( "d" ) );
6316             if ( !cd.getName().equals( "cd" ) ) {
6317                 return false;
6318             }
6319             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6320                                                                                             p2.getNode( "c" ) );
6321             if ( !cd2.getName().equals( "cd" ) ) {
6322                 return false;
6323             }
6324             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6325                                                                                             p2.getNode( "e" ) );
6326             if ( !cde.getName().equals( "cde" ) ) {
6327                 return false;
6328             }
6329             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
6330                                                                                              p2.getNode( "c" ) );
6331             if ( !cde2.getName().equals( "cde" ) ) {
6332                 return false;
6333             }
6334             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6335                                                                                              p2.getNode( "f" ) );
6336             if ( !cdef.getName().equals( "cdef" ) ) {
6337                 return false;
6338             }
6339             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6340                                                                                               p2.getNode( "f" ) );
6341             if ( !cdef2.getName().equals( "cdef" ) ) {
6342                 return false;
6343             }
6344             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
6345                                                                                               p2.getNode( "d" ) );
6346             if ( !cdef3.getName().equals( "cdef" ) ) {
6347                 return false;
6348             }
6349             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6350                                                                                            p2.getNode( "a" ) );
6351             if ( !rt.getName().equals( "r" ) ) {
6352                 return false;
6353             }
6354             final Phylogeny p3 = factory.create(
6355                                                  "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
6356                                                  new NHXParser() )[ 0 ];
6357             PhylogenyMethods.preOrderReId( p3 );
6358             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
6359                                                                                              p3.getNode( "c" ) );
6360             if ( !bc_3.getName().equals( "bc" ) ) {
6361                 return false;
6362             }
6363             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6364                                                                                              p3.getNode( "c" ) );
6365             if ( !ac_3.getName().equals( "abc" ) ) {
6366                 return false;
6367             }
6368             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6369                                                                                              p3.getNode( "d" ) );
6370             if ( !ad_3.getName().equals( "abcde" ) ) {
6371                 return false;
6372             }
6373             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6374                                                                                              p3.getNode( "f" ) );
6375             if ( !af_3.getName().equals( "abcdef" ) ) {
6376                 return false;
6377             }
6378             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6379                                                                                              p3.getNode( "g" ) );
6380             if ( !ag_3.getName().equals( "" ) ) {
6381                 return false;
6382             }
6383             if ( !ag_3.isRoot() ) {
6384                 return false;
6385             }
6386             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6387                                                                                              p3.getNode( "l" ) );
6388             if ( !al_3.getName().equals( "" ) ) {
6389                 return false;
6390             }
6391             if ( !al_3.isRoot() ) {
6392                 return false;
6393             }
6394             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
6395                                                                                              p3.getNode( "l" ) );
6396             if ( !kl_3.getName().equals( "" ) ) {
6397                 return false;
6398             }
6399             if ( !kl_3.isRoot() ) {
6400                 return false;
6401             }
6402             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
6403                                                                                              p3.getNode( "l" ) );
6404             if ( !fl_3.getName().equals( "" ) ) {
6405                 return false;
6406             }
6407             if ( !fl_3.isRoot() ) {
6408                 return false;
6409             }
6410             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
6411                                                                                              p3.getNode( "k" ) );
6412             if ( !gk_3.getName().equals( "ghijk" ) ) {
6413                 return false;
6414             }
6415             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
6416             PhylogenyMethods.preOrderReId( p4 );
6417             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
6418                                                                                             p4.getNode( "c" ) );
6419             if ( !r_4.getName().equals( "r" ) ) {
6420                 return false;
6421             }
6422             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
6423             PhylogenyMethods.preOrderReId( p5 );
6424             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
6425                                                                                             p5.getNode( "c" ) );
6426             if ( !r_5.getName().equals( "root" ) ) {
6427                 return false;
6428             }
6429             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
6430             PhylogenyMethods.preOrderReId( p6 );
6431             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
6432                                                                                             p6.getNode( "a" ) );
6433             if ( !r_6.getName().equals( "rot" ) ) {
6434                 return false;
6435             }
6436             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
6437             PhylogenyMethods.preOrderReId( p7 );
6438             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
6439                                                                                             p7.getNode( "e" ) );
6440             if ( !r_7.getName().equals( "rott" ) ) {
6441                 return false;
6442             }
6443             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6444                                                                                              p7.getNode( "a" ) );
6445             if ( !r_71.getName().equals( "rott" ) ) {
6446                 return false;
6447             }
6448             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6449                                                                                              p7.getNode( "rott" ) );
6450             if ( !r_72.getName().equals( "rott" ) ) {
6451                 return false;
6452             }
6453             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6454                                                                                              p7.getNode( "a" ) );
6455             if ( !r_73.getName().equals( "rott" ) ) {
6456                 return false;
6457             }
6458             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6459                                                                                              p7.getNode( "rott" ) );
6460             if ( !r_74.getName().equals( "rott" ) ) {
6461                 return false;
6462             }
6463             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6464                                                                                              p7.getNode( "e" ) );
6465             if ( !r_75.getName().equals( "e" ) ) {
6466                 return false;
6467             }
6468         }
6469         catch ( final Exception e ) {
6470             e.printStackTrace( System.out );
6471             return false;
6472         }
6473         return true;
6474     }
6475
6476     private static boolean testHmmscanOutputParser() {
6477         final String test_dir = Test.PATH_TO_TEST_DATA;
6478         try {
6479             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
6480                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ),
6481                                                                                          "MONBR",
6482                                                                                          INDIVIDUAL_SCORE_CUTOFF.NONE );
6483             parser1.parse();
6484             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
6485                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ),
6486                                                                                          "MONBR",
6487                                                                                          INDIVIDUAL_SCORE_CUTOFF.NONE );
6488             final List<Protein> proteins = parser2.parse();
6489             if ( parser2.getProteinsEncountered() != 4 ) {
6490                 return false;
6491             }
6492             if ( proteins.size() != 4 ) {
6493                 return false;
6494             }
6495             if ( parser2.getDomainsEncountered() != 69 ) {
6496                 return false;
6497             }
6498             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
6499                 return false;
6500             }
6501             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
6502                 return false;
6503             }
6504             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
6505                 return false;
6506             }
6507             final Protein p1 = proteins.get( 0 );
6508             if ( p1.getNumberOfProteinDomains() != 15 ) {
6509                 return false;
6510             }
6511             if ( p1.getLength() != 850 ) {
6512                 return false;
6513             }
6514             final Protein p2 = proteins.get( 1 );
6515             if ( p2.getNumberOfProteinDomains() != 51 ) {
6516                 return false;
6517             }
6518             if ( p2.getLength() != 1291 ) {
6519                 return false;
6520             }
6521             final Protein p3 = proteins.get( 2 );
6522             if ( p3.getNumberOfProteinDomains() != 2 ) {
6523                 return false;
6524             }
6525             final Protein p4 = proteins.get( 3 );
6526             if ( p4.getNumberOfProteinDomains() != 1 ) {
6527                 return false;
6528             }
6529             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
6530                 return false;
6531             }
6532             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
6533                 return false;
6534             }
6535             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
6536                 return false;
6537             }
6538             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
6539                 return false;
6540             }
6541             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
6542                 return false;
6543             }
6544             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
6545                 return false;
6546             }
6547             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
6548                 return false;
6549             }
6550         }
6551         catch ( final Exception e ) {
6552             e.printStackTrace( System.out );
6553             return false;
6554         }
6555         return true;
6556     }
6557
6558     private static boolean testLastExternalNodeMethods() {
6559         try {
6560             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6561             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
6562             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
6563             final PhylogenyNode n1 = t0.getNode( "A" );
6564             if ( n1.isLastExternalNode() ) {
6565                 return false;
6566             }
6567             final PhylogenyNode n2 = t0.getNode( "B" );
6568             if ( n2.isLastExternalNode() ) {
6569                 return false;
6570             }
6571             final PhylogenyNode n3 = t0.getNode( "C" );
6572             if ( n3.isLastExternalNode() ) {
6573                 return false;
6574             }
6575             final PhylogenyNode n4 = t0.getNode( "D" );
6576             if ( !n4.isLastExternalNode() ) {
6577                 return false;
6578             }
6579         }
6580         catch ( final Exception e ) {
6581             e.printStackTrace( System.out );
6582             return false;
6583         }
6584         return true;
6585     }
6586
6587     private static boolean testLevelOrderIterator() {
6588         try {
6589             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6590             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
6591             PhylogenyNodeIterator it0;
6592             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
6593                 it0.next();
6594             }
6595             for( it0.reset(); it0.hasNext(); ) {
6596                 it0.next();
6597             }
6598             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
6599             if ( !it.next().getName().equals( "r" ) ) {
6600                 return false;
6601             }
6602             if ( !it.next().getName().equals( "ab" ) ) {
6603                 return false;
6604             }
6605             if ( !it.next().getName().equals( "cd" ) ) {
6606                 return false;
6607             }
6608             if ( !it.next().getName().equals( "A" ) ) {
6609                 return false;
6610             }
6611             if ( !it.next().getName().equals( "B" ) ) {
6612                 return false;
6613             }
6614             if ( !it.next().getName().equals( "C" ) ) {
6615                 return false;
6616             }
6617             if ( !it.next().getName().equals( "D" ) ) {
6618                 return false;
6619             }
6620             if ( it.hasNext() ) {
6621                 return false;
6622             }
6623             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",
6624                                                  new NHXParser() )[ 0 ];
6625             PhylogenyNodeIterator it2;
6626             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
6627                 it2.next();
6628             }
6629             for( it2.reset(); it2.hasNext(); ) {
6630                 it2.next();
6631             }
6632             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
6633             if ( !it3.next().getName().equals( "r" ) ) {
6634                 return false;
6635             }
6636             if ( !it3.next().getName().equals( "abc" ) ) {
6637                 return false;
6638             }
6639             if ( !it3.next().getName().equals( "defg" ) ) {
6640                 return false;
6641             }
6642             if ( !it3.next().getName().equals( "A" ) ) {
6643                 return false;
6644             }
6645             if ( !it3.next().getName().equals( "B" ) ) {
6646                 return false;
6647             }
6648             if ( !it3.next().getName().equals( "C" ) ) {
6649                 return false;
6650             }
6651             if ( !it3.next().getName().equals( "D" ) ) {
6652                 return false;
6653             }
6654             if ( !it3.next().getName().equals( "E" ) ) {
6655                 return false;
6656             }
6657             if ( !it3.next().getName().equals( "F" ) ) {
6658                 return false;
6659             }
6660             if ( !it3.next().getName().equals( "G" ) ) {
6661                 return false;
6662             }
6663             if ( !it3.next().getName().equals( "1" ) ) {
6664                 return false;
6665             }
6666             if ( !it3.next().getName().equals( "2" ) ) {
6667                 return false;
6668             }
6669             if ( !it3.next().getName().equals( "3" ) ) {
6670                 return false;
6671             }
6672             if ( !it3.next().getName().equals( "4" ) ) {
6673                 return false;
6674             }
6675             if ( !it3.next().getName().equals( "5" ) ) {
6676                 return false;
6677             }
6678             if ( !it3.next().getName().equals( "6" ) ) {
6679                 return false;
6680             }
6681             if ( !it3.next().getName().equals( "f1" ) ) {
6682                 return false;
6683             }
6684             if ( !it3.next().getName().equals( "f2" ) ) {
6685                 return false;
6686             }
6687             if ( !it3.next().getName().equals( "f3" ) ) {
6688                 return false;
6689             }
6690             if ( !it3.next().getName().equals( "a" ) ) {
6691                 return false;
6692             }
6693             if ( !it3.next().getName().equals( "b" ) ) {
6694                 return false;
6695             }
6696             if ( !it3.next().getName().equals( "f21" ) ) {
6697                 return false;
6698             }
6699             if ( !it3.next().getName().equals( "X" ) ) {
6700                 return false;
6701             }
6702             if ( !it3.next().getName().equals( "Y" ) ) {
6703                 return false;
6704             }
6705             if ( !it3.next().getName().equals( "Z" ) ) {
6706                 return false;
6707             }
6708             if ( it3.hasNext() ) {
6709                 return false;
6710             }
6711             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6712             PhylogenyNodeIterator it4;
6713             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6714                 it4.next();
6715             }
6716             for( it4.reset(); it4.hasNext(); ) {
6717                 it4.next();
6718             }
6719             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6720             if ( !it5.next().getName().equals( "r" ) ) {
6721                 return false;
6722             }
6723             if ( !it5.next().getName().equals( "A" ) ) {
6724                 return false;
6725             }
6726             if ( !it5.next().getName().equals( "B" ) ) {
6727                 return false;
6728             }
6729             if ( !it5.next().getName().equals( "C" ) ) {
6730                 return false;
6731             }
6732             if ( !it5.next().getName().equals( "D" ) ) {
6733                 return false;
6734             }
6735             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6736             PhylogenyNodeIterator it6;
6737             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6738                 it6.next();
6739             }
6740             for( it6.reset(); it6.hasNext(); ) {
6741                 it6.next();
6742             }
6743             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6744             if ( !it7.next().getName().equals( "A" ) ) {
6745                 return false;
6746             }
6747             if ( it.hasNext() ) {
6748                 return false;
6749             }
6750         }
6751         catch ( final Exception e ) {
6752             e.printStackTrace( System.out );
6753             return false;
6754         }
6755         return true;
6756     }
6757
6758     private static boolean testMafft( final String path ) {
6759         try {
6760             final List<String> opts = new ArrayList<String>();
6761             opts.add( "--maxiterate" );
6762             opts.add( "1000" );
6763             opts.add( "--localpair" );
6764             opts.add( "--quiet" );
6765             Msa msa = null;
6766             final MsaInferrer mafft = Mafft.createInstance( path );
6767             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6768             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6769                 return false;
6770             }
6771             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6772                 return false;
6773             }
6774         }
6775         catch ( final Exception e ) {
6776             e.printStackTrace( System.out );
6777             return false;
6778         }
6779         return true;
6780     }
6781
6782     private static boolean testMidpointrooting() {
6783         try {
6784             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6785             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6786             PhylogenyMethods.midpointRoot( t0 );
6787             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6788                 return false;
6789             }
6790             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6791                 return false;
6792             }
6793             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6794                            1 ) ) {
6795                 return false;
6796             }
6797             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",
6798                                                  new NHXParser() )[ 0 ];
6799             if ( !t1.isRooted() ) {
6800                 return false;
6801             }
6802             PhylogenyMethods.midpointRoot( t1 );
6803             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6804                 return false;
6805             }
6806             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6807                 return false;
6808             }
6809             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6810                 return false;
6811             }
6812             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6813                 return false;
6814             }
6815             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6816                 return false;
6817             }
6818             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6819                 return false;
6820             }
6821             t1.reRoot( t1.getNode( "A" ) );
6822             PhylogenyMethods.midpointRoot( t1 );
6823             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6824                 return false;
6825             }
6826             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6827                 return false;
6828             }
6829             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6830                 return false;
6831             }
6832             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6833                 return false;
6834             }
6835             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6836                 System.exit( -1 );
6837                 return false;
6838             }
6839             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6840                 return false;
6841             }
6842         }
6843         catch ( final Exception e ) {
6844             e.printStackTrace( System.out );
6845             return false;
6846         }
6847         return true;
6848     }
6849
6850     private static boolean testMsaQualityMethod() {
6851         try {
6852             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6853             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6854             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6855             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6856             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6857             l.add( s0 );
6858             l.add( s1 );
6859             l.add( s2 );
6860             l.add( s3 );
6861             final Msa msa = BasicMsa.createInstance( l );
6862             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6863                 return false;
6864             }
6865             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6866                 return false;
6867             }
6868             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6869                 return false;
6870             }
6871             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6872                 return false;
6873             }
6874             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6875                 return false;
6876             }
6877             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6878                 return false;
6879             }
6880             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6881                 return false;
6882             }
6883         }
6884         catch ( final Exception e ) {
6885             e.printStackTrace( System.out );
6886             return false;
6887         }
6888         return true;
6889     }
6890
6891     private static boolean testMsaEntropy() {
6892         try {
6893             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6894             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6895             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6896             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6897             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6898             l.add( s0 );
6899             l.add( s1 );
6900             l.add( s2 );
6901             l.add( s3 );
6902             final Msa msa = BasicMsa.createInstance( l );
6903             //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6904             //FIXME
6905             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6906             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6907             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6908             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6909             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6910             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6911             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6912             //            System.out.println();
6913             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6914             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6915             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6916             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6917             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6918             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6919             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6920             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6921             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6922             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6923             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6924             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6925             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6926             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6927             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6928             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6929             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6930             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6931             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6932             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6933             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6934             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6935             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6936             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6937             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6938             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6939             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6940             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6941             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6942             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6943             final Msa msa2 = BasicMsa.createInstance( l2 );
6944             //            System.out.println();
6945             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6946             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6947             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6948         }
6949         catch ( final Exception e ) {
6950             e.printStackTrace( System.out );
6951             return false;
6952         }
6953         return true;
6954     }
6955
6956     private static boolean testDeleteableMsa() {
6957         try {
6958             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6959             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6960             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6961             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6962             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6963             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6964             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6965             l0.add( s0 );
6966             l0.add( s1 );
6967             l0.add( s2 );
6968             l0.add( s3 );
6969             l0.add( s4 );
6970             l0.add( s5 );
6971             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6972             dmsa0.deleteRow( "b", false );
6973             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6974                 return false;
6975             }
6976             dmsa0.deleteRow( "e", false );
6977             dmsa0.deleteRow( "a", false );
6978             dmsa0.deleteRow( "f", false );
6979             if ( dmsa0.getLength() != 4 ) {
6980                 return false;
6981             }
6982             if ( dmsa0.getNumberOfSequences() != 2 ) {
6983                 return false;
6984             }
6985             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6986                 return false;
6987             }
6988             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6989                 return false;
6990             }
6991             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6992                 return false;
6993             }
6994             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6995                 return false;
6996             }
6997             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6998                 return false;
6999             }
7000             dmsa0.deleteRow( "c", false );
7001             dmsa0.deleteRow( "d", false );
7002             if ( dmsa0.getNumberOfSequences() != 0 ) {
7003                 return false;
7004             }
7005             //
7006             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
7007             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
7008             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
7009             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
7010             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
7011             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
7012             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
7013             l1.add( s_0 );
7014             l1.add( s_1 );
7015             l1.add( s_2 );
7016             l1.add( s_3 );
7017             l1.add( s_4 );
7018             l1.add( s_5 );
7019             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
7020             dmsa1.deleteGapOnlyColumns();
7021             dmsa1.deleteRow( "a", false );
7022             dmsa1.deleteRow( "f", false );
7023             dmsa1.deleteRow( "d", false );
7024             dmsa1.deleteGapOnlyColumns();
7025             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
7026                 return false;
7027             }
7028             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
7029                 return false;
7030             }
7031             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
7032                 return false;
7033             }
7034             dmsa1.deleteRow( "c", false );
7035             dmsa1.deleteGapOnlyColumns();
7036             final Writer w0 = new StringWriter();
7037             dmsa1.write( w0, MSA_FORMAT.FASTA );
7038             final Writer w1 = new StringWriter();
7039             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
7040             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
7041                 return false;
7042             }
7043             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
7044                 return false;
7045             }
7046             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
7047             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
7048             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
7049             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
7050             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
7051             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
7052             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
7053             l2.add( s__0 );
7054             l2.add( s__1 );
7055             l2.add( s__2 );
7056             l2.add( s__3 );
7057             l2.add( s__4 );
7058             l2.add( s__5 );
7059             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
7060             dmsa2.deleteGapColumns( 0.5 );
7061             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
7062                 return false;
7063             }
7064             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
7065                 return false;
7066             }
7067             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
7068                 return false;
7069             }
7070             dmsa2.deleteGapColumns( 0.2 );
7071             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
7072                 return false;
7073             }
7074             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
7075                 return false;
7076             }
7077             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
7078                 return false;
7079             }
7080             dmsa2.deleteGapColumns( 0 );
7081             dmsa2.deleteRow( "a", false );
7082             dmsa2.deleteRow( "b", false );
7083             dmsa2.deleteRow( "f", false );
7084             dmsa2.deleteRow( "e", false );
7085             dmsa2.setIdentifier( 0, "new_c" );
7086             dmsa2.setIdentifier( 1, "new_d" );
7087             dmsa2.setResidueAt( 0, 0, 'x' );
7088             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
7089             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
7090                 return false;
7091             }
7092             final Writer w = new StringWriter();
7093             dmsa2.write( w, MSA_FORMAT.PHYLIP );
7094             final String phylip = w.toString();
7095             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
7096                 System.out.println( phylip );
7097                 return false;
7098             }
7099             final Writer w2 = new StringWriter();
7100             dmsa2.write( w2, MSA_FORMAT.FASTA );
7101             final String fasta = w2.toString();
7102             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
7103                 System.out.println( fasta );
7104                 return false;
7105             }
7106         }
7107         catch ( final Exception e ) {
7108             e.printStackTrace( System.out );
7109             return false;
7110         }
7111         return true;
7112     }
7113
7114     private static boolean testNextNodeWithCollapsing() {
7115         try {
7116             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7117             PhylogenyNode n;
7118             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
7119             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7120             final Phylogeny t0 = factory.create( sb0.toString(), new NHXParser() )[ 0 ];
7121             t0.getNode( "cd" ).setCollapse( true );
7122             t0.getNode( "cde" ).setCollapse( true );
7123             n = t0.getFirstExternalNode();
7124             while ( n != null ) {
7125                 ext.add( n );
7126                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7127             }
7128             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7129                 return false;
7130             }
7131             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7132                 return false;
7133             }
7134             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
7135                 return false;
7136             }
7137             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
7138                 return false;
7139             }
7140             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
7141                 return false;
7142             }
7143             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
7144                 return false;
7145             }
7146             ext.clear();
7147             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7148             final Phylogeny t1 = factory.create( sb1.toString(), new NHXParser() )[ 0 ];
7149             t1.getNode( "ab" ).setCollapse( true );
7150             t1.getNode( "cd" ).setCollapse( true );
7151             t1.getNode( "cde" ).setCollapse( true );
7152             n = t1.getNode( "ab" );
7153             ext = new ArrayList<PhylogenyNode>();
7154             while ( n != null ) {
7155                 ext.add( n );
7156                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7157             }
7158             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7159                 return false;
7160             }
7161             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7162                 return false;
7163             }
7164             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
7165                 return false;
7166             }
7167             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
7168                 return false;
7169             }
7170             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
7171                 return false;
7172             }
7173             ext.clear();
7174             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7175             final Phylogeny t2 = factory.create( sb2.toString(), new NHXParser() )[ 0 ];
7176             t2.getNode( "ab" ).setCollapse( true );
7177             t2.getNode( "cd" ).setCollapse( true );
7178             t2.getNode( "cde" ).setCollapse( true );
7179             t2.getNode( "c" ).setCollapse( true );
7180             t2.getNode( "d" ).setCollapse( true );
7181             t2.getNode( "e" ).setCollapse( true );
7182             t2.getNode( "gh" ).setCollapse( true );
7183             n = t2.getNode( "ab" );
7184             ext = new ArrayList<PhylogenyNode>();
7185             while ( n != null ) {
7186                 ext.add( n );
7187                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7188             }
7189             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7190                 return false;
7191             }
7192             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7193                 return false;
7194             }
7195             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
7196                 return false;
7197             }
7198             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
7199                 return false;
7200             }
7201             ext.clear();
7202             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7203             final Phylogeny t3 = factory.create( sb3.toString(), new NHXParser() )[ 0 ];
7204             t3.getNode( "ab" ).setCollapse( true );
7205             t3.getNode( "cd" ).setCollapse( true );
7206             t3.getNode( "cde" ).setCollapse( true );
7207             t3.getNode( "c" ).setCollapse( true );
7208             t3.getNode( "d" ).setCollapse( true );
7209             t3.getNode( "e" ).setCollapse( true );
7210             t3.getNode( "gh" ).setCollapse( true );
7211             t3.getNode( "fgh" ).setCollapse( true );
7212             n = t3.getNode( "ab" );
7213             ext = new ArrayList<PhylogenyNode>();
7214             while ( n != null ) {
7215                 ext.add( n );
7216                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7217             }
7218             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7219                 return false;
7220             }
7221             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7222                 return false;
7223             }
7224             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
7225                 return false;
7226             }
7227             ext.clear();
7228             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7229             final Phylogeny t4 = factory.create( sb4.toString(), new NHXParser() )[ 0 ];
7230             t4.getNode( "ab" ).setCollapse( true );
7231             t4.getNode( "cd" ).setCollapse( true );
7232             t4.getNode( "cde" ).setCollapse( true );
7233             t4.getNode( "c" ).setCollapse( true );
7234             t4.getNode( "d" ).setCollapse( true );
7235             t4.getNode( "e" ).setCollapse( true );
7236             t4.getNode( "gh" ).setCollapse( true );
7237             t4.getNode( "fgh" ).setCollapse( true );
7238             t4.getNode( "abcdefgh" ).setCollapse( true );
7239             n = t4.getNode( "abcdefgh" );
7240             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
7241                 return false;
7242             }
7243             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7244             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
7245             ext.clear();
7246             n = t5.getFirstExternalNode();
7247             while ( n != null ) {
7248                 ext.add( n );
7249                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7250             }
7251             if ( ext.size() != 8 ) {
7252                 return false;
7253             }
7254             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7255                 return false;
7256             }
7257             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7258                 return false;
7259             }
7260             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7261                 return false;
7262             }
7263             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7264                 return false;
7265             }
7266             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7267                 return false;
7268             }
7269             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7270                 return false;
7271             }
7272             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
7273                 return false;
7274             }
7275             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
7276                 return false;
7277             }
7278             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7279             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
7280             ext.clear();
7281             t6.getNode( "ab" ).setCollapse( true );
7282             n = t6.getNode( "ab" );
7283             while ( n != null ) {
7284                 ext.add( n );
7285                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7286             }
7287             if ( ext.size() != 7 ) {
7288                 return false;
7289             }
7290             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7291                 return false;
7292             }
7293             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7294                 return false;
7295             }
7296             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7297                 return false;
7298             }
7299             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7300                 return false;
7301             }
7302             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7303                 return false;
7304             }
7305             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7306                 return false;
7307             }
7308             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7309                 return false;
7310             }
7311             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7312             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
7313             ext.clear();
7314             t7.getNode( "cd" ).setCollapse( true );
7315             n = t7.getNode( "a" );
7316             while ( n != null ) {
7317                 ext.add( n );
7318                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7319             }
7320             if ( ext.size() != 7 ) {
7321                 return false;
7322             }
7323             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7324                 return false;
7325             }
7326             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7327                 return false;
7328             }
7329             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7330                 return false;
7331             }
7332             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7333                 return false;
7334             }
7335             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7336                 return false;
7337             }
7338             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7339                 return false;
7340             }
7341             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7342                 return false;
7343             }
7344             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7345             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
7346             ext.clear();
7347             t8.getNode( "cd" ).setCollapse( true );
7348             t8.getNode( "c" ).setCollapse( true );
7349             t8.getNode( "d" ).setCollapse( true );
7350             n = t8.getNode( "a" );
7351             while ( n != null ) {
7352                 ext.add( n );
7353                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7354             }
7355             if ( ext.size() != 7 ) {
7356                 return false;
7357             }
7358             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7359                 return false;
7360             }
7361             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7362                 return false;
7363             }
7364             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7365                 System.out.println( "2 fail" );
7366                 return false;
7367             }
7368             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7369                 return false;
7370             }
7371             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7372                 return false;
7373             }
7374             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7375                 return false;
7376             }
7377             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7378                 return false;
7379             }
7380             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7381             final Phylogeny t9 = factory.create( sb9.toString(), new NHXParser() )[ 0 ];
7382             ext.clear();
7383             t9.getNode( "gh" ).setCollapse( true );
7384             n = t9.getNode( "a" );
7385             while ( n != null ) {
7386                 ext.add( n );
7387                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7388             }
7389             if ( ext.size() != 7 ) {
7390                 return false;
7391             }
7392             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7393                 return false;
7394             }
7395             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7396                 return false;
7397             }
7398             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7399                 return false;
7400             }
7401             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7402                 return false;
7403             }
7404             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7405                 return false;
7406             }
7407             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7408                 return false;
7409             }
7410             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7411                 return false;
7412             }
7413             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7414             final Phylogeny t10 = factory.create( sb10.toString(), new NHXParser() )[ 0 ];
7415             ext.clear();
7416             t10.getNode( "gh" ).setCollapse( true );
7417             t10.getNode( "g" ).setCollapse( true );
7418             t10.getNode( "h" ).setCollapse( true );
7419             n = t10.getNode( "a" );
7420             while ( n != null ) {
7421                 ext.add( n );
7422                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7423             }
7424             if ( ext.size() != 7 ) {
7425                 return false;
7426             }
7427             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7428                 return false;
7429             }
7430             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7431                 return false;
7432             }
7433             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7434                 return false;
7435             }
7436             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7437                 return false;
7438             }
7439             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7440                 return false;
7441             }
7442             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7443                 return false;
7444             }
7445             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7446                 return false;
7447             }
7448             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7449             final Phylogeny t11 = factory.create( sb11.toString(), new NHXParser() )[ 0 ];
7450             ext.clear();
7451             t11.getNode( "gh" ).setCollapse( true );
7452             t11.getNode( "fgh" ).setCollapse( true );
7453             n = t11.getNode( "a" );
7454             while ( n != null ) {
7455                 ext.add( n );
7456                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7457             }
7458             if ( ext.size() != 6 ) {
7459                 return false;
7460             }
7461             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7462                 return false;
7463             }
7464             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7465                 return false;
7466             }
7467             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7468                 return false;
7469             }
7470             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7471                 return false;
7472             }
7473             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7474                 return false;
7475             }
7476             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7477                 return false;
7478             }
7479             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7480             final Phylogeny t12 = factory.create( sb12.toString(), new NHXParser() )[ 0 ];
7481             ext.clear();
7482             t12.getNode( "gh" ).setCollapse( true );
7483             t12.getNode( "fgh" ).setCollapse( true );
7484             t12.getNode( "g" ).setCollapse( true );
7485             t12.getNode( "h" ).setCollapse( true );
7486             t12.getNode( "f" ).setCollapse( true );
7487             n = t12.getNode( "a" );
7488             while ( n != null ) {
7489                 ext.add( n );
7490                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7491             }
7492             if ( ext.size() != 6 ) {
7493                 return false;
7494             }
7495             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7496                 return false;
7497             }
7498             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7499                 return false;
7500             }
7501             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7502                 return false;
7503             }
7504             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7505                 return false;
7506             }
7507             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7508                 return false;
7509             }
7510             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7511                 return false;
7512             }
7513             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7514             final Phylogeny t13 = factory.create( sb13.toString(), new NHXParser() )[ 0 ];
7515             ext.clear();
7516             t13.getNode( "ab" ).setCollapse( true );
7517             t13.getNode( "b" ).setCollapse( true );
7518             t13.getNode( "fgh" ).setCollapse( true );
7519             t13.getNode( "gh" ).setCollapse( true );
7520             n = t13.getNode( "ab" );
7521             while ( n != null ) {
7522                 ext.add( n );
7523                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7524             }
7525             if ( ext.size() != 5 ) {
7526                 return false;
7527             }
7528             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7529                 return false;
7530             }
7531             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7532                 return false;
7533             }
7534             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7535                 return false;
7536             }
7537             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7538                 return false;
7539             }
7540             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7541                 return false;
7542             }
7543             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
7544             final Phylogeny t14 = factory.create( sb14.toString(), new NHXParser() )[ 0 ];
7545             ext.clear();
7546             t14.getNode( "ab" ).setCollapse( true );
7547             t14.getNode( "a" ).setCollapse( true );
7548             t14.getNode( "fgh" ).setCollapse( true );
7549             t14.getNode( "gh" ).setCollapse( true );
7550             n = t14.getNode( "ab" );
7551             while ( n != null ) {
7552                 ext.add( n );
7553                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7554             }
7555             if ( ext.size() != 5 ) {
7556                 return false;
7557             }
7558             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7559                 return false;
7560             }
7561             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7562                 return false;
7563             }
7564             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7565                 return false;
7566             }
7567             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7568                 return false;
7569             }
7570             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7571                 return false;
7572             }
7573             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" );
7574             final Phylogeny t15 = factory.create( sb15.toString(), new NHXParser() )[ 0 ];
7575             ext.clear();
7576             t15.getNode( "ab" ).setCollapse( true );
7577             t15.getNode( "a" ).setCollapse( true );
7578             t15.getNode( "fgh" ).setCollapse( true );
7579             t15.getNode( "gh" ).setCollapse( true );
7580             n = t15.getNode( "ab" );
7581             while ( n != null ) {
7582                 ext.add( n );
7583                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7584             }
7585             if ( ext.size() != 6 ) {
7586                 return false;
7587             }
7588             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7589                 return false;
7590             }
7591             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7592                 return false;
7593             }
7594             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7595                 return false;
7596             }
7597             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7598                 return false;
7599             }
7600             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
7601                 return false;
7602             }
7603             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7604                 return false;
7605             }
7606             //
7607             //
7608             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" );
7609             final Phylogeny t16 = factory.create( sb16.toString(), new NHXParser() )[ 0 ];
7610             ext.clear();
7611             t16.getNode( "ab" ).setCollapse( true );
7612             t16.getNode( "a" ).setCollapse( true );
7613             t16.getNode( "fgh" ).setCollapse( true );
7614             t16.getNode( "gh" ).setCollapse( true );
7615             t16.getNode( "cd" ).setCollapse( true );
7616             t16.getNode( "cde" ).setCollapse( true );
7617             t16.getNode( "d" ).setCollapse( true );
7618             t16.getNode( "x" ).setCollapse( true );
7619             n = t16.getNode( "ab" );
7620             while ( n != null ) {
7621                 ext.add( n );
7622                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7623             }
7624             if ( ext.size() != 4 ) {
7625                 return false;
7626             }
7627             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7628                 return false;
7629             }
7630             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7631                 return false;
7632             }
7633             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
7634                 return false;
7635             }
7636             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
7637                 return false;
7638             }
7639         }
7640         catch ( final Exception e ) {
7641             e.printStackTrace( System.out );
7642             return false;
7643         }
7644         return true;
7645     }
7646
7647     private static boolean testNexusCharactersParsing() {
7648         try {
7649             final NexusCharactersParser parser = new NexusCharactersParser();
7650             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
7651             parser.parse();
7652             String[] labels = parser.getCharStateLabels();
7653             if ( labels.length != 7 ) {
7654                 return false;
7655             }
7656             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7657                 return false;
7658             }
7659             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7660                 return false;
7661             }
7662             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7663                 return false;
7664             }
7665             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7666                 return false;
7667             }
7668             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7669                 return false;
7670             }
7671             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7672                 return false;
7673             }
7674             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7675                 return false;
7676             }
7677             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7678             parser.parse();
7679             labels = parser.getCharStateLabels();
7680             if ( labels.length != 7 ) {
7681                 return false;
7682             }
7683             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7684                 return false;
7685             }
7686             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7687                 return false;
7688             }
7689             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7690                 return false;
7691             }
7692             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7693                 return false;
7694             }
7695             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7696                 return false;
7697             }
7698             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7699                 return false;
7700             }
7701             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7702                 return false;
7703             }
7704         }
7705         catch ( final Exception e ) {
7706             e.printStackTrace( System.out );
7707             return false;
7708         }
7709         return true;
7710     }
7711
7712     private static boolean testNexusMatrixParsing() {
7713         try {
7714             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7715             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7716             parser.parse();
7717             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7718             if ( m.getNumberOfCharacters() != 9 ) {
7719                 return false;
7720             }
7721             if ( m.getNumberOfIdentifiers() != 5 ) {
7722                 return false;
7723             }
7724             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7725                 return false;
7726             }
7727             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7728                 return false;
7729             }
7730             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7731                 return false;
7732             }
7733             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7734                 return false;
7735             }
7736             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7737                 return false;
7738             }
7739             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7740                 return false;
7741             }
7742             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7743                 return false;
7744             }
7745             //            if ( labels.length != 7 ) {
7746             //                return false;
7747             //            }
7748             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7749             //                return false;
7750             //            }
7751             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7752             //                return false;
7753             //            }
7754             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7755             //                return false;
7756             //            }
7757             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7758             //                return false;
7759             //            }
7760             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7761             //                return false;
7762             //            }
7763             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7764             //                return false;
7765             //            }
7766             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7767             //                return false;
7768             //            }
7769             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7770             //            parser.parse();
7771             //            labels = parser.getCharStateLabels();
7772             //            if ( labels.length != 7 ) {
7773             //                return false;
7774             //            }
7775             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7776             //                return false;
7777             //            }
7778             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7779             //                return false;
7780             //            }
7781             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7782             //                return false;
7783             //            }
7784             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7785             //                return false;
7786             //            }
7787             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7788             //                return false;
7789             //            }
7790             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7791             //                return false;
7792             //            }
7793             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7794             //                return false;
7795             //            }
7796         }
7797         catch ( final Exception e ) {
7798             e.printStackTrace( System.out );
7799             return false;
7800         }
7801         return true;
7802     }
7803
7804     private static boolean testNexusTreeParsing() {
7805         try {
7806             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7807             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7808             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7809             if ( phylogenies.length != 1 ) {
7810                 return false;
7811             }
7812             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7813                 return false;
7814             }
7815             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7816                 return false;
7817             }
7818             phylogenies = null;
7819             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7820             if ( phylogenies.length != 1 ) {
7821                 return false;
7822             }
7823             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7824                 return false;
7825             }
7826             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7827                 return false;
7828             }
7829             phylogenies = null;
7830             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7831             if ( phylogenies.length != 1 ) {
7832                 return false;
7833             }
7834             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7835                 return false;
7836             }
7837             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7838                 return false;
7839             }
7840             if ( phylogenies[ 0 ].isRooted() ) {
7841                 return false;
7842             }
7843             phylogenies = null;
7844             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7845             if ( phylogenies.length != 18 ) {
7846                 return false;
7847             }
7848             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7849                 return false;
7850             }
7851             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7852                 return false;
7853             }
7854             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7855                 return false;
7856             }
7857             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7858                 return false;
7859             }
7860             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7861                 return false;
7862             }
7863             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7864                 return false;
7865             }
7866             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7867                 return false;
7868             }
7869             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7870                 return false;
7871             }
7872             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7873                 return false;
7874             }
7875             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7876                 return false;
7877             }
7878             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7879                 return false;
7880             }
7881             if ( phylogenies[ 8 ].isRooted() ) {
7882                 return false;
7883             }
7884             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7885                 return false;
7886             }
7887             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7888                 return false;
7889             }
7890             if ( !phylogenies[ 9 ].isRooted() ) {
7891                 return false;
7892             }
7893             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7894                 return false;
7895             }
7896             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7897                 return false;
7898             }
7899             if ( !phylogenies[ 10 ].isRooted() ) {
7900                 return false;
7901             }
7902             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7903                 return false;
7904             }
7905             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7906                 return false;
7907             }
7908             if ( phylogenies[ 11 ].isRooted() ) {
7909                 return false;
7910             }
7911             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7912                 return false;
7913             }
7914             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7915                 return false;
7916             }
7917             if ( !phylogenies[ 12 ].isRooted() ) {
7918                 return false;
7919             }
7920             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7921                 return false;
7922             }
7923             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7924                 return false;
7925             }
7926             if ( !phylogenies[ 13 ].isRooted() ) {
7927                 return false;
7928             }
7929             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7930                 return false;
7931             }
7932             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7933                 return false;
7934             }
7935             if ( !phylogenies[ 14 ].isRooted() ) {
7936                 return false;
7937             }
7938             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7939                 return false;
7940             }
7941             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7942                 return false;
7943             }
7944             if ( phylogenies[ 15 ].isRooted() ) {
7945                 return false;
7946             }
7947             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7948                 return false;
7949             }
7950             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7951                 return false;
7952             }
7953             if ( !phylogenies[ 16 ].isRooted() ) {
7954                 return false;
7955             }
7956             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7957                 return false;
7958             }
7959             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7960                 return false;
7961             }
7962             if ( phylogenies[ 17 ].isRooted() ) {
7963                 return false;
7964             }
7965             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7966                 return false;
7967             }
7968             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7969             phylogenies = null;
7970             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7971             if ( phylogenies.length != 9 ) {
7972                 return false;
7973             }
7974             if ( !isEqual( 0.48039661496919533,
7975                            phylogenies[ 0 ].getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7976                 return false;
7977             }
7978             if ( !isEqual( 0.3959796191512233,
7979                            phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7980                 return false;
7981             }
7982             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7983                 return false;
7984             }
7985             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7986                 return false;
7987             }
7988             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7989                 return false;
7990             }
7991             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7992                 return false;
7993             }
7994             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7995                 return false;
7996             }
7997         }
7998         catch ( final Exception e ) {
7999             e.printStackTrace( System.out );
8000             return false;
8001         }
8002         return true;
8003     }
8004
8005     private static boolean testNexusTreeParsingIterating() {
8006         try {
8007             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
8008             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
8009             if ( !p.hasNext() ) {
8010                 return false;
8011             }
8012             Phylogeny phy = p.next();
8013             if ( phy == null ) {
8014                 return false;
8015             }
8016             if ( phy.getNumberOfExternalNodes() != 25 ) {
8017                 return false;
8018             }
8019             if ( !phy.getName().equals( "" ) ) {
8020                 return false;
8021             }
8022             if ( p.hasNext() ) {
8023                 return false;
8024             }
8025             phy = p.next();
8026             if ( phy != null ) {
8027                 return false;
8028             }
8029             p.reset();
8030             if ( !p.hasNext() ) {
8031                 return false;
8032             }
8033             phy = p.next();
8034             if ( phy == null ) {
8035                 return false;
8036             }
8037             if ( phy.getNumberOfExternalNodes() != 25 ) {
8038                 return false;
8039             }
8040             if ( !phy.getName().equals( "" ) ) {
8041                 return false;
8042             }
8043             if ( p.hasNext() ) {
8044                 return false;
8045             }
8046             phy = p.next();
8047             if ( phy != null ) {
8048                 return false;
8049             }
8050             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
8051             if ( !p.hasNext() ) {
8052                 return false;
8053             }
8054             phy = p.next();
8055             if ( phy == null ) {
8056                 return false;
8057             }
8058             if ( phy.getNumberOfExternalNodes() != 10 ) {
8059                 return false;
8060             }
8061             if ( !phy.getName().equals( "name" ) ) {
8062                 return false;
8063             }
8064             if ( p.hasNext() ) {
8065                 return false;
8066             }
8067             phy = p.next();
8068             if ( phy != null ) {
8069                 return false;
8070             }
8071             p.reset();
8072             if ( !p.hasNext() ) {
8073                 return false;
8074             }
8075             phy = p.next();
8076             if ( phy == null ) {
8077                 return false;
8078             }
8079             if ( phy.getNumberOfExternalNodes() != 10 ) {
8080                 return false;
8081             }
8082             if ( !phy.getName().equals( "name" ) ) {
8083                 return false;
8084             }
8085             if ( p.hasNext() ) {
8086                 return false;
8087             }
8088             phy = p.next();
8089             if ( phy != null ) {
8090                 return false;
8091             }
8092             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
8093             if ( !p.hasNext() ) {
8094                 return false;
8095             }
8096             phy = p.next();
8097             if ( phy == null ) {
8098                 return false;
8099             }
8100             if ( phy.getNumberOfExternalNodes() != 3 ) {
8101                 return false;
8102             }
8103             if ( !phy.getName().equals( "" ) ) {
8104                 return false;
8105             }
8106             if ( phy.isRooted() ) {
8107                 return false;
8108             }
8109             if ( p.hasNext() ) {
8110                 return false;
8111             }
8112             phy = p.next();
8113             if ( phy != null ) {
8114                 return false;
8115             }
8116             //
8117             p.reset();
8118             if ( !p.hasNext() ) {
8119                 return false;
8120             }
8121             phy = p.next();
8122             if ( phy == null ) {
8123                 return false;
8124             }
8125             if ( phy.getNumberOfExternalNodes() != 3 ) {
8126                 return false;
8127             }
8128             if ( !phy.getName().equals( "" ) ) {
8129                 return false;
8130             }
8131             if ( p.hasNext() ) {
8132                 return false;
8133             }
8134             phy = p.next();
8135             if ( phy != null ) {
8136                 return false;
8137             }
8138             //
8139             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
8140             if ( !p.hasNext() ) {
8141                 return false;
8142             }
8143             //0
8144             phy = p.next();
8145             if ( phy == null ) {
8146                 return false;
8147             }
8148             if ( phy.getNumberOfExternalNodes() != 10 ) {
8149                 return false;
8150             }
8151             if ( !phy.getName().equals( "tree 0" ) ) {
8152                 return false;
8153             }
8154             //1
8155             if ( !p.hasNext() ) {
8156                 return false;
8157             }
8158             phy = p.next();
8159             if ( phy == null ) {
8160                 return false;
8161             }
8162             if ( phy.getNumberOfExternalNodes() != 10 ) {
8163                 return false;
8164             }
8165             if ( !phy.getName().equals( "tree 1" ) ) {
8166                 return false;
8167             }
8168             //2
8169             if ( !p.hasNext() ) {
8170                 return false;
8171             }
8172             phy = p.next();
8173             if ( phy == null ) {
8174                 return false;
8175             }
8176             if ( phy.getNumberOfExternalNodes() != 3 ) {
8177                 System.out.println( phy.toString() );
8178                 return false;
8179             }
8180             if ( !phy.getName().equals( "" ) ) {
8181                 return false;
8182             }
8183             if ( phy.isRooted() ) {
8184                 return false;
8185             }
8186             //3
8187             if ( !p.hasNext() ) {
8188                 return false;
8189             }
8190             phy = p.next();
8191             if ( phy == null ) {
8192                 return false;
8193             }
8194             if ( phy.getNumberOfExternalNodes() != 4 ) {
8195                 return false;
8196             }
8197             if ( !phy.getName().equals( "" ) ) {
8198                 return false;
8199             }
8200             if ( !phy.isRooted() ) {
8201                 return false;
8202             }
8203             //4
8204             if ( !p.hasNext() ) {
8205                 return false;
8206             }
8207             phy = p.next();
8208             if ( phy == null ) {
8209                 return false;
8210             }
8211             if ( phy.getNumberOfExternalNodes() != 5 ) {
8212                 System.out.println( phy.getNumberOfExternalNodes() );
8213                 return false;
8214             }
8215             if ( !phy.getName().equals( "" ) ) {
8216                 return false;
8217             }
8218             if ( !phy.isRooted() ) {
8219                 return false;
8220             }
8221             //5
8222             if ( !p.hasNext() ) {
8223                 return false;
8224             }
8225             phy = p.next();
8226             if ( phy == null ) {
8227                 return false;
8228             }
8229             if ( phy.getNumberOfExternalNodes() != 3 ) {
8230                 return false;
8231             }
8232             if ( !phy.getName().equals( "" ) ) {
8233                 return false;
8234             }
8235             if ( phy.isRooted() ) {
8236                 return false;
8237             }
8238             //6
8239             if ( !p.hasNext() ) {
8240                 return false;
8241             }
8242             phy = p.next();
8243             if ( phy == null ) {
8244                 return false;
8245             }
8246             if ( phy.getNumberOfExternalNodes() != 2 ) {
8247                 return false;
8248             }
8249             if ( !phy.getName().equals( "" ) ) {
8250                 return false;
8251             }
8252             if ( !phy.isRooted() ) {
8253                 return false;
8254             }
8255             //7
8256             if ( !p.hasNext() ) {
8257                 return false;
8258             }
8259             phy = p.next();
8260             if ( phy.getNumberOfExternalNodes() != 3 ) {
8261                 return false;
8262             }
8263             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8264                 return false;
8265             }
8266             if ( !phy.isRooted() ) {
8267                 return false;
8268             }
8269             //8
8270             if ( !p.hasNext() ) {
8271                 return false;
8272             }
8273             phy = p.next();
8274             if ( phy.getNumberOfExternalNodes() != 3 ) {
8275                 return false;
8276             }
8277             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
8278                 return false;
8279             }
8280             if ( !phy.getName().equals( "tree 8" ) ) {
8281                 return false;
8282             }
8283             //9
8284             if ( !p.hasNext() ) {
8285                 return false;
8286             }
8287             phy = p.next();
8288             if ( phy.getNumberOfExternalNodes() != 3 ) {
8289                 return false;
8290             }
8291             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
8292                 return false;
8293             }
8294             if ( !phy.getName().equals( "tree 9" ) ) {
8295                 return false;
8296             }
8297             //10
8298             if ( !p.hasNext() ) {
8299                 return false;
8300             }
8301             phy = p.next();
8302             if ( phy.getNumberOfExternalNodes() != 3 ) {
8303                 return false;
8304             }
8305             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8306                 return false;
8307             }
8308             if ( !phy.getName().equals( "tree 10" ) ) {
8309                 return false;
8310             }
8311             if ( !phy.isRooted() ) {
8312                 return false;
8313             }
8314             //11
8315             if ( !p.hasNext() ) {
8316                 return false;
8317             }
8318             phy = p.next();
8319             if ( phy.getNumberOfExternalNodes() != 3 ) {
8320                 return false;
8321             }
8322             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
8323                 return false;
8324             }
8325             if ( !phy.getName().equals( "tree 11" ) ) {
8326                 return false;
8327             }
8328             if ( phy.isRooted() ) {
8329                 return false;
8330             }
8331             //12
8332             if ( !p.hasNext() ) {
8333                 return false;
8334             }
8335             phy = p.next();
8336             if ( phy.getNumberOfExternalNodes() != 3 ) {
8337                 return false;
8338             }
8339             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
8340                 return false;
8341             }
8342             if ( !phy.getName().equals( "tree 12" ) ) {
8343                 return false;
8344             }
8345             if ( !phy.isRooted() ) {
8346                 return false;
8347             }
8348             //13
8349             if ( !p.hasNext() ) {
8350                 return false;
8351             }
8352             phy = p.next();
8353             if ( phy.getNumberOfExternalNodes() != 3 ) {
8354                 return false;
8355             }
8356             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8357                 return false;
8358             }
8359             if ( !phy.getName().equals( "tree 13" ) ) {
8360                 return false;
8361             }
8362             if ( !phy.isRooted() ) {
8363                 return false;
8364             }
8365             //14
8366             if ( !p.hasNext() ) {
8367                 return false;
8368             }
8369             phy = p.next();
8370             if ( phy.getNumberOfExternalNodes() != 10 ) {
8371                 System.out.println( phy.getNumberOfExternalNodes() );
8372                 return false;
8373             }
8374             if ( !phy.toNewHampshire()
8375                     .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;" ) ) {
8376                 System.out.println( phy.toNewHampshire() );
8377                 return false;
8378             }
8379             if ( !phy.getName().equals( "tree 14" ) ) {
8380                 return false;
8381             }
8382             if ( !phy.isRooted() ) {
8383                 return false;
8384             }
8385             //15
8386             if ( !p.hasNext() ) {
8387                 return false;
8388             }
8389             phy = p.next();
8390             if ( phy.getNumberOfExternalNodes() != 10 ) {
8391                 System.out.println( phy.getNumberOfExternalNodes() );
8392                 return false;
8393             }
8394             if ( !phy.toNewHampshire()
8395                     .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;" ) ) {
8396                 System.out.println( phy.toNewHampshire() );
8397                 return false;
8398             }
8399             if ( !phy.getName().equals( "tree 15" ) ) {
8400                 return false;
8401             }
8402             if ( phy.isRooted() ) {
8403                 return false;
8404             }
8405             //16
8406             if ( !p.hasNext() ) {
8407                 return false;
8408             }
8409             phy = p.next();
8410             if ( phy.getNumberOfExternalNodes() != 10 ) {
8411                 System.out.println( phy.getNumberOfExternalNodes() );
8412                 return false;
8413             }
8414             if ( !phy.toNewHampshire()
8415                     .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;" ) ) {
8416                 System.out.println( phy.toNewHampshire() );
8417                 return false;
8418             }
8419             if ( !phy.getName().equals( "tree 16" ) ) {
8420                 return false;
8421             }
8422             if ( !phy.isRooted() ) {
8423                 return false;
8424             }
8425             //17
8426             if ( !p.hasNext() ) {
8427                 return false;
8428             }
8429             phy = p.next();
8430             if ( phy.getNumberOfExternalNodes() != 10 ) {
8431                 System.out.println( phy.getNumberOfExternalNodes() );
8432                 return false;
8433             }
8434             if ( !phy.toNewHampshire()
8435                     .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;" ) ) {
8436                 System.out.println( phy.toNewHampshire() );
8437                 return false;
8438             }
8439             if ( !phy.getName().equals( "tree 17" ) ) {
8440                 return false;
8441             }
8442             if ( phy.isRooted() ) {
8443                 return false;
8444             }
8445             //
8446             if ( p.hasNext() ) {
8447                 return false;
8448             }
8449             phy = p.next();
8450             if ( phy != null ) {
8451                 return false;
8452             }
8453             p.reset();
8454             //0
8455             if ( !p.hasNext() ) {
8456                 return false;
8457             }
8458             phy = p.next();
8459             if ( phy == null ) {
8460                 return false;
8461             }
8462             if ( phy.getNumberOfExternalNodes() != 10 ) {
8463                 return false;
8464             }
8465             if ( !phy.getName().equals( "tree 0" ) ) {
8466                 return false;
8467             }
8468             //1
8469             if ( !p.hasNext() ) {
8470                 return false;
8471             }
8472             phy = p.next();
8473             if ( phy == null ) {
8474                 return false;
8475             }
8476             if ( phy.getNumberOfExternalNodes() != 10 ) {
8477                 return false;
8478             }
8479             if ( !phy.getName().equals( "tree 1" ) ) {
8480                 return false;
8481             }
8482             //2
8483             if ( !p.hasNext() ) {
8484                 return false;
8485             }
8486             phy = p.next();
8487             if ( phy == null ) {
8488                 return false;
8489             }
8490             if ( phy.getNumberOfExternalNodes() != 3 ) {
8491                 return false;
8492             }
8493             if ( !phy.getName().equals( "" ) ) {
8494                 return false;
8495             }
8496             if ( phy.isRooted() ) {
8497                 return false;
8498             }
8499             //3
8500             if ( !p.hasNext() ) {
8501                 return false;
8502             }
8503             phy = p.next();
8504             if ( phy == null ) {
8505                 return false;
8506             }
8507             if ( phy.getNumberOfExternalNodes() != 4 ) {
8508                 return false;
8509             }
8510             if ( !phy.getName().equals( "" ) ) {
8511                 return false;
8512             }
8513             if ( !phy.isRooted() ) {
8514                 return false;
8515             }
8516             //4
8517             if ( !p.hasNext() ) {
8518                 return false;
8519             }
8520             phy = p.next();
8521             if ( phy == null ) {
8522                 return false;
8523             }
8524             if ( phy.getNumberOfExternalNodes() != 5 ) {
8525                 System.out.println( phy.getNumberOfExternalNodes() );
8526                 return false;
8527             }
8528             if ( !phy.getName().equals( "" ) ) {
8529                 return false;
8530             }
8531             if ( !phy.isRooted() ) {
8532                 return false;
8533             }
8534             //5
8535             if ( !p.hasNext() ) {
8536                 return false;
8537             }
8538             phy = p.next();
8539             if ( phy == null ) {
8540                 return false;
8541             }
8542             if ( phy.getNumberOfExternalNodes() != 3 ) {
8543                 return false;
8544             }
8545             if ( !phy.getName().equals( "" ) ) {
8546                 return false;
8547             }
8548             if ( phy.isRooted() ) {
8549                 return false;
8550             }
8551             //
8552             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
8553             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
8554             // 0
8555             if ( !p2.hasNext() ) {
8556                 return false;
8557             }
8558             phy = p2.next();
8559             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8560                 return false;
8561             }
8562             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8563                 return false;
8564             }
8565             // 1
8566             if ( !p2.hasNext() ) {
8567                 return false;
8568             }
8569             phy = p2.next();
8570             // 2
8571             if ( !p2.hasNext() ) {
8572                 return false;
8573             }
8574             phy = p2.next();
8575             // 3
8576             if ( !p2.hasNext() ) {
8577                 return false;
8578             }
8579             phy = p2.next();
8580             // 4
8581             if ( !p2.hasNext() ) {
8582                 return false;
8583             }
8584             phy = p2.next();
8585             // 5
8586             if ( !p2.hasNext() ) {
8587                 return false;
8588             }
8589             phy = p2.next();
8590             // 6
8591             if ( !p2.hasNext() ) {
8592                 return false;
8593             }
8594             phy = p2.next();
8595             // 7
8596             if ( !p2.hasNext() ) {
8597                 return false;
8598             }
8599             phy = p2.next();
8600             // 8
8601             if ( !p2.hasNext() ) {
8602                 return false;
8603             }
8604             phy = p2.next();
8605             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
8606                 return false;
8607             }
8608             if ( p2.hasNext() ) {
8609                 return false;
8610             }
8611             phy = p2.next();
8612             if ( phy != null ) {
8613                 return false;
8614             }
8615             // 0
8616             p2.reset();
8617             if ( !p2.hasNext() ) {
8618                 return false;
8619             }
8620             phy = p2.next();
8621             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8622                 return false;
8623             }
8624             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8625                 return false;
8626             }
8627         }
8628         catch ( final Exception e ) {
8629             e.printStackTrace( System.out );
8630             return false;
8631         }
8632         return true;
8633     }
8634
8635     private static boolean testNexusTreeParsingTranslating() {
8636         try {
8637             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8638             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
8639             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
8640             if ( phylogenies.length != 1 ) {
8641                 return false;
8642             }
8643             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8644                 return false;
8645             }
8646             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8647                 return false;
8648             }
8649             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8650                 return false;
8651             }
8652             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8653                 return false;
8654             }
8655             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8656                     .equals( "Aranaeus" ) ) {
8657                 return false;
8658             }
8659             phylogenies = null;
8660             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
8661             if ( phylogenies.length != 3 ) {
8662                 return false;
8663             }
8664             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8665                 return false;
8666             }
8667             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8668                 return false;
8669             }
8670             if ( phylogenies[ 0 ].isRooted() ) {
8671                 return false;
8672             }
8673             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8674                 return false;
8675             }
8676             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8677                 return false;
8678             }
8679             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8680                     .equals( "Aranaeus" ) ) {
8681                 return false;
8682             }
8683             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8684                 return false;
8685             }
8686             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8687                 return false;
8688             }
8689             if ( phylogenies[ 1 ].isRooted() ) {
8690                 return false;
8691             }
8692             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8693                 return false;
8694             }
8695             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8696                 return false;
8697             }
8698             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8699                     .equals( "Aranaeus" ) ) {
8700                 return false;
8701             }
8702             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8703                 return false;
8704             }
8705             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8706                 return false;
8707             }
8708             if ( !phylogenies[ 2 ].isRooted() ) {
8709                 return false;
8710             }
8711             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8712                 return false;
8713             }
8714             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8715                 return false;
8716             }
8717             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8718                     .equals( "Aranaeus" ) ) {
8719                 return false;
8720             }
8721             phylogenies = null;
8722             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8723             if ( phylogenies.length != 3 ) {
8724                 return false;
8725             }
8726             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8727                 return false;
8728             }
8729             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8730                 return false;
8731             }
8732             if ( phylogenies[ 0 ].isRooted() ) {
8733                 return false;
8734             }
8735             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8736                 return false;
8737             }
8738             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8739                 return false;
8740             }
8741             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8742                     .equals( "Aranaeus" ) ) {
8743                 return false;
8744             }
8745             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8746                 return false;
8747             }
8748             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8749                 return false;
8750             }
8751             if ( phylogenies[ 1 ].isRooted() ) {
8752                 return false;
8753             }
8754             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8755                 return false;
8756             }
8757             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8758                 return false;
8759             }
8760             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8761                     .equals( "Aranaeus" ) ) {
8762                 return false;
8763             }
8764             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8765                 return false;
8766             }
8767             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8768                 return false;
8769             }
8770             if ( !phylogenies[ 2 ].isRooted() ) {
8771                 return false;
8772             }
8773             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8774                 return false;
8775             }
8776             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8777                 return false;
8778             }
8779             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8780                     .equals( "Aranaeus" ) ) {
8781                 return false;
8782             }
8783             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8784             if ( phylogenies.length != 3 ) {
8785                 return false;
8786             }
8787             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8788                            0.00100049 ) ) {
8789                 return false;
8790             }
8791         }
8792         catch ( final Exception e ) {
8793             e.printStackTrace( System.out );
8794             return false;
8795         }
8796         return true;
8797     }
8798
8799     private static boolean testNHParsing() {
8800         try {
8801             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8802             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8803             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8804                 return false;
8805             }
8806             final NHXParser nhxp = new NHXParser();
8807             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8808             nhxp.setReplaceUnderscores( true );
8809             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8810             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8811                 return false;
8812             }
8813             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8814                 return false;
8815             }
8816             final Phylogeny p1b = factory.create(
8817                                                   "   \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 ",
8818                                                   new NHXParser() )[ 0 ];
8819             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8820                 return false;
8821             }
8822             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8823                 return false;
8824             }
8825             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ).toString(), new NHXParser() )[ 0 ];
8826             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8827             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8828             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ).toString(), new NHXParser() )[ 0 ];
8829             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8830             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8831             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8832             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8833             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8834             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8835             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8836                     + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; " + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8837                                                     new NHXParser() );
8838             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8839                 return false;
8840             }
8841             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8842                 return false;
8843             }
8844             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8845                 return false;
8846             }
8847             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8848                 return false;
8849             }
8850             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8851             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8852             final String p16_S = "((A,B),C)";
8853             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8854             if ( p16.length != 1 ) {
8855                 return false;
8856             }
8857             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8858                 return false;
8859             }
8860             final String p17_S = "(C,(A,B))";
8861             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8862             if ( p17.length != 1 ) {
8863                 return false;
8864             }
8865             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8866                 return false;
8867             }
8868             final String p18_S = "((A,B),(C,D))";
8869             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8870             if ( p18.length != 1 ) {
8871                 return false;
8872             }
8873             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8874                 return false;
8875             }
8876             final String p19_S = "(((A,B),C),D)";
8877             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8878             if ( p19.length != 1 ) {
8879                 return false;
8880             }
8881             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8882                 return false;
8883             }
8884             final String p20_S = "(A,(B,(C,D)))";
8885             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8886             if ( p20.length != 1 ) {
8887                 return false;
8888             }
8889             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8890                 return false;
8891             }
8892             final String p21_S = "(A,(B,(C,(D,E))))";
8893             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8894             if ( p21.length != 1 ) {
8895                 return false;
8896             }
8897             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8898                 return false;
8899             }
8900             final String p22_S = "((((A,B),C),D),E)";
8901             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8902             if ( p22.length != 1 ) {
8903                 return false;
8904             }
8905             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8906                 return false;
8907             }
8908             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8909             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8910             if ( p23.length != 1 ) {
8911                 System.out.println( "xl=" + p23.length );
8912                 System.exit( -1 );
8913                 return false;
8914             }
8915             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8916                 return false;
8917             }
8918             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8919             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8920             if ( p24.length != 1 ) {
8921                 return false;
8922             }
8923             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8924                 return false;
8925             }
8926             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8927             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8928             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8929             if ( p241.length != 2 ) {
8930                 return false;
8931             }
8932             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8933                 return false;
8934             }
8935             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8936                 return false;
8937             }
8938             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8939                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8940                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8941                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8942                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8943                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8944                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8945                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8946             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8947             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8948                 return false;
8949             }
8950             final String p26_S = "(A,B)ab";
8951             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8952             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8953                 return false;
8954             }
8955             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8956             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8957             if ( p27s.length != 1 ) {
8958                 System.out.println( "xxl=" + p27s.length );
8959                 System.exit( -1 );
8960                 return false;
8961             }
8962             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8963                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8964                 System.exit( -1 );
8965                 return false;
8966             }
8967             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8968                                                     new NHXParser() );
8969             if ( p27.length != 1 ) {
8970                 System.out.println( "yl=" + p27.length );
8971                 System.exit( -1 );
8972                 return false;
8973             }
8974             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8975                 System.out.println( p27[ 0 ].toNewHampshireX() );
8976                 System.exit( -1 );
8977                 return false;
8978             }
8979             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8980             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8981             final String p28_S3 = "(A,B)ab";
8982             final String p28_S4 = "((((A,B),C),D),;E;)";
8983             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8984                                                     new NHXParser() );
8985             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8986                 return false;
8987             }
8988             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8989                 return false;
8990             }
8991             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8992                 return false;
8993             }
8994             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8995                 return false;
8996             }
8997             if ( p28.length != 4 ) {
8998                 return false;
8999             }
9000             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";
9001             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
9002             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
9003                 return false;
9004             }
9005             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";
9006             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
9007             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
9008                 return false;
9009             }
9010             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
9011             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
9012             if ( ( p32.length != 0 ) ) {
9013                 return false;
9014             }
9015             final String p33_S = "A";
9016             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
9017             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
9018                 return false;
9019             }
9020             final String p34_S = "B;";
9021             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
9022             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
9023                 return false;
9024             }
9025             final String p35_S = "B:0.2";
9026             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
9027             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
9028                 return false;
9029             }
9030             final String p36_S = "(A)";
9031             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
9032             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
9033                 return false;
9034             }
9035             final String p37_S = "((A))";
9036             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
9037             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
9038                 return false;
9039             }
9040             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
9041             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
9042             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
9043                 return false;
9044             }
9045             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
9046             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
9047             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
9048                 return false;
9049             }
9050             final String p40_S = "(A,B,C)";
9051             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
9052             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
9053                 return false;
9054             }
9055             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
9056             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
9057             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
9058                 return false;
9059             }
9060             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
9061             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
9062             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
9063                 return false;
9064             }
9065             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)";
9066             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
9067             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
9068                 return false;
9069             }
9070             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)))";
9071             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
9072             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
9073                 return false;
9074             }
9075             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
9076             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
9077             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
9078                 return false;
9079             }
9080             final String p46_S = "";
9081             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
9082             if ( p46.length != 0 ) {
9083                 return false;
9084             }
9085             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ).toString(),
9086                                                   new NHXParser() )[ 0 ];
9087             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
9088                 return false;
9089             }
9090             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ).toString(),
9091                                                   new NHXParser() )[ 0 ];
9092             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
9093                 return false;
9094             }
9095             final Phylogeny p49 = factory
9096                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ).toString(),
9097                              new NHXParser() )[ 0 ];
9098             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
9099                 return false;
9100             }
9101             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ).toString(),
9102                                                   new NHXParser() )[ 0 ];
9103             if ( p50.getNode( "A" ) == null ) {
9104                 return false;
9105             }
9106             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9107                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
9108                 return false;
9109             }
9110             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
9111                 return false;
9112             }
9113             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
9114                     .equals( "((A,B)88:2.0,C);" ) ) {
9115                 return false;
9116             }
9117             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ).toString(),
9118                                                   new NHXParser() )[ 0 ];
9119             if ( p51.getNode( "A(A" ) == null ) {
9120                 return false;
9121             }
9122             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ).toString(),
9123                                                   new NHXParser() )[ 0 ];
9124             if ( p52.getNode( "A(A" ) == null ) {
9125                 return false;
9126             }
9127             final Phylogeny p53 = factory
9128                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ).toString(),
9129                              new NHXParser() )[ 0 ];
9130             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
9131                 return false;
9132             }
9133             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ).toString(),
9134                                                   new NHXParser() )[ 0 ];
9135             if ( p54.getNode( "A" ) == null ) {
9136                 return false;
9137             }
9138             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9139                     .equals( "((A,B)[88],C);" ) ) {
9140                 return false;
9141             }
9142             final Phylogeny p55 = factory
9143                     .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);" )
9144                             .toString(), new NHXParser() )[ 0 ];
9145             if ( !p55.toNewHampshire()
9146                     .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);" ) ) {
9147                 System.out.println( p55.toNewHampshire() );
9148                 return false;
9149             }
9150             final Phylogeny p56 = factory
9151                     .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);" )
9152                             .toString(), new NHXParser() )[ 0 ];
9153             if ( !p56.toNewHampshire()
9154                     .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);" ) ) {
9155                 System.out.println( p56.toNewHampshire() );
9156                 return false;
9157             }
9158             final Phylogeny p57 = factory
9159                     .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);" )
9160                             .toString(), new NHXParser() )[ 0 ];
9161             if ( !p57.toNewHampshire()
9162                     .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);" ) ) {
9163                 System.out.println( p56.toNewHampshire() );
9164                 return false;
9165             }
9166             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
9167             final Phylogeny p58 = factory.create( s58, new NHXParser() )[ 0 ];
9168             if ( !p58.toNewHampshire().equals( s58 ) ) {
9169                 System.out.println( p58.toNewHampshire() );
9170                 return false;
9171             }
9172             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
9173             final Phylogeny p59 = factory.create( s59, new NHXParser() )[ 0 ];
9174             if ( !p59.toNewHampshire().equals( s59 ) ) {
9175                 System.out.println( p59.toNewHampshire() );
9176                 return false;
9177             }
9178             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
9179             final Phylogeny p60 = factory.create( s60, new NHXParser() )[ 0 ];
9180             if ( !p60.toNewHampshire().equals( s60 ) ) {
9181                 System.out.println( p60.toNewHampshire() );
9182                 return false;
9183             }
9184             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
9185             final Phylogeny p61 = factory.create( s61, new NHXParser() )[ 0 ];
9186             if ( !p61.toNewHampshire()
9187                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
9188                 System.out.println( p61.toNewHampshire() );
9189                 return false;
9190             }
9191             final String s62 = "(1[&type=\"X\",size=123,subtree=(1,2);]:0.003,2[&type=\"(X,Y:3)\"]:0.004)[&type=\"(X,Y)\"]:0.0;";
9192             final Phylogeny p62 = factory.create( s62, new NHXParser() )[ 0 ];
9193             if ( !p62.toNewHampshire().equals( "(1:0.003,2:0.004):0.0;" ) ) {
9194                 System.out.println( p62.toNewHampshire() );
9195                 return false;
9196             }
9197             final String s63 = "(1:0.003[&type=\"X\",size=123,subtree=(1,2);],2:0.004[&type=\"(X,Y:3)\"]):0.0[&type=\"(X,Y)\"];";
9198             final Phylogeny p63 = factory.create( s63, new NHXParser() )[ 0 ];
9199             if ( !p63.toNewHampshire().equals( "(1:0.003,2:0.004):0.0;" ) ) {
9200                 System.out.println( p63.toNewHampshire() );
9201                 return false;
9202             }
9203             final String s64 = "((1,2):[95.5],3);";
9204             final Phylogeny p64 = factory.create( s64, new NHXParser() )[ 0 ];
9205             if ( !p64.toNewHampshireX().equals( "((1,2)[&&NHX:B=95.5],3)" ) ) {
9206                 System.out.println( p64.toNewHampshireX() );
9207                 return false;
9208             }
9209             final String s65 = "((1:0.1,2:0.2):0.3[10.2],3);";
9210             final Phylogeny p65 = factory.create( s65, new NHXParser() )[ 0 ];
9211             if ( !p65.toNewHampshireX().equals( "((1:0.1,2:0.2):0.3[&&NHX:B=10.2],3)" ) ) {
9212                 System.out.println( p65.toNewHampshireX() );
9213                 return false;
9214             }
9215             final Phylogeny p66 = factory.create( "((A,B)ab:2[0.44],C)", new NHXParser() )[ 0 ];
9216             if ( !isEqual( 0.44, p66.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
9217                 return false;
9218             }
9219             final Phylogeny p67 = factory.create( "((A,B):2[0.67],C)", new NHXParser() )[ 0 ];
9220             if ( !isEqual( 0.67, p67.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9221                 return false;
9222             }
9223             final Phylogeny p68 = factory.create( "((A,B):[0.68],C)", new NHXParser() )[ 0 ];
9224             if ( !isEqual( 0.68, p68.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9225                 return false;
9226             }
9227             final Phylogeny p69 = factory.create( "((A,B)[0.69],C)", new NHXParser() )[ 0 ];
9228             if ( !isEqual( 0.69, p69.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9229                 return false;
9230             }
9231             final Phylogeny p70 = factory.create( "((A,B)[+0.7],C)", new NHXParser() )[ 0 ];
9232             if ( !isEqual( 0.7, p70.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9233                 return false;
9234             }
9235             final Phylogeny p71 = factory.create( "((A,B)[-0.71],C)", new NHXParser() )[ 0 ];
9236             if ( !isEqual( -0.71, p71.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9237                 return false;
9238             }
9239             final Phylogeny p72 = factory.create( "((A,B)[],C)", new NHXParser() )[ 0 ];
9240             if ( !p72.toNewHampshireX().equals( "((A,B),C)" ) ) {
9241                 return false;
9242             }
9243             final Phylogeny p73 = factory.create( "((A,B)[12x],C)", new NHXParser() )[ 0 ];
9244             if ( !p73.toNewHampshireX().equals( "((A,B),C)" ) ) {
9245                 return false;
9246             }
9247             final Phylogeny p74 = factory.create( "((A,B)[12+],C)", new NHXParser() )[ 0 ];
9248             if ( !p74.toNewHampshireX().equals( "((A,B),C)" ) ) {
9249                 return false;
9250             }
9251             final Phylogeny p75 = factory.create( "((A,B)ab[222]:3,C)", new NHXParser() )[ 0 ];
9252             if ( !isEqual( 222, p75.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9253                 return false;
9254             }
9255             final Phylogeny p76 = factory.create( "((A,B)[100]:12,C)", new NHXParser() )[ 0 ];
9256             if ( !isEqual( 100, p76.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9257                 return false;
9258             }
9259             final Phylogeny p77 = factory.create( "((A,B)abcde:13[77],C)", new NHXParser() )[ 0 ];
9260             if ( !isEqual( 77, p77.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9261                 return false;
9262             }
9263             final Phylogeny p78 = factory.create( "((A,B):14[0],C)", new NHXParser() )[ 0 ];
9264             if ( !isEqual( 0, p78.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9265                 return false;
9266             }
9267             final String the_one = "((((((a,b)ab:3.0[2],c):12.0[100],(d,e)de)abcde:13.0[2],f):14.0[0]):0.0[0]):0.0[0];";
9268             final Phylogeny p79 = factory.create(
9269                                                   "((((((a,b)ab[2]:3,c)[100]:12,(d,e)de)abcde:13[2],f):14[0]):0[0])[0]:0;",
9270                                                   new NHXParser() )[ 0 ];
9271             final String str79 = p79.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
9272             if ( !str79.equals( the_one ) ) {
9273                 System.out.println( str79 );
9274                 return false;
9275             }
9276             final Phylogeny p80 = factory.create(
9277                                                   "((((((a[a)],b[12])ab[2]:3,c)[+100]:12,(d,e)de[12d,)])ab[]c[]de:13[2],f):14[0]):0[0])[0]:0;",
9278                                                   new NHXParser() )[ 0 ];
9279             final String str80 = p80.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
9280             if ( !str80.equals( the_one ) ) {
9281                 System.out.println( str80 );
9282                 return false;
9283             }
9284         }
9285         catch ( final Exception e ) {
9286             e.printStackTrace( System.out );
9287             return false;
9288         }
9289         return true;
9290     }
9291
9292     private static boolean testNHParsingSpecialChars() {
9293         try {
9294             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9295             final String i0 = "(A!+=~QWERTY!@#$%^&*-,€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ)";
9296             final Phylogeny p0 = factory.create( i0, new NHXParser() )[ 0 ];
9297             if ( !p0.toNewHampshireX().equals( i0 ) ) {
9298                 System.out.println();
9299                 System.out.println( p0.toNewHampshireX() );
9300                 System.out.println( i0 );
9301                 return false;
9302             }
9303             final String i1 = "(हिंदी,한글,ไทย,'Tiếng Việt',ひらがなカタカナ漢字,繁體字,русский)";
9304             final Phylogeny p1 = factory.create( i1, new NHXParser() )[ 0 ];
9305             if ( !p1.toNewHampshireX().equals( i1 ) ) {
9306                 System.out.println();
9307                 System.out.println( p1.toNewHampshireX() );
9308                 System.out.println( i1 );
9309                 return false;
9310             }
9311         }
9312         catch ( final Exception e ) {
9313             e.printStackTrace( System.out );
9314             return false;
9315         }
9316         return true;
9317     }
9318
9319     private static boolean testNHParsingIter() {
9320         try {
9321             final String p0_str = "(A,B);";
9322             final NHXParser p = new NHXParser();
9323             p.setSource( p0_str );
9324             if ( !p.hasNext() ) {
9325                 return false;
9326             }
9327             final Phylogeny p0 = p.next();
9328             if ( !p0.toNewHampshire().equals( p0_str ) ) {
9329                 System.out.println( p0.toNewHampshire() );
9330                 return false;
9331             }
9332             if ( p.hasNext() ) {
9333                 return false;
9334             }
9335             if ( p.next() != null ) {
9336                 return false;
9337             }
9338             //
9339             final String p00_str = "(A,B)root;";
9340             p.setSource( p00_str );
9341             final Phylogeny p00 = p.next();
9342             if ( !p00.toNewHampshire().equals( p00_str ) ) {
9343                 System.out.println( p00.toNewHampshire() );
9344                 return false;
9345             }
9346             //
9347             final String p000_str = "A;";
9348             p.setSource( p000_str );
9349             final Phylogeny p000 = p.next();
9350             if ( !p000.toNewHampshire().equals( p000_str ) ) {
9351                 System.out.println( p000.toNewHampshire() );
9352                 return false;
9353             }
9354             //
9355             final String p0000_str = "A";
9356             p.setSource( p0000_str );
9357             final Phylogeny p0000 = p.next();
9358             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
9359                 System.out.println( p0000.toNewHampshire() );
9360                 return false;
9361             }
9362             //
9363             p.setSource( "(A)" );
9364             final Phylogeny p00000 = p.next();
9365             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
9366                 System.out.println( p00000.toNewHampshire() );
9367                 return false;
9368             }
9369             //
9370             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
9371             p.setSource( p1_str );
9372             if ( !p.hasNext() ) {
9373                 return false;
9374             }
9375             final Phylogeny p1_0 = p.next();
9376             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
9377                 System.out.println( p1_0.toNewHampshire() );
9378                 return false;
9379             }
9380             if ( !p.hasNext() ) {
9381                 return false;
9382             }
9383             final Phylogeny p1_1 = p.next();
9384             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
9385                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
9386                 return false;
9387             }
9388             if ( !p.hasNext() ) {
9389                 return false;
9390             }
9391             final Phylogeny p1_2 = p.next();
9392             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
9393                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
9394                 return false;
9395             }
9396             if ( !p.hasNext() ) {
9397                 return false;
9398             }
9399             final Phylogeny p1_3 = p.next();
9400             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
9401                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
9402                 return false;
9403             }
9404             if ( p.hasNext() ) {
9405                 return false;
9406             }
9407             if ( p.next() != null ) {
9408                 return false;
9409             }
9410             //
9411             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
9412             p.setSource( p2_str );
9413             if ( !p.hasNext() ) {
9414                 return false;
9415             }
9416             Phylogeny p2_0 = p.next();
9417             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9418                 System.out.println( p2_0.toNewHampshire() );
9419                 return false;
9420             }
9421             if ( !p.hasNext() ) {
9422                 return false;
9423             }
9424             Phylogeny p2_1 = p.next();
9425             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9426                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9427                 return false;
9428             }
9429             if ( !p.hasNext() ) {
9430                 return false;
9431             }
9432             Phylogeny p2_2 = p.next();
9433             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9434                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9435                 return false;
9436             }
9437             if ( !p.hasNext() ) {
9438                 return false;
9439             }
9440             Phylogeny p2_3 = p.next();
9441             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9442                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9443                 return false;
9444             }
9445             if ( !p.hasNext() ) {
9446                 return false;
9447             }
9448             Phylogeny p2_4 = p.next();
9449             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9450                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9451                 return false;
9452             }
9453             if ( p.hasNext() ) {
9454                 return false;
9455             }
9456             if ( p.next() != null ) {
9457                 return false;
9458             }
9459             ////
9460             p.reset();
9461             if ( !p.hasNext() ) {
9462                 return false;
9463             }
9464             p2_0 = p.next();
9465             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9466                 System.out.println( p2_0.toNewHampshire() );
9467                 return false;
9468             }
9469             if ( !p.hasNext() ) {
9470                 return false;
9471             }
9472             p2_1 = p.next();
9473             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9474                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9475                 return false;
9476             }
9477             if ( !p.hasNext() ) {
9478                 return false;
9479             }
9480             p2_2 = p.next();
9481             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9482                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9483                 return false;
9484             }
9485             if ( !p.hasNext() ) {
9486                 return false;
9487             }
9488             p2_3 = p.next();
9489             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9490                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9491                 return false;
9492             }
9493             if ( !p.hasNext() ) {
9494                 return false;
9495             }
9496             p2_4 = p.next();
9497             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9498                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9499                 return false;
9500             }
9501             if ( p.hasNext() ) {
9502                 return false;
9503             }
9504             if ( p.next() != null ) {
9505                 return false;
9506             }
9507             //
9508             final String p3_str = "((A,B),C)abc";
9509             p.setSource( p3_str );
9510             if ( !p.hasNext() ) {
9511                 return false;
9512             }
9513             final Phylogeny p3_0 = p.next();
9514             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
9515                 return false;
9516             }
9517             if ( p.hasNext() ) {
9518                 return false;
9519             }
9520             if ( p.next() != null ) {
9521                 return false;
9522             }
9523             //
9524             final String p4_str = "((A,B)ab,C)abc";
9525             p.setSource( p4_str );
9526             if ( !p.hasNext() ) {
9527                 return false;
9528             }
9529             final Phylogeny p4_0 = p.next();
9530             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
9531                 return false;
9532             }
9533             if ( p.hasNext() ) {
9534                 return false;
9535             }
9536             if ( p.next() != null ) {
9537                 return false;
9538             }
9539             //
9540             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
9541             p.setSource( p5_str );
9542             if ( !p.hasNext() ) {
9543                 return false;
9544             }
9545             final Phylogeny p5_0 = p.next();
9546             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
9547                 return false;
9548             }
9549             if ( p.hasNext() ) {
9550                 return false;
9551             }
9552             if ( p.next() != null ) {
9553                 return false;
9554             }
9555             //
9556             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
9557             p.setSource( p6_str );
9558             if ( !p.hasNext() ) {
9559                 return false;
9560             }
9561             Phylogeny p6_0 = p.next();
9562             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9563                 return false;
9564             }
9565             if ( p.hasNext() ) {
9566                 return false;
9567             }
9568             if ( p.next() != null ) {
9569                 return false;
9570             }
9571             p.reset();
9572             if ( !p.hasNext() ) {
9573                 return false;
9574             }
9575             p6_0 = p.next();
9576             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9577                 return false;
9578             }
9579             if ( p.hasNext() ) {
9580                 return false;
9581             }
9582             if ( p.next() != null ) {
9583                 return false;
9584             }
9585             //
9586             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
9587             p.setSource( p7_str );
9588             if ( !p.hasNext() ) {
9589                 return false;
9590             }
9591             Phylogeny p7_0 = p.next();
9592             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9593                 return false;
9594             }
9595             if ( p.hasNext() ) {
9596                 return false;
9597             }
9598             if ( p.next() != null ) {
9599                 return false;
9600             }
9601             p.reset();
9602             if ( !p.hasNext() ) {
9603                 return false;
9604             }
9605             p7_0 = p.next();
9606             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9607                 return false;
9608             }
9609             if ( p.hasNext() ) {
9610                 return false;
9611             }
9612             if ( p.next() != null ) {
9613                 return false;
9614             }
9615             //
9616             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
9617             p.setSource( p8_str );
9618             if ( !p.hasNext() ) {
9619                 return false;
9620             }
9621             Phylogeny p8_0 = p.next();
9622             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9623                 return false;
9624             }
9625             if ( !p.hasNext() ) {
9626                 return false;
9627             }
9628             if ( !p.hasNext() ) {
9629                 return false;
9630             }
9631             Phylogeny p8_1 = p.next();
9632             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9633                 return false;
9634             }
9635             if ( p.hasNext() ) {
9636                 return false;
9637             }
9638             if ( p.next() != null ) {
9639                 return false;
9640             }
9641             p.reset();
9642             if ( !p.hasNext() ) {
9643                 return false;
9644             }
9645             p8_0 = p.next();
9646             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9647                 return false;
9648             }
9649             if ( !p.hasNext() ) {
9650                 return false;
9651             }
9652             p8_1 = p.next();
9653             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9654                 return false;
9655             }
9656             if ( p.hasNext() ) {
9657                 return false;
9658             }
9659             if ( p.next() != null ) {
9660                 return false;
9661             }
9662             p.reset();
9663             //
9664             p.setSource( "" );
9665             if ( p.hasNext() ) {
9666                 return false;
9667             }
9668             //
9669             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
9670             if ( !p.hasNext() ) {
9671                 return false;
9672             }
9673             Phylogeny p_27 = p.next();
9674             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9675                 System.out.println( p_27.toNewHampshireX() );
9676                 System.exit( -1 );
9677                 return false;
9678             }
9679             if ( p.hasNext() ) {
9680                 return false;
9681             }
9682             if ( p.next() != null ) {
9683                 return false;
9684             }
9685             p.reset();
9686             if ( !p.hasNext() ) {
9687                 return false;
9688             }
9689             p_27 = p.next();
9690             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9691                 System.out.println( p_27.toNewHampshireX() );
9692                 System.exit( -1 );
9693                 return false;
9694             }
9695             if ( p.hasNext() ) {
9696                 return false;
9697             }
9698             if ( p.next() != null ) {
9699                 return false;
9700             }
9701             //
9702             final String p30_str = "(A,B);(C,D)";
9703             final NHXParser p30 = new NHXParser();
9704             p30.setSource( p30_str );
9705             if ( !p30.hasNext() ) {
9706                 return false;
9707             }
9708             Phylogeny phy30 = p30.next();
9709             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9710                 System.out.println( phy30.toNewHampshire() );
9711                 return false;
9712             }
9713             if ( !p30.hasNext() ) {
9714                 return false;
9715             }
9716             Phylogeny phy301 = p30.next();
9717             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9718                 System.out.println( phy301.toNewHampshire() );
9719                 return false;
9720             }
9721             if ( p30.hasNext() ) {
9722                 return false;
9723             }
9724             if ( p30.hasNext() ) {
9725                 return false;
9726             }
9727             if ( p30.next() != null ) {
9728                 return false;
9729             }
9730             if ( p30.next() != null ) {
9731                 return false;
9732             }
9733             p30.reset();
9734             if ( !p30.hasNext() ) {
9735                 return false;
9736             }
9737             phy30 = p30.next();
9738             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9739                 System.out.println( phy30.toNewHampshire() );
9740                 return false;
9741             }
9742             if ( !p30.hasNext() ) {
9743                 return false;
9744             }
9745             phy301 = p30.next();
9746             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9747                 System.out.println( phy301.toNewHampshire() );
9748                 return false;
9749             }
9750             if ( p30.hasNext() ) {
9751                 return false;
9752             }
9753             if ( p30.hasNext() ) {
9754                 return false;
9755             }
9756             if ( p30.next() != null ) {
9757                 return false;
9758             }
9759             if ( p30.next() != null ) {
9760                 return false;
9761             }
9762         }
9763         catch ( final Exception e ) {
9764             e.printStackTrace( System.out );
9765             return false;
9766         }
9767         return true;
9768     }
9769
9770     private static boolean testNHXconversion() {
9771         try {
9772             final PhylogenyNode n1 = new PhylogenyNode();
9773             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9774             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9775             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9776             final PhylogenyNode n5 = PhylogenyNode
9777                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
9778             final PhylogenyNode n6 = PhylogenyNode
9779                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
9780             if ( !n1.toNewHampshireX().equals( "" ) ) {
9781                 return false;
9782             }
9783             if ( !n2.toNewHampshireX().equals( "" ) ) {
9784                 return false;
9785             }
9786             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
9787                 return false;
9788             }
9789             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
9790                 return false;
9791             }
9792             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
9793                 return false;
9794             }
9795             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9796                 System.out.println( n6.toNewHampshireX() );
9797                 return false;
9798             }
9799             final PhylogenyNode n7 = new PhylogenyNode();
9800             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9801             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9802                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9803                 System.out.println( n7
9804                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9805                 return false;
9806             }
9807         }
9808         catch ( final Exception e ) {
9809             e.printStackTrace( System.out );
9810             return false;
9811         }
9812         return true;
9813     }
9814
9815     private static boolean testNHXNodeParsing() {
9816         try {
9817             final PhylogenyNode n1 = new PhylogenyNode();
9818             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9819             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9820             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9821             final PhylogenyNode n5 = PhylogenyNode
9822                     .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]" );
9823             if ( !n3.getName().equals( "n3" ) ) {
9824                 return false;
9825             }
9826             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9827                 return false;
9828             }
9829             if ( n3.isDuplication() ) {
9830                 return false;
9831             }
9832             if ( n3.isHasAssignedEvent() ) {
9833                 return false;
9834             }
9835             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9836                 return false;
9837             }
9838             if ( !n4.getName().equals( "n4" ) ) {
9839                 return false;
9840             }
9841             if ( n4.getDistanceToParent() != 0.01 ) {
9842                 return false;
9843             }
9844             if ( !n5.getName().equals( "n5" ) ) {
9845                 return false;
9846             }
9847             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9848                 return false;
9849             }
9850             if ( n5.getDistanceToParent() != 0.1 ) {
9851                 return false;
9852             }
9853             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9854                 return false;
9855             }
9856             if ( !n5.isDuplication() ) {
9857                 return false;
9858             }
9859             if ( !n5.isHasAssignedEvent() ) {
9860                 return false;
9861             }
9862             final PhylogenyNode n8 = PhylogenyNode
9863                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9864                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9865             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9866                 return false;
9867             }
9868             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9869                 return false;
9870             }
9871             final PhylogenyNode n9 = PhylogenyNode
9872                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9873                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9874             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9875                 return false;
9876             }
9877             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9878                 return false;
9879             }
9880             final PhylogenyNode n10 = PhylogenyNode
9881                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9882             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9883                 return false;
9884             }
9885             final PhylogenyNode n20 = PhylogenyNode
9886                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9887             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9888                 return false;
9889             }
9890             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9891                 return false;
9892             }
9893             final PhylogenyNode n20x = PhylogenyNode
9894                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9895             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9896                 return false;
9897             }
9898             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9899                 return false;
9900             }
9901             final PhylogenyNode n20xx = PhylogenyNode
9902                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9903             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9904                 return false;
9905             }
9906             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9907                 return false;
9908             }
9909             final PhylogenyNode n20xxx = PhylogenyNode
9910                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9911             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9912                 return false;
9913             }
9914             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9915                 return false;
9916             }
9917             final PhylogenyNode n20xxxx = PhylogenyNode
9918                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9919             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9920                 return false;
9921             }
9922             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9923                 return false;
9924             }
9925             final PhylogenyNode n21 = PhylogenyNode
9926                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9927             if ( !n21.getName().equals( "N21_PIG" ) ) {
9928                 return false;
9929             }
9930             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9931                 return false;
9932             }
9933             final PhylogenyNode n21x = PhylogenyNode
9934                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9935             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9936                 return false;
9937             }
9938             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9939                 return false;
9940             }
9941             final PhylogenyNode n22 = PhylogenyNode
9942                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9943             if ( !n22.getName().equals( "n22/PIG" ) ) {
9944                 return false;
9945             }
9946             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9947                 return false;
9948             }
9949             final PhylogenyNode n23 = PhylogenyNode
9950                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9951             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9952                 return false;
9953             }
9954             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9955                 return false;
9956             }
9957             final PhylogenyNode a = PhylogenyNode
9958                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9959             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9960                 return false;
9961             }
9962             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9963                 return false;
9964             }
9965             final PhylogenyNode c1 = PhylogenyNode
9966                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9967                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9968             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9969                 return false;
9970             }
9971             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9972                 return false;
9973             }
9974             final PhylogenyNode c2 = PhylogenyNode
9975                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9976                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9977             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9978                 return false;
9979             }
9980             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9981                 return false;
9982             }
9983             final PhylogenyNode e3 = PhylogenyNode
9984                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9985             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9986                 return false;
9987             }
9988             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9989                 return false;
9990             }
9991             final PhylogenyNode n11 = PhylogenyNode
9992                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9993                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9994             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9995                 return false;
9996             }
9997             if ( n11.getDistanceToParent() != 0.4 ) {
9998                 return false;
9999             }
10000             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
10001                 return false;
10002             }
10003             final PhylogenyNode n12 = PhylogenyNode
10004                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
10005                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10006             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
10007                 return false;
10008             }
10009             if ( n12.getDistanceToParent() != 0.4 ) {
10010                 return false;
10011             }
10012             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
10013                 return false;
10014             }
10015             final PhylogenyNode o = PhylogenyNode
10016                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10017             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
10018                 return false;
10019             }
10020             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
10021                 return false;
10022             }
10023             if ( n1.getName().compareTo( "" ) != 0 ) {
10024                 return false;
10025             }
10026             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
10027                 return false;
10028             }
10029             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
10030                 return false;
10031             }
10032             if ( n2.getName().compareTo( "" ) != 0 ) {
10033                 return false;
10034             }
10035             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
10036                 return false;
10037             }
10038             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
10039                 return false;
10040             }
10041             final PhylogenyNode n00 = PhylogenyNode
10042                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
10043             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
10044                 return false;
10045             }
10046             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
10047                 return false;
10048             }
10049             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
10050             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
10051                 return false;
10052             }
10053             final PhylogenyNode n13 = PhylogenyNode
10054                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10055             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
10056                 return false;
10057             }
10058             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
10059                 return false;
10060             }
10061             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10062                 return false;
10063             }
10064             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
10065                 return false;
10066             }
10067             final PhylogenyNode n14 = PhylogenyNode
10068                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10069             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
10070                 return false;
10071             }
10072             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
10073                 return false;
10074             }
10075             final PhylogenyNode n15 = PhylogenyNode
10076                     .createInstanceFromNhxString( "something_wicked[123]",
10077                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10078             if ( !n15.getName().equals( "something_wicked" ) ) {
10079                 return false;
10080             }
10081             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
10082                 return false;
10083             }
10084             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
10085                 return false;
10086             }
10087             final PhylogenyNode n16 = PhylogenyNode
10088                     .createInstanceFromNhxString( "something_wicked2[9]",
10089                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10090             if ( !n16.getName().equals( "something_wicked2" ) ) {
10091                 return false;
10092             }
10093             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
10094                 return false;
10095             }
10096             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
10097                 return false;
10098             }
10099             final PhylogenyNode n17 = PhylogenyNode
10100                     .createInstanceFromNhxString( "something_wicked3[a]",
10101                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10102             if ( !n17.getName().equals( "something_wicked3" ) ) {
10103                 return false;
10104             }
10105             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
10106                 return false;
10107             }
10108             final PhylogenyNode n18 = PhylogenyNode
10109                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10110             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
10111                 return false;
10112             }
10113             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
10114                 return false;
10115             }
10116             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
10117                 return false;
10118             }
10119             final PhylogenyNode n19 = PhylogenyNode
10120                     .createInstanceFromNhxString( "BLAH_1-roejojoej",
10121                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10122             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
10123                 return false;
10124             }
10125             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
10126                 return false;
10127             }
10128             final PhylogenyNode n30 = PhylogenyNode
10129                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
10130                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10131             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
10132                 return false;
10133             }
10134             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
10135                 return false;
10136             }
10137             final PhylogenyNode n31 = PhylogenyNode
10138                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
10139                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10140             if ( n31.getNodeData().isHasTaxonomy() ) {
10141                 return false;
10142             }
10143             final PhylogenyNode n32 = PhylogenyNode
10144                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10145             if ( n32.getNodeData().isHasTaxonomy() ) {
10146                 return false;
10147             }
10148             final PhylogenyNode n40 = PhylogenyNode
10149                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10150             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10151                 return false;
10152             }
10153             final PhylogenyNode n41 = PhylogenyNode
10154                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10155             if ( n41.getNodeData().isHasTaxonomy() ) {
10156                 return false;
10157             }
10158             final PhylogenyNode n42 = PhylogenyNode
10159                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
10160             if ( n42.getNodeData().isHasTaxonomy() ) {
10161                 return false;
10162             }
10163             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
10164                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
10165             if ( n43.getNodeData().isHasTaxonomy() ) {
10166                 return false;
10167             }
10168             final PhylogenyNode n44 = PhylogenyNode
10169                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10170             if ( n44.getNodeData().isHasTaxonomy() ) {
10171                 return false;
10172             }
10173         }
10174         catch ( final Exception e ) {
10175             e.printStackTrace( System.out );
10176             return false;
10177         }
10178         return true;
10179     }
10180
10181     private static boolean testNHXNodeParsing2() {
10182         try {
10183             final PhylogenyNode n0_0 = PhylogenyNode.createInstanceFromNhxString( "n0:[ignore me 123]:1E-3",
10184                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10185                                                                                   true,
10186                                                                                   true );
10187             if ( !n0_0.getName().equals( "n0" ) ) {
10188                 return false;
10189             }
10190             if ( !isEqual( n0_0.getDistanceToParent(), 0.001 ) ) {
10191                 return false;
10192             }
10193             final PhylogenyNode n0_1 = PhylogenyNode.createInstanceFromNhxString( "n0[ignore me 123]:1E-3",
10194                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10195                                                                                   true,
10196                                                                                   true );
10197             if ( !n0_1.getName().equals( "n0" ) ) {
10198                 return false;
10199             }
10200             if ( !isEqual( n0_1.getDistanceToParent(), 0.001 ) ) {
10201                 return false;
10202             }
10203             final PhylogenyNode n0_2 = PhylogenyNode.createInstanceFromNhxString( "n0:1E-3[ignore me 123]",
10204                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10205                                                                                   true,
10206                                                                                   true );
10207             if ( !n0_2.getName().equals( "n0" ) ) {
10208                 return false;
10209             }
10210             if ( !isEqual( n0_2.getDistanceToParent(), 0.001 ) ) {
10211                 return false;
10212             }
10213             final PhylogenyNode n0_3 = PhylogenyNode.createInstanceFromNhxString( "n0:1E-3:[ignore me 123]",
10214                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10215                                                                                   true,
10216                                                                                   true );
10217             if ( !n0_3.getName().equals( "n0" ) ) {
10218                 return false;
10219             }
10220             if ( !isEqual( n0_3.getDistanceToParent(), 0.001 ) ) {
10221                 return false;
10222             }
10223             final PhylogenyNode n0_4 = PhylogenyNode.createInstanceFromNhxString( "n0:0.001:[ignore me 123]",
10224                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10225                                                                                   true,
10226                                                                                   true );
10227             if ( !n0_4.getName().equals( "n0" ) ) {
10228                 return false;
10229             }
10230             if ( !isEqual( n0_4.getDistanceToParent(), 0.001 ) ) {
10231                 return false;
10232             }
10233             final PhylogenyNode n1_0 = PhylogenyNode
10234                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]",
10235                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10236                                                   true,
10237                                                   true );
10238             if ( !n1_0.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10239                 return false;
10240             }
10241             if ( n1_0.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10242                 return false;
10243             }
10244             final PhylogenyNode n1_1 = PhylogenyNode
10245                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]:0.001",
10246                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10247                                                   true,
10248                                                   true );
10249             if ( !n1_1.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10250                 return false;
10251             }
10252             if ( n1_1.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10253                 return false;
10254             }
10255             if ( !isEqual( n1_1.getDistanceToParent(), 0.001 ) ) {
10256                 return false;
10257             }
10258             final PhylogenyNode n1_2 = PhylogenyNode
10259                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:0.001[&!color=#FFFFFF]",
10260                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10261                                                   true,
10262                                                   true );
10263             if ( !n1_2.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10264                 return false;
10265             }
10266             if ( n1_2.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10267                 return false;
10268             }
10269             if ( !isEqual( n1_2.getDistanceToParent(), 0.001 ) ) {
10270                 return false;
10271             }
10272             final PhylogenyNode n1_3 = PhylogenyNode
10273                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[&boostrap=69,&!color=#FFFFFF]",
10274                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10275                                                   true,
10276                                                   true );
10277             if ( !n1_3.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10278                 return false;
10279             }
10280             if ( n1_3.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10281                 return false;
10282             }
10283             if ( !isEqual( n1_3.getDistanceToParent(), 0.001 ) ) {
10284                 return false;
10285             }
10286             if ( !isEqual( n1_3.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
10287                 return false;
10288             }
10289             if ( !n1_3.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
10290                 return false;
10291             }
10292             final PhylogenyNode n1_4 = PhylogenyNode
10293                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&bootstrap=69,&!colour=#FFFFFF]:1e-3",
10294                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10295                                                   true,
10296                                                   true );
10297             if ( !n1_4.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10298                 return false;
10299             }
10300             if ( n1_4.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10301                 return false;
10302             }
10303             if ( !isEqual( n1_4.getDistanceToParent(), 0.001 ) ) {
10304                 return false;
10305             }
10306             if ( !isEqual( n1_4.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
10307                 return false;
10308             }
10309             if ( !n1_4.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
10310                 return false;
10311             }
10312             final PhylogenyNode n1_5 = PhylogenyNode
10313                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[69.0]",
10314                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10315                                                   true,
10316                                                   true );
10317             if ( !n1_5.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10318                 return false;
10319             }
10320             if ( !isEqual( n1_5.getDistanceToParent(), 0.001 ) ) {
10321                 return false;
10322             }
10323             if ( !isEqual( n1_5.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
10324                 return false;
10325             }
10326             final PhylogenyNode n1_6 = PhylogenyNode
10327                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00]:1e-3",
10328                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10329                                                   true,
10330                                                   true );
10331             if ( !n1_6.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10332                 return false;
10333             }
10334             if ( !isEqual( n1_6.getDistanceToParent(), 0.001 ) ) {
10335                 return false;
10336             }
10337             if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getStandardDeviation(), 0.11 ) ) {
10338                 return false;
10339             }
10340             if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getValue(), 0.95 ) ) {
10341                 return false;
10342             }
10343             if ( !n1_6.getBranchData().getConfidence( 0 ).getType().equals( "posterior probability" ) ) {
10344                 return false;
10345             }
10346         }
10347         catch ( final Exception e ) {
10348             e.printStackTrace( System.out );
10349             return false;
10350         }
10351         return true;
10352     }
10353
10354     private static boolean testNHXParsing() {
10355         try {
10356             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10357             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])",
10358                                                  new NHXParser() )[ 0 ];
10359             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
10360                 return false;
10361             }
10362             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]";
10363             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
10364             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10365                 return false;
10366             }
10367             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]";
10368             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
10369             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
10370                 return false;
10371             }
10372             final Phylogeny[] p3 = factory.create(
10373                                                    "[  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]",
10374                                                    new NHXParser() );
10375             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10376                 return false;
10377             }
10378             final Phylogeny[] p4 = factory.create(
10379                                                    "(((((((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(]",
10380                                                    new NHXParser() );
10381             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10382                 return false;
10383             }
10384             final Phylogeny[] p5 = factory.create(
10385                                                    "[]  (  [][ ][   ]  ([((( &&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(((]",
10386                                                    new NHXParser() );
10387             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10388                 return false;
10389             }
10390             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)";
10391             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)";
10392             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
10393             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
10394                 return false;
10395             }
10396             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)))";
10397             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)))";
10398             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
10399             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
10400                 return false;
10401             }
10402             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])   ))[,,, ])))))))";
10403             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
10404             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
10405             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
10406                 return false;
10407             }
10408             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
10409             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10410                 return false;
10411             }
10412             final Phylogeny p10 = factory.create(
10413                                                   " [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]",
10414                                                   new NHXParser() )[ 0 ];
10415             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10416                 return false;
10417             }
10418             final Phylogeny p11 = factory.create(
10419                                                   " [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]",
10420                                                   new NHXParser() )[ 0 ];
10421             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10422                 return false;
10423             }
10424             final Phylogeny p12 = factory.create( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]",
10425                                                   new NHXParser() )[ 0 ];
10426             if ( !p12.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10427                 return false;
10428             }
10429         }
10430         catch ( final Exception e ) {
10431             e.printStackTrace( System.out );
10432             return false;
10433         }
10434         return true;
10435     }
10436
10437     private static boolean testNHXParsingMB() {
10438         try {
10439             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10440             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
10441                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10442                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
10443                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
10444                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
10445                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10446                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
10447                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
10448                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
10449             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
10450                 return false;
10451             }
10452             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
10453                 return false;
10454             }
10455             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
10456                            0.1100000000000000e+00 ) ) {
10457                 return false;
10458             }
10459             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
10460                 return false;
10461             }
10462             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
10463                 return false;
10464             }
10465             final Phylogeny p2 = factory
10466                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
10467                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10468                             + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
10469                             + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
10470                             + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
10471                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10472                             + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
10473                             + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
10474                             + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
10475             if ( p2.getNode( "1" ) == null ) {
10476                 return false;
10477             }
10478             if ( p2.getNode( "2" ) == null ) {
10479                 return false;
10480             }
10481         }
10482         catch ( final Exception e ) {
10483             e.printStackTrace( System.out );
10484             System.exit( -1 );
10485             return false;
10486         }
10487         return true;
10488     }
10489
10490     private static boolean testNHXParsingQuotes() {
10491         try {
10492             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10493             final NHXParser p = new NHXParser();
10494             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
10495             if ( phylogenies_0.length != 5 ) {
10496                 return false;
10497             }
10498             final Phylogeny phy = phylogenies_0[ 4 ];
10499             if ( phy.getNumberOfExternalNodes() != 7 ) {
10500                 return false;
10501             }
10502             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
10503                 return false;
10504             }
10505             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
10506                 return false;
10507             }
10508             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
10509                     .getScientificName().equals( "hsapiens" ) ) {
10510                 return false;
10511             }
10512             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
10513                 return false;
10514             }
10515             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
10516                 return false;
10517             }
10518             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
10519                 return false;
10520             }
10521             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
10522                 return false;
10523             }
10524             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
10525                 return false;
10526             }
10527             final NHXParser p1p = new NHXParser();
10528             p1p.setIgnoreQuotes( true );
10529             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
10530             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
10531                 return false;
10532             }
10533             final NHXParser p2p = new NHXParser();
10534             p1p.setIgnoreQuotes( false );
10535             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
10536             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
10537                 return false;
10538             }
10539             final NHXParser p3p = new NHXParser();
10540             p3p.setIgnoreQuotes( false );
10541             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
10542             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
10543                 return false;
10544             }
10545             final NHXParser p4p = new NHXParser();
10546             p4p.setIgnoreQuotes( false );
10547             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
10548             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
10549                 return false;
10550             }
10551             final Phylogeny p10 = factory.create(
10552                                                   " [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]",
10553                                                   new NHXParser() )[ 0 ];
10554             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]";
10555             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
10556                 return false;
10557             }
10558             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
10559             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
10560                 return false;
10561             }
10562             final Phylogeny p12 = factory.create(
10563                                                   " [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]",
10564                                                   new NHXParser() )[ 0 ];
10565             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]";
10566             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
10567                 return false;
10568             }
10569             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
10570             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
10571                 return false;
10572             }
10573             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;";
10574             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
10575                 return false;
10576             }
10577             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
10578             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
10579                 return false;
10580             }
10581         }
10582         catch ( final Exception e ) {
10583             e.printStackTrace( System.out );
10584             return false;
10585         }
10586         return true;
10587     }
10588
10589     private static boolean testNodeRemoval() {
10590         try {
10591             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10592             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
10593             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
10594             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
10595                 return false;
10596             }
10597             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
10598             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
10599             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
10600                 return false;
10601             }
10602             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
10603             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
10604             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
10605                 return false;
10606             }
10607         }
10608         catch ( final Exception e ) {
10609             e.printStackTrace( System.out );
10610             return false;
10611         }
10612         return true;
10613     }
10614
10615     private static boolean testPhylogenyBranch() {
10616         try {
10617             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
10618             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
10619             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
10620             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
10621             if ( !a1b1.equals( a1b1 ) ) {
10622                 return false;
10623             }
10624             if ( !a1b1.equals( b1a1 ) ) {
10625                 return false;
10626             }
10627             if ( !b1a1.equals( a1b1 ) ) {
10628                 return false;
10629             }
10630             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
10631             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
10632             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
10633             if ( a1_b1.equals( b1_a1 ) ) {
10634                 return false;
10635             }
10636             if ( a1_b1.equals( a1_b1_ ) ) {
10637                 return false;
10638             }
10639             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
10640             if ( !a1_b1.equals( b1_a1_ ) ) {
10641                 return false;
10642             }
10643             if ( a1_b1_.equals( b1_a1_ ) ) {
10644                 return false;
10645             }
10646             if ( !a1_b1_.equals( b1_a1 ) ) {
10647                 return false;
10648             }
10649         }
10650         catch ( final Exception e ) {
10651             e.printStackTrace( System.out );
10652             return false;
10653         }
10654         return true;
10655     }
10656
10657     private static boolean testPhyloXMLparsingOfDistributionElement() {
10658         try {
10659             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10660             PhyloXmlParser xml_parser = null;
10661             try {
10662                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
10663             }
10664             catch ( final Exception e ) {
10665                 // Do nothing -- means were not running from jar.
10666             }
10667             if ( xml_parser == null ) {
10668                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
10669                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
10670                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
10671                 }
10672                 else {
10673                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
10674                 }
10675             }
10676             final Phylogeny[] phylogenies_0 = factory
10677                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml" ), xml_parser );
10678             if ( xml_parser.getErrorCount() > 0 ) {
10679                 System.out.println( xml_parser.getErrorMessages().toString() );
10680                 return false;
10681             }
10682             if ( phylogenies_0.length != 1 ) {
10683                 return false;
10684             }
10685             final Phylogeny t1 = phylogenies_0[ 0 ];
10686             PhylogenyNode n = null;
10687             Distribution d = null;
10688             n = t1.getNode( "root node" );
10689             if ( !n.getNodeData().isHasDistribution() ) {
10690                 return false;
10691             }
10692             if ( n.getNodeData().getDistributions().size() != 1 ) {
10693                 return false;
10694             }
10695             d = n.getNodeData().getDistribution();
10696             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10697                 return false;
10698             }
10699             if ( d.getPoints().size() != 1 ) {
10700                 return false;
10701             }
10702             if ( d.getPolygons() != null ) {
10703                 return false;
10704             }
10705             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10706                 return false;
10707             }
10708             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10709                 return false;
10710             }
10711             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10712                 return false;
10713             }
10714             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10715                 return false;
10716             }
10717             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10718                 return false;
10719             }
10720             n = t1.getNode( "node a" );
10721             if ( !n.getNodeData().isHasDistribution() ) {
10722                 return false;
10723             }
10724             if ( n.getNodeData().getDistributions().size() != 2 ) {
10725                 return false;
10726             }
10727             d = n.getNodeData().getDistribution( 1 );
10728             if ( !d.getDesc().equals( "San Diego" ) ) {
10729                 return false;
10730             }
10731             if ( d.getPoints().size() != 1 ) {
10732                 return false;
10733             }
10734             if ( d.getPolygons() != null ) {
10735                 return false;
10736             }
10737             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10738                 return false;
10739             }
10740             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10741                 return false;
10742             }
10743             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10744                 return false;
10745             }
10746             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10747                 return false;
10748             }
10749             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10750                 return false;
10751             }
10752             n = t1.getNode( "node bb" );
10753             if ( !n.getNodeData().isHasDistribution() ) {
10754                 return false;
10755             }
10756             if ( n.getNodeData().getDistributions().size() != 1 ) {
10757                 return false;
10758             }
10759             d = n.getNodeData().getDistribution( 0 );
10760             if ( d.getPoints().size() != 3 ) {
10761                 return false;
10762             }
10763             if ( d.getPolygons().size() != 2 ) {
10764                 return false;
10765             }
10766             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10767                 return false;
10768             }
10769             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10770                 return false;
10771             }
10772             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10773                 return false;
10774             }
10775             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10776                 return false;
10777             }
10778             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10779                 return false;
10780             }
10781             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10782                 return false;
10783             }
10784             Polygon p = d.getPolygons().get( 0 );
10785             if ( p.getPoints().size() != 3 ) {
10786                 return false;
10787             }
10788             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10789                 return false;
10790             }
10791             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10792                 return false;
10793             }
10794             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10795                 return false;
10796             }
10797             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10798                 return false;
10799             }
10800             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10801                 return false;
10802             }
10803             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10804                 return false;
10805             }
10806             p = d.getPolygons().get( 1 );
10807             if ( p.getPoints().size() != 3 ) {
10808                 return false;
10809             }
10810             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10811                 return false;
10812             }
10813             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10814                 return false;
10815             }
10816             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10817                 return false;
10818             }
10819             // Roundtrip:
10820             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
10821             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
10822             if ( rt.length != 1 ) {
10823                 return false;
10824             }
10825             final Phylogeny t1_rt = rt[ 0 ];
10826             n = t1_rt.getNode( "root node" );
10827             if ( !n.getNodeData().isHasDistribution() ) {
10828                 return false;
10829             }
10830             if ( n.getNodeData().getDistributions().size() != 1 ) {
10831                 return false;
10832             }
10833             d = n.getNodeData().getDistribution();
10834             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10835                 return false;
10836             }
10837             if ( d.getPoints().size() != 1 ) {
10838                 return false;
10839             }
10840             if ( d.getPolygons() != null ) {
10841                 return false;
10842             }
10843             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10844                 return false;
10845             }
10846             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10847                 return false;
10848             }
10849             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10850                 return false;
10851             }
10852             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10853                 return false;
10854             }
10855             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10856                 return false;
10857             }
10858             n = t1_rt.getNode( "node a" );
10859             if ( !n.getNodeData().isHasDistribution() ) {
10860                 return false;
10861             }
10862             if ( n.getNodeData().getDistributions().size() != 2 ) {
10863                 return false;
10864             }
10865             d = n.getNodeData().getDistribution( 1 );
10866             if ( !d.getDesc().equals( "San Diego" ) ) {
10867                 return false;
10868             }
10869             if ( d.getPoints().size() != 1 ) {
10870                 return false;
10871             }
10872             if ( d.getPolygons() != null ) {
10873                 return false;
10874             }
10875             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10876                 return false;
10877             }
10878             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10879                 return false;
10880             }
10881             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10882                 return false;
10883             }
10884             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10885                 return false;
10886             }
10887             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10888                 return false;
10889             }
10890             n = t1_rt.getNode( "node bb" );
10891             if ( !n.getNodeData().isHasDistribution() ) {
10892                 return false;
10893             }
10894             if ( n.getNodeData().getDistributions().size() != 1 ) {
10895                 return false;
10896             }
10897             d = n.getNodeData().getDistribution( 0 );
10898             if ( d.getPoints().size() != 3 ) {
10899                 return false;
10900             }
10901             if ( d.getPolygons().size() != 2 ) {
10902                 return false;
10903             }
10904             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10905                 return false;
10906             }
10907             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10908                 return false;
10909             }
10910             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10911                 return false;
10912             }
10913             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10914                 return false;
10915             }
10916             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10917                 return false;
10918             }
10919             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10920                 return false;
10921             }
10922             p = d.getPolygons().get( 0 );
10923             if ( p.getPoints().size() != 3 ) {
10924                 return false;
10925             }
10926             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10927                 return false;
10928             }
10929             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10930                 return false;
10931             }
10932             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10933                 return false;
10934             }
10935             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10936                 return false;
10937             }
10938             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10939                 return false;
10940             }
10941             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10942                 return false;
10943             }
10944             p = d.getPolygons().get( 1 );
10945             if ( p.getPoints().size() != 3 ) {
10946                 return false;
10947             }
10948             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10949                 return false;
10950             }
10951             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10952                 return false;
10953             }
10954             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10955                 return false;
10956             }
10957         }
10958         catch ( final Exception e ) {
10959             e.printStackTrace( System.out );
10960             return false;
10961         }
10962         return true;
10963     }
10964
10965     private static boolean testPostOrderIterator() {
10966         try {
10967             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10968             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10969             PhylogenyNodeIterator it0;
10970             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
10971                 it0.next();
10972             }
10973             for( it0.reset(); it0.hasNext(); ) {
10974                 it0.next();
10975             }
10976             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r",
10977                                                  new NHXParser() )[ 0 ];
10978             final PhylogenyNodeIterator it = t1.iteratorPostorder();
10979             if ( !it.next().getName().equals( "A" ) ) {
10980                 return false;
10981             }
10982             if ( !it.next().getName().equals( "B" ) ) {
10983                 return false;
10984             }
10985             if ( !it.next().getName().equals( "ab" ) ) {
10986                 return false;
10987             }
10988             if ( !it.next().getName().equals( "C" ) ) {
10989                 return false;
10990             }
10991             if ( !it.next().getName().equals( "D" ) ) {
10992                 return false;
10993             }
10994             if ( !it.next().getName().equals( "cd" ) ) {
10995                 return false;
10996             }
10997             if ( !it.next().getName().equals( "abcd" ) ) {
10998                 return false;
10999             }
11000             if ( !it.next().getName().equals( "E" ) ) {
11001                 return false;
11002             }
11003             if ( !it.next().getName().equals( "F" ) ) {
11004                 return false;
11005             }
11006             if ( !it.next().getName().equals( "ef" ) ) {
11007                 return false;
11008             }
11009             if ( !it.next().getName().equals( "G" ) ) {
11010                 return false;
11011             }
11012             if ( !it.next().getName().equals( "H" ) ) {
11013                 return false;
11014             }
11015             if ( !it.next().getName().equals( "gh" ) ) {
11016                 return false;
11017             }
11018             if ( !it.next().getName().equals( "efgh" ) ) {
11019                 return false;
11020             }
11021             if ( !it.next().getName().equals( "r" ) ) {
11022                 return false;
11023             }
11024             if ( it.hasNext() ) {
11025                 return false;
11026             }
11027         }
11028         catch ( final Exception e ) {
11029             e.printStackTrace( System.out );
11030             return false;
11031         }
11032         return true;
11033     }
11034
11035     private static boolean testPreOrderIterator() {
11036         try {
11037             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11038             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
11039             PhylogenyNodeIterator it0;
11040             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
11041                 it0.next();
11042             }
11043             for( it0.reset(); it0.hasNext(); ) {
11044                 it0.next();
11045             }
11046             PhylogenyNodeIterator it = t0.iteratorPreorder();
11047             if ( !it.next().getName().equals( "r" ) ) {
11048                 return false;
11049             }
11050             if ( !it.next().getName().equals( "ab" ) ) {
11051                 return false;
11052             }
11053             if ( !it.next().getName().equals( "A" ) ) {
11054                 return false;
11055             }
11056             if ( !it.next().getName().equals( "B" ) ) {
11057                 return false;
11058             }
11059             if ( !it.next().getName().equals( "cd" ) ) {
11060                 return false;
11061             }
11062             if ( !it.next().getName().equals( "C" ) ) {
11063                 return false;
11064             }
11065             if ( !it.next().getName().equals( "D" ) ) {
11066                 return false;
11067             }
11068             if ( it.hasNext() ) {
11069                 return false;
11070             }
11071             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r",
11072                                                  new NHXParser() )[ 0 ];
11073             it = t1.iteratorPreorder();
11074             if ( !it.next().getName().equals( "r" ) ) {
11075                 return false;
11076             }
11077             if ( !it.next().getName().equals( "abcd" ) ) {
11078                 return false;
11079             }
11080             if ( !it.next().getName().equals( "ab" ) ) {
11081                 return false;
11082             }
11083             if ( !it.next().getName().equals( "A" ) ) {
11084                 return false;
11085             }
11086             if ( !it.next().getName().equals( "B" ) ) {
11087                 return false;
11088             }
11089             if ( !it.next().getName().equals( "cd" ) ) {
11090                 return false;
11091             }
11092             if ( !it.next().getName().equals( "C" ) ) {
11093                 return false;
11094             }
11095             if ( !it.next().getName().equals( "D" ) ) {
11096                 return false;
11097             }
11098             if ( !it.next().getName().equals( "efgh" ) ) {
11099                 return false;
11100             }
11101             if ( !it.next().getName().equals( "ef" ) ) {
11102                 return false;
11103             }
11104             if ( !it.next().getName().equals( "E" ) ) {
11105                 return false;
11106             }
11107             if ( !it.next().getName().equals( "F" ) ) {
11108                 return false;
11109             }
11110             if ( !it.next().getName().equals( "gh" ) ) {
11111                 return false;
11112             }
11113             if ( !it.next().getName().equals( "G" ) ) {
11114                 return false;
11115             }
11116             if ( !it.next().getName().equals( "H" ) ) {
11117                 return false;
11118             }
11119             if ( it.hasNext() ) {
11120                 return false;
11121             }
11122         }
11123         catch ( final Exception e ) {
11124             e.printStackTrace( System.out );
11125             return false;
11126         }
11127         return true;
11128     }
11129
11130     private static boolean testPropertiesMap() {
11131         try {
11132             final PropertiesList pm = new PropertiesList();
11133             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
11134             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
11135             final Property p2 = new Property( "something:else",
11136                                               "?",
11137                                               "improbable:research",
11138                                               "xsd:decimal",
11139                                               AppliesTo.NODE );
11140             pm.addProperty( p0 );
11141             pm.addProperty( p1 );
11142             pm.addProperty( p2 );
11143             if ( !pm.getProperties( "dimensions:diameter" ).get( 0 ).getValue().equals( "1" ) ) {
11144                 return false;
11145             }
11146             if ( !pm.getProperties( "dimensions:length" ).get( 0 ).getValue().equals( "2" ) ) {
11147                 return false;
11148             }
11149             if ( pm.getProperties().size() != 3 ) {
11150                 return false;
11151             }
11152             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
11153                 return false;
11154             }
11155             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
11156                 return false;
11157             }
11158             if ( pm.getProperties().size() != 3 ) {
11159                 return false;
11160             }
11161         }
11162         catch ( final Exception e ) {
11163             e.printStackTrace( System.out );
11164             return false;
11165         }
11166         return true;
11167     }
11168
11169     private static boolean testProteinId() {
11170         try {
11171             final ProteinId id1 = new ProteinId( "a" );
11172             final ProteinId id2 = new ProteinId( "a" );
11173             final ProteinId id3 = new ProteinId( "A" );
11174             final ProteinId id4 = new ProteinId( "b" );
11175             if ( !id1.equals( id1 ) ) {
11176                 return false;
11177             }
11178             if ( id1.getId().equals( "x" ) ) {
11179                 return false;
11180             }
11181             if ( id1.getId().equals( null ) ) {
11182                 return false;
11183             }
11184             if ( !id1.equals( id2 ) ) {
11185                 return false;
11186             }
11187             if ( id1.equals( id3 ) ) {
11188                 return false;
11189             }
11190             if ( id1.hashCode() != id1.hashCode() ) {
11191                 return false;
11192             }
11193             if ( id1.hashCode() != id2.hashCode() ) {
11194                 return false;
11195             }
11196             if ( id1.hashCode() == id3.hashCode() ) {
11197                 return false;
11198             }
11199             if ( id1.compareTo( id1 ) != 0 ) {
11200                 return false;
11201             }
11202             if ( id1.compareTo( id2 ) != 0 ) {
11203                 return false;
11204             }
11205             if ( id1.compareTo( id3 ) != 0 ) {
11206                 return false;
11207             }
11208             if ( id1.compareTo( id4 ) >= 0 ) {
11209                 return false;
11210             }
11211             if ( id4.compareTo( id1 ) <= 0 ) {
11212                 return false;
11213             }
11214             if ( !id4.getId().equals( "b" ) ) {
11215                 return false;
11216             }
11217             final ProteinId id5 = new ProteinId( " C " );
11218             if ( !id5.getId().equals( "C" ) ) {
11219                 return false;
11220             }
11221             if ( id5.equals( id1 ) ) {
11222                 return false;
11223             }
11224         }
11225         catch ( final Exception e ) {
11226             e.printStackTrace( System.out );
11227             return false;
11228         }
11229         return true;
11230     }
11231
11232     private static boolean testReIdMethods() {
11233         try {
11234             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11235             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
11236             final long count = PhylogenyNode.getNodeCount();
11237             p.levelOrderReID();
11238             if ( p.getNode( "r" ).getId() != count ) {
11239                 return false;
11240             }
11241             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
11242                 return false;
11243             }
11244             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
11245                 return false;
11246             }
11247             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
11248                 return false;
11249             }
11250             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
11251                 return false;
11252             }
11253             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
11254                 return false;
11255             }
11256             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
11257                 return false;
11258             }
11259             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
11260                 return false;
11261             }
11262             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
11263                 return false;
11264             }
11265             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
11266                 return false;
11267             }
11268             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
11269                 return false;
11270             }
11271             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
11272                 return false;
11273             }
11274             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
11275                 return false;
11276             }
11277             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
11278                 return false;
11279             }
11280             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
11281                 return false;
11282             }
11283         }
11284         catch ( final Exception e ) {
11285             e.printStackTrace( System.out );
11286             return false;
11287         }
11288         return true;
11289     }
11290
11291     private static boolean testRerooting() {
11292         try {
11293             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11294             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",
11295                                                  new NHXParser() )[ 0 ];
11296             if ( !t1.isRooted() ) {
11297                 return false;
11298             }
11299             t1.reRoot( t1.getNode( "D" ) );
11300             t1.reRoot( t1.getNode( "CD" ) );
11301             t1.reRoot( t1.getNode( "A" ) );
11302             t1.reRoot( t1.getNode( "B" ) );
11303             t1.reRoot( t1.getNode( "AB" ) );
11304             t1.reRoot( t1.getNode( "D" ) );
11305             t1.reRoot( t1.getNode( "C" ) );
11306             t1.reRoot( t1.getNode( "CD" ) );
11307             t1.reRoot( t1.getNode( "A" ) );
11308             t1.reRoot( t1.getNode( "B" ) );
11309             t1.reRoot( t1.getNode( "AB" ) );
11310             t1.reRoot( t1.getNode( "D" ) );
11311             t1.reRoot( t1.getNode( "D" ) );
11312             t1.reRoot( t1.getNode( "C" ) );
11313             t1.reRoot( t1.getNode( "A" ) );
11314             t1.reRoot( t1.getNode( "B" ) );
11315             t1.reRoot( t1.getNode( "AB" ) );
11316             t1.reRoot( t1.getNode( "C" ) );
11317             t1.reRoot( t1.getNode( "D" ) );
11318             t1.reRoot( t1.getNode( "CD" ) );
11319             t1.reRoot( t1.getNode( "D" ) );
11320             t1.reRoot( t1.getNode( "A" ) );
11321             t1.reRoot( t1.getNode( "B" ) );
11322             t1.reRoot( t1.getNode( "AB" ) );
11323             t1.reRoot( t1.getNode( "C" ) );
11324             t1.reRoot( t1.getNode( "D" ) );
11325             t1.reRoot( t1.getNode( "CD" ) );
11326             t1.reRoot( t1.getNode( "D" ) );
11327             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
11328                 return false;
11329             }
11330             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
11331                 return false;
11332             }
11333             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
11334                 return false;
11335             }
11336             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
11337                 return false;
11338             }
11339             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
11340                 return false;
11341             }
11342             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
11343                 return false;
11344             }
11345             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",
11346                                                  new NHXParser() )[ 0 ];
11347             t2.reRoot( t2.getNode( "A" ) );
11348             t2.reRoot( t2.getNode( "D" ) );
11349             t2.reRoot( t2.getNode( "ABC" ) );
11350             t2.reRoot( t2.getNode( "A" ) );
11351             t2.reRoot( t2.getNode( "B" ) );
11352             t2.reRoot( t2.getNode( "D" ) );
11353             t2.reRoot( t2.getNode( "C" ) );
11354             t2.reRoot( t2.getNode( "ABC" ) );
11355             t2.reRoot( t2.getNode( "A" ) );
11356             t2.reRoot( t2.getNode( "B" ) );
11357             t2.reRoot( t2.getNode( "AB" ) );
11358             t2.reRoot( t2.getNode( "AB" ) );
11359             t2.reRoot( t2.getNode( "D" ) );
11360             t2.reRoot( t2.getNode( "C" ) );
11361             t2.reRoot( t2.getNode( "B" ) );
11362             t2.reRoot( t2.getNode( "AB" ) );
11363             t2.reRoot( t2.getNode( "D" ) );
11364             t2.reRoot( t2.getNode( "D" ) );
11365             t2.reRoot( t2.getNode( "ABC" ) );
11366             t2.reRoot( t2.getNode( "A" ) );
11367             t2.reRoot( t2.getNode( "B" ) );
11368             t2.reRoot( t2.getNode( "AB" ) );
11369             t2.reRoot( t2.getNode( "D" ) );
11370             t2.reRoot( t2.getNode( "C" ) );
11371             t2.reRoot( t2.getNode( "ABC" ) );
11372             t2.reRoot( t2.getNode( "A" ) );
11373             t2.reRoot( t2.getNode( "B" ) );
11374             t2.reRoot( t2.getNode( "AB" ) );
11375             t2.reRoot( t2.getNode( "D" ) );
11376             t2.reRoot( t2.getNode( "D" ) );
11377             t2.reRoot( t2.getNode( "C" ) );
11378             t2.reRoot( t2.getNode( "A" ) );
11379             t2.reRoot( t2.getNode( "B" ) );
11380             t2.reRoot( t2.getNode( "AB" ) );
11381             t2.reRoot( t2.getNode( "C" ) );
11382             t2.reRoot( t2.getNode( "D" ) );
11383             t2.reRoot( t2.getNode( "ABC" ) );
11384             t2.reRoot( t2.getNode( "D" ) );
11385             t2.reRoot( t2.getNode( "A" ) );
11386             t2.reRoot( t2.getNode( "B" ) );
11387             t2.reRoot( t2.getNode( "AB" ) );
11388             t2.reRoot( t2.getNode( "C" ) );
11389             t2.reRoot( t2.getNode( "D" ) );
11390             t2.reRoot( t2.getNode( "ABC" ) );
11391             t2.reRoot( t2.getNode( "D" ) );
11392             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11393                 return false;
11394             }
11395             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11396                 return false;
11397             }
11398             t2.reRoot( t2.getNode( "ABC" ) );
11399             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11400                 return false;
11401             }
11402             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11403                 return false;
11404             }
11405             t2.reRoot( t2.getNode( "AB" ) );
11406             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11407                 return false;
11408             }
11409             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11410                 return false;
11411             }
11412             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11413                 return false;
11414             }
11415             t2.reRoot( t2.getNode( "AB" ) );
11416             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11417                 return false;
11418             }
11419             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11420                 return false;
11421             }
11422             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11423                 return false;
11424             }
11425             t2.reRoot( t2.getNode( "D" ) );
11426             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11427                 return false;
11428             }
11429             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11430                 return false;
11431             }
11432             t2.reRoot( t2.getNode( "ABC" ) );
11433             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11434                 return false;
11435             }
11436             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11437                 return false;
11438             }
11439             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
11440                                                  new NHXParser() )[ 0 ];
11441             t3.reRoot( t3.getNode( "B" ) );
11442             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11443                 return false;
11444             }
11445             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11446                 return false;
11447             }
11448             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11449                 return false;
11450             }
11451             t3.reRoot( t3.getNode( "B" ) );
11452             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11453                 return false;
11454             }
11455             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11456                 return false;
11457             }
11458             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11459                 return false;
11460             }
11461             t3.reRoot( t3.getRoot() );
11462             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11463                 return false;
11464             }
11465             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11466                 return false;
11467             }
11468             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11469                 return false;
11470             }
11471         }
11472         catch ( final Exception e ) {
11473             e.printStackTrace( System.out );
11474             return false;
11475         }
11476         return true;
11477     }
11478
11479     private static boolean testSDIse() {
11480         try {
11481             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11482             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
11483             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
11484             gene1.setRooted( true );
11485             species1.setRooted( true );
11486             final SDI sdi = new SDI( gene1, species1 );
11487             if ( !gene1.getRoot().isDuplication() ) {
11488                 return false;
11489             }
11490             final Phylogeny species2 = factory.create(
11491                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11492                                                        new NHXParser() )[ 0 ];
11493             final Phylogeny gene2 = factory.create(
11494                                                     "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11495                                                     new NHXParser() )[ 0 ];
11496             species2.setRooted( true );
11497             gene2.setRooted( true );
11498             final SDI sdi2 = new SDI( gene2, species2 );
11499             if ( sdi2.getDuplicationsSum() != 0 ) {
11500                 return false;
11501             }
11502             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
11503                 return false;
11504             }
11505             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
11506                 return false;
11507             }
11508             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
11509                 return false;
11510             }
11511             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
11512                 return false;
11513             }
11514             if ( !gene2.getNode( "r" ).isSpeciation() ) {
11515                 return false;
11516             }
11517             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
11518                 return false;
11519             }
11520             final Phylogeny species3 = factory.create(
11521                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11522                                                        new NHXParser() )[ 0 ];
11523             final Phylogeny gene3 = factory.create(
11524                                                     "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11525                                                     new NHXParser() )[ 0 ];
11526             species3.setRooted( true );
11527             gene3.setRooted( true );
11528             final SDI sdi3 = new SDI( gene3, species3 );
11529             if ( sdi3.getDuplicationsSum() != 1 ) {
11530                 return false;
11531             }
11532             if ( !gene3.getNode( "aa" ).isDuplication() ) {
11533                 return false;
11534             }
11535             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
11536                 return false;
11537             }
11538             final Phylogeny species4 = factory.create(
11539                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11540                                                        new NHXParser() )[ 0 ];
11541             final Phylogeny gene4 = factory.create(
11542                                                     "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11543                                                     new NHXParser() )[ 0 ];
11544             species4.setRooted( true );
11545             gene4.setRooted( true );
11546             final SDI sdi4 = new SDI( gene4, species4 );
11547             if ( sdi4.getDuplicationsSum() != 1 ) {
11548                 return false;
11549             }
11550             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
11551                 return false;
11552             }
11553             if ( !gene4.getNode( "abc" ).isDuplication() ) {
11554                 return false;
11555             }
11556             if ( gene4.getNode( "abcd" ).isDuplication() ) {
11557                 return false;
11558             }
11559             if ( species4.getNumberOfExternalNodes() != 6 ) {
11560                 return false;
11561             }
11562             if ( gene4.getNumberOfExternalNodes() != 6 ) {
11563                 return false;
11564             }
11565             final Phylogeny species5 = factory.create(
11566                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11567                                                        new NHXParser() )[ 0 ];
11568             final Phylogeny gene5 = factory.create(
11569                                                     "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11570                                                     new NHXParser() )[ 0 ];
11571             species5.setRooted( true );
11572             gene5.setRooted( true );
11573             final SDI sdi5 = new SDI( gene5, species5 );
11574             if ( sdi5.getDuplicationsSum() != 2 ) {
11575                 return false;
11576             }
11577             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
11578                 return false;
11579             }
11580             if ( !gene5.getNode( "adc" ).isDuplication() ) {
11581                 return false;
11582             }
11583             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
11584                 return false;
11585             }
11586             if ( species5.getNumberOfExternalNodes() != 6 ) {
11587                 return false;
11588             }
11589             if ( gene5.getNumberOfExternalNodes() != 6 ) {
11590                 return false;
11591             }
11592             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
11593             // Conjecture for Comparing Molecular Phylogenies"
11594             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
11595             final Phylogeny species6 = factory.create(
11596                                                        "(((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,"
11597                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11598                                                        new NHXParser() )[ 0 ];
11599             final Phylogeny gene6 = factory.create(
11600                                                     "(((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,"
11601                                                             + "((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,"
11602                                                             + "(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;",
11603                                                     new NHXParser() )[ 0 ];
11604             species6.setRooted( true );
11605             gene6.setRooted( true );
11606             final SDI sdi6 = new SDI( gene6, species6 );
11607             if ( sdi6.getDuplicationsSum() != 3 ) {
11608                 return false;
11609             }
11610             if ( !gene6.getNode( "r" ).isDuplication() ) {
11611                 return false;
11612             }
11613             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
11614                 return false;
11615             }
11616             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
11617                 return false;
11618             }
11619             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
11620                 return false;
11621             }
11622             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
11623                 return false;
11624             }
11625             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
11626                 return false;
11627             }
11628             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
11629                 return false;
11630             }
11631             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
11632                 return false;
11633             }
11634             sdi6.computeMappingCostL();
11635             if ( sdi6.computeMappingCostL() != 17 ) {
11636                 return false;
11637             }
11638             if ( species6.getNumberOfExternalNodes() != 9 ) {
11639                 return false;
11640             }
11641             if ( gene6.getNumberOfExternalNodes() != 9 ) {
11642                 return false;
11643             }
11644             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
11645                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
11646                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
11647                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
11648                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
11649             species7.setRooted( true );
11650             final Phylogeny gene7_1 = Test
11651                     .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])" );
11652             gene7_1.setRooted( true );
11653             final SDI sdi7 = new SDI( gene7_1, species7 );
11654             if ( sdi7.getDuplicationsSum() != 0 ) {
11655                 return false;
11656             }
11657             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
11658                 return false;
11659             }
11660             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
11661                 return false;
11662             }
11663             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
11664                 return false;
11665             }
11666             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
11667                 return false;
11668             }
11669             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
11670                 return false;
11671             }
11672             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
11673                 return false;
11674             }
11675             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
11676                 return false;
11677             }
11678             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
11679                 return false;
11680             }
11681             final Phylogeny gene7_2 = Test
11682                     .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])" );
11683             gene7_2.setRooted( true );
11684             final SDI sdi7_2 = new SDI( gene7_2, species7 );
11685             if ( sdi7_2.getDuplicationsSum() != 1 ) {
11686                 return false;
11687             }
11688             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
11689                 return false;
11690             }
11691             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
11692                 return false;
11693             }
11694             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
11695                 return false;
11696             }
11697             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
11698                 return false;
11699             }
11700             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
11701                 return false;
11702             }
11703             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
11704                 return false;
11705             }
11706             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
11707                 return false;
11708             }
11709             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
11710                 return false;
11711             }
11712             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
11713                 return false;
11714             }
11715         }
11716         catch ( final Exception e ) {
11717             return false;
11718         }
11719         return true;
11720     }
11721
11722     private static boolean testSDIunrooted() {
11723         try {
11724             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11725             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef",
11726                                                  new NHXParser() )[ 0 ];
11727             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
11728             final Iterator<PhylogenyBranch> iter = l.iterator();
11729             PhylogenyBranch br = iter.next();
11730             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
11731                 return false;
11732             }
11733             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
11734                 return false;
11735             }
11736             br = iter.next();
11737             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11738                 return false;
11739             }
11740             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11741                 return false;
11742             }
11743             br = iter.next();
11744             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
11745                 return false;
11746             }
11747             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
11748                 return false;
11749             }
11750             br = iter.next();
11751             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11752                 return false;
11753             }
11754             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11755                 return false;
11756             }
11757             br = iter.next();
11758             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11759                 return false;
11760             }
11761             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11762                 return false;
11763             }
11764             br = iter.next();
11765             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11766                 return false;
11767             }
11768             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11769                 return false;
11770             }
11771             br = iter.next();
11772             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11773                 return false;
11774             }
11775             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11776                 return false;
11777             }
11778             br = iter.next();
11779             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11780                 return false;
11781             }
11782             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11783                 return false;
11784             }
11785             br = iter.next();
11786             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11787                 return false;
11788             }
11789             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11790                 return false;
11791             }
11792             br = iter.next();
11793             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11794                 return false;
11795             }
11796             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11797                 return false;
11798             }
11799             br = iter.next();
11800             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11801                 return false;
11802             }
11803             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11804                 return false;
11805             }
11806             br = iter.next();
11807             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
11808                 return false;
11809             }
11810             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
11811                 return false;
11812             }
11813             br = iter.next();
11814             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11815                 return false;
11816             }
11817             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11818                 return false;
11819             }
11820             br = iter.next();
11821             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
11822                 return false;
11823             }
11824             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
11825                 return false;
11826             }
11827             br = iter.next();
11828             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
11829                 return false;
11830             }
11831             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
11832                 return false;
11833             }
11834             if ( iter.hasNext() ) {
11835                 return false;
11836             }
11837             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
11838             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
11839             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
11840             br = iter1.next();
11841             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11842                 return false;
11843             }
11844             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11845                 return false;
11846             }
11847             br = iter1.next();
11848             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11849                 return false;
11850             }
11851             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11852                 return false;
11853             }
11854             br = iter1.next();
11855             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11856                 return false;
11857             }
11858             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11859                 return false;
11860             }
11861             if ( iter1.hasNext() ) {
11862                 return false;
11863             }
11864             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
11865             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
11866             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
11867             br = iter2.next();
11868             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11869                 return false;
11870             }
11871             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11872                 return false;
11873             }
11874             br = iter2.next();
11875             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11876                 return false;
11877             }
11878             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11879                 return false;
11880             }
11881             br = iter2.next();
11882             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11883                 return false;
11884             }
11885             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11886                 return false;
11887             }
11888             if ( iter2.hasNext() ) {
11889                 return false;
11890             }
11891             final Phylogeny species0 = factory.create(
11892                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11893                                                        new NHXParser() )[ 0 ];
11894             final Phylogeny gene1 = factory.create(
11895                                                     "(((((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])",
11896                                                     new NHXParser() )[ 0 ];
11897             species0.setRooted( true );
11898             gene1.setRooted( true );
11899             final SDIR sdi_unrooted = new SDIR();
11900             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
11901             if ( sdi_unrooted.getCount() != 1 ) {
11902                 return false;
11903             }
11904             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
11905                 return false;
11906             }
11907             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
11908                 return false;
11909             }
11910             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
11911                 return false;
11912             }
11913             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11914                 return false;
11915             }
11916             final Phylogeny gene2 = factory.create(
11917                                                     "(((((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])",
11918                                                     new NHXParser() )[ 0 ];
11919             gene2.setRooted( true );
11920             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
11921             if ( sdi_unrooted.getCount() != 1 ) {
11922                 return false;
11923             }
11924             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11925                 return false;
11926             }
11927             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11928                 return false;
11929             }
11930             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
11931                 return false;
11932             }
11933             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11934                 return false;
11935             }
11936             final Phylogeny species6 = factory.create(
11937                                                        "(((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,"
11938                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11939                                                        new NHXParser() )[ 0 ];
11940             final Phylogeny gene6 = factory.create(
11941                                                     "((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],"
11942                                                             + "(((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],"
11943                                                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11944                                                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11945                                                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11946                                                     new NHXParser() )[ 0 ];
11947             species6.setRooted( true );
11948             gene6.setRooted( true );
11949             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
11950             if ( sdi_unrooted.getCount() != 1 ) {
11951                 return false;
11952             }
11953             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11954                 return false;
11955             }
11956             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11957                 return false;
11958             }
11959             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11960                 return false;
11961             }
11962             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11963                 return false;
11964             }
11965             if ( !p6[ 0 ].getRoot().isDuplication() ) {
11966                 return false;
11967             }
11968             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11969                 return false;
11970             }
11971             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11972                 return false;
11973             }
11974             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11975                 return false;
11976             }
11977             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11978                 return false;
11979             }
11980             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11981                 return false;
11982             }
11983             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11984                 return false;
11985             }
11986             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11987                 return false;
11988             }
11989             p6 = null;
11990             final Phylogeny species7 = factory.create(
11991                                                        "(((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,"
11992                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11993                                                        new NHXParser() )[ 0 ];
11994             final Phylogeny gene7 = factory.create(
11995                                                     "((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],"
11996                                                             + "(((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],"
11997                                                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11998                                                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11999                                                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
12000                                                     new NHXParser() )[ 0 ];
12001             species7.setRooted( true );
12002             gene7.setRooted( true );
12003             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
12004             if ( sdi_unrooted.getCount() != 1 ) {
12005                 return false;
12006             }
12007             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
12008                 return false;
12009             }
12010             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
12011                 return false;
12012             }
12013             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
12014                 return false;
12015             }
12016             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
12017                 return false;
12018             }
12019             if ( !p7[ 0 ].getRoot().isDuplication() ) {
12020                 return false;
12021             }
12022             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
12023                 return false;
12024             }
12025             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
12026                 return false;
12027             }
12028             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
12029                 return false;
12030             }
12031             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
12032                 return false;
12033             }
12034             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
12035                 return false;
12036             }
12037             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
12038                 return false;
12039             }
12040             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
12041                 return false;
12042             }
12043             p7 = null;
12044             final Phylogeny species8 = factory.create(
12045                                                        "(((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,"
12046                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
12047                                                        new NHXParser() )[ 0 ];
12048             final Phylogeny gene8 = factory.create(
12049                                                     "((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],"
12050                                                             + "(((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],"
12051                                                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
12052                                                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
12053                                                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
12054                                                     new NHXParser() )[ 0 ];
12055             species8.setRooted( true );
12056             gene8.setRooted( true );
12057             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
12058             if ( sdi_unrooted.getCount() != 1 ) {
12059                 return false;
12060             }
12061             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
12062                 return false;
12063             }
12064             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
12065                 return false;
12066             }
12067             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
12068                 return false;
12069             }
12070             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
12071                 return false;
12072             }
12073             if ( !p8[ 0 ].getRoot().isDuplication() ) {
12074                 return false;
12075             }
12076             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
12077                 return false;
12078             }
12079             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
12080                 return false;
12081             }
12082             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
12083                 return false;
12084             }
12085             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
12086                 return false;
12087             }
12088             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
12089                 return false;
12090             }
12091             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
12092                 return false;
12093             }
12094             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
12095                 return false;
12096             }
12097             p8 = null;
12098         }
12099         catch ( final Exception e ) {
12100             e.printStackTrace( System.out );
12101             return false;
12102         }
12103         return true;
12104     }
12105
12106     private static boolean testSequenceDbWsTools1() {
12107         try {
12108             final PhylogenyNode n = new PhylogenyNode();
12109             n.setName( "NP_001025424" );
12110             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
12111             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
12112                     || !acc.getValue().equals( "NP_001025424" ) ) {
12113                 return false;
12114             }
12115             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
12116             acc = SequenceDbWsTools.obtainSeqAccession( n );
12117             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
12118                     || !acc.getValue().equals( "NP_001025424" ) ) {
12119                 return false;
12120             }
12121             n.setName( "NP_001025424.1" );
12122             acc = SequenceDbWsTools.obtainSeqAccession( n );
12123             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
12124                     || !acc.getValue().equals( "NP_001025424" ) ) {
12125                 return false;
12126             }
12127             n.setName( "NM_001030253" );
12128             acc = SequenceDbWsTools.obtainSeqAccession( n );
12129             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
12130                     || !acc.getValue().equals( "NM_001030253" ) ) {
12131                 return false;
12132             }
12133             n.setName( "BCL2_HUMAN" );
12134             acc = SequenceDbWsTools.obtainSeqAccession( n );
12135             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
12136                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
12137                 System.out.println( acc.toString() );
12138                 return false;
12139             }
12140             n.setName( "P10415" );
12141             acc = SequenceDbWsTools.obtainSeqAccession( n );
12142             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
12143                     || !acc.getValue().equals( "P10415" ) ) {
12144                 System.out.println( acc.toString() );
12145                 return false;
12146             }
12147             n.setName( " P10415 " );
12148             acc = SequenceDbWsTools.obtainSeqAccession( n );
12149             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
12150                     || !acc.getValue().equals( "P10415" ) ) {
12151                 System.out.println( acc.toString() );
12152                 return false;
12153             }
12154             n.setName( "_P10415|" );
12155             acc = SequenceDbWsTools.obtainSeqAccession( n );
12156             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
12157                     || !acc.getValue().equals( "P10415" ) ) {
12158                 System.out.println( acc.toString() );
12159                 return false;
12160             }
12161             n.setName( "AY695820" );
12162             acc = SequenceDbWsTools.obtainSeqAccession( n );
12163             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12164                     || !acc.getValue().equals( "AY695820" ) ) {
12165                 System.out.println( acc.toString() );
12166                 return false;
12167             }
12168             n.setName( "_AY695820_" );
12169             acc = SequenceDbWsTools.obtainSeqAccession( n );
12170             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12171                     || !acc.getValue().equals( "AY695820" ) ) {
12172                 System.out.println( acc.toString() );
12173                 return false;
12174             }
12175             n.setName( "AAA59452" );
12176             acc = SequenceDbWsTools.obtainSeqAccession( n );
12177             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12178                     || !acc.getValue().equals( "AAA59452" ) ) {
12179                 System.out.println( acc.toString() );
12180                 return false;
12181             }
12182             n.setName( "_AAA59452_" );
12183             acc = SequenceDbWsTools.obtainSeqAccession( n );
12184             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12185                     || !acc.getValue().equals( "AAA59452" ) ) {
12186                 System.out.println( acc.toString() );
12187                 return false;
12188             }
12189             n.setName( "AAA59452.1" );
12190             acc = SequenceDbWsTools.obtainSeqAccession( n );
12191             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12192                     || !acc.getValue().equals( "AAA59452.1" ) ) {
12193                 System.out.println( acc.toString() );
12194                 return false;
12195             }
12196             n.setName( "_AAA59452.1_" );
12197             acc = SequenceDbWsTools.obtainSeqAccession( n );
12198             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12199                     || !acc.getValue().equals( "AAA59452.1" ) ) {
12200                 System.out.println( acc.toString() );
12201                 return false;
12202             }
12203             n.setName( "GI:94894583" );
12204             acc = SequenceDbWsTools.obtainSeqAccession( n );
12205             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
12206                     || !acc.getValue().equals( "94894583" ) ) {
12207                 System.out.println( acc.toString() );
12208                 return false;
12209             }
12210             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
12211             acc = SequenceDbWsTools.obtainSeqAccession( n );
12212             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
12213                     || !acc.getValue().equals( "71845847" ) ) {
12214                 System.out.println( acc.toString() );
12215                 return false;
12216             }
12217             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
12218             acc = SequenceDbWsTools.obtainSeqAccession( n );
12219             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12220                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
12221                 System.out.println( acc.toString() );
12222                 return false;
12223             }
12224         }
12225         catch ( final Exception e ) {
12226             return false;
12227         }
12228         return true;
12229     }
12230
12231     private static boolean testSequenceDbWsTools2() {
12232         try {
12233             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
12234             SequenceDbWsTools.obtainSeqInformation( n1 );
12235             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
12236                 return false;
12237             }
12238             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
12239                 return false;
12240             }
12241             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
12242                 return false;
12243             }
12244             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
12245                 return false;
12246             }
12247             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
12248             SequenceDbWsTools.obtainSeqInformation( n2 );
12249             if ( !n2.getNodeData().getSequence().getName()
12250                     .equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
12251                 return false;
12252             }
12253             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
12254                 return false;
12255             }
12256             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
12257                 return false;
12258             }
12259             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
12260                 return false;
12261             }
12262             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
12263             SequenceDbWsTools.obtainSeqInformation( n3 );
12264             if ( !n3.getNodeData().getSequence().getName()
12265                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
12266                 return false;
12267             }
12268             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
12269                 return false;
12270             }
12271             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
12272                 return false;
12273             }
12274             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
12275                 return false;
12276             }
12277         }
12278         catch ( final IOException e ) {
12279             System.out.println();
12280             System.out.println( "the following might be due to absence internet connection:" );
12281             e.printStackTrace( System.out );
12282             return true;
12283         }
12284         catch ( final Exception e ) {
12285             e.printStackTrace();
12286             return false;
12287         }
12288         return true;
12289     }
12290
12291     private static boolean testSequenceIdParsing() {
12292         try {
12293             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
12294             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12295                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
12296                 if ( id != null ) {
12297                     System.out.println( "value   =" + id.getValue() );
12298                     System.out.println( "provider=" + id.getSource() );
12299                 }
12300                 return false;
12301             }
12302             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
12303             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12304                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
12305                 if ( id != null ) {
12306                     System.out.println( "value   =" + id.getValue() );
12307                     System.out.println( "provider=" + id.getSource() );
12308                 }
12309                 return false;
12310             }
12311             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
12312             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12313                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
12314                 if ( id != null ) {
12315                     System.out.println( "value   =" + id.getValue() );
12316                     System.out.println( "provider=" + id.getSource() );
12317                 }
12318                 return false;
12319             }
12320             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
12321             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12322                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
12323                 if ( id != null ) {
12324                     System.out.println( "value   =" + id.getValue() );
12325                     System.out.println( "provider=" + id.getSource() );
12326                 }
12327                 return false;
12328             }
12329             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
12330             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12331                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
12332                 if ( id != null ) {
12333                     System.out.println( "value   =" + id.getValue() );
12334                     System.out.println( "provider=" + id.getSource() );
12335                 }
12336                 return false;
12337             }
12338             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
12339             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12340                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
12341                 if ( id != null ) {
12342                     System.out.println( "value   =" + id.getValue() );
12343                     System.out.println( "provider=" + id.getSource() );
12344                 }
12345                 return false;
12346             }
12347             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
12348             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12349                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
12350                 if ( id != null ) {
12351                     System.out.println( "value   =" + id.getValue() );
12352                     System.out.println( "provider=" + id.getSource() );
12353                 }
12354                 return false;
12355             }
12356             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
12357             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12358                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
12359                 if ( id != null ) {
12360                     System.out.println( "value   =" + id.getValue() );
12361                     System.out.println( "provider=" + id.getSource() );
12362                 }
12363                 return false;
12364             }
12365             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
12366             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12367                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
12368                 if ( id != null ) {
12369                     System.out.println( "value   =" + id.getValue() );
12370                     System.out.println( "provider=" + id.getSource() );
12371                 }
12372                 return false;
12373             }
12374             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
12375             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12376                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
12377                 if ( id != null ) {
12378                     System.out.println( "value   =" + id.getValue() );
12379                     System.out.println( "provider=" + id.getSource() );
12380                 }
12381                 return false;
12382             }
12383             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
12384             if ( id != null ) {
12385                 System.out.println( "value   =" + id.getValue() );
12386                 System.out.println( "provider=" + id.getSource() );
12387                 return false;
12388             }
12389             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
12390             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12391                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
12392                 if ( id != null ) {
12393                     System.out.println( "value   =" + id.getValue() );
12394                     System.out.println( "provider=" + id.getSource() );
12395                 }
12396                 return false;
12397             }
12398             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
12399             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12400                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
12401                 if ( id != null ) {
12402                     System.out.println( "value   =" + id.getValue() );
12403                     System.out.println( "provider=" + id.getSource() );
12404                 }
12405                 return false;
12406             }
12407             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
12408             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12409                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
12410                 if ( id != null ) {
12411                     System.out.println( "value   =" + id.getValue() );
12412                     System.out.println( "provider=" + id.getSource() );
12413                 }
12414                 return false;
12415             }
12416             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
12417             if ( id != null ) {
12418                 System.out.println( "value   =" + id.getValue() );
12419                 System.out.println( "provider=" + id.getSource() );
12420                 return false;
12421             }
12422         }
12423         catch ( final Exception e ) {
12424             e.printStackTrace( System.out );
12425             return false;
12426         }
12427         return true;
12428     }
12429
12430     private static boolean testSequenceWriter() {
12431         try {
12432             final String n = ForesterUtil.LINE_SEPARATOR;
12433             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
12434                 return false;
12435             }
12436             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
12437                 return false;
12438             }
12439             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
12440                 return false;
12441             }
12442             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
12443                 return false;
12444             }
12445             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
12446                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
12447                 return false;
12448             }
12449             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
12450                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
12451                 return false;
12452             }
12453         }
12454         catch ( final Exception e ) {
12455             e.printStackTrace();
12456             return false;
12457         }
12458         return true;
12459     }
12460
12461     private static boolean testSpecies() {
12462         try {
12463             final Species s1 = new BasicSpecies( "a" );
12464             final Species s2 = new BasicSpecies( "a" );
12465             final Species s3 = new BasicSpecies( "A" );
12466             final Species s4 = new BasicSpecies( "b" );
12467             if ( !s1.equals( s1 ) ) {
12468                 return false;
12469             }
12470             if ( s1.getSpeciesId().equals( "x" ) ) {
12471                 return false;
12472             }
12473             if ( s1.getSpeciesId().equals( null ) ) {
12474                 return false;
12475             }
12476             if ( !s1.equals( s2 ) ) {
12477                 return false;
12478             }
12479             if ( s1.equals( s3 ) ) {
12480                 return false;
12481             }
12482             if ( s1.hashCode() != s1.hashCode() ) {
12483                 return false;
12484             }
12485             if ( s1.hashCode() != s2.hashCode() ) {
12486                 return false;
12487             }
12488             if ( s1.hashCode() == s3.hashCode() ) {
12489                 return false;
12490             }
12491             if ( s1.compareTo( s1 ) != 0 ) {
12492                 return false;
12493             }
12494             if ( s1.compareTo( s2 ) != 0 ) {
12495                 return false;
12496             }
12497             if ( s1.compareTo( s3 ) != 0 ) {
12498                 return false;
12499             }
12500             if ( s1.compareTo( s4 ) >= 0 ) {
12501                 return false;
12502             }
12503             if ( s4.compareTo( s1 ) <= 0 ) {
12504                 return false;
12505             }
12506             if ( !s4.getSpeciesId().equals( "b" ) ) {
12507                 return false;
12508             }
12509             final Species s5 = new BasicSpecies( " C " );
12510             if ( !s5.getSpeciesId().equals( "C" ) ) {
12511                 return false;
12512             }
12513             if ( s5.equals( s1 ) ) {
12514                 return false;
12515             }
12516         }
12517         catch ( final Exception e ) {
12518             e.printStackTrace( System.out );
12519             return false;
12520         }
12521         return true;
12522     }
12523
12524     private static boolean testSplit() {
12525         try {
12526             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12527             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12528             //Archaeopteryx.createApplication( p0 );
12529             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
12530             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12531             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12532             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12533             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12534             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12535             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12536             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12537             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12538             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12539             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
12540             // System.out.println( s0.toString() );
12541             //
12542             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12543             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12544             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12545             if ( s0.match( query_nodes ) ) {
12546                 return false;
12547             }
12548             query_nodes = new HashSet<PhylogenyNode>();
12549             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12550             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12551             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12552             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12553             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12554             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12555             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12556             if ( !s0.match( query_nodes ) ) {
12557                 return false;
12558             }
12559             //
12560             query_nodes = new HashSet<PhylogenyNode>();
12561             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12562             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12563             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12564             if ( !s0.match( query_nodes ) ) {
12565                 return false;
12566             }
12567             //
12568             query_nodes = new HashSet<PhylogenyNode>();
12569             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12570             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12571             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12572             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12573             if ( !s0.match( query_nodes ) ) {
12574                 return false;
12575             }
12576             //
12577             query_nodes = new HashSet<PhylogenyNode>();
12578             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12579             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12580             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12581             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12582             if ( !s0.match( query_nodes ) ) {
12583                 return false;
12584             }
12585             //
12586             query_nodes = new HashSet<PhylogenyNode>();
12587             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12589             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12590             if ( !s0.match( query_nodes ) ) {
12591                 return false;
12592             }
12593             query_nodes = new HashSet<PhylogenyNode>();
12594             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12595             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12596             if ( !s0.match( query_nodes ) ) {
12597                 return false;
12598             }
12599             query_nodes = new HashSet<PhylogenyNode>();
12600             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12601             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12602             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12603             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12604             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12605             if ( !s0.match( query_nodes ) ) {
12606                 return false;
12607             }
12608             query_nodes = new HashSet<PhylogenyNode>();
12609             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12610             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12611             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12612             if ( !s0.match( query_nodes ) ) {
12613                 return false;
12614             }
12615             query_nodes = new HashSet<PhylogenyNode>();
12616             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12617             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12618             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12619             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12620             if ( !s0.match( query_nodes ) ) {
12621                 return false;
12622             }
12623             query_nodes = new HashSet<PhylogenyNode>();
12624             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12625             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12626             if ( s0.match( query_nodes ) ) {
12627                 return false;
12628             }
12629             query_nodes = new HashSet<PhylogenyNode>();
12630             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12631             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12632             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12633             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12634             if ( s0.match( query_nodes ) ) {
12635                 return false;
12636             }
12637             query_nodes = new HashSet<PhylogenyNode>();
12638             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12640             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12641             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12642             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12643             if ( s0.match( query_nodes ) ) {
12644                 return false;
12645             }
12646             query_nodes = new HashSet<PhylogenyNode>();
12647             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12648             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12649             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12650             if ( s0.match( query_nodes ) ) {
12651                 return false;
12652             }
12653             query_nodes = new HashSet<PhylogenyNode>();
12654             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12655             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12656             if ( s0.match( query_nodes ) ) {
12657                 return false;
12658             }
12659             query_nodes = new HashSet<PhylogenyNode>();
12660             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12661             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12662             if ( s0.match( query_nodes ) ) {
12663                 return false;
12664             }
12665             query_nodes = new HashSet<PhylogenyNode>();
12666             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12667             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12668             if ( s0.match( query_nodes ) ) {
12669                 return false;
12670             }
12671             query_nodes = new HashSet<PhylogenyNode>();
12672             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12673             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12674             if ( s0.match( query_nodes ) ) {
12675                 return false;
12676             }
12677             query_nodes = new HashSet<PhylogenyNode>();
12678             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12679             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12680             if ( s0.match( query_nodes ) ) {
12681                 return false;
12682             }
12683             query_nodes = new HashSet<PhylogenyNode>();
12684             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12685             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12686             if ( s0.match( query_nodes ) ) {
12687                 return false;
12688             }
12689             query_nodes = new HashSet<PhylogenyNode>();
12690             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12691             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12692             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12693             if ( s0.match( query_nodes ) ) {
12694                 return false;
12695             }
12696             query_nodes = new HashSet<PhylogenyNode>();
12697             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12698             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12699             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12700             if ( s0.match( query_nodes ) ) {
12701                 return false;
12702             }
12703             query_nodes = new HashSet<PhylogenyNode>();
12704             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12705             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12706             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12707             if ( s0.match( query_nodes ) ) {
12708                 return false;
12709             }
12710             query_nodes = new HashSet<PhylogenyNode>();
12711             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12712             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12713             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12714             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12715             if ( s0.match( query_nodes ) ) {
12716                 return false;
12717             }
12718             /////////
12719             //            query_nodes = new HashSet<PhylogenyNode>();
12720             //            query_nodes.add( new PhylogenyNode( "X" ) );
12721             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12722             //            query_nodes.add( new PhylogenyNode( "A" ) );
12723             //            query_nodes.add( new PhylogenyNode( "B" ) );
12724             //            query_nodes.add( new PhylogenyNode( "C" ) );
12725             //            query_nodes.add( new PhylogenyNode( "D" ) );
12726             //            query_nodes.add( new PhylogenyNode( "E" ) );
12727             //            query_nodes.add( new PhylogenyNode( "F" ) );
12728             //            query_nodes.add( new PhylogenyNode( "G" ) );
12729             //            if ( !s0.match( query_nodes ) ) {
12730             //                return false;
12731             //            }
12732             //            query_nodes = new HashSet<PhylogenyNode>();
12733             //            query_nodes.add( new PhylogenyNode( "X" ) );
12734             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12735             //            query_nodes.add( new PhylogenyNode( "A" ) );
12736             //            query_nodes.add( new PhylogenyNode( "B" ) );
12737             //            query_nodes.add( new PhylogenyNode( "C" ) );
12738             //            if ( !s0.match( query_nodes ) ) {
12739             //                return false;
12740             //            }
12741             //            //
12742             //            query_nodes = new HashSet<PhylogenyNode>();
12743             //            query_nodes.add( new PhylogenyNode( "X" ) );
12744             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12745             //            query_nodes.add( new PhylogenyNode( "D" ) );
12746             //            query_nodes.add( new PhylogenyNode( "E" ) );
12747             //            query_nodes.add( new PhylogenyNode( "F" ) );
12748             //            query_nodes.add( new PhylogenyNode( "G" ) );
12749             //            if ( !s0.match( query_nodes ) ) {
12750             //                return false;
12751             //            }
12752             //            //
12753             //            query_nodes = new HashSet<PhylogenyNode>();
12754             //            query_nodes.add( new PhylogenyNode( "X" ) );
12755             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12756             //            query_nodes.add( new PhylogenyNode( "A" ) );
12757             //            query_nodes.add( new PhylogenyNode( "B" ) );
12758             //            query_nodes.add( new PhylogenyNode( "C" ) );
12759             //            query_nodes.add( new PhylogenyNode( "D" ) );
12760             //            if ( !s0.match( query_nodes ) ) {
12761             //                return false;
12762             //            }
12763             //            //
12764             //            query_nodes = new HashSet<PhylogenyNode>();
12765             //            query_nodes.add( new PhylogenyNode( "X" ) );
12766             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12767             //            query_nodes.add( new PhylogenyNode( "E" ) );
12768             //            query_nodes.add( new PhylogenyNode( "F" ) );
12769             //            query_nodes.add( new PhylogenyNode( "G" ) );
12770             //            if ( !s0.match( query_nodes ) ) {
12771             //                return false;
12772             //            }
12773             //            //
12774             //            query_nodes = new HashSet<PhylogenyNode>();
12775             //            query_nodes.add( new PhylogenyNode( "X" ) );
12776             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12777             //            query_nodes.add( new PhylogenyNode( "F" ) );
12778             //            query_nodes.add( new PhylogenyNode( "G" ) );
12779             //            if ( !s0.match( query_nodes ) ) {
12780             //                return false;
12781             //            }
12782             //
12783             query_nodes = new HashSet<PhylogenyNode>();
12784             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12785             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12786             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12787             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12788             if ( s0.match( query_nodes ) ) {
12789                 return false;
12790             }
12791             //
12792             query_nodes = new HashSet<PhylogenyNode>();
12793             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12794             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12795             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12796             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12797             if ( s0.match( query_nodes ) ) {
12798                 return false;
12799             }
12800             ///////////////////////////
12801             //
12802             query_nodes = new HashSet<PhylogenyNode>();
12803             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12804             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12805             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12806             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12807             if ( s0.match( query_nodes ) ) {
12808                 return false;
12809             }
12810             //
12811             query_nodes = new HashSet<PhylogenyNode>();
12812             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12813             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12814             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12815             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12816             if ( s0.match( query_nodes ) ) {
12817                 return false;
12818             }
12819             //
12820             query_nodes = new HashSet<PhylogenyNode>();
12821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12822             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12823             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12824             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12825             if ( s0.match( query_nodes ) ) {
12826                 return false;
12827             }
12828             //
12829             query_nodes = new HashSet<PhylogenyNode>();
12830             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12831             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12832             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12833             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12834             if ( s0.match( query_nodes ) ) {
12835                 return false;
12836             }
12837             //
12838             query_nodes = new HashSet<PhylogenyNode>();
12839             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12840             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12841             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12842             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12843             if ( s0.match( query_nodes ) ) {
12844                 return false;
12845             }
12846             //
12847             query_nodes = new HashSet<PhylogenyNode>();
12848             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12849             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12850             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12851             if ( s0.match( query_nodes ) ) {
12852                 return false;
12853             }
12854             //
12855             query_nodes = new HashSet<PhylogenyNode>();
12856             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12857             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12858             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12859             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12860             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12861             if ( s0.match( query_nodes ) ) {
12862                 return false;
12863             }
12864             //
12865             query_nodes = new HashSet<PhylogenyNode>();
12866             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12867             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12868             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12869             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12871             if ( s0.match( query_nodes ) ) {
12872                 return false;
12873             }
12874             //
12875             query_nodes = new HashSet<PhylogenyNode>();
12876             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12877             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12878             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12879             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12880             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12881             if ( s0.match( query_nodes ) ) {
12882                 return false;
12883             }
12884             //
12885             query_nodes = new HashSet<PhylogenyNode>();
12886             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12890             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12891             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12892             if ( s0.match( query_nodes ) ) {
12893                 return false;
12894             }
12895         }
12896         catch ( final Exception e ) {
12897             e.printStackTrace();
12898             return false;
12899         }
12900         return true;
12901     }
12902
12903     private static boolean testSplitStrict() {
12904         try {
12905             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12906             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12907             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
12908             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12909             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12910             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12911             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12912             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12913             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12914             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12915             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
12916             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12917             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12918             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12919             if ( s0.match( query_nodes ) ) {
12920                 return false;
12921             }
12922             query_nodes = new HashSet<PhylogenyNode>();
12923             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12924             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12925             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12926             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12927             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12928             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12929             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12930             if ( !s0.match( query_nodes ) ) {
12931                 return false;
12932             }
12933             //
12934             query_nodes = new HashSet<PhylogenyNode>();
12935             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12936             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12937             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12938             if ( !s0.match( query_nodes ) ) {
12939                 return false;
12940             }
12941             //
12942             query_nodes = new HashSet<PhylogenyNode>();
12943             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12944             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12945             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12946             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12947             if ( !s0.match( query_nodes ) ) {
12948                 return false;
12949             }
12950             //
12951             query_nodes = new HashSet<PhylogenyNode>();
12952             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12953             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12954             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12955             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12956             if ( !s0.match( query_nodes ) ) {
12957                 return false;
12958             }
12959             //
12960             query_nodes = new HashSet<PhylogenyNode>();
12961             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12962             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12963             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12964             if ( !s0.match( query_nodes ) ) {
12965                 return false;
12966             }
12967             //
12968             query_nodes = new HashSet<PhylogenyNode>();
12969             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12970             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12971             if ( !s0.match( query_nodes ) ) {
12972                 return false;
12973             }
12974             //
12975             query_nodes = new HashSet<PhylogenyNode>();
12976             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12977             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12978             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12979             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12980             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12981             if ( !s0.match( query_nodes ) ) {
12982                 return false;
12983             }
12984             //
12985             query_nodes = new HashSet<PhylogenyNode>();
12986             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12987             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12988             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12989             if ( !s0.match( query_nodes ) ) {
12990                 return false;
12991             }
12992             //
12993             query_nodes = new HashSet<PhylogenyNode>();
12994             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12995             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12996             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12997             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12998             if ( !s0.match( query_nodes ) ) {
12999                 return false;
13000             }
13001             //
13002             query_nodes = new HashSet<PhylogenyNode>();
13003             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
13004             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13005             if ( s0.match( query_nodes ) ) {
13006                 return false;
13007             }
13008             //
13009             query_nodes = new HashSet<PhylogenyNode>();
13010             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13011             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
13012             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
13013             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
13014             if ( s0.match( query_nodes ) ) {
13015                 return false;
13016             }
13017             //
13018             query_nodes = new HashSet<PhylogenyNode>();
13019             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
13020             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
13021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
13022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
13023             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
13024             if ( s0.match( query_nodes ) ) {
13025                 return false;
13026             }
13027             //
13028             query_nodes = new HashSet<PhylogenyNode>();
13029             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13030             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
13031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
13032             if ( s0.match( query_nodes ) ) {
13033                 return false;
13034             }
13035             //
13036             query_nodes = new HashSet<PhylogenyNode>();
13037             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
13039             if ( s0.match( query_nodes ) ) {
13040                 return false;
13041             }
13042             //
13043             query_nodes = new HashSet<PhylogenyNode>();
13044             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13045             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
13046             if ( s0.match( query_nodes ) ) {
13047                 return false;
13048             }
13049             //
13050             query_nodes = new HashSet<PhylogenyNode>();
13051             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13052             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
13053             if ( s0.match( query_nodes ) ) {
13054                 return false;
13055             }
13056             //
13057             query_nodes = new HashSet<PhylogenyNode>();
13058             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13059             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
13060             if ( s0.match( query_nodes ) ) {
13061                 return false;
13062             }
13063             //
13064             query_nodes = new HashSet<PhylogenyNode>();
13065             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13066             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
13067             if ( s0.match( query_nodes ) ) {
13068                 return false;
13069             }
13070             //
13071             query_nodes = new HashSet<PhylogenyNode>();
13072             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13073             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
13074             if ( s0.match( query_nodes ) ) {
13075                 return false;
13076             }
13077             //
13078             query_nodes = new HashSet<PhylogenyNode>();
13079             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13080             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
13081             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
13082             if ( s0.match( query_nodes ) ) {
13083                 return false;
13084             }
13085             //
13086             query_nodes = new HashSet<PhylogenyNode>();
13087             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13088             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
13089             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
13090             if ( s0.match( query_nodes ) ) {
13091                 return false;
13092             }
13093             //
13094             query_nodes = new HashSet<PhylogenyNode>();
13095             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
13096             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
13097             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13098             if ( s0.match( query_nodes ) ) {
13099                 return false;
13100             }
13101             //
13102             query_nodes = new HashSet<PhylogenyNode>();
13103             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
13104             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
13105             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
13106             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
13107             if ( s0.match( query_nodes ) ) {
13108                 return false;
13109             }
13110         }
13111         catch ( final Exception e ) {
13112             e.printStackTrace();
13113             return false;
13114         }
13115         return true;
13116     }
13117
13118     private static boolean testSubtreeDeletion() {
13119         try {
13120             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13121             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
13122             t1.deleteSubtree( t1.getNode( "A" ), false );
13123             if ( t1.getNumberOfExternalNodes() != 5 ) {
13124                 return false;
13125             }
13126             t1.toNewHampshireX();
13127             t1.deleteSubtree( t1.getNode( "E" ), false );
13128             if ( t1.getNumberOfExternalNodes() != 4 ) {
13129                 return false;
13130             }
13131             t1.toNewHampshireX();
13132             t1.deleteSubtree( t1.getNode( "F" ), false );
13133             if ( t1.getNumberOfExternalNodes() != 3 ) {
13134                 return false;
13135             }
13136             t1.toNewHampshireX();
13137             t1.deleteSubtree( t1.getNode( "D" ), false );
13138             t1.toNewHampshireX();
13139             if ( t1.getNumberOfExternalNodes() != 3 ) {
13140                 return false;
13141             }
13142             t1.deleteSubtree( t1.getNode( "def" ), false );
13143             t1.toNewHampshireX();
13144             if ( t1.getNumberOfExternalNodes() != 2 ) {
13145                 return false;
13146             }
13147             t1.deleteSubtree( t1.getNode( "B" ), false );
13148             t1.toNewHampshireX();
13149             if ( t1.getNumberOfExternalNodes() != 1 ) {
13150                 return false;
13151             }
13152             t1.deleteSubtree( t1.getNode( "C" ), false );
13153             t1.toNewHampshireX();
13154             if ( t1.getNumberOfExternalNodes() != 1 ) {
13155                 return false;
13156             }
13157             t1.deleteSubtree( t1.getNode( "abc" ), false );
13158             t1.toNewHampshireX();
13159             if ( t1.getNumberOfExternalNodes() != 1 ) {
13160                 return false;
13161             }
13162             t1.deleteSubtree( t1.getNode( "r" ), false );
13163             if ( t1.getNumberOfExternalNodes() != 0 ) {
13164                 return false;
13165             }
13166             if ( !t1.isEmpty() ) {
13167                 return false;
13168             }
13169             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
13170             t2.deleteSubtree( t2.getNode( "A" ), false );
13171             t2.toNewHampshireX();
13172             if ( t2.getNumberOfExternalNodes() != 5 ) {
13173                 return false;
13174             }
13175             t2.deleteSubtree( t2.getNode( "abc" ), false );
13176             t2.toNewHampshireX();
13177             if ( t2.getNumberOfExternalNodes() != 3 ) {
13178                 return false;
13179             }
13180             t2.deleteSubtree( t2.getNode( "def" ), false );
13181             t2.toNewHampshireX();
13182             if ( t2.getNumberOfExternalNodes() != 1 ) {
13183                 return false;
13184             }
13185         }
13186         catch ( final Exception e ) {
13187             e.printStackTrace( System.out );
13188             return false;
13189         }
13190         return true;
13191     }
13192
13193     private static boolean testSupportCount() {
13194         try {
13195             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13196             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
13197             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
13198                     + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
13199                     + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))" + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
13200                                                               new NHXParser() );
13201             SupportCount.count( t0_1, phylogenies_1, true, false );
13202             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
13203             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
13204                     + "(((((A,B),C),D),E),((F,G),X))" + "(((((A,Y),B),C),D),((F,G),E))" + "(((((A,B),C),D),E),(F,G))"
13205                     + "(((((A,B),C),D),E),(F,G))" + "(((((A,B),C),D),E),(F,G))" + "(((((A,B),C),D),E),(F,G),Z)"
13206                     + "(((((A,B),C),D),E),(F,G))" + "((((((A,B),C),D),E),F),G)" + "(((((X,Y),F,G),E),((A,B),C)),D)",
13207                                                               new NHXParser() );
13208             SupportCount.count( t0_2, phylogenies_2, true, false );
13209             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
13210             while ( it.hasNext() ) {
13211                 final PhylogenyNode n = it.next();
13212                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
13213                     return false;
13214                 }
13215             }
13216             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
13217             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
13218                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
13219             SupportCount.count( t0_3, phylogenies_3, true, false );
13220             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
13221             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
13222                 return false;
13223             }
13224             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
13225                 return false;
13226             }
13227             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
13228                 return false;
13229             }
13230             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
13231                 return false;
13232             }
13233             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
13234                 return false;
13235             }
13236             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
13237                 return false;
13238             }
13239             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
13240                 return false;
13241             }
13242             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
13243                 return false;
13244             }
13245             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
13246                 return false;
13247             }
13248             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
13249                 return false;
13250             }
13251             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13252             final Phylogeny[] phylogenies_4 = factory
13253                     .create( "((((((A,X),C),B),D),E),F) " + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
13254             SupportCount.count( t0_4, phylogenies_4, true, false );
13255             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
13256             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
13257                 return false;
13258             }
13259             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
13260                 return false;
13261             }
13262             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
13263                 return false;
13264             }
13265             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
13266                 return false;
13267             }
13268             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
13269                 return false;
13270             }
13271             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
13272                 return false;
13273             }
13274             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
13275                 return false;
13276             }
13277             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
13278                 return false;
13279             }
13280             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
13281                 return false;
13282             }
13283             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
13284                 return false;
13285             }
13286             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13287             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13288             double d = SupportCount.compare( b1, a, true, true, true );
13289             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
13290                 return false;
13291             }
13292             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13293             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13294             d = SupportCount.compare( b2, a, true, true, true );
13295             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
13296                 return false;
13297             }
13298             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13299             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
13300             d = SupportCount.compare( b3, a, true, true, true );
13301             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
13302                 return false;
13303             }
13304             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
13305             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
13306             d = SupportCount.compare( b4, a, true, true, false );
13307             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
13308                 return false;
13309             }
13310         }
13311         catch ( final Exception e ) {
13312             e.printStackTrace( System.out );
13313             return false;
13314         }
13315         return true;
13316     }
13317
13318     private static boolean testSupportTransfer() {
13319         try {
13320             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13321             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)",
13322                                                  new NHXParser() )[ 0 ];
13323             final Phylogeny p2 = factory.create(
13324                                                  "(((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)",
13325                                                  new NHXParser() )[ 0 ];
13326             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
13327                 return false;
13328             }
13329             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
13330                 return false;
13331             }
13332             support_transfer.moveBranchLengthsToBootstrap( p1 );
13333             support_transfer.transferSupportValues( p1, p2 );
13334             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
13335                 return false;
13336             }
13337             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
13338                 return false;
13339             }
13340             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
13341                 return false;
13342             }
13343             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
13344                 return false;
13345             }
13346             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
13347                 return false;
13348             }
13349             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
13350                 return false;
13351             }
13352             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
13353                 return false;
13354             }
13355             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
13356                 return false;
13357             }
13358         }
13359         catch ( final Exception e ) {
13360             e.printStackTrace( System.out );
13361             return false;
13362         }
13363         return true;
13364     }
13365
13366     private static boolean testTaxonomyExtraction() {
13367         try {
13368             final PhylogenyNode n0 = PhylogenyNode
13369                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13370             if ( n0.getNodeData().isHasTaxonomy() ) {
13371                 return false;
13372             }
13373             final PhylogenyNode n1 = PhylogenyNode
13374                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13375             if ( n1.getNodeData().isHasTaxonomy() ) {
13376                 System.out.println( n1.toString() );
13377                 return false;
13378             }
13379             final PhylogenyNode n2x = PhylogenyNode
13380                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13381             if ( n2x.getNodeData().isHasTaxonomy() ) {
13382                 return false;
13383             }
13384             final PhylogenyNode n3 = PhylogenyNode
13385                     .createInstanceFromNhxString( "BLAGG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13386             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13387                 System.out.println( n3.toString() );
13388                 return false;
13389             }
13390             final PhylogenyNode n4 = PhylogenyNode
13391                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13392             if ( n4.getNodeData().isHasTaxonomy() ) {
13393                 System.out.println( n4.toString() );
13394                 return false;
13395             }
13396             final PhylogenyNode n5 = PhylogenyNode
13397                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13398             if ( n5.getNodeData().isHasTaxonomy() ) {
13399                 System.out.println( n5.toString() );
13400                 return false;
13401             }
13402             final PhylogenyNode n6 = PhylogenyNode
13403                     .createInstanceFromNhxString( "BLAGG-12345-blag",
13404                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13405             if ( n6.getNodeData().isHasTaxonomy() ) {
13406                 System.out.println( n6.toString() );
13407                 return false;
13408             }
13409             final PhylogenyNode n7 = PhylogenyNode
13410                     .createInstanceFromNhxString( "BL-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13411             if ( n7.getNodeData().isHasTaxonomy() ) {
13412                 System.out.println( n7.toString() );
13413                 return false;
13414             }
13415             final PhylogenyNode n8 = PhylogenyNode
13416                     .createInstanceFromNhxString( "BLAGG_12345-blag",
13417                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13418             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13419                 System.out.println( n8.toString() );
13420                 return false;
13421             }
13422             final PhylogenyNode n9 = PhylogenyNode
13423                     .createInstanceFromNhxString( "BLAGG_12345/blag",
13424                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13425             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13426                 System.out.println( n9.toString() );
13427                 return false;
13428             }
13429             final PhylogenyNode n10x = PhylogenyNode
13430                     .createInstanceFromNhxString( "BLAG!_12X45-blag",
13431                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13432             if ( n10x.getNodeData().isHasTaxonomy() ) {
13433                 System.out.println( n10x.toString() );
13434                 return false;
13435             }
13436             final PhylogenyNode n10xx = PhylogenyNode
13437                     .createInstanceFromNhxString( "BLAG!_1YX45-blag",
13438                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13439             if ( n10xx.getNodeData().isHasTaxonomy() ) {
13440                 System.out.println( n10xx.toString() );
13441                 return false;
13442             }
13443             final PhylogenyNode n10 = PhylogenyNode
13444                     .createInstanceFromNhxString( "BLAGG_9YX45-blag",
13445                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13446             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
13447                 System.out.println( n10.toString() );
13448                 return false;
13449             }
13450             final PhylogenyNode n10v = PhylogenyNode
13451                     .createInstanceFromNhxString( "BLAGG_BPM1-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13452             if ( !n10v.getNodeData().getTaxonomy().getTaxonomyCode().equals( "BPM1" ) ) {
13453                 System.out.println( n10v.toString() );
13454                 return false;
13455             }
13456             final PhylogenyNode n10v2 = PhylogenyNode
13457                     .createInstanceFromNhxString( "BLAGG_ABV-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13458             if ( !n10v2.getNodeData().getTaxonomy().getTaxonomyCode().equals( "ABV" ) ) {
13459                 System.out.println( n10v2.toString() );
13460                 return false;
13461             }
13462             final PhylogenyNode n11 = PhylogenyNode
13463                     .createInstanceFromNhxString( "BLAG@_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13464             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13465                 System.out.println( n11.toString() );
13466                 return false;
13467             }
13468             final PhylogenyNode n12 = PhylogenyNode
13469                     .createInstanceFromNhxString( "BLA_G_Mus_musculus_musculus",
13470                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13471             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13472                 System.out.println( n12.toString() );
13473                 return false;
13474             }
13475             final PhylogenyNode n13 = PhylogenyNode
13476                     .createInstanceFromNhxString( "BLAaG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13477             if ( n13.getNodeData().isHasTaxonomy() ) {
13478                 System.out.println( n13.toString() );
13479                 return false;
13480             }
13481             final PhylogenyNode n14 = PhylogenyNode
13482                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13483             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13484                 System.out.println( n14.toString() );
13485                 return false;
13486             }
13487             final PhylogenyNode n15 = PhylogenyNode
13488                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13489             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13490                 System.out.println( n15.toString() );
13491                 return false;
13492             }
13493             final PhylogenyNode n16 = PhylogenyNode
13494                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13495             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13496                 System.out.println( n16.toString() );
13497                 return false;
13498             }
13499             final PhylogenyNode n17 = PhylogenyNode
13500                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13501             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13502                 System.out.println( n17.toString() );
13503                 return false;
13504             }
13505             final PhylogenyNode n18 = PhylogenyNode
13506                     .createInstanceFromNhxString( "Mus_musculus_musculus_392",
13507                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13508             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13509                 System.out.println( n18.toString() );
13510                 return false;
13511             }
13512             final PhylogenyNode n19 = PhylogenyNode
13513                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
13514                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13515             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13516                 System.out.println( n19.toString() );
13517                 return false;
13518             }
13519             final PhylogenyNode n20 = PhylogenyNode
13520                     .createInstanceFromNhxString( "Mus musculus musculus 392",
13521                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13522             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13523                 System.out.println( n20.toString() );
13524                 return false;
13525             }
13526             final PhylogenyNode n21 = PhylogenyNode
13527                     .createInstanceFromNhxString( "Mus musculus musculus K392",
13528                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13529             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13530                 System.out.println( n21.toString() );
13531                 return false;
13532             }
13533             final PhylogenyNode n23 = PhylogenyNode
13534                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
13535                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13536             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13537                 System.out.println( n23.toString() );
13538                 return false;
13539             }
13540             final PhylogenyNode n24 = PhylogenyNode
13541                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13542             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13543                 System.out.println( n24.toString() );
13544                 return false;
13545             }
13546             //
13547             final PhylogenyNode n25 = PhylogenyNode
13548                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
13549                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13550             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
13551                 System.out.println( n25.toString() );
13552                 return false;
13553             }
13554             final PhylogenyNode n26 = PhylogenyNode
13555                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
13556                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13557             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13558                 System.out.println( n26.toString() );
13559                 return false;
13560             }
13561             final PhylogenyNode n27 = PhylogenyNode
13562                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13563             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13564                 System.out.println( n27.toString() );
13565                 return false;
13566             }
13567         }
13568         catch ( final Exception e ) {
13569             e.printStackTrace( System.out );
13570             return false;
13571         }
13572         return true;
13573     }
13574
13575     private static boolean testTreeCopy() {
13576         try {
13577             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
13578             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
13579             final Phylogeny t1 = t0.copy();
13580             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
13581                 return false;
13582             }
13583             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13584                 return false;
13585             }
13586             t0.deleteSubtree( t0.getNode( "c" ), true );
13587             t0.deleteSubtree( t0.getNode( "a" ), true );
13588             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
13589             t0.getNode( "b" ).setName( "Bee" );
13590             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
13591                 return false;
13592             }
13593             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13594                 return false;
13595             }
13596             t0.deleteSubtree( t0.getNode( "e" ), true );
13597             t0.deleteSubtree( t0.getNode( "Bee" ), true );
13598             t0.deleteSubtree( t0.getNode( "d" ), true );
13599             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13600                 return false;
13601             }
13602         }
13603         catch ( final Exception e ) {
13604             e.printStackTrace();
13605             return false;
13606         }
13607         return true;
13608     }
13609
13610     private static boolean testTreeMethods() {
13611         try {
13612             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13613             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
13614             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
13615             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
13616                 System.out.println( t0.toNewHampshireX() );
13617                 return false;
13618             }
13619             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
13620             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
13621             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
13622                 return false;
13623             }
13624             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
13625                 return false;
13626             }
13627             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
13628                 return false;
13629             }
13630         }
13631         catch ( final Exception e ) {
13632             e.printStackTrace( System.out );
13633             return false;
13634         }
13635         return true;
13636     }
13637     
13638     private static boolean testPhylogenyMethods() {
13639         try {
13640             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13641             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)r", new NHXParser() )[ 0 ];
13642           
13643             if ( PhylogenyMethods.calculateLevel( t0.getNode( "A" ) ) != 0 ) {
13644                 return false;
13645             }
13646             if ( PhylogenyMethods.calculateLevel( t0.getNode( "B" ) ) != 0 ) {
13647                 return false;
13648             }
13649             if ( PhylogenyMethods.calculateLevel( t0.getNode( "ab" ) ) != 1 ) {
13650                 return false;
13651             }
13652             if ( PhylogenyMethods.calculateLevel( t0.getNode( "C" ) ) != 0 ) {
13653                 return false;
13654             }
13655             if ( PhylogenyMethods.calculateLevel( t0.getNode( "abc" ) ) != 2 ) {
13656                 return false;
13657             }
13658             if ( PhylogenyMethods.calculateLevel( t0.getNode( "D" ) ) != 0 ) {
13659                 return false;
13660             }
13661             if ( PhylogenyMethods.calculateLevel( t0.getNode( "abcd" ) ) != 3 ) {
13662                 return false;
13663             }
13664             if ( PhylogenyMethods.calculateLevel( t0.getNode( "E" ) ) != 0 ) {
13665                 return false;
13666             }
13667             if ( PhylogenyMethods.calculateLevel( t0.getNode( "r" ) ) != 4 ) {
13668                 return false;
13669             }
13670             final Phylogeny t1 = factory.create( "((((A,B)ab,C)abc,D)abcd,E,((((((X)1)2)3)4)5)6)r", new NHXParser() )[ 0 ];
13671             if ( PhylogenyMethods.calculateLevel( t1.getNode( "r" ) ) != 7 ) {
13672                 return false;
13673             }
13674             if ( PhylogenyMethods.calculateLevel( t1.getNode( "X" ) ) != 0 ) {
13675                 return false;
13676             }
13677             if ( PhylogenyMethods.calculateLevel( t1.getNode( "6" ) ) != 6 ) {
13678                 return false;
13679             }
13680             if ( PhylogenyMethods.calculateLevel( t1.getNode( "5" ) ) != 5 ) {
13681                 return false;
13682             }
13683             if ( PhylogenyMethods.calculateLevel( t1.getNode( "4" ) ) != 4 ) {
13684                 return false;
13685             }
13686             if ( PhylogenyMethods.calculateLevel( t1.getNode( "3" ) ) != 3 ) {
13687                 return false;
13688             }
13689             if ( PhylogenyMethods.calculateLevel( t1.getNode( "2" ) ) != 2 ) {
13690                 return false;
13691             }
13692             if ( PhylogenyMethods.calculateLevel( t1.getNode( "1" ) ) != 1 ) {
13693                 return false;
13694             }
13695             if ( PhylogenyMethods.calculateLevel( t1.getNode( "abcd" ) ) != 3 ) {
13696                 return false;
13697             }
13698             
13699         }
13700         catch ( final Exception e ) {
13701             e.printStackTrace( System.out );
13702             return false;
13703         }
13704         return true;
13705     }
13706
13707     private static boolean testUniprotEntryRetrieval() {
13708         try {
13709             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 5000 );
13710             if ( !entry.getAccession().equals( "P12345" ) ) {
13711                 return false;
13712             }
13713             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
13714                 return false;
13715             }
13716             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
13717                 return false;
13718             }
13719             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
13720                 return false;
13721             }
13722             if ( !entry.getGeneName().equals( "GOT2" ) ) {
13723                 return false;
13724             }
13725             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
13726                 return false;
13727             }
13728             if ( entry.getMolecularSequence() == null ) {
13729                 return false;
13730             }
13731             if ( !entry.getMolecularSequence().getMolecularSequenceAsString()
13732                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
13733                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
13734                 System.out.println( "got: " + entry.getMolecularSequence().getMolecularSequenceAsString() );
13735                 System.out.println( "expected something else." );
13736                 return false;
13737             }
13738         }
13739         catch ( final IOException e ) {
13740             System.out.println();
13741             System.out.println( "the following might be due to absence internet connection:" );
13742             e.printStackTrace( System.out );
13743             return true;
13744         }
13745         catch ( final NullPointerException f ) {
13746             f.printStackTrace( System.out );
13747             return false;
13748         }
13749         catch ( final Exception e ) {
13750             return false;
13751         }
13752         return true;
13753     }
13754
13755     private static boolean testUniprotTaxonomySearch() {
13756         try {
13757             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
13758                                                                                                  10 );
13759             if ( results.size() != 1 ) {
13760                 return false;
13761             }
13762             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13763                 return false;
13764             }
13765             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13766                 return false;
13767             }
13768             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13769                 return false;
13770             }
13771             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13772                 return false;
13773             }
13774             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13775                 return false;
13776             }
13777             results = null;
13778             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
13779             if ( results.size() != 1 ) {
13780                 return false;
13781             }
13782             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13783                 return false;
13784             }
13785             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13786                 return false;
13787             }
13788             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13789                 return false;
13790             }
13791             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13792                 return false;
13793             }
13794             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13795                 return false;
13796             }
13797             results = null;
13798             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
13799             if ( results.size() != 1 ) {
13800                 return false;
13801             }
13802             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13803                 return false;
13804             }
13805             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13806                 return false;
13807             }
13808             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13809                 return false;
13810             }
13811             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13812                 return false;
13813             }
13814             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13815                 return false;
13816             }
13817             results = null;
13818             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
13819             if ( results.size() != 1 ) {
13820                 return false;
13821             }
13822             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13823                 return false;
13824             }
13825             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13826                 return false;
13827             }
13828             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13829                 return false;
13830             }
13831             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13832                 return false;
13833             }
13834             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13835                 return false;
13836             }
13837             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
13838                 return false;
13839             }
13840             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
13841                 return false;
13842             }
13843             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13844                     .equals( "Nematostella vectensis" ) ) {
13845                 System.out.println( results.get( 0 ).getLineage() );
13846                 return false;
13847             }
13848             //
13849             results = null;
13850             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
13851             if ( results.size() != 1 ) {
13852                 return false;
13853             }
13854             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13855                 return false;
13856             }
13857             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13858                 return false;
13859             }
13860             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13861                 return false;
13862             }
13863             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13864                 return false;
13865             }
13866             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13867                 return false;
13868             }
13869             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13870                     .equals( "Xenopus tropicalis" ) ) {
13871                 System.out.println( results.get( 0 ).getLineage() );
13872                 return false;
13873             }
13874             //
13875             results = null;
13876             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
13877             if ( results.size() != 1 ) {
13878                 return false;
13879             }
13880             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13881                 return false;
13882             }
13883             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13884                 return false;
13885             }
13886             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13887                 return false;
13888             }
13889             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13890                 return false;
13891             }
13892             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13893                 return false;
13894             }
13895             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13896                     .equals( "Xenopus tropicalis" ) ) {
13897                 System.out.println( results.get( 0 ).getLineage() );
13898                 return false;
13899             }
13900             //
13901             results = null;
13902             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
13903             if ( results.size() != 1 ) {
13904                 return false;
13905             }
13906             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13907                 return false;
13908             }
13909             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13910                 return false;
13911             }
13912             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13913                 return false;
13914             }
13915             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13916                 return false;
13917             }
13918             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13919                 return false;
13920             }
13921             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13922                     .equals( "Xenopus tropicalis" ) ) {
13923                 System.out.println( results.get( 0 ).getLineage() );
13924                 return false;
13925             }
13926         }
13927         catch ( final IOException e ) {
13928             System.out.println();
13929             System.out.println( "the following might be due to absence internet connection:" );
13930             e.printStackTrace( System.out );
13931             return true;
13932         }
13933         catch ( final Exception e ) {
13934             return false;
13935         }
13936         return true;
13937     }
13938 }