de674db48f5c3292210215289f6fcdd808eee90c
[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.development.DevelopmentTools;
48 import org.forester.evoinference.TestPhylogenyReconstruction;
49 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
50 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
51 import org.forester.go.TestGo;
52 import org.forester.io.parsers.FastaParser;
53 import org.forester.io.parsers.GeneralMsaParser;
54 import org.forester.io.parsers.HmmscanPerDomainTableParser;
55 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
56 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
57 import org.forester.io.parsers.nexus.NexusCharactersParser;
58 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
59 import org.forester.io.parsers.nhx.NHXParser;
60 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
61 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
62 import org.forester.io.parsers.tol.TolParser;
63 import org.forester.io.parsers.util.ParserUtils;
64 import org.forester.io.writers.PhylogenyWriter;
65 import org.forester.io.writers.SequenceWriter;
66 import org.forester.msa.BasicMsa;
67 import org.forester.msa.DeleteableMsa;
68 import org.forester.msa.Mafft;
69 import org.forester.msa.Msa;
70 import org.forester.msa.Msa.MSA_FORMAT;
71 import org.forester.msa.MsaInferrer;
72 import org.forester.msa.MsaMethods;
73 import org.forester.pccx.TestPccx;
74 import org.forester.phylogeny.Phylogeny;
75 import org.forester.phylogeny.PhylogenyBranch;
76 import org.forester.phylogeny.PhylogenyMethods;
77 import org.forester.phylogeny.PhylogenyNode;
78 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
79 import org.forester.phylogeny.data.Accession;
80 import org.forester.phylogeny.data.Accession.Source;
81 import org.forester.phylogeny.data.BinaryCharacters;
82 import org.forester.phylogeny.data.BranchWidth;
83 import org.forester.phylogeny.data.Confidence;
84 import org.forester.phylogeny.data.Distribution;
85 import org.forester.phylogeny.data.DomainArchitecture;
86 import org.forester.phylogeny.data.Event;
87 import org.forester.phylogeny.data.Identifier;
88 import org.forester.phylogeny.data.PhylogenyData;
89 import org.forester.phylogeny.data.PhylogenyDataUtil;
90 import org.forester.phylogeny.data.Polygon;
91 import org.forester.phylogeny.data.PropertiesList;
92 import org.forester.phylogeny.data.Property;
93 import org.forester.phylogeny.data.Property.AppliesTo;
94 import org.forester.phylogeny.data.ProteinDomain;
95 import org.forester.phylogeny.data.Taxonomy;
96 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
97 import org.forester.phylogeny.factories.PhylogenyFactory;
98 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
99 import org.forester.protein.BasicDomain;
100 import org.forester.protein.BasicProtein;
101 import org.forester.protein.Domain;
102 import org.forester.protein.Protein;
103 import org.forester.protein.ProteinId;
104 import org.forester.rio.TestRIO;
105 import org.forester.sdi.SDI;
106 import org.forester.sdi.SDIR;
107 import org.forester.sdi.TestGSDI;
108 import org.forester.sequence.BasicSequence;
109 import org.forester.sequence.MolecularSequence;
110 import org.forester.species.BasicSpecies;
111 import org.forester.species.Species;
112 import org.forester.surfacing.TestSurfacing;
113 import org.forester.tools.ConfidenceAssessor;
114 import org.forester.tools.SupportCount;
115 import org.forester.tools.TreeSplitMatrix;
116 import org.forester.util.AsciiHistogram;
117 import org.forester.util.BasicDescriptiveStatistics;
118 import org.forester.util.BasicTable;
119 import org.forester.util.BasicTableParser;
120 import org.forester.util.DescriptiveStatistics;
121 import org.forester.util.ForesterConstants;
122 import org.forester.util.ForesterUtil;
123 import org.forester.util.GeneralTable;
124 import org.forester.util.SequenceAccessionTools;
125 import org.forester.ws.seqdb.SequenceDatabaseEntry;
126 import org.forester.ws.seqdb.SequenceDbWsTools;
127 import org.forester.ws.seqdb.UniProtTaxonomy;
128
129 @SuppressWarnings( "unused")
130 public final class Test {
131
132     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
133             + ForesterUtil.getFileSeparator() + "resources" + ForesterUtil.getFileSeparator();
134     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
135             + ForesterUtil.getFileSeparator() + "test_data" + ForesterUtil.getFileSeparator();
136     private final static boolean PERFORM_DB_TESTS          = false;
137     private static final boolean PERFORM_WEB_TREE_ACCESS   = false;
138     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
139             + ForesterConstants.PHYLO_XML_VERSION + "/" + ForesterConstants.PHYLO_XML_XSD;
140     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
141             + ForesterConstants.PHYLO_XML_VERSION + "/" + ForesterConstants.PHYLO_XML_XSD;
142     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
143     private final static double  ZERO_DIFF                 = 1.0E-9;
144
145     private static boolean isEqual( final double a, final double b ) {
146         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
147     }
148
149     public static void main( final String[] args ) {
150         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
151         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
152                 + "]" );
153         Locale.setDefault( Locale.US );
154         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
155         int failed = 0;
156         int succeeded = 0;
157         System.out.print( "[Test if directory with files for testing exists/is readable: " );
158         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
159             System.out.println( "OK.]" );
160         }
161         else {
162             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
163             System.out.println( "Testing aborted." );
164             System.exit( -1 );
165         }
166         System.out.print( "[Test if resources directory exists/is readable: " );
167         if ( testDir( PATH_TO_RESOURCES ) ) {
168             System.out.println( "OK.]" );
169         }
170         else {
171             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
172             System.out.println( "Testing aborted." );
173             System.exit( -1 );
174         }
175         final long start_time = new Date().getTime();
176         System.out.print( "Basic node methods: " );
177         if ( Test.testBasicNodeMethods() ) {
178             System.out.println( "OK." );
179             succeeded++;
180         }
181         else {
182             System.out.println( "failed." );
183             failed++;
184         }
185         System.out.print( "Protein id: " );
186         if ( !testProteinId() ) {
187             System.out.println( "failed." );
188             failed++;
189         }
190         else {
191             succeeded++;
192         }
193         System.out.println( "OK." );
194         System.out.print( "Species: " );
195         if ( !testSpecies() ) {
196             System.out.println( "failed." );
197             failed++;
198         }
199         else {
200             succeeded++;
201         }
202         System.out.println( "OK." );
203         System.out.print( "Basic domain: " );
204         if ( !testBasicDomain() ) {
205             System.out.println( "failed." );
206             failed++;
207         }
208         else {
209             succeeded++;
210         }
211         System.out.println( "OK." );
212         System.out.print( "Basic protein: " );
213         if ( !testBasicProtein() ) {
214             System.out.println( "failed." );
215             failed++;
216         }
217         else {
218             succeeded++;
219         }
220         System.out.println( "OK." );
221         System.out.print( "Sequence writer: " );
222         if ( testSequenceWriter() ) {
223             System.out.println( "OK." );
224             succeeded++;
225         }
226         else {
227             System.out.println( "failed." );
228             failed++;
229         }
230         System.out.print( "Sequence id parsing: " );
231         if ( testSequenceIdParsing() ) {
232             System.out.println( "OK." );
233             succeeded++;
234         }
235         else {
236             System.out.println( "failed." );
237             failed++;
238         }
239         System.out.print( "UniProtKB id extraction: " );
240         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
241             System.out.println( "OK." );
242             succeeded++;
243         }
244         else {
245             System.out.println( "failed." );
246             failed++;
247         }
248         System.out.print( "Sequence DB tools 1: " );
249         if ( testSequenceDbWsTools1() ) {
250             System.out.println( "OK." );
251             succeeded++;
252         }
253         else {
254             System.out.println( "failed." );
255             failed++;
256         }
257         System.out.print( "Hmmscan output parser: " );
258         if ( testHmmscanOutputParser() ) {
259             System.out.println( "OK." );
260             succeeded++;
261         }
262         else {
263             System.out.println( "failed." );
264             failed++;
265         }
266         System.out.print( "Overlap removal: " );
267         if ( !org.forester.test.Test.testOverlapRemoval() ) {
268             System.out.println( "failed." );
269             failed++;
270         }
271         else {
272             succeeded++;
273         }
274         System.out.println( "OK." );
275         System.out.print( "Engulfing overlap removal: " );
276         if ( !Test.testEngulfingOverlapRemoval() ) {
277             System.out.println( "failed." );
278             failed++;
279         }
280         else {
281             succeeded++;
282         }
283         System.out.println( "OK." );
284         System.out.print( "Taxonomy data extraction: " );
285         if ( Test.testExtractTaxonomyDataFromNodeName() ) {
286             System.out.println( "OK." );
287             succeeded++;
288         }
289         else {
290             System.out.println( "failed." );
291             failed++;
292         }
293         System.out.print( "Taxonomy code extraction: " );
294         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
295             System.out.println( "OK." );
296             succeeded++;
297         }
298         else {
299             System.out.println( "failed." );
300             failed++;
301         }
302         System.out.print( "SN extraction: " );
303         if ( Test.testExtractSNFromNodeName() ) {
304             System.out.println( "OK." );
305             succeeded++;
306         }
307         else {
308             System.out.println( "failed." );
309             failed++;
310         }
311         System.out.print( "Taxonomy extraction (general): " );
312         if ( Test.testTaxonomyExtraction() ) {
313             System.out.println( "OK." );
314             succeeded++;
315         }
316         else {
317             System.out.println( "failed." );
318             failed++;
319         }
320         System.out.print( "Uri for Aptx web sequence accession: " );
321         if ( Test.testCreateUriForSeqWeb() ) {
322             System.out.println( "OK." );
323             succeeded++;
324         }
325         else {
326             System.out.println( "failed." );
327             failed++;
328         }
329         System.out.print( "Basic node construction and parsing of NHX (node level): " );
330         if ( Test.testNHXNodeParsing() ) {
331             System.out.println( "OK." );
332             succeeded++;
333         }
334         else {
335             System.out.println( "failed." );
336             failed++;
337         }
338         System.out.print( "Node construction and parsing of NHX (node level): " );
339         if ( Test.testNHXNodeParsing2() ) {
340             System.out.println( "OK." );
341             succeeded++;
342         }
343         else {
344             System.out.println( "failed." );
345             failed++;
346         }
347         System.out.print( "NHX parsing iterating: " );
348         if ( Test.testNHParsingIter() ) {
349             System.out.println( "OK." );
350             succeeded++;
351         }
352         else {
353             System.out.println( "failed." );
354             failed++;
355         }
356         System.out.print( "NH parsing: " );
357         if ( Test.testNHParsing() ) {
358             System.out.println( "OK." );
359             succeeded++;
360         }
361         else {
362             System.out.println( "failed." );
363             failed++;
364         }
365         System.out.print( "NH parsing - special chars: " );
366         if ( Test.testNHParsingSpecialChars() ) {
367             System.out.println( "OK." );
368             succeeded++;
369         }
370         else {
371             System.out.println( "failed." );
372             failed++;
373         }
374         System.out.print( "Conversion to NHX (node level): " );
375         if ( Test.testNHXconversion() ) {
376             System.out.println( "OK." );
377             succeeded++;
378         }
379         else {
380             System.out.println( "failed." );
381             failed++;
382         }
383         System.out.print( "NHX parsing: " );
384         if ( Test.testNHXParsing() ) {
385             System.out.println( "OK." );
386             succeeded++;
387         }
388         else {
389             System.out.println( "failed." );
390             failed++;
391         }
392         System.out.print( "NHX parsing with quotes: " );
393         if ( Test.testNHXParsingQuotes() ) {
394             System.out.println( "OK." );
395             succeeded++;
396         }
397         else {
398             System.out.println( "failed." );
399             failed++;
400         }
401         System.out.print( "NHX parsing (MrBayes): " );
402         if ( Test.testNHXParsingMB() ) {
403             System.out.println( "OK." );
404             succeeded++;
405         }
406         else {
407             System.out.println( "failed." );
408             failed++;
409         }
410         System.out.print( "Nexus characters parsing: " );
411         if ( Test.testNexusCharactersParsing() ) {
412             System.out.println( "OK." );
413             succeeded++;
414         }
415         else {
416             System.out.println( "failed." );
417             failed++;
418         }
419         System.out.print( "Nexus tree parsing iterating: " );
420         if ( Test.testNexusTreeParsingIterating() ) {
421             System.out.println( "OK." );
422             succeeded++;
423         }
424         else {
425             System.out.println( "failed." );
426             failed++;
427         }
428         System.out.print( "Nexus tree parsing: " );
429         if ( Test.testNexusTreeParsing() ) {
430             System.out.println( "OK." );
431             succeeded++;
432         }
433         else {
434             System.out.println( "failed." );
435             failed++;
436         }
437         System.out.print( "Nexus tree parsing (translating): " );
438         if ( Test.testNexusTreeParsingTranslating() ) {
439             System.out.println( "OK." );
440             succeeded++;
441         }
442         else {
443             System.out.println( "failed." );
444             failed++;
445         }
446         System.out.print( "Nexus matrix parsing: " );
447         if ( Test.testNexusMatrixParsing() ) {
448             System.out.println( "OK." );
449             succeeded++;
450         }
451         else {
452             System.out.println( "failed." );
453             failed++;
454         }
455         System.out.print( "Basic phyloXML parsing: " );
456         if ( Test.testBasicPhyloXMLparsing() ) {
457             System.out.println( "OK." );
458             succeeded++;
459         }
460         else {
461             System.out.println( "failed." );
462             failed++;
463         }
464         System.out.print( "Basic phyloXML parsing (validating against schema): " );
465         if ( testBasicPhyloXMLparsingValidating() ) {
466             System.out.println( "OK." );
467             succeeded++;
468         }
469         else {
470             System.out.println( "failed." );
471             failed++;
472         }
473         System.out.print( "phyloXML parsing (validating against schema): " );
474         if ( testPhyloXMLparsingValidating() ) {
475             System.out.println( "OK." );
476             succeeded++;
477         }
478         else {
479             System.out.println( "failed." );
480             failed++;
481         }
482         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
483         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
484             System.out.println( "OK." );
485             succeeded++;
486         }
487         else {
488             System.out.println( "failed." );
489             failed++;
490         }
491         System.out.print( "phyloXML Distribution Element: " );
492         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
493             System.out.println( "OK." );
494             succeeded++;
495         }
496         else {
497             System.out.println( "failed." );
498             failed++;
499         }
500         System.out.print( "Tol XML parsing: " );
501         if ( Test.testBasicTolXMLparsing() ) {
502             System.out.println( "OK." );
503             succeeded++;
504         }
505         else {
506             System.out.println( "failed." );
507             failed++;
508         }
509         System.out.print( "UTF-8 parsing from file: " );
510         if ( Test.testUTF8ParsingFromFile() ) {
511             System.out.println( "OK." );
512             succeeded++;
513         }
514         else {
515             System.out.println( "failed." );
516             failed++;
517         }
518         System.out.print( "Copying of node data: " );
519         if ( Test.testCopyOfNodeData() ) {
520             System.out.println( "OK." );
521             succeeded++;
522         }
523         else {
524             System.out.println( "failed." );
525             failed++;
526         }
527         System.out.print( "Tree copy: " );
528         if ( Test.testTreeCopy() ) {
529             System.out.println( "OK." );
530             succeeded++;
531         }
532         else {
533             System.out.println( "failed." );
534             failed++;
535         }
536         System.out.print( "Basic tree methods: " );
537         if ( Test.testBasicTreeMethods() ) {
538             System.out.println( "OK." );
539             succeeded++;
540         }
541         else {
542             System.out.println( "failed." );
543             failed++;
544         }
545         System.out.print( "Tree methods: " );
546         if ( Test.testTreeMethods() ) {
547             System.out.println( "OK." );
548             succeeded++;
549         }
550         else {
551             System.out.println( "failed." );
552             failed++;
553         }
554         System.out.print( "Postorder Iterator: " );
555         if ( Test.testPostOrderIterator() ) {
556             System.out.println( "OK." );
557             succeeded++;
558         }
559         else {
560             System.out.println( "failed." );
561             failed++;
562         }
563         System.out.print( "Preorder Iterator: " );
564         if ( Test.testPreOrderIterator() ) {
565             System.out.println( "OK." );
566             succeeded++;
567         }
568         else {
569             System.out.println( "failed." );
570             failed++;
571         }
572         System.out.print( "Levelorder Iterator: " );
573         if ( Test.testLevelOrderIterator() ) {
574             System.out.println( "OK." );
575             succeeded++;
576         }
577         else {
578             System.out.println( "failed." );
579             failed++;
580         }
581         System.out.print( "Re-id methods: " );
582         if ( Test.testReIdMethods() ) {
583             System.out.println( "OK." );
584             succeeded++;
585         }
586         else {
587             System.out.println( "failed." );
588             failed++;
589         }
590         System.out.print( "Methods on last external nodes: " );
591         if ( Test.testLastExternalNodeMethods() ) {
592             System.out.println( "OK." );
593             succeeded++;
594         }
595         else {
596             System.out.println( "failed." );
597             failed++;
598         }
599         System.out.print( "Methods on external nodes: " );
600         if ( Test.testExternalNodeRelatedMethods() ) {
601             System.out.println( "OK." );
602             succeeded++;
603         }
604         else {
605             System.out.println( "failed." );
606             failed++;
607         }
608         System.out.print( "Deletion of external nodes: " );
609         if ( Test.testDeletionOfExternalNodes() ) {
610             System.out.println( "OK." );
611             succeeded++;
612         }
613         else {
614             System.out.println( "failed." );
615             failed++;
616         }
617         System.out.print( "Subtree deletion: " );
618         if ( Test.testSubtreeDeletion() ) {
619             System.out.println( "OK." );
620             succeeded++;
621         }
622         else {
623             System.out.println( "failed." );
624             failed++;
625         }
626         System.out.print( "Phylogeny branch: " );
627         if ( Test.testPhylogenyBranch() ) {
628             System.out.println( "OK." );
629             succeeded++;
630         }
631         else {
632             System.out.println( "failed." );
633             failed++;
634         }
635         System.out.print( "Rerooting: " );
636         if ( Test.testRerooting() ) {
637             System.out.println( "OK." );
638             succeeded++;
639         }
640         else {
641             System.out.println( "failed." );
642             failed++;
643         }
644         System.out.print( "Mipoint rooting: " );
645         if ( Test.testMidpointrooting() ) {
646             System.out.println( "OK." );
647             succeeded++;
648         }
649         else {
650             System.out.println( "failed." );
651             failed++;
652         }
653         System.out.print( "Node removal: " );
654         if ( Test.testNodeRemoval() ) {
655             System.out.println( "OK." );
656             succeeded++;
657         }
658         else {
659             System.out.println( "failed." );
660             failed++;
661         }
662         System.out.print( "Support count: " );
663         if ( Test.testSupportCount() ) {
664             System.out.println( "OK." );
665             succeeded++;
666         }
667         else {
668             System.out.println( "failed." );
669             failed++;
670         }
671         System.out.print( "Support transfer: " );
672         if ( Test.testSupportTransfer() ) {
673             System.out.println( "OK." );
674             succeeded++;
675         }
676         else {
677             System.out.println( "failed." );
678             failed++;
679         }
680         System.out.print( "Finding of LCA: " );
681         if ( Test.testGetLCA() ) {
682             System.out.println( "OK." );
683             succeeded++;
684         }
685         else {
686             System.out.println( "failed." );
687             failed++;
688         }
689         System.out.print( "Finding of LCA 2: " );
690         if ( Test.testGetLCA2() ) {
691             System.out.println( "OK." );
692             succeeded++;
693         }
694         else {
695             System.out.println( "failed." );
696             failed++;
697         }
698         System.out.print( "Calculation of distance between nodes: " );
699         if ( Test.testGetDistance() ) {
700             System.out.println( "OK." );
701             succeeded++;
702         }
703         else {
704             System.out.println( "failed." );
705             failed++;
706         }
707         System.out.print( "Descriptive statistics: " );
708         if ( Test.testDescriptiveStatistics() ) {
709             System.out.println( "OK." );
710             succeeded++;
711         }
712         else {
713             System.out.println( "failed." );
714             failed++;
715         }
716         System.out.print( "Data objects and methods: " );
717         if ( Test.testDataObjects() ) {
718             System.out.println( "OK." );
719             succeeded++;
720         }
721         else {
722             System.out.println( "failed." );
723             failed++;
724         }
725         System.out.print( "Properties map: " );
726         if ( Test.testPropertiesMap() ) {
727             System.out.println( "OK." );
728             succeeded++;
729         }
730         else {
731             System.out.println( "failed." );
732             failed++;
733         }
734         System.out.print( "SDIse: " );
735         if ( Test.testSDIse() ) {
736             System.out.println( "OK." );
737             succeeded++;
738         }
739         else {
740             System.out.println( "failed." );
741             failed++;
742         }
743         System.out.print( "SDIunrooted: " );
744         if ( Test.testSDIunrooted() ) {
745             System.out.println( "OK." );
746             succeeded++;
747         }
748         else {
749             System.out.println( "failed." );
750             failed++;
751         }
752         System.out.print( "GSDI: " );
753         if ( TestGSDI.test() ) {
754             System.out.println( "OK." );
755             succeeded++;
756         }
757         else {
758             System.out.println( "failed." );
759             failed++;
760         }
761         System.out.print( "RIO: " );
762         if ( TestRIO.test() ) {
763             System.out.println( "OK." );
764             succeeded++;
765         }
766         else {
767             System.out.println( "failed." );
768             failed++;
769         }
770         System.out.print( "Phylogeny reconstruction:" );
771         System.out.println();
772         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
773             System.out.println( "OK." );
774             succeeded++;
775         }
776         else {
777             System.out.println( "failed." );
778             failed++;
779         }
780         System.out.print( "Analysis of domain architectures: " );
781         System.out.println();
782         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
783             System.out.println( "OK." );
784             succeeded++;
785         }
786         else {
787             System.out.println( "failed." );
788             failed++;
789         }
790         System.out.print( "GO: " );
791         System.out.println();
792         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
793             System.out.println( "OK." );
794             succeeded++;
795         }
796         else {
797             System.out.println( "failed." );
798             failed++;
799         }
800         System.out.print( "Modeling tools: " );
801         if ( TestPccx.test() ) {
802             System.out.println( "OK." );
803             succeeded++;
804         }
805         else {
806             System.out.println( "failed." );
807             failed++;
808         }
809         System.out.print( "Split Matrix strict: " );
810         if ( Test.testSplitStrict() ) {
811             System.out.println( "OK." );
812             succeeded++;
813         }
814         else {
815             System.out.println( "failed." );
816             failed++;
817         }
818         System.out.print( "Split Matrix: " );
819         if ( Test.testSplit() ) {
820             System.out.println( "OK." );
821             succeeded++;
822         }
823         else {
824             System.out.println( "failed." );
825             failed++;
826         }
827         System.out.print( "Confidence Assessor: " );
828         if ( Test.testConfidenceAssessor() ) {
829             System.out.println( "OK." );
830             succeeded++;
831         }
832         else {
833             System.out.println( "failed." );
834             failed++;
835         }
836         System.out.print( "Basic table: " );
837         if ( Test.testBasicTable() ) {
838             System.out.println( "OK." );
839             succeeded++;
840         }
841         else {
842             System.out.println( "failed." );
843             failed++;
844         }
845         System.out.print( "General table: " );
846         if ( Test.testGeneralTable() ) {
847             System.out.println( "OK." );
848             succeeded++;
849         }
850         else {
851             System.out.println( "failed." );
852             failed++;
853         }
854         System.out.print( "Amino acid sequence: " );
855         if ( Test.testAminoAcidSequence() ) {
856             System.out.println( "OK." );
857             succeeded++;
858         }
859         else {
860             System.out.println( "failed." );
861             failed++;
862         }
863         System.out.print( "General MSA parser: " );
864         if ( Test.testGeneralMsaParser() ) {
865             System.out.println( "OK." );
866             succeeded++;
867         }
868         else {
869             System.out.println( "failed." );
870             failed++;
871         }
872         System.out.print( "Fasta parser for msa: " );
873         if ( Test.testFastaParser() ) {
874             System.out.println( "OK." );
875             succeeded++;
876         }
877         else {
878             System.out.println( "failed." );
879             failed++;
880         }
881         System.out.print( "Creation of balanced phylogeny: " );
882         if ( Test.testCreateBalancedPhylogeny() ) {
883             System.out.println( "OK." );
884             succeeded++;
885         }
886         else {
887             System.out.println( "failed." );
888             failed++;
889         }
890         System.out.print( "Genbank accessor parsing: " );
891         if ( Test.testGenbankAccessorParsing() ) {
892             System.out.println( "OK." );
893             succeeded++;
894         }
895         else {
896             System.out.println( "failed." );
897             failed++;
898         }
899         String path = "";
900         final String os = ForesterUtil.OS_NAME.toLowerCase();
901         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
902             path = "/usr/local/bin/mafft";
903         }
904         else if ( os.indexOf( "win" ) >= 0 ) {
905             path = "C:\\Program Files\\mafft-win\\mafft.bat";
906         }
907         else {
908             path = "mafft";
909             if ( !MsaInferrer.isInstalled( path ) ) {
910                 path = "/usr/bin/mafft";
911             }
912             if ( !MsaInferrer.isInstalled( path ) ) {
913                 path = "/usr/local/bin/mafft";
914             }
915         }
916         if ( MsaInferrer.isInstalled( path ) ) {
917             System.out.print( "MAFFT (external program): " );
918             if ( Test.testMafft( path ) ) {
919                 System.out.println( "OK." );
920                 succeeded++;
921             }
922             else {
923                 System.out.println( "failed [will not count towards failed tests]" );
924             }
925         }
926         System.out.print( "Next nodes with collapsed: " );
927         if ( Test.testNextNodeWithCollapsing() ) {
928             System.out.println( "OK." );
929             succeeded++;
930         }
931         else {
932             System.out.println( "failed." );
933             failed++;
934         }
935         System.out.print( "Simple MSA quality: " );
936         if ( Test.testMsaQualityMethod() ) {
937             System.out.println( "OK." );
938             succeeded++;
939         }
940         else {
941             System.out.println( "failed." );
942             failed++;
943         }
944         System.out.print( "Deleteable MSA: " );
945         if ( Test.testDeleteableMsa() ) {
946             System.out.println( "OK." );
947             succeeded++;
948         }
949         else {
950             System.out.println( "failed." );
951             failed++;
952         }
953         System.out.print( "MSA entropy: " );
954         if ( Test.testMsaEntropy() ) {
955             System.out.println( "OK." );
956             succeeded++;
957         }
958         else {
959             System.out.println( "failed." );
960             failed++;
961         }
962         if ( PERFORM_DB_TESTS ) {
963             System.out.print( "Uniprot Entry Retrieval: " );
964             if ( Test.testUniprotEntryRetrieval() ) {
965                 System.out.println( "OK." );
966                 succeeded++;
967             }
968             else {
969                 System.out.println( "failed." );
970                 failed++;
971             }
972             System.out.print( "Ebi Entry Retrieval: " );
973             if ( Test.testEbiEntryRetrieval() ) {
974                 System.out.println( "OK." );
975                 succeeded++;
976             }
977             else {
978                 System.out.println( "failed." );
979                 failed++;
980             }
981             System.out.print( "Sequence DB tools 2: " );
982             if ( testSequenceDbWsTools2() ) {
983                 System.out.println( "OK." );
984                 succeeded++;
985             }
986             else {
987                 System.out.println( "failed." );
988                 failed++;
989                 System.exit( -1 );
990             }
991             System.out.print( "Uniprot Taxonomy Search: " );
992             if ( Test.testUniprotTaxonomySearch() ) {
993                 System.out.println( "OK." );
994                 succeeded++;
995             }
996             else {
997                 System.out.println( "failed." );
998                 failed++;
999             }
1000         }
1001         if ( PERFORM_WEB_TREE_ACCESS ) {
1002             System.out.print( "TreeBase acccess: " );
1003             if ( Test.testTreeBaseReading() ) {
1004                 System.out.println( "OK." );
1005                 succeeded++;
1006             }
1007             else {
1008                 System.out.println( "failed." );
1009                 failed++;
1010             }
1011             System.out.print( "ToL access: " );
1012             if ( Test.testToLReading() ) {
1013                 System.out.println( "OK." );
1014                 succeeded++;
1015             }
1016             else {
1017                 System.out.println( "failed." );
1018                 failed++;
1019             }
1020             System.out.print( "NHX parsing from URL: " );
1021             if ( Test.testNHXparsingFromURL() ) {
1022                 System.out.println( "OK." );
1023                 succeeded++;
1024             }
1025             else {
1026                 System.out.println( "failed." );
1027                 failed++;
1028             }
1029             System.out.print( "NHX parsing from URL 2: " );
1030             if ( Test.testNHXparsingFromURL2() ) {
1031                 System.out.println( "OK." );
1032                 succeeded++;
1033             }
1034             else {
1035                 System.out.println( "failed." );
1036                 failed++;
1037             }
1038             System.out.print( "phyloXML parsing from URL: " );
1039             if ( Test.testPhyloXMLparsingFromURL() ) {
1040                 System.out.println( "OK." );
1041                 succeeded++;
1042             }
1043             else {
1044                 System.out.println( "failed." );
1045                 failed++;
1046             }
1047             System.out.print( "TreeFam access: " );
1048             if ( Test.testTreeFamReading() ) {
1049                 System.out.println( "OK." );
1050                 succeeded++;
1051             }
1052             else {
1053                 System.out.println( "failed." );
1054                 failed++;
1055             }
1056             System.out.print( "Pfam tree access: " );
1057             if ( Test.testPfamTreeReading() ) {
1058                 System.out.println( "OK." );
1059                 succeeded++;
1060             }
1061             else {
1062                 System.out.println( "failed." );
1063                 failed++;
1064             }
1065         }
1066         System.out.println();
1067         final Runtime rt = java.lang.Runtime.getRuntime();
1068         final long free_memory = rt.freeMemory() / 1000000;
1069         final long total_memory = rt.totalMemory() / 1000000;
1070         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1071                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1072         System.out.println();
1073         System.out.println( "Successful tests: " + succeeded );
1074         System.out.println( "Failed     tests: " + failed );
1075         System.out.println();
1076         if ( failed < 1 ) {
1077             System.out.println( "OK." );
1078         }
1079         else {
1080             System.out.println( "Not OK." );
1081         }
1082     }
1083
1084     private static boolean testEngulfingOverlapRemoval() {
1085         try {
1086             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1087             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1088             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1089             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1090             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1091             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1092             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1093             final List<Boolean> covered = new ArrayList<Boolean>();
1094             covered.add( true ); // 0
1095             covered.add( false ); // 1
1096             covered.add( true ); // 2
1097             covered.add( false ); // 3
1098             covered.add( true ); // 4
1099             covered.add( true ); // 5
1100             covered.add( false ); // 6
1101             covered.add( true ); // 7
1102             covered.add( true ); // 8
1103             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1104                 return false;
1105             }
1106             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1107                 return false;
1108             }
1109             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1110                 return false;
1111             }
1112             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1113                 return false;
1114             }
1115             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1116                 return false;
1117             }
1118             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1119                 return false;
1120             }
1121             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1122                 return false;
1123             }
1124             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1125             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1126             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1127             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1128             abc.addProteinDomain( a );
1129             abc.addProteinDomain( b );
1130             abc.addProteinDomain( c );
1131             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1132             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1133             if ( abc.getNumberOfProteinDomains() != 3 ) {
1134                 return false;
1135             }
1136             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1137                 return false;
1138             }
1139             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1140                 return false;
1141             }
1142             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1143                 return false;
1144             }
1145             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1146                 return false;
1147             }
1148             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1149             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1150             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1151             final Protein def = new BasicProtein( "def", "nemve", 0 );
1152             def.addProteinDomain( d );
1153             def.addProteinDomain( e );
1154             def.addProteinDomain( f );
1155             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1156             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1157             if ( def.getNumberOfProteinDomains() != 3 ) {
1158                 return false;
1159             }
1160             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1161                 return false;
1162             }
1163             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1164                 return false;
1165             }
1166             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1167                 return false;
1168             }
1169             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1170                 return false;
1171             }
1172             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1173                 return false;
1174             }
1175         }
1176         catch ( final Exception e ) {
1177             e.printStackTrace( System.out );
1178             return false;
1179         }
1180         return true;
1181     }
1182
1183     private static final boolean testNHXparsingFromURL2() {
1184         try {
1185             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1186             final Phylogeny phys[] = AptxUtil
1187                     .readPhylogeniesFromUrl( new URL( s ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1188             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1189                 return false;
1190             }
1191             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1192                 System.out.println( phys[ 0 ].toNewHampshire() );
1193                 return false;
1194             }
1195             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1196                 System.out.println( phys[ 1 ].toNewHampshire() );
1197                 return false;
1198             }
1199             final Phylogeny phys2[] = AptxUtil
1200                     .readPhylogeniesFromUrl( new URL( s ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1201             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1202                 return false;
1203             }
1204             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1205                 System.out.println( phys2[ 0 ].toNewHampshire() );
1206                 return false;
1207             }
1208             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1209                 System.out.println( phys2[ 1 ].toNewHampshire() );
1210                 return false;
1211             }
1212             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1213                     + "SwissTree/ST001/consensus_tree.nhx" ),
1214                                                                        false,
1215                                                                        false,
1216                                                                        false,
1217                                                                        TAXONOMY_EXTRACTION.NO,
1218                                                                        false );
1219             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1220                 return false;
1221             }
1222             if ( !phys3[ 0 ].toNewHampshire()
1223                     .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))))));" ) ) {
1224                 System.out.println( phys3[ 0 ].toNewHampshire() );
1225                 return false;
1226             }
1227             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1228                     + "SwissTree/ST001/consensus_tree.nhx" ),
1229                                                                        false,
1230                                                                        false,
1231                                                                        false,
1232                                                                        TAXONOMY_EXTRACTION.NO,
1233                                                                        false );
1234             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1235                 return false;
1236             }
1237             if ( !phys4[ 0 ].toNewHampshire()
1238                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1239                 System.out.println( phys4[ 0 ].toNewHampshire() );
1240                 return false;
1241             }
1242         }
1243         catch ( final Exception e ) {
1244             e.printStackTrace();
1245             return false;
1246         }
1247         return true;
1248     }
1249
1250     private static final boolean testNHXparsingFromURL() {
1251         try {
1252             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1253             final URL u = new URL( s );
1254             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1255             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1256             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1257                 return false;
1258             }
1259             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1260                 System.out.println( phys[ 0 ].toNewHampshire() );
1261                 return false;
1262             }
1263             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1264                 System.out.println( phys[ 1 ].toNewHampshire() );
1265                 return false;
1266             }
1267             final URL u2 = new URL( s );
1268             final Phylogeny[] phys2 = factory.create( u2.openStream(), new NHXParser() );
1269             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1270                 return false;
1271             }
1272             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1273                 System.out.println( phys2[ 0 ].toNewHampshire() );
1274                 return false;
1275             }
1276             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1277             final NHXParser p = new NHXParser();
1278             final URL u3 = new URL( s );
1279             p.setSource( u3 );
1280             if ( !p.hasNext() ) {
1281                 return false;
1282             }
1283             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1284                 return false;
1285             }
1286             if ( !p.hasNext() ) {
1287                 return false;
1288             }
1289             p.reset();
1290             if ( !p.hasNext() ) {
1291                 return false;
1292             }
1293             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1294                 return false;
1295             }
1296             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1297                 return false;
1298             }
1299             p.reset();
1300             if ( !p.hasNext() ) {
1301                 return false;
1302             }
1303             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1304                 return false;
1305             }
1306             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1307                 return false;
1308             }
1309         }
1310         catch ( final Exception e ) {
1311             System.out.println( e.toString() );
1312             e.printStackTrace();
1313             return false;
1314         }
1315         return true;
1316     }
1317
1318     private static boolean testOverlapRemoval() {
1319         try {
1320             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1321             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1322             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1323             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1324             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1325             final List<Boolean> covered = new ArrayList<Boolean>();
1326             covered.add( true ); // 0
1327             covered.add( false ); // 1
1328             covered.add( true ); // 2
1329             covered.add( false ); // 3
1330             covered.add( true ); // 4
1331             covered.add( true ); // 5
1332             covered.add( false ); // 6
1333             covered.add( true ); // 7
1334             covered.add( true ); // 8
1335             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1336                 return false;
1337             }
1338             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1339                 return false;
1340             }
1341             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1342                 return false;
1343             }
1344             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1345                 return false;
1346             }
1347             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1348                 return false;
1349             }
1350             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1351             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1352             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1353             ab.addProteinDomain( a );
1354             ab.addProteinDomain( b );
1355             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1356             if ( ab.getNumberOfProteinDomains() != 2 ) {
1357                 return false;
1358             }
1359             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1360                 return false;
1361             }
1362             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1363                 return false;
1364             }
1365             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1366             if ( ab.getNumberOfProteinDomains() != 2 ) {
1367                 return false;
1368             }
1369             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1370                 return false;
1371             }
1372             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1373             final Domain d = new BasicDomain( "d",
1374                                               ( short ) 10000,
1375                                               ( short ) 10500,
1376                                               ( short ) 1,
1377                                               ( short ) 1,
1378                                               0.0000001,
1379                                               1 );
1380             final Domain e = new BasicDomain( "e",
1381                                               ( short ) 5000,
1382                                               ( short ) 5500,
1383                                               ( short ) 1,
1384                                               ( short ) 1,
1385                                               0.0001,
1386                                               1 );
1387             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1388             cde.addProteinDomain( c );
1389             cde.addProteinDomain( d );
1390             cde.addProteinDomain( e );
1391             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1392             if ( cde.getNumberOfProteinDomains() != 3 ) {
1393                 return false;
1394             }
1395             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1396                 return false;
1397             }
1398             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1399             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1400             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1401             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1402             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1403             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1404             fghi.addProteinDomain( f );
1405             fghi.addProteinDomain( g );
1406             fghi.addProteinDomain( h );
1407             fghi.addProteinDomain( i );
1408             fghi.addProteinDomain( i );
1409             fghi.addProteinDomain( i );
1410             fghi.addProteinDomain( i2 );
1411             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1412             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1413                 return false;
1414             }
1415             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1416                 return false;
1417             }
1418             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1419                 return false;
1420             }
1421             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1422             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1423                 return false;
1424             }
1425             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1426                 return false;
1427             }
1428             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1429             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1430             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1431             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1432             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1433             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1434             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1435             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1436             jklm.addProteinDomain( j );
1437             jklm.addProteinDomain( k );
1438             jklm.addProteinDomain( l );
1439             jklm.addProteinDomain( m );
1440             jklm.addProteinDomain( m0 );
1441             jklm.addProteinDomain( m1 );
1442             jklm.addProteinDomain( m2 );
1443             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1444             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1445                 return false;
1446             }
1447             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1448                 return false;
1449             }
1450             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1451                 return false;
1452             }
1453             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1454             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1455                 return false;
1456             }
1457             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1458                 return false;
1459             }
1460             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1461             final Protein od = new BasicProtein( "od", "varanus", 0 );
1462             od.addProteinDomain( only );
1463             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1464             if ( od.getNumberOfProteinDomains() != 1 ) {
1465                 return false;
1466             }
1467             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1468                 return false;
1469             }
1470         }
1471         catch ( final Exception e ) {
1472             e.printStackTrace( System.out );
1473             return false;
1474         }
1475         return true;
1476     }
1477
1478     private static final boolean testPfamTreeReading() {
1479         try {
1480             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1481             final NHXParser parser = new NHXParser();
1482             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1483             parser.setReplaceUnderscores( false );
1484             parser.setGuessRootedness( true );
1485             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1486             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1487                 return false;
1488             }
1489             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1490                 return false;
1491             }
1492         }
1493         catch ( final Exception e ) {
1494             e.printStackTrace();
1495             return false;
1496         }
1497         return true;
1498     }
1499
1500     private static final boolean testPhyloXMLparsingFromURL() {
1501         try {
1502             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1503             final URL u = new URL( s );
1504             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1505             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1506                 return false;
1507             }
1508             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1509             if ( ( phys2 == null ) || ( phys2.length != 2 ) ) {
1510                 return false;
1511             }
1512         }
1513         catch ( final Exception e ) {
1514             e.printStackTrace();
1515             return false;
1516         }
1517         return true;
1518     }
1519
1520     private static final boolean testToLReading() {
1521         try {
1522             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1523             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, new TolParser() );
1524             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1525                 return false;
1526             }
1527             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1528                 return false;
1529             }
1530             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName()
1531                     .equals( "Protacanthopterygii" ) ) {
1532                 return false;
1533             }
1534             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1535                 return false;
1536             }
1537             //
1538             final URL u2 = new URL( WebserviceUtil.TOL_URL_BASE + "17706" );
1539             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, new TolParser() );
1540             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
1541                 return false;
1542             }
1543             if ( !phys2[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "17706" ) ) {
1544                 return false;
1545             }
1546             if ( phys2[ 0 ].getNumberOfExternalNodes() < 5 ) {
1547                 return false;
1548             }
1549         }
1550         catch ( final Exception e ) {
1551             e.printStackTrace();
1552             return false;
1553         }
1554         return true;
1555     }
1556
1557     private static final boolean testTreeBaseReading() {
1558         try {
1559             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "72557?format=nexus" );
1560             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1561             parser.setReplaceUnderscores( true );
1562             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1563             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1564                 return false;
1565             }
1566             final URL u_1 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2406?format=nexus" );
1567             final NexusPhylogeniesParser parser_1 = new NexusPhylogeniesParser();
1568             final Phylogeny[] phys_1 = ForesterUtil.readPhylogeniesFromUrl( u_1, parser_1 );
1569             if ( ( phys_1 == null ) || ( phys_1.length != 1 ) ) {
1570                 return false;
1571             }
1572             final URL u_2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "422?format=nexus" );
1573             final NexusPhylogeniesParser parser_2 = new NexusPhylogeniesParser();
1574             final Phylogeny[] phys_2 = ForesterUtil.readPhylogeniesFromUrl( u_2, parser_2 );
1575             if ( ( phys_2 == null ) || ( phys_2.length != 1 ) ) {
1576                 return false;
1577             }
1578             final URL u_3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2654?format=nexus" );
1579             final NexusPhylogeniesParser parser_3 = new NexusPhylogeniesParser();
1580             final Phylogeny[] phys_3 = ForesterUtil.readPhylogeniesFromUrl( u_3, parser_3 );
1581             if ( ( phys_3 == null ) || ( phys_3.length != 1 ) ) {
1582                 return false;
1583             }
1584             final URL u_4 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1585             final NexusPhylogeniesParser parser_4 = new NexusPhylogeniesParser();
1586             final Phylogeny[] phys_4 = ForesterUtil.readPhylogeniesFromUrl( u_4, parser_4 );
1587             if ( ( phys_4 == null ) || ( phys_4.length != 1 ) ) {
1588                 return false;
1589             }
1590             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1591             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1592             parser2.setReplaceUnderscores( true );
1593             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, parser2 );
1594             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1595                 return false;
1596             }
1597             final URL u3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14909?format=nexus" );
1598             final NexusPhylogeniesParser parser3 = new NexusPhylogeniesParser();
1599             final Phylogeny[] phys3 = ForesterUtil.readPhylogeniesFromUrl( u3, parser3 );
1600             if ( ( phys3 == null ) || ( phys3.length != 2 ) ) {
1601                 return false;
1602             }
1603             final Phylogeny[] phys4 = ForesterUtil.readPhylogeniesFromUrl(
1604                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1605                                                                                    + "14525?format=nexus" ),
1606                                                                            new NexusPhylogeniesParser() );
1607             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1608                 return false;
1609             }
1610             final Phylogeny[] phys5 = ForesterUtil.readPhylogeniesFromUrl(
1611                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1612                                                                                    + "15632?format=nexus" ),
1613                                                                            new NexusPhylogeniesParser() );
1614             if ( ( phys5 == null ) || ( phys5.length != 1 ) ) {
1615                 return false;
1616             }
1617             final Phylogeny[] phys6 = ForesterUtil.readPhylogeniesFromUrl(
1618                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1619                                                                                    + "10190?format=nexus" ),
1620                                                                            new NexusPhylogeniesParser() );
1621             if ( ( phys6 == null ) || ( phys6.length != 1 ) ) {
1622                 return false;
1623             }
1624             final Phylogeny[] phys7 = ForesterUtil.readPhylogeniesFromUrl(
1625                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1626                                                                                    + "13246?format=nexus" ),
1627                                                                            new NexusPhylogeniesParser() );
1628             if ( ( phys7 == null ) || ( phys7.length != 2 ) ) {
1629                 return false;
1630             }
1631             final Phylogeny[] phys8 = ForesterUtil.readPhylogeniesFromUrl(
1632                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1633                                                                                    + "11662?format=nexus" ),
1634                                                                            new NexusPhylogeniesParser() );
1635             if ( ( phys8 == null ) || ( phys8.length != 2 ) ) {
1636                 return false;
1637             }
1638             final Phylogeny[] phys9 = ForesterUtil.readPhylogeniesFromUrl(
1639                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1640                                                                                    + "562?format=nexus" ),
1641                                                                            new NexusPhylogeniesParser() );
1642             if ( ( phys9 == null ) || ( phys9.length != 4 ) ) {
1643                 return false;
1644             }
1645             final Phylogeny[] phys16424 = ForesterUtil.readPhylogeniesFromUrl(
1646                                                                                new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1647                                                                                        + "16424?format=nexus" ),
1648                                                                                new NexusPhylogeniesParser() );
1649             if ( ( phys16424 == null ) || ( phys16424.length != 1 ) ) {
1650                 return false;
1651             }
1652             final Phylogeny[] phys17878 = ForesterUtil.readPhylogeniesFromUrl(
1653                                                                                new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1654                                                                                        + "17878?format=nexus" ),
1655                                                                                new NexusPhylogeniesParser() );
1656             if ( ( phys17878 == null ) || ( phys17878.length != 17 ) ) {
1657                 return false;
1658             }
1659             final Phylogeny[] phys18804 = ForesterUtil.readPhylogeniesFromUrl(
1660                                                                                new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1661                                                                                        + "18804?format=nexus" ),
1662                                                                                new NexusPhylogeniesParser() );
1663             if ( ( phys18804 == null ) || ( phys18804.length != 2 ) ) {
1664                 return false;
1665             }
1666             final Phylogeny[] phys346 = ForesterUtil.readPhylogeniesFromUrl(
1667                                                                              new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1668                                                                                      + "346?format=nexus" ),
1669                                                                              new NexusPhylogeniesParser() );
1670             if ( ( phys346 == null ) || ( phys346.length != 1 ) ) {
1671                 return false;
1672             }
1673         }
1674         catch ( final Exception e ) {
1675             e.printStackTrace();
1676             return false;
1677         }
1678         return true;
1679     }
1680
1681     private static final boolean testTreeFamReading() {
1682         try {
1683             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1684             final NHXParser parser = new NHXParser();
1685             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1686             parser.setReplaceUnderscores( false );
1687             parser.setGuessRootedness( true );
1688             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1689             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1690                 return false;
1691             }
1692             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1693                 return false;
1694             }
1695         }
1696         catch ( final Exception e ) {
1697             e.printStackTrace();
1698             return false;
1699         }
1700         return true;
1701     }
1702
1703     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1704         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1705         return p;
1706     }
1707
1708     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1709         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1710     }
1711
1712     private static boolean testAminoAcidSequence() {
1713         try {
1714             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1715             if ( aa1.getLength() != 13 ) {
1716                 return false;
1717             }
1718             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1719                 return false;
1720             }
1721             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1722                 return false;
1723             }
1724             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1725                 return false;
1726             }
1727             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1728             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1729                 return false;
1730             }
1731             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1732             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1733                 return false;
1734             }
1735             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1736             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1737                 return false;
1738             }
1739         }
1740         catch ( final Exception e ) {
1741             e.printStackTrace();
1742             return false;
1743         }
1744         return true;
1745     }
1746
1747     private static boolean testBasicDomain() {
1748         try {
1749             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1750             if ( !pd.getDomainId().equals( "id" ) ) {
1751                 return false;
1752             }
1753             if ( pd.getNumber() != 1 ) {
1754                 return false;
1755             }
1756             if ( pd.getTotalCount() != 4 ) {
1757                 return false;
1758             }
1759             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1760                 return false;
1761             }
1762             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1763             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1764             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1765             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1766             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1767             if ( !a1.equals( a1 ) ) {
1768                 return false;
1769             }
1770             if ( !a1.equals( a1_copy ) ) {
1771                 return false;
1772             }
1773             if ( !a1.equals( a1_equal ) ) {
1774                 return false;
1775             }
1776             if ( !a1.equals( a2 ) ) {
1777                 return false;
1778             }
1779             if ( a1.equals( a3 ) ) {
1780                 return false;
1781             }
1782             if ( a1.compareTo( a1 ) != 0 ) {
1783                 return false;
1784             }
1785             if ( a1.compareTo( a1_copy ) != 0 ) {
1786                 return false;
1787             }
1788             if ( a1.compareTo( a1_equal ) != 0 ) {
1789                 return false;
1790             }
1791             if ( a1.compareTo( a2 ) != 0 ) {
1792                 return false;
1793             }
1794             if ( a1.compareTo( a3 ) == 0 ) {
1795                 return false;
1796             }
1797         }
1798         catch ( final Exception e ) {
1799             e.printStackTrace( System.out );
1800             return false;
1801         }
1802         return true;
1803     }
1804
1805     private static boolean testBasicNodeMethods() {
1806         try {
1807             if ( PhylogenyNode.getNodeCount() != 0 ) {
1808                 return false;
1809             }
1810             final PhylogenyNode n1 = new PhylogenyNode();
1811             final PhylogenyNode n2 = PhylogenyNode
1812                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1813             final PhylogenyNode n3 = PhylogenyNode
1814                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1815             final PhylogenyNode n4 = PhylogenyNode
1816                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1817             if ( n1.isHasAssignedEvent() ) {
1818                 return false;
1819             }
1820             if ( PhylogenyNode.getNodeCount() != 4 ) {
1821                 return false;
1822             }
1823             if ( n3.getIndicator() != 0 ) {
1824                 return false;
1825             }
1826             if ( n3.getNumberOfExternalNodes() != 1 ) {
1827                 return false;
1828             }
1829             if ( !n3.isExternal() ) {
1830                 return false;
1831             }
1832             if ( !n3.isRoot() ) {
1833                 return false;
1834             }
1835             if ( !n4.getName().equals( "n4" ) ) {
1836                 return false;
1837             }
1838         }
1839         catch ( final Exception e ) {
1840             e.printStackTrace( System.out );
1841             return false;
1842         }
1843         return true;
1844     }
1845
1846     private static boolean testUTF8ParsingFromFile() {
1847         try {
1848             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1849             final Phylogeny[] phylogenies_xml = ParserBasedPhylogenyFactory.getInstance()
1850                     .create( new File( Test.PATH_TO_TEST_DATA + "chars.xml" ), xml_parser );
1851             if ( xml_parser.getErrorCount() > 0 ) {
1852                 System.out.println( xml_parser.getErrorMessages().toString() );
1853                 return false;
1854             }
1855             if ( phylogenies_xml.length != 1 ) {
1856                 return false;
1857             }
1858             final Phylogeny[] phylogenies_xml2 = ParserBasedPhylogenyFactory.getInstance()
1859                     .create( new StringBuffer( phylogenies_xml[ 0 ].toPhyloXML( 0 ) ), xml_parser );
1860             final Phylogeny[] phylogenies_nh = ParserBasedPhylogenyFactory.getInstance()
1861                     .create( new File( Test.PATH_TO_TEST_DATA + "chars.nh" ), new NHXParser() );
1862             if ( phylogenies_nh.length != 1 ) {
1863                 return false;
1864             }
1865             final Phylogeny[] phylogenies_nex = ParserBasedPhylogenyFactory.getInstance()
1866                     .create( new File( Test.PATH_TO_TEST_DATA + "chars.nex" ), new NexusPhylogeniesParser() );
1867             if ( phylogenies_nex.length != 1 ) {
1868                 return false;
1869             }
1870             final String[] xml_n = phylogenies_xml[ 0 ].getAllExternalNodeNames();
1871             final String[] xml_n2 = phylogenies_xml2[ 0 ].getAllExternalNodeNames();
1872             final String[] nh_n = phylogenies_nh[ 0 ].getAllExternalNodeNames();
1873             final String[] nex_n = phylogenies_nex[ 0 ].getAllExternalNodeNames();
1874             final String n0 = "AQ~!@#$%^&*()_+-=\\{}|;:\"<>?,./";
1875             final String n1 = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ";
1876             final String n2 = "漢字ひらがなカタカナ";
1877             final String n3 = "อักษรไทย";
1878             final String n4 = "繁體字";
1879             final String n5 = "한글";
1880             final String n6 = "देवनागरी";
1881             final String n7 = "chữ Quốc ngữ";
1882             final String n8 = "ру́сский язы́к";
1883             final String n9 = "អក្សរខ្មែរ";
1884             if ( !xml_n[ 0 ].equals( n0 ) ) {
1885                 System.out.println( xml_n[ 0 ] );
1886                 System.out.println( n0 );
1887                 return false;
1888             }
1889             if ( !xml_n2[ 0 ].equals( n0 ) ) {
1890                 System.out.println( xml_n2[ 0 ] );
1891                 System.out.println( n0 );
1892                 return false;
1893             }
1894             if ( !nh_n[ 0 ].equals( n0 ) ) {
1895                 System.out.println( nh_n[ 0 ] );
1896                 System.out.println( n0 );
1897                 return false;
1898             }
1899             if ( !nex_n[ 0 ].equals( n0 ) ) {
1900                 System.out.println( nex_n[ 0 ] );
1901                 System.out.println( n0 );
1902                 return false;
1903             }
1904             if ( !xml_n[ 1 ].equals( n1 ) ) {
1905                 System.out.println( xml_n[ 1 ] );
1906                 System.out.println( n1 );
1907                 return false;
1908             }
1909             if ( !xml_n2[ 1 ].equals( n1 ) ) {
1910                 System.out.println( xml_n2[ 1 ] );
1911                 System.out.println( n1 );
1912                 return false;
1913             }
1914             if ( !nh_n[ 1 ].equals( n1 ) ) {
1915                 System.out.println( nh_n[ 1 ] );
1916                 System.out.println( n1 );
1917                 return false;
1918             }
1919             if ( !nex_n[ 1 ].equals( n1 ) ) {
1920                 System.out.println( nex_n[ 1 ] );
1921                 System.out.println( n1 );
1922                 return false;
1923             }
1924             if ( !xml_n[ 2 ].equals( n2 ) ) {
1925                 System.out.println( xml_n[ 2 ] );
1926                 System.out.println( n2 );
1927                 return false;
1928             }
1929             if ( !xml_n2[ 2 ].equals( n2 ) ) {
1930                 System.out.println( xml_n2[ 2 ] );
1931                 System.out.println( n2 );
1932                 return false;
1933             }
1934             if ( !nh_n[ 2 ].equals( n2 ) ) {
1935                 System.out.println( nh_n[ 2 ] );
1936                 System.out.println( n2 );
1937                 return false;
1938             }
1939             if ( !nex_n[ 2 ].equals( n2 ) ) {
1940                 System.out.println( nex_n[ 2 ] );
1941                 System.out.println( n2 );
1942                 return false;
1943             }
1944             //
1945             if ( !xml_n[ 3 ].equals( n3 ) ) {
1946                 System.out.println( xml_n[ 3 ] );
1947                 System.out.println( n3 );
1948                 return false;
1949             }
1950             if ( !xml_n2[ 3 ].equals( n3 ) ) {
1951                 System.out.println( xml_n2[ 3 ] );
1952                 System.out.println( n3 );
1953                 return false;
1954             }
1955             if ( !nh_n[ 3 ].equals( n3 ) ) {
1956                 System.out.println( nh_n[ 3 ] );
1957                 System.out.println( n3 );
1958                 return false;
1959             }
1960             if ( !nex_n[ 3 ].equals( n3 ) ) {
1961                 System.out.println( nex_n[ 3 ] );
1962                 System.out.println( n3 );
1963                 return false;
1964             }
1965             //
1966             if ( !xml_n[ 4 ].equals( n4 ) ) {
1967                 System.out.println( xml_n[ 4 ] );
1968                 System.out.println( n4 );
1969                 return false;
1970             }
1971             if ( !nh_n[ 4 ].equals( n4 ) ) {
1972                 System.out.println( nh_n[ 4 ] );
1973                 System.out.println( n4 );
1974                 return false;
1975             }
1976             if ( !nex_n[ 4 ].equals( n4 ) ) {
1977                 System.out.println( nex_n[ 4 ] );
1978                 System.out.println( n4 );
1979                 return false;
1980             }
1981             //
1982             if ( !xml_n[ 5 ].equals( n5 ) ) {
1983                 System.out.println( xml_n[ 5 ] );
1984                 System.out.println( n5 );
1985                 return false;
1986             }
1987             if ( !nh_n[ 5 ].equals( n5 ) ) {
1988                 System.out.println( nh_n[ 5 ] );
1989                 System.out.println( n5 );
1990                 return false;
1991             }
1992             if ( !nex_n[ 5 ].equals( n5 ) ) {
1993                 System.out.println( nex_n[ 5 ] );
1994                 System.out.println( n5 );
1995                 return false;
1996             }
1997             //
1998             if ( !xml_n[ 6 ].equals( n6 ) ) {
1999                 System.out.println( xml_n[ 6 ] );
2000                 System.out.println( n6 );
2001                 return false;
2002             }
2003             if ( !nh_n[ 6 ].equals( n6 ) ) {
2004                 System.out.println( nh_n[ 6 ] );
2005                 System.out.println( n6 );
2006                 return false;
2007             }
2008             if ( !nex_n[ 6 ].equals( n6 ) ) {
2009                 System.out.println( nex_n[ 6 ] );
2010                 System.out.println( n6 );
2011                 return false;
2012             }
2013             //
2014             if ( !xml_n[ 7 ].equals( n7 ) ) {
2015                 System.out.println( xml_n[ 7 ] );
2016                 System.out.println( n7 );
2017                 return false;
2018             }
2019             if ( !nh_n[ 7 ].equals( n7 ) ) {
2020                 System.out.println( nh_n[ 7 ] );
2021                 System.out.println( n7 );
2022                 return false;
2023             }
2024             if ( !nex_n[ 7 ].equals( n7 ) ) {
2025                 System.out.println( nex_n[ 7 ] );
2026                 System.out.println( n7 );
2027                 return false;
2028             }
2029             if ( !xml_n[ 8 ].equals( n8 ) ) {
2030                 System.out.println( xml_n[ 8 ] );
2031                 System.out.println( n8 );
2032                 return false;
2033             }
2034             if ( !nh_n[ 8 ].equals( n8 ) ) {
2035                 System.out.println( nh_n[ 8 ] );
2036                 System.out.println( n8 );
2037                 return false;
2038             }
2039             if ( !nex_n[ 8 ].equals( n8 ) ) {
2040                 System.out.println( nex_n[ 8 ] );
2041                 System.out.println( n8 );
2042                 return false;
2043             }
2044             if ( !xml_n[ 9 ].equals( n9 ) ) {
2045                 System.out.println( xml_n[ 9 ] );
2046                 System.out.println( n9 );
2047                 return false;
2048             }
2049             if ( !xml_n2[ 9 ].equals( n9 ) ) {
2050                 System.out.println( xml_n2[ 9 ] );
2051                 System.out.println( n9 );
2052                 return false;
2053             }
2054             if ( !nh_n[ 9 ].equals( n9 ) ) {
2055                 System.out.println( nh_n[ 9 ] );
2056                 System.out.println( n9 );
2057                 return false;
2058             }
2059             if ( !nex_n[ 9 ].equals( n9 ) ) {
2060                 System.out.println( nex_n[ 9 ] );
2061                 System.out.println( n9 );
2062                 return false;
2063             }
2064             if ( !phylogenies_xml[ 0 ].toNewHampshire().equals( phylogenies_nh[ 0 ].toNewHampshire() ) ) {
2065                 System.out.println( phylogenies_xml[ 0 ].toNewHampshire() );
2066                 System.out.println( phylogenies_nh[ 0 ].toNewHampshire() );
2067                 return false;
2068             }
2069             if ( !phylogenies_xml[ 0 ].toNewHampshire().equals( phylogenies_nex[ 0 ].toNewHampshire() ) ) {
2070                 System.out.println( phylogenies_xml[ 0 ].toNewHampshire() );
2071                 System.out.println( phylogenies_nex[ 0 ].toNewHampshire() );
2072                 return false;
2073             }
2074         }
2075         catch ( final Exception e ) {
2076             e.printStackTrace( System.out );
2077             return false;
2078         }
2079         return true;
2080     }
2081
2082     private static boolean testBasicPhyloXMLparsing() {
2083         try {
2084             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2085             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2086             final Phylogeny[] phylogenies_0 = factory
2087                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ), xml_parser );
2088             if ( xml_parser.getErrorCount() > 0 ) {
2089                 System.out.println( xml_parser.getErrorMessages().toString() );
2090                 return false;
2091             }
2092             if ( phylogenies_0.length != 4 ) {
2093                 return false;
2094             }
2095             final Phylogeny t1 = phylogenies_0[ 0 ];
2096             final Phylogeny t2 = phylogenies_0[ 1 ];
2097             final Phylogeny t3 = phylogenies_0[ 2 ];
2098             final Phylogeny t4 = phylogenies_0[ 3 ];
2099             if ( t1.getNumberOfExternalNodes() != 1 ) {
2100                 return false;
2101             }
2102             if ( !t1.isRooted() ) {
2103                 return false;
2104             }
2105             if ( t1.isRerootable() ) {
2106                 return false;
2107             }
2108             if ( !t1.getType().equals( "gene_tree" ) ) {
2109                 return false;
2110             }
2111             if ( t2.getNumberOfExternalNodes() != 2 ) {
2112                 return false;
2113             }
2114             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
2115                 return false;
2116             }
2117             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
2118                 return false;
2119             }
2120             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2121                 return false;
2122             }
2123             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2124                 return false;
2125             }
2126             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2127                 return false;
2128             }
2129             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2130                 return false;
2131             }
2132             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2133                     .startsWith( "actgtgggggt" ) ) {
2134                 return false;
2135             }
2136             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2137                     .startsWith( "ctgtgatgcat" ) ) {
2138                 return false;
2139             }
2140             if ( t3.getNumberOfExternalNodes() != 4 ) {
2141                 return false;
2142             }
2143             if ( !t1.getName().equals( "t1" ) ) {
2144                 return false;
2145             }
2146             if ( !t2.getName().equals( "t2" ) ) {
2147                 return false;
2148             }
2149             if ( !t3.getName().equals( "t3" ) ) {
2150                 return false;
2151             }
2152             if ( !t4.getName().equals( "t4" ) ) {
2153                 return false;
2154             }
2155             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
2156                 return false;
2157             }
2158             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
2159                 return false;
2160             }
2161             if ( !t3.getNode( "root node" ).isDuplication() ) {
2162                 return false;
2163             }
2164             if ( !t3.getNode( "node a" ).isDuplication() ) {
2165                 return false;
2166             }
2167             if ( t3.getNode( "node a" ).isSpeciation() ) {
2168                 return false;
2169             }
2170             if ( t3.getNode( "node bc" ).isDuplication() ) {
2171                 return false;
2172             }
2173             if ( !t3.getNode( "node bc" ).isSpeciation() ) {
2174                 return false;
2175             }
2176             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2177                 return false;
2178             }
2179             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
2180                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2181                 return false;
2182             }
2183             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2184                 return false;
2185             }
2186             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2187                 return false;
2188             }
2189             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2190                     .equals( "UniProtKB" ) ) {
2191                 return false;
2192             }
2193             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2194                     .equals( "apoptosis" ) ) {
2195                 return false;
2196             }
2197             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2198                     .equals( "GO:0006915" ) ) {
2199                 return false;
2200             }
2201             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2202                     .equals( "UniProtKB" ) ) {
2203                 return false;
2204             }
2205             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2206                     .equals( "experimental" ) ) {
2207                 return false;
2208             }
2209             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2210                     .equals( "function" ) ) {
2211                 return false;
2212             }
2213             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2214                     .getValue() != 1 ) {
2215                 return false;
2216             }
2217             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence().getType()
2218                     .equals( "ml" ) ) {
2219                 return false;
2220             }
2221             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2222                     .equals( "apoptosis" ) ) {
2223                 return false;
2224             }
2225             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2226                     .getProperties( "AFFY:expression" ).get( 0 ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2227                 return false;
2228             }
2229             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2230                     .getProperties( "AFFY:expression" ).get( 0 ).getDataType().equals( "xsd:double" ) ) {
2231                 return false;
2232             }
2233             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2234                     .getProperties( "AFFY:expression" ).get( 0 ).getRef().equals( "AFFY:expression" ) ) {
2235                 return false;
2236             }
2237             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2238                     .getProperties( "AFFY:expression" ).get( 0 ).getUnit().equals( "AFFY:x" ) ) {
2239                 return false;
2240             }
2241             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2242                     .getProperties( "AFFY:expression" ).get( 0 ).getValue().equals( "0.2" ) ) {
2243                 return false;
2244             }
2245             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2246                     .getProperties( "MED:disease" ).get( 0 ).getValue().equals( "lymphoma" ) ) {
2247                 return false;
2248             }
2249             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2250                     .equals( "GO:0005829" ) ) {
2251                 return false;
2252             }
2253             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2254                     .equals( "intracellular organelle" ) ) {
2255                 return false;
2256             }
2257             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2258                 return false;
2259             }
2260             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2261                     .equals( "UniProt link" ) ) ) {
2262                 return false;
2263             }
2264             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2265                 return false;
2266             }
2267             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
2268             if ( x.size() != 4 ) {
2269                 return false;
2270             }
2271             int c = 0;
2272             for( final Accession acc : x ) {
2273                 if ( c == 0 ) {
2274                     if ( !acc.getSource().equals( "KEGG" ) ) {
2275                         return false;
2276                     }
2277                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2278                         return false;
2279                     }
2280                 }
2281                 c++;
2282             }
2283         }
2284         catch ( final Exception e ) {
2285             e.printStackTrace( System.out );
2286             return false;
2287         }
2288         return true;
2289     }
2290
2291     private static boolean testBasicPhyloXMLparsingRoundtrip() {
2292         try {
2293             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2294             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2295             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2296                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2297             }
2298             else {
2299                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2300             }
2301             final Phylogeny[] phylogenies_0 = factory
2302                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ), xml_parser );
2303             if ( xml_parser.getErrorCount() > 0 ) {
2304                 System.out.println( xml_parser.getErrorMessages().toString() );
2305                 return false;
2306             }
2307             if ( phylogenies_0.length != 4 ) {
2308                 return false;
2309             }
2310             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
2311             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
2312             if ( phylogenies_t1.length != 1 ) {
2313                 return false;
2314             }
2315             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
2316             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
2317                 return false;
2318             }
2319             if ( !t1_rt.isRooted() ) {
2320                 return false;
2321             }
2322             if ( t1_rt.isRerootable() ) {
2323                 return false;
2324             }
2325             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
2326                 return false;
2327             }
2328             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
2329             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
2330             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
2331             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2332                 return false;
2333             }
2334             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2335                 return false;
2336             }
2337             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2338                 return false;
2339             }
2340             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2341                 return false;
2342             }
2343             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2344                     .startsWith( "actgtgggggt" ) ) {
2345                 return false;
2346             }
2347             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2348                     .startsWith( "ctgtgatgcat" ) ) {
2349                 return false;
2350             }
2351             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
2352             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
2353             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
2354             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
2355             if ( phylogenies_1.length != 1 ) {
2356                 return false;
2357             }
2358             final Phylogeny t3_rt = phylogenies_1[ 0 ];
2359             if ( !t3_rt.getName().equals( "t3" ) ) {
2360                 return false;
2361             }
2362             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
2363                 return false;
2364             }
2365             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
2366                 return false;
2367             }
2368             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
2369                 return false;
2370             }
2371             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2372                 return false;
2373             }
2374             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
2375                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2376                 return false;
2377             }
2378             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2379                 return false;
2380             }
2381             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue()
2382                     .equals( "Q9BZR8" ) ) {
2383                 return false;
2384             }
2385             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2386                     .equals( "UniProtKB" ) ) {
2387                 return false;
2388             }
2389             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2390                     .equals( "apoptosis" ) ) {
2391                 return false;
2392             }
2393             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2394                     .equals( "GO:0006915" ) ) {
2395                 return false;
2396             }
2397             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2398                     .equals( "UniProtKB" ) ) {
2399                 return false;
2400             }
2401             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2402                     .equals( "experimental" ) ) {
2403                 return false;
2404             }
2405             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2406                     .equals( "function" ) ) {
2407                 return false;
2408             }
2409             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2410                     .getValue() != 1 ) {
2411                 return false;
2412             }
2413             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2414                     .getType().equals( "ml" ) ) {
2415                 return false;
2416             }
2417             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2418                     .equals( "apoptosis" ) ) {
2419                 return false;
2420             }
2421             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2422                     .getProperties( "AFFY:expression" ).get( 0 ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2423                 return false;
2424             }
2425             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2426                     .getProperties( "AFFY:expression" ).get( 0 ).getDataType().equals( "xsd:double" ) ) {
2427                 return false;
2428             }
2429             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2430                     .getProperties( "AFFY:expression" ).get( 0 ).getRef().equals( "AFFY:expression" ) ) {
2431                 return false;
2432             }
2433             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2434                     .getProperties( "AFFY:expression" ).get( 0 ).getUnit().equals( "AFFY:x" ) ) {
2435                 return false;
2436             }
2437             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2438                     .getProperties( "AFFY:expression" ).get( 0 ).getValue().equals( "0.2" ) ) {
2439                 return false;
2440             }
2441             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2442                     .getProperties( "MED:disease" ).get( 0 ).getValue().equals( "lymphoma" ) ) {
2443                 return false;
2444             }
2445             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2446                     .equals( "GO:0005829" ) ) {
2447                 return false;
2448             }
2449             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2450                     .equals( "intracellular organelle" ) ) {
2451                 return false;
2452             }
2453             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType()
2454                     .equals( "source" ) ) ) {
2455                 return false;
2456             }
2457             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2458                     .equals( "UniProt link" ) ) ) {
2459                 return false;
2460             }
2461             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2462                 return false;
2463             }
2464             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi()
2465                     .equals( "10.1038/387489a0" ) ) ) {
2466                 return false;
2467             }
2468             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2469                     .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." ) ) ) {
2470                 System.out.println( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription() );
2471                 return false;
2472             }
2473             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2474                 return false;
2475             }
2476             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2477                 return false;
2478             }
2479             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName()
2480                     .equals( "molting animals" ) ) {
2481                 return false;
2482             }
2483             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2484                 return false;
2485             }
2486             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2487                     .equals( "ncbi" ) ) {
2488                 return false;
2489             }
2490             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture()
2491                     .getTotalLength() != 124 ) {
2492                 return false;
2493             }
2494             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2495                     .getName().equals( "B" ) ) {
2496                 return false;
2497             }
2498             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2499                     .getFrom() != 21 ) {
2500                 return false;
2501             }
2502             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2503                     .getTo() != 44 ) {
2504                 return false;
2505             }
2506             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2507                     .getLength() != 24 ) {
2508                 return false;
2509             }
2510             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2511                     .getConfidence() != 0 ) {
2512                 return false;
2513             }
2514             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2515                     .equals( "pfam" ) ) {
2516                 return false;
2517             }
2518             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2519                 return false;
2520             }
2521             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2522                 return false;
2523             }
2524             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2525                 return false;
2526             }
2527             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2528                 return false;
2529             }
2530             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2531             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2532                 return false;
2533             }
2534             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2535                 return false;
2536             }
2537             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2538                 return false;
2539             }
2540             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2541                 return false;
2542             }
2543             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2544                 return false;
2545             }
2546             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2547                 return false;
2548             }
2549             if ( taxbb.getSynonyms().size() != 2 ) {
2550                 return false;
2551             }
2552             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2553                 return false;
2554             }
2555             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2556                 return false;
2557             }
2558             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2559                 return false;
2560             }
2561             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2562                 return false;
2563             }
2564             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2565                 return false;
2566             }
2567             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2568                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2569                 return false;
2570             }
2571             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2572                 return false;
2573             }
2574             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2575                 return false;
2576             }
2577             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2578                 return false;
2579             }
2580             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2581                 return false;
2582             }
2583             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2584                 return false;
2585             }
2586             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2587                 return false;
2588             }
2589             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2590                 return false;
2591             }
2592             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2593                 return false;
2594             }
2595             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2596                     .equalsIgnoreCase( "435" ) ) {
2597                 return false;
2598             }
2599             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString()
2600                     .equalsIgnoreCase( "416" ) ) {
2601                 return false;
2602             }
2603             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2604                     .equalsIgnoreCase( "443.7" ) ) {
2605                 return false;
2606             }
2607             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2608                 return false;
2609             }
2610             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2611                 return false;
2612             }
2613             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2614                     .equalsIgnoreCase( "433" ) ) {
2615                 return false;
2616             }
2617             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2618                     .getCrossReferences();
2619             if ( x.size() != 4 ) {
2620                 return false;
2621             }
2622             int c = 0;
2623             for( final Accession acc : x ) {
2624                 if ( c == 0 ) {
2625                     if ( !acc.getSource().equals( "KEGG" ) ) {
2626                         return false;
2627                     }
2628                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2629                         return false;
2630                     }
2631                 }
2632                 c++;
2633             }
2634         }
2635         catch ( final Exception e ) {
2636             e.printStackTrace( System.out );
2637             return false;
2638         }
2639         return true;
2640     }
2641
2642     private static boolean testBasicPhyloXMLparsingValidating() {
2643         try {
2644             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2645             PhyloXmlParser xml_parser = null;
2646             try {
2647                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2648             }
2649             catch ( final Exception e ) {
2650                 // Do nothing -- means were not running from jar.
2651             }
2652             if ( xml_parser == null ) {
2653                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2654                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2655                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2656                 }
2657                 else {
2658                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2659                 }
2660             }
2661             final Phylogeny[] phylogenies_0 = factory
2662                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ), xml_parser );
2663             if ( xml_parser.getErrorCount() > 0 ) {
2664                 System.out.println( xml_parser.getErrorMessages().toString() );
2665                 return false;
2666             }
2667             if ( phylogenies_0.length != 4 ) {
2668                 return false;
2669             }
2670             final Phylogeny t1 = phylogenies_0[ 0 ];
2671             final Phylogeny t2 = phylogenies_0[ 1 ];
2672             final Phylogeny t3 = phylogenies_0[ 2 ];
2673             final Phylogeny t4 = phylogenies_0[ 3 ];
2674             if ( !t1.getName().equals( "t1" ) ) {
2675                 return false;
2676             }
2677             if ( !t2.getName().equals( "t2" ) ) {
2678                 return false;
2679             }
2680             if ( !t3.getName().equals( "t3" ) ) {
2681                 return false;
2682             }
2683             if ( !t4.getName().equals( "t4" ) ) {
2684                 return false;
2685             }
2686             if ( t1.getNumberOfExternalNodes() != 1 ) {
2687                 return false;
2688             }
2689             if ( t2.getNumberOfExternalNodes() != 2 ) {
2690                 return false;
2691             }
2692             if ( t3.getNumberOfExternalNodes() != 4 ) {
2693                 return false;
2694             }
2695             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2696             final Phylogeny[] phylogenies_1 = factory.create( new File( x2 ), xml_parser );
2697             if ( xml_parser.getErrorCount() > 0 ) {
2698                 System.out.println( "errors:" );
2699                 System.out.println( xml_parser.getErrorMessages().toString() );
2700                 return false;
2701             }
2702             if ( phylogenies_1.length != 4 ) {
2703                 return false;
2704             }
2705             final Phylogeny[] phylogenies_2 = factory
2706                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml" ), xml_parser );
2707             if ( xml_parser.getErrorCount() > 0 ) {
2708                 System.out.println( "errors:" );
2709                 System.out.println( xml_parser.getErrorMessages().toString() );
2710                 return false;
2711             }
2712             if ( phylogenies_2.length != 1 ) {
2713                 return false;
2714             }
2715             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2716                 return false;
2717             }
2718             final Phylogeny[] phylogenies_3 = factory
2719                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml" ), xml_parser );
2720             if ( xml_parser.getErrorCount() > 0 ) {
2721                 System.out.println( xml_parser.getErrorMessages().toString() );
2722                 return false;
2723             }
2724             if ( phylogenies_3.length != 2 ) {
2725                 return false;
2726             }
2727             final Phylogeny a = phylogenies_3[ 0 ];
2728             if ( !a.getName().equals( "tree 4" ) ) {
2729                 return false;
2730             }
2731             if ( a.getNumberOfExternalNodes() != 3 ) {
2732                 return false;
2733             }
2734             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2735                 return false;
2736             }
2737             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2738                 return false;
2739             }
2740             final Phylogeny[] phylogenies_4 = factory
2741                     .create( new File( Test.PATH_TO_TEST_DATA + "special_characters.xml" ), xml_parser );
2742             if ( xml_parser.getErrorCount() > 0 ) {
2743                 System.out.println( xml_parser.getErrorMessages().toString() );
2744                 return false;
2745             }
2746             if ( phylogenies_4.length != 1 ) {
2747                 return false;
2748             }
2749             final Phylogeny s = phylogenies_4[ 0 ];
2750             if ( s.getNumberOfExternalNodes() != 6 ) {
2751                 return false;
2752             }
2753             s.getNode( "first" );
2754             s.getNode( "<>" );
2755             s.getNode( "\"<a'b&c'd\">\"" );
2756             s.getNode( "'''\"" );
2757             s.getNode( "\"\"\"" );
2758             s.getNode( "dick & doof" );
2759         }
2760         catch ( final Exception e ) {
2761             e.printStackTrace( System.out );
2762             return false;
2763         }
2764         return true;
2765     }
2766
2767     private static boolean testPhyloXMLparsingValidating() {
2768         try {
2769             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2770             PhyloXmlParser xml_parser = null;
2771             try {
2772                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2773             }
2774             catch ( final Exception e ) {
2775                 // Do nothing -- means were not running from jar.
2776             }
2777             if ( xml_parser == null ) {
2778                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2779                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2780                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2781                 }
2782                 else {
2783                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2784                 }
2785             }
2786             final Phylogeny[] phylogenies_0 = factory
2787                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_1.xml" ), xml_parser );
2788             if ( xml_parser.getErrorCount() > 0 ) {
2789                 System.out.println( xml_parser.getErrorMessages().toString() );
2790                 return false;
2791             }
2792             if ( phylogenies_0.length != 3 ) {
2793                 return false;
2794             }
2795         }
2796         catch ( final Exception e ) {
2797             e.printStackTrace( System.out );
2798             return false;
2799         }
2800         return true;
2801     }
2802
2803     private static boolean testBasicProtein() {
2804         try {
2805             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2806             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2807             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2808             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2809             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2810             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2811             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2812             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2813             p0.addProteinDomain( y );
2814             p0.addProteinDomain( e );
2815             p0.addProteinDomain( b );
2816             p0.addProteinDomain( c );
2817             p0.addProteinDomain( d );
2818             p0.addProteinDomain( a );
2819             p0.addProteinDomain( x );
2820             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2821                 return false;
2822             }
2823             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2824                 return false;
2825             }
2826             //
2827             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2828             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2829             aa0.addProteinDomain( a1 );
2830             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2831                 return false;
2832             }
2833             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2834                 return false;
2835             }
2836             //
2837             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2838             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2839             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2840             aa1.addProteinDomain( a11 );
2841             aa1.addProteinDomain( a12 );
2842             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2843                 return false;
2844             }
2845             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2846                 return false;
2847             }
2848             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2849             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2850                 return false;
2851             }
2852             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2853                 return false;
2854             }
2855             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2856                 return false;
2857             }
2858             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2859             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2860                 return false;
2861             }
2862             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2863                 return false;
2864             }
2865             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2866                 return false;
2867             }
2868             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2869                 return false;
2870             }
2871             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2872             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2873                 return false;
2874             }
2875             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2876                 return false;
2877             }
2878             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2879                 return false;
2880             }
2881             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2882                 return false;
2883             }
2884             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2885             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2886                 return false;
2887             }
2888             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2889                 return false;
2890             }
2891             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2892                 return false;
2893             }
2894             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2895                 return false;
2896             }
2897             //
2898             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2899             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2900             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2901             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2902             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2903             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2904             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2905             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2906             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2907             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2908             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2909             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2910             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2911             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2912             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2913             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2914             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2915             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2916             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2917             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2918             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2919             p00.addProteinDomain( y0 );
2920             p00.addProteinDomain( e0 );
2921             p00.addProteinDomain( b0 );
2922             p00.addProteinDomain( c0 );
2923             p00.addProteinDomain( d0 );
2924             p00.addProteinDomain( a0 );
2925             p00.addProteinDomain( x0 );
2926             p00.addProteinDomain( y1 );
2927             p00.addProteinDomain( y2 );
2928             p00.addProteinDomain( y3 );
2929             p00.addProteinDomain( e1 );
2930             p00.addProteinDomain( e2 );
2931             p00.addProteinDomain( e3 );
2932             p00.addProteinDomain( e4 );
2933             p00.addProteinDomain( e5 );
2934             p00.addProteinDomain( z0 );
2935             p00.addProteinDomain( z1 );
2936             p00.addProteinDomain( z2 );
2937             p00.addProteinDomain( zz0 );
2938             p00.addProteinDomain( zz1 );
2939             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2940                 return false;
2941             }
2942             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2943                 return false;
2944             }
2945             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2946                 return false;
2947             }
2948             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2949                 return false;
2950             }
2951             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" ) ) {
2952                 return false;
2953             }
2954             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2955             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2956             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2957             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2958             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2959             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2960             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2961             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2962             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2963             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2964             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2965             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2966             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2967             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2968             p.addProteinDomain( B15 );
2969             p.addProteinDomain( C50 );
2970             p.addProteinDomain( A60 );
2971             p.addProteinDomain( A30 );
2972             p.addProteinDomain( C70 );
2973             p.addProteinDomain( B35 );
2974             p.addProteinDomain( B40 );
2975             p.addProteinDomain( A0 );
2976             p.addProteinDomain( A10 );
2977             p.addProteinDomain( A20 );
2978             p.addProteinDomain( B25 );
2979             p.addProteinDomain( D80 );
2980             List<String> domains_ids = new ArrayList<String>();
2981             domains_ids.add( "A" );
2982             domains_ids.add( "B" );
2983             domains_ids.add( "C" );
2984             if ( !p.contains( domains_ids, false ) ) {
2985                 return false;
2986             }
2987             if ( !p.contains( domains_ids, true ) ) {
2988                 return false;
2989             }
2990             domains_ids.add( "X" );
2991             if ( p.contains( domains_ids, false ) ) {
2992                 return false;
2993             }
2994             if ( p.contains( domains_ids, true ) ) {
2995                 return false;
2996             }
2997             domains_ids = new ArrayList<String>();
2998             domains_ids.add( "A" );
2999             domains_ids.add( "C" );
3000             domains_ids.add( "D" );
3001             if ( !p.contains( domains_ids, false ) ) {
3002                 return false;
3003             }
3004             if ( !p.contains( domains_ids, true ) ) {
3005                 return false;
3006             }
3007             domains_ids = new ArrayList<String>();
3008             domains_ids.add( "A" );
3009             domains_ids.add( "D" );
3010             domains_ids.add( "C" );
3011             if ( !p.contains( domains_ids, false ) ) {
3012                 return false;
3013             }
3014             if ( p.contains( domains_ids, true ) ) {
3015                 return false;
3016             }
3017             domains_ids = new ArrayList<String>();
3018             domains_ids.add( "A" );
3019             domains_ids.add( "A" );
3020             domains_ids.add( "B" );
3021             if ( !p.contains( domains_ids, false ) ) {
3022                 return false;
3023             }
3024             if ( !p.contains( domains_ids, true ) ) {
3025                 return false;
3026             }
3027             domains_ids = new ArrayList<String>();
3028             domains_ids.add( "A" );
3029             domains_ids.add( "A" );
3030             domains_ids.add( "A" );
3031             domains_ids.add( "B" );
3032             domains_ids.add( "B" );
3033             if ( !p.contains( domains_ids, false ) ) {
3034                 return false;
3035             }
3036             if ( !p.contains( domains_ids, true ) ) {
3037                 return false;
3038             }
3039             domains_ids = new ArrayList<String>();
3040             domains_ids.add( "A" );
3041             domains_ids.add( "A" );
3042             domains_ids.add( "B" );
3043             domains_ids.add( "A" );
3044             domains_ids.add( "B" );
3045             domains_ids.add( "B" );
3046             domains_ids.add( "A" );
3047             domains_ids.add( "B" );
3048             domains_ids.add( "C" );
3049             domains_ids.add( "A" );
3050             domains_ids.add( "C" );
3051             domains_ids.add( "D" );
3052             if ( !p.contains( domains_ids, false ) ) {
3053                 return false;
3054             }
3055             if ( p.contains( domains_ids, true ) ) {
3056                 return false;
3057             }
3058         }
3059         catch ( final Exception e ) {
3060             e.printStackTrace( System.out );
3061             return false;
3062         }
3063         return true;
3064     }
3065
3066     private static boolean testBasicTable() {
3067         try {
3068             final BasicTable<String> t0 = new BasicTable<String>();
3069             if ( t0.getNumberOfColumns() != 0 ) {
3070                 return false;
3071             }
3072             if ( t0.getNumberOfRows() != 0 ) {
3073                 return false;
3074             }
3075             t0.setValue( 3, 2, "23" );
3076             t0.setValue( 10, 1, "error" );
3077             t0.setValue( 10, 1, "110" );
3078             t0.setValue( 9, 1, "19" );
3079             t0.setValue( 1, 10, "101" );
3080             t0.setValue( 10, 10, "1010" );
3081             t0.setValue( 100, 10, "10100" );
3082             t0.setValue( 0, 0, "00" );
3083             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3084                 return false;
3085             }
3086             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3087                 return false;
3088             }
3089             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3090                 return false;
3091             }
3092             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3093                 return false;
3094             }
3095             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3096                 return false;
3097             }
3098             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3099                 return false;
3100             }
3101             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3102                 return false;
3103             }
3104             if ( t0.getNumberOfColumns() != 101 ) {
3105                 return false;
3106             }
3107             if ( t0.getNumberOfRows() != 11 ) {
3108                 return false;
3109             }
3110             if ( t0.getValueAsString( 49, 4 ) != null ) {
3111                 return false;
3112             }
3113             final String l = ForesterUtil.getLineSeparator();
3114             final StringBuffer source = new StringBuffer();
3115             source.append( "" + l );
3116             source.append( "# 1 1 1 1 1 1 1 1" + l );
3117             source.append( " 00 01 02 03" + l );
3118             source.append( "   10 11 12 13  " + l );
3119             source.append( "20 21 22 23 " + l );
3120             source.append( "    30  31    32 33" + l );
3121             source.append( "40 41 42 43" + l );
3122             source.append( "  # 1 1 1 1 1 " + l );
3123             source.append( "50 51 52 53 54" + l );
3124             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
3125             if ( t1.getNumberOfColumns() != 5 ) {
3126                 return false;
3127             }
3128             if ( t1.getNumberOfRows() != 6 ) {
3129                 return false;
3130             }
3131             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
3132                 return false;
3133             }
3134             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
3135                 return false;
3136             }
3137             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
3138                 return false;
3139             }
3140             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
3141                 return false;
3142             }
3143             final StringBuffer source1 = new StringBuffer();
3144             source1.append( "" + l );
3145             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3146             source1.append( " 00; 01 ;02;03" + l );
3147             source1.append( "   10; 11; 12; 13  " + l );
3148             source1.append( "20; 21; 22; 23 " + l );
3149             source1.append( "    30;  31;    32; 33" + l );
3150             source1.append( "40;41;42;43" + l );
3151             source1.append( "  # 1 1 1 1 1 " + l );
3152             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
3153             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
3154             if ( t2.getNumberOfColumns() != 5 ) {
3155                 return false;
3156             }
3157             if ( t2.getNumberOfRows() != 6 ) {
3158                 return false;
3159             }
3160             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
3161                 return false;
3162             }
3163             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
3164                 return false;
3165             }
3166             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
3167                 return false;
3168             }
3169             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
3170                 return false;
3171             }
3172             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
3173                 return false;
3174             }
3175             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
3176                 return false;
3177             }
3178             final StringBuffer source2 = new StringBuffer();
3179             source2.append( "" + l );
3180             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3181             source2.append( " 00; 01 ;02;03" + l );
3182             source2.append( "   10; 11; 12; 13  " + l );
3183             source2.append( "20; 21; 22; 23 " + l );
3184             source2.append( "                     " + l );
3185             source2.append( "    30;  31;    32; 33" + l );
3186             source2.append( "40;41;42;43" + l );
3187             source2.append( "  comment: 1 1 1 1 1 " + l );
3188             source2.append( ";;;50  ;   52; 53;;54   " + l );
3189             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
3190                                                                         ';',
3191                                                                         false,
3192                                                                         false,
3193                                                                         "comment:",
3194                                                                         false );
3195             if ( tl.size() != 2 ) {
3196                 return false;
3197             }
3198             final BasicTable<String> t3 = tl.get( 0 );
3199             final BasicTable<String> t4 = tl.get( 1 );
3200             if ( t3.getNumberOfColumns() != 4 ) {
3201                 return false;
3202             }
3203             if ( t3.getNumberOfRows() != 3 ) {
3204                 return false;
3205             }
3206             if ( t4.getNumberOfColumns() != 4 ) {
3207                 return false;
3208             }
3209             if ( t4.getNumberOfRows() != 3 ) {
3210                 return false;
3211             }
3212             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
3213                 return false;
3214             }
3215             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
3216                 return false;
3217             }
3218         }
3219         catch ( final Exception e ) {
3220             e.printStackTrace( System.out );
3221             return false;
3222         }
3223         return true;
3224     }
3225
3226     private static boolean testBasicTolXMLparsing() {
3227         try {
3228             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3229             final TolParser parser = new TolParser();
3230             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
3231             if ( parser.getErrorCount() > 0 ) {
3232                 System.out.println( parser.getErrorMessages().toString() );
3233                 return false;
3234             }
3235             if ( phylogenies_0.length != 1 ) {
3236                 return false;
3237             }
3238             final Phylogeny t1 = phylogenies_0[ 0 ];
3239             if ( t1.getNumberOfExternalNodes() != 5 ) {
3240                 return false;
3241             }
3242             if ( !t1.isRooted() ) {
3243                 return false;
3244             }
3245             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
3246                 return false;
3247             }
3248             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
3249                 return false;
3250             }
3251             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3252                     .equals( "Rhombozoa" ) ) {
3253                 return false;
3254             }
3255             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
3256                 return false;
3257             }
3258             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
3259             if ( parser.getErrorCount() > 0 ) {
3260                 System.out.println( parser.getErrorMessages().toString() );
3261                 return false;
3262             }
3263             if ( phylogenies_1.length != 1 ) {
3264                 return false;
3265             }
3266             final Phylogeny t2 = phylogenies_1[ 0 ];
3267             if ( t2.getNumberOfExternalNodes() != 664 ) {
3268                 return false;
3269             }
3270             if ( !t2.isRooted() ) {
3271                 return false;
3272             }
3273             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
3274                 return false;
3275             }
3276             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
3277                 return false;
3278             }
3279             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3280                 return false;
3281             }
3282             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3283                 return false;
3284             }
3285             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3286                     .equals( "Aquificae" ) ) {
3287                 return false;
3288             }
3289             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3290                     .equals( "Aquifex" ) ) {
3291                 return false;
3292             }
3293             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
3294             if ( parser.getErrorCount() > 0 ) {
3295                 System.out.println( parser.getErrorMessages().toString() );
3296                 return false;
3297             }
3298             if ( phylogenies_2.length != 1 ) {
3299                 return false;
3300             }
3301             final Phylogeny t3 = phylogenies_2[ 0 ];
3302             if ( t3.getNumberOfExternalNodes() != 184 ) {
3303                 return false;
3304             }
3305             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
3306                 return false;
3307             }
3308             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
3309                 return false;
3310             }
3311             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
3312                 return false;
3313             }
3314             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
3315             if ( parser.getErrorCount() > 0 ) {
3316                 System.out.println( parser.getErrorMessages().toString() );
3317                 return false;
3318             }
3319             if ( phylogenies_3.length != 1 ) {
3320                 return false;
3321             }
3322             final Phylogeny t4 = phylogenies_3[ 0 ];
3323             if ( t4.getNumberOfExternalNodes() != 1 ) {
3324                 return false;
3325             }
3326             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
3327                 return false;
3328             }
3329             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
3330                 return false;
3331             }
3332             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
3333                 return false;
3334             }
3335             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
3336             if ( parser.getErrorCount() > 0 ) {
3337                 System.out.println( parser.getErrorMessages().toString() );
3338                 return false;
3339             }
3340             if ( phylogenies_4.length != 1 ) {
3341                 return false;
3342             }
3343             final Phylogeny t5 = phylogenies_4[ 0 ];
3344             if ( t5.getNumberOfExternalNodes() != 13 ) {
3345                 return false;
3346             }
3347             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
3348                 return false;
3349             }
3350             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
3351                 return false;
3352             }
3353             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
3354                 return false;
3355             }
3356         }
3357         catch ( final Exception e ) {
3358             e.printStackTrace( System.out );
3359             return false;
3360         }
3361         return true;
3362     }
3363
3364     private static boolean testBasicTreeMethods() {
3365         try {
3366             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3367             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
3368             if ( t2.getNumberOfExternalNodes() != 4 ) {
3369                 return false;
3370             }
3371             if ( t2.calculateHeight( false ) != 8.5 ) {
3372                 return false;
3373             }
3374             if ( !t2.isCompletelyBinary() ) {
3375                 return false;
3376             }
3377             if ( t2.isEmpty() ) {
3378                 return false;
3379             }
3380             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
3381             if ( t3.getNumberOfExternalNodes() != 5 ) {
3382                 return false;
3383             }
3384             if ( t3.calculateHeight( true ) != 11 ) {
3385                 return false;
3386             }
3387             if ( t3.isCompletelyBinary() ) {
3388                 return false;
3389             }
3390             final PhylogenyNode n = t3.getNode( "ABC" );
3391             final Phylogeny t4 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3,(F,G,H,I))",
3392                                                  new NHXParser() )[ 0 ];
3393             if ( t4.getNumberOfExternalNodes() != 9 ) {
3394                 return false;
3395             }
3396             if ( t4.calculateHeight( false ) != 11 ) {
3397                 return false;
3398             }
3399             if ( t4.isCompletelyBinary() ) {
3400                 return false;
3401             }
3402             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)" );
3403             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
3404             if ( t5.getNumberOfExternalNodes() != 8 ) {
3405                 return false;
3406             }
3407             if ( t5.calculateHeight( false ) != 15 ) {
3408                 return false;
3409             }
3410             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)" );
3411             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
3412             if ( t6.calculateHeight( true ) != 15 ) {
3413                 return false;
3414             }
3415             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)" );
3416             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
3417             if ( t7.calculateHeight( true ) != 15 ) {
3418                 return false;
3419             }
3420             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)" );
3421             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
3422             if ( t8.getNumberOfExternalNodes() != 10 ) {
3423                 return false;
3424             }
3425             if ( t8.calculateHeight( true ) != 15 ) {
3426                 return false;
3427             }
3428             final char[] a9 = new char[] { 'a' };
3429             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
3430             if ( t9.calculateHeight( true ) != 0 ) {
3431                 return false;
3432             }
3433             final char[] a10 = new char[] { 'a', ':', '6' };
3434             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
3435             if ( t10.calculateHeight( true ) != 6 ) {
3436                 return false;
3437             }
3438         }
3439         catch ( final Exception e ) {
3440             e.printStackTrace( System.out );
3441             return false;
3442         }
3443         return true;
3444     }
3445
3446     private static boolean testConfidenceAssessor() {
3447         try {
3448             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3449             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3450             final Phylogeny[] ev0 = factory.create(
3451                                                     "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3452                                                     new NHXParser() );
3453             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3454             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3455                 return false;
3456             }
3457             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3458                 return false;
3459             }
3460             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3461             final Phylogeny[] ev1 = factory.create(
3462                                                     "((((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)));",
3463                                                     new NHXParser() );
3464             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3465             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3466                 return false;
3467             }
3468             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3469                 return false;
3470             }
3471             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3472             final Phylogeny[] ev_b = factory.create(
3473                                                      "((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",
3474                                                      new NHXParser() );
3475             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3476             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3477                 return false;
3478             }
3479             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3480                 return false;
3481             }
3482             //
3483             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3484             final Phylogeny[] ev1x = factory.create(
3485                                                      "((((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)));",
3486                                                      new NHXParser() );
3487             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3488             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3489                 return false;
3490             }
3491             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3492                 return false;
3493             }
3494             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3495             final Phylogeny[] ev_bx = factory.create(
3496                                                       "((((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",
3497                                                       new NHXParser() );
3498             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3499             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3500                 return false;
3501             }
3502             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3503                 return false;
3504             }
3505             final Phylogeny[] t2 = factory.create(
3506                                                    "((((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);",
3507                                                    new NHXParser() );
3508             final Phylogeny[] ev2 = factory.create(
3509                                                     "((((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);",
3510                                                     new NHXParser() );
3511             for( final Phylogeny target : t2 ) {
3512                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3513             }
3514             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3515                                                  new NHXParser() )[ 0 ];
3516             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3517             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3518             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3519                 return false;
3520             }
3521             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3522                 return false;
3523             }
3524             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3525                 return false;
3526             }
3527         }
3528         catch ( final Exception e ) {
3529             e.printStackTrace();
3530             return false;
3531         }
3532         return true;
3533     }
3534
3535     private static boolean testCopyOfNodeData() {
3536         try {
3537             final PhylogenyNode n1 = PhylogenyNode
3538                     .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]" );
3539             final PhylogenyNode n2 = n1.copyNodeData();
3540             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3541                 return false;
3542             }
3543         }
3544         catch ( final Exception e ) {
3545             e.printStackTrace();
3546             return false;
3547         }
3548         return true;
3549     }
3550
3551     private static boolean testCreateBalancedPhylogeny() {
3552         try {
3553             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3554             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3555                 return false;
3556             }
3557             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3558                 return false;
3559             }
3560             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3561             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3562                 return false;
3563             }
3564             if ( p1.getNumberOfExternalNodes() != 100 ) {
3565                 return false;
3566             }
3567         }
3568         catch ( final Exception e ) {
3569             e.printStackTrace();
3570             return false;
3571         }
3572         return true;
3573     }
3574
3575     private static boolean testCreateUriForSeqWeb() {
3576         try {
3577             final PhylogenyNode n = new PhylogenyNode();
3578             n.setName( "tr|B3RJ64" );
3579             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3580                 return false;
3581             }
3582             n.setName( "B0LM41_HUMAN" );
3583             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3584                     .equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3585                 return false;
3586             }
3587             n.setName( "NP_001025424" );
3588             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3589                     .equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3590                 return false;
3591             }
3592             n.setName( "_NM_001030253-" );
3593             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3594                     .equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3595                 return false;
3596             }
3597             n.setName( "XM_002122186" );
3598             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3599                     .equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3600                 return false;
3601             }
3602             n.setName( "dgh_AAA34956_gdg" );
3603             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3604                 return false;
3605             }
3606             n.setName( "AAA34956" );
3607             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3608                 return false;
3609             }
3610             n.setName( "GI:394892" );
3611             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3612                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3613                 return false;
3614             }
3615             n.setName( "gi_394892" );
3616             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3617                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3618                 return false;
3619             }
3620             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3621             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3622                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3623                 return false;
3624             }
3625             n.setName( "P12345" );
3626             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3627                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3628                 return false;
3629             }
3630             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3631             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3632                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3633                 return false;
3634             }
3635         }
3636         catch ( final Exception e ) {
3637             e.printStackTrace( System.out );
3638             return false;
3639         }
3640         return true;
3641     }
3642
3643     private static boolean testDataObjects() {
3644         try {
3645             final Confidence s0 = new Confidence();
3646             final Confidence s1 = new Confidence();
3647             if ( !s0.isEqual( s1 ) ) {
3648                 return false;
3649             }
3650             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3651             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3652             if ( s2.isEqual( s1 ) ) {
3653                 return false;
3654             }
3655             if ( !s2.isEqual( s3 ) ) {
3656                 return false;
3657             }
3658             final Confidence s4 = ( Confidence ) s3.copy();
3659             if ( !s4.isEqual( s3 ) ) {
3660                 return false;
3661             }
3662             s3.asSimpleText();
3663             s3.asText();
3664             // Taxonomy
3665             // ----------
3666             final Taxonomy t1 = new Taxonomy();
3667             final Taxonomy t2 = new Taxonomy();
3668             final Taxonomy t3 = new Taxonomy();
3669             final Taxonomy t4 = new Taxonomy();
3670             final Taxonomy t5 = new Taxonomy();
3671             t1.setIdentifier( new Identifier( "ecoli" ) );
3672             t1.setTaxonomyCode( "ECOLI" );
3673             t1.setScientificName( "E. coli" );
3674             t1.setCommonName( "coli" );
3675             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3676             if ( !t1.isEqual( t0 ) ) {
3677                 return false;
3678             }
3679             t2.setIdentifier( new Identifier( "ecoli" ) );
3680             t2.setTaxonomyCode( "OTHER" );
3681             t2.setScientificName( "what" );
3682             t2.setCommonName( "something" );
3683             if ( !t1.isEqual( t2 ) ) {
3684                 return false;
3685             }
3686             t2.setIdentifier( new Identifier( "nemve" ) );
3687             if ( t1.isEqual( t2 ) ) {
3688                 return false;
3689             }
3690             t1.setIdentifier( null );
3691             t3.setTaxonomyCode( "ECOLI" );
3692             t3.setScientificName( "what" );
3693             t3.setCommonName( "something" );
3694             if ( !t1.isEqual( t3 ) ) {
3695                 return false;
3696             }
3697             t1.setIdentifier( null );
3698             t1.setTaxonomyCode( "" );
3699             t4.setScientificName( "E. ColI" );
3700             t4.setCommonName( "something" );
3701             if ( !t1.isEqual( t4 ) ) {
3702                 return false;
3703             }
3704             t4.setScientificName( "B. subtilis" );
3705             t4.setCommonName( "something" );
3706             if ( t1.isEqual( t4 ) ) {
3707                 return false;
3708             }
3709             t1.setIdentifier( null );
3710             t1.setTaxonomyCode( "" );
3711             t1.setScientificName( "" );
3712             t5.setCommonName( "COLI" );
3713             if ( !t1.isEqual( t5 ) ) {
3714                 return false;
3715             }
3716             t5.setCommonName( "vibrio" );
3717             if ( t1.isEqual( t5 ) ) {
3718                 return false;
3719             }
3720             // Identifier
3721             // ----------
3722             final Identifier id0 = new Identifier( "123", "pfam" );
3723             final Identifier id1 = ( Identifier ) id0.copy();
3724             if ( !id1.isEqual( id1 ) ) {
3725                 return false;
3726             }
3727             if ( !id1.isEqual( id0 ) ) {
3728                 return false;
3729             }
3730             if ( !id0.isEqual( id1 ) ) {
3731                 return false;
3732             }
3733             id1.asSimpleText();
3734             id1.asText();
3735             // ProteinDomain
3736             // ---------------
3737             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3738             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3739             if ( !pd1.isEqual( pd1 ) ) {
3740                 return false;
3741             }
3742             if ( !pd1.isEqual( pd0 ) ) {
3743                 return false;
3744             }
3745             pd1.asSimpleText();
3746             pd1.asText();
3747             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3748             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3749             if ( !pd3.isEqual( pd3 ) ) {
3750                 return false;
3751             }
3752             if ( !pd2.isEqual( pd3 ) ) {
3753                 return false;
3754             }
3755             if ( !pd0.isEqual( pd3 ) ) {
3756                 return false;
3757             }
3758             pd3.asSimpleText();
3759             pd3.asText();
3760             // DomainArchitecture
3761             // ------------------
3762             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3763             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3764             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3765             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3766             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3767             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3768             domains0.add( d2 );
3769             domains0.add( d0 );
3770             domains0.add( d3 );
3771             domains0.add( d1 );
3772             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3773             if ( ds0.getNumberOfDomains() != 4 ) {
3774                 return false;
3775             }
3776             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3777             if ( !ds0.isEqual( ds0 ) ) {
3778                 return false;
3779             }
3780             if ( !ds0.isEqual( ds1 ) ) {
3781                 return false;
3782             }
3783             if ( ds1.getNumberOfDomains() != 4 ) {
3784                 return false;
3785             }
3786             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3787             domains1.add( d1 );
3788             domains1.add( d2 );
3789             domains1.add( d4 );
3790             domains1.add( d0 );
3791             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3792             if ( ds0.isEqual( ds2 ) ) {
3793                 return false;
3794             }
3795             ds1.asSimpleText();
3796             ds1.asText();
3797             ds1.toNHX();
3798             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3799             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3800                 System.out.println( ds3.toNHX() );
3801                 return false;
3802             }
3803             if ( ds3.getNumberOfDomains() != 3 ) {
3804                 return false;
3805             }
3806             // Event
3807             // -----
3808             final Event e1 = new Event( Event.EventType.fusion );
3809             if ( e1.isDuplication() ) {
3810                 return false;
3811             }
3812             if ( !e1.isFusion() ) {
3813                 return false;
3814             }
3815             if ( !e1.asText().toString().equals( "fusion" ) ) {
3816                 return false;
3817             }
3818             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3819                 return false;
3820             }
3821             final Event e11 = new Event( Event.EventType.fusion );
3822             if ( !e11.isEqual( e1 ) ) {
3823                 return false;
3824             }
3825             if ( !e11.toNHX().toString().equals( "" ) ) {
3826                 return false;
3827             }
3828             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3829             if ( e2.isDuplication() ) {
3830                 return false;
3831             }
3832             if ( !e2.isSpeciationOrDuplication() ) {
3833                 return false;
3834             }
3835             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3836                 return false;
3837             }
3838             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3839                 return false;
3840             }
3841             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3842                 return false;
3843             }
3844             if ( e11.isEqual( e2 ) ) {
3845                 return false;
3846             }
3847             final Event e2c = ( Event ) e2.copy();
3848             if ( !e2c.isEqual( e2 ) ) {
3849                 return false;
3850             }
3851             Event e3 = new Event( 1, 2, 3 );
3852             if ( e3.isDuplication() ) {
3853                 return false;
3854             }
3855             if ( e3.isSpeciation() ) {
3856                 return false;
3857             }
3858             if ( e3.isGeneLoss() ) {
3859                 return false;
3860             }
3861             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3862                 return false;
3863             }
3864             final Event e3c = ( Event ) e3.copy();
3865             final Event e3cc = ( Event ) e3c.copy();
3866             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3867                 return false;
3868             }
3869             e3 = null;
3870             if ( !e3c.isEqual( e3cc ) ) {
3871                 return false;
3872             }
3873             Event e4 = new Event( 1, 2, 3 );
3874             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3875                 return false;
3876             }
3877             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3878                 return false;
3879             }
3880             final Event e4c = ( Event ) e4.copy();
3881             e4 = null;
3882             final Event e4cc = ( Event ) e4c.copy();
3883             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3884                 return false;
3885             }
3886             if ( !e4c.isEqual( e4cc ) ) {
3887                 return false;
3888             }
3889             final Event e5 = new Event();
3890             if ( !e5.isUnassigned() ) {
3891                 return false;
3892             }
3893             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3894                 return false;
3895             }
3896             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3897                 return false;
3898             }
3899             final Event e6 = new Event( 1, 0, 0 );
3900             if ( !e6.asText().toString().equals( "duplication" ) ) {
3901                 return false;
3902             }
3903             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3904                 return false;
3905             }
3906             final Event e7 = new Event( 0, 1, 0 );
3907             if ( !e7.asText().toString().equals( "speciation" ) ) {
3908                 return false;
3909             }
3910             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3911                 return false;
3912             }
3913             final Event e8 = new Event( 0, 0, 1 );
3914             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3915                 return false;
3916             }
3917             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3918                 return false;
3919             }
3920         }
3921         catch ( final Exception e ) {
3922             e.printStackTrace( System.out );
3923             return false;
3924         }
3925         return true;
3926     }
3927
3928     private static boolean testDeletionOfExternalNodes() {
3929         try {
3930             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3931             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3932             final PhylogenyWriter w = new PhylogenyWriter();
3933             if ( t0.isEmpty() ) {
3934                 return false;
3935             }
3936             if ( t0.getNumberOfExternalNodes() != 1 ) {
3937                 return false;
3938             }
3939             t0.deleteSubtree( t0.getNode( "A" ), false );
3940             if ( t0.getNumberOfExternalNodes() != 0 ) {
3941                 return false;
3942             }
3943             if ( !t0.isEmpty() ) {
3944                 return false;
3945             }
3946             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3947             if ( t1.getNumberOfExternalNodes() != 2 ) {
3948                 return false;
3949             }
3950             t1.deleteSubtree( t1.getNode( "A" ), false );
3951             if ( t1.getNumberOfExternalNodes() != 1 ) {
3952                 return false;
3953             }
3954             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3955                 return false;
3956             }
3957             t1.deleteSubtree( t1.getNode( "B" ), false );
3958             if ( t1.getNumberOfExternalNodes() != 1 ) {
3959                 return false;
3960             }
3961             t1.deleteSubtree( t1.getNode( "r" ), false );
3962             if ( !t1.isEmpty() ) {
3963                 return false;
3964             }
3965             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3966             if ( t2.getNumberOfExternalNodes() != 3 ) {
3967                 return false;
3968             }
3969             t2.deleteSubtree( t2.getNode( "B" ), false );
3970             if ( t2.getNumberOfExternalNodes() != 2 ) {
3971                 return false;
3972             }
3973             t2.toNewHampshireX();
3974             PhylogenyNode n = t2.getNode( "A" );
3975             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3976                 return false;
3977             }
3978             t2.deleteSubtree( t2.getNode( "A" ), false );
3979             if ( t2.getNumberOfExternalNodes() != 2 ) {
3980                 return false;
3981             }
3982             t2.deleteSubtree( t2.getNode( "C" ), true );
3983             if ( t2.getNumberOfExternalNodes() != 1 ) {
3984                 return false;
3985             }
3986             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3987             if ( t3.getNumberOfExternalNodes() != 4 ) {
3988                 return false;
3989             }
3990             t3.deleteSubtree( t3.getNode( "B" ), true );
3991             if ( t3.getNumberOfExternalNodes() != 3 ) {
3992                 return false;
3993             }
3994             n = t3.getNode( "A" );
3995             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3996                 return false;
3997             }
3998             n = n.getNextExternalNode();
3999             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
4000                 return false;
4001             }
4002             t3.deleteSubtree( t3.getNode( "A" ), true );
4003             if ( t3.getNumberOfExternalNodes() != 2 ) {
4004                 return false;
4005             }
4006             n = t3.getNode( "C" );
4007             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
4008                 return false;
4009             }
4010             t3.deleteSubtree( t3.getNode( "C" ), true );
4011             if ( t3.getNumberOfExternalNodes() != 1 ) {
4012                 return false;
4013             }
4014             t3.deleteSubtree( t3.getNode( "D" ), true );
4015             if ( t3.getNumberOfExternalNodes() != 0 ) {
4016                 return false;
4017             }
4018             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4019             if ( t4.getNumberOfExternalNodes() != 6 ) {
4020                 return false;
4021             }
4022             t4.deleteSubtree( t4.getNode( "B2" ), true );
4023             if ( t4.getNumberOfExternalNodes() != 5 ) {
4024                 return false;
4025             }
4026             String s = w.toNewHampshire( t4, true ).toString();
4027             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
4028                 return false;
4029             }
4030             t4.deleteSubtree( t4.getNode( "B11" ), true );
4031             if ( t4.getNumberOfExternalNodes() != 4 ) {
4032                 return false;
4033             }
4034             t4.deleteSubtree( t4.getNode( "C" ), true );
4035             if ( t4.getNumberOfExternalNodes() != 3 ) {
4036                 return false;
4037             }
4038             n = t4.getNode( "A" );
4039             n = n.getNextExternalNode();
4040             if ( !n.getName().equals( "B12" ) ) {
4041                 return false;
4042             }
4043             n = n.getNextExternalNode();
4044             if ( !n.getName().equals( "D" ) ) {
4045                 return false;
4046             }
4047             s = w.toNewHampshire( t4, true ).toString();
4048             if ( !s.equals( "((A,B12),D);" ) ) {
4049                 return false;
4050             }
4051             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4052             t5.deleteSubtree( t5.getNode( "A" ), true );
4053             if ( t5.getNumberOfExternalNodes() != 5 ) {
4054                 return false;
4055             }
4056             s = w.toNewHampshire( t5, true ).toString();
4057             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
4058                 return false;
4059             }
4060             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4061             t6.deleteSubtree( t6.getNode( "B11" ), true );
4062             if ( t6.getNumberOfExternalNodes() != 5 ) {
4063                 return false;
4064             }
4065             s = w.toNewHampshire( t6, false ).toString();
4066             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
4067                 return false;
4068             }
4069             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4070             t7.deleteSubtree( t7.getNode( "B12" ), true );
4071             if ( t7.getNumberOfExternalNodes() != 5 ) {
4072                 return false;
4073             }
4074             s = w.toNewHampshire( t7, true ).toString();
4075             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
4076                 return false;
4077             }
4078             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4079             t8.deleteSubtree( t8.getNode( "B2" ), true );
4080             if ( t8.getNumberOfExternalNodes() != 5 ) {
4081                 return false;
4082             }
4083             s = w.toNewHampshire( t8, false ).toString();
4084             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
4085                 return false;
4086             }
4087             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4088             t9.deleteSubtree( t9.getNode( "C" ), true );
4089             if ( t9.getNumberOfExternalNodes() != 5 ) {
4090                 return false;
4091             }
4092             s = w.toNewHampshire( t9, true ).toString();
4093             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
4094                 return false;
4095             }
4096             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4097             t10.deleteSubtree( t10.getNode( "D" ), true );
4098             if ( t10.getNumberOfExternalNodes() != 5 ) {
4099                 return false;
4100             }
4101             s = w.toNewHampshire( t10, true ).toString();
4102             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
4103                 return false;
4104             }
4105             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
4106             t11.deleteSubtree( t11.getNode( "A" ), true );
4107             if ( t11.getNumberOfExternalNodes() != 2 ) {
4108                 return false;
4109             }
4110             s = w.toNewHampshire( t11, true ).toString();
4111             if ( !s.equals( "(B,C);" ) ) {
4112                 return false;
4113             }
4114             t11.deleteSubtree( t11.getNode( "C" ), true );
4115             if ( t11.getNumberOfExternalNodes() != 1 ) {
4116                 return false;
4117             }
4118             s = w.toNewHampshire( t11, false ).toString();
4119             if ( !s.equals( "B;" ) ) {
4120                 return false;
4121             }
4122             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
4123             t12.deleteSubtree( t12.getNode( "B2" ), true );
4124             if ( t12.getNumberOfExternalNodes() != 8 ) {
4125                 return false;
4126             }
4127             s = w.toNewHampshire( t12, true ).toString();
4128             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
4129                 return false;
4130             }
4131             t12.deleteSubtree( t12.getNode( "B3" ), true );
4132             if ( t12.getNumberOfExternalNodes() != 7 ) {
4133                 return false;
4134             }
4135             s = w.toNewHampshire( t12, true ).toString();
4136             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
4137                 return false;
4138             }
4139             t12.deleteSubtree( t12.getNode( "C3" ), true );
4140             if ( t12.getNumberOfExternalNodes() != 6 ) {
4141                 return false;
4142             }
4143             s = w.toNewHampshire( t12, true ).toString();
4144             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
4145                 return false;
4146             }
4147             t12.deleteSubtree( t12.getNode( "A1" ), true );
4148             if ( t12.getNumberOfExternalNodes() != 5 ) {
4149                 return false;
4150             }
4151             s = w.toNewHampshire( t12, true ).toString();
4152             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
4153                 return false;
4154             }
4155             t12.deleteSubtree( t12.getNode( "B1" ), true );
4156             if ( t12.getNumberOfExternalNodes() != 4 ) {
4157                 return false;
4158             }
4159             s = w.toNewHampshire( t12, true ).toString();
4160             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
4161                 return false;
4162             }
4163             t12.deleteSubtree( t12.getNode( "A3" ), true );
4164             if ( t12.getNumberOfExternalNodes() != 3 ) {
4165                 return false;
4166             }
4167             s = w.toNewHampshire( t12, true ).toString();
4168             if ( !s.equals( "(A2,(C1,C2));" ) ) {
4169                 return false;
4170             }
4171             t12.deleteSubtree( t12.getNode( "A2" ), true );
4172             if ( t12.getNumberOfExternalNodes() != 2 ) {
4173                 return false;
4174             }
4175             s = w.toNewHampshire( t12, true ).toString();
4176             if ( !s.equals( "(C1,C2);" ) ) {
4177                 return false;
4178             }
4179             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
4180             t13.deleteSubtree( t13.getNode( "D" ), true );
4181             if ( t13.getNumberOfExternalNodes() != 4 ) {
4182                 return false;
4183             }
4184             s = w.toNewHampshire( t13, true ).toString();
4185             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
4186                 return false;
4187             }
4188             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
4189             t14.deleteSubtree( t14.getNode( "E" ), true );
4190             if ( t14.getNumberOfExternalNodes() != 5 ) {
4191                 return false;
4192             }
4193             s = w.toNewHampshire( t14, true ).toString();
4194             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
4195                 return false;
4196             }
4197             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
4198             t15.deleteSubtree( t15.getNode( "B2" ), true );
4199             if ( t15.getNumberOfExternalNodes() != 11 ) {
4200                 return false;
4201             }
4202             t15.deleteSubtree( t15.getNode( "B1" ), true );
4203             if ( t15.getNumberOfExternalNodes() != 10 ) {
4204                 return false;
4205             }
4206             t15.deleteSubtree( t15.getNode( "B3" ), true );
4207             if ( t15.getNumberOfExternalNodes() != 9 ) {
4208                 return false;
4209             }
4210             t15.deleteSubtree( t15.getNode( "B4" ), true );
4211             if ( t15.getNumberOfExternalNodes() != 8 ) {
4212                 return false;
4213             }
4214             t15.deleteSubtree( t15.getNode( "A1" ), true );
4215             if ( t15.getNumberOfExternalNodes() != 7 ) {
4216                 return false;
4217             }
4218             t15.deleteSubtree( t15.getNode( "C4" ), true );
4219             if ( t15.getNumberOfExternalNodes() != 6 ) {
4220                 return false;
4221             }
4222         }
4223         catch ( final Exception e ) {
4224             e.printStackTrace( System.out );
4225             return false;
4226         }
4227         return true;
4228     }
4229
4230     private static boolean testDescriptiveStatistics() {
4231         try {
4232             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
4233             dss1.addValue( 82 );
4234             dss1.addValue( 78 );
4235             dss1.addValue( 70 );
4236             dss1.addValue( 58 );
4237             dss1.addValue( 42 );
4238             if ( dss1.getN() != 5 ) {
4239                 return false;
4240             }
4241             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
4242                 return false;
4243             }
4244             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
4245                 return false;
4246             }
4247             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
4248                 return false;
4249             }
4250             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
4251                 return false;
4252             }
4253             if ( !Test.isEqual( dss1.median(), 70 ) ) {
4254                 return false;
4255             }
4256             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
4257                 return false;
4258             }
4259             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
4260                 return false;
4261             }
4262             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
4263                 return false;
4264             }
4265             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
4266                 return false;
4267             }
4268             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
4269                 return false;
4270             }
4271             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
4272                 return false;
4273             }
4274             dss1.addValue( 123 );
4275             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
4276                 return false;
4277             }
4278             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
4279                 return false;
4280             }
4281             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
4282                 return false;
4283             }
4284             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
4285             dss2.addValue( -1.85 );
4286             dss2.addValue( 57.5 );
4287             dss2.addValue( 92.78 );
4288             dss2.addValue( 57.78 );
4289             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
4290                 return false;
4291             }
4292             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
4293                 return false;
4294             }
4295             final double[] a = dss2.getDataAsDoubleArray();
4296             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
4297                 return false;
4298             }
4299             dss2.addValue( -100 );
4300             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
4301                 return false;
4302             }
4303             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
4304                 return false;
4305             }
4306             final double[] ds = new double[ 14 ];
4307             ds[ 0 ] = 34;
4308             ds[ 1 ] = 23;
4309             ds[ 2 ] = 1;
4310             ds[ 3 ] = 32;
4311             ds[ 4 ] = 11;
4312             ds[ 5 ] = 2;
4313             ds[ 6 ] = 12;
4314             ds[ 7 ] = 33;
4315             ds[ 8 ] = 13;
4316             ds[ 9 ] = 22;
4317             ds[ 10 ] = 21;
4318             ds[ 11 ] = 35;
4319             ds[ 12 ] = 24;
4320             ds[ 13 ] = 31;
4321             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
4322             if ( bins.length != 4 ) {
4323                 return false;
4324             }
4325             if ( bins[ 0 ] != 2 ) {
4326                 return false;
4327             }
4328             if ( bins[ 1 ] != 3 ) {
4329                 return false;
4330             }
4331             if ( bins[ 2 ] != 4 ) {
4332                 return false;
4333             }
4334             if ( bins[ 3 ] != 5 ) {
4335                 return false;
4336             }
4337             final double[] ds1 = new double[ 9 ];
4338             ds1[ 0 ] = 10.0;
4339             ds1[ 1 ] = 19.0;
4340             ds1[ 2 ] = 9.999;
4341             ds1[ 3 ] = 0.0;
4342             ds1[ 4 ] = 39.9;
4343             ds1[ 5 ] = 39.999;
4344             ds1[ 6 ] = 30.0;
4345             ds1[ 7 ] = 19.999;
4346             ds1[ 8 ] = 30.1;
4347             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
4348             if ( bins1.length != 4 ) {
4349                 return false;
4350             }
4351             if ( bins1[ 0 ] != 2 ) {
4352                 return false;
4353             }
4354             if ( bins1[ 1 ] != 3 ) {
4355                 return false;
4356             }
4357             if ( bins1[ 2 ] != 0 ) {
4358                 return false;
4359             }
4360             if ( bins1[ 3 ] != 4 ) {
4361                 return false;
4362             }
4363             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
4364             if ( bins1_1.length != 3 ) {
4365                 return false;
4366             }
4367             if ( bins1_1[ 0 ] != 3 ) {
4368                 return false;
4369             }
4370             if ( bins1_1[ 1 ] != 2 ) {
4371                 return false;
4372             }
4373             if ( bins1_1[ 2 ] != 4 ) {
4374                 return false;
4375             }
4376             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
4377             if ( bins1_2.length != 3 ) {
4378                 return false;
4379             }
4380             if ( bins1_2[ 0 ] != 2 ) {
4381                 return false;
4382             }
4383             if ( bins1_2[ 1 ] != 2 ) {
4384                 return false;
4385             }
4386             if ( bins1_2[ 2 ] != 2 ) {
4387                 return false;
4388             }
4389             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
4390             dss3.addValue( 1 );
4391             dss3.addValue( 1 );
4392             dss3.addValue( 1 );
4393             dss3.addValue( 2 );
4394             dss3.addValue( 3 );
4395             dss3.addValue( 4 );
4396             dss3.addValue( 5 );
4397             dss3.addValue( 5 );
4398             dss3.addValue( 5 );
4399             dss3.addValue( 6 );
4400             dss3.addValue( 7 );
4401             dss3.addValue( 8 );
4402             dss3.addValue( 9 );
4403             dss3.addValue( 10 );
4404             dss3.addValue( 10 );
4405             dss3.addValue( 10 );
4406             final AsciiHistogram histo = new AsciiHistogram( dss3 );
4407             histo.toStringBuffer( 10, '=', 40, 5 );
4408             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
4409         }
4410         catch ( final Exception e ) {
4411             e.printStackTrace( System.out );
4412             return false;
4413         }
4414         return true;
4415     }
4416
4417     private static boolean testDir( final String file ) {
4418         try {
4419             final File f = new File( file );
4420             if ( !f.exists() ) {
4421                 return false;
4422             }
4423             if ( !f.isDirectory() ) {
4424                 return false;
4425             }
4426             if ( !f.canRead() ) {
4427                 return false;
4428             }
4429         }
4430         catch ( final Exception e ) {
4431             return false;
4432         }
4433         return true;
4434     }
4435
4436     private static boolean testEbiEntryRetrieval() {
4437         try {
4438             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
4439             if ( !entry.getAccession().equals( "AAK41263" ) ) {
4440                 System.out.println( entry.getAccession() );
4441                 return false;
4442             }
4443             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
4444                 System.out.println( entry.getTaxonomyScientificName() );
4445                 return false;
4446             }
4447             if ( !entry.getSequenceName()
4448                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4449                 System.out.println( entry.getSequenceName() );
4450                 return false;
4451             }
4452             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4453                 System.out.println( entry.getGeneName() );
4454                 return false;
4455             }
4456             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4457                 System.out.println( entry.getTaxonomyIdentifier() );
4458                 return false;
4459             }
4460             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4461                 System.out.println( entry.getAnnotations().first().getRefValue() );
4462                 return false;
4463             }
4464             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4465                 System.out.println( entry.getAnnotations().first().getRefSource() );
4466                 return false;
4467             }
4468             if ( entry.getCrossReferences().size() < 1 ) {
4469                 return false;
4470             }
4471             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4472             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4473                 return false;
4474             }
4475             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4476                 System.out.println( entry1.getTaxonomyScientificName() );
4477                 return false;
4478             }
4479             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4480                 System.out.println( entry1.getSequenceName() );
4481                 return false;
4482             }
4483             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4484                 System.out.println( entry1.getTaxonomyIdentifier() );
4485                 return false;
4486             }
4487             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4488                 System.out.println( entry1.getGeneName() );
4489                 return false;
4490             }
4491             if ( entry1.getCrossReferences().size() < 1 ) {
4492                 return false;
4493             }
4494             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4495             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4496                 return false;
4497             }
4498             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4499                 System.out.println( entry2.getTaxonomyScientificName() );
4500                 return false;
4501             }
4502             if ( !entry2.getSequenceName()
4503                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4504                 System.out.println( entry2.getSequenceName() );
4505                 return false;
4506             }
4507             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4508                 System.out.println( entry2.getTaxonomyIdentifier() );
4509                 return false;
4510             }
4511             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4512                 System.out.println( entry2.getGeneName() );
4513                 return false;
4514             }
4515             if ( entry2.getCrossReferences().size() < 1 ) {
4516                 return false;
4517             }
4518             if ( !entry2.getChromosome().equals( "20" ) ) {
4519                 return false;
4520             }
4521             if ( !entry2.getMap().equals( "20q11.22" ) ) {
4522                 return false;
4523             }
4524             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4525             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4526                 return false;
4527             }
4528             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4529                 System.out.println( entry3.getTaxonomyScientificName() );
4530                 return false;
4531             }
4532             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4533                 System.out.println( entry3.getSequenceName() );
4534                 return false;
4535             }
4536             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4537                 System.out.println( entry3.getTaxonomyIdentifier() );
4538                 return false;
4539             }
4540             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4541                 System.out.println( entry3.getSequenceSymbol() );
4542                 return false;
4543             }
4544             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4545                 return false;
4546             }
4547             if ( entry3.getCrossReferences().size() < 1 ) {
4548                 return false;
4549             }
4550             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4551             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4552                 return false;
4553             }
4554             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4555                 System.out.println( entry4.getTaxonomyScientificName() );
4556                 return false;
4557             }
4558             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4559                 System.out.println( entry4.getSequenceName() );
4560                 return false;
4561             }
4562             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4563                 System.out.println( entry4.getTaxonomyIdentifier() );
4564                 return false;
4565             }
4566             if ( !entry4.getGeneName().equals( "ras" ) ) {
4567                 System.out.println( entry4.getGeneName() );
4568                 return false;
4569             }
4570             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4571             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4572                 return false;
4573             }
4574             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4575                 System.out.println( entry5.getTaxonomyScientificName() );
4576                 return false;
4577             }
4578             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4579                 System.out.println( entry5.getSequenceName() );
4580                 return false;
4581             }
4582             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4583                 System.out.println( entry5.getTaxonomyIdentifier() );
4584                 return false;
4585             }
4586             final SequenceDatabaseEntry entry6 = SequenceDbWsTools.obtainEntry( "M30539" );
4587             if ( !entry6.getAccession().equals( "M30539" ) ) {
4588                 return false;
4589             }
4590             if ( !entry6.getGeneName().equals( "ras" ) ) {
4591                 return false;
4592             }
4593             if ( !entry6.getSequenceName().equals( "Human SK2 c-Ha-ras-1 oncogene-encoded protein gene, exon 1" ) ) {
4594                 return false;
4595             }
4596             if ( !entry6.getTaxonomyIdentifier().equals( "9606" ) ) {
4597                 return false;
4598             }
4599             if ( !entry6.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4600                 return false;
4601             }
4602             if ( entry6.getCrossReferences().size() < 1 ) {
4603                 return false;
4604             }
4605         }
4606         catch ( final IOException e ) {
4607             System.out.println();
4608             System.out.println( "the following might be due to absence internet connection:" );
4609             e.printStackTrace( System.out );
4610             return true;
4611         }
4612         catch ( final Exception e ) {
4613             e.printStackTrace();
4614             return false;
4615         }
4616         return true;
4617     }
4618
4619     private static boolean testExternalNodeRelatedMethods() {
4620         try {
4621             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4622             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4623             PhylogenyNode n = t1.getNode( "A" );
4624             n = n.getNextExternalNode();
4625             if ( !n.getName().equals( "B" ) ) {
4626                 return false;
4627             }
4628             n = n.getNextExternalNode();
4629             if ( !n.getName().equals( "C" ) ) {
4630                 return false;
4631             }
4632             n = n.getNextExternalNode();
4633             if ( !n.getName().equals( "D" ) ) {
4634                 return false;
4635             }
4636             n = t1.getNode( "B" );
4637             while ( !n.isLastExternalNode() ) {
4638                 n = n.getNextExternalNode();
4639             }
4640             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4641             n = t2.getNode( "A" );
4642             n = n.getNextExternalNode();
4643             if ( !n.getName().equals( "B" ) ) {
4644                 return false;
4645             }
4646             n = n.getNextExternalNode();
4647             if ( !n.getName().equals( "C" ) ) {
4648                 return false;
4649             }
4650             n = n.getNextExternalNode();
4651             if ( !n.getName().equals( "D" ) ) {
4652                 return false;
4653             }
4654             n = t2.getNode( "B" );
4655             while ( !n.isLastExternalNode() ) {
4656                 n = n.getNextExternalNode();
4657             }
4658             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4659             n = t3.getNode( "A" );
4660             n = n.getNextExternalNode();
4661             if ( !n.getName().equals( "B" ) ) {
4662                 return false;
4663             }
4664             n = n.getNextExternalNode();
4665             if ( !n.getName().equals( "C" ) ) {
4666                 return false;
4667             }
4668             n = n.getNextExternalNode();
4669             if ( !n.getName().equals( "D" ) ) {
4670                 return false;
4671             }
4672             n = n.getNextExternalNode();
4673             if ( !n.getName().equals( "E" ) ) {
4674                 return false;
4675             }
4676             n = n.getNextExternalNode();
4677             if ( !n.getName().equals( "F" ) ) {
4678                 return false;
4679             }
4680             n = n.getNextExternalNode();
4681             if ( !n.getName().equals( "G" ) ) {
4682                 return false;
4683             }
4684             n = n.getNextExternalNode();
4685             if ( !n.getName().equals( "H" ) ) {
4686                 return false;
4687             }
4688             n = t3.getNode( "B" );
4689             while ( !n.isLastExternalNode() ) {
4690                 n = n.getNextExternalNode();
4691             }
4692             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4693             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4694                 final PhylogenyNode node = iter.next();
4695             }
4696             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4697             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4698                 final PhylogenyNode node = iter.next();
4699             }
4700             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))",
4701                                                  new NHXParser() )[ 0 ];
4702             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4703             if ( !iter.next().getName().equals( "A" ) ) {
4704                 return false;
4705             }
4706             if ( !iter.next().getName().equals( "B" ) ) {
4707                 return false;
4708             }
4709             if ( !iter.next().getName().equals( "C" ) ) {
4710                 return false;
4711             }
4712             if ( !iter.next().getName().equals( "D" ) ) {
4713                 return false;
4714             }
4715             if ( !iter.next().getName().equals( "E" ) ) {
4716                 return false;
4717             }
4718             if ( !iter.next().getName().equals( "F" ) ) {
4719                 return false;
4720             }
4721             if ( iter.hasNext() ) {
4722                 return false;
4723             }
4724         }
4725         catch ( final Exception e ) {
4726             e.printStackTrace( System.out );
4727             return false;
4728         }
4729         return true;
4730     }
4731
4732     private static boolean testExtractSNFromNodeName() {
4733         try {
4734             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4735                 return false;
4736             }
4737             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4738                 return false;
4739             }
4740             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4741                 return false;
4742             }
4743             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4744                     .equals( "Mus musculus musculus" ) ) {
4745                 return false;
4746             }
4747             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4748                     .equals( "Mus musculus musculus" ) ) {
4749                 return false;
4750             }
4751             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4752                     .equals( "Mus musculus musculus" ) ) {
4753                 return false;
4754             }
4755             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4756                     .equals( "Mus musculus musculus" ) ) {
4757                 return false;
4758             }
4759             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4760                 return false;
4761             }
4762             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4763                     .equals( "Mus musculus musculus" ) ) {
4764                 return false;
4765             }
4766             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4767                     .equals( "Mus musculus musculus" ) ) {
4768                 return false;
4769             }
4770             if ( ParserUtils
4771                     .extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4772                 return false;
4773             }
4774             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4775                 return false;
4776             }
4777             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4778                 return false;
4779             }
4780             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4781                 return false;
4782             }
4783             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4784                     .equals( "Mus musculus musculus" ) ) {
4785                 return false;
4786             }
4787             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4788                 return false;
4789             }
4790             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4791                 return false;
4792             }
4793             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4794                 return false;
4795             }
4796             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4797                 return false;
4798             }
4799             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4800                 return false;
4801             }
4802             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4803                 return false;
4804             }
4805             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4806                 return false;
4807             }
4808             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4809                 return false;
4810             }
4811             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4812                     .equals( "Mus musculus" ) ) {
4813                 return false;
4814             }
4815             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4816                     .equals( "Mus musculus" ) ) {
4817                 return false;
4818             }
4819             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4820                 return false;
4821             }
4822             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4823                     .equals( "Mus musculus musculus" ) ) {
4824                 return false;
4825             }
4826             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4827                     .equals( "Mus musculus musculus" ) ) {
4828                 return false;
4829             }
4830             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4831                     .equals( "Mus musculus musculus" ) ) {
4832                 return false;
4833             }
4834             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4835                 return false;
4836             }
4837             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4838                     .equals( "Pilostyles mexicana" ) ) {
4839                 return false;
4840             }
4841             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4842                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4843                 return false;
4844             }
4845             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4846                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4847                 return false;
4848             }
4849             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4850                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4851                 return false;
4852             }
4853             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4854                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4855                 return false;
4856             }
4857             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4858                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4859                 return false;
4860             }
4861             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4862                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4863                 return false;
4864             }
4865             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4866                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4867                 return false;
4868             }
4869             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4870                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4871                 return false;
4872             }
4873             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4874                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4875                 return false;
4876             }
4877             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4878                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4879                 return false;
4880             }
4881             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4882                     .equals( "Escherichia coli (strain K12)" ) ) {
4883                 return false;
4884             }
4885             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4886                     .equals( "Escherichia coli (strain K12)" ) ) {
4887                 return false;
4888             }
4889             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4890                     .equals( "Escherichia coli (str. K12)" ) ) {
4891                 return false;
4892             }
4893             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4894                     .equals( "Escherichia coli (str. K12)" ) ) {
4895                 return false;
4896             }
4897             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4898                     .equals( "Escherichia coli (str. K12)" ) ) {
4899                 return false;
4900             }
4901             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4902                     .equals( "Escherichia coli (var. K12)" ) ) {
4903                 return false;
4904             }
4905             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4906                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4907                 return false;
4908             }
4909             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4910                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4911                 return false;
4912             }
4913             if ( !ParserUtils
4914                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4915                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4916                 return false;
4917             }
4918             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4919                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4920                 return false;
4921             }
4922             if ( !ParserUtils
4923                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4924                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4925                 return false;
4926             }
4927             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4928                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4929                 return false;
4930             }
4931             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4932                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4933                 return false;
4934             }
4935             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4936                 return false;
4937             }
4938             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4939                 return false;
4940             }
4941             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4942                 return false;
4943             }
4944             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4945                     .equals( "Macrocera sp." ) ) {
4946                 return false;
4947             }
4948             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4949                 return false;
4950             }
4951             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4952                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4953                 return false;
4954             }
4955             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4956                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4957                 return false;
4958             }
4959             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4960                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4961                 return false;
4962             }
4963             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4964                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4965                 return false;
4966             }
4967         }
4968         catch ( final Exception e ) {
4969             e.printStackTrace( System.out );
4970             return false;
4971         }
4972         return true;
4973     }
4974
4975     private static boolean testExtractTaxonomyDataFromNodeName() {
4976         try {
4977             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
4978             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4979                 return false;
4980             }
4981             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
4982             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4983                 return false;
4984             }
4985             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
4986             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4987                 return false;
4988             }
4989             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
4990             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4991                 return false;
4992             }
4993             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
4994             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4995                 return false;
4996             }
4997             n = new PhylogenyNode( "HNRPR_HUMAN" );
4998             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4999                 return false;
5000             }
5001             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
5002             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5003                 return false;
5004             }
5005         }
5006         catch ( final Exception e ) {
5007             e.printStackTrace( System.out );
5008             return false;
5009         }
5010         return true;
5011     }
5012
5013     private static boolean testExtractTaxonomyCodeFromNodeName() {
5014         try {
5015             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE",
5016                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5017                 return false;
5018             }
5019             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5020                     .equals( "SOYBN" ) ) {
5021                 return false;
5022             }
5023             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
5024                     .equals( "ARATH" ) ) {
5025                 return false;
5026             }
5027             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
5028                     .equals( "ARATH" ) ) {
5029                 return false;
5030             }
5031             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE )
5032                     .equals( "RAT" ) ) {
5033                 return false;
5034             }
5035             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE )
5036                     .equals( "RAT" ) ) {
5037                 return false;
5038             }
5039             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1",
5040                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5041                 return false;
5042             }
5043             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5044                     .equals( "SOYBN" ) ) {
5045                 return false;
5046             }
5047             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5048                     .equals( "SOYBN" ) ) {
5049                 return false;
5050             }
5051             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5052                     .equals( "SOYBN" ) ) {
5053                 return false;
5054             }
5055             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5056                     .equals( "SOYBN" ) ) {
5057                 return false;
5058             }
5059             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5060                     .equals( "SOYBN" ) ) {
5061                 return false;
5062             }
5063             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5064                     .equals( "SOYBN" ) ) {
5065                 return false;
5066             }
5067             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
5068                     .equals( "SOYBN" ) ) {
5069                 return false;
5070             }
5071             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
5072                     .equals( "SOYBN" ) ) {
5073                 return false;
5074             }
5075             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx",
5076                                                               TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
5077                 return false;
5078             }
5079             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
5080                     .equals( "SOYBN" ) ) {
5081                 return false;
5082             }
5083             if ( !ParserUtils
5084                     .extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5085                     .equals( "ECOLI" ) ) {
5086                 return false;
5087             }
5088             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blagg_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
5089                     .equals( "9YX45" ) ) {
5090                 return false;
5091             }
5092             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
5093                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5094                     .equals( "MOUSE" ) ) {
5095                 return false;
5096             }
5097             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
5098                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5099                     .equals( "MOUSE" ) ) {
5100                 return false;
5101             }
5102             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
5103                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5104                     .equals( "MOUSE" ) ) {
5105                 return false;
5106             }
5107             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
5108                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5109                 return false;
5110             }
5111             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
5112                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5113                 return false;
5114             }
5115             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5116                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5117                     .equals( "RAT" ) ) {
5118                 return false;
5119             }
5120             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5121                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5122                     .equals( "RAT" ) ) {
5123                 return false;
5124             }
5125             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
5126                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5127                     .equals( "RAT" ) ) {
5128                 return false;
5129             }
5130             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
5131                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5132                 return false;
5133             }
5134             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
5135                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5136                 return false;
5137             }
5138             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5139                     .equals( "RAT" ) ) {
5140                 return false;
5141             }
5142             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5143                     .equals( "PIG" ) ) {
5144                 return false;
5145             }
5146             if ( !ParserUtils
5147                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5148                     .equals( "MOUSE" ) ) {
5149                 return false;
5150             }
5151             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5152                     .equals( "MOUSE" ) ) {
5153                 return false;
5154             }
5155             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ",
5156                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5157                 return false;
5158             }
5159         }
5160         catch ( final Exception e ) {
5161             e.printStackTrace( System.out );
5162             return false;
5163         }
5164         return true;
5165     }
5166
5167     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
5168         try {
5169             PhylogenyNode n = new PhylogenyNode();
5170             n.setName( "tr|B3RJ64" );
5171             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5172                 return false;
5173             }
5174             n.setName( "tr.B3RJ64" );
5175             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5176                 return false;
5177             }
5178             n.setName( "tr=B3RJ64" );
5179             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5180                 return false;
5181             }
5182             n.setName( "tr-B3RJ64" );
5183             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5184                 return false;
5185             }
5186             n.setName( "tr/B3RJ64" );
5187             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5188                 return false;
5189             }
5190             n.setName( "tr\\B3RJ64" );
5191             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5192                 return false;
5193             }
5194             n.setName( "tr_B3RJ64" );
5195             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5196                 return false;
5197             }
5198             n.setName( " tr|B3RJ64 " );
5199             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5200                 return false;
5201             }
5202             n.setName( "-tr|B3RJ64-" );
5203             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5204                 return false;
5205             }
5206             n.setName( "-tr=B3RJ64-" );
5207             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5208                 return false;
5209             }
5210             n.setName( "_tr=B3RJ64_" );
5211             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5212                 return false;
5213             }
5214             n.setName( " tr_tr|B3RJ64_sp|123 " );
5215             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5216                 return false;
5217             }
5218             n.setName( "B3RJ64" );
5219             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5220                 return false;
5221             }
5222             n.setName( "sp|B3RJ64" );
5223             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5224                 return false;
5225             }
5226             n.setName( "sp|B3RJ64C" );
5227             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5228                 return false;
5229             }
5230             n.setName( "sp B3RJ64" );
5231             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5232                 return false;
5233             }
5234             n.setName( "sp|B3RJ6X" );
5235             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5236                 return false;
5237             }
5238             n.setName( "sp|B3RJ6" );
5239             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5240                 return false;
5241             }
5242             n.setName( "K1PYK7_CRAGI" );
5243             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5244                 return false;
5245             }
5246             n.setName( "K1PYK7_PEA" );
5247             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
5248                 return false;
5249             }
5250             n.setName( "K1PYK7_RAT" );
5251             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
5252                 return false;
5253             }
5254             n.setName( "K1PYK7_PIG" );
5255             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5256                 return false;
5257             }
5258             n.setName( "~K1PYK7_PIG~" );
5259             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5260                 return false;
5261             }
5262             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
5263             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5264                 return false;
5265             }
5266             n.setName( "K1PYKX_CRAGI" );
5267             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5268                 return false;
5269             }
5270             n.setName( "XXXXX_CRAGI" );
5271             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
5272                 return false;
5273             }
5274             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
5275             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
5276                 return false;
5277             }
5278             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
5279             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5280                 return false;
5281             }
5282             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
5283             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
5284                 return false;
5285             }
5286             n = new PhylogenyNode();
5287             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
5288             seq.setSymbol( "K1PYK7_CRAGI" );
5289             n.getNodeData().addSequence( seq );
5290             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5291                 return false;
5292             }
5293             seq.setSymbol( "tr|B3RJ64" );
5294             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5295                 return false;
5296             }
5297             n = new PhylogenyNode();
5298             seq = new org.forester.phylogeny.data.Sequence();
5299             seq.setName( "K1PYK7_CRAGI" );
5300             n.getNodeData().addSequence( seq );
5301             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5302                 return false;
5303             }
5304             seq.setName( "tr|B3RJ64" );
5305             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5306                 return false;
5307             }
5308             n = new PhylogenyNode();
5309             seq = new org.forester.phylogeny.data.Sequence();
5310             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
5311             n.getNodeData().addSequence( seq );
5312             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
5313                 return false;
5314             }
5315             n = new PhylogenyNode();
5316             seq = new org.forester.phylogeny.data.Sequence();
5317             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
5318             n.getNodeData().addSequence( seq );
5319             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5320                 return false;
5321             }
5322             //
5323             n = new PhylogenyNode();
5324             n.setName( "ACP19736" );
5325             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5326                 return false;
5327             }
5328             n = new PhylogenyNode();
5329             n.setName( "|ACP19736|" );
5330             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5331                 return false;
5332             }
5333         }
5334         catch ( final Exception e ) {
5335             e.printStackTrace( System.out );
5336             return false;
5337         }
5338         return true;
5339     }
5340
5341     private static boolean testFastaParser() {
5342         try {
5343             final FileInputStream fis1 = new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" );
5344             if ( !FastaParser.isLikelyFasta( fis1 ) ) {
5345                 fis1.close();
5346                 return false;
5347             }
5348             else {
5349                 fis1.close();
5350             }
5351             final FileInputStream fis2 = new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" );
5352             if ( FastaParser.isLikelyFasta( fis2 ) ) {
5353                 fis2.close();
5354                 return false;
5355             }
5356             else {
5357                 fis2.close();
5358             }
5359             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
5360             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
5361                 return false;
5362             }
5363             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
5364                 return false;
5365             }
5366             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
5367                 return false;
5368             }
5369             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
5370                 return false;
5371             }
5372             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
5373                 return false;
5374             }
5375             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
5376                 return false;
5377             }
5378         }
5379         catch ( final Exception e ) {
5380             e.printStackTrace();
5381             return false;
5382         }
5383         return true;
5384     }
5385
5386     private static boolean testGenbankAccessorParsing() {
5387         //The format for GenBank Accession numbers are:
5388         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
5389         //Protein:    3 letters + 5 numerals
5390         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
5391         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
5392             return false;
5393         }
5394         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
5395             return false;
5396         }
5397         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" )
5398                 .equals( "AY423861.24" ) ) {
5399             return false;
5400         }
5401         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
5402             return false;
5403         }
5404         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
5405             return false;
5406         }
5407         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
5408             return false;
5409         }
5410         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
5411             return false;
5412         }
5413         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
5414             return false;
5415         }
5416         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
5417             return false;
5418         }
5419         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
5420             return false;
5421         }
5422         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
5423             return false;
5424         }
5425         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
5426             return false;
5427         }
5428         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
5429             return false;
5430         }
5431         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
5432             return false;
5433         }
5434         return true;
5435     }
5436
5437     private static boolean testGeneralMsaParser() {
5438         try {
5439             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
5440             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
5441             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
5442             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
5443             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
5444             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
5445             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
5446             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
5447             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5448                 return false;
5449             }
5450             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5451                 return false;
5452             }
5453             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5454                 return false;
5455             }
5456             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5457                 return false;
5458             }
5459             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5460                 return false;
5461             }
5462             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5463                 return false;
5464             }
5465             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5466                 return false;
5467             }
5468             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5469                 return false;
5470             }
5471             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5472                 return false;
5473             }
5474             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5475                 return false;
5476             }
5477             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5478                 return false;
5479             }
5480             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5481                 return false;
5482             }
5483             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5484             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5485                 return false;
5486             }
5487             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5488                 return false;
5489             }
5490             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5491                 return false;
5492             }
5493             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5494             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5495                 return false;
5496             }
5497             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5498                 return false;
5499             }
5500             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5501                 return false;
5502             }
5503             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5504             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5505                 return false;
5506             }
5507             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5508                 return false;
5509             }
5510             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5511                 return false;
5512             }
5513         }
5514         catch ( final Exception e ) {
5515             e.printStackTrace();
5516             return false;
5517         }
5518         return true;
5519     }
5520
5521     private static boolean testGeneralTable() {
5522         try {
5523             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5524             t0.setValue( 3, 2, "23" );
5525             t0.setValue( 10, 1, "error" );
5526             t0.setValue( 10, 1, "110" );
5527             t0.setValue( 9, 1, "19" );
5528             t0.setValue( 1, 10, "101" );
5529             t0.setValue( 10, 10, "1010" );
5530             t0.setValue( 100, 10, "10100" );
5531             t0.setValue( 0, 0, "00" );
5532             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5533                 return false;
5534             }
5535             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5536                 return false;
5537             }
5538             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5539                 return false;
5540             }
5541             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5542                 return false;
5543             }
5544             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5545                 return false;
5546             }
5547             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5548                 return false;
5549             }
5550             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5551                 return false;
5552             }
5553             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5554                 return false;
5555             }
5556             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5557                 return false;
5558             }
5559             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5560             t1.setValue( "3", "2", "23" );
5561             t1.setValue( "10", "1", "error" );
5562             t1.setValue( "10", "1", "110" );
5563             t1.setValue( "9", "1", "19" );
5564             t1.setValue( "1", "10", "101" );
5565             t1.setValue( "10", "10", "1010" );
5566             t1.setValue( "100", "10", "10100" );
5567             t1.setValue( "0", "0", "00" );
5568             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5569             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5570                 return false;
5571             }
5572             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5573                 return false;
5574             }
5575             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5576                 return false;
5577             }
5578             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5579                 return false;
5580             }
5581             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5582                 return false;
5583             }
5584             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5585                 return false;
5586             }
5587             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5588                 return false;
5589             }
5590             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5591                 return false;
5592             }
5593             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5594                 return false;
5595             }
5596             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5597                 return false;
5598             }
5599         }
5600         catch ( final Exception e ) {
5601             e.printStackTrace( System.out );
5602             return false;
5603         }
5604         return true;
5605     }
5606
5607     private static boolean testGetDistance() {
5608         try {
5609             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5610             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",
5611                                                  new NHXParser() )[ 0 ];
5612             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5613                 return false;
5614             }
5615             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5616                 return false;
5617             }
5618             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5619                 return false;
5620             }
5621             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5622                 return false;
5623             }
5624             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5625                 return false;
5626             }
5627             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5628                 return false;
5629             }
5630             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5631                 return false;
5632             }
5633             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5634                 return false;
5635             }
5636             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5637                 return false;
5638             }
5639             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5640                 return false;
5641             }
5642             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5643                 return false;
5644             }
5645             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5646                 return false;
5647             }
5648             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5649                 return false;
5650             }
5651             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5652                 return false;
5653             }
5654             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5655                 return false;
5656             }
5657             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5658                 return false;
5659             }
5660             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5661                 return false;
5662             }
5663             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5664                 return false;
5665             }
5666             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5667                 return false;
5668             }
5669             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5670                 return false;
5671             }
5672             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5673                 return false;
5674             }
5675             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5676                 return false;
5677             }
5678             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5679                 return false;
5680             }
5681             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5682                 return false;
5683             }
5684             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5685                 return false;
5686             }
5687             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5688                 return false;
5689             }
5690             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5691                 return false;
5692             }
5693             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5694                 return false;
5695             }
5696             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5697                 return false;
5698             }
5699             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5700                 return false;
5701             }
5702             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5703                 return false;
5704             }
5705             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",
5706                                                  new NHXParser() )[ 0 ];
5707             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5708                 return false;
5709             }
5710             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5711                 return false;
5712             }
5713             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5714                 return false;
5715             }
5716             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5717                 return false;
5718             }
5719             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5720                 return false;
5721             }
5722             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5723                 return false;
5724             }
5725             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5726                 return false;
5727             }
5728             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5729                 return false;
5730             }
5731             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5732                 return false;
5733             }
5734             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5735                 return false;
5736             }
5737             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5738                 return false;
5739             }
5740         }
5741         catch ( final Exception e ) {
5742             e.printStackTrace( System.out );
5743             return false;
5744         }
5745         return true;
5746     }
5747
5748     private static boolean testGetLCA() {
5749         try {
5750             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5751             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5752                                                  new NHXParser() )[ 0 ];
5753             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5754             if ( !A.getName().equals( "A" ) ) {
5755                 return false;
5756             }
5757             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5758             if ( !gh.getName().equals( "gh" ) ) {
5759                 return false;
5760             }
5761             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5762             if ( !ab.getName().equals( "ab" ) ) {
5763                 return false;
5764             }
5765             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5766             if ( !ab2.getName().equals( "ab" ) ) {
5767                 return false;
5768             }
5769             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5770             if ( !gh2.getName().equals( "gh" ) ) {
5771                 return false;
5772             }
5773             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5774             if ( !gh3.getName().equals( "gh" ) ) {
5775                 return false;
5776             }
5777             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5778             if ( !abc.getName().equals( "abc" ) ) {
5779                 return false;
5780             }
5781             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5782             if ( !abc2.getName().equals( "abc" ) ) {
5783                 return false;
5784             }
5785             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5786             if ( !abcd.getName().equals( "abcd" ) ) {
5787                 return false;
5788             }
5789             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5790             if ( !abcd2.getName().equals( "abcd" ) ) {
5791                 return false;
5792             }
5793             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5794             if ( !abcdef.getName().equals( "abcdef" ) ) {
5795                 return false;
5796             }
5797             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5798             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5799                 return false;
5800             }
5801             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5802             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5803                 return false;
5804             }
5805             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5806             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5807                 return false;
5808             }
5809             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5810             if ( !abcde.getName().equals( "abcde" ) ) {
5811                 return false;
5812             }
5813             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5814             if ( !abcde2.getName().equals( "abcde" ) ) {
5815                 return false;
5816             }
5817             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5818             if ( !r.getName().equals( "abcdefgh" ) ) {
5819                 return false;
5820             }
5821             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5822             if ( !r2.getName().equals( "abcdefgh" ) ) {
5823                 return false;
5824             }
5825             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5826             if ( !r3.getName().equals( "abcdefgh" ) ) {
5827                 return false;
5828             }
5829             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5830             if ( !abcde3.getName().equals( "abcde" ) ) {
5831                 return false;
5832             }
5833             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5834             if ( !abcde4.getName().equals( "abcde" ) ) {
5835                 return false;
5836             }
5837             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5838             if ( !ab3.getName().equals( "ab" ) ) {
5839                 return false;
5840             }
5841             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5842             if ( !ab4.getName().equals( "ab" ) ) {
5843                 return false;
5844             }
5845             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5846             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5847             if ( !cd.getName().equals( "cd" ) ) {
5848                 return false;
5849             }
5850             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5851             if ( !cd2.getName().equals( "cd" ) ) {
5852                 return false;
5853             }
5854             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5855             if ( !cde.getName().equals( "cde" ) ) {
5856                 return false;
5857             }
5858             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5859             if ( !cde2.getName().equals( "cde" ) ) {
5860                 return false;
5861             }
5862             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5863             if ( !cdef.getName().equals( "cdef" ) ) {
5864                 return false;
5865             }
5866             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5867             if ( !cdef2.getName().equals( "cdef" ) ) {
5868                 return false;
5869             }
5870             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5871             if ( !cdef3.getName().equals( "cdef" ) ) {
5872                 return false;
5873             }
5874             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5875             if ( !rt.getName().equals( "r" ) ) {
5876                 return false;
5877             }
5878             final Phylogeny p3 = factory.create(
5879                                                  "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5880                                                  new NHXParser() )[ 0 ];
5881             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5882             if ( !bc_3.getName().equals( "bc" ) ) {
5883                 return false;
5884             }
5885             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5886             if ( !ac_3.getName().equals( "abc" ) ) {
5887                 return false;
5888             }
5889             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5890             if ( !ad_3.getName().equals( "abcde" ) ) {
5891                 return false;
5892             }
5893             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5894             if ( !af_3.getName().equals( "abcdef" ) ) {
5895                 return false;
5896             }
5897             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5898             if ( !ag_3.getName().equals( "" ) ) {
5899                 return false;
5900             }
5901             if ( !ag_3.isRoot() ) {
5902                 return false;
5903             }
5904             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5905             if ( !al_3.getName().equals( "" ) ) {
5906                 return false;
5907             }
5908             if ( !al_3.isRoot() ) {
5909                 return false;
5910             }
5911             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5912             if ( !kl_3.getName().equals( "" ) ) {
5913                 return false;
5914             }
5915             if ( !kl_3.isRoot() ) {
5916                 return false;
5917             }
5918             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5919             if ( !fl_3.getName().equals( "" ) ) {
5920                 return false;
5921             }
5922             if ( !fl_3.isRoot() ) {
5923                 return false;
5924             }
5925             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5926             if ( !gk_3.getName().equals( "ghijk" ) ) {
5927                 return false;
5928             }
5929             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5930             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5931             if ( !r_4.getName().equals( "r" ) ) {
5932                 return false;
5933             }
5934             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5935             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5936             if ( !r_5.getName().equals( "root" ) ) {
5937                 return false;
5938             }
5939             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5940             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5941             if ( !r_6.getName().equals( "rot" ) ) {
5942                 return false;
5943             }
5944             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5945             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5946             if ( !r_7.getName().equals( "rott" ) ) {
5947                 return false;
5948             }
5949         }
5950         catch ( final Exception e ) {
5951             e.printStackTrace( System.out );
5952             return false;
5953         }
5954         return true;
5955     }
5956
5957     private static boolean testGetLCA2() {
5958         try {
5959             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5960             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5961             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5962             PhylogenyMethods.preOrderReId( p_a );
5963             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5964                                                                                               p_a.getNode( "a" ) );
5965             if ( !p_a_1.getName().equals( "a" ) ) {
5966                 return false;
5967             }
5968             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5969             PhylogenyMethods.preOrderReId( p_b );
5970             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5971                                                                                               p_b.getNode( "a" ) );
5972             if ( !p_b_1.getName().equals( "b" ) ) {
5973                 return false;
5974             }
5975             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5976                                                                                               p_b.getNode( "b" ) );
5977             if ( !p_b_2.getName().equals( "b" ) ) {
5978                 return false;
5979             }
5980             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5981             PhylogenyMethods.preOrderReId( p_c );
5982             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5983                                                                                               p_c.getNode( "a" ) );
5984             if ( !p_c_1.getName().equals( "b" ) ) {
5985                 return false;
5986             }
5987             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5988                                                                                               p_c.getNode( "c" ) );
5989             if ( !p_c_2.getName().equals( "c" ) ) {
5990                 System.out.println( p_c_2.getName() );
5991                 System.exit( -1 );
5992                 return false;
5993             }
5994             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5995                                                                                               p_c.getNode( "b" ) );
5996             if ( !p_c_3.getName().equals( "b" ) ) {
5997                 return false;
5998             }
5999             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
6000                                                                                               p_c.getNode( "a" ) );
6001             if ( !p_c_4.getName().equals( "c" ) ) {
6002                 return false;
6003             }
6004             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
6005                                                  new NHXParser() )[ 0 ];
6006             PhylogenyMethods.preOrderReId( p1 );
6007             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6008                                                                                           p1.getNode( "A" ) );
6009             if ( !A.getName().equals( "A" ) ) {
6010                 return false;
6011             }
6012             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
6013                                                                                            p1.getNode( "gh" ) );
6014             if ( !gh.getName().equals( "gh" ) ) {
6015                 return false;
6016             }
6017             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6018                                                                                            p1.getNode( "B" ) );
6019             if ( !ab.getName().equals( "ab" ) ) {
6020                 return false;
6021             }
6022             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
6023                                                                                             p1.getNode( "A" ) );
6024             if ( !ab2.getName().equals( "ab" ) ) {
6025                 return false;
6026             }
6027             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
6028                                                                                             p1.getNode( "G" ) );
6029             if ( !gh2.getName().equals( "gh" ) ) {
6030                 return false;
6031             }
6032             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
6033                                                                                             p1.getNode( "H" ) );
6034             if ( !gh3.getName().equals( "gh" ) ) {
6035                 return false;
6036             }
6037             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
6038                                                                                             p1.getNode( "A" ) );
6039             if ( !abc.getName().equals( "abc" ) ) {
6040                 return false;
6041             }
6042             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6043                                                                                              p1.getNode( "C" ) );
6044             if ( !abc2.getName().equals( "abc" ) ) {
6045                 return false;
6046             }
6047             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6048                                                                                              p1.getNode( "D" ) );
6049             if ( !abcd.getName().equals( "abcd" ) ) {
6050                 return false;
6051             }
6052             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
6053                                                                                               p1.getNode( "A" ) );
6054             if ( !abcd2.getName().equals( "abcd" ) ) {
6055                 return false;
6056             }
6057             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6058                                                                                                p1.getNode( "F" ) );
6059             if ( !abcdef.getName().equals( "abcdef" ) ) {
6060                 return false;
6061             }
6062             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
6063                                                                                                 p1.getNode( "A" ) );
6064             if ( !abcdef2.getName().equals( "abcdef" ) ) {
6065                 return false;
6066             }
6067             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
6068                                                                                                 p1.getNode( "F" ) );
6069             if ( !abcdef3.getName().equals( "abcdef" ) ) {
6070                 return false;
6071             }
6072             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
6073                                                                                                 p1.getNode( "ab" ) );
6074             if ( !abcdef4.getName().equals( "abcdef" ) ) {
6075                 return false;
6076             }
6077             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6078                                                                                               p1.getNode( "E" ) );
6079             if ( !abcde.getName().equals( "abcde" ) ) {
6080                 return false;
6081             }
6082             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6083                                                                                                p1.getNode( "A" ) );
6084             if ( !abcde2.getName().equals( "abcde" ) ) {
6085                 return false;
6086             }
6087             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
6088                                                                                           p1.getNode( "abcdefgh" ) );
6089             if ( !r.getName().equals( "abcdefgh" ) ) {
6090                 return false;
6091             }
6092             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6093                                                                                            p1.getNode( "H" ) );
6094             if ( !r2.getName().equals( "abcdefgh" ) ) {
6095                 return false;
6096             }
6097             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
6098                                                                                            p1.getNode( "A" ) );
6099             if ( !r3.getName().equals( "abcdefgh" ) ) {
6100                 return false;
6101             }
6102             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6103                                                                                                p1.getNode( "abcde" ) );
6104             if ( !abcde3.getName().equals( "abcde" ) ) {
6105                 return false;
6106             }
6107             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
6108                                                                                                p1.getNode( "E" ) );
6109             if ( !abcde4.getName().equals( "abcde" ) ) {
6110                 return false;
6111             }
6112             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
6113                                                                                             p1.getNode( "B" ) );
6114             if ( !ab3.getName().equals( "ab" ) ) {
6115                 return false;
6116             }
6117             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
6118                                                                                             p1.getNode( "ab" ) );
6119             if ( !ab4.getName().equals( "ab" ) ) {
6120                 return false;
6121             }
6122             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
6123             PhylogenyMethods.preOrderReId( p2 );
6124             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6125                                                                                            p2.getNode( "d" ) );
6126             if ( !cd.getName().equals( "cd" ) ) {
6127                 return false;
6128             }
6129             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6130                                                                                             p2.getNode( "c" ) );
6131             if ( !cd2.getName().equals( "cd" ) ) {
6132                 return false;
6133             }
6134             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6135                                                                                             p2.getNode( "e" ) );
6136             if ( !cde.getName().equals( "cde" ) ) {
6137                 return false;
6138             }
6139             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
6140                                                                                              p2.getNode( "c" ) );
6141             if ( !cde2.getName().equals( "cde" ) ) {
6142                 return false;
6143             }
6144             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6145                                                                                              p2.getNode( "f" ) );
6146             if ( !cdef.getName().equals( "cdef" ) ) {
6147                 return false;
6148             }
6149             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6150                                                                                               p2.getNode( "f" ) );
6151             if ( !cdef2.getName().equals( "cdef" ) ) {
6152                 return false;
6153             }
6154             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
6155                                                                                               p2.getNode( "d" ) );
6156             if ( !cdef3.getName().equals( "cdef" ) ) {
6157                 return false;
6158             }
6159             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6160                                                                                            p2.getNode( "a" ) );
6161             if ( !rt.getName().equals( "r" ) ) {
6162                 return false;
6163             }
6164             final Phylogeny p3 = factory.create(
6165                                                  "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
6166                                                  new NHXParser() )[ 0 ];
6167             PhylogenyMethods.preOrderReId( p3 );
6168             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
6169                                                                                              p3.getNode( "c" ) );
6170             if ( !bc_3.getName().equals( "bc" ) ) {
6171                 return false;
6172             }
6173             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6174                                                                                              p3.getNode( "c" ) );
6175             if ( !ac_3.getName().equals( "abc" ) ) {
6176                 return false;
6177             }
6178             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6179                                                                                              p3.getNode( "d" ) );
6180             if ( !ad_3.getName().equals( "abcde" ) ) {
6181                 return false;
6182             }
6183             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6184                                                                                              p3.getNode( "f" ) );
6185             if ( !af_3.getName().equals( "abcdef" ) ) {
6186                 return false;
6187             }
6188             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6189                                                                                              p3.getNode( "g" ) );
6190             if ( !ag_3.getName().equals( "" ) ) {
6191                 return false;
6192             }
6193             if ( !ag_3.isRoot() ) {
6194                 return false;
6195             }
6196             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6197                                                                                              p3.getNode( "l" ) );
6198             if ( !al_3.getName().equals( "" ) ) {
6199                 return false;
6200             }
6201             if ( !al_3.isRoot() ) {
6202                 return false;
6203             }
6204             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
6205                                                                                              p3.getNode( "l" ) );
6206             if ( !kl_3.getName().equals( "" ) ) {
6207                 return false;
6208             }
6209             if ( !kl_3.isRoot() ) {
6210                 return false;
6211             }
6212             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
6213                                                                                              p3.getNode( "l" ) );
6214             if ( !fl_3.getName().equals( "" ) ) {
6215                 return false;
6216             }
6217             if ( !fl_3.isRoot() ) {
6218                 return false;
6219             }
6220             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
6221                                                                                              p3.getNode( "k" ) );
6222             if ( !gk_3.getName().equals( "ghijk" ) ) {
6223                 return false;
6224             }
6225             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
6226             PhylogenyMethods.preOrderReId( p4 );
6227             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
6228                                                                                             p4.getNode( "c" ) );
6229             if ( !r_4.getName().equals( "r" ) ) {
6230                 return false;
6231             }
6232             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
6233             PhylogenyMethods.preOrderReId( p5 );
6234             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
6235                                                                                             p5.getNode( "c" ) );
6236             if ( !r_5.getName().equals( "root" ) ) {
6237                 return false;
6238             }
6239             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
6240             PhylogenyMethods.preOrderReId( p6 );
6241             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
6242                                                                                             p6.getNode( "a" ) );
6243             if ( !r_6.getName().equals( "rot" ) ) {
6244                 return false;
6245             }
6246             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
6247             PhylogenyMethods.preOrderReId( p7 );
6248             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
6249                                                                                             p7.getNode( "e" ) );
6250             if ( !r_7.getName().equals( "rott" ) ) {
6251                 return false;
6252             }
6253             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6254                                                                                              p7.getNode( "a" ) );
6255             if ( !r_71.getName().equals( "rott" ) ) {
6256                 return false;
6257             }
6258             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6259                                                                                              p7.getNode( "rott" ) );
6260             if ( !r_72.getName().equals( "rott" ) ) {
6261                 return false;
6262             }
6263             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6264                                                                                              p7.getNode( "a" ) );
6265             if ( !r_73.getName().equals( "rott" ) ) {
6266                 return false;
6267             }
6268             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6269                                                                                              p7.getNode( "rott" ) );
6270             if ( !r_74.getName().equals( "rott" ) ) {
6271                 return false;
6272             }
6273             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6274                                                                                              p7.getNode( "e" ) );
6275             if ( !r_75.getName().equals( "e" ) ) {
6276                 return false;
6277             }
6278         }
6279         catch ( final Exception e ) {
6280             e.printStackTrace( System.out );
6281             return false;
6282         }
6283         return true;
6284     }
6285
6286     private static boolean testHmmscanOutputParser() {
6287         final String test_dir = Test.PATH_TO_TEST_DATA;
6288         try {
6289             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
6290                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ),
6291                                                                                          "MONBR",
6292                                                                                          INDIVIDUAL_SCORE_CUTOFF.NONE );
6293             parser1.parse();
6294             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
6295                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ),
6296                                                                                          "MONBR",
6297                                                                                          INDIVIDUAL_SCORE_CUTOFF.NONE );
6298             final List<Protein> proteins = parser2.parse();
6299             if ( parser2.getProteinsEncountered() != 4 ) {
6300                 return false;
6301             }
6302             if ( proteins.size() != 4 ) {
6303                 return false;
6304             }
6305             if ( parser2.getDomainsEncountered() != 69 ) {
6306                 return false;
6307             }
6308             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
6309                 return false;
6310             }
6311             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
6312                 return false;
6313             }
6314             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
6315                 return false;
6316             }
6317             final Protein p1 = proteins.get( 0 );
6318             if ( p1.getNumberOfProteinDomains() != 15 ) {
6319                 return false;
6320             }
6321             if ( p1.getLength() != 850 ) {
6322                 return false;
6323             }
6324             final Protein p2 = proteins.get( 1 );
6325             if ( p2.getNumberOfProteinDomains() != 51 ) {
6326                 return false;
6327             }
6328             if ( p2.getLength() != 1291 ) {
6329                 return false;
6330             }
6331             final Protein p3 = proteins.get( 2 );
6332             if ( p3.getNumberOfProteinDomains() != 2 ) {
6333                 return false;
6334             }
6335             final Protein p4 = proteins.get( 3 );
6336             if ( p4.getNumberOfProteinDomains() != 1 ) {
6337                 return false;
6338             }
6339             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
6340                 return false;
6341             }
6342             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
6343                 return false;
6344             }
6345             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
6346                 return false;
6347             }
6348             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
6349                 return false;
6350             }
6351             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
6352                 return false;
6353             }
6354             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
6355                 return false;
6356             }
6357             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
6358                 return false;
6359             }
6360         }
6361         catch ( final Exception e ) {
6362             e.printStackTrace( System.out );
6363             return false;
6364         }
6365         return true;
6366     }
6367
6368     private static boolean testLastExternalNodeMethods() {
6369         try {
6370             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6371             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
6372             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
6373             final PhylogenyNode n1 = t0.getNode( "A" );
6374             if ( n1.isLastExternalNode() ) {
6375                 return false;
6376             }
6377             final PhylogenyNode n2 = t0.getNode( "B" );
6378             if ( n2.isLastExternalNode() ) {
6379                 return false;
6380             }
6381             final PhylogenyNode n3 = t0.getNode( "C" );
6382             if ( n3.isLastExternalNode() ) {
6383                 return false;
6384             }
6385             final PhylogenyNode n4 = t0.getNode( "D" );
6386             if ( !n4.isLastExternalNode() ) {
6387                 return false;
6388             }
6389         }
6390         catch ( final Exception e ) {
6391             e.printStackTrace( System.out );
6392             return false;
6393         }
6394         return true;
6395     }
6396
6397     private static boolean testLevelOrderIterator() {
6398         try {
6399             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6400             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
6401             PhylogenyNodeIterator it0;
6402             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
6403                 it0.next();
6404             }
6405             for( it0.reset(); it0.hasNext(); ) {
6406                 it0.next();
6407             }
6408             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
6409             if ( !it.next().getName().equals( "r" ) ) {
6410                 return false;
6411             }
6412             if ( !it.next().getName().equals( "ab" ) ) {
6413                 return false;
6414             }
6415             if ( !it.next().getName().equals( "cd" ) ) {
6416                 return false;
6417             }
6418             if ( !it.next().getName().equals( "A" ) ) {
6419                 return false;
6420             }
6421             if ( !it.next().getName().equals( "B" ) ) {
6422                 return false;
6423             }
6424             if ( !it.next().getName().equals( "C" ) ) {
6425                 return false;
6426             }
6427             if ( !it.next().getName().equals( "D" ) ) {
6428                 return false;
6429             }
6430             if ( it.hasNext() ) {
6431                 return false;
6432             }
6433             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",
6434                                                  new NHXParser() )[ 0 ];
6435             PhylogenyNodeIterator it2;
6436             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
6437                 it2.next();
6438             }
6439             for( it2.reset(); it2.hasNext(); ) {
6440                 it2.next();
6441             }
6442             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
6443             if ( !it3.next().getName().equals( "r" ) ) {
6444                 return false;
6445             }
6446             if ( !it3.next().getName().equals( "abc" ) ) {
6447                 return false;
6448             }
6449             if ( !it3.next().getName().equals( "defg" ) ) {
6450                 return false;
6451             }
6452             if ( !it3.next().getName().equals( "A" ) ) {
6453                 return false;
6454             }
6455             if ( !it3.next().getName().equals( "B" ) ) {
6456                 return false;
6457             }
6458             if ( !it3.next().getName().equals( "C" ) ) {
6459                 return false;
6460             }
6461             if ( !it3.next().getName().equals( "D" ) ) {
6462                 return false;
6463             }
6464             if ( !it3.next().getName().equals( "E" ) ) {
6465                 return false;
6466             }
6467             if ( !it3.next().getName().equals( "F" ) ) {
6468                 return false;
6469             }
6470             if ( !it3.next().getName().equals( "G" ) ) {
6471                 return false;
6472             }
6473             if ( !it3.next().getName().equals( "1" ) ) {
6474                 return false;
6475             }
6476             if ( !it3.next().getName().equals( "2" ) ) {
6477                 return false;
6478             }
6479             if ( !it3.next().getName().equals( "3" ) ) {
6480                 return false;
6481             }
6482             if ( !it3.next().getName().equals( "4" ) ) {
6483                 return false;
6484             }
6485             if ( !it3.next().getName().equals( "5" ) ) {
6486                 return false;
6487             }
6488             if ( !it3.next().getName().equals( "6" ) ) {
6489                 return false;
6490             }
6491             if ( !it3.next().getName().equals( "f1" ) ) {
6492                 return false;
6493             }
6494             if ( !it3.next().getName().equals( "f2" ) ) {
6495                 return false;
6496             }
6497             if ( !it3.next().getName().equals( "f3" ) ) {
6498                 return false;
6499             }
6500             if ( !it3.next().getName().equals( "a" ) ) {
6501                 return false;
6502             }
6503             if ( !it3.next().getName().equals( "b" ) ) {
6504                 return false;
6505             }
6506             if ( !it3.next().getName().equals( "f21" ) ) {
6507                 return false;
6508             }
6509             if ( !it3.next().getName().equals( "X" ) ) {
6510                 return false;
6511             }
6512             if ( !it3.next().getName().equals( "Y" ) ) {
6513                 return false;
6514             }
6515             if ( !it3.next().getName().equals( "Z" ) ) {
6516                 return false;
6517             }
6518             if ( it3.hasNext() ) {
6519                 return false;
6520             }
6521             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6522             PhylogenyNodeIterator it4;
6523             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6524                 it4.next();
6525             }
6526             for( it4.reset(); it4.hasNext(); ) {
6527                 it4.next();
6528             }
6529             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6530             if ( !it5.next().getName().equals( "r" ) ) {
6531                 return false;
6532             }
6533             if ( !it5.next().getName().equals( "A" ) ) {
6534                 return false;
6535             }
6536             if ( !it5.next().getName().equals( "B" ) ) {
6537                 return false;
6538             }
6539             if ( !it5.next().getName().equals( "C" ) ) {
6540                 return false;
6541             }
6542             if ( !it5.next().getName().equals( "D" ) ) {
6543                 return false;
6544             }
6545             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6546             PhylogenyNodeIterator it6;
6547             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6548                 it6.next();
6549             }
6550             for( it6.reset(); it6.hasNext(); ) {
6551                 it6.next();
6552             }
6553             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6554             if ( !it7.next().getName().equals( "A" ) ) {
6555                 return false;
6556             }
6557             if ( it.hasNext() ) {
6558                 return false;
6559             }
6560         }
6561         catch ( final Exception e ) {
6562             e.printStackTrace( System.out );
6563             return false;
6564         }
6565         return true;
6566     }
6567
6568     private static boolean testMafft( final String path ) {
6569         try {
6570             final List<String> opts = new ArrayList<String>();
6571             opts.add( "--maxiterate" );
6572             opts.add( "1000" );
6573             opts.add( "--localpair" );
6574             opts.add( "--quiet" );
6575             Msa msa = null;
6576             final MsaInferrer mafft = Mafft.createInstance( path );
6577             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6578             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6579                 return false;
6580             }
6581             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6582                 return false;
6583             }
6584         }
6585         catch ( final Exception e ) {
6586             e.printStackTrace( System.out );
6587             return false;
6588         }
6589         return true;
6590     }
6591
6592     private static boolean testMidpointrooting() {
6593         try {
6594             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6595             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6596             PhylogenyMethods.midpointRoot( t0 );
6597             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6598                 return false;
6599             }
6600             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6601                 return false;
6602             }
6603             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6604                            1 ) ) {
6605                 return false;
6606             }
6607             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",
6608                                                  new NHXParser() )[ 0 ];
6609             if ( !t1.isRooted() ) {
6610                 return false;
6611             }
6612             PhylogenyMethods.midpointRoot( t1 );
6613             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6614                 return false;
6615             }
6616             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6617                 return false;
6618             }
6619             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6620                 return false;
6621             }
6622             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6623                 return false;
6624             }
6625             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6626                 return false;
6627             }
6628             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6629                 return false;
6630             }
6631             t1.reRoot( t1.getNode( "A" ) );
6632             PhylogenyMethods.midpointRoot( t1 );
6633             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6634                 return false;
6635             }
6636             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6637                 return false;
6638             }
6639             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6640                 return false;
6641             }
6642             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6643                 return false;
6644             }
6645             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6646                 System.exit( -1 );
6647                 return false;
6648             }
6649             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6650                 return false;
6651             }
6652         }
6653         catch ( final Exception e ) {
6654             e.printStackTrace( System.out );
6655             return false;
6656         }
6657         return true;
6658     }
6659
6660     private static boolean testMsaQualityMethod() {
6661         try {
6662             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6663             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6664             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6665             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6666             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6667             l.add( s0 );
6668             l.add( s1 );
6669             l.add( s2 );
6670             l.add( s3 );
6671             final Msa msa = BasicMsa.createInstance( l );
6672             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6673                 return false;
6674             }
6675             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6676                 return false;
6677             }
6678             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6679                 return false;
6680             }
6681             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6682                 return false;
6683             }
6684             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6685                 return false;
6686             }
6687             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6688                 return false;
6689             }
6690             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6691                 return false;
6692             }
6693         }
6694         catch ( final Exception e ) {
6695             e.printStackTrace( System.out );
6696             return false;
6697         }
6698         return true;
6699     }
6700
6701     private static boolean testMsaEntropy() {
6702         try {
6703             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6704             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6705             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6706             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6707             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6708             l.add( s0 );
6709             l.add( s1 );
6710             l.add( s2 );
6711             l.add( s3 );
6712             final Msa msa = BasicMsa.createInstance( l );
6713             //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6714             //FIXME
6715             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6716             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6717             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6718             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6719             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6720             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6721             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6722             //            System.out.println();
6723             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6724             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6725             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6726             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6727             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6728             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6729             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6730             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6731             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6732             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6733             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6734             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6735             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6736             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6737             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6738             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6739             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6740             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6741             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6742             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6743             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6744             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6745             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6746             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6747             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6748             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6749             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6750             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6751             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6752             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6753             final Msa msa2 = BasicMsa.createInstance( l2 );
6754             //            System.out.println();
6755             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6756             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6757             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6758         }
6759         catch ( final Exception e ) {
6760             e.printStackTrace( System.out );
6761             return false;
6762         }
6763         return true;
6764     }
6765
6766     private static boolean testDeleteableMsa() {
6767         try {
6768             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6769             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6770             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6771             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6772             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6773             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6774             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6775             l0.add( s0 );
6776             l0.add( s1 );
6777             l0.add( s2 );
6778             l0.add( s3 );
6779             l0.add( s4 );
6780             l0.add( s5 );
6781             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6782             dmsa0.deleteRow( "b", false );
6783             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6784                 return false;
6785             }
6786             dmsa0.deleteRow( "e", false );
6787             dmsa0.deleteRow( "a", false );
6788             dmsa0.deleteRow( "f", false );
6789             if ( dmsa0.getLength() != 4 ) {
6790                 return false;
6791             }
6792             if ( dmsa0.getNumberOfSequences() != 2 ) {
6793                 return false;
6794             }
6795             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6796                 return false;
6797             }
6798             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6799                 return false;
6800             }
6801             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6802                 return false;
6803             }
6804             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6805                 return false;
6806             }
6807             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6808                 return false;
6809             }
6810             dmsa0.deleteRow( "c", false );
6811             dmsa0.deleteRow( "d", false );
6812             if ( dmsa0.getNumberOfSequences() != 0 ) {
6813                 return false;
6814             }
6815             //
6816             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6817             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6818             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6819             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6820             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6821             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6822             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6823             l1.add( s_0 );
6824             l1.add( s_1 );
6825             l1.add( s_2 );
6826             l1.add( s_3 );
6827             l1.add( s_4 );
6828             l1.add( s_5 );
6829             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6830             dmsa1.deleteGapOnlyColumns();
6831             dmsa1.deleteRow( "a", false );
6832             dmsa1.deleteRow( "f", false );
6833             dmsa1.deleteRow( "d", false );
6834             dmsa1.deleteGapOnlyColumns();
6835             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6836                 return false;
6837             }
6838             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6839                 return false;
6840             }
6841             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6842                 return false;
6843             }
6844             dmsa1.deleteRow( "c", false );
6845             dmsa1.deleteGapOnlyColumns();
6846             final Writer w0 = new StringWriter();
6847             dmsa1.write( w0, MSA_FORMAT.FASTA );
6848             final Writer w1 = new StringWriter();
6849             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6850             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6851                 return false;
6852             }
6853             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6854                 return false;
6855             }
6856             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6857             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6858             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6859             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6860             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6861             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6862             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6863             l2.add( s__0 );
6864             l2.add( s__1 );
6865             l2.add( s__2 );
6866             l2.add( s__3 );
6867             l2.add( s__4 );
6868             l2.add( s__5 );
6869             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6870             dmsa2.deleteGapColumns( 0.5 );
6871             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6872                 return false;
6873             }
6874             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6875                 return false;
6876             }
6877             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6878                 return false;
6879             }
6880             dmsa2.deleteGapColumns( 0.2 );
6881             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6882                 return false;
6883             }
6884             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6885                 return false;
6886             }
6887             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6888                 return false;
6889             }
6890             dmsa2.deleteGapColumns( 0 );
6891             dmsa2.deleteRow( "a", false );
6892             dmsa2.deleteRow( "b", false );
6893             dmsa2.deleteRow( "f", false );
6894             dmsa2.deleteRow( "e", false );
6895             dmsa2.setIdentifier( 0, "new_c" );
6896             dmsa2.setIdentifier( 1, "new_d" );
6897             dmsa2.setResidueAt( 0, 0, 'x' );
6898             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6899             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6900                 return false;
6901             }
6902             final Writer w = new StringWriter();
6903             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6904             final String phylip = w.toString();
6905             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6906                 System.out.println( phylip );
6907                 return false;
6908             }
6909             final Writer w2 = new StringWriter();
6910             dmsa2.write( w2, MSA_FORMAT.FASTA );
6911             final String fasta = w2.toString();
6912             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6913                 System.out.println( fasta );
6914                 return false;
6915             }
6916         }
6917         catch ( final Exception e ) {
6918             e.printStackTrace( System.out );
6919             return false;
6920         }
6921         return true;
6922     }
6923
6924     private static boolean testNextNodeWithCollapsing() {
6925         try {
6926             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6927             PhylogenyNode n;
6928             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6929             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6930             final Phylogeny t0 = factory.create( sb0.toString(), new NHXParser() )[ 0 ];
6931             t0.getNode( "cd" ).setCollapse( true );
6932             t0.getNode( "cde" ).setCollapse( true );
6933             n = t0.getFirstExternalNode();
6934             while ( n != null ) {
6935                 ext.add( n );
6936                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6937             }
6938             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6939                 return false;
6940             }
6941             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6942                 return false;
6943             }
6944             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6945                 return false;
6946             }
6947             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6948                 return false;
6949             }
6950             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6951                 return false;
6952             }
6953             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6954                 return false;
6955             }
6956             ext.clear();
6957             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6958             final Phylogeny t1 = factory.create( sb1.toString(), new NHXParser() )[ 0 ];
6959             t1.getNode( "ab" ).setCollapse( true );
6960             t1.getNode( "cd" ).setCollapse( true );
6961             t1.getNode( "cde" ).setCollapse( true );
6962             n = t1.getNode( "ab" );
6963             ext = new ArrayList<PhylogenyNode>();
6964             while ( n != null ) {
6965                 ext.add( n );
6966                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6967             }
6968             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6969                 return false;
6970             }
6971             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6972                 return false;
6973             }
6974             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6975                 return false;
6976             }
6977             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6978                 return false;
6979             }
6980             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6981                 return false;
6982             }
6983             ext.clear();
6984             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6985             final Phylogeny t2 = factory.create( sb2.toString(), new NHXParser() )[ 0 ];
6986             t2.getNode( "ab" ).setCollapse( true );
6987             t2.getNode( "cd" ).setCollapse( true );
6988             t2.getNode( "cde" ).setCollapse( true );
6989             t2.getNode( "c" ).setCollapse( true );
6990             t2.getNode( "d" ).setCollapse( true );
6991             t2.getNode( "e" ).setCollapse( true );
6992             t2.getNode( "gh" ).setCollapse( true );
6993             n = t2.getNode( "ab" );
6994             ext = new ArrayList<PhylogenyNode>();
6995             while ( n != null ) {
6996                 ext.add( n );
6997                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6998             }
6999             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7000                 return false;
7001             }
7002             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7003                 return false;
7004             }
7005             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
7006                 return false;
7007             }
7008             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
7009                 return false;
7010             }
7011             ext.clear();
7012             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7013             final Phylogeny t3 = factory.create( sb3.toString(), new NHXParser() )[ 0 ];
7014             t3.getNode( "ab" ).setCollapse( true );
7015             t3.getNode( "cd" ).setCollapse( true );
7016             t3.getNode( "cde" ).setCollapse( true );
7017             t3.getNode( "c" ).setCollapse( true );
7018             t3.getNode( "d" ).setCollapse( true );
7019             t3.getNode( "e" ).setCollapse( true );
7020             t3.getNode( "gh" ).setCollapse( true );
7021             t3.getNode( "fgh" ).setCollapse( true );
7022             n = t3.getNode( "ab" );
7023             ext = new ArrayList<PhylogenyNode>();
7024             while ( n != null ) {
7025                 ext.add( n );
7026                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7027             }
7028             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7029                 return false;
7030             }
7031             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7032                 return false;
7033             }
7034             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
7035                 return false;
7036             }
7037             ext.clear();
7038             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7039             final Phylogeny t4 = factory.create( sb4.toString(), new NHXParser() )[ 0 ];
7040             t4.getNode( "ab" ).setCollapse( true );
7041             t4.getNode( "cd" ).setCollapse( true );
7042             t4.getNode( "cde" ).setCollapse( true );
7043             t4.getNode( "c" ).setCollapse( true );
7044             t4.getNode( "d" ).setCollapse( true );
7045             t4.getNode( "e" ).setCollapse( true );
7046             t4.getNode( "gh" ).setCollapse( true );
7047             t4.getNode( "fgh" ).setCollapse( true );
7048             t4.getNode( "abcdefgh" ).setCollapse( true );
7049             n = t4.getNode( "abcdefgh" );
7050             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
7051                 return false;
7052             }
7053             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7054             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
7055             ext.clear();
7056             n = t5.getFirstExternalNode();
7057             while ( n != null ) {
7058                 ext.add( n );
7059                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7060             }
7061             if ( ext.size() != 8 ) {
7062                 return false;
7063             }
7064             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7065                 return false;
7066             }
7067             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7068                 return false;
7069             }
7070             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7071                 return false;
7072             }
7073             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7074                 return false;
7075             }
7076             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7077                 return false;
7078             }
7079             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7080                 return false;
7081             }
7082             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
7083                 return false;
7084             }
7085             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
7086                 return false;
7087             }
7088             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7089             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
7090             ext.clear();
7091             t6.getNode( "ab" ).setCollapse( true );
7092             n = t6.getNode( "ab" );
7093             while ( n != null ) {
7094                 ext.add( n );
7095                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7096             }
7097             if ( ext.size() != 7 ) {
7098                 return false;
7099             }
7100             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7101                 return false;
7102             }
7103             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7104                 return false;
7105             }
7106             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7107                 return false;
7108             }
7109             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7110                 return false;
7111             }
7112             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7113                 return false;
7114             }
7115             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7116                 return false;
7117             }
7118             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7119                 return false;
7120             }
7121             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7122             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
7123             ext.clear();
7124             t7.getNode( "cd" ).setCollapse( true );
7125             n = t7.getNode( "a" );
7126             while ( n != null ) {
7127                 ext.add( n );
7128                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7129             }
7130             if ( ext.size() != 7 ) {
7131                 return false;
7132             }
7133             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7134                 return false;
7135             }
7136             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7137                 return false;
7138             }
7139             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7140                 return false;
7141             }
7142             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7143                 return false;
7144             }
7145             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7146                 return false;
7147             }
7148             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7149                 return false;
7150             }
7151             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7152                 return false;
7153             }
7154             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7155             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
7156             ext.clear();
7157             t8.getNode( "cd" ).setCollapse( true );
7158             t8.getNode( "c" ).setCollapse( true );
7159             t8.getNode( "d" ).setCollapse( true );
7160             n = t8.getNode( "a" );
7161             while ( n != null ) {
7162                 ext.add( n );
7163                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7164             }
7165             if ( ext.size() != 7 ) {
7166                 return false;
7167             }
7168             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7169                 return false;
7170             }
7171             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7172                 return false;
7173             }
7174             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7175                 System.out.println( "2 fail" );
7176                 return false;
7177             }
7178             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7179                 return false;
7180             }
7181             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7182                 return false;
7183             }
7184             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7185                 return false;
7186             }
7187             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7188                 return false;
7189             }
7190             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7191             final Phylogeny t9 = factory.create( sb9.toString(), new NHXParser() )[ 0 ];
7192             ext.clear();
7193             t9.getNode( "gh" ).setCollapse( true );
7194             n = t9.getNode( "a" );
7195             while ( n != null ) {
7196                 ext.add( n );
7197                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7198             }
7199             if ( ext.size() != 7 ) {
7200                 return false;
7201             }
7202             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7203                 return false;
7204             }
7205             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7206                 return false;
7207             }
7208             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7209                 return false;
7210             }
7211             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7212                 return false;
7213             }
7214             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7215                 return false;
7216             }
7217             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7218                 return false;
7219             }
7220             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7221                 return false;
7222             }
7223             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7224             final Phylogeny t10 = factory.create( sb10.toString(), new NHXParser() )[ 0 ];
7225             ext.clear();
7226             t10.getNode( "gh" ).setCollapse( true );
7227             t10.getNode( "g" ).setCollapse( true );
7228             t10.getNode( "h" ).setCollapse( true );
7229             n = t10.getNode( "a" );
7230             while ( n != null ) {
7231                 ext.add( n );
7232                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7233             }
7234             if ( ext.size() != 7 ) {
7235                 return false;
7236             }
7237             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7238                 return false;
7239             }
7240             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7241                 return false;
7242             }
7243             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7244                 return false;
7245             }
7246             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7247                 return false;
7248             }
7249             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7250                 return false;
7251             }
7252             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7253                 return false;
7254             }
7255             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7256                 return false;
7257             }
7258             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7259             final Phylogeny t11 = factory.create( sb11.toString(), new NHXParser() )[ 0 ];
7260             ext.clear();
7261             t11.getNode( "gh" ).setCollapse( true );
7262             t11.getNode( "fgh" ).setCollapse( true );
7263             n = t11.getNode( "a" );
7264             while ( n != null ) {
7265                 ext.add( n );
7266                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7267             }
7268             if ( ext.size() != 6 ) {
7269                 return false;
7270             }
7271             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7272                 return false;
7273             }
7274             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7275                 return false;
7276             }
7277             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7278                 return false;
7279             }
7280             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7281                 return false;
7282             }
7283             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7284                 return false;
7285             }
7286             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7287                 return false;
7288             }
7289             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7290             final Phylogeny t12 = factory.create( sb12.toString(), new NHXParser() )[ 0 ];
7291             ext.clear();
7292             t12.getNode( "gh" ).setCollapse( true );
7293             t12.getNode( "fgh" ).setCollapse( true );
7294             t12.getNode( "g" ).setCollapse( true );
7295             t12.getNode( "h" ).setCollapse( true );
7296             t12.getNode( "f" ).setCollapse( true );
7297             n = t12.getNode( "a" );
7298             while ( n != null ) {
7299                 ext.add( n );
7300                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7301             }
7302             if ( ext.size() != 6 ) {
7303                 return false;
7304             }
7305             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7306                 return false;
7307             }
7308             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7309                 return false;
7310             }
7311             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7312                 return false;
7313             }
7314             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7315                 return false;
7316             }
7317             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7318                 return false;
7319             }
7320             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7321                 return false;
7322             }
7323             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7324             final Phylogeny t13 = factory.create( sb13.toString(), new NHXParser() )[ 0 ];
7325             ext.clear();
7326             t13.getNode( "ab" ).setCollapse( true );
7327             t13.getNode( "b" ).setCollapse( true );
7328             t13.getNode( "fgh" ).setCollapse( true );
7329             t13.getNode( "gh" ).setCollapse( true );
7330             n = t13.getNode( "ab" );
7331             while ( n != null ) {
7332                 ext.add( n );
7333                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7334             }
7335             if ( ext.size() != 5 ) {
7336                 return false;
7337             }
7338             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7339                 return false;
7340             }
7341             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7342                 return false;
7343             }
7344             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7345                 return false;
7346             }
7347             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7348                 return false;
7349             }
7350             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7351                 return false;
7352             }
7353             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
7354             final Phylogeny t14 = factory.create( sb14.toString(), new NHXParser() )[ 0 ];
7355             ext.clear();
7356             t14.getNode( "ab" ).setCollapse( true );
7357             t14.getNode( "a" ).setCollapse( true );
7358             t14.getNode( "fgh" ).setCollapse( true );
7359             t14.getNode( "gh" ).setCollapse( true );
7360             n = t14.getNode( "ab" );
7361             while ( n != null ) {
7362                 ext.add( n );
7363                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7364             }
7365             if ( ext.size() != 5 ) {
7366                 return false;
7367             }
7368             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7369                 return false;
7370             }
7371             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7372                 return false;
7373             }
7374             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7375                 return false;
7376             }
7377             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7378                 return false;
7379             }
7380             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7381                 return false;
7382             }
7383             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" );
7384             final Phylogeny t15 = factory.create( sb15.toString(), new NHXParser() )[ 0 ];
7385             ext.clear();
7386             t15.getNode( "ab" ).setCollapse( true );
7387             t15.getNode( "a" ).setCollapse( true );
7388             t15.getNode( "fgh" ).setCollapse( true );
7389             t15.getNode( "gh" ).setCollapse( true );
7390             n = t15.getNode( "ab" );
7391             while ( n != null ) {
7392                 ext.add( n );
7393                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7394             }
7395             if ( ext.size() != 6 ) {
7396                 return false;
7397             }
7398             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7399                 return false;
7400             }
7401             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7402                 return false;
7403             }
7404             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7405                 return false;
7406             }
7407             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7408                 return false;
7409             }
7410             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
7411                 return false;
7412             }
7413             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7414                 return false;
7415             }
7416             //
7417             //
7418             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" );
7419             final Phylogeny t16 = factory.create( sb16.toString(), new NHXParser() )[ 0 ];
7420             ext.clear();
7421             t16.getNode( "ab" ).setCollapse( true );
7422             t16.getNode( "a" ).setCollapse( true );
7423             t16.getNode( "fgh" ).setCollapse( true );
7424             t16.getNode( "gh" ).setCollapse( true );
7425             t16.getNode( "cd" ).setCollapse( true );
7426             t16.getNode( "cde" ).setCollapse( true );
7427             t16.getNode( "d" ).setCollapse( true );
7428             t16.getNode( "x" ).setCollapse( true );
7429             n = t16.getNode( "ab" );
7430             while ( n != null ) {
7431                 ext.add( n );
7432                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7433             }
7434             if ( ext.size() != 4 ) {
7435                 return false;
7436             }
7437             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7438                 return false;
7439             }
7440             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7441                 return false;
7442             }
7443             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
7444                 return false;
7445             }
7446             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
7447                 return false;
7448             }
7449         }
7450         catch ( final Exception e ) {
7451             e.printStackTrace( System.out );
7452             return false;
7453         }
7454         return true;
7455     }
7456
7457     private static boolean testNexusCharactersParsing() {
7458         try {
7459             final NexusCharactersParser parser = new NexusCharactersParser();
7460             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
7461             parser.parse();
7462             String[] labels = parser.getCharStateLabels();
7463             if ( labels.length != 7 ) {
7464                 return false;
7465             }
7466             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7467                 return false;
7468             }
7469             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7470                 return false;
7471             }
7472             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7473                 return false;
7474             }
7475             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7476                 return false;
7477             }
7478             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7479                 return false;
7480             }
7481             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7482                 return false;
7483             }
7484             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7485                 return false;
7486             }
7487             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7488             parser.parse();
7489             labels = parser.getCharStateLabels();
7490             if ( labels.length != 7 ) {
7491                 return false;
7492             }
7493             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7494                 return false;
7495             }
7496             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7497                 return false;
7498             }
7499             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7500                 return false;
7501             }
7502             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7503                 return false;
7504             }
7505             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7506                 return false;
7507             }
7508             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7509                 return false;
7510             }
7511             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7512                 return false;
7513             }
7514         }
7515         catch ( final Exception e ) {
7516             e.printStackTrace( System.out );
7517             return false;
7518         }
7519         return true;
7520     }
7521
7522     private static boolean testNexusMatrixParsing() {
7523         try {
7524             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7525             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7526             parser.parse();
7527             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7528             if ( m.getNumberOfCharacters() != 9 ) {
7529                 return false;
7530             }
7531             if ( m.getNumberOfIdentifiers() != 5 ) {
7532                 return false;
7533             }
7534             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7535                 return false;
7536             }
7537             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7538                 return false;
7539             }
7540             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7541                 return false;
7542             }
7543             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7544                 return false;
7545             }
7546             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7547                 return false;
7548             }
7549             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7550                 return false;
7551             }
7552             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7553                 return false;
7554             }
7555             //            if ( labels.length != 7 ) {
7556             //                return false;
7557             //            }
7558             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7559             //                return false;
7560             //            }
7561             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7562             //                return false;
7563             //            }
7564             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7565             //                return false;
7566             //            }
7567             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7568             //                return false;
7569             //            }
7570             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7571             //                return false;
7572             //            }
7573             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7574             //                return false;
7575             //            }
7576             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7577             //                return false;
7578             //            }
7579             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7580             //            parser.parse();
7581             //            labels = parser.getCharStateLabels();
7582             //            if ( labels.length != 7 ) {
7583             //                return false;
7584             //            }
7585             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7586             //                return false;
7587             //            }
7588             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7589             //                return false;
7590             //            }
7591             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7592             //                return false;
7593             //            }
7594             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7595             //                return false;
7596             //            }
7597             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7598             //                return false;
7599             //            }
7600             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7601             //                return false;
7602             //            }
7603             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7604             //                return false;
7605             //            }
7606         }
7607         catch ( final Exception e ) {
7608             e.printStackTrace( System.out );
7609             return false;
7610         }
7611         return true;
7612     }
7613
7614     private static boolean testNexusTreeParsing() {
7615         try {
7616             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7617             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7618             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7619             if ( phylogenies.length != 1 ) {
7620                 return false;
7621             }
7622             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7623                 return false;
7624             }
7625             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7626                 return false;
7627             }
7628             phylogenies = null;
7629             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7630             if ( phylogenies.length != 1 ) {
7631                 return false;
7632             }
7633             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7634                 return false;
7635             }
7636             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7637                 return false;
7638             }
7639             phylogenies = null;
7640             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7641             if ( phylogenies.length != 1 ) {
7642                 return false;
7643             }
7644             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7645                 return false;
7646             }
7647             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7648                 return false;
7649             }
7650             if ( phylogenies[ 0 ].isRooted() ) {
7651                 return false;
7652             }
7653             phylogenies = null;
7654             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7655             if ( phylogenies.length != 18 ) {
7656                 return false;
7657             }
7658             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7659                 return false;
7660             }
7661             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7662                 return false;
7663             }
7664             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7665                 return false;
7666             }
7667             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7668                 return false;
7669             }
7670             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7671                 return false;
7672             }
7673             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7674                 return false;
7675             }
7676             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7677                 return false;
7678             }
7679             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7680                 return false;
7681             }
7682             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7683                 return false;
7684             }
7685             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7686                 return false;
7687             }
7688             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7689                 return false;
7690             }
7691             if ( phylogenies[ 8 ].isRooted() ) {
7692                 return false;
7693             }
7694             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7695                 return false;
7696             }
7697             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7698                 return false;
7699             }
7700             if ( !phylogenies[ 9 ].isRooted() ) {
7701                 return false;
7702             }
7703             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7704                 return false;
7705             }
7706             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7707                 return false;
7708             }
7709             if ( !phylogenies[ 10 ].isRooted() ) {
7710                 return false;
7711             }
7712             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7713                 return false;
7714             }
7715             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7716                 return false;
7717             }
7718             if ( phylogenies[ 11 ].isRooted() ) {
7719                 return false;
7720             }
7721             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7722                 return false;
7723             }
7724             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7725                 return false;
7726             }
7727             if ( !phylogenies[ 12 ].isRooted() ) {
7728                 return false;
7729             }
7730             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7731                 return false;
7732             }
7733             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7734                 return false;
7735             }
7736             if ( !phylogenies[ 13 ].isRooted() ) {
7737                 return false;
7738             }
7739             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7740                 return false;
7741             }
7742             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7743                 return false;
7744             }
7745             if ( !phylogenies[ 14 ].isRooted() ) {
7746                 return false;
7747             }
7748             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7749                 return false;
7750             }
7751             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7752                 return false;
7753             }
7754             if ( phylogenies[ 15 ].isRooted() ) {
7755                 return false;
7756             }
7757             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7758                 return false;
7759             }
7760             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7761                 return false;
7762             }
7763             if ( !phylogenies[ 16 ].isRooted() ) {
7764                 return false;
7765             }
7766             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7767                 return false;
7768             }
7769             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7770                 return false;
7771             }
7772             if ( phylogenies[ 17 ].isRooted() ) {
7773                 return false;
7774             }
7775             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7776                 return false;
7777             }
7778             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7779             phylogenies = null;
7780             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7781             if ( phylogenies.length != 9 ) {
7782                 return false;
7783             }
7784             if ( !isEqual( 0.48039661496919533,
7785                            phylogenies[ 0 ].getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7786                 return false;
7787             }
7788             if ( !isEqual( 0.3959796191512233,
7789                            phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7790                 return false;
7791             }
7792             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7793                 return false;
7794             }
7795             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7796                 return false;
7797             }
7798             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7799                 return false;
7800             }
7801             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7802                 return false;
7803             }
7804             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7805                 return false;
7806             }
7807         }
7808         catch ( final Exception e ) {
7809             e.printStackTrace( System.out );
7810             return false;
7811         }
7812         return true;
7813     }
7814
7815     private static boolean testNexusTreeParsingIterating() {
7816         try {
7817             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7818             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7819             if ( !p.hasNext() ) {
7820                 return false;
7821             }
7822             Phylogeny phy = p.next();
7823             if ( phy == null ) {
7824                 return false;
7825             }
7826             if ( phy.getNumberOfExternalNodes() != 25 ) {
7827                 return false;
7828             }
7829             if ( !phy.getName().equals( "" ) ) {
7830                 return false;
7831             }
7832             if ( p.hasNext() ) {
7833                 return false;
7834             }
7835             phy = p.next();
7836             if ( phy != null ) {
7837                 return false;
7838             }
7839             p.reset();
7840             if ( !p.hasNext() ) {
7841                 return false;
7842             }
7843             phy = p.next();
7844             if ( phy == null ) {
7845                 return false;
7846             }
7847             if ( phy.getNumberOfExternalNodes() != 25 ) {
7848                 return false;
7849             }
7850             if ( !phy.getName().equals( "" ) ) {
7851                 return false;
7852             }
7853             if ( p.hasNext() ) {
7854                 return false;
7855             }
7856             phy = p.next();
7857             if ( phy != null ) {
7858                 return false;
7859             }
7860             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7861             if ( !p.hasNext() ) {
7862                 return false;
7863             }
7864             phy = p.next();
7865             if ( phy == null ) {
7866                 return false;
7867             }
7868             if ( phy.getNumberOfExternalNodes() != 10 ) {
7869                 return false;
7870             }
7871             if ( !phy.getName().equals( "name" ) ) {
7872                 return false;
7873             }
7874             if ( p.hasNext() ) {
7875                 return false;
7876             }
7877             phy = p.next();
7878             if ( phy != null ) {
7879                 return false;
7880             }
7881             p.reset();
7882             if ( !p.hasNext() ) {
7883                 return false;
7884             }
7885             phy = p.next();
7886             if ( phy == null ) {
7887                 return false;
7888             }
7889             if ( phy.getNumberOfExternalNodes() != 10 ) {
7890                 return false;
7891             }
7892             if ( !phy.getName().equals( "name" ) ) {
7893                 return false;
7894             }
7895             if ( p.hasNext() ) {
7896                 return false;
7897             }
7898             phy = p.next();
7899             if ( phy != null ) {
7900                 return false;
7901             }
7902             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7903             if ( !p.hasNext() ) {
7904                 return false;
7905             }
7906             phy = p.next();
7907             if ( phy == null ) {
7908                 return false;
7909             }
7910             if ( phy.getNumberOfExternalNodes() != 3 ) {
7911                 return false;
7912             }
7913             if ( !phy.getName().equals( "" ) ) {
7914                 return false;
7915             }
7916             if ( phy.isRooted() ) {
7917                 return false;
7918             }
7919             if ( p.hasNext() ) {
7920                 return false;
7921             }
7922             phy = p.next();
7923             if ( phy != null ) {
7924                 return false;
7925             }
7926             //
7927             p.reset();
7928             if ( !p.hasNext() ) {
7929                 return false;
7930             }
7931             phy = p.next();
7932             if ( phy == null ) {
7933                 return false;
7934             }
7935             if ( phy.getNumberOfExternalNodes() != 3 ) {
7936                 return false;
7937             }
7938             if ( !phy.getName().equals( "" ) ) {
7939                 return false;
7940             }
7941             if ( p.hasNext() ) {
7942                 return false;
7943             }
7944             phy = p.next();
7945             if ( phy != null ) {
7946                 return false;
7947             }
7948             //
7949             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7950             if ( !p.hasNext() ) {
7951                 return false;
7952             }
7953             //0
7954             phy = p.next();
7955             if ( phy == null ) {
7956                 return false;
7957             }
7958             if ( phy.getNumberOfExternalNodes() != 10 ) {
7959                 return false;
7960             }
7961             if ( !phy.getName().equals( "tree 0" ) ) {
7962                 return false;
7963             }
7964             //1
7965             if ( !p.hasNext() ) {
7966                 return false;
7967             }
7968             phy = p.next();
7969             if ( phy == null ) {
7970                 return false;
7971             }
7972             if ( phy.getNumberOfExternalNodes() != 10 ) {
7973                 return false;
7974             }
7975             if ( !phy.getName().equals( "tree 1" ) ) {
7976                 return false;
7977             }
7978             //2
7979             if ( !p.hasNext() ) {
7980                 return false;
7981             }
7982             phy = p.next();
7983             if ( phy == null ) {
7984                 return false;
7985             }
7986             if ( phy.getNumberOfExternalNodes() != 3 ) {
7987                 System.out.println( phy.toString() );
7988                 return false;
7989             }
7990             if ( !phy.getName().equals( "" ) ) {
7991                 return false;
7992             }
7993             if ( phy.isRooted() ) {
7994                 return false;
7995             }
7996             //3
7997             if ( !p.hasNext() ) {
7998                 return false;
7999             }
8000             phy = p.next();
8001             if ( phy == null ) {
8002                 return false;
8003             }
8004             if ( phy.getNumberOfExternalNodes() != 4 ) {
8005                 return false;
8006             }
8007             if ( !phy.getName().equals( "" ) ) {
8008                 return false;
8009             }
8010             if ( !phy.isRooted() ) {
8011                 return false;
8012             }
8013             //4
8014             if ( !p.hasNext() ) {
8015                 return false;
8016             }
8017             phy = p.next();
8018             if ( phy == null ) {
8019                 return false;
8020             }
8021             if ( phy.getNumberOfExternalNodes() != 5 ) {
8022                 System.out.println( phy.getNumberOfExternalNodes() );
8023                 return false;
8024             }
8025             if ( !phy.getName().equals( "" ) ) {
8026                 return false;
8027             }
8028             if ( !phy.isRooted() ) {
8029                 return false;
8030             }
8031             //5
8032             if ( !p.hasNext() ) {
8033                 return false;
8034             }
8035             phy = p.next();
8036             if ( phy == null ) {
8037                 return false;
8038             }
8039             if ( phy.getNumberOfExternalNodes() != 3 ) {
8040                 return false;
8041             }
8042             if ( !phy.getName().equals( "" ) ) {
8043                 return false;
8044             }
8045             if ( phy.isRooted() ) {
8046                 return false;
8047             }
8048             //6
8049             if ( !p.hasNext() ) {
8050                 return false;
8051             }
8052             phy = p.next();
8053             if ( phy == null ) {
8054                 return false;
8055             }
8056             if ( phy.getNumberOfExternalNodes() != 2 ) {
8057                 return false;
8058             }
8059             if ( !phy.getName().equals( "" ) ) {
8060                 return false;
8061             }
8062             if ( !phy.isRooted() ) {
8063                 return false;
8064             }
8065             //7
8066             if ( !p.hasNext() ) {
8067                 return false;
8068             }
8069             phy = p.next();
8070             if ( phy.getNumberOfExternalNodes() != 3 ) {
8071                 return false;
8072             }
8073             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8074                 return false;
8075             }
8076             if ( !phy.isRooted() ) {
8077                 return false;
8078             }
8079             //8
8080             if ( !p.hasNext() ) {
8081                 return false;
8082             }
8083             phy = p.next();
8084             if ( phy.getNumberOfExternalNodes() != 3 ) {
8085                 return false;
8086             }
8087             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
8088                 return false;
8089             }
8090             if ( !phy.getName().equals( "tree 8" ) ) {
8091                 return false;
8092             }
8093             //9
8094             if ( !p.hasNext() ) {
8095                 return false;
8096             }
8097             phy = p.next();
8098             if ( phy.getNumberOfExternalNodes() != 3 ) {
8099                 return false;
8100             }
8101             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
8102                 return false;
8103             }
8104             if ( !phy.getName().equals( "tree 9" ) ) {
8105                 return false;
8106             }
8107             //10
8108             if ( !p.hasNext() ) {
8109                 return false;
8110             }
8111             phy = p.next();
8112             if ( phy.getNumberOfExternalNodes() != 3 ) {
8113                 return false;
8114             }
8115             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8116                 return false;
8117             }
8118             if ( !phy.getName().equals( "tree 10" ) ) {
8119                 return false;
8120             }
8121             if ( !phy.isRooted() ) {
8122                 return false;
8123             }
8124             //11
8125             if ( !p.hasNext() ) {
8126                 return false;
8127             }
8128             phy = p.next();
8129             if ( phy.getNumberOfExternalNodes() != 3 ) {
8130                 return false;
8131             }
8132             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
8133                 return false;
8134             }
8135             if ( !phy.getName().equals( "tree 11" ) ) {
8136                 return false;
8137             }
8138             if ( phy.isRooted() ) {
8139                 return false;
8140             }
8141             //12
8142             if ( !p.hasNext() ) {
8143                 return false;
8144             }
8145             phy = p.next();
8146             if ( phy.getNumberOfExternalNodes() != 3 ) {
8147                 return false;
8148             }
8149             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
8150                 return false;
8151             }
8152             if ( !phy.getName().equals( "tree 12" ) ) {
8153                 return false;
8154             }
8155             if ( !phy.isRooted() ) {
8156                 return false;
8157             }
8158             //13
8159             if ( !p.hasNext() ) {
8160                 return false;
8161             }
8162             phy = p.next();
8163             if ( phy.getNumberOfExternalNodes() != 3 ) {
8164                 return false;
8165             }
8166             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8167                 return false;
8168             }
8169             if ( !phy.getName().equals( "tree 13" ) ) {
8170                 return false;
8171             }
8172             if ( !phy.isRooted() ) {
8173                 return false;
8174             }
8175             //14
8176             if ( !p.hasNext() ) {
8177                 return false;
8178             }
8179             phy = p.next();
8180             if ( phy.getNumberOfExternalNodes() != 10 ) {
8181                 System.out.println( phy.getNumberOfExternalNodes() );
8182                 return false;
8183             }
8184             if ( !phy.toNewHampshire()
8185                     .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;" ) ) {
8186                 System.out.println( phy.toNewHampshire() );
8187                 return false;
8188             }
8189             if ( !phy.getName().equals( "tree 14" ) ) {
8190                 return false;
8191             }
8192             if ( !phy.isRooted() ) {
8193                 return false;
8194             }
8195             //15
8196             if ( !p.hasNext() ) {
8197                 return false;
8198             }
8199             phy = p.next();
8200             if ( phy.getNumberOfExternalNodes() != 10 ) {
8201                 System.out.println( phy.getNumberOfExternalNodes() );
8202                 return false;
8203             }
8204             if ( !phy.toNewHampshire()
8205                     .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;" ) ) {
8206                 System.out.println( phy.toNewHampshire() );
8207                 return false;
8208             }
8209             if ( !phy.getName().equals( "tree 15" ) ) {
8210                 return false;
8211             }
8212             if ( phy.isRooted() ) {
8213                 return false;
8214             }
8215             //16
8216             if ( !p.hasNext() ) {
8217                 return false;
8218             }
8219             phy = p.next();
8220             if ( phy.getNumberOfExternalNodes() != 10 ) {
8221                 System.out.println( phy.getNumberOfExternalNodes() );
8222                 return false;
8223             }
8224             if ( !phy.toNewHampshire()
8225                     .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;" ) ) {
8226                 System.out.println( phy.toNewHampshire() );
8227                 return false;
8228             }
8229             if ( !phy.getName().equals( "tree 16" ) ) {
8230                 return false;
8231             }
8232             if ( !phy.isRooted() ) {
8233                 return false;
8234             }
8235             //17
8236             if ( !p.hasNext() ) {
8237                 return false;
8238             }
8239             phy = p.next();
8240             if ( phy.getNumberOfExternalNodes() != 10 ) {
8241                 System.out.println( phy.getNumberOfExternalNodes() );
8242                 return false;
8243             }
8244             if ( !phy.toNewHampshire()
8245                     .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;" ) ) {
8246                 System.out.println( phy.toNewHampshire() );
8247                 return false;
8248             }
8249             if ( !phy.getName().equals( "tree 17" ) ) {
8250                 return false;
8251             }
8252             if ( phy.isRooted() ) {
8253                 return false;
8254             }
8255             //
8256             if ( p.hasNext() ) {
8257                 return false;
8258             }
8259             phy = p.next();
8260             if ( phy != null ) {
8261                 return false;
8262             }
8263             p.reset();
8264             //0
8265             if ( !p.hasNext() ) {
8266                 return false;
8267             }
8268             phy = p.next();
8269             if ( phy == null ) {
8270                 return false;
8271             }
8272             if ( phy.getNumberOfExternalNodes() != 10 ) {
8273                 return false;
8274             }
8275             if ( !phy.getName().equals( "tree 0" ) ) {
8276                 return false;
8277             }
8278             //1
8279             if ( !p.hasNext() ) {
8280                 return false;
8281             }
8282             phy = p.next();
8283             if ( phy == null ) {
8284                 return false;
8285             }
8286             if ( phy.getNumberOfExternalNodes() != 10 ) {
8287                 return false;
8288             }
8289             if ( !phy.getName().equals( "tree 1" ) ) {
8290                 return false;
8291             }
8292             //2
8293             if ( !p.hasNext() ) {
8294                 return false;
8295             }
8296             phy = p.next();
8297             if ( phy == null ) {
8298                 return false;
8299             }
8300             if ( phy.getNumberOfExternalNodes() != 3 ) {
8301                 return false;
8302             }
8303             if ( !phy.getName().equals( "" ) ) {
8304                 return false;
8305             }
8306             if ( phy.isRooted() ) {
8307                 return false;
8308             }
8309             //3
8310             if ( !p.hasNext() ) {
8311                 return false;
8312             }
8313             phy = p.next();
8314             if ( phy == null ) {
8315                 return false;
8316             }
8317             if ( phy.getNumberOfExternalNodes() != 4 ) {
8318                 return false;
8319             }
8320             if ( !phy.getName().equals( "" ) ) {
8321                 return false;
8322             }
8323             if ( !phy.isRooted() ) {
8324                 return false;
8325             }
8326             //4
8327             if ( !p.hasNext() ) {
8328                 return false;
8329             }
8330             phy = p.next();
8331             if ( phy == null ) {
8332                 return false;
8333             }
8334             if ( phy.getNumberOfExternalNodes() != 5 ) {
8335                 System.out.println( phy.getNumberOfExternalNodes() );
8336                 return false;
8337             }
8338             if ( !phy.getName().equals( "" ) ) {
8339                 return false;
8340             }
8341             if ( !phy.isRooted() ) {
8342                 return false;
8343             }
8344             //5
8345             if ( !p.hasNext() ) {
8346                 return false;
8347             }
8348             phy = p.next();
8349             if ( phy == null ) {
8350                 return false;
8351             }
8352             if ( phy.getNumberOfExternalNodes() != 3 ) {
8353                 return false;
8354             }
8355             if ( !phy.getName().equals( "" ) ) {
8356                 return false;
8357             }
8358             if ( phy.isRooted() ) {
8359                 return false;
8360             }
8361             //
8362             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
8363             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
8364             // 0
8365             if ( !p2.hasNext() ) {
8366                 return false;
8367             }
8368             phy = p2.next();
8369             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8370                 return false;
8371             }
8372             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8373                 return false;
8374             }
8375             // 1
8376             if ( !p2.hasNext() ) {
8377                 return false;
8378             }
8379             phy = p2.next();
8380             // 2
8381             if ( !p2.hasNext() ) {
8382                 return false;
8383             }
8384             phy = p2.next();
8385             // 3
8386             if ( !p2.hasNext() ) {
8387                 return false;
8388             }
8389             phy = p2.next();
8390             // 4
8391             if ( !p2.hasNext() ) {
8392                 return false;
8393             }
8394             phy = p2.next();
8395             // 5
8396             if ( !p2.hasNext() ) {
8397                 return false;
8398             }
8399             phy = p2.next();
8400             // 6
8401             if ( !p2.hasNext() ) {
8402                 return false;
8403             }
8404             phy = p2.next();
8405             // 7
8406             if ( !p2.hasNext() ) {
8407                 return false;
8408             }
8409             phy = p2.next();
8410             // 8
8411             if ( !p2.hasNext() ) {
8412                 return false;
8413             }
8414             phy = p2.next();
8415             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
8416                 return false;
8417             }
8418             if ( p2.hasNext() ) {
8419                 return false;
8420             }
8421             phy = p2.next();
8422             if ( phy != null ) {
8423                 return false;
8424             }
8425             // 0
8426             p2.reset();
8427             if ( !p2.hasNext() ) {
8428                 return false;
8429             }
8430             phy = p2.next();
8431             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8432                 return false;
8433             }
8434             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8435                 return false;
8436             }
8437         }
8438         catch ( final Exception e ) {
8439             e.printStackTrace( System.out );
8440             return false;
8441         }
8442         return true;
8443     }
8444
8445     private static boolean testNexusTreeParsingTranslating() {
8446         try {
8447             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8448             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
8449             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
8450             if ( phylogenies.length != 1 ) {
8451                 return false;
8452             }
8453             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8454                 return false;
8455             }
8456             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8457                 return false;
8458             }
8459             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8460                 return false;
8461             }
8462             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8463                 return false;
8464             }
8465             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8466                     .equals( "Aranaeus" ) ) {
8467                 return false;
8468             }
8469             phylogenies = null;
8470             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
8471             if ( phylogenies.length != 3 ) {
8472                 return false;
8473             }
8474             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8475                 return false;
8476             }
8477             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8478                 return false;
8479             }
8480             if ( phylogenies[ 0 ].isRooted() ) {
8481                 return false;
8482             }
8483             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8484                 return false;
8485             }
8486             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8487                 return false;
8488             }
8489             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8490                     .equals( "Aranaeus" ) ) {
8491                 return false;
8492             }
8493             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8494                 return false;
8495             }
8496             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8497                 return false;
8498             }
8499             if ( phylogenies[ 1 ].isRooted() ) {
8500                 return false;
8501             }
8502             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8503                 return false;
8504             }
8505             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8506                 return false;
8507             }
8508             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8509                     .equals( "Aranaeus" ) ) {
8510                 return false;
8511             }
8512             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8513                 return false;
8514             }
8515             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8516                 return false;
8517             }
8518             if ( !phylogenies[ 2 ].isRooted() ) {
8519                 return false;
8520             }
8521             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8522                 return false;
8523             }
8524             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8525                 return false;
8526             }
8527             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8528                     .equals( "Aranaeus" ) ) {
8529                 return false;
8530             }
8531             phylogenies = null;
8532             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8533             if ( phylogenies.length != 3 ) {
8534                 return false;
8535             }
8536             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8537                 return false;
8538             }
8539             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8540                 return false;
8541             }
8542             if ( phylogenies[ 0 ].isRooted() ) {
8543                 return false;
8544             }
8545             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8546                 return false;
8547             }
8548             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8549                 return false;
8550             }
8551             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8552                     .equals( "Aranaeus" ) ) {
8553                 return false;
8554             }
8555             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8556                 return false;
8557             }
8558             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8559                 return false;
8560             }
8561             if ( phylogenies[ 1 ].isRooted() ) {
8562                 return false;
8563             }
8564             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8565                 return false;
8566             }
8567             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8568                 return false;
8569             }
8570             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8571                     .equals( "Aranaeus" ) ) {
8572                 return false;
8573             }
8574             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8575                 return false;
8576             }
8577             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8578                 return false;
8579             }
8580             if ( !phylogenies[ 2 ].isRooted() ) {
8581                 return false;
8582             }
8583             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8584                 return false;
8585             }
8586             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8587                 return false;
8588             }
8589             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8590                     .equals( "Aranaeus" ) ) {
8591                 return false;
8592             }
8593             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8594             if ( phylogenies.length != 3 ) {
8595                 return false;
8596             }
8597             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8598                            0.00100049 ) ) {
8599                 return false;
8600             }
8601         }
8602         catch ( final Exception e ) {
8603             e.printStackTrace( System.out );
8604             return false;
8605         }
8606         return true;
8607     }
8608
8609     private static boolean testNHParsing() {
8610         try {
8611             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8612             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8613             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8614                 return false;
8615             }
8616             final NHXParser nhxp = new NHXParser();
8617             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8618             nhxp.setReplaceUnderscores( true );
8619             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8620             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8621                 return false;
8622             }
8623             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8624                 return false;
8625             }
8626             final Phylogeny p1b = factory.create(
8627                                                   "   \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 ",
8628                                                   new NHXParser() )[ 0 ];
8629             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8630                 return false;
8631             }
8632             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8633                 return false;
8634             }
8635             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ).toString(), new NHXParser() )[ 0 ];
8636             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8637             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8638             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ).toString(), new NHXParser() )[ 0 ];
8639             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8640             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8641             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8642             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8643             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8644             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8645             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8646                     + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; " + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8647                                                     new NHXParser() );
8648             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8649                 return false;
8650             }
8651             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8652                 return false;
8653             }
8654             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8655                 return false;
8656             }
8657             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8658                 return false;
8659             }
8660             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8661             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8662             final String p16_S = "((A,B),C)";
8663             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8664             if ( p16.length != 1 ) {
8665                 return false;
8666             }
8667             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8668                 return false;
8669             }
8670             final String p17_S = "(C,(A,B))";
8671             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8672             if ( p17.length != 1 ) {
8673                 return false;
8674             }
8675             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8676                 return false;
8677             }
8678             final String p18_S = "((A,B),(C,D))";
8679             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8680             if ( p18.length != 1 ) {
8681                 return false;
8682             }
8683             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8684                 return false;
8685             }
8686             final String p19_S = "(((A,B),C),D)";
8687             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8688             if ( p19.length != 1 ) {
8689                 return false;
8690             }
8691             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8692                 return false;
8693             }
8694             final String p20_S = "(A,(B,(C,D)))";
8695             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8696             if ( p20.length != 1 ) {
8697                 return false;
8698             }
8699             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8700                 return false;
8701             }
8702             final String p21_S = "(A,(B,(C,(D,E))))";
8703             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8704             if ( p21.length != 1 ) {
8705                 return false;
8706             }
8707             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8708                 return false;
8709             }
8710             final String p22_S = "((((A,B),C),D),E)";
8711             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8712             if ( p22.length != 1 ) {
8713                 return false;
8714             }
8715             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8716                 return false;
8717             }
8718             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8719             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8720             if ( p23.length != 1 ) {
8721                 System.out.println( "xl=" + p23.length );
8722                 System.exit( -1 );
8723                 return false;
8724             }
8725             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8726                 return false;
8727             }
8728             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8729             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8730             if ( p24.length != 1 ) {
8731                 return false;
8732             }
8733             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8734                 return false;
8735             }
8736             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8737             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8738             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8739             if ( p241.length != 2 ) {
8740                 return false;
8741             }
8742             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8743                 return false;
8744             }
8745             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8746                 return false;
8747             }
8748             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8749                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8750                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8751                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8752                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8753                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8754                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8755                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8756             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8757             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8758                 return false;
8759             }
8760             final String p26_S = "(A,B)ab";
8761             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8762             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8763                 return false;
8764             }
8765             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8766             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8767             if ( p27s.length != 1 ) {
8768                 System.out.println( "xxl=" + p27s.length );
8769                 System.exit( -1 );
8770                 return false;
8771             }
8772             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8773                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8774                 System.exit( -1 );
8775                 return false;
8776             }
8777             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8778                                                     new NHXParser() );
8779             if ( p27.length != 1 ) {
8780                 System.out.println( "yl=" + p27.length );
8781                 System.exit( -1 );
8782                 return false;
8783             }
8784             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8785                 System.out.println( p27[ 0 ].toNewHampshireX() );
8786                 System.exit( -1 );
8787                 return false;
8788             }
8789             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8790             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8791             final String p28_S3 = "(A,B)ab";
8792             final String p28_S4 = "((((A,B),C),D),;E;)";
8793             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8794                                                     new NHXParser() );
8795             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8796                 return false;
8797             }
8798             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8799                 return false;
8800             }
8801             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8802                 return false;
8803             }
8804             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8805                 return false;
8806             }
8807             if ( p28.length != 4 ) {
8808                 return false;
8809             }
8810             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";
8811             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8812             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8813                 return false;
8814             }
8815             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";
8816             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8817             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8818                 return false;
8819             }
8820             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8821             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8822             if ( ( p32.length != 0 ) ) {
8823                 return false;
8824             }
8825             final String p33_S = "A";
8826             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8827             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8828                 return false;
8829             }
8830             final String p34_S = "B;";
8831             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8832             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8833                 return false;
8834             }
8835             final String p35_S = "B:0.2";
8836             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8837             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8838                 return false;
8839             }
8840             final String p36_S = "(A)";
8841             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8842             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8843                 return false;
8844             }
8845             final String p37_S = "((A))";
8846             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8847             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8848                 return false;
8849             }
8850             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8851             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8852             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8853                 return false;
8854             }
8855             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8856             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8857             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8858                 return false;
8859             }
8860             final String p40_S = "(A,B,C)";
8861             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8862             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8863                 return false;
8864             }
8865             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8866             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8867             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8868                 return false;
8869             }
8870             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8871             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8872             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8873                 return false;
8874             }
8875             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)";
8876             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8877             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8878                 return false;
8879             }
8880             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)))";
8881             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8882             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8883                 return false;
8884             }
8885             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8886             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8887             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8888                 return false;
8889             }
8890             final String p46_S = "";
8891             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8892             if ( p46.length != 0 ) {
8893                 return false;
8894             }
8895             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ).toString(),
8896                                                   new NHXParser() )[ 0 ];
8897             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8898                 return false;
8899             }
8900             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ).toString(),
8901                                                   new NHXParser() )[ 0 ];
8902             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8903                 return false;
8904             }
8905             final Phylogeny p49 = factory
8906                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ).toString(),
8907                              new NHXParser() )[ 0 ];
8908             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8909                 return false;
8910             }
8911             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ).toString(),
8912                                                   new NHXParser() )[ 0 ];
8913             if ( p50.getNode( "A" ) == null ) {
8914                 return false;
8915             }
8916             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8917                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8918                 return false;
8919             }
8920             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8921                 return false;
8922             }
8923             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8924                     .equals( "((A,B)88:2.0,C);" ) ) {
8925                 return false;
8926             }
8927             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ).toString(),
8928                                                   new NHXParser() )[ 0 ];
8929             if ( p51.getNode( "A(A" ) == null ) {
8930                 return false;
8931             }
8932             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ).toString(),
8933                                                   new NHXParser() )[ 0 ];
8934             if ( p52.getNode( "A(A" ) == null ) {
8935                 return false;
8936             }
8937             final Phylogeny p53 = factory
8938                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ).toString(),
8939                              new NHXParser() )[ 0 ];
8940             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8941                 return false;
8942             }
8943             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ).toString(),
8944                                                   new NHXParser() )[ 0 ];
8945             if ( p54.getNode( "A" ) == null ) {
8946                 return false;
8947             }
8948             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8949                     .equals( "((A,B)[88],C);" ) ) {
8950                 return false;
8951             }
8952             final Phylogeny p55 = factory
8953                     .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);" )
8954                             .toString(), new NHXParser() )[ 0 ];
8955             if ( !p55.toNewHampshire()
8956                     .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);" ) ) {
8957                 System.out.println( p55.toNewHampshire() );
8958                 return false;
8959             }
8960             final Phylogeny p56 = factory
8961                     .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);" )
8962                             .toString(), new NHXParser() )[ 0 ];
8963             if ( !p56.toNewHampshire()
8964                     .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);" ) ) {
8965                 System.out.println( p56.toNewHampshire() );
8966                 return false;
8967             }
8968             final Phylogeny p57 = factory
8969                     .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);" )
8970                             .toString(), new NHXParser() )[ 0 ];
8971             if ( !p57.toNewHampshire()
8972                     .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);" ) ) {
8973                 System.out.println( p56.toNewHampshire() );
8974                 return false;
8975             }
8976             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8977             final Phylogeny p58 = factory.create( s58, new NHXParser() )[ 0 ];
8978             if ( !p58.toNewHampshire().equals( s58 ) ) {
8979                 System.out.println( p58.toNewHampshire() );
8980                 return false;
8981             }
8982             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8983             final Phylogeny p59 = factory.create( s59, new NHXParser() )[ 0 ];
8984             if ( !p59.toNewHampshire().equals( s59 ) ) {
8985                 System.out.println( p59.toNewHampshire() );
8986                 return false;
8987             }
8988             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8989             final Phylogeny p60 = factory.create( s60, new NHXParser() )[ 0 ];
8990             if ( !p60.toNewHampshire().equals( s60 ) ) {
8991                 System.out.println( p60.toNewHampshire() );
8992                 return false;
8993             }
8994             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8995             final Phylogeny p61 = factory.create( s61, new NHXParser() )[ 0 ];
8996             if ( !p61.toNewHampshire()
8997                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8998                 System.out.println( p61.toNewHampshire() );
8999                 return false;
9000             }
9001             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;";
9002             final Phylogeny p62 = factory.create( s62, new NHXParser() )[ 0 ];
9003             if ( !p62.toNewHampshire().equals( "(1:0.003,2:0.004):0.0;" ) ) {
9004                 System.out.println( p62.toNewHampshire() );
9005                 return false;
9006             }
9007             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)\"];";
9008             final Phylogeny p63 = factory.create( s63, new NHXParser() )[ 0 ];
9009             if ( !p63.toNewHampshire().equals( "(1:0.003,2:0.004):0.0;" ) ) {
9010                 System.out.println( p63.toNewHampshire() );
9011                 return false;
9012             }
9013             final String s64 = "((1,2):[95.5],3);";
9014             final Phylogeny p64 = factory.create( s64, new NHXParser() )[ 0 ];
9015             if ( !p64.toNewHampshireX().equals( "((1,2)[&&NHX:B=95.5],3)" ) ) {
9016                 System.out.println( p64.toNewHampshireX() );
9017                 return false;
9018             }
9019             final String s65 = "((1:0.1,2:0.2):0.3[10.2],3);";
9020             final Phylogeny p65 = factory.create( s65, new NHXParser() )[ 0 ];
9021             if ( !p65.toNewHampshireX().equals( "((1:0.1,2:0.2):0.3[&&NHX:B=10.2],3)" ) ) {
9022                 System.out.println( p65.toNewHampshireX() );
9023                 return false;
9024             }
9025             final Phylogeny p66 = factory.create( "((A,B)ab:2[0.44],C)", new NHXParser() )[ 0 ];
9026             if ( !isEqual( 0.44, p66.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
9027                 return false;
9028             }
9029             final Phylogeny p67 = factory.create( "((A,B):2[0.67],C)", new NHXParser() )[ 0 ];
9030             if ( !isEqual( 0.67, p67.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9031                 return false;
9032             }
9033             final Phylogeny p68 = factory.create( "((A,B):[0.68],C)", new NHXParser() )[ 0 ];
9034             if ( !isEqual( 0.68, p68.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9035                 return false;
9036             }
9037             final Phylogeny p69 = factory.create( "((A,B)[0.69],C)", new NHXParser() )[ 0 ];
9038             if ( !isEqual( 0.69, p69.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9039                 return false;
9040             }
9041             final Phylogeny p70 = factory.create( "((A,B)[+0.7],C)", new NHXParser() )[ 0 ];
9042             if ( !isEqual( 0.7, p70.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9043                 return false;
9044             }
9045             final Phylogeny p71 = factory.create( "((A,B)[-0.71],C)", new NHXParser() )[ 0 ];
9046             if ( !isEqual( -0.71, p71.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9047                 return false;
9048             }
9049             final Phylogeny p72 = factory.create( "((A,B)[],C)", new NHXParser() )[ 0 ];
9050             if ( !p72.toNewHampshireX().equals( "((A,B),C)" ) ) {
9051                 return false;
9052             }
9053             final Phylogeny p73 = factory.create( "((A,B)[12x],C)", new NHXParser() )[ 0 ];
9054             if ( !p73.toNewHampshireX().equals( "((A,B),C)" ) ) {
9055                 return false;
9056             }
9057             final Phylogeny p74 = factory.create( "((A,B)[12+],C)", new NHXParser() )[ 0 ];
9058             if ( !p74.toNewHampshireX().equals( "((A,B),C)" ) ) {
9059                 return false;
9060             }
9061             final Phylogeny p75 = factory.create( "((A,B)ab[222]:3,C)", new NHXParser() )[ 0 ];
9062             if ( !isEqual( 222, p75.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9063                 return false;
9064             }
9065             final Phylogeny p76 = factory.create( "((A,B)[100]:12,C)", new NHXParser() )[ 0 ];
9066             if ( !isEqual( 100, p76.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9067                 return false;
9068             }
9069             final Phylogeny p77 = factory.create( "((A,B)abcde:13[77],C)", new NHXParser() )[ 0 ];
9070             if ( !isEqual( 77, p77.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9071                 return false;
9072             }
9073             final Phylogeny p78 = factory.create( "((A,B):14[0],C)", new NHXParser() )[ 0 ];
9074             if ( !isEqual( 0, p78.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9075                 return false;
9076             }
9077             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];";
9078             final Phylogeny p79 = factory.create(
9079                                                   "((((((a,b)ab[2]:3,c)[100]:12,(d,e)de)abcde:13[2],f):14[0]):0[0])[0]:0;",
9080                                                   new NHXParser() )[ 0 ];
9081             final String str79 = p79.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
9082             if ( !str79.equals( the_one ) ) {
9083                 System.out.println( str79 );
9084                 return false;
9085             }
9086             final Phylogeny p80 = factory.create(
9087                                                   "((((((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;",
9088                                                   new NHXParser() )[ 0 ];
9089             final String str80 = p80.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
9090             if ( !str80.equals( the_one ) ) {
9091                 System.out.println( str80 );
9092                 return false;
9093             }
9094         }
9095         catch ( final Exception e ) {
9096             e.printStackTrace( System.out );
9097             return false;
9098         }
9099         return true;
9100     }
9101
9102     private static boolean testNHParsingSpecialChars() {
9103         try {
9104             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9105             final String i0 = "(A!+=~QWERTY!@#$%^&*-,€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ)";
9106             final Phylogeny p0 = factory.create( i0, new NHXParser() )[ 0 ];
9107             if ( !p0.toNewHampshireX().equals( i0 ) ) {
9108                 System.out.println();
9109                 System.out.println( p0.toNewHampshireX() );
9110                 System.out.println( i0 );
9111                 return false;
9112             }
9113             final String i1 = "(हिंदी,한글,ไทย,'Tiếng Việt',ひらがなカタカナ漢字,繁體字,русский)";
9114             final Phylogeny p1 = factory.create( i1, new NHXParser() )[ 0 ];
9115             if ( !p1.toNewHampshireX().equals( i1 ) ) {
9116                 System.out.println();
9117                 System.out.println( p1.toNewHampshireX() );
9118                 System.out.println( i1 );
9119                 return false;
9120             }
9121         }
9122         catch ( final Exception e ) {
9123             e.printStackTrace( System.out );
9124             return false;
9125         }
9126         return true;
9127     }
9128
9129     private static boolean testNHParsingIter() {
9130         try {
9131             final String p0_str = "(A,B);";
9132             final NHXParser p = new NHXParser();
9133             p.setSource( p0_str );
9134             if ( !p.hasNext() ) {
9135                 return false;
9136             }
9137             final Phylogeny p0 = p.next();
9138             if ( !p0.toNewHampshire().equals( p0_str ) ) {
9139                 System.out.println( p0.toNewHampshire() );
9140                 return false;
9141             }
9142             if ( p.hasNext() ) {
9143                 return false;
9144             }
9145             if ( p.next() != null ) {
9146                 return false;
9147             }
9148             //
9149             final String p00_str = "(A,B)root;";
9150             p.setSource( p00_str );
9151             final Phylogeny p00 = p.next();
9152             if ( !p00.toNewHampshire().equals( p00_str ) ) {
9153                 System.out.println( p00.toNewHampshire() );
9154                 return false;
9155             }
9156             //
9157             final String p000_str = "A;";
9158             p.setSource( p000_str );
9159             final Phylogeny p000 = p.next();
9160             if ( !p000.toNewHampshire().equals( p000_str ) ) {
9161                 System.out.println( p000.toNewHampshire() );
9162                 return false;
9163             }
9164             //
9165             final String p0000_str = "A";
9166             p.setSource( p0000_str );
9167             final Phylogeny p0000 = p.next();
9168             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
9169                 System.out.println( p0000.toNewHampshire() );
9170                 return false;
9171             }
9172             //
9173             p.setSource( "(A)" );
9174             final Phylogeny p00000 = p.next();
9175             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
9176                 System.out.println( p00000.toNewHampshire() );
9177                 return false;
9178             }
9179             //
9180             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
9181             p.setSource( p1_str );
9182             if ( !p.hasNext() ) {
9183                 return false;
9184             }
9185             final Phylogeny p1_0 = p.next();
9186             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
9187                 System.out.println( p1_0.toNewHampshire() );
9188                 return false;
9189             }
9190             if ( !p.hasNext() ) {
9191                 return false;
9192             }
9193             final Phylogeny p1_1 = p.next();
9194             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
9195                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
9196                 return false;
9197             }
9198             if ( !p.hasNext() ) {
9199                 return false;
9200             }
9201             final Phylogeny p1_2 = p.next();
9202             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
9203                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
9204                 return false;
9205             }
9206             if ( !p.hasNext() ) {
9207                 return false;
9208             }
9209             final Phylogeny p1_3 = p.next();
9210             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
9211                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
9212                 return false;
9213             }
9214             if ( p.hasNext() ) {
9215                 return false;
9216             }
9217             if ( p.next() != null ) {
9218                 return false;
9219             }
9220             //
9221             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
9222             p.setSource( p2_str );
9223             if ( !p.hasNext() ) {
9224                 return false;
9225             }
9226             Phylogeny p2_0 = p.next();
9227             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9228                 System.out.println( p2_0.toNewHampshire() );
9229                 return false;
9230             }
9231             if ( !p.hasNext() ) {
9232                 return false;
9233             }
9234             Phylogeny p2_1 = p.next();
9235             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9236                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9237                 return false;
9238             }
9239             if ( !p.hasNext() ) {
9240                 return false;
9241             }
9242             Phylogeny p2_2 = p.next();
9243             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9244                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9245                 return false;
9246             }
9247             if ( !p.hasNext() ) {
9248                 return false;
9249             }
9250             Phylogeny p2_3 = p.next();
9251             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9252                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9253                 return false;
9254             }
9255             if ( !p.hasNext() ) {
9256                 return false;
9257             }
9258             Phylogeny p2_4 = p.next();
9259             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9260                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9261                 return false;
9262             }
9263             if ( p.hasNext() ) {
9264                 return false;
9265             }
9266             if ( p.next() != null ) {
9267                 return false;
9268             }
9269             ////
9270             p.reset();
9271             if ( !p.hasNext() ) {
9272                 return false;
9273             }
9274             p2_0 = p.next();
9275             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9276                 System.out.println( p2_0.toNewHampshire() );
9277                 return false;
9278             }
9279             if ( !p.hasNext() ) {
9280                 return false;
9281             }
9282             p2_1 = p.next();
9283             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9284                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9285                 return false;
9286             }
9287             if ( !p.hasNext() ) {
9288                 return false;
9289             }
9290             p2_2 = p.next();
9291             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9292                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9293                 return false;
9294             }
9295             if ( !p.hasNext() ) {
9296                 return false;
9297             }
9298             p2_3 = p.next();
9299             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9300                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9301                 return false;
9302             }
9303             if ( !p.hasNext() ) {
9304                 return false;
9305             }
9306             p2_4 = p.next();
9307             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9308                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9309                 return false;
9310             }
9311             if ( p.hasNext() ) {
9312                 return false;
9313             }
9314             if ( p.next() != null ) {
9315                 return false;
9316             }
9317             //
9318             final String p3_str = "((A,B),C)abc";
9319             p.setSource( p3_str );
9320             if ( !p.hasNext() ) {
9321                 return false;
9322             }
9323             final Phylogeny p3_0 = p.next();
9324             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
9325                 return false;
9326             }
9327             if ( p.hasNext() ) {
9328                 return false;
9329             }
9330             if ( p.next() != null ) {
9331                 return false;
9332             }
9333             //
9334             final String p4_str = "((A,B)ab,C)abc";
9335             p.setSource( p4_str );
9336             if ( !p.hasNext() ) {
9337                 return false;
9338             }
9339             final Phylogeny p4_0 = p.next();
9340             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
9341                 return false;
9342             }
9343             if ( p.hasNext() ) {
9344                 return false;
9345             }
9346             if ( p.next() != null ) {
9347                 return false;
9348             }
9349             //
9350             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
9351             p.setSource( p5_str );
9352             if ( !p.hasNext() ) {
9353                 return false;
9354             }
9355             final Phylogeny p5_0 = p.next();
9356             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
9357                 return false;
9358             }
9359             if ( p.hasNext() ) {
9360                 return false;
9361             }
9362             if ( p.next() != null ) {
9363                 return false;
9364             }
9365             //
9366             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
9367             p.setSource( p6_str );
9368             if ( !p.hasNext() ) {
9369                 return false;
9370             }
9371             Phylogeny p6_0 = p.next();
9372             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9373                 return false;
9374             }
9375             if ( p.hasNext() ) {
9376                 return false;
9377             }
9378             if ( p.next() != null ) {
9379                 return false;
9380             }
9381             p.reset();
9382             if ( !p.hasNext() ) {
9383                 return false;
9384             }
9385             p6_0 = p.next();
9386             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9387                 return false;
9388             }
9389             if ( p.hasNext() ) {
9390                 return false;
9391             }
9392             if ( p.next() != null ) {
9393                 return false;
9394             }
9395             //
9396             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
9397             p.setSource( p7_str );
9398             if ( !p.hasNext() ) {
9399                 return false;
9400             }
9401             Phylogeny p7_0 = p.next();
9402             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9403                 return false;
9404             }
9405             if ( p.hasNext() ) {
9406                 return false;
9407             }
9408             if ( p.next() != null ) {
9409                 return false;
9410             }
9411             p.reset();
9412             if ( !p.hasNext() ) {
9413                 return false;
9414             }
9415             p7_0 = p.next();
9416             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9417                 return false;
9418             }
9419             if ( p.hasNext() ) {
9420                 return false;
9421             }
9422             if ( p.next() != null ) {
9423                 return false;
9424             }
9425             //
9426             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
9427             p.setSource( p8_str );
9428             if ( !p.hasNext() ) {
9429                 return false;
9430             }
9431             Phylogeny p8_0 = p.next();
9432             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9433                 return false;
9434             }
9435             if ( !p.hasNext() ) {
9436                 return false;
9437             }
9438             if ( !p.hasNext() ) {
9439                 return false;
9440             }
9441             Phylogeny p8_1 = p.next();
9442             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9443                 return false;
9444             }
9445             if ( p.hasNext() ) {
9446                 return false;
9447             }
9448             if ( p.next() != null ) {
9449                 return false;
9450             }
9451             p.reset();
9452             if ( !p.hasNext() ) {
9453                 return false;
9454             }
9455             p8_0 = p.next();
9456             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9457                 return false;
9458             }
9459             if ( !p.hasNext() ) {
9460                 return false;
9461             }
9462             p8_1 = p.next();
9463             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9464                 return false;
9465             }
9466             if ( p.hasNext() ) {
9467                 return false;
9468             }
9469             if ( p.next() != null ) {
9470                 return false;
9471             }
9472             p.reset();
9473             //
9474             p.setSource( "" );
9475             if ( p.hasNext() ) {
9476                 return false;
9477             }
9478             //
9479             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
9480             if ( !p.hasNext() ) {
9481                 return false;
9482             }
9483             Phylogeny p_27 = p.next();
9484             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9485                 System.out.println( p_27.toNewHampshireX() );
9486                 System.exit( -1 );
9487                 return false;
9488             }
9489             if ( p.hasNext() ) {
9490                 return false;
9491             }
9492             if ( p.next() != null ) {
9493                 return false;
9494             }
9495             p.reset();
9496             if ( !p.hasNext() ) {
9497                 return false;
9498             }
9499             p_27 = p.next();
9500             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9501                 System.out.println( p_27.toNewHampshireX() );
9502                 System.exit( -1 );
9503                 return false;
9504             }
9505             if ( p.hasNext() ) {
9506                 return false;
9507             }
9508             if ( p.next() != null ) {
9509                 return false;
9510             }
9511             //
9512             final String p30_str = "(A,B);(C,D)";
9513             final NHXParser p30 = new NHXParser();
9514             p30.setSource( p30_str );
9515             if ( !p30.hasNext() ) {
9516                 return false;
9517             }
9518             Phylogeny phy30 = p30.next();
9519             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9520                 System.out.println( phy30.toNewHampshire() );
9521                 return false;
9522             }
9523             if ( !p30.hasNext() ) {
9524                 return false;
9525             }
9526             Phylogeny phy301 = p30.next();
9527             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9528                 System.out.println( phy301.toNewHampshire() );
9529                 return false;
9530             }
9531             if ( p30.hasNext() ) {
9532                 return false;
9533             }
9534             if ( p30.hasNext() ) {
9535                 return false;
9536             }
9537             if ( p30.next() != null ) {
9538                 return false;
9539             }
9540             if ( p30.next() != null ) {
9541                 return false;
9542             }
9543             p30.reset();
9544             if ( !p30.hasNext() ) {
9545                 return false;
9546             }
9547             phy30 = p30.next();
9548             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9549                 System.out.println( phy30.toNewHampshire() );
9550                 return false;
9551             }
9552             if ( !p30.hasNext() ) {
9553                 return false;
9554             }
9555             phy301 = p30.next();
9556             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9557                 System.out.println( phy301.toNewHampshire() );
9558                 return false;
9559             }
9560             if ( p30.hasNext() ) {
9561                 return false;
9562             }
9563             if ( p30.hasNext() ) {
9564                 return false;
9565             }
9566             if ( p30.next() != null ) {
9567                 return false;
9568             }
9569             if ( p30.next() != null ) {
9570                 return false;
9571             }
9572         }
9573         catch ( final Exception e ) {
9574             e.printStackTrace( System.out );
9575             return false;
9576         }
9577         return true;
9578     }
9579
9580     private static boolean testNHXconversion() {
9581         try {
9582             final PhylogenyNode n1 = new PhylogenyNode();
9583             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9584             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9585             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9586             final PhylogenyNode n5 = PhylogenyNode
9587                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
9588             final PhylogenyNode n6 = PhylogenyNode
9589                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
9590             if ( !n1.toNewHampshireX().equals( "" ) ) {
9591                 return false;
9592             }
9593             if ( !n2.toNewHampshireX().equals( "" ) ) {
9594                 return false;
9595             }
9596             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
9597                 return false;
9598             }
9599             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
9600                 return false;
9601             }
9602             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
9603                 return false;
9604             }
9605             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9606                 System.out.println( n6.toNewHampshireX() );
9607                 return false;
9608             }
9609             final PhylogenyNode n7 = new PhylogenyNode();
9610             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9611             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9612                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9613                 System.out.println( n7
9614                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9615                 return false;
9616             }
9617         }
9618         catch ( final Exception e ) {
9619             e.printStackTrace( System.out );
9620             return false;
9621         }
9622         return true;
9623     }
9624
9625     private static boolean testNHXNodeParsing() {
9626         try {
9627             final PhylogenyNode n1 = new PhylogenyNode();
9628             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9629             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9630             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9631             final PhylogenyNode n5 = PhylogenyNode
9632                     .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]" );
9633             if ( !n3.getName().equals( "n3" ) ) {
9634                 return false;
9635             }
9636             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9637                 return false;
9638             }
9639             if ( n3.isDuplication() ) {
9640                 return false;
9641             }
9642             if ( n3.isHasAssignedEvent() ) {
9643                 return false;
9644             }
9645             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9646                 return false;
9647             }
9648             if ( !n4.getName().equals( "n4" ) ) {
9649                 return false;
9650             }
9651             if ( n4.getDistanceToParent() != 0.01 ) {
9652                 return false;
9653             }
9654             if ( !n5.getName().equals( "n5" ) ) {
9655                 return false;
9656             }
9657             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9658                 return false;
9659             }
9660             if ( n5.getDistanceToParent() != 0.1 ) {
9661                 return false;
9662             }
9663             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9664                 return false;
9665             }
9666             if ( !n5.isDuplication() ) {
9667                 return false;
9668             }
9669             if ( !n5.isHasAssignedEvent() ) {
9670                 return false;
9671             }
9672             final PhylogenyNode n8 = PhylogenyNode
9673                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9674                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9675             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9676                 return false;
9677             }
9678             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9679                 return false;
9680             }
9681             final PhylogenyNode n9 = PhylogenyNode
9682                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9683                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9684             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9685                 return false;
9686             }
9687             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9688                 return false;
9689             }
9690             final PhylogenyNode n10 = PhylogenyNode
9691                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9692             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9693                 return false;
9694             }
9695             final PhylogenyNode n20 = PhylogenyNode
9696                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9697             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9698                 return false;
9699             }
9700             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9701                 return false;
9702             }
9703             final PhylogenyNode n20x = PhylogenyNode
9704                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9705             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9706                 return false;
9707             }
9708             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9709                 return false;
9710             }
9711             final PhylogenyNode n20xx = PhylogenyNode
9712                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9713             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9714                 return false;
9715             }
9716             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9717                 return false;
9718             }
9719             final PhylogenyNode n20xxx = PhylogenyNode
9720                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9721             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9722                 return false;
9723             }
9724             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9725                 return false;
9726             }
9727             final PhylogenyNode n20xxxx = PhylogenyNode
9728                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9729             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9730                 return false;
9731             }
9732             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9733                 return false;
9734             }
9735             final PhylogenyNode n21 = PhylogenyNode
9736                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9737             if ( !n21.getName().equals( "N21_PIG" ) ) {
9738                 return false;
9739             }
9740             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9741                 return false;
9742             }
9743             final PhylogenyNode n21x = PhylogenyNode
9744                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9745             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9746                 return false;
9747             }
9748             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9749                 return false;
9750             }
9751             final PhylogenyNode n22 = PhylogenyNode
9752                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9753             if ( !n22.getName().equals( "n22/PIG" ) ) {
9754                 return false;
9755             }
9756             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9757                 return false;
9758             }
9759             final PhylogenyNode n23 = PhylogenyNode
9760                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9761             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9762                 return false;
9763             }
9764             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9765                 return false;
9766             }
9767             final PhylogenyNode a = PhylogenyNode
9768                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9769             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9770                 return false;
9771             }
9772             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9773                 return false;
9774             }
9775             final PhylogenyNode c1 = PhylogenyNode
9776                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9777                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9778             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9779                 return false;
9780             }
9781             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9782                 return false;
9783             }
9784             final PhylogenyNode c2 = PhylogenyNode
9785                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9786                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9787             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9788                 return false;
9789             }
9790             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9791                 return false;
9792             }
9793             final PhylogenyNode e3 = PhylogenyNode
9794                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9795             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9796                 return false;
9797             }
9798             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9799                 return false;
9800             }
9801             final PhylogenyNode n11 = PhylogenyNode
9802                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9803                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9804             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9805                 return false;
9806             }
9807             if ( n11.getDistanceToParent() != 0.4 ) {
9808                 return false;
9809             }
9810             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9811                 return false;
9812             }
9813             final PhylogenyNode n12 = PhylogenyNode
9814                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9815                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9816             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9817                 return false;
9818             }
9819             if ( n12.getDistanceToParent() != 0.4 ) {
9820                 return false;
9821             }
9822             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9823                 return false;
9824             }
9825             final PhylogenyNode o = PhylogenyNode
9826                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9827             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9828                 return false;
9829             }
9830             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9831                 return false;
9832             }
9833             if ( n1.getName().compareTo( "" ) != 0 ) {
9834                 return false;
9835             }
9836             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9837                 return false;
9838             }
9839             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9840                 return false;
9841             }
9842             if ( n2.getName().compareTo( "" ) != 0 ) {
9843                 return false;
9844             }
9845             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9846                 return false;
9847             }
9848             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9849                 return false;
9850             }
9851             final PhylogenyNode n00 = PhylogenyNode
9852                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9853             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9854                 return false;
9855             }
9856             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9857                 return false;
9858             }
9859             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9860             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9861                 return false;
9862             }
9863             final PhylogenyNode n13 = PhylogenyNode
9864                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9865             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9866                 return false;
9867             }
9868             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9869                 return false;
9870             }
9871             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9872                 return false;
9873             }
9874             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9875                 return false;
9876             }
9877             final PhylogenyNode n14 = PhylogenyNode
9878                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9879             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9880                 return false;
9881             }
9882             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9883                 return false;
9884             }
9885             final PhylogenyNode n15 = PhylogenyNode
9886                     .createInstanceFromNhxString( "something_wicked[123]",
9887                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9888             if ( !n15.getName().equals( "something_wicked" ) ) {
9889                 return false;
9890             }
9891             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9892                 return false;
9893             }
9894             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9895                 return false;
9896             }
9897             final PhylogenyNode n16 = PhylogenyNode
9898                     .createInstanceFromNhxString( "something_wicked2[9]",
9899                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9900             if ( !n16.getName().equals( "something_wicked2" ) ) {
9901                 return false;
9902             }
9903             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9904                 return false;
9905             }
9906             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9907                 return false;
9908             }
9909             final PhylogenyNode n17 = PhylogenyNode
9910                     .createInstanceFromNhxString( "something_wicked3[a]",
9911                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9912             if ( !n17.getName().equals( "something_wicked3" ) ) {
9913                 return false;
9914             }
9915             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9916                 return false;
9917             }
9918             final PhylogenyNode n18 = PhylogenyNode
9919                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9920             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9921                 return false;
9922             }
9923             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9924                 return false;
9925             }
9926             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9927                 return false;
9928             }
9929             final PhylogenyNode n19 = PhylogenyNode
9930                     .createInstanceFromNhxString( "BLAH_1-roejojoej",
9931                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9932             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9933                 return false;
9934             }
9935             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9936                 return false;
9937             }
9938             final PhylogenyNode n30 = PhylogenyNode
9939                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9940                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9941             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9942                 return false;
9943             }
9944             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9945                 return false;
9946             }
9947             final PhylogenyNode n31 = PhylogenyNode
9948                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9949                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9950             if ( n31.getNodeData().isHasTaxonomy() ) {
9951                 return false;
9952             }
9953             final PhylogenyNode n32 = PhylogenyNode
9954                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9955             if ( n32.getNodeData().isHasTaxonomy() ) {
9956                 return false;
9957             }
9958             final PhylogenyNode n40 = PhylogenyNode
9959                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9960             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9961                 return false;
9962             }
9963             final PhylogenyNode n41 = PhylogenyNode
9964                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9965             if ( n41.getNodeData().isHasTaxonomy() ) {
9966                 return false;
9967             }
9968             final PhylogenyNode n42 = PhylogenyNode
9969                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9970             if ( n42.getNodeData().isHasTaxonomy() ) {
9971                 return false;
9972             }
9973             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9974                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9975             if ( n43.getNodeData().isHasTaxonomy() ) {
9976                 return false;
9977             }
9978             final PhylogenyNode n44 = PhylogenyNode
9979                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9980             if ( n44.getNodeData().isHasTaxonomy() ) {
9981                 return false;
9982             }
9983         }
9984         catch ( final Exception e ) {
9985             e.printStackTrace( System.out );
9986             return false;
9987         }
9988         return true;
9989     }
9990
9991     private static boolean testNHXNodeParsing2() {
9992         try {
9993             final PhylogenyNode n0_0 = PhylogenyNode.createInstanceFromNhxString( "n0:[ignore me 123]:1E-3",
9994                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
9995                                                                                   true,
9996                                                                                   true );
9997             if ( !n0_0.getName().equals( "n0" ) ) {
9998                 return false;
9999             }
10000             if ( !isEqual( n0_0.getDistanceToParent(), 0.001 ) ) {
10001                 return false;
10002             }
10003             final PhylogenyNode n0_1 = PhylogenyNode.createInstanceFromNhxString( "n0[ignore me 123]:1E-3",
10004                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10005                                                                                   true,
10006                                                                                   true );
10007             if ( !n0_1.getName().equals( "n0" ) ) {
10008                 return false;
10009             }
10010             if ( !isEqual( n0_1.getDistanceToParent(), 0.001 ) ) {
10011                 return false;
10012             }
10013             final PhylogenyNode n0_2 = PhylogenyNode.createInstanceFromNhxString( "n0:1E-3[ignore me 123]",
10014                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10015                                                                                   true,
10016                                                                                   true );
10017             if ( !n0_2.getName().equals( "n0" ) ) {
10018                 return false;
10019             }
10020             if ( !isEqual( n0_2.getDistanceToParent(), 0.001 ) ) {
10021                 return false;
10022             }
10023             final PhylogenyNode n0_3 = PhylogenyNode.createInstanceFromNhxString( "n0:1E-3:[ignore me 123]",
10024                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10025                                                                                   true,
10026                                                                                   true );
10027             if ( !n0_3.getName().equals( "n0" ) ) {
10028                 return false;
10029             }
10030             if ( !isEqual( n0_3.getDistanceToParent(), 0.001 ) ) {
10031                 return false;
10032             }
10033             final PhylogenyNode n0_4 = PhylogenyNode.createInstanceFromNhxString( "n0:0.001:[ignore me 123]",
10034                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10035                                                                                   true,
10036                                                                                   true );
10037             if ( !n0_4.getName().equals( "n0" ) ) {
10038                 return false;
10039             }
10040             if ( !isEqual( n0_4.getDistanceToParent(), 0.001 ) ) {
10041                 return false;
10042             }
10043             final PhylogenyNode n1_0 = PhylogenyNode
10044                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]",
10045                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10046                                                   true,
10047                                                   true );
10048             if ( !n1_0.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10049                 return false;
10050             }
10051             if ( n1_0.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10052                 return false;
10053             }
10054             final PhylogenyNode n1_1 = PhylogenyNode
10055                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]:0.001",
10056                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10057                                                   true,
10058                                                   true );
10059             if ( !n1_1.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10060                 return false;
10061             }
10062             if ( n1_1.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10063                 return false;
10064             }
10065             if ( !isEqual( n1_1.getDistanceToParent(), 0.001 ) ) {
10066                 return false;
10067             }
10068             final PhylogenyNode n1_2 = PhylogenyNode
10069                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:0.001[&!color=#FFFFFF]",
10070                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10071                                                   true,
10072                                                   true );
10073             if ( !n1_2.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10074                 return false;
10075             }
10076             if ( n1_2.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10077                 return false;
10078             }
10079             if ( !isEqual( n1_2.getDistanceToParent(), 0.001 ) ) {
10080                 return false;
10081             }
10082             final PhylogenyNode n1_3 = PhylogenyNode
10083                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[&boostrap=69,&!color=#FFFFFF]",
10084                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10085                                                   true,
10086                                                   true );
10087             if ( !n1_3.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10088                 return false;
10089             }
10090             if ( n1_3.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10091                 return false;
10092             }
10093             if ( !isEqual( n1_3.getDistanceToParent(), 0.001 ) ) {
10094                 return false;
10095             }
10096             if ( !isEqual( n1_3.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
10097                 return false;
10098             }
10099             if ( !n1_3.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
10100                 return false;
10101             }
10102             final PhylogenyNode n1_4 = PhylogenyNode
10103                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&bootstrap=69,&!colour=#FFFFFF]:1e-3",
10104                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10105                                                   true,
10106                                                   true );
10107             if ( !n1_4.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10108                 return false;
10109             }
10110             if ( n1_4.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10111                 return false;
10112             }
10113             if ( !isEqual( n1_4.getDistanceToParent(), 0.001 ) ) {
10114                 return false;
10115             }
10116             if ( !isEqual( n1_4.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
10117                 return false;
10118             }
10119             if ( !n1_4.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
10120                 return false;
10121             }
10122             final PhylogenyNode n1_5 = PhylogenyNode
10123                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[69.0]",
10124                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10125                                                   true,
10126                                                   true );
10127             if ( !n1_5.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10128                 return false;
10129             }
10130             if ( !isEqual( n1_5.getDistanceToParent(), 0.001 ) ) {
10131                 return false;
10132             }
10133             if ( !isEqual( n1_5.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
10134                 return false;
10135             }
10136             final PhylogenyNode n1_6 = PhylogenyNode
10137                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00]:1e-3",
10138                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10139                                                   true,
10140                                                   true );
10141             if ( !n1_6.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10142                 return false;
10143             }
10144             if ( !isEqual( n1_6.getDistanceToParent(), 0.001 ) ) {
10145                 return false;
10146             }
10147             if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getStandardDeviation(), 0.11 ) ) {
10148                 return false;
10149             }
10150             if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getValue(), 0.95 ) ) {
10151                 return false;
10152             }
10153             if ( !n1_6.getBranchData().getConfidence( 0 ).getType().equals( "posterior probability" ) ) {
10154                 return false;
10155             }
10156         }
10157         catch ( final Exception e ) {
10158             e.printStackTrace( System.out );
10159             return false;
10160         }
10161         return true;
10162     }
10163
10164     private static boolean testNHXParsing() {
10165         try {
10166             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10167             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])",
10168                                                  new NHXParser() )[ 0 ];
10169             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
10170                 return false;
10171             }
10172             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]";
10173             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
10174             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10175                 return false;
10176             }
10177             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]";
10178             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
10179             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
10180                 return false;
10181             }
10182             final Phylogeny[] p3 = factory.create(
10183                                                    "[  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]",
10184                                                    new NHXParser() );
10185             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10186                 return false;
10187             }
10188             final Phylogeny[] p4 = factory.create(
10189                                                    "(((((((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(]",
10190                                                    new NHXParser() );
10191             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10192                 return false;
10193             }
10194             final Phylogeny[] p5 = factory.create(
10195                                                    "[]  (  [][ ][   ]  ([((( &&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(((]",
10196                                                    new NHXParser() );
10197             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10198                 return false;
10199             }
10200             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)";
10201             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)";
10202             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
10203             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
10204                 return false;
10205             }
10206             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)))";
10207             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)))";
10208             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
10209             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
10210                 return false;
10211             }
10212             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])   ))[,,, ])))))))";
10213             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
10214             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
10215             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
10216                 return false;
10217             }
10218             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
10219             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10220                 return false;
10221             }
10222             final Phylogeny p10 = factory.create(
10223                                                   " [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]",
10224                                                   new NHXParser() )[ 0 ];
10225             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10226                 return false;
10227             }
10228             final Phylogeny p11 = factory.create(
10229                                                   " [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]",
10230                                                   new NHXParser() )[ 0 ];
10231             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10232                 return false;
10233             }
10234             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]",
10235                                                   new NHXParser() )[ 0 ];
10236             if ( !p12.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10237                 return false;
10238             }
10239         }
10240         catch ( final Exception e ) {
10241             e.printStackTrace( System.out );
10242             return false;
10243         }
10244         return true;
10245     }
10246
10247     private static boolean testNHXParsingMB() {
10248         try {
10249             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10250             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
10251                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10252                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
10253                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
10254                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
10255                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10256                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
10257                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
10258                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
10259             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
10260                 return false;
10261             }
10262             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
10263                 return false;
10264             }
10265             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
10266                            0.1100000000000000e+00 ) ) {
10267                 return false;
10268             }
10269             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
10270                 return false;
10271             }
10272             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
10273                 return false;
10274             }
10275             final Phylogeny p2 = factory
10276                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
10277                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10278                             + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
10279                             + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
10280                             + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
10281                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10282                             + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
10283                             + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
10284                             + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
10285             if ( p2.getNode( "1" ) == null ) {
10286                 return false;
10287             }
10288             if ( p2.getNode( "2" ) == null ) {
10289                 return false;
10290             }
10291         }
10292         catch ( final Exception e ) {
10293             e.printStackTrace( System.out );
10294             System.exit( -1 );
10295             return false;
10296         }
10297         return true;
10298     }
10299
10300     private static boolean testNHXParsingQuotes() {
10301         try {
10302             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10303             final NHXParser p = new NHXParser();
10304             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
10305             if ( phylogenies_0.length != 5 ) {
10306                 return false;
10307             }
10308             final Phylogeny phy = phylogenies_0[ 4 ];
10309             if ( phy.getNumberOfExternalNodes() != 7 ) {
10310                 return false;
10311             }
10312             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
10313                 return false;
10314             }
10315             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
10316                 return false;
10317             }
10318             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
10319                     .getScientificName().equals( "hsapiens" ) ) {
10320                 return false;
10321             }
10322             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
10323                 return false;
10324             }
10325             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
10326                 return false;
10327             }
10328             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
10329                 return false;
10330             }
10331             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
10332                 return false;
10333             }
10334             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
10335                 return false;
10336             }
10337             final NHXParser p1p = new NHXParser();
10338             p1p.setIgnoreQuotes( true );
10339             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
10340             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
10341                 return false;
10342             }
10343             final NHXParser p2p = new NHXParser();
10344             p1p.setIgnoreQuotes( false );
10345             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
10346             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
10347                 return false;
10348             }
10349             final NHXParser p3p = new NHXParser();
10350             p3p.setIgnoreQuotes( false );
10351             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
10352             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
10353                 return false;
10354             }
10355             final NHXParser p4p = new NHXParser();
10356             p4p.setIgnoreQuotes( false );
10357             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
10358             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
10359                 return false;
10360             }
10361             final Phylogeny p10 = factory.create(
10362                                                   " [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]",
10363                                                   new NHXParser() )[ 0 ];
10364             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]";
10365             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
10366                 return false;
10367             }
10368             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
10369             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
10370                 return false;
10371             }
10372             final Phylogeny p12 = factory.create(
10373                                                   " [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]",
10374                                                   new NHXParser() )[ 0 ];
10375             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]";
10376             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
10377                 return false;
10378             }
10379             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
10380             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
10381                 return false;
10382             }
10383             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;";
10384             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
10385                 return false;
10386             }
10387             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
10388             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
10389                 return false;
10390             }
10391         }
10392         catch ( final Exception e ) {
10393             e.printStackTrace( System.out );
10394             return false;
10395         }
10396         return true;
10397     }
10398
10399     private static boolean testNodeRemoval() {
10400         try {
10401             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10402             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
10403             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
10404             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
10405                 return false;
10406             }
10407             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
10408             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
10409             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
10410                 return false;
10411             }
10412             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
10413             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
10414             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
10415                 return false;
10416             }
10417         }
10418         catch ( final Exception e ) {
10419             e.printStackTrace( System.out );
10420             return false;
10421         }
10422         return true;
10423     }
10424
10425     private static boolean testPhylogenyBranch() {
10426         try {
10427             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
10428             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
10429             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
10430             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
10431             if ( !a1b1.equals( a1b1 ) ) {
10432                 return false;
10433             }
10434             if ( !a1b1.equals( b1a1 ) ) {
10435                 return false;
10436             }
10437             if ( !b1a1.equals( a1b1 ) ) {
10438                 return false;
10439             }
10440             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
10441             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
10442             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
10443             if ( a1_b1.equals( b1_a1 ) ) {
10444                 return false;
10445             }
10446             if ( a1_b1.equals( a1_b1_ ) ) {
10447                 return false;
10448             }
10449             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
10450             if ( !a1_b1.equals( b1_a1_ ) ) {
10451                 return false;
10452             }
10453             if ( a1_b1_.equals( b1_a1_ ) ) {
10454                 return false;
10455             }
10456             if ( !a1_b1_.equals( b1_a1 ) ) {
10457                 return false;
10458             }
10459         }
10460         catch ( final Exception e ) {
10461             e.printStackTrace( System.out );
10462             return false;
10463         }
10464         return true;
10465     }
10466
10467     private static boolean testPhyloXMLparsingOfDistributionElement() {
10468         try {
10469             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10470             PhyloXmlParser xml_parser = null;
10471             try {
10472                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
10473             }
10474             catch ( final Exception e ) {
10475                 // Do nothing -- means were not running from jar.
10476             }
10477             if ( xml_parser == null ) {
10478                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
10479                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
10480                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
10481                 }
10482                 else {
10483                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
10484                 }
10485             }
10486             final Phylogeny[] phylogenies_0 = factory
10487                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml" ), xml_parser );
10488             if ( xml_parser.getErrorCount() > 0 ) {
10489                 System.out.println( xml_parser.getErrorMessages().toString() );
10490                 return false;
10491             }
10492             if ( phylogenies_0.length != 1 ) {
10493                 return false;
10494             }
10495             final Phylogeny t1 = phylogenies_0[ 0 ];
10496             PhylogenyNode n = null;
10497             Distribution d = null;
10498             n = t1.getNode( "root node" );
10499             if ( !n.getNodeData().isHasDistribution() ) {
10500                 return false;
10501             }
10502             if ( n.getNodeData().getDistributions().size() != 1 ) {
10503                 return false;
10504             }
10505             d = n.getNodeData().getDistribution();
10506             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10507                 return false;
10508             }
10509             if ( d.getPoints().size() != 1 ) {
10510                 return false;
10511             }
10512             if ( d.getPolygons() != null ) {
10513                 return false;
10514             }
10515             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10516                 return false;
10517             }
10518             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10519                 return false;
10520             }
10521             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10522                 return false;
10523             }
10524             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10525                 return false;
10526             }
10527             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10528                 return false;
10529             }
10530             n = t1.getNode( "node a" );
10531             if ( !n.getNodeData().isHasDistribution() ) {
10532                 return false;
10533             }
10534             if ( n.getNodeData().getDistributions().size() != 2 ) {
10535                 return false;
10536             }
10537             d = n.getNodeData().getDistribution( 1 );
10538             if ( !d.getDesc().equals( "San Diego" ) ) {
10539                 return false;
10540             }
10541             if ( d.getPoints().size() != 1 ) {
10542                 return false;
10543             }
10544             if ( d.getPolygons() != null ) {
10545                 return false;
10546             }
10547             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10548                 return false;
10549             }
10550             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10551                 return false;
10552             }
10553             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10554                 return false;
10555             }
10556             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10557                 return false;
10558             }
10559             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10560                 return false;
10561             }
10562             n = t1.getNode( "node bb" );
10563             if ( !n.getNodeData().isHasDistribution() ) {
10564                 return false;
10565             }
10566             if ( n.getNodeData().getDistributions().size() != 1 ) {
10567                 return false;
10568             }
10569             d = n.getNodeData().getDistribution( 0 );
10570             if ( d.getPoints().size() != 3 ) {
10571                 return false;
10572             }
10573             if ( d.getPolygons().size() != 2 ) {
10574                 return false;
10575             }
10576             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10577                 return false;
10578             }
10579             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10580                 return false;
10581             }
10582             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10583                 return false;
10584             }
10585             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10586                 return false;
10587             }
10588             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10589                 return false;
10590             }
10591             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10592                 return false;
10593             }
10594             Polygon p = d.getPolygons().get( 0 );
10595             if ( p.getPoints().size() != 3 ) {
10596                 return false;
10597             }
10598             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10599                 return false;
10600             }
10601             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10602                 return false;
10603             }
10604             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10605                 return false;
10606             }
10607             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10608                 return false;
10609             }
10610             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10611                 return false;
10612             }
10613             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10614                 return false;
10615             }
10616             p = d.getPolygons().get( 1 );
10617             if ( p.getPoints().size() != 3 ) {
10618                 return false;
10619             }
10620             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10621                 return false;
10622             }
10623             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10624                 return false;
10625             }
10626             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10627                 return false;
10628             }
10629             // Roundtrip:
10630             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
10631             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
10632             if ( rt.length != 1 ) {
10633                 return false;
10634             }
10635             final Phylogeny t1_rt = rt[ 0 ];
10636             n = t1_rt.getNode( "root node" );
10637             if ( !n.getNodeData().isHasDistribution() ) {
10638                 return false;
10639             }
10640             if ( n.getNodeData().getDistributions().size() != 1 ) {
10641                 return false;
10642             }
10643             d = n.getNodeData().getDistribution();
10644             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10645                 return false;
10646             }
10647             if ( d.getPoints().size() != 1 ) {
10648                 return false;
10649             }
10650             if ( d.getPolygons() != null ) {
10651                 return false;
10652             }
10653             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10654                 return false;
10655             }
10656             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10657                 return false;
10658             }
10659             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10660                 return false;
10661             }
10662             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10663                 return false;
10664             }
10665             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10666                 return false;
10667             }
10668             n = t1_rt.getNode( "node a" );
10669             if ( !n.getNodeData().isHasDistribution() ) {
10670                 return false;
10671             }
10672             if ( n.getNodeData().getDistributions().size() != 2 ) {
10673                 return false;
10674             }
10675             d = n.getNodeData().getDistribution( 1 );
10676             if ( !d.getDesc().equals( "San Diego" ) ) {
10677                 return false;
10678             }
10679             if ( d.getPoints().size() != 1 ) {
10680                 return false;
10681             }
10682             if ( d.getPolygons() != null ) {
10683                 return false;
10684             }
10685             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10686                 return false;
10687             }
10688             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10689                 return false;
10690             }
10691             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10692                 return false;
10693             }
10694             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10695                 return false;
10696             }
10697             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10698                 return false;
10699             }
10700             n = t1_rt.getNode( "node bb" );
10701             if ( !n.getNodeData().isHasDistribution() ) {
10702                 return false;
10703             }
10704             if ( n.getNodeData().getDistributions().size() != 1 ) {
10705                 return false;
10706             }
10707             d = n.getNodeData().getDistribution( 0 );
10708             if ( d.getPoints().size() != 3 ) {
10709                 return false;
10710             }
10711             if ( d.getPolygons().size() != 2 ) {
10712                 return false;
10713             }
10714             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10715                 return false;
10716             }
10717             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10718                 return false;
10719             }
10720             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10721                 return false;
10722             }
10723             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10724                 return false;
10725             }
10726             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10727                 return false;
10728             }
10729             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10730                 return false;
10731             }
10732             p = d.getPolygons().get( 0 );
10733             if ( p.getPoints().size() != 3 ) {
10734                 return false;
10735             }
10736             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10737                 return false;
10738             }
10739             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10740                 return false;
10741             }
10742             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10743                 return false;
10744             }
10745             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10746                 return false;
10747             }
10748             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10749                 return false;
10750             }
10751             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10752                 return false;
10753             }
10754             p = d.getPolygons().get( 1 );
10755             if ( p.getPoints().size() != 3 ) {
10756                 return false;
10757             }
10758             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10759                 return false;
10760             }
10761             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10762                 return false;
10763             }
10764             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10765                 return false;
10766             }
10767         }
10768         catch ( final Exception e ) {
10769             e.printStackTrace( System.out );
10770             return false;
10771         }
10772         return true;
10773     }
10774
10775     private static boolean testPostOrderIterator() {
10776         try {
10777             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10778             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10779             PhylogenyNodeIterator it0;
10780             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
10781                 it0.next();
10782             }
10783             for( it0.reset(); it0.hasNext(); ) {
10784                 it0.next();
10785             }
10786             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r",
10787                                                  new NHXParser() )[ 0 ];
10788             final PhylogenyNodeIterator it = t1.iteratorPostorder();
10789             if ( !it.next().getName().equals( "A" ) ) {
10790                 return false;
10791             }
10792             if ( !it.next().getName().equals( "B" ) ) {
10793                 return false;
10794             }
10795             if ( !it.next().getName().equals( "ab" ) ) {
10796                 return false;
10797             }
10798             if ( !it.next().getName().equals( "C" ) ) {
10799                 return false;
10800             }
10801             if ( !it.next().getName().equals( "D" ) ) {
10802                 return false;
10803             }
10804             if ( !it.next().getName().equals( "cd" ) ) {
10805                 return false;
10806             }
10807             if ( !it.next().getName().equals( "abcd" ) ) {
10808                 return false;
10809             }
10810             if ( !it.next().getName().equals( "E" ) ) {
10811                 return false;
10812             }
10813             if ( !it.next().getName().equals( "F" ) ) {
10814                 return false;
10815             }
10816             if ( !it.next().getName().equals( "ef" ) ) {
10817                 return false;
10818             }
10819             if ( !it.next().getName().equals( "G" ) ) {
10820                 return false;
10821             }
10822             if ( !it.next().getName().equals( "H" ) ) {
10823                 return false;
10824             }
10825             if ( !it.next().getName().equals( "gh" ) ) {
10826                 return false;
10827             }
10828             if ( !it.next().getName().equals( "efgh" ) ) {
10829                 return false;
10830             }
10831             if ( !it.next().getName().equals( "r" ) ) {
10832                 return false;
10833             }
10834             if ( it.hasNext() ) {
10835                 return false;
10836             }
10837         }
10838         catch ( final Exception e ) {
10839             e.printStackTrace( System.out );
10840             return false;
10841         }
10842         return true;
10843     }
10844
10845     private static boolean testPreOrderIterator() {
10846         try {
10847             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10848             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10849             PhylogenyNodeIterator it0;
10850             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10851                 it0.next();
10852             }
10853             for( it0.reset(); it0.hasNext(); ) {
10854                 it0.next();
10855             }
10856             PhylogenyNodeIterator it = t0.iteratorPreorder();
10857             if ( !it.next().getName().equals( "r" ) ) {
10858                 return false;
10859             }
10860             if ( !it.next().getName().equals( "ab" ) ) {
10861                 return false;
10862             }
10863             if ( !it.next().getName().equals( "A" ) ) {
10864                 return false;
10865             }
10866             if ( !it.next().getName().equals( "B" ) ) {
10867                 return false;
10868             }
10869             if ( !it.next().getName().equals( "cd" ) ) {
10870                 return false;
10871             }
10872             if ( !it.next().getName().equals( "C" ) ) {
10873                 return false;
10874             }
10875             if ( !it.next().getName().equals( "D" ) ) {
10876                 return false;
10877             }
10878             if ( it.hasNext() ) {
10879                 return false;
10880             }
10881             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r",
10882                                                  new NHXParser() )[ 0 ];
10883             it = t1.iteratorPreorder();
10884             if ( !it.next().getName().equals( "r" ) ) {
10885                 return false;
10886             }
10887             if ( !it.next().getName().equals( "abcd" ) ) {
10888                 return false;
10889             }
10890             if ( !it.next().getName().equals( "ab" ) ) {
10891                 return false;
10892             }
10893             if ( !it.next().getName().equals( "A" ) ) {
10894                 return false;
10895             }
10896             if ( !it.next().getName().equals( "B" ) ) {
10897                 return false;
10898             }
10899             if ( !it.next().getName().equals( "cd" ) ) {
10900                 return false;
10901             }
10902             if ( !it.next().getName().equals( "C" ) ) {
10903                 return false;
10904             }
10905             if ( !it.next().getName().equals( "D" ) ) {
10906                 return false;
10907             }
10908             if ( !it.next().getName().equals( "efgh" ) ) {
10909                 return false;
10910             }
10911             if ( !it.next().getName().equals( "ef" ) ) {
10912                 return false;
10913             }
10914             if ( !it.next().getName().equals( "E" ) ) {
10915                 return false;
10916             }
10917             if ( !it.next().getName().equals( "F" ) ) {
10918                 return false;
10919             }
10920             if ( !it.next().getName().equals( "gh" ) ) {
10921                 return false;
10922             }
10923             if ( !it.next().getName().equals( "G" ) ) {
10924                 return false;
10925             }
10926             if ( !it.next().getName().equals( "H" ) ) {
10927                 return false;
10928             }
10929             if ( it.hasNext() ) {
10930                 return false;
10931             }
10932         }
10933         catch ( final Exception e ) {
10934             e.printStackTrace( System.out );
10935             return false;
10936         }
10937         return true;
10938     }
10939
10940     private static boolean testPropertiesMap() {
10941         try {
10942             final PropertiesList pm = new PropertiesList();
10943             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10944             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10945             final Property p2 = new Property( "something:else",
10946                                               "?",
10947                                               "improbable:research",
10948                                               "xsd:decimal",
10949                                               AppliesTo.NODE );
10950             pm.addProperty( p0 );
10951             pm.addProperty( p1 );
10952             pm.addProperty( p2 );
10953             if ( !pm.getProperties( "dimensions:diameter" ).get( 0 ).getValue().equals( "1" ) ) {
10954                 return false;
10955             }
10956             if ( !pm.getProperties( "dimensions:length" ).get( 0 ).getValue().equals( "2" ) ) {
10957                 return false;
10958             }
10959             if ( pm.getProperties().size() != 3 ) {
10960                 return false;
10961             }
10962             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10963                 return false;
10964             }
10965             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10966                 return false;
10967             }
10968             if ( pm.getProperties().size() != 3 ) {
10969                 return false;
10970             }
10971         }
10972         catch ( final Exception e ) {
10973             e.printStackTrace( System.out );
10974             return false;
10975         }
10976         return true;
10977     }
10978
10979     private static boolean testProteinId() {
10980         try {
10981             final ProteinId id1 = new ProteinId( "a" );
10982             final ProteinId id2 = new ProteinId( "a" );
10983             final ProteinId id3 = new ProteinId( "A" );
10984             final ProteinId id4 = new ProteinId( "b" );
10985             if ( !id1.equals( id1 ) ) {
10986                 return false;
10987             }
10988             if ( id1.getId().equals( "x" ) ) {
10989                 return false;
10990             }
10991             if ( id1.getId().equals( null ) ) {
10992                 return false;
10993             }
10994             if ( !id1.equals( id2 ) ) {
10995                 return false;
10996             }
10997             if ( id1.equals( id3 ) ) {
10998                 return false;
10999             }
11000             if ( id1.hashCode() != id1.hashCode() ) {
11001                 return false;
11002             }
11003             if ( id1.hashCode() != id2.hashCode() ) {
11004                 return false;
11005             }
11006             if ( id1.hashCode() == id3.hashCode() ) {
11007                 return false;
11008             }
11009             if ( id1.compareTo( id1 ) != 0 ) {
11010                 return false;
11011             }
11012             if ( id1.compareTo( id2 ) != 0 ) {
11013                 return false;
11014             }
11015             if ( id1.compareTo( id3 ) != 0 ) {
11016                 return false;
11017             }
11018             if ( id1.compareTo( id4 ) >= 0 ) {
11019                 return false;
11020             }
11021             if ( id4.compareTo( id1 ) <= 0 ) {
11022                 return false;
11023             }
11024             if ( !id4.getId().equals( "b" ) ) {
11025                 return false;
11026             }
11027             final ProteinId id5 = new ProteinId( " C " );
11028             if ( !id5.getId().equals( "C" ) ) {
11029                 return false;
11030             }
11031             if ( id5.equals( id1 ) ) {
11032                 return false;
11033             }
11034         }
11035         catch ( final Exception e ) {
11036             e.printStackTrace( System.out );
11037             return false;
11038         }
11039         return true;
11040     }
11041
11042     private static boolean testReIdMethods() {
11043         try {
11044             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11045             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
11046             final long count = PhylogenyNode.getNodeCount();
11047             p.levelOrderReID();
11048             if ( p.getNode( "r" ).getId() != count ) {
11049                 return false;
11050             }
11051             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
11052                 return false;
11053             }
11054             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
11055                 return false;
11056             }
11057             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
11058                 return false;
11059             }
11060             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
11061                 return false;
11062             }
11063             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
11064                 return false;
11065             }
11066             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
11067                 return false;
11068             }
11069             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
11070                 return false;
11071             }
11072             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
11073                 return false;
11074             }
11075             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
11076                 return false;
11077             }
11078             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
11079                 return false;
11080             }
11081             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
11082                 return false;
11083             }
11084             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
11085                 return false;
11086             }
11087             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
11088                 return false;
11089             }
11090             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
11091                 return false;
11092             }
11093         }
11094         catch ( final Exception e ) {
11095             e.printStackTrace( System.out );
11096             return false;
11097         }
11098         return true;
11099     }
11100
11101     private static boolean testRerooting() {
11102         try {
11103             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11104             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",
11105                                                  new NHXParser() )[ 0 ];
11106             if ( !t1.isRooted() ) {
11107                 return false;
11108             }
11109             t1.reRoot( t1.getNode( "D" ) );
11110             t1.reRoot( t1.getNode( "CD" ) );
11111             t1.reRoot( t1.getNode( "A" ) );
11112             t1.reRoot( t1.getNode( "B" ) );
11113             t1.reRoot( t1.getNode( "AB" ) );
11114             t1.reRoot( t1.getNode( "D" ) );
11115             t1.reRoot( t1.getNode( "C" ) );
11116             t1.reRoot( t1.getNode( "CD" ) );
11117             t1.reRoot( t1.getNode( "A" ) );
11118             t1.reRoot( t1.getNode( "B" ) );
11119             t1.reRoot( t1.getNode( "AB" ) );
11120             t1.reRoot( t1.getNode( "D" ) );
11121             t1.reRoot( t1.getNode( "D" ) );
11122             t1.reRoot( t1.getNode( "C" ) );
11123             t1.reRoot( t1.getNode( "A" ) );
11124             t1.reRoot( t1.getNode( "B" ) );
11125             t1.reRoot( t1.getNode( "AB" ) );
11126             t1.reRoot( t1.getNode( "C" ) );
11127             t1.reRoot( t1.getNode( "D" ) );
11128             t1.reRoot( t1.getNode( "CD" ) );
11129             t1.reRoot( t1.getNode( "D" ) );
11130             t1.reRoot( t1.getNode( "A" ) );
11131             t1.reRoot( t1.getNode( "B" ) );
11132             t1.reRoot( t1.getNode( "AB" ) );
11133             t1.reRoot( t1.getNode( "C" ) );
11134             t1.reRoot( t1.getNode( "D" ) );
11135             t1.reRoot( t1.getNode( "CD" ) );
11136             t1.reRoot( t1.getNode( "D" ) );
11137             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
11138                 return false;
11139             }
11140             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
11141                 return false;
11142             }
11143             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
11144                 return false;
11145             }
11146             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
11147                 return false;
11148             }
11149             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
11150                 return false;
11151             }
11152             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
11153                 return false;
11154             }
11155             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",
11156                                                  new NHXParser() )[ 0 ];
11157             t2.reRoot( t2.getNode( "A" ) );
11158             t2.reRoot( t2.getNode( "D" ) );
11159             t2.reRoot( t2.getNode( "ABC" ) );
11160             t2.reRoot( t2.getNode( "A" ) );
11161             t2.reRoot( t2.getNode( "B" ) );
11162             t2.reRoot( t2.getNode( "D" ) );
11163             t2.reRoot( t2.getNode( "C" ) );
11164             t2.reRoot( t2.getNode( "ABC" ) );
11165             t2.reRoot( t2.getNode( "A" ) );
11166             t2.reRoot( t2.getNode( "B" ) );
11167             t2.reRoot( t2.getNode( "AB" ) );
11168             t2.reRoot( t2.getNode( "AB" ) );
11169             t2.reRoot( t2.getNode( "D" ) );
11170             t2.reRoot( t2.getNode( "C" ) );
11171             t2.reRoot( t2.getNode( "B" ) );
11172             t2.reRoot( t2.getNode( "AB" ) );
11173             t2.reRoot( t2.getNode( "D" ) );
11174             t2.reRoot( t2.getNode( "D" ) );
11175             t2.reRoot( t2.getNode( "ABC" ) );
11176             t2.reRoot( t2.getNode( "A" ) );
11177             t2.reRoot( t2.getNode( "B" ) );
11178             t2.reRoot( t2.getNode( "AB" ) );
11179             t2.reRoot( t2.getNode( "D" ) );
11180             t2.reRoot( t2.getNode( "C" ) );
11181             t2.reRoot( t2.getNode( "ABC" ) );
11182             t2.reRoot( t2.getNode( "A" ) );
11183             t2.reRoot( t2.getNode( "B" ) );
11184             t2.reRoot( t2.getNode( "AB" ) );
11185             t2.reRoot( t2.getNode( "D" ) );
11186             t2.reRoot( t2.getNode( "D" ) );
11187             t2.reRoot( t2.getNode( "C" ) );
11188             t2.reRoot( t2.getNode( "A" ) );
11189             t2.reRoot( t2.getNode( "B" ) );
11190             t2.reRoot( t2.getNode( "AB" ) );
11191             t2.reRoot( t2.getNode( "C" ) );
11192             t2.reRoot( t2.getNode( "D" ) );
11193             t2.reRoot( t2.getNode( "ABC" ) );
11194             t2.reRoot( t2.getNode( "D" ) );
11195             t2.reRoot( t2.getNode( "A" ) );
11196             t2.reRoot( t2.getNode( "B" ) );
11197             t2.reRoot( t2.getNode( "AB" ) );
11198             t2.reRoot( t2.getNode( "C" ) );
11199             t2.reRoot( t2.getNode( "D" ) );
11200             t2.reRoot( t2.getNode( "ABC" ) );
11201             t2.reRoot( t2.getNode( "D" ) );
11202             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11203                 return false;
11204             }
11205             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11206                 return false;
11207             }
11208             t2.reRoot( t2.getNode( "ABC" ) );
11209             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11210                 return false;
11211             }
11212             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11213                 return false;
11214             }
11215             t2.reRoot( t2.getNode( "AB" ) );
11216             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11217                 return false;
11218             }
11219             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11220                 return false;
11221             }
11222             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11223                 return false;
11224             }
11225             t2.reRoot( t2.getNode( "AB" ) );
11226             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11227                 return false;
11228             }
11229             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11230                 return false;
11231             }
11232             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11233                 return false;
11234             }
11235             t2.reRoot( t2.getNode( "D" ) );
11236             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11237                 return false;
11238             }
11239             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11240                 return false;
11241             }
11242             t2.reRoot( t2.getNode( "ABC" ) );
11243             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11244                 return false;
11245             }
11246             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11247                 return false;
11248             }
11249             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
11250                                                  new NHXParser() )[ 0 ];
11251             t3.reRoot( t3.getNode( "B" ) );
11252             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11253                 return false;
11254             }
11255             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11256                 return false;
11257             }
11258             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11259                 return false;
11260             }
11261             t3.reRoot( t3.getNode( "B" ) );
11262             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11263                 return false;
11264             }
11265             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11266                 return false;
11267             }
11268             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11269                 return false;
11270             }
11271             t3.reRoot( t3.getRoot() );
11272             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11273                 return false;
11274             }
11275             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11276                 return false;
11277             }
11278             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11279                 return false;
11280             }
11281         }
11282         catch ( final Exception e ) {
11283             e.printStackTrace( System.out );
11284             return false;
11285         }
11286         return true;
11287     }
11288
11289     private static boolean testSDIse() {
11290         try {
11291             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11292             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
11293             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
11294             gene1.setRooted( true );
11295             species1.setRooted( true );
11296             final SDI sdi = new SDI( gene1, species1 );
11297             if ( !gene1.getRoot().isDuplication() ) {
11298                 return false;
11299             }
11300             final Phylogeny species2 = factory.create(
11301                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11302                                                        new NHXParser() )[ 0 ];
11303             final Phylogeny gene2 = factory.create(
11304                                                     "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11305                                                     new NHXParser() )[ 0 ];
11306             species2.setRooted( true );
11307             gene2.setRooted( true );
11308             final SDI sdi2 = new SDI( gene2, species2 );
11309             if ( sdi2.getDuplicationsSum() != 0 ) {
11310                 return false;
11311             }
11312             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
11313                 return false;
11314             }
11315             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
11316                 return false;
11317             }
11318             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
11319                 return false;
11320             }
11321             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
11322                 return false;
11323             }
11324             if ( !gene2.getNode( "r" ).isSpeciation() ) {
11325                 return false;
11326             }
11327             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
11328                 return false;
11329             }
11330             final Phylogeny species3 = factory.create(
11331                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11332                                                        new NHXParser() )[ 0 ];
11333             final Phylogeny gene3 = factory.create(
11334                                                     "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11335                                                     new NHXParser() )[ 0 ];
11336             species3.setRooted( true );
11337             gene3.setRooted( true );
11338             final SDI sdi3 = new SDI( gene3, species3 );
11339             if ( sdi3.getDuplicationsSum() != 1 ) {
11340                 return false;
11341             }
11342             if ( !gene3.getNode( "aa" ).isDuplication() ) {
11343                 return false;
11344             }
11345             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
11346                 return false;
11347             }
11348             final Phylogeny species4 = factory.create(
11349                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11350                                                        new NHXParser() )[ 0 ];
11351             final Phylogeny gene4 = factory.create(
11352                                                     "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11353                                                     new NHXParser() )[ 0 ];
11354             species4.setRooted( true );
11355             gene4.setRooted( true );
11356             final SDI sdi4 = new SDI( gene4, species4 );
11357             if ( sdi4.getDuplicationsSum() != 1 ) {
11358                 return false;
11359             }
11360             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
11361                 return false;
11362             }
11363             if ( !gene4.getNode( "abc" ).isDuplication() ) {
11364                 return false;
11365             }
11366             if ( gene4.getNode( "abcd" ).isDuplication() ) {
11367                 return false;
11368             }
11369             if ( species4.getNumberOfExternalNodes() != 6 ) {
11370                 return false;
11371             }
11372             if ( gene4.getNumberOfExternalNodes() != 6 ) {
11373                 return false;
11374             }
11375             final Phylogeny species5 = factory.create(
11376                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11377                                                        new NHXParser() )[ 0 ];
11378             final Phylogeny gene5 = factory.create(
11379                                                     "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11380                                                     new NHXParser() )[ 0 ];
11381             species5.setRooted( true );
11382             gene5.setRooted( true );
11383             final SDI sdi5 = new SDI( gene5, species5 );
11384             if ( sdi5.getDuplicationsSum() != 2 ) {
11385                 return false;
11386             }
11387             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
11388                 return false;
11389             }
11390             if ( !gene5.getNode( "adc" ).isDuplication() ) {
11391                 return false;
11392             }
11393             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
11394                 return false;
11395             }
11396             if ( species5.getNumberOfExternalNodes() != 6 ) {
11397                 return false;
11398             }
11399             if ( gene5.getNumberOfExternalNodes() != 6 ) {
11400                 return false;
11401             }
11402             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
11403             // Conjecture for Comparing Molecular Phylogenies"
11404             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
11405             final Phylogeny species6 = factory.create(
11406                                                        "(((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,"
11407                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11408                                                        new NHXParser() )[ 0 ];
11409             final Phylogeny gene6 = factory.create(
11410                                                     "(((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,"
11411                                                             + "((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,"
11412                                                             + "(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;",
11413                                                     new NHXParser() )[ 0 ];
11414             species6.setRooted( true );
11415             gene6.setRooted( true );
11416             final SDI sdi6 = new SDI( gene6, species6 );
11417             if ( sdi6.getDuplicationsSum() != 3 ) {
11418                 return false;
11419             }
11420             if ( !gene6.getNode( "r" ).isDuplication() ) {
11421                 return false;
11422             }
11423             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
11424                 return false;
11425             }
11426             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
11427                 return false;
11428             }
11429             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
11430                 return false;
11431             }
11432             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
11433                 return false;
11434             }
11435             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
11436                 return false;
11437             }
11438             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
11439                 return false;
11440             }
11441             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
11442                 return false;
11443             }
11444             sdi6.computeMappingCostL();
11445             if ( sdi6.computeMappingCostL() != 17 ) {
11446                 return false;
11447             }
11448             if ( species6.getNumberOfExternalNodes() != 9 ) {
11449                 return false;
11450             }
11451             if ( gene6.getNumberOfExternalNodes() != 9 ) {
11452                 return false;
11453             }
11454             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
11455                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
11456                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
11457                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
11458                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
11459             species7.setRooted( true );
11460             final Phylogeny gene7_1 = Test
11461                     .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])" );
11462             gene7_1.setRooted( true );
11463             final SDI sdi7 = new SDI( gene7_1, species7 );
11464             if ( sdi7.getDuplicationsSum() != 0 ) {
11465                 return false;
11466             }
11467             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
11468                 return false;
11469             }
11470             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
11471                 return false;
11472             }
11473             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
11474                 return false;
11475             }
11476             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
11477                 return false;
11478             }
11479             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
11480                 return false;
11481             }
11482             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
11483                 return false;
11484             }
11485             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
11486                 return false;
11487             }
11488             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
11489                 return false;
11490             }
11491             final Phylogeny gene7_2 = Test
11492                     .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])" );
11493             gene7_2.setRooted( true );
11494             final SDI sdi7_2 = new SDI( gene7_2, species7 );
11495             if ( sdi7_2.getDuplicationsSum() != 1 ) {
11496                 return false;
11497             }
11498             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
11499                 return false;
11500             }
11501             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
11502                 return false;
11503             }
11504             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
11505                 return false;
11506             }
11507             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
11508                 return false;
11509             }
11510             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
11511                 return false;
11512             }
11513             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
11514                 return false;
11515             }
11516             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
11517                 return false;
11518             }
11519             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
11520                 return false;
11521             }
11522             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
11523                 return false;
11524             }
11525         }
11526         catch ( final Exception e ) {
11527             return false;
11528         }
11529         return true;
11530     }
11531
11532     private static boolean testSDIunrooted() {
11533         try {
11534             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11535             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef",
11536                                                  new NHXParser() )[ 0 ];
11537             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
11538             final Iterator<PhylogenyBranch> iter = l.iterator();
11539             PhylogenyBranch br = iter.next();
11540             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
11541                 return false;
11542             }
11543             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
11544                 return false;
11545             }
11546             br = iter.next();
11547             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11548                 return false;
11549             }
11550             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11551                 return false;
11552             }
11553             br = iter.next();
11554             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
11555                 return false;
11556             }
11557             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
11558                 return false;
11559             }
11560             br = iter.next();
11561             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11562                 return false;
11563             }
11564             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11565                 return false;
11566             }
11567             br = iter.next();
11568             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11569                 return false;
11570             }
11571             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11572                 return false;
11573             }
11574             br = iter.next();
11575             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11576                 return false;
11577             }
11578             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11579                 return false;
11580             }
11581             br = iter.next();
11582             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11583                 return false;
11584             }
11585             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11586                 return false;
11587             }
11588             br = iter.next();
11589             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11590                 return false;
11591             }
11592             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11593                 return false;
11594             }
11595             br = iter.next();
11596             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11597                 return false;
11598             }
11599             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11600                 return false;
11601             }
11602             br = iter.next();
11603             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11604                 return false;
11605             }
11606             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11607                 return false;
11608             }
11609             br = iter.next();
11610             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11611                 return false;
11612             }
11613             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11614                 return false;
11615             }
11616             br = iter.next();
11617             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
11618                 return false;
11619             }
11620             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
11621                 return false;
11622             }
11623             br = iter.next();
11624             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11625                 return false;
11626             }
11627             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11628                 return false;
11629             }
11630             br = iter.next();
11631             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
11632                 return false;
11633             }
11634             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
11635                 return false;
11636             }
11637             br = iter.next();
11638             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
11639                 return false;
11640             }
11641             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
11642                 return false;
11643             }
11644             if ( iter.hasNext() ) {
11645                 return false;
11646             }
11647             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
11648             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
11649             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
11650             br = iter1.next();
11651             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11652                 return false;
11653             }
11654             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11655                 return false;
11656             }
11657             br = iter1.next();
11658             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11659                 return false;
11660             }
11661             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11662                 return false;
11663             }
11664             br = iter1.next();
11665             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11666                 return false;
11667             }
11668             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11669                 return false;
11670             }
11671             if ( iter1.hasNext() ) {
11672                 return false;
11673             }
11674             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
11675             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
11676             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
11677             br = iter2.next();
11678             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11679                 return false;
11680             }
11681             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11682                 return false;
11683             }
11684             br = iter2.next();
11685             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11686                 return false;
11687             }
11688             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11689                 return false;
11690             }
11691             br = iter2.next();
11692             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11693                 return false;
11694             }
11695             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11696                 return false;
11697             }
11698             if ( iter2.hasNext() ) {
11699                 return false;
11700             }
11701             final Phylogeny species0 = factory.create(
11702                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11703                                                        new NHXParser() )[ 0 ];
11704             final Phylogeny gene1 = factory.create(
11705                                                     "(((((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])",
11706                                                     new NHXParser() )[ 0 ];
11707             species0.setRooted( true );
11708             gene1.setRooted( true );
11709             final SDIR sdi_unrooted = new SDIR();
11710             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
11711             if ( sdi_unrooted.getCount() != 1 ) {
11712                 return false;
11713             }
11714             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
11715                 return false;
11716             }
11717             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
11718                 return false;
11719             }
11720             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
11721                 return false;
11722             }
11723             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11724                 return false;
11725             }
11726             final Phylogeny gene2 = factory.create(
11727                                                     "(((((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])",
11728                                                     new NHXParser() )[ 0 ];
11729             gene2.setRooted( true );
11730             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
11731             if ( sdi_unrooted.getCount() != 1 ) {
11732                 return false;
11733             }
11734             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11735                 return false;
11736             }
11737             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11738                 return false;
11739             }
11740             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
11741                 return false;
11742             }
11743             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11744                 return false;
11745             }
11746             final Phylogeny species6 = factory.create(
11747                                                        "(((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,"
11748                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11749                                                        new NHXParser() )[ 0 ];
11750             final Phylogeny gene6 = factory.create(
11751                                                     "((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],"
11752                                                             + "(((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],"
11753                                                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11754                                                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11755                                                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11756                                                     new NHXParser() )[ 0 ];
11757             species6.setRooted( true );
11758             gene6.setRooted( true );
11759             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
11760             if ( sdi_unrooted.getCount() != 1 ) {
11761                 return false;
11762             }
11763             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11764                 return false;
11765             }
11766             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11767                 return false;
11768             }
11769             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11770                 return false;
11771             }
11772             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11773                 return false;
11774             }
11775             if ( !p6[ 0 ].getRoot().isDuplication() ) {
11776                 return false;
11777             }
11778             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11779                 return false;
11780             }
11781             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11782                 return false;
11783             }
11784             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11785                 return false;
11786             }
11787             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11788                 return false;
11789             }
11790             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11791                 return false;
11792             }
11793             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11794                 return false;
11795             }
11796             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11797                 return false;
11798             }
11799             p6 = null;
11800             final Phylogeny species7 = factory.create(
11801                                                        "(((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,"
11802                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11803                                                        new NHXParser() )[ 0 ];
11804             final Phylogeny gene7 = factory.create(
11805                                                     "((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],"
11806                                                             + "(((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],"
11807                                                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11808                                                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11809                                                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11810                                                     new NHXParser() )[ 0 ];
11811             species7.setRooted( true );
11812             gene7.setRooted( true );
11813             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11814             if ( sdi_unrooted.getCount() != 1 ) {
11815                 return false;
11816             }
11817             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11818                 return false;
11819             }
11820             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11821                 return false;
11822             }
11823             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11824                 return false;
11825             }
11826             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11827                 return false;
11828             }
11829             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11830                 return false;
11831             }
11832             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11833                 return false;
11834             }
11835             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11836                 return false;
11837             }
11838             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11839                 return false;
11840             }
11841             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11842                 return false;
11843             }
11844             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11845                 return false;
11846             }
11847             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11848                 return false;
11849             }
11850             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11851                 return false;
11852             }
11853             p7 = null;
11854             final Phylogeny species8 = factory.create(
11855                                                        "(((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,"
11856                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11857                                                        new NHXParser() )[ 0 ];
11858             final Phylogeny gene8 = factory.create(
11859                                                     "((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],"
11860                                                             + "(((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],"
11861                                                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11862                                                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11863                                                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11864                                                     new NHXParser() )[ 0 ];
11865             species8.setRooted( true );
11866             gene8.setRooted( true );
11867             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11868             if ( sdi_unrooted.getCount() != 1 ) {
11869                 return false;
11870             }
11871             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11872                 return false;
11873             }
11874             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11875                 return false;
11876             }
11877             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11878                 return false;
11879             }
11880             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11881                 return false;
11882             }
11883             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11884                 return false;
11885             }
11886             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11887                 return false;
11888             }
11889             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11890                 return false;
11891             }
11892             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11893                 return false;
11894             }
11895             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11896                 return false;
11897             }
11898             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11899                 return false;
11900             }
11901             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11902                 return false;
11903             }
11904             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11905                 return false;
11906             }
11907             p8 = null;
11908         }
11909         catch ( final Exception e ) {
11910             e.printStackTrace( System.out );
11911             return false;
11912         }
11913         return true;
11914     }
11915
11916     private static boolean testSequenceDbWsTools1() {
11917         try {
11918             final PhylogenyNode n = new PhylogenyNode();
11919             n.setName( "NP_001025424" );
11920             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11921             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11922                     || !acc.getValue().equals( "NP_001025424" ) ) {
11923                 return false;
11924             }
11925             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11926             acc = SequenceDbWsTools.obtainSeqAccession( n );
11927             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11928                     || !acc.getValue().equals( "NP_001025424" ) ) {
11929                 return false;
11930             }
11931             n.setName( "NP_001025424.1" );
11932             acc = SequenceDbWsTools.obtainSeqAccession( n );
11933             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11934                     || !acc.getValue().equals( "NP_001025424" ) ) {
11935                 return false;
11936             }
11937             n.setName( "NM_001030253" );
11938             acc = SequenceDbWsTools.obtainSeqAccession( n );
11939             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11940                     || !acc.getValue().equals( "NM_001030253" ) ) {
11941                 return false;
11942             }
11943             n.setName( "BCL2_HUMAN" );
11944             acc = SequenceDbWsTools.obtainSeqAccession( n );
11945             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11946                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11947                 System.out.println( acc.toString() );
11948                 return false;
11949             }
11950             n.setName( "P10415" );
11951             acc = SequenceDbWsTools.obtainSeqAccession( n );
11952             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11953                     || !acc.getValue().equals( "P10415" ) ) {
11954                 System.out.println( acc.toString() );
11955                 return false;
11956             }
11957             n.setName( " P10415 " );
11958             acc = SequenceDbWsTools.obtainSeqAccession( n );
11959             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11960                     || !acc.getValue().equals( "P10415" ) ) {
11961                 System.out.println( acc.toString() );
11962                 return false;
11963             }
11964             n.setName( "_P10415|" );
11965             acc = SequenceDbWsTools.obtainSeqAccession( n );
11966             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11967                     || !acc.getValue().equals( "P10415" ) ) {
11968                 System.out.println( acc.toString() );
11969                 return false;
11970             }
11971             n.setName( "AY695820" );
11972             acc = SequenceDbWsTools.obtainSeqAccession( n );
11973             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11974                     || !acc.getValue().equals( "AY695820" ) ) {
11975                 System.out.println( acc.toString() );
11976                 return false;
11977             }
11978             n.setName( "_AY695820_" );
11979             acc = SequenceDbWsTools.obtainSeqAccession( n );
11980             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11981                     || !acc.getValue().equals( "AY695820" ) ) {
11982                 System.out.println( acc.toString() );
11983                 return false;
11984             }
11985             n.setName( "AAA59452" );
11986             acc = SequenceDbWsTools.obtainSeqAccession( n );
11987             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11988                     || !acc.getValue().equals( "AAA59452" ) ) {
11989                 System.out.println( acc.toString() );
11990                 return false;
11991             }
11992             n.setName( "_AAA59452_" );
11993             acc = SequenceDbWsTools.obtainSeqAccession( n );
11994             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11995                     || !acc.getValue().equals( "AAA59452" ) ) {
11996                 System.out.println( acc.toString() );
11997                 return false;
11998             }
11999             n.setName( "AAA59452.1" );
12000             acc = SequenceDbWsTools.obtainSeqAccession( n );
12001             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12002                     || !acc.getValue().equals( "AAA59452.1" ) ) {
12003                 System.out.println( acc.toString() );
12004                 return false;
12005             }
12006             n.setName( "_AAA59452.1_" );
12007             acc = SequenceDbWsTools.obtainSeqAccession( n );
12008             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12009                     || !acc.getValue().equals( "AAA59452.1" ) ) {
12010                 System.out.println( acc.toString() );
12011                 return false;
12012             }
12013             n.setName( "GI:94894583" );
12014             acc = SequenceDbWsTools.obtainSeqAccession( n );
12015             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
12016                     || !acc.getValue().equals( "94894583" ) ) {
12017                 System.out.println( acc.toString() );
12018                 return false;
12019             }
12020             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
12021             acc = SequenceDbWsTools.obtainSeqAccession( n );
12022             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
12023                     || !acc.getValue().equals( "71845847" ) ) {
12024                 System.out.println( acc.toString() );
12025                 return false;
12026             }
12027             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
12028             acc = SequenceDbWsTools.obtainSeqAccession( n );
12029             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12030                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
12031                 System.out.println( acc.toString() );
12032                 return false;
12033             }
12034         }
12035         catch ( final Exception e ) {
12036             return false;
12037         }
12038         return true;
12039     }
12040
12041     private static boolean testSequenceDbWsTools2() {
12042         try {
12043             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
12044             SequenceDbWsTools.obtainSeqInformation( n1 );
12045             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
12046                 return false;
12047             }
12048             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
12049                 return false;
12050             }
12051             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
12052                 return false;
12053             }
12054             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
12055                 return false;
12056             }
12057             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
12058             SequenceDbWsTools.obtainSeqInformation( n2 );
12059             if ( !n2.getNodeData().getSequence().getName()
12060                     .equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
12061                 return false;
12062             }
12063             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
12064                 return false;
12065             }
12066             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
12067                 return false;
12068             }
12069             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
12070                 return false;
12071             }
12072             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
12073             SequenceDbWsTools.obtainSeqInformation( n3 );
12074             if ( !n3.getNodeData().getSequence().getName()
12075                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
12076                 return false;
12077             }
12078             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
12079                 return false;
12080             }
12081             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
12082                 return false;
12083             }
12084             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
12085                 return false;
12086             }
12087         }
12088         catch ( final IOException e ) {
12089             System.out.println();
12090             System.out.println( "the following might be due to absence internet connection:" );
12091             e.printStackTrace( System.out );
12092             return true;
12093         }
12094         catch ( final Exception e ) {
12095             e.printStackTrace();
12096             return false;
12097         }
12098         return true;
12099     }
12100
12101     private static boolean testSequenceIdParsing() {
12102         try {
12103             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
12104             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12105                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
12106                 if ( id != null ) {
12107                     System.out.println( "value   =" + id.getValue() );
12108                     System.out.println( "provider=" + id.getSource() );
12109                 }
12110                 return false;
12111             }
12112             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
12113             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12114                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
12115                 if ( id != null ) {
12116                     System.out.println( "value   =" + id.getValue() );
12117                     System.out.println( "provider=" + id.getSource() );
12118                 }
12119                 return false;
12120             }
12121             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
12122             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12123                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
12124                 if ( id != null ) {
12125                     System.out.println( "value   =" + id.getValue() );
12126                     System.out.println( "provider=" + id.getSource() );
12127                 }
12128                 return false;
12129             }
12130             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
12131             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12132                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
12133                 if ( id != null ) {
12134                     System.out.println( "value   =" + id.getValue() );
12135                     System.out.println( "provider=" + id.getSource() );
12136                 }
12137                 return false;
12138             }
12139             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
12140             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12141                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
12142                 if ( id != null ) {
12143                     System.out.println( "value   =" + id.getValue() );
12144                     System.out.println( "provider=" + id.getSource() );
12145                 }
12146                 return false;
12147             }
12148             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
12149             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12150                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
12151                 if ( id != null ) {
12152                     System.out.println( "value   =" + id.getValue() );
12153                     System.out.println( "provider=" + id.getSource() );
12154                 }
12155                 return false;
12156             }
12157             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
12158             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12159                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
12160                 if ( id != null ) {
12161                     System.out.println( "value   =" + id.getValue() );
12162                     System.out.println( "provider=" + id.getSource() );
12163                 }
12164                 return false;
12165             }
12166             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
12167             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12168                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
12169                 if ( id != null ) {
12170                     System.out.println( "value   =" + id.getValue() );
12171                     System.out.println( "provider=" + id.getSource() );
12172                 }
12173                 return false;
12174             }
12175             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
12176             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12177                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
12178                 if ( id != null ) {
12179                     System.out.println( "value   =" + id.getValue() );
12180                     System.out.println( "provider=" + id.getSource() );
12181                 }
12182                 return false;
12183             }
12184             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
12185             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12186                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
12187                 if ( id != null ) {
12188                     System.out.println( "value   =" + id.getValue() );
12189                     System.out.println( "provider=" + id.getSource() );
12190                 }
12191                 return false;
12192             }
12193             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
12194             if ( id != null ) {
12195                 System.out.println( "value   =" + id.getValue() );
12196                 System.out.println( "provider=" + id.getSource() );
12197                 return false;
12198             }
12199             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
12200             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12201                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
12202                 if ( id != null ) {
12203                     System.out.println( "value   =" + id.getValue() );
12204                     System.out.println( "provider=" + id.getSource() );
12205                 }
12206                 return false;
12207             }
12208             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
12209             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12210                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
12211                 if ( id != null ) {
12212                     System.out.println( "value   =" + id.getValue() );
12213                     System.out.println( "provider=" + id.getSource() );
12214                 }
12215                 return false;
12216             }
12217             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
12218             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12219                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
12220                 if ( id != null ) {
12221                     System.out.println( "value   =" + id.getValue() );
12222                     System.out.println( "provider=" + id.getSource() );
12223                 }
12224                 return false;
12225             }
12226             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
12227             if ( id != null ) {
12228                 System.out.println( "value   =" + id.getValue() );
12229                 System.out.println( "provider=" + id.getSource() );
12230                 return false;
12231             }
12232         }
12233         catch ( final Exception e ) {
12234             e.printStackTrace( System.out );
12235             return false;
12236         }
12237         return true;
12238     }
12239
12240     private static boolean testSequenceWriter() {
12241         try {
12242             final String n = ForesterUtil.LINE_SEPARATOR;
12243             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
12244                 return false;
12245             }
12246             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
12247                 return false;
12248             }
12249             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
12250                 return false;
12251             }
12252             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
12253                 return false;
12254             }
12255             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
12256                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
12257                 return false;
12258             }
12259             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
12260                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
12261                 return false;
12262             }
12263         }
12264         catch ( final Exception e ) {
12265             e.printStackTrace();
12266             return false;
12267         }
12268         return true;
12269     }
12270
12271     private static boolean testSpecies() {
12272         try {
12273             final Species s1 = new BasicSpecies( "a" );
12274             final Species s2 = new BasicSpecies( "a" );
12275             final Species s3 = new BasicSpecies( "A" );
12276             final Species s4 = new BasicSpecies( "b" );
12277             if ( !s1.equals( s1 ) ) {
12278                 return false;
12279             }
12280             if ( s1.getSpeciesId().equals( "x" ) ) {
12281                 return false;
12282             }
12283             if ( s1.getSpeciesId().equals( null ) ) {
12284                 return false;
12285             }
12286             if ( !s1.equals( s2 ) ) {
12287                 return false;
12288             }
12289             if ( s1.equals( s3 ) ) {
12290                 return false;
12291             }
12292             if ( s1.hashCode() != s1.hashCode() ) {
12293                 return false;
12294             }
12295             if ( s1.hashCode() != s2.hashCode() ) {
12296                 return false;
12297             }
12298             if ( s1.hashCode() == s3.hashCode() ) {
12299                 return false;
12300             }
12301             if ( s1.compareTo( s1 ) != 0 ) {
12302                 return false;
12303             }
12304             if ( s1.compareTo( s2 ) != 0 ) {
12305                 return false;
12306             }
12307             if ( s1.compareTo( s3 ) != 0 ) {
12308                 return false;
12309             }
12310             if ( s1.compareTo( s4 ) >= 0 ) {
12311                 return false;
12312             }
12313             if ( s4.compareTo( s1 ) <= 0 ) {
12314                 return false;
12315             }
12316             if ( !s4.getSpeciesId().equals( "b" ) ) {
12317                 return false;
12318             }
12319             final Species s5 = new BasicSpecies( " C " );
12320             if ( !s5.getSpeciesId().equals( "C" ) ) {
12321                 return false;
12322             }
12323             if ( s5.equals( s1 ) ) {
12324                 return false;
12325             }
12326         }
12327         catch ( final Exception e ) {
12328             e.printStackTrace( System.out );
12329             return false;
12330         }
12331         return true;
12332     }
12333
12334     private static boolean testSplit() {
12335         try {
12336             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12337             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12338             //Archaeopteryx.createApplication( p0 );
12339             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
12340             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12341             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12342             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12343             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12344             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12345             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12346             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12347             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12348             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12349             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
12350             // System.out.println( s0.toString() );
12351             //
12352             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12353             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12354             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12355             if ( s0.match( query_nodes ) ) {
12356                 return false;
12357             }
12358             query_nodes = new HashSet<PhylogenyNode>();
12359             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12360             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12361             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12362             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12363             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12364             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12365             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12366             if ( !s0.match( query_nodes ) ) {
12367                 return false;
12368             }
12369             //
12370             query_nodes = new HashSet<PhylogenyNode>();
12371             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12372             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12373             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12374             if ( !s0.match( query_nodes ) ) {
12375                 return false;
12376             }
12377             //
12378             query_nodes = new HashSet<PhylogenyNode>();
12379             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12380             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12381             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12382             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12383             if ( !s0.match( query_nodes ) ) {
12384                 return false;
12385             }
12386             //
12387             query_nodes = new HashSet<PhylogenyNode>();
12388             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12389             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12390             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12391             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12392             if ( !s0.match( query_nodes ) ) {
12393                 return false;
12394             }
12395             //
12396             query_nodes = new HashSet<PhylogenyNode>();
12397             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12398             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12399             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12400             if ( !s0.match( query_nodes ) ) {
12401                 return false;
12402             }
12403             query_nodes = new HashSet<PhylogenyNode>();
12404             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12405             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12406             if ( !s0.match( query_nodes ) ) {
12407                 return false;
12408             }
12409             query_nodes = new HashSet<PhylogenyNode>();
12410             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12411             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12412             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12413             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12414             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12415             if ( !s0.match( query_nodes ) ) {
12416                 return false;
12417             }
12418             query_nodes = new HashSet<PhylogenyNode>();
12419             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12420             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12421             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12422             if ( !s0.match( query_nodes ) ) {
12423                 return false;
12424             }
12425             query_nodes = new HashSet<PhylogenyNode>();
12426             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12427             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12428             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12429             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12430             if ( !s0.match( query_nodes ) ) {
12431                 return false;
12432             }
12433             query_nodes = new HashSet<PhylogenyNode>();
12434             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12435             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12436             if ( s0.match( query_nodes ) ) {
12437                 return false;
12438             }
12439             query_nodes = new HashSet<PhylogenyNode>();
12440             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12441             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12442             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12443             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12444             if ( s0.match( query_nodes ) ) {
12445                 return false;
12446             }
12447             query_nodes = new HashSet<PhylogenyNode>();
12448             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12449             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12450             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12451             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12452             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12453             if ( s0.match( query_nodes ) ) {
12454                 return false;
12455             }
12456             query_nodes = new HashSet<PhylogenyNode>();
12457             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12458             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12459             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12460             if ( s0.match( query_nodes ) ) {
12461                 return false;
12462             }
12463             query_nodes = new HashSet<PhylogenyNode>();
12464             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12465             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12466             if ( s0.match( query_nodes ) ) {
12467                 return false;
12468             }
12469             query_nodes = new HashSet<PhylogenyNode>();
12470             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12471             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12472             if ( s0.match( query_nodes ) ) {
12473                 return false;
12474             }
12475             query_nodes = new HashSet<PhylogenyNode>();
12476             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12477             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12478             if ( s0.match( query_nodes ) ) {
12479                 return false;
12480             }
12481             query_nodes = new HashSet<PhylogenyNode>();
12482             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12483             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12484             if ( s0.match( query_nodes ) ) {
12485                 return false;
12486             }
12487             query_nodes = new HashSet<PhylogenyNode>();
12488             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12489             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12490             if ( s0.match( query_nodes ) ) {
12491                 return false;
12492             }
12493             query_nodes = new HashSet<PhylogenyNode>();
12494             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12495             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12496             if ( s0.match( query_nodes ) ) {
12497                 return false;
12498             }
12499             query_nodes = new HashSet<PhylogenyNode>();
12500             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12501             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12502             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12503             if ( s0.match( query_nodes ) ) {
12504                 return false;
12505             }
12506             query_nodes = new HashSet<PhylogenyNode>();
12507             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12508             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12509             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12510             if ( s0.match( query_nodes ) ) {
12511                 return false;
12512             }
12513             query_nodes = new HashSet<PhylogenyNode>();
12514             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12515             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12516             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12517             if ( s0.match( query_nodes ) ) {
12518                 return false;
12519             }
12520             query_nodes = new HashSet<PhylogenyNode>();
12521             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12522             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12523             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12524             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12525             if ( s0.match( query_nodes ) ) {
12526                 return false;
12527             }
12528             /////////
12529             //            query_nodes = new HashSet<PhylogenyNode>();
12530             //            query_nodes.add( new PhylogenyNode( "X" ) );
12531             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12532             //            query_nodes.add( new PhylogenyNode( "A" ) );
12533             //            query_nodes.add( new PhylogenyNode( "B" ) );
12534             //            query_nodes.add( new PhylogenyNode( "C" ) );
12535             //            query_nodes.add( new PhylogenyNode( "D" ) );
12536             //            query_nodes.add( new PhylogenyNode( "E" ) );
12537             //            query_nodes.add( new PhylogenyNode( "F" ) );
12538             //            query_nodes.add( new PhylogenyNode( "G" ) );
12539             //            if ( !s0.match( query_nodes ) ) {
12540             //                return false;
12541             //            }
12542             //            query_nodes = new HashSet<PhylogenyNode>();
12543             //            query_nodes.add( new PhylogenyNode( "X" ) );
12544             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12545             //            query_nodes.add( new PhylogenyNode( "A" ) );
12546             //            query_nodes.add( new PhylogenyNode( "B" ) );
12547             //            query_nodes.add( new PhylogenyNode( "C" ) );
12548             //            if ( !s0.match( query_nodes ) ) {
12549             //                return false;
12550             //            }
12551             //            //
12552             //            query_nodes = new HashSet<PhylogenyNode>();
12553             //            query_nodes.add( new PhylogenyNode( "X" ) );
12554             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12555             //            query_nodes.add( new PhylogenyNode( "D" ) );
12556             //            query_nodes.add( new PhylogenyNode( "E" ) );
12557             //            query_nodes.add( new PhylogenyNode( "F" ) );
12558             //            query_nodes.add( new PhylogenyNode( "G" ) );
12559             //            if ( !s0.match( query_nodes ) ) {
12560             //                return false;
12561             //            }
12562             //            //
12563             //            query_nodes = new HashSet<PhylogenyNode>();
12564             //            query_nodes.add( new PhylogenyNode( "X" ) );
12565             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12566             //            query_nodes.add( new PhylogenyNode( "A" ) );
12567             //            query_nodes.add( new PhylogenyNode( "B" ) );
12568             //            query_nodes.add( new PhylogenyNode( "C" ) );
12569             //            query_nodes.add( new PhylogenyNode( "D" ) );
12570             //            if ( !s0.match( query_nodes ) ) {
12571             //                return false;
12572             //            }
12573             //            //
12574             //            query_nodes = new HashSet<PhylogenyNode>();
12575             //            query_nodes.add( new PhylogenyNode( "X" ) );
12576             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12577             //            query_nodes.add( new PhylogenyNode( "E" ) );
12578             //            query_nodes.add( new PhylogenyNode( "F" ) );
12579             //            query_nodes.add( new PhylogenyNode( "G" ) );
12580             //            if ( !s0.match( query_nodes ) ) {
12581             //                return false;
12582             //            }
12583             //            //
12584             //            query_nodes = new HashSet<PhylogenyNode>();
12585             //            query_nodes.add( new PhylogenyNode( "X" ) );
12586             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12587             //            query_nodes.add( new PhylogenyNode( "F" ) );
12588             //            query_nodes.add( new PhylogenyNode( "G" ) );
12589             //            if ( !s0.match( query_nodes ) ) {
12590             //                return false;
12591             //            }
12592             //
12593             query_nodes = new HashSet<PhylogenyNode>();
12594             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12595             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12596             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12597             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12598             if ( s0.match( query_nodes ) ) {
12599                 return false;
12600             }
12601             //
12602             query_nodes = new HashSet<PhylogenyNode>();
12603             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12604             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12605             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12606             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12607             if ( s0.match( query_nodes ) ) {
12608                 return false;
12609             }
12610             ///////////////////////////
12611             //
12612             query_nodes = new HashSet<PhylogenyNode>();
12613             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12614             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12615             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12616             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12617             if ( s0.match( query_nodes ) ) {
12618                 return false;
12619             }
12620             //
12621             query_nodes = new HashSet<PhylogenyNode>();
12622             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12623             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12624             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12625             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12626             if ( s0.match( query_nodes ) ) {
12627                 return false;
12628             }
12629             //
12630             query_nodes = new HashSet<PhylogenyNode>();
12631             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12632             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12633             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12634             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12635             if ( s0.match( query_nodes ) ) {
12636                 return false;
12637             }
12638             //
12639             query_nodes = new HashSet<PhylogenyNode>();
12640             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12641             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12642             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12643             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12644             if ( s0.match( query_nodes ) ) {
12645                 return false;
12646             }
12647             //
12648             query_nodes = new HashSet<PhylogenyNode>();
12649             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12650             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12651             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12652             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12653             if ( s0.match( query_nodes ) ) {
12654                 return false;
12655             }
12656             //
12657             query_nodes = new HashSet<PhylogenyNode>();
12658             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12659             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12660             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12661             if ( s0.match( query_nodes ) ) {
12662                 return false;
12663             }
12664             //
12665             query_nodes = new HashSet<PhylogenyNode>();
12666             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12667             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12668             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12669             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12670             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12671             if ( s0.match( query_nodes ) ) {
12672                 return false;
12673             }
12674             //
12675             query_nodes = new HashSet<PhylogenyNode>();
12676             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12677             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12678             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12679             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12680             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12681             if ( s0.match( query_nodes ) ) {
12682                 return false;
12683             }
12684             //
12685             query_nodes = new HashSet<PhylogenyNode>();
12686             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12688             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12689             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12690             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12691             if ( s0.match( query_nodes ) ) {
12692                 return false;
12693             }
12694             //
12695             query_nodes = new HashSet<PhylogenyNode>();
12696             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12697             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12698             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12699             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12700             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12701             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12702             if ( s0.match( query_nodes ) ) {
12703                 return false;
12704             }
12705         }
12706         catch ( final Exception e ) {
12707             e.printStackTrace();
12708             return false;
12709         }
12710         return true;
12711     }
12712
12713     private static boolean testSplitStrict() {
12714         try {
12715             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12716             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12717             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
12718             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12719             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12720             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12721             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12722             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12723             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12724             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12725             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
12726             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12727             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12728             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12729             if ( s0.match( query_nodes ) ) {
12730                 return false;
12731             }
12732             query_nodes = new HashSet<PhylogenyNode>();
12733             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12734             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12735             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12736             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12737             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12738             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12739             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12740             if ( !s0.match( query_nodes ) ) {
12741                 return false;
12742             }
12743             //
12744             query_nodes = new HashSet<PhylogenyNode>();
12745             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12746             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12747             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12748             if ( !s0.match( query_nodes ) ) {
12749                 return false;
12750             }
12751             //
12752             query_nodes = new HashSet<PhylogenyNode>();
12753             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12754             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12755             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12756             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12757             if ( !s0.match( query_nodes ) ) {
12758                 return false;
12759             }
12760             //
12761             query_nodes = new HashSet<PhylogenyNode>();
12762             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12763             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12764             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12765             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12766             if ( !s0.match( query_nodes ) ) {
12767                 return false;
12768             }
12769             //
12770             query_nodes = new HashSet<PhylogenyNode>();
12771             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12772             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12773             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12774             if ( !s0.match( query_nodes ) ) {
12775                 return false;
12776             }
12777             //
12778             query_nodes = new HashSet<PhylogenyNode>();
12779             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12780             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12781             if ( !s0.match( query_nodes ) ) {
12782                 return false;
12783             }
12784             //
12785             query_nodes = new HashSet<PhylogenyNode>();
12786             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12787             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12788             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12789             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12790             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12791             if ( !s0.match( query_nodes ) ) {
12792                 return false;
12793             }
12794             //
12795             query_nodes = new HashSet<PhylogenyNode>();
12796             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12797             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12798             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12799             if ( !s0.match( query_nodes ) ) {
12800                 return false;
12801             }
12802             //
12803             query_nodes = new HashSet<PhylogenyNode>();
12804             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12805             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12806             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12807             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12808             if ( !s0.match( query_nodes ) ) {
12809                 return false;
12810             }
12811             //
12812             query_nodes = new HashSet<PhylogenyNode>();
12813             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12814             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12815             if ( s0.match( query_nodes ) ) {
12816                 return false;
12817             }
12818             //
12819             query_nodes = new HashSet<PhylogenyNode>();
12820             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12822             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12823             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12824             if ( s0.match( query_nodes ) ) {
12825                 return false;
12826             }
12827             //
12828             query_nodes = new HashSet<PhylogenyNode>();
12829             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12830             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12831             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12832             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12833             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12834             if ( s0.match( query_nodes ) ) {
12835                 return false;
12836             }
12837             //
12838             query_nodes = new HashSet<PhylogenyNode>();
12839             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12840             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12841             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12842             if ( s0.match( query_nodes ) ) {
12843                 return false;
12844             }
12845             //
12846             query_nodes = new HashSet<PhylogenyNode>();
12847             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12848             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12849             if ( s0.match( query_nodes ) ) {
12850                 return false;
12851             }
12852             //
12853             query_nodes = new HashSet<PhylogenyNode>();
12854             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12855             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12856             if ( s0.match( query_nodes ) ) {
12857                 return false;
12858             }
12859             //
12860             query_nodes = new HashSet<PhylogenyNode>();
12861             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12862             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12863             if ( s0.match( query_nodes ) ) {
12864                 return false;
12865             }
12866             //
12867             query_nodes = new HashSet<PhylogenyNode>();
12868             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12869             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12870             if ( s0.match( query_nodes ) ) {
12871                 return false;
12872             }
12873             //
12874             query_nodes = new HashSet<PhylogenyNode>();
12875             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12876             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12877             if ( s0.match( query_nodes ) ) {
12878                 return false;
12879             }
12880             //
12881             query_nodes = new HashSet<PhylogenyNode>();
12882             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12883             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12884             if ( s0.match( query_nodes ) ) {
12885                 return false;
12886             }
12887             //
12888             query_nodes = new HashSet<PhylogenyNode>();
12889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12890             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12891             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12892             if ( s0.match( query_nodes ) ) {
12893                 return false;
12894             }
12895             //
12896             query_nodes = new HashSet<PhylogenyNode>();
12897             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12898             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12899             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12900             if ( s0.match( query_nodes ) ) {
12901                 return false;
12902             }
12903             //
12904             query_nodes = new HashSet<PhylogenyNode>();
12905             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12908             if ( s0.match( query_nodes ) ) {
12909                 return false;
12910             }
12911             //
12912             query_nodes = new HashSet<PhylogenyNode>();
12913             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12914             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12915             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12916             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12917             if ( s0.match( query_nodes ) ) {
12918                 return false;
12919             }
12920         }
12921         catch ( final Exception e ) {
12922             e.printStackTrace();
12923             return false;
12924         }
12925         return true;
12926     }
12927
12928     private static boolean testSubtreeDeletion() {
12929         try {
12930             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12931             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12932             t1.deleteSubtree( t1.getNode( "A" ), false );
12933             if ( t1.getNumberOfExternalNodes() != 5 ) {
12934                 return false;
12935             }
12936             t1.toNewHampshireX();
12937             t1.deleteSubtree( t1.getNode( "E" ), false );
12938             if ( t1.getNumberOfExternalNodes() != 4 ) {
12939                 return false;
12940             }
12941             t1.toNewHampshireX();
12942             t1.deleteSubtree( t1.getNode( "F" ), false );
12943             if ( t1.getNumberOfExternalNodes() != 3 ) {
12944                 return false;
12945             }
12946             t1.toNewHampshireX();
12947             t1.deleteSubtree( t1.getNode( "D" ), false );
12948             t1.toNewHampshireX();
12949             if ( t1.getNumberOfExternalNodes() != 3 ) {
12950                 return false;
12951             }
12952             t1.deleteSubtree( t1.getNode( "def" ), false );
12953             t1.toNewHampshireX();
12954             if ( t1.getNumberOfExternalNodes() != 2 ) {
12955                 return false;
12956             }
12957             t1.deleteSubtree( t1.getNode( "B" ), false );
12958             t1.toNewHampshireX();
12959             if ( t1.getNumberOfExternalNodes() != 1 ) {
12960                 return false;
12961             }
12962             t1.deleteSubtree( t1.getNode( "C" ), false );
12963             t1.toNewHampshireX();
12964             if ( t1.getNumberOfExternalNodes() != 1 ) {
12965                 return false;
12966             }
12967             t1.deleteSubtree( t1.getNode( "abc" ), false );
12968             t1.toNewHampshireX();
12969             if ( t1.getNumberOfExternalNodes() != 1 ) {
12970                 return false;
12971             }
12972             t1.deleteSubtree( t1.getNode( "r" ), false );
12973             if ( t1.getNumberOfExternalNodes() != 0 ) {
12974                 return false;
12975             }
12976             if ( !t1.isEmpty() ) {
12977                 return false;
12978             }
12979             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12980             t2.deleteSubtree( t2.getNode( "A" ), false );
12981             t2.toNewHampshireX();
12982             if ( t2.getNumberOfExternalNodes() != 5 ) {
12983                 return false;
12984             }
12985             t2.deleteSubtree( t2.getNode( "abc" ), false );
12986             t2.toNewHampshireX();
12987             if ( t2.getNumberOfExternalNodes() != 3 ) {
12988                 return false;
12989             }
12990             t2.deleteSubtree( t2.getNode( "def" ), false );
12991             t2.toNewHampshireX();
12992             if ( t2.getNumberOfExternalNodes() != 1 ) {
12993                 return false;
12994             }
12995         }
12996         catch ( final Exception e ) {
12997             e.printStackTrace( System.out );
12998             return false;
12999         }
13000         return true;
13001     }
13002
13003     private static boolean testSupportCount() {
13004         try {
13005             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13006             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
13007             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
13008                     + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
13009                     + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))" + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
13010                                                               new NHXParser() );
13011             SupportCount.count( t0_1, phylogenies_1, true, false );
13012             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
13013             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
13014                     + "(((((A,B),C),D),E),((F,G),X))" + "(((((A,Y),B),C),D),((F,G),E))" + "(((((A,B),C),D),E),(F,G))"
13015                     + "(((((A,B),C),D),E),(F,G))" + "(((((A,B),C),D),E),(F,G))" + "(((((A,B),C),D),E),(F,G),Z)"
13016                     + "(((((A,B),C),D),E),(F,G))" + "((((((A,B),C),D),E),F),G)" + "(((((X,Y),F,G),E),((A,B),C)),D)",
13017                                                               new NHXParser() );
13018             SupportCount.count( t0_2, phylogenies_2, true, false );
13019             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
13020             while ( it.hasNext() ) {
13021                 final PhylogenyNode n = it.next();
13022                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
13023                     return false;
13024                 }
13025             }
13026             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
13027             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
13028                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
13029             SupportCount.count( t0_3, phylogenies_3, true, false );
13030             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
13031             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
13032                 return false;
13033             }
13034             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
13035                 return false;
13036             }
13037             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
13038                 return false;
13039             }
13040             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
13041                 return false;
13042             }
13043             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
13044                 return false;
13045             }
13046             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
13047                 return false;
13048             }
13049             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
13050                 return false;
13051             }
13052             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
13053                 return false;
13054             }
13055             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
13056                 return false;
13057             }
13058             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
13059                 return false;
13060             }
13061             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13062             final Phylogeny[] phylogenies_4 = factory
13063                     .create( "((((((A,X),C),B),D),E),F) " + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
13064             SupportCount.count( t0_4, phylogenies_4, true, false );
13065             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
13066             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
13067                 return false;
13068             }
13069             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
13070                 return false;
13071             }
13072             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
13073                 return false;
13074             }
13075             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
13076                 return false;
13077             }
13078             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
13079                 return false;
13080             }
13081             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
13082                 return false;
13083             }
13084             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
13085                 return false;
13086             }
13087             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
13088                 return false;
13089             }
13090             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
13091                 return false;
13092             }
13093             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
13094                 return false;
13095             }
13096             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13097             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13098             double d = SupportCount.compare( b1, a, true, true, true );
13099             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
13100                 return false;
13101             }
13102             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13103             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13104             d = SupportCount.compare( b2, a, true, true, true );
13105             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
13106                 return false;
13107             }
13108             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13109             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
13110             d = SupportCount.compare( b3, a, true, true, true );
13111             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
13112                 return false;
13113             }
13114             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
13115             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
13116             d = SupportCount.compare( b4, a, true, true, false );
13117             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
13118                 return false;
13119             }
13120         }
13121         catch ( final Exception e ) {
13122             e.printStackTrace( System.out );
13123             return false;
13124         }
13125         return true;
13126     }
13127
13128     private static boolean testSupportTransfer() {
13129         try {
13130             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13131             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)",
13132                                                  new NHXParser() )[ 0 ];
13133             final Phylogeny p2 = factory.create(
13134                                                  "(((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)",
13135                                                  new NHXParser() )[ 0 ];
13136             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
13137                 return false;
13138             }
13139             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
13140                 return false;
13141             }
13142             support_transfer.moveBranchLengthsToBootstrap( p1 );
13143             support_transfer.transferSupportValues( p1, p2 );
13144             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
13145                 return false;
13146             }
13147             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
13148                 return false;
13149             }
13150             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
13151                 return false;
13152             }
13153             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
13154                 return false;
13155             }
13156             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
13157                 return false;
13158             }
13159             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
13160                 return false;
13161             }
13162             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
13163                 return false;
13164             }
13165             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
13166                 return false;
13167             }
13168         }
13169         catch ( final Exception e ) {
13170             e.printStackTrace( System.out );
13171             return false;
13172         }
13173         return true;
13174     }
13175
13176     private static boolean testTaxonomyExtraction() {
13177         try {
13178             final PhylogenyNode n0 = PhylogenyNode
13179                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13180             if ( n0.getNodeData().isHasTaxonomy() ) {
13181                 return false;
13182             }
13183             final PhylogenyNode n1 = PhylogenyNode
13184                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13185             if ( n1.getNodeData().isHasTaxonomy() ) {
13186                 System.out.println( n1.toString() );
13187                 return false;
13188             }
13189             final PhylogenyNode n2x = PhylogenyNode
13190                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13191             if ( n2x.getNodeData().isHasTaxonomy() ) {
13192                 return false;
13193             }
13194             final PhylogenyNode n3 = PhylogenyNode
13195                     .createInstanceFromNhxString( "BLAGG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13196             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13197                 System.out.println( n3.toString() );
13198                 return false;
13199             }
13200             final PhylogenyNode n4 = PhylogenyNode
13201                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13202             if ( n4.getNodeData().isHasTaxonomy() ) {
13203                 System.out.println( n4.toString() );
13204                 return false;
13205             }
13206             final PhylogenyNode n5 = PhylogenyNode
13207                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13208             if ( n5.getNodeData().isHasTaxonomy() ) {
13209                 System.out.println( n5.toString() );
13210                 return false;
13211             }
13212             final PhylogenyNode n6 = PhylogenyNode
13213                     .createInstanceFromNhxString( "BLAGG-12345-blag",
13214                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13215             if ( n6.getNodeData().isHasTaxonomy() ) {
13216                 System.out.println( n6.toString() );
13217                 return false;
13218             }
13219             final PhylogenyNode n7 = PhylogenyNode
13220                     .createInstanceFromNhxString( "BL-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13221             if ( n7.getNodeData().isHasTaxonomy() ) {
13222                 System.out.println( n7.toString() );
13223                 return false;
13224             }
13225             final PhylogenyNode n8 = PhylogenyNode
13226                     .createInstanceFromNhxString( "BLAGG_12345-blag",
13227                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13228             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13229                 System.out.println( n8.toString() );
13230                 return false;
13231             }
13232             final PhylogenyNode n9 = PhylogenyNode
13233                     .createInstanceFromNhxString( "BLAGG_12345/blag",
13234                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13235             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13236                 System.out.println( n9.toString() );
13237                 return false;
13238             }
13239             final PhylogenyNode n10x = PhylogenyNode
13240                     .createInstanceFromNhxString( "BLAG!_12X45-blag",
13241                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13242             if ( n10x.getNodeData().isHasTaxonomy() ) {
13243                 System.out.println( n10x.toString() );
13244                 return false;
13245             }
13246             final PhylogenyNode n10xx = PhylogenyNode
13247                     .createInstanceFromNhxString( "BLAG!_1YX45-blag",
13248                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13249             if ( n10xx.getNodeData().isHasTaxonomy() ) {
13250                 System.out.println( n10xx.toString() );
13251                 return false;
13252             }
13253             final PhylogenyNode n10 = PhylogenyNode
13254                     .createInstanceFromNhxString( "BLAGG_9YX45-blag",
13255                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13256             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
13257                 System.out.println( n10.toString() );
13258                 return false;
13259             }
13260             final PhylogenyNode n10v = PhylogenyNode
13261                     .createInstanceFromNhxString( "BLAGG_BPM1-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13262             if ( !n10v.getNodeData().getTaxonomy().getTaxonomyCode().equals( "BPM1" ) ) {
13263                 System.out.println( n10v.toString() );
13264                 return false;
13265             }
13266             final PhylogenyNode n10v2 = PhylogenyNode
13267                     .createInstanceFromNhxString( "BLAGG_ABV-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13268             if ( !n10v2.getNodeData().getTaxonomy().getTaxonomyCode().equals( "ABV" ) ) {
13269                 System.out.println( n10v2.toString() );
13270                 return false;
13271             }
13272             final PhylogenyNode n11 = PhylogenyNode
13273                     .createInstanceFromNhxString( "BLAG@_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13274             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13275                 System.out.println( n11.toString() );
13276                 return false;
13277             }
13278             final PhylogenyNode n12 = PhylogenyNode
13279                     .createInstanceFromNhxString( "BLA_G_Mus_musculus_musculus",
13280                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13281             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13282                 System.out.println( n12.toString() );
13283                 return false;
13284             }
13285             final PhylogenyNode n13 = PhylogenyNode
13286                     .createInstanceFromNhxString( "BLAaG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13287             if ( n13.getNodeData().isHasTaxonomy() ) {
13288                 System.out.println( n13.toString() );
13289                 return false;
13290             }
13291             final PhylogenyNode n14 = PhylogenyNode
13292                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13293             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13294                 System.out.println( n14.toString() );
13295                 return false;
13296             }
13297             final PhylogenyNode n15 = PhylogenyNode
13298                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13299             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13300                 System.out.println( n15.toString() );
13301                 return false;
13302             }
13303             final PhylogenyNode n16 = PhylogenyNode
13304                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13305             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13306                 System.out.println( n16.toString() );
13307                 return false;
13308             }
13309             final PhylogenyNode n17 = PhylogenyNode
13310                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13311             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13312                 System.out.println( n17.toString() );
13313                 return false;
13314             }
13315             final PhylogenyNode n18 = PhylogenyNode
13316                     .createInstanceFromNhxString( "Mus_musculus_musculus_392",
13317                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13318             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13319                 System.out.println( n18.toString() );
13320                 return false;
13321             }
13322             final PhylogenyNode n19 = PhylogenyNode
13323                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
13324                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13325             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13326                 System.out.println( n19.toString() );
13327                 return false;
13328             }
13329             final PhylogenyNode n20 = PhylogenyNode
13330                     .createInstanceFromNhxString( "Mus musculus musculus 392",
13331                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13332             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13333                 System.out.println( n20.toString() );
13334                 return false;
13335             }
13336             final PhylogenyNode n21 = PhylogenyNode
13337                     .createInstanceFromNhxString( "Mus musculus musculus K392",
13338                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13339             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13340                 System.out.println( n21.toString() );
13341                 return false;
13342             }
13343             final PhylogenyNode n23 = PhylogenyNode
13344                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
13345                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13346             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13347                 System.out.println( n23.toString() );
13348                 return false;
13349             }
13350             final PhylogenyNode n24 = PhylogenyNode
13351                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13352             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13353                 System.out.println( n24.toString() );
13354                 return false;
13355             }
13356             //
13357             final PhylogenyNode n25 = PhylogenyNode
13358                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
13359                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13360             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
13361                 System.out.println( n25.toString() );
13362                 return false;
13363             }
13364             final PhylogenyNode n26 = PhylogenyNode
13365                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
13366                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13367             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13368                 System.out.println( n26.toString() );
13369                 return false;
13370             }
13371             final PhylogenyNode n27 = PhylogenyNode
13372                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13373             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13374                 System.out.println( n27.toString() );
13375                 return false;
13376             }
13377         }
13378         catch ( final Exception e ) {
13379             e.printStackTrace( System.out );
13380             return false;
13381         }
13382         return true;
13383     }
13384
13385     private static boolean testTreeCopy() {
13386         try {
13387             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
13388             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
13389             final Phylogeny t1 = t0.copy();
13390             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
13391                 return false;
13392             }
13393             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13394                 return false;
13395             }
13396             t0.deleteSubtree( t0.getNode( "c" ), true );
13397             t0.deleteSubtree( t0.getNode( "a" ), true );
13398             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
13399             t0.getNode( "b" ).setName( "Bee" );
13400             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
13401                 return false;
13402             }
13403             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13404                 return false;
13405             }
13406             t0.deleteSubtree( t0.getNode( "e" ), true );
13407             t0.deleteSubtree( t0.getNode( "Bee" ), true );
13408             t0.deleteSubtree( t0.getNode( "d" ), true );
13409             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13410                 return false;
13411             }
13412         }
13413         catch ( final Exception e ) {
13414             e.printStackTrace();
13415             return false;
13416         }
13417         return true;
13418     }
13419
13420     private static boolean testTreeMethods() {
13421         try {
13422             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13423             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
13424             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
13425             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
13426                 System.out.println( t0.toNewHampshireX() );
13427                 return false;
13428             }
13429             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
13430             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
13431             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
13432                 return false;
13433             }
13434             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
13435                 return false;
13436             }
13437             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
13438                 return false;
13439             }
13440         }
13441         catch ( final Exception e ) {
13442             e.printStackTrace( System.out );
13443             return false;
13444         }
13445         return true;
13446     }
13447
13448     private static boolean testUniprotEntryRetrieval() {
13449         try {
13450             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 5000 );
13451             if ( !entry.getAccession().equals( "P12345" ) ) {
13452                 return false;
13453             }
13454             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
13455                 return false;
13456             }
13457             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
13458                 return false;
13459             }
13460             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
13461                 return false;
13462             }
13463             if ( !entry.getGeneName().equals( "GOT2" ) ) {
13464                 return false;
13465             }
13466             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
13467                 return false;
13468             }
13469             if ( entry.getMolecularSequence() == null ) {
13470                 return false;
13471             }
13472             if ( !entry.getMolecularSequence().getMolecularSequenceAsString()
13473                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
13474                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
13475                 System.out.println( "got: " + entry.getMolecularSequence().getMolecularSequenceAsString() );
13476                 System.out.println( "expected something else." );
13477                 return false;
13478             }
13479         }
13480         catch ( final IOException e ) {
13481             System.out.println();
13482             System.out.println( "the following might be due to absence internet connection:" );
13483             e.printStackTrace( System.out );
13484             return true;
13485         }
13486         catch ( final NullPointerException f ) {
13487             f.printStackTrace( System.out );
13488             return false;
13489         }
13490         catch ( final Exception e ) {
13491             return false;
13492         }
13493         return true;
13494     }
13495
13496     private static boolean testUniprotTaxonomySearch() {
13497         try {
13498             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
13499                                                                                                  10 );
13500             if ( results.size() != 1 ) {
13501                 return false;
13502             }
13503             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13504                 return false;
13505             }
13506             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13507                 return false;
13508             }
13509             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13510                 return false;
13511             }
13512             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13513                 return false;
13514             }
13515             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13516                 return false;
13517             }
13518             results = null;
13519             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
13520             if ( results.size() != 1 ) {
13521                 return false;
13522             }
13523             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13524                 return false;
13525             }
13526             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13527                 return false;
13528             }
13529             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13530                 return false;
13531             }
13532             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13533                 return false;
13534             }
13535             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13536                 return false;
13537             }
13538             results = null;
13539             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
13540             if ( results.size() != 1 ) {
13541                 return false;
13542             }
13543             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13544                 return false;
13545             }
13546             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13547                 return false;
13548             }
13549             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13550                 return false;
13551             }
13552             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13553                 return false;
13554             }
13555             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13556                 return false;
13557             }
13558             results = null;
13559             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
13560             if ( results.size() != 1 ) {
13561                 return false;
13562             }
13563             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13564                 return false;
13565             }
13566             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13567                 return false;
13568             }
13569             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13570                 return false;
13571             }
13572             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13573                 return false;
13574             }
13575             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13576                 return false;
13577             }
13578             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
13579                 return false;
13580             }
13581             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
13582                 return false;
13583             }
13584             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13585                     .equals( "Nematostella vectensis" ) ) {
13586                 System.out.println( results.get( 0 ).getLineage() );
13587                 return false;
13588             }
13589             //
13590             results = null;
13591             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
13592             if ( results.size() != 1 ) {
13593                 return false;
13594             }
13595             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13596                 return false;
13597             }
13598             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13599                 return false;
13600             }
13601             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13602                 return false;
13603             }
13604             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13605                 return false;
13606             }
13607             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13608                 return false;
13609             }
13610             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13611                     .equals( "Xenopus tropicalis" ) ) {
13612                 System.out.println( results.get( 0 ).getLineage() );
13613                 return false;
13614             }
13615             //
13616             results = null;
13617             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
13618             if ( results.size() != 1 ) {
13619                 return false;
13620             }
13621             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13622                 return false;
13623             }
13624             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13625                 return false;
13626             }
13627             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13628                 return false;
13629             }
13630             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13631                 return false;
13632             }
13633             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13634                 return false;
13635             }
13636             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13637                     .equals( "Xenopus tropicalis" ) ) {
13638                 System.out.println( results.get( 0 ).getLineage() );
13639                 return false;
13640             }
13641             //
13642             results = null;
13643             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
13644             if ( results.size() != 1 ) {
13645                 return false;
13646             }
13647             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13648                 return false;
13649             }
13650             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13651                 return false;
13652             }
13653             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13654                 return false;
13655             }
13656             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13657                 return false;
13658             }
13659             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13660                 return false;
13661             }
13662             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13663                     .equals( "Xenopus tropicalis" ) ) {
13664                 System.out.println( results.get( 0 ).getLineage() );
13665                 return false;
13666             }
13667         }
13668         catch ( final IOException e ) {
13669             System.out.println();
13670             System.out.println( "the following might be due to absence internet connection:" );
13671             e.printStackTrace( System.out );
13672             return true;
13673         }
13674         catch ( final Exception e ) {
13675             return false;
13676         }
13677         return true;
13678     }
13679 }