949d9ddcc61a87bdfd2367bcf4930af379e520bd
[jalview.git] / 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( "Phylogeny methods:" );
555         if ( Test.testPhylogenyMethods() ) {
556             System.out.println( "OK." );
557             succeeded++;
558         }
559         else {
560             System.out.println( "failed." );
561             failed++;
562         }
563         System.out.print( "Postorder Iterator: " );
564         if ( Test.testPostOrderIterator() ) {
565             System.out.println( "OK." );
566             succeeded++;
567         }
568         else {
569             System.out.println( "failed." );
570             failed++;
571         }
572         System.out.print( "Preorder Iterator: " );
573         if ( Test.testPreOrderIterator() ) {
574             System.out.println( "OK." );
575             succeeded++;
576         }
577         else {
578             System.out.println( "failed." );
579             failed++;
580         }
581         System.out.print( "Levelorder Iterator: " );
582         if ( Test.testLevelOrderIterator() ) {
583             System.out.println( "OK." );
584             succeeded++;
585         }
586         else {
587             System.out.println( "failed." );
588             failed++;
589         }
590         System.out.print( "Re-id methods: " );
591         if ( Test.testReIdMethods() ) {
592             System.out.println( "OK." );
593             succeeded++;
594         }
595         else {
596             System.out.println( "failed." );
597             failed++;
598         }
599         System.out.print( "Methods on last external nodes: " );
600         if ( Test.testLastExternalNodeMethods() ) {
601             System.out.println( "OK." );
602             succeeded++;
603         }
604         else {
605             System.out.println( "failed." );
606             failed++;
607         }
608         System.out.print( "Methods on external nodes: " );
609         if ( Test.testExternalNodeRelatedMethods() ) {
610             System.out.println( "OK." );
611             succeeded++;
612         }
613         else {
614             System.out.println( "failed." );
615             failed++;
616         }
617         System.out.print( "Deletion of external nodes: " );
618         if ( Test.testDeletionOfExternalNodes() ) {
619             System.out.println( "OK." );
620             succeeded++;
621         }
622         else {
623             System.out.println( "failed." );
624             failed++;
625         }
626         System.out.print( "Subtree deletion: " );
627         if ( Test.testSubtreeDeletion() ) {
628             System.out.println( "OK." );
629             succeeded++;
630         }
631         else {
632             System.out.println( "failed." );
633             failed++;
634         }
635         System.out.print( "Phylogeny branch: " );
636         if ( Test.testPhylogenyBranch() ) {
637             System.out.println( "OK." );
638             succeeded++;
639         }
640         else {
641             System.out.println( "failed." );
642             failed++;
643         }
644         System.out.print( "Rerooting: " );
645         if ( Test.testRerooting() ) {
646             System.out.println( "OK." );
647             succeeded++;
648         }
649         else {
650             System.out.println( "failed." );
651             failed++;
652         }
653         System.out.print( "Mipoint rooting: " );
654         if ( Test.testMidpointrooting() ) {
655             System.out.println( "OK." );
656             succeeded++;
657         }
658         else {
659             System.out.println( "failed." );
660             failed++;
661         }
662         System.out.print( "Node removal: " );
663         if ( Test.testNodeRemoval() ) {
664             System.out.println( "OK." );
665             succeeded++;
666         }
667         else {
668             System.out.println( "failed." );
669             failed++;
670         }
671         System.out.print( "Support count: " );
672         if ( Test.testSupportCount() ) {
673             System.out.println( "OK." );
674             succeeded++;
675         }
676         else {
677             System.out.println( "failed." );
678             failed++;
679         }
680         System.out.print( "Support transfer: " );
681         if ( Test.testSupportTransfer() ) {
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: " );
690         if ( Test.testGetLCA() ) {
691             System.out.println( "OK." );
692             succeeded++;
693         }
694         else {
695             System.out.println( "failed." );
696             failed++;
697         }
698         System.out.print( "Finding of LCA 2: " );
699         if ( Test.testGetLCA2() ) {
700             System.out.println( "OK." );
701             succeeded++;
702         }
703         else {
704             System.out.println( "failed." );
705             failed++;
706         }
707         System.out.print( "Calculation of distance between nodes: " );
708         if ( Test.testGetDistance() ) {
709             System.out.println( "OK." );
710             succeeded++;
711         }
712         else {
713             System.out.println( "failed." );
714             failed++;
715         }
716         System.out.print( "Descriptive statistics: " );
717         if ( Test.testDescriptiveStatistics() ) {
718             System.out.println( "OK." );
719             succeeded++;
720         }
721         else {
722             System.out.println( "failed." );
723             failed++;
724         }
725         System.out.print( "Data objects and methods: " );
726         if ( Test.testDataObjects() ) {
727             System.out.println( "OK." );
728             succeeded++;
729         }
730         else {
731             System.out.println( "failed." );
732             failed++;
733         }
734         System.out.print( "Properties map: " );
735         if ( Test.testPropertiesMap() ) {
736             System.out.println( "OK." );
737             succeeded++;
738         }
739         else {
740             System.out.println( "failed." );
741             failed++;
742         }
743         System.out.print( "SDIse: " );
744         if ( Test.testSDIse() ) {
745             System.out.println( "OK." );
746             succeeded++;
747         }
748         else {
749             System.out.println( "failed." );
750             failed++;
751         }
752         System.out.print( "SDIunrooted: " );
753         if ( Test.testSDIunrooted() ) {
754             System.out.println( "OK." );
755             succeeded++;
756         }
757         else {
758             System.out.println( "failed." );
759             failed++;
760         }
761         System.out.print( "GSDI: " );
762         if ( TestGSDI.test() ) {
763             System.out.println( "OK." );
764             succeeded++;
765         }
766         else {
767             System.out.println( "failed." );
768             failed++;
769         }
770         System.out.print( "RIO: " );
771         if ( TestRIO.test() ) {
772             System.out.println( "OK." );
773             succeeded++;
774         }
775         else {
776             System.out.println( "failed." );
777             failed++;
778         }
779         System.out.print( "Phylogeny reconstruction:" );
780         System.out.println();
781         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
782             System.out.println( "OK." );
783             succeeded++;
784         }
785         else {
786             System.out.println( "failed." );
787             failed++;
788         }
789         System.out.print( "Analysis of domain architectures: " );
790         System.out.println();
791         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
792             System.out.println( "OK." );
793             succeeded++;
794         }
795         else {
796             System.out.println( "failed." );
797             failed++;
798         }
799         System.out.print( "GO: " );
800         System.out.println();
801         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
802             System.out.println( "OK." );
803             succeeded++;
804         }
805         else {
806             System.out.println( "failed." );
807             failed++;
808         }
809         System.out.print( "Modeling tools: " );
810         if ( TestPccx.test() ) {
811             System.out.println( "OK." );
812             succeeded++;
813         }
814         else {
815             System.out.println( "failed." );
816             failed++;
817         }
818         System.out.print( "Split Matrix strict: " );
819         if ( Test.testSplitStrict() ) {
820             System.out.println( "OK." );
821             succeeded++;
822         }
823         else {
824             System.out.println( "failed." );
825             failed++;
826         }
827         System.out.print( "Split Matrix: " );
828         if ( Test.testSplit() ) {
829             System.out.println( "OK." );
830             succeeded++;
831         }
832         else {
833             System.out.println( "failed." );
834             failed++;
835         }
836         System.out.print( "Confidence Assessor: " );
837         if ( Test.testConfidenceAssessor() ) {
838             System.out.println( "OK." );
839             succeeded++;
840         }
841         else {
842             System.out.println( "failed." );
843             failed++;
844         }
845         System.out.print( "Basic table: " );
846         if ( Test.testBasicTable() ) {
847             System.out.println( "OK." );
848             succeeded++;
849         }
850         else {
851             System.out.println( "failed." );
852             failed++;
853         }
854         System.out.print( "General table: " );
855         if ( Test.testGeneralTable() ) {
856             System.out.println( "OK." );
857             succeeded++;
858         }
859         else {
860             System.out.println( "failed." );
861             failed++;
862         }
863         System.out.print( "Amino acid sequence: " );
864         if ( Test.testAminoAcidSequence() ) {
865             System.out.println( "OK." );
866             succeeded++;
867         }
868         else {
869             System.out.println( "failed." );
870             failed++;
871         }
872         System.out.print( "General MSA parser: " );
873         if ( Test.testGeneralMsaParser() ) {
874             System.out.println( "OK." );
875             succeeded++;
876         }
877         else {
878             System.out.println( "failed." );
879             failed++;
880         }
881         System.out.print( "Fasta parser for msa: " );
882         if ( Test.testFastaParser() ) {
883             System.out.println( "OK." );
884             succeeded++;
885         }
886         else {
887             System.out.println( "failed." );
888             failed++;
889         }
890         System.out.print( "Creation of balanced phylogeny: " );
891         if ( Test.testCreateBalancedPhylogeny() ) {
892             System.out.println( "OK." );
893             succeeded++;
894         }
895         else {
896             System.out.println( "failed." );
897             failed++;
898         }
899         System.out.print( "Genbank accessor parsing: " );
900         if ( Test.testGenbankAccessorParsing() ) {
901             System.out.println( "OK." );
902             succeeded++;
903         }
904         else {
905             System.out.println( "failed." );
906             failed++;
907         }
908         String path = "";
909         final String os = ForesterUtil.OS_NAME.toLowerCase();
910         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
911             path = "/usr/local/bin/mafft";
912         }
913         else if ( os.indexOf( "win" ) >= 0 ) {
914             path = "C:\\Program Files\\mafft-win\\mafft.bat";
915         }
916         else {
917             path = "mafft";
918             if ( !MsaInferrer.isInstalled( path ) ) {
919                 path = "/usr/bin/mafft";
920             }
921             if ( !MsaInferrer.isInstalled( path ) ) {
922                 path = "/usr/local/bin/mafft";
923             }
924         }
925         if ( MsaInferrer.isInstalled( path ) ) {
926             System.out.print( "MAFFT (external program): " );
927             if ( Test.testMafft( path ) ) {
928                 System.out.println( "OK." );
929                 succeeded++;
930             }
931             else {
932                 System.out.println( "failed [will not count towards failed tests]" );
933             }
934         }
935         System.out.print( "Next nodes with collapsed: " );
936         if ( Test.testNextNodeWithCollapsing() ) {
937             System.out.println( "OK." );
938             succeeded++;
939         }
940         else {
941             System.out.println( "failed." );
942             failed++;
943         }
944         System.out.print( "Simple MSA quality: " );
945         if ( Test.testMsaQualityMethod() ) {
946             System.out.println( "OK." );
947             succeeded++;
948         }
949         else {
950             System.out.println( "failed." );
951             failed++;
952         }
953         System.out.print( "Deleteable MSA: " );
954         if ( Test.testDeleteableMsa() ) {
955             System.out.println( "OK." );
956             succeeded++;
957         }
958         else {
959             System.out.println( "failed." );
960             failed++;
961         }
962         System.out.print( "MSA entropy: " );
963         if ( Test.testMsaEntropy() ) {
964             System.out.println( "OK." );
965             succeeded++;
966         }
967         else {
968             System.out.println( "failed." );
969             failed++;
970         }
971         if ( PERFORM_DB_TESTS ) {
972             System.out.print( "Uniprot Entry Retrieval: " );
973             if ( Test.testUniprotEntryRetrieval() ) {
974                 System.out.println( "OK." );
975                 succeeded++;
976             }
977             else {
978                 System.out.println( "failed." );
979                 failed++;
980             }
981             System.out.print( "Ebi Entry Retrieval: " );
982             if ( Test.testEbiEntryRetrieval() ) {
983                 System.out.println( "OK." );
984                 succeeded++;
985             }
986             else {
987                 System.out.println( "failed." );
988                 failed++;
989             }
990             System.out.print( "Sequence DB tools 2: " );
991             if ( testSequenceDbWsTools2() ) {
992                 System.out.println( "OK." );
993                 succeeded++;
994             }
995             else {
996                 System.out.println( "failed." );
997                 failed++;
998                 System.exit( -1 );
999             }
1000             System.out.print( "Uniprot Taxonomy Search: " );
1001             if ( Test.testUniprotTaxonomySearch() ) {
1002                 System.out.println( "OK." );
1003                 succeeded++;
1004             }
1005             else {
1006                 System.out.println( "failed." );
1007                 failed++;
1008             }
1009         }
1010         if ( PERFORM_WEB_TREE_ACCESS ) {
1011             System.out.print( "TreeBase acccess: " );
1012             if ( Test.testTreeBaseReading() ) {
1013                 System.out.println( "OK." );
1014                 succeeded++;
1015             }
1016             else {
1017                 System.out.println( "failed." );
1018                 failed++;
1019             }
1020             System.out.print( "ToL access: " );
1021             if ( Test.testToLReading() ) {
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: " );
1030             if ( Test.testNHXparsingFromURL() ) {
1031                 System.out.println( "OK." );
1032                 succeeded++;
1033             }
1034             else {
1035                 System.out.println( "failed." );
1036                 failed++;
1037             }
1038             System.out.print( "NHX parsing from URL 2: " );
1039             if ( Test.testNHXparsingFromURL2() ) {
1040                 System.out.println( "OK." );
1041                 succeeded++;
1042             }
1043             else {
1044                 System.out.println( "failed." );
1045                 failed++;
1046             }
1047             System.out.print( "phyloXML parsing from URL: " );
1048             if ( Test.testPhyloXMLparsingFromURL() ) {
1049                 System.out.println( "OK." );
1050                 succeeded++;
1051             }
1052             else {
1053                 System.out.println( "failed." );
1054                 failed++;
1055             }
1056             System.out.print( "TreeFam access: " );
1057             if ( Test.testTreeFamReading() ) {
1058                 System.out.println( "OK." );
1059                 succeeded++;
1060             }
1061             else {
1062                 System.out.println( "failed." );
1063                 failed++;
1064             }
1065             System.out.print( "Pfam tree access: " );
1066             if ( Test.testPfamTreeReading() ) {
1067                 System.out.println( "OK." );
1068                 succeeded++;
1069             }
1070             else {
1071                 System.out.println( "failed." );
1072                 failed++;
1073             }
1074         }
1075         System.out.println();
1076         final Runtime rt = java.lang.Runtime.getRuntime();
1077         final long free_memory = rt.freeMemory() / 1000000;
1078         final long total_memory = rt.totalMemory() / 1000000;
1079         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1080                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1081         System.out.println();
1082         System.out.println( "Successful tests: " + succeeded );
1083         System.out.println( "Failed     tests: " + failed );
1084         System.out.println();
1085         if ( failed < 1 ) {
1086             System.out.println( "OK." );
1087         }
1088         else {
1089             System.out.println( "Not OK." );
1090         }
1091     }
1092
1093     private static boolean testEngulfingOverlapRemoval() {
1094         try {
1095             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1096             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1097             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1098             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1099             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1100             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1101             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1102             final List<Boolean> covered = new ArrayList<Boolean>();
1103             covered.add( true ); // 0
1104             covered.add( false ); // 1
1105             covered.add( true ); // 2
1106             covered.add( false ); // 3
1107             covered.add( true ); // 4
1108             covered.add( true ); // 5
1109             covered.add( false ); // 6
1110             covered.add( true ); // 7
1111             covered.add( true ); // 8
1112             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1113                 return false;
1114             }
1115             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1116                 return false;
1117             }
1118             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1119                 return false;
1120             }
1121             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1122                 return false;
1123             }
1124             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1125                 return false;
1126             }
1127             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1128                 return false;
1129             }
1130             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1131                 return false;
1132             }
1133             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1134             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1135             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1136             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1137             abc.addProteinDomain( a );
1138             abc.addProteinDomain( b );
1139             abc.addProteinDomain( c );
1140             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1141             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1142             if ( abc.getNumberOfProteinDomains() != 3 ) {
1143                 return false;
1144             }
1145             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1146                 return false;
1147             }
1148             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1149                 return false;
1150             }
1151             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1152                 return false;
1153             }
1154             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1155                 return false;
1156             }
1157             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1158             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1159             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1160             final Protein def = new BasicProtein( "def", "nemve", 0 );
1161             def.addProteinDomain( d );
1162             def.addProteinDomain( e );
1163             def.addProteinDomain( f );
1164             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1165             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1166             if ( def.getNumberOfProteinDomains() != 3 ) {
1167                 return false;
1168             }
1169             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1170                 return false;
1171             }
1172             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1173                 return false;
1174             }
1175             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1176                 return false;
1177             }
1178             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1179                 return false;
1180             }
1181             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1182                 return false;
1183             }
1184         }
1185         catch ( final Exception e ) {
1186             e.printStackTrace( System.out );
1187             return false;
1188         }
1189         return true;
1190     }
1191
1192     private static final boolean testNHXparsingFromURL2() {
1193         try {
1194             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1195             final Phylogeny phys[] = AptxUtil
1196                     .readPhylogeniesFromUrl( new URL( s ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1197             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1198                 return false;
1199             }
1200             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1201                 System.out.println( phys[ 0 ].toNewHampshire() );
1202                 return false;
1203             }
1204             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1205                 System.out.println( phys[ 1 ].toNewHampshire() );
1206                 return false;
1207             }
1208             final Phylogeny phys2[] = AptxUtil
1209                     .readPhylogeniesFromUrl( new URL( s ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1210             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1211                 return false;
1212             }
1213             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1214                 System.out.println( phys2[ 0 ].toNewHampshire() );
1215                 return false;
1216             }
1217             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1218                 System.out.println( phys2[ 1 ].toNewHampshire() );
1219                 return false;
1220             }
1221             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1222                     + "SwissTree/ST001/consensus_tree.nhx" ),
1223                                                                        false,
1224                                                                        false,
1225                                                                        false,
1226                                                                        TAXONOMY_EXTRACTION.NO,
1227                                                                        false );
1228             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1229                 return false;
1230             }
1231             if ( !phys3[ 0 ].toNewHampshire()
1232                     .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))))));" ) ) {
1233                 System.out.println( phys3[ 0 ].toNewHampshire() );
1234                 return false;
1235             }
1236             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1237                     + "SwissTree/ST001/consensus_tree.nhx" ),
1238                                                                        false,
1239                                                                        false,
1240                                                                        false,
1241                                                                        TAXONOMY_EXTRACTION.NO,
1242                                                                        false );
1243             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1244                 return false;
1245             }
1246             if ( !phys4[ 0 ].toNewHampshire()
1247                     .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))))));" ) ) {
1248                 System.out.println( phys4[ 0 ].toNewHampshire() );
1249                 return false;
1250             }
1251         }
1252         catch ( final Exception e ) {
1253             e.printStackTrace();
1254             return false;
1255         }
1256         return true;
1257     }
1258
1259     private static final boolean testNHXparsingFromURL() {
1260         try {
1261             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1262             final URL u = new URL( s );
1263             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1264             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1265             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1266                 return false;
1267             }
1268             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1269                 System.out.println( phys[ 0 ].toNewHampshire() );
1270                 return false;
1271             }
1272             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1273                 System.out.println( phys[ 1 ].toNewHampshire() );
1274                 return false;
1275             }
1276             final URL u2 = new URL( s );
1277             final Phylogeny[] phys2 = factory.create( u2.openStream(), new NHXParser() );
1278             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1279                 return false;
1280             }
1281             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1282                 System.out.println( phys2[ 0 ].toNewHampshire() );
1283                 return false;
1284             }
1285             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1286             final NHXParser p = new NHXParser();
1287             final URL u3 = new URL( s );
1288             p.setSource( u3 );
1289             if ( !p.hasNext() ) {
1290                 return false;
1291             }
1292             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1293                 return false;
1294             }
1295             if ( !p.hasNext() ) {
1296                 return false;
1297             }
1298             p.reset();
1299             if ( !p.hasNext() ) {
1300                 return false;
1301             }
1302             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1303                 return false;
1304             }
1305             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1306                 return false;
1307             }
1308             p.reset();
1309             if ( !p.hasNext() ) {
1310                 return false;
1311             }
1312             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1313                 return false;
1314             }
1315             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1316                 return false;
1317             }
1318         }
1319         catch ( final Exception e ) {
1320             System.out.println( e.toString() );
1321             e.printStackTrace();
1322             return false;
1323         }
1324         return true;
1325     }
1326
1327     private static boolean testOverlapRemoval() {
1328         try {
1329             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1330             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1331             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1332             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1333             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1334             final List<Boolean> covered = new ArrayList<Boolean>();
1335             covered.add( true ); // 0
1336             covered.add( false ); // 1
1337             covered.add( true ); // 2
1338             covered.add( false ); // 3
1339             covered.add( true ); // 4
1340             covered.add( true ); // 5
1341             covered.add( false ); // 6
1342             covered.add( true ); // 7
1343             covered.add( true ); // 8
1344             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1345                 return false;
1346             }
1347             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1348                 return false;
1349             }
1350             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1351                 return false;
1352             }
1353             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1354                 return false;
1355             }
1356             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1357                 return false;
1358             }
1359             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1360             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1361             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1362             ab.addProteinDomain( a );
1363             ab.addProteinDomain( b );
1364             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1365             if ( ab.getNumberOfProteinDomains() != 2 ) {
1366                 return false;
1367             }
1368             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1369                 return false;
1370             }
1371             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1372                 return false;
1373             }
1374             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1375             if ( ab.getNumberOfProteinDomains() != 2 ) {
1376                 return false;
1377             }
1378             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1379                 return false;
1380             }
1381             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1382             final Domain d = new BasicDomain( "d",
1383                                               ( short ) 10000,
1384                                               ( short ) 10500,
1385                                               ( short ) 1,
1386                                               ( short ) 1,
1387                                               0.0000001,
1388                                               1 );
1389             final Domain e = new BasicDomain( "e",
1390                                               ( short ) 5000,
1391                                               ( short ) 5500,
1392                                               ( short ) 1,
1393                                               ( short ) 1,
1394                                               0.0001,
1395                                               1 );
1396             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1397             cde.addProteinDomain( c );
1398             cde.addProteinDomain( d );
1399             cde.addProteinDomain( e );
1400             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1401             if ( cde.getNumberOfProteinDomains() != 3 ) {
1402                 return false;
1403             }
1404             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1405                 return false;
1406             }
1407             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1408             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1409             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1410             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1411             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1412             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1413             fghi.addProteinDomain( f );
1414             fghi.addProteinDomain( g );
1415             fghi.addProteinDomain( h );
1416             fghi.addProteinDomain( i );
1417             fghi.addProteinDomain( i );
1418             fghi.addProteinDomain( i );
1419             fghi.addProteinDomain( i2 );
1420             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1421             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1422                 return false;
1423             }
1424             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1425                 return false;
1426             }
1427             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1428                 return false;
1429             }
1430             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1431             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1432                 return false;
1433             }
1434             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1435                 return false;
1436             }
1437             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1438             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1439             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1440             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1441             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1442             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1443             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1444             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1445             jklm.addProteinDomain( j );
1446             jklm.addProteinDomain( k );
1447             jklm.addProteinDomain( l );
1448             jklm.addProteinDomain( m );
1449             jklm.addProteinDomain( m0 );
1450             jklm.addProteinDomain( m1 );
1451             jklm.addProteinDomain( m2 );
1452             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1453             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1454                 return false;
1455             }
1456             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1457                 return false;
1458             }
1459             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1460                 return false;
1461             }
1462             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1463             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1464                 return false;
1465             }
1466             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1467                 return false;
1468             }
1469             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1470             final Protein od = new BasicProtein( "od", "varanus", 0 );
1471             od.addProteinDomain( only );
1472             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1473             if ( od.getNumberOfProteinDomains() != 1 ) {
1474                 return false;
1475             }
1476             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1477                 return false;
1478             }
1479         }
1480         catch ( final Exception e ) {
1481             e.printStackTrace( System.out );
1482             return false;
1483         }
1484         return true;
1485     }
1486
1487     private static final boolean testPfamTreeReading() {
1488         try {
1489             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1490             final NHXParser parser = new NHXParser();
1491             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1492             parser.setReplaceUnderscores( false );
1493             parser.setGuessRootedness( true );
1494             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1495             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1496                 return false;
1497             }
1498             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1499                 return false;
1500             }
1501         }
1502         catch ( final Exception e ) {
1503             e.printStackTrace();
1504             return false;
1505         }
1506         return true;
1507     }
1508
1509     private static final boolean testPhyloXMLparsingFromURL() {
1510         try {
1511             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1512             final URL u = new URL( s );
1513             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1514             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1515                 return false;
1516             }
1517             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1518             if ( ( phys2 == null ) || ( phys2.length != 2 ) ) {
1519                 return false;
1520             }
1521         }
1522         catch ( final Exception e ) {
1523             e.printStackTrace();
1524             return false;
1525         }
1526         return true;
1527     }
1528
1529     private static final boolean testToLReading() {
1530         try {
1531             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1532             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, new TolParser() );
1533             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1534                 return false;
1535             }
1536             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1537                 return false;
1538             }
1539             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName()
1540                     .equals( "Protacanthopterygii" ) ) {
1541                 return false;
1542             }
1543             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1544                 return false;
1545             }
1546             //
1547             final URL u2 = new URL( WebserviceUtil.TOL_URL_BASE + "17706" );
1548             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, new TolParser() );
1549             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
1550                 return false;
1551             }
1552             if ( !phys2[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "17706" ) ) {
1553                 return false;
1554             }
1555             if ( phys2[ 0 ].getNumberOfExternalNodes() < 5 ) {
1556                 return false;
1557             }
1558         }
1559         catch ( final Exception e ) {
1560             e.printStackTrace();
1561             return false;
1562         }
1563         return true;
1564     }
1565
1566     private static final boolean testTreeBaseReading() {
1567         try {
1568             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "72557?format=nexus" );
1569             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1570             parser.setReplaceUnderscores( true );
1571             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1572             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1573                 return false;
1574             }
1575             final URL u_1 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2406?format=nexus" );
1576             final NexusPhylogeniesParser parser_1 = new NexusPhylogeniesParser();
1577             final Phylogeny[] phys_1 = ForesterUtil.readPhylogeniesFromUrl( u_1, parser_1 );
1578             if ( ( phys_1 == null ) || ( phys_1.length != 1 ) ) {
1579                 return false;
1580             }
1581             final URL u_2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "422?format=nexus" );
1582             final NexusPhylogeniesParser parser_2 = new NexusPhylogeniesParser();
1583             final Phylogeny[] phys_2 = ForesterUtil.readPhylogeniesFromUrl( u_2, parser_2 );
1584             if ( ( phys_2 == null ) || ( phys_2.length != 1 ) ) {
1585                 return false;
1586             }
1587             final URL u_3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2654?format=nexus" );
1588             final NexusPhylogeniesParser parser_3 = new NexusPhylogeniesParser();
1589             final Phylogeny[] phys_3 = ForesterUtil.readPhylogeniesFromUrl( u_3, parser_3 );
1590             if ( ( phys_3 == null ) || ( phys_3.length != 1 ) ) {
1591                 return false;
1592             }
1593             final URL u_4 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1594             final NexusPhylogeniesParser parser_4 = new NexusPhylogeniesParser();
1595             final Phylogeny[] phys_4 = ForesterUtil.readPhylogeniesFromUrl( u_4, parser_4 );
1596             if ( ( phys_4 == null ) || ( phys_4.length != 1 ) ) {
1597                 return false;
1598             }
1599             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1600             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1601             parser2.setReplaceUnderscores( true );
1602             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, parser2 );
1603             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1604                 return false;
1605             }
1606             final URL u3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14909?format=nexus" );
1607             final NexusPhylogeniesParser parser3 = new NexusPhylogeniesParser();
1608             final Phylogeny[] phys3 = ForesterUtil.readPhylogeniesFromUrl( u3, parser3 );
1609             if ( ( phys3 == null ) || ( phys3.length != 2 ) ) {
1610                 return false;
1611             }
1612             final Phylogeny[] phys4 = ForesterUtil.readPhylogeniesFromUrl(
1613                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1614                                                                                    + "14525?format=nexus" ),
1615                                                                            new NexusPhylogeniesParser() );
1616             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1617                 return false;
1618             }
1619             final Phylogeny[] phys5 = ForesterUtil.readPhylogeniesFromUrl(
1620                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1621                                                                                    + "15632?format=nexus" ),
1622                                                                            new NexusPhylogeniesParser() );
1623             if ( ( phys5 == null ) || ( phys5.length != 1 ) ) {
1624                 return false;
1625             }
1626             final Phylogeny[] phys6 = ForesterUtil.readPhylogeniesFromUrl(
1627                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1628                                                                                    + "10190?format=nexus" ),
1629                                                                            new NexusPhylogeniesParser() );
1630             if ( ( phys6 == null ) || ( phys6.length != 1 ) ) {
1631                 return false;
1632             }
1633             final Phylogeny[] phys7 = ForesterUtil.readPhylogeniesFromUrl(
1634                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1635                                                                                    + "13246?format=nexus" ),
1636                                                                            new NexusPhylogeniesParser() );
1637             if ( ( phys7 == null ) || ( phys7.length != 2 ) ) {
1638                 return false;
1639             }
1640             final Phylogeny[] phys8 = ForesterUtil.readPhylogeniesFromUrl(
1641                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1642                                                                                    + "11662?format=nexus" ),
1643                                                                            new NexusPhylogeniesParser() );
1644             if ( ( phys8 == null ) || ( phys8.length != 2 ) ) {
1645                 return false;
1646             }
1647             final Phylogeny[] phys9 = ForesterUtil.readPhylogeniesFromUrl(
1648                                                                            new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1649                                                                                    + "562?format=nexus" ),
1650                                                                            new NexusPhylogeniesParser() );
1651             if ( ( phys9 == null ) || ( phys9.length != 4 ) ) {
1652                 return false;
1653             }
1654             final Phylogeny[] phys16424 = ForesterUtil.readPhylogeniesFromUrl(
1655                                                                                new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1656                                                                                        + "16424?format=nexus" ),
1657                                                                                new NexusPhylogeniesParser() );
1658             if ( ( phys16424 == null ) || ( phys16424.length != 1 ) ) {
1659                 return false;
1660             }
1661             final Phylogeny[] phys17878 = ForesterUtil.readPhylogeniesFromUrl(
1662                                                                                new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1663                                                                                        + "17878?format=nexus" ),
1664                                                                                new NexusPhylogeniesParser() );
1665             if ( ( phys17878 == null ) || ( phys17878.length != 17 ) ) {
1666                 return false;
1667             }
1668             final Phylogeny[] phys18804 = ForesterUtil.readPhylogeniesFromUrl(
1669                                                                                new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1670                                                                                        + "18804?format=nexus" ),
1671                                                                                new NexusPhylogeniesParser() );
1672             if ( ( phys18804 == null ) || ( phys18804.length != 2 ) ) {
1673                 return false;
1674             }
1675             final Phylogeny[] phys346 = ForesterUtil.readPhylogeniesFromUrl(
1676                                                                              new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE
1677                                                                                      + "346?format=nexus" ),
1678                                                                              new NexusPhylogeniesParser() );
1679             if ( ( phys346 == null ) || ( phys346.length != 1 ) ) {
1680                 return false;
1681             }
1682         }
1683         catch ( final Exception e ) {
1684             e.printStackTrace();
1685             return false;
1686         }
1687         return true;
1688     }
1689
1690     private static final boolean testTreeFamReading() {
1691         try {
1692             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1693             final NHXParser parser = new NHXParser();
1694             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1695             parser.setReplaceUnderscores( false );
1696             parser.setGuessRootedness( true );
1697             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1698             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1699                 return false;
1700             }
1701             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1702                 return false;
1703             }
1704         }
1705         catch ( final Exception e ) {
1706             e.printStackTrace();
1707             return false;
1708         }
1709         return true;
1710     }
1711
1712     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1713         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1714         return p;
1715     }
1716
1717     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1718         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1719     }
1720
1721     private static boolean testAminoAcidSequence() {
1722         try {
1723             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1724             if ( aa1.getLength() != 13 ) {
1725                 return false;
1726             }
1727             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1728                 return false;
1729             }
1730             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1731                 return false;
1732             }
1733             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1734                 return false;
1735             }
1736             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1737             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1738                 return false;
1739             }
1740             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1741             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1742                 return false;
1743             }
1744             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1745             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1746                 return false;
1747             }
1748         }
1749         catch ( final Exception e ) {
1750             e.printStackTrace();
1751             return false;
1752         }
1753         return true;
1754     }
1755
1756     private static boolean testBasicDomain() {
1757         try {
1758             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1759             if ( !pd.getDomainId().equals( "id" ) ) {
1760                 return false;
1761             }
1762             if ( pd.getNumber() != 1 ) {
1763                 return false;
1764             }
1765             if ( pd.getTotalCount() != 4 ) {
1766                 return false;
1767             }
1768             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1769                 return false;
1770             }
1771             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1772             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1773             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1774             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1775             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1776             if ( !a1.equals( a1 ) ) {
1777                 return false;
1778             }
1779             if ( !a1.equals( a1_copy ) ) {
1780                 return false;
1781             }
1782             if ( !a1.equals( a1_equal ) ) {
1783                 return false;
1784             }
1785             if ( !a1.equals( a2 ) ) {
1786                 return false;
1787             }
1788             if ( a1.equals( a3 ) ) {
1789                 return false;
1790             }
1791             if ( a1.compareTo( a1 ) != 0 ) {
1792                 return false;
1793             }
1794             if ( a1.compareTo( a1_copy ) != 0 ) {
1795                 return false;
1796             }
1797             if ( a1.compareTo( a1_equal ) != 0 ) {
1798                 return false;
1799             }
1800             if ( a1.compareTo( a2 ) != 0 ) {
1801                 return false;
1802             }
1803             if ( a1.compareTo( a3 ) == 0 ) {
1804                 return false;
1805             }
1806         }
1807         catch ( final Exception e ) {
1808             e.printStackTrace( System.out );
1809             return false;
1810         }
1811         return true;
1812     }
1813
1814     private static boolean testBasicNodeMethods() {
1815         try {
1816             if ( PhylogenyNode.getNodeCount() != 0 ) {
1817                 return false;
1818             }
1819             final PhylogenyNode n1 = new PhylogenyNode();
1820             final PhylogenyNode n2 = PhylogenyNode
1821                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1822             final PhylogenyNode n3 = PhylogenyNode
1823                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1824             final PhylogenyNode n4 = PhylogenyNode
1825                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1826             if ( n1.isHasAssignedEvent() ) {
1827                 return false;
1828             }
1829             if ( PhylogenyNode.getNodeCount() != 4 ) {
1830                 return false;
1831             }
1832             if ( n3.getIndicator() != 0 ) {
1833                 return false;
1834             }
1835             if ( n3.getNumberOfExternalNodes() != 1 ) {
1836                 return false;
1837             }
1838             if ( !n3.isExternal() ) {
1839                 return false;
1840             }
1841             if ( !n3.isRoot() ) {
1842                 return false;
1843             }
1844             if ( !n4.getName().equals( "n4" ) ) {
1845                 return false;
1846             }
1847         }
1848         catch ( final Exception e ) {
1849             e.printStackTrace( System.out );
1850             return false;
1851         }
1852         return true;
1853     }
1854
1855     private static boolean testUTF8ParsingFromFile() {
1856         try {
1857             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1858             final Phylogeny[] phylogenies_xml = ParserBasedPhylogenyFactory.getInstance()
1859                     .create( new File( Test.PATH_TO_TEST_DATA + "chars.xml" ), xml_parser );
1860             if ( xml_parser.getErrorCount() > 0 ) {
1861                 System.out.println( xml_parser.getErrorMessages().toString() );
1862                 return false;
1863             }
1864             if ( phylogenies_xml.length != 1 ) {
1865                 return false;
1866             }
1867             final Phylogeny[] phylogenies_xml2 = ParserBasedPhylogenyFactory.getInstance()
1868                     .create( new StringBuffer( phylogenies_xml[ 0 ].toPhyloXML( 0 ) ), xml_parser );
1869             final Phylogeny[] phylogenies_nh = ParserBasedPhylogenyFactory.getInstance()
1870                     .create( new File( Test.PATH_TO_TEST_DATA + "chars.nh" ), new NHXParser() );
1871             if ( phylogenies_nh.length != 1 ) {
1872                 return false;
1873             }
1874             final Phylogeny[] phylogenies_nex = ParserBasedPhylogenyFactory.getInstance()
1875                     .create( new File( Test.PATH_TO_TEST_DATA + "chars.nex" ), new NexusPhylogeniesParser() );
1876             if ( phylogenies_nex.length != 1 ) {
1877                 return false;
1878             }
1879             final String[] xml_n = phylogenies_xml[ 0 ].getAllExternalNodeNames();
1880             final String[] xml_n2 = phylogenies_xml2[ 0 ].getAllExternalNodeNames();
1881             final String[] nh_n = phylogenies_nh[ 0 ].getAllExternalNodeNames();
1882             final String[] nex_n = phylogenies_nex[ 0 ].getAllExternalNodeNames();
1883             final String n0 = "AQ~!@#$%^&*()_+-=\\{}|;:\"<>?,./";
1884             final String n1 = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ";
1885             final String n2 = "漢字ひらがなカタカナ";
1886             final String n3 = "อักษรไทย";
1887             final String n4 = "繁體字";
1888             final String n5 = "한글";
1889             final String n6 = "देवनागरी";
1890             final String n7 = "chữ Quốc ngữ";
1891             final String n8 = "ру́сский язы́к";
1892             final String n9 = "អក្សរខ្មែរ";
1893             if ( !xml_n[ 0 ].equals( n0 ) ) {
1894                 System.out.println( xml_n[ 0 ] );
1895                 System.out.println( n0 );
1896                 return false;
1897             }
1898             if ( !xml_n2[ 0 ].equals( n0 ) ) {
1899                 System.out.println( xml_n2[ 0 ] );
1900                 System.out.println( n0 );
1901                 return false;
1902             }
1903             if ( !nh_n[ 0 ].equals( n0 ) ) {
1904                 System.out.println( nh_n[ 0 ] );
1905                 System.out.println( n0 );
1906                 return false;
1907             }
1908             if ( !nex_n[ 0 ].equals( n0 ) ) {
1909                 System.out.println( nex_n[ 0 ] );
1910                 System.out.println( n0 );
1911                 return false;
1912             }
1913             if ( !xml_n[ 1 ].equals( n1 ) ) {
1914                 System.out.println( xml_n[ 1 ] );
1915                 System.out.println( n1 );
1916                 return false;
1917             }
1918             if ( !xml_n2[ 1 ].equals( n1 ) ) {
1919                 System.out.println( xml_n2[ 1 ] );
1920                 System.out.println( n1 );
1921                 return false;
1922             }
1923             if ( !nh_n[ 1 ].equals( n1 ) ) {
1924                 System.out.println( nh_n[ 1 ] );
1925                 System.out.println( n1 );
1926                 return false;
1927             }
1928             if ( !nex_n[ 1 ].equals( n1 ) ) {
1929                 System.out.println( nex_n[ 1 ] );
1930                 System.out.println( n1 );
1931                 return false;
1932             }
1933             if ( !xml_n[ 2 ].equals( n2 ) ) {
1934                 System.out.println( xml_n[ 2 ] );
1935                 System.out.println( n2 );
1936                 return false;
1937             }
1938             if ( !xml_n2[ 2 ].equals( n2 ) ) {
1939                 System.out.println( xml_n2[ 2 ] );
1940                 System.out.println( n2 );
1941                 return false;
1942             }
1943             if ( !nh_n[ 2 ].equals( n2 ) ) {
1944                 System.out.println( nh_n[ 2 ] );
1945                 System.out.println( n2 );
1946                 return false;
1947             }
1948             if ( !nex_n[ 2 ].equals( n2 ) ) {
1949                 System.out.println( nex_n[ 2 ] );
1950                 System.out.println( n2 );
1951                 return false;
1952             }
1953             //
1954             if ( !xml_n[ 3 ].equals( n3 ) ) {
1955                 System.out.println( xml_n[ 3 ] );
1956                 System.out.println( n3 );
1957                 return false;
1958             }
1959             if ( !xml_n2[ 3 ].equals( n3 ) ) {
1960                 System.out.println( xml_n2[ 3 ] );
1961                 System.out.println( n3 );
1962                 return false;
1963             }
1964             if ( !nh_n[ 3 ].equals( n3 ) ) {
1965                 System.out.println( nh_n[ 3 ] );
1966                 System.out.println( n3 );
1967                 return false;
1968             }
1969             if ( !nex_n[ 3 ].equals( n3 ) ) {
1970                 System.out.println( nex_n[ 3 ] );
1971                 System.out.println( n3 );
1972                 return false;
1973             }
1974             //
1975             if ( !xml_n[ 4 ].equals( n4 ) ) {
1976                 System.out.println( xml_n[ 4 ] );
1977                 System.out.println( n4 );
1978                 return false;
1979             }
1980             if ( !nh_n[ 4 ].equals( n4 ) ) {
1981                 System.out.println( nh_n[ 4 ] );
1982                 System.out.println( n4 );
1983                 return false;
1984             }
1985             if ( !nex_n[ 4 ].equals( n4 ) ) {
1986                 System.out.println( nex_n[ 4 ] );
1987                 System.out.println( n4 );
1988                 return false;
1989             }
1990             //
1991             if ( !xml_n[ 5 ].equals( n5 ) ) {
1992                 System.out.println( xml_n[ 5 ] );
1993                 System.out.println( n5 );
1994                 return false;
1995             }
1996             if ( !nh_n[ 5 ].equals( n5 ) ) {
1997                 System.out.println( nh_n[ 5 ] );
1998                 System.out.println( n5 );
1999                 return false;
2000             }
2001             if ( !nex_n[ 5 ].equals( n5 ) ) {
2002                 System.out.println( nex_n[ 5 ] );
2003                 System.out.println( n5 );
2004                 return false;
2005             }
2006             //
2007             if ( !xml_n[ 6 ].equals( n6 ) ) {
2008                 System.out.println( xml_n[ 6 ] );
2009                 System.out.println( n6 );
2010                 return false;
2011             }
2012             if ( !nh_n[ 6 ].equals( n6 ) ) {
2013                 System.out.println( nh_n[ 6 ] );
2014                 System.out.println( n6 );
2015                 return false;
2016             }
2017             if ( !nex_n[ 6 ].equals( n6 ) ) {
2018                 System.out.println( nex_n[ 6 ] );
2019                 System.out.println( n6 );
2020                 return false;
2021             }
2022             //
2023             if ( !xml_n[ 7 ].equals( n7 ) ) {
2024                 System.out.println( xml_n[ 7 ] );
2025                 System.out.println( n7 );
2026                 return false;
2027             }
2028             if ( !nh_n[ 7 ].equals( n7 ) ) {
2029                 System.out.println( nh_n[ 7 ] );
2030                 System.out.println( n7 );
2031                 return false;
2032             }
2033             if ( !nex_n[ 7 ].equals( n7 ) ) {
2034                 System.out.println( nex_n[ 7 ] );
2035                 System.out.println( n7 );
2036                 return false;
2037             }
2038             if ( !xml_n[ 8 ].equals( n8 ) ) {
2039                 System.out.println( xml_n[ 8 ] );
2040                 System.out.println( n8 );
2041                 return false;
2042             }
2043             if ( !nh_n[ 8 ].equals( n8 ) ) {
2044                 System.out.println( nh_n[ 8 ] );
2045                 System.out.println( n8 );
2046                 return false;
2047             }
2048             if ( !nex_n[ 8 ].equals( n8 ) ) {
2049                 System.out.println( nex_n[ 8 ] );
2050                 System.out.println( n8 );
2051                 return false;
2052             }
2053             if ( !xml_n[ 9 ].equals( n9 ) ) {
2054                 System.out.println( xml_n[ 9 ] );
2055                 System.out.println( n9 );
2056                 return false;
2057             }
2058             if ( !xml_n2[ 9 ].equals( n9 ) ) {
2059                 System.out.println( xml_n2[ 9 ] );
2060                 System.out.println( n9 );
2061                 return false;
2062             }
2063             if ( !nh_n[ 9 ].equals( n9 ) ) {
2064                 System.out.println( nh_n[ 9 ] );
2065                 System.out.println( n9 );
2066                 return false;
2067             }
2068             if ( !nex_n[ 9 ].equals( n9 ) ) {
2069                 System.out.println( nex_n[ 9 ] );
2070                 System.out.println( n9 );
2071                 return false;
2072             }
2073             if ( !phylogenies_xml[ 0 ].toNewHampshire().equals( phylogenies_nh[ 0 ].toNewHampshire() ) ) {
2074                 System.out.println( phylogenies_xml[ 0 ].toNewHampshire() );
2075                 System.out.println( phylogenies_nh[ 0 ].toNewHampshire() );
2076                 return false;
2077             }
2078             if ( !phylogenies_xml[ 0 ].toNewHampshire().equals( phylogenies_nex[ 0 ].toNewHampshire() ) ) {
2079                 System.out.println( phylogenies_xml[ 0 ].toNewHampshire() );
2080                 System.out.println( phylogenies_nex[ 0 ].toNewHampshire() );
2081                 return false;
2082             }
2083         }
2084         catch ( final Exception e ) {
2085             e.printStackTrace( System.out );
2086             return false;
2087         }
2088         return true;
2089     }
2090
2091     private static boolean testBasicPhyloXMLparsing() {
2092         try {
2093             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2094             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2095             final Phylogeny[] phylogenies_0 = factory
2096                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ), xml_parser );
2097             if ( xml_parser.getErrorCount() > 0 ) {
2098                 System.out.println( xml_parser.getErrorMessages().toString() );
2099                 return false;
2100             }
2101             if ( phylogenies_0.length != 4 ) {
2102                 return false;
2103             }
2104             final Phylogeny t1 = phylogenies_0[ 0 ];
2105             final Phylogeny t2 = phylogenies_0[ 1 ];
2106             final Phylogeny t3 = phylogenies_0[ 2 ];
2107             final Phylogeny t4 = phylogenies_0[ 3 ];
2108             if ( t1.getNumberOfExternalNodes() != 1 ) {
2109                 return false;
2110             }
2111             if ( !t1.isRooted() ) {
2112                 return false;
2113             }
2114             if ( t1.isRerootable() ) {
2115                 return false;
2116             }
2117             if ( !t1.getType().equals( "gene_tree" ) ) {
2118                 return false;
2119             }
2120             if ( t2.getNumberOfExternalNodes() != 2 ) {
2121                 return false;
2122             }
2123             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
2124                 return false;
2125             }
2126             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
2127                 return false;
2128             }
2129             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2130                 return false;
2131             }
2132             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2133                 return false;
2134             }
2135             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2136                 return false;
2137             }
2138             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2139                 return false;
2140             }
2141             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2142                     .startsWith( "actgtgggggt" ) ) {
2143                 return false;
2144             }
2145             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2146                     .startsWith( "ctgtgatgcat" ) ) {
2147                 return false;
2148             }
2149             if ( t3.getNumberOfExternalNodes() != 4 ) {
2150                 return false;
2151             }
2152             if ( !t1.getName().equals( "t1" ) ) {
2153                 return false;
2154             }
2155             if ( !t2.getName().equals( "t2" ) ) {
2156                 return false;
2157             }
2158             if ( !t3.getName().equals( "t3" ) ) {
2159                 return false;
2160             }
2161             if ( !t4.getName().equals( "t4" ) ) {
2162                 return false;
2163             }
2164             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
2165                 return false;
2166             }
2167             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
2168                 return false;
2169             }
2170             if ( !t3.getNode( "root node" ).isDuplication() ) {
2171                 return false;
2172             }
2173             if ( !t3.getNode( "node a" ).isDuplication() ) {
2174                 return false;
2175             }
2176             if ( t3.getNode( "node a" ).isSpeciation() ) {
2177                 return false;
2178             }
2179             if ( t3.getNode( "node bc" ).isDuplication() ) {
2180                 return false;
2181             }
2182             if ( !t3.getNode( "node bc" ).isSpeciation() ) {
2183                 return false;
2184             }
2185             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2186                 return false;
2187             }
2188             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
2189                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2190                 return false;
2191             }
2192             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2193                 return false;
2194             }
2195             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2196                 return false;
2197             }
2198             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2199                     .equals( "UniProtKB" ) ) {
2200                 return false;
2201             }
2202             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2203                     .equals( "apoptosis" ) ) {
2204                 return false;
2205             }
2206             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2207                     .equals( "GO:0006915" ) ) {
2208                 return false;
2209             }
2210             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2211                     .equals( "UniProtKB" ) ) {
2212                 return false;
2213             }
2214             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2215                     .equals( "experimental" ) ) {
2216                 return false;
2217             }
2218             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2219                     .equals( "function" ) ) {
2220                 return false;
2221             }
2222             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2223                     .getValue() != 1 ) {
2224                 return false;
2225             }
2226             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence().getType()
2227                     .equals( "ml" ) ) {
2228                 return false;
2229             }
2230             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2231                     .equals( "apoptosis" ) ) {
2232                 return false;
2233             }
2234             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2235                     .getProperties( "AFFY:expression" ).get( 0 ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2236                 return false;
2237             }
2238             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2239                     .getProperties( "AFFY:expression" ).get( 0 ).getDataType().equals( "xsd:double" ) ) {
2240                 return false;
2241             }
2242             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2243                     .getProperties( "AFFY:expression" ).get( 0 ).getRef().equals( "AFFY:expression" ) ) {
2244                 return false;
2245             }
2246             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2247                     .getProperties( "AFFY:expression" ).get( 0 ).getUnit().equals( "AFFY:x" ) ) {
2248                 return false;
2249             }
2250             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2251                     .getProperties( "AFFY:expression" ).get( 0 ).getValue().equals( "0.2" ) ) {
2252                 return false;
2253             }
2254             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2255                     .getProperties( "MED:disease" ).get( 0 ).getValue().equals( "lymphoma" ) ) {
2256                 return false;
2257             }
2258             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2259                     .equals( "GO:0005829" ) ) {
2260                 return false;
2261             }
2262             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2263                     .equals( "intracellular organelle" ) ) {
2264                 return false;
2265             }
2266             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2267                 return false;
2268             }
2269             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2270                     .equals( "UniProt link" ) ) ) {
2271                 return false;
2272             }
2273             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2274                 return false;
2275             }
2276             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
2277             if ( x.size() != 4 ) {
2278                 return false;
2279             }
2280             int c = 0;
2281             for( final Accession acc : x ) {
2282                 if ( c == 0 ) {
2283                     if ( !acc.getSource().equals( "KEGG" ) ) {
2284                         return false;
2285                     }
2286                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2287                         return false;
2288                     }
2289                 }
2290                 c++;
2291             }
2292         }
2293         catch ( final Exception e ) {
2294             e.printStackTrace( System.out );
2295             return false;
2296         }
2297         return true;
2298     }
2299
2300     private static boolean testBasicPhyloXMLparsingRoundtrip() {
2301         try {
2302             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2303             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2304             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2305                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2306             }
2307             else {
2308                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2309             }
2310             final Phylogeny[] phylogenies_0 = factory
2311                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ), xml_parser );
2312             if ( xml_parser.getErrorCount() > 0 ) {
2313                 System.out.println( xml_parser.getErrorMessages().toString() );
2314                 return false;
2315             }
2316             if ( phylogenies_0.length != 4 ) {
2317                 return false;
2318             }
2319             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
2320             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
2321             if ( phylogenies_t1.length != 1 ) {
2322                 return false;
2323             }
2324             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
2325             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
2326                 return false;
2327             }
2328             if ( !t1_rt.isRooted() ) {
2329                 return false;
2330             }
2331             if ( t1_rt.isRerootable() ) {
2332                 return false;
2333             }
2334             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
2335                 return false;
2336             }
2337             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
2338             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
2339             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
2340             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2341                 return false;
2342             }
2343             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2344                 return false;
2345             }
2346             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2347                 return false;
2348             }
2349             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2350                 return false;
2351             }
2352             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2353                     .startsWith( "actgtgggggt" ) ) {
2354                 return false;
2355             }
2356             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2357                     .startsWith( "ctgtgatgcat" ) ) {
2358                 return false;
2359             }
2360             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
2361             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
2362             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
2363             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
2364             if ( phylogenies_1.length != 1 ) {
2365                 return false;
2366             }
2367             final Phylogeny t3_rt = phylogenies_1[ 0 ];
2368             if ( !t3_rt.getName().equals( "t3" ) ) {
2369                 return false;
2370             }
2371             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
2372                 return false;
2373             }
2374             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
2375                 return false;
2376             }
2377             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
2378                 return false;
2379             }
2380             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2381                 return false;
2382             }
2383             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
2384                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2385                 return false;
2386             }
2387             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2388                 return false;
2389             }
2390             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue()
2391                     .equals( "Q9BZR8" ) ) {
2392                 return false;
2393             }
2394             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2395                     .equals( "UniProtKB" ) ) {
2396                 return false;
2397             }
2398             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2399                     .equals( "apoptosis" ) ) {
2400                 return false;
2401             }
2402             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2403                     .equals( "GO:0006915" ) ) {
2404                 return false;
2405             }
2406             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2407                     .equals( "UniProtKB" ) ) {
2408                 return false;
2409             }
2410             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2411                     .equals( "experimental" ) ) {
2412                 return false;
2413             }
2414             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2415                     .equals( "function" ) ) {
2416                 return false;
2417             }
2418             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2419                     .getValue() != 1 ) {
2420                 return false;
2421             }
2422             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2423                     .getType().equals( "ml" ) ) {
2424                 return false;
2425             }
2426             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2427                     .equals( "apoptosis" ) ) {
2428                 return false;
2429             }
2430             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2431                     .getProperties( "AFFY:expression" ).get( 0 ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2432                 return false;
2433             }
2434             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2435                     .getProperties( "AFFY:expression" ).get( 0 ).getDataType().equals( "xsd:double" ) ) {
2436                 return false;
2437             }
2438             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2439                     .getProperties( "AFFY:expression" ).get( 0 ).getRef().equals( "AFFY:expression" ) ) {
2440                 return false;
2441             }
2442             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2443                     .getProperties( "AFFY:expression" ).get( 0 ).getUnit().equals( "AFFY:x" ) ) {
2444                 return false;
2445             }
2446             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2447                     .getProperties( "AFFY:expression" ).get( 0 ).getValue().equals( "0.2" ) ) {
2448                 return false;
2449             }
2450             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2451                     .getProperties( "MED:disease" ).get( 0 ).getValue().equals( "lymphoma" ) ) {
2452                 return false;
2453             }
2454             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2455                     .equals( "GO:0005829" ) ) {
2456                 return false;
2457             }
2458             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2459                     .equals( "intracellular organelle" ) ) {
2460                 return false;
2461             }
2462             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType()
2463                     .equals( "source" ) ) ) {
2464                 return false;
2465             }
2466             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2467                     .equals( "UniProt link" ) ) ) {
2468                 return false;
2469             }
2470             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2471                 return false;
2472             }
2473             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi()
2474                     .equals( "10.1038/387489a0" ) ) ) {
2475                 return false;
2476             }
2477             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2478                     .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." ) ) ) {
2479                 System.out.println( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription() );
2480                 return false;
2481             }
2482             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2483                 return false;
2484             }
2485             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2486                 return false;
2487             }
2488             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName()
2489                     .equals( "molting animals" ) ) {
2490                 return false;
2491             }
2492             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2493                 return false;
2494             }
2495             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2496                     .equals( "ncbi" ) ) {
2497                 return false;
2498             }
2499             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture()
2500                     .getTotalLength() != 124 ) {
2501                 return false;
2502             }
2503             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2504                     .getName().equals( "B" ) ) {
2505                 return false;
2506             }
2507             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2508                     .getFrom() != 21 ) {
2509                 return false;
2510             }
2511             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2512                     .getTo() != 44 ) {
2513                 return false;
2514             }
2515             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2516                     .getLength() != 24 ) {
2517                 return false;
2518             }
2519             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2520                     .getConfidence() != 0 ) {
2521                 return false;
2522             }
2523             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2524                     .equals( "pfam" ) ) {
2525                 return false;
2526             }
2527             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2528                 return false;
2529             }
2530             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2531                 return false;
2532             }
2533             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2534                 return false;
2535             }
2536             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2537                 return false;
2538             }
2539             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2540             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2541                 return false;
2542             }
2543             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2544                 return false;
2545             }
2546             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2547                 return false;
2548             }
2549             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2550                 return false;
2551             }
2552             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2553                 return false;
2554             }
2555             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2556                 return false;
2557             }
2558             if ( taxbb.getSynonyms().size() != 2 ) {
2559                 return false;
2560             }
2561             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2562                 return false;
2563             }
2564             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2565                 return false;
2566             }
2567             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2568                 return false;
2569             }
2570             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2571                 return false;
2572             }
2573             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2574                 return false;
2575             }
2576             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2577                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2578                 return false;
2579             }
2580             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2581                 return false;
2582             }
2583             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2584                 return false;
2585             }
2586             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2587                 return false;
2588             }
2589             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2590                 return false;
2591             }
2592             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2593                 return false;
2594             }
2595             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2596                 return false;
2597             }
2598             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2599                 return false;
2600             }
2601             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2602                 return false;
2603             }
2604             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2605                     .equalsIgnoreCase( "435" ) ) {
2606                 return false;
2607             }
2608             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString()
2609                     .equalsIgnoreCase( "416" ) ) {
2610                 return false;
2611             }
2612             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2613                     .equalsIgnoreCase( "443.7" ) ) {
2614                 return false;
2615             }
2616             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2617                 return false;
2618             }
2619             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2620                 return false;
2621             }
2622             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2623                     .equalsIgnoreCase( "433" ) ) {
2624                 return false;
2625             }
2626             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2627                     .getCrossReferences();
2628             if ( x.size() != 4 ) {
2629                 return false;
2630             }
2631             int c = 0;
2632             for( final Accession acc : x ) {
2633                 if ( c == 0 ) {
2634                     if ( !acc.getSource().equals( "KEGG" ) ) {
2635                         return false;
2636                     }
2637                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2638                         return false;
2639                     }
2640                 }
2641                 c++;
2642             }
2643         }
2644         catch ( final Exception e ) {
2645             e.printStackTrace( System.out );
2646             return false;
2647         }
2648         return true;
2649     }
2650
2651     private static boolean testBasicPhyloXMLparsingValidating() {
2652         try {
2653             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2654             PhyloXmlParser xml_parser = null;
2655             try {
2656                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2657             }
2658             catch ( final Exception e ) {
2659                 // Do nothing -- means were not running from jar.
2660             }
2661             if ( xml_parser == null ) {
2662                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2663                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2664                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2665                 }
2666                 else {
2667                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2668                 }
2669             }
2670             final Phylogeny[] phylogenies_0 = factory
2671                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ), xml_parser );
2672             if ( xml_parser.getErrorCount() > 0 ) {
2673                 System.out.println( xml_parser.getErrorMessages().toString() );
2674                 return false;
2675             }
2676             if ( phylogenies_0.length != 4 ) {
2677                 return false;
2678             }
2679             final Phylogeny t1 = phylogenies_0[ 0 ];
2680             final Phylogeny t2 = phylogenies_0[ 1 ];
2681             final Phylogeny t3 = phylogenies_0[ 2 ];
2682             final Phylogeny t4 = phylogenies_0[ 3 ];
2683             if ( !t1.getName().equals( "t1" ) ) {
2684                 return false;
2685             }
2686             if ( !t2.getName().equals( "t2" ) ) {
2687                 return false;
2688             }
2689             if ( !t3.getName().equals( "t3" ) ) {
2690                 return false;
2691             }
2692             if ( !t4.getName().equals( "t4" ) ) {
2693                 return false;
2694             }
2695             if ( t1.getNumberOfExternalNodes() != 1 ) {
2696                 return false;
2697             }
2698             if ( t2.getNumberOfExternalNodes() != 2 ) {
2699                 return false;
2700             }
2701             if ( t3.getNumberOfExternalNodes() != 4 ) {
2702                 return false;
2703             }
2704             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2705             final Phylogeny[] phylogenies_1 = factory.create( new File( x2 ), xml_parser );
2706             if ( xml_parser.getErrorCount() > 0 ) {
2707                 System.out.println( "errors:" );
2708                 System.out.println( xml_parser.getErrorMessages().toString() );
2709                 return false;
2710             }
2711             if ( phylogenies_1.length != 4 ) {
2712                 return false;
2713             }
2714             final Phylogeny[] phylogenies_2 = factory
2715                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml" ), xml_parser );
2716             if ( xml_parser.getErrorCount() > 0 ) {
2717                 System.out.println( "errors:" );
2718                 System.out.println( xml_parser.getErrorMessages().toString() );
2719                 return false;
2720             }
2721             if ( phylogenies_2.length != 1 ) {
2722                 return false;
2723             }
2724             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2725                 return false;
2726             }
2727             final Phylogeny[] phylogenies_3 = factory
2728                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml" ), xml_parser );
2729             if ( xml_parser.getErrorCount() > 0 ) {
2730                 System.out.println( xml_parser.getErrorMessages().toString() );
2731                 return false;
2732             }
2733             if ( phylogenies_3.length != 2 ) {
2734                 return false;
2735             }
2736             final Phylogeny a = phylogenies_3[ 0 ];
2737             if ( !a.getName().equals( "tree 4" ) ) {
2738                 return false;
2739             }
2740             if ( a.getNumberOfExternalNodes() != 3 ) {
2741                 return false;
2742             }
2743             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2744                 return false;
2745             }
2746             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2747                 return false;
2748             }
2749             final Phylogeny[] phylogenies_4 = factory
2750                     .create( new File( Test.PATH_TO_TEST_DATA + "special_characters.xml" ), xml_parser );
2751             if ( xml_parser.getErrorCount() > 0 ) {
2752                 System.out.println( xml_parser.getErrorMessages().toString() );
2753                 return false;
2754             }
2755             if ( phylogenies_4.length != 1 ) {
2756                 return false;
2757             }
2758             final Phylogeny s = phylogenies_4[ 0 ];
2759             if ( s.getNumberOfExternalNodes() != 6 ) {
2760                 return false;
2761             }
2762             s.getNode( "first" );
2763             s.getNode( "<>" );
2764             s.getNode( "\"<a'b&c'd\">\"" );
2765             s.getNode( "'''\"" );
2766             s.getNode( "\"\"\"" );
2767             s.getNode( "dick & doof" );
2768         }
2769         catch ( final Exception e ) {
2770             e.printStackTrace( System.out );
2771             return false;
2772         }
2773         return true;
2774     }
2775
2776     private static boolean testPhyloXMLparsingValidating() {
2777         try {
2778             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2779             PhyloXmlParser xml_parser = null;
2780             try {
2781                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2782             }
2783             catch ( final Exception e ) {
2784                 // Do nothing -- means were not running from jar.
2785             }
2786             if ( xml_parser == null ) {
2787                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2788                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2789                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2790                 }
2791                 else {
2792                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2793                 }
2794             }
2795             final Phylogeny[] phylogenies_0 = factory
2796                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_1.xml" ), xml_parser );
2797             if ( xml_parser.getErrorCount() > 0 ) {
2798                 System.out.println( xml_parser.getErrorMessages().toString() );
2799                 return false;
2800             }
2801             if ( phylogenies_0.length != 3 ) {
2802                 return false;
2803             }
2804         }
2805         catch ( final Exception e ) {
2806             e.printStackTrace( System.out );
2807             return false;
2808         }
2809         return true;
2810     }
2811
2812     private static boolean testBasicProtein() {
2813         try {
2814             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2815             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2816             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2817             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2818             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2819             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2820             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2821             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2822             p0.addProteinDomain( y );
2823             p0.addProteinDomain( e );
2824             p0.addProteinDomain( b );
2825             p0.addProteinDomain( c );
2826             p0.addProteinDomain( d );
2827             p0.addProteinDomain( a );
2828             p0.addProteinDomain( x );
2829             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2830                 return false;
2831             }
2832             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2833                 return false;
2834             }
2835             //
2836             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2837             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2838             aa0.addProteinDomain( a1 );
2839             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2840                 return false;
2841             }
2842             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2843                 return false;
2844             }
2845             //
2846             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2847             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2848             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2849             aa1.addProteinDomain( a11 );
2850             aa1.addProteinDomain( a12 );
2851             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2852                 return false;
2853             }
2854             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2855                 return false;
2856             }
2857             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2858             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2859                 return false;
2860             }
2861             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2862                 return false;
2863             }
2864             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2865                 return false;
2866             }
2867             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2868             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2869                 return false;
2870             }
2871             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2872                 return false;
2873             }
2874             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2875                 return false;
2876             }
2877             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2878                 return false;
2879             }
2880             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2881             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2882                 return false;
2883             }
2884             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2885                 return false;
2886             }
2887             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2888                 return false;
2889             }
2890             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2891                 return false;
2892             }
2893             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2894             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2895                 return false;
2896             }
2897             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2898                 return false;
2899             }
2900             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2901                 return false;
2902             }
2903             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2904                 return false;
2905             }
2906             //
2907             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2908             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2909             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2910             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2911             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2912             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2913             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2914             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2915             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2916             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2917             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2918             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2919             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2920             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2921             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2922             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2923             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2924             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2925             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2926             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2927             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2928             p00.addProteinDomain( y0 );
2929             p00.addProteinDomain( e0 );
2930             p00.addProteinDomain( b0 );
2931             p00.addProteinDomain( c0 );
2932             p00.addProteinDomain( d0 );
2933             p00.addProteinDomain( a0 );
2934             p00.addProteinDomain( x0 );
2935             p00.addProteinDomain( y1 );
2936             p00.addProteinDomain( y2 );
2937             p00.addProteinDomain( y3 );
2938             p00.addProteinDomain( e1 );
2939             p00.addProteinDomain( e2 );
2940             p00.addProteinDomain( e3 );
2941             p00.addProteinDomain( e4 );
2942             p00.addProteinDomain( e5 );
2943             p00.addProteinDomain( z0 );
2944             p00.addProteinDomain( z1 );
2945             p00.addProteinDomain( z2 );
2946             p00.addProteinDomain( zz0 );
2947             p00.addProteinDomain( zz1 );
2948             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2949                 return false;
2950             }
2951             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2952                 return false;
2953             }
2954             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2955                 return false;
2956             }
2957             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2958                 return false;
2959             }
2960             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" ) ) {
2961                 return false;
2962             }
2963             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2964             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2965             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2966             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2967             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2968             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2969             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2970             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2971             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2972             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2973             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2974             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2975             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2976             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2977             p.addProteinDomain( B15 );
2978             p.addProteinDomain( C50 );
2979             p.addProteinDomain( A60 );
2980             p.addProteinDomain( A30 );
2981             p.addProteinDomain( C70 );
2982             p.addProteinDomain( B35 );
2983             p.addProteinDomain( B40 );
2984             p.addProteinDomain( A0 );
2985             p.addProteinDomain( A10 );
2986             p.addProteinDomain( A20 );
2987             p.addProteinDomain( B25 );
2988             p.addProteinDomain( D80 );
2989             List<String> domains_ids = new ArrayList<String>();
2990             domains_ids.add( "A" );
2991             domains_ids.add( "B" );
2992             domains_ids.add( "C" );
2993             if ( !p.contains( domains_ids, false ) ) {
2994                 return false;
2995             }
2996             if ( !p.contains( domains_ids, true ) ) {
2997                 return false;
2998             }
2999             domains_ids.add( "X" );
3000             if ( p.contains( domains_ids, false ) ) {
3001                 return false;
3002             }
3003             if ( p.contains( domains_ids, true ) ) {
3004                 return false;
3005             }
3006             domains_ids = new ArrayList<String>();
3007             domains_ids.add( "A" );
3008             domains_ids.add( "C" );
3009             domains_ids.add( "D" );
3010             if ( !p.contains( domains_ids, false ) ) {
3011                 return false;
3012             }
3013             if ( !p.contains( domains_ids, true ) ) {
3014                 return false;
3015             }
3016             domains_ids = new ArrayList<String>();
3017             domains_ids.add( "A" );
3018             domains_ids.add( "D" );
3019             domains_ids.add( "C" );
3020             if ( !p.contains( domains_ids, false ) ) {
3021                 return false;
3022             }
3023             if ( p.contains( domains_ids, true ) ) {
3024                 return false;
3025             }
3026             domains_ids = new ArrayList<String>();
3027             domains_ids.add( "A" );
3028             domains_ids.add( "A" );
3029             domains_ids.add( "B" );
3030             if ( !p.contains( domains_ids, false ) ) {
3031                 return false;
3032             }
3033             if ( !p.contains( domains_ids, true ) ) {
3034                 return false;
3035             }
3036             domains_ids = new ArrayList<String>();
3037             domains_ids.add( "A" );
3038             domains_ids.add( "A" );
3039             domains_ids.add( "A" );
3040             domains_ids.add( "B" );
3041             domains_ids.add( "B" );
3042             if ( !p.contains( domains_ids, false ) ) {
3043                 return false;
3044             }
3045             if ( !p.contains( domains_ids, true ) ) {
3046                 return false;
3047             }
3048             domains_ids = new ArrayList<String>();
3049             domains_ids.add( "A" );
3050             domains_ids.add( "A" );
3051             domains_ids.add( "B" );
3052             domains_ids.add( "A" );
3053             domains_ids.add( "B" );
3054             domains_ids.add( "B" );
3055             domains_ids.add( "A" );
3056             domains_ids.add( "B" );
3057             domains_ids.add( "C" );
3058             domains_ids.add( "A" );
3059             domains_ids.add( "C" );
3060             domains_ids.add( "D" );
3061             if ( !p.contains( domains_ids, false ) ) {
3062                 return false;
3063             }
3064             if ( p.contains( domains_ids, true ) ) {
3065                 return false;
3066             }
3067         }
3068         catch ( final Exception e ) {
3069             e.printStackTrace( System.out );
3070             return false;
3071         }
3072         return true;
3073     }
3074
3075     private static boolean testBasicTable() {
3076         try {
3077             final BasicTable<String> t0 = new BasicTable<String>();
3078             if ( t0.getNumberOfColumns() != 0 ) {
3079                 return false;
3080             }
3081             if ( t0.getNumberOfRows() != 0 ) {
3082                 return false;
3083             }
3084             t0.setValue( 3, 2, "23" );
3085             t0.setValue( 10, 1, "error" );
3086             t0.setValue( 10, 1, "110" );
3087             t0.setValue( 9, 1, "19" );
3088             t0.setValue( 1, 10, "101" );
3089             t0.setValue( 10, 10, "1010" );
3090             t0.setValue( 100, 10, "10100" );
3091             t0.setValue( 0, 0, "00" );
3092             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3093                 return false;
3094             }
3095             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3096                 return false;
3097             }
3098             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3099                 return false;
3100             }
3101             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3102                 return false;
3103             }
3104             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3105                 return false;
3106             }
3107             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3108                 return false;
3109             }
3110             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3111                 return false;
3112             }
3113             if ( t0.getNumberOfColumns() != 101 ) {
3114                 return false;
3115             }
3116             if ( t0.getNumberOfRows() != 11 ) {
3117                 return false;
3118             }
3119             if ( t0.getValueAsString( 49, 4 ) != null ) {
3120                 return false;
3121             }
3122             final String l = ForesterUtil.getLineSeparator();
3123             final StringBuffer source = new StringBuffer();
3124             source.append( "" + l );
3125             source.append( "# 1 1 1 1 1 1 1 1" + l );
3126             source.append( " 00 01 02 03" + l );
3127             source.append( "   10 11 12 13  " + l );
3128             source.append( "20 21 22 23 " + l );
3129             source.append( "    30  31    32 33" + l );
3130             source.append( "40 41 42 43" + l );
3131             source.append( "  # 1 1 1 1 1 " + l );
3132             source.append( "50 51 52 53 54" + l );
3133             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
3134             if ( t1.getNumberOfColumns() != 5 ) {
3135                 return false;
3136             }
3137             if ( t1.getNumberOfRows() != 6 ) {
3138                 return false;
3139             }
3140             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
3141                 return false;
3142             }
3143             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
3144                 return false;
3145             }
3146             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
3147                 return false;
3148             }
3149             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
3150                 return false;
3151             }
3152             final StringBuffer source1 = new StringBuffer();
3153             source1.append( "" + l );
3154             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3155             source1.append( " 00; 01 ;02;03" + l );
3156             source1.append( "   10; 11; 12; 13  " + l );
3157             source1.append( "20; 21; 22; 23 " + l );
3158             source1.append( "    30;  31;    32; 33" + l );
3159             source1.append( "40;41;42;43" + l );
3160             source1.append( "  # 1 1 1 1 1 " + l );
3161             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
3162             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
3163             if ( t2.getNumberOfColumns() != 5 ) {
3164                 return false;
3165             }
3166             if ( t2.getNumberOfRows() != 6 ) {
3167                 return false;
3168             }
3169             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
3170                 return false;
3171             }
3172             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
3173                 return false;
3174             }
3175             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
3176                 return false;
3177             }
3178             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
3179                 return false;
3180             }
3181             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
3182                 return false;
3183             }
3184             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
3185                 return false;
3186             }
3187             final StringBuffer source2 = new StringBuffer();
3188             source2.append( "" + l );
3189             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3190             source2.append( " 00; 01 ;02;03" + l );
3191             source2.append( "   10; 11; 12; 13  " + l );
3192             source2.append( "20; 21; 22; 23 " + l );
3193             source2.append( "                     " + l );
3194             source2.append( "    30;  31;    32; 33" + l );
3195             source2.append( "40;41;42;43" + l );
3196             source2.append( "  comment: 1 1 1 1 1 " + l );
3197             source2.append( ";;;50  ;   52; 53;;54   " + l );
3198             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
3199                                                                         ';',
3200                                                                         false,
3201                                                                         false,
3202                                                                         "comment:",
3203                                                                         false );
3204             if ( tl.size() != 2 ) {
3205                 return false;
3206             }
3207             final BasicTable<String> t3 = tl.get( 0 );
3208             final BasicTable<String> t4 = tl.get( 1 );
3209             if ( t3.getNumberOfColumns() != 4 ) {
3210                 return false;
3211             }
3212             if ( t3.getNumberOfRows() != 3 ) {
3213                 return false;
3214             }
3215             if ( t4.getNumberOfColumns() != 4 ) {
3216                 return false;
3217             }
3218             if ( t4.getNumberOfRows() != 3 ) {
3219                 return false;
3220             }
3221             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
3222                 return false;
3223             }
3224             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
3225                 return false;
3226             }
3227         }
3228         catch ( final Exception e ) {
3229             e.printStackTrace( System.out );
3230             return false;
3231         }
3232         return true;
3233     }
3234
3235     private static boolean testBasicTolXMLparsing() {
3236         try {
3237             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3238             final TolParser parser = new TolParser();
3239             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
3240             if ( parser.getErrorCount() > 0 ) {
3241                 System.out.println( parser.getErrorMessages().toString() );
3242                 return false;
3243             }
3244             if ( phylogenies_0.length != 1 ) {
3245                 return false;
3246             }
3247             final Phylogeny t1 = phylogenies_0[ 0 ];
3248             if ( t1.getNumberOfExternalNodes() != 5 ) {
3249                 return false;
3250             }
3251             if ( !t1.isRooted() ) {
3252                 return false;
3253             }
3254             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
3255                 return false;
3256             }
3257             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
3258                 return false;
3259             }
3260             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3261                     .equals( "Rhombozoa" ) ) {
3262                 return false;
3263             }
3264             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
3265                 return false;
3266             }
3267             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
3268             if ( parser.getErrorCount() > 0 ) {
3269                 System.out.println( parser.getErrorMessages().toString() );
3270                 return false;
3271             }
3272             if ( phylogenies_1.length != 1 ) {
3273                 return false;
3274             }
3275             final Phylogeny t2 = phylogenies_1[ 0 ];
3276             if ( t2.getNumberOfExternalNodes() != 664 ) {
3277                 return false;
3278             }
3279             if ( !t2.isRooted() ) {
3280                 return false;
3281             }
3282             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
3283                 return false;
3284             }
3285             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
3286                 return false;
3287             }
3288             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3289                 return false;
3290             }
3291             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3292                 return false;
3293             }
3294             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3295                     .equals( "Aquificae" ) ) {
3296                 return false;
3297             }
3298             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3299                     .equals( "Aquifex" ) ) {
3300                 return false;
3301             }
3302             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
3303             if ( parser.getErrorCount() > 0 ) {
3304                 System.out.println( parser.getErrorMessages().toString() );
3305                 return false;
3306             }
3307             if ( phylogenies_2.length != 1 ) {
3308                 return false;
3309             }
3310             final Phylogeny t3 = phylogenies_2[ 0 ];
3311             if ( t3.getNumberOfExternalNodes() != 184 ) {
3312                 return false;
3313             }
3314             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
3315                 return false;
3316             }
3317             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
3318                 return false;
3319             }
3320             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
3321                 return false;
3322             }
3323             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
3324             if ( parser.getErrorCount() > 0 ) {
3325                 System.out.println( parser.getErrorMessages().toString() );
3326                 return false;
3327             }
3328             if ( phylogenies_3.length != 1 ) {
3329                 return false;
3330             }
3331             final Phylogeny t4 = phylogenies_3[ 0 ];
3332             if ( t4.getNumberOfExternalNodes() != 1 ) {
3333                 return false;
3334             }
3335             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
3336                 return false;
3337             }
3338             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
3339                 return false;
3340             }
3341             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
3342                 return false;
3343             }
3344             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
3345             if ( parser.getErrorCount() > 0 ) {
3346                 System.out.println( parser.getErrorMessages().toString() );
3347                 return false;
3348             }
3349             if ( phylogenies_4.length != 1 ) {
3350                 return false;
3351             }
3352             final Phylogeny t5 = phylogenies_4[ 0 ];
3353             if ( t5.getNumberOfExternalNodes() != 13 ) {
3354                 return false;
3355             }
3356             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
3357                 return false;
3358             }
3359             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
3360                 return false;
3361             }
3362             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
3363                 return false;
3364             }
3365         }
3366         catch ( final Exception e ) {
3367             e.printStackTrace( System.out );
3368             return false;
3369         }
3370         return true;
3371     }
3372
3373     private static boolean testBasicTreeMethods() {
3374         try {
3375             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3376             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
3377             if ( t2.getNumberOfExternalNodes() != 4 ) {
3378                 return false;
3379             }
3380             if ( t2.calculateHeight( false ) != 8.5 ) {
3381                 return false;
3382             }
3383             if ( !t2.isCompletelyBinary() ) {
3384                 return false;
3385             }
3386             if ( t2.isEmpty() ) {
3387                 return false;
3388             }
3389             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
3390             if ( t3.getNumberOfExternalNodes() != 5 ) {
3391                 return false;
3392             }
3393             if ( t3.calculateHeight( true ) != 11 ) {
3394                 return false;
3395             }
3396             if ( t3.isCompletelyBinary() ) {
3397                 return false;
3398             }
3399             final PhylogenyNode n = t3.getNode( "ABC" );
3400             final Phylogeny t4 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3,(F,G,H,I))",
3401                                                  new NHXParser() )[ 0 ];
3402             if ( t4.getNumberOfExternalNodes() != 9 ) {
3403                 return false;
3404             }
3405             if ( t4.calculateHeight( false ) != 11 ) {
3406                 return false;
3407             }
3408             if ( t4.isCompletelyBinary() ) {
3409                 return false;
3410             }
3411             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)" );
3412             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
3413             if ( t5.getNumberOfExternalNodes() != 8 ) {
3414                 return false;
3415             }
3416             if ( t5.calculateHeight( false ) != 15 ) {
3417                 return false;
3418             }
3419             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)" );
3420             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
3421             if ( t6.calculateHeight( true ) != 15 ) {
3422                 return false;
3423             }
3424             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)" );
3425             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
3426             if ( t7.calculateHeight( true ) != 15 ) {
3427                 return false;
3428             }
3429             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)" );
3430             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
3431             if ( t8.getNumberOfExternalNodes() != 10 ) {
3432                 return false;
3433             }
3434             if ( t8.calculateHeight( true ) != 15 ) {
3435                 return false;
3436             }
3437             final char[] a9 = new char[] { 'a' };
3438             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
3439             if ( t9.calculateHeight( true ) != 0 ) {
3440                 return false;
3441             }
3442             final char[] a10 = new char[] { 'a', ':', '6' };
3443             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
3444             if ( t10.calculateHeight( true ) != 6 ) {
3445                 return false;
3446             }
3447         }
3448         catch ( final Exception e ) {
3449             e.printStackTrace( System.out );
3450             return false;
3451         }
3452         return true;
3453     }
3454
3455     private static boolean testConfidenceAssessor() {
3456         try {
3457             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3458             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3459             final Phylogeny[] ev0 = factory.create(
3460                                                     "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3461                                                     new NHXParser() );
3462             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3463             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3464                 return false;
3465             }
3466             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3467                 return false;
3468             }
3469             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3470             final Phylogeny[] ev1 = factory.create(
3471                                                     "((((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)));",
3472                                                     new NHXParser() );
3473             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3474             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3475                 return false;
3476             }
3477             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3478                 return false;
3479             }
3480             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3481             final Phylogeny[] ev_b = factory.create(
3482                                                      "((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",
3483                                                      new NHXParser() );
3484             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3485             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3486                 return false;
3487             }
3488             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3489                 return false;
3490             }
3491             //
3492             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3493             final Phylogeny[] ev1x = factory.create(
3494                                                      "((((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)));",
3495                                                      new NHXParser() );
3496             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3497             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3498                 return false;
3499             }
3500             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3501                 return false;
3502             }
3503             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3504             final Phylogeny[] ev_bx = factory.create(
3505                                                       "((((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",
3506                                                       new NHXParser() );
3507             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3508             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3509                 return false;
3510             }
3511             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3512                 return false;
3513             }
3514             final Phylogeny[] t2 = factory.create(
3515                                                    "((((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);",
3516                                                    new NHXParser() );
3517             final Phylogeny[] ev2 = factory.create(
3518                                                     "((((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);",
3519                                                     new NHXParser() );
3520             for( final Phylogeny target : t2 ) {
3521                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3522             }
3523             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3524                                                  new NHXParser() )[ 0 ];
3525             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3526             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3527             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3528                 return false;
3529             }
3530             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3531                 return false;
3532             }
3533             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3534                 return false;
3535             }
3536         }
3537         catch ( final Exception e ) {
3538             e.printStackTrace();
3539             return false;
3540         }
3541         return true;
3542     }
3543
3544     private static boolean testCopyOfNodeData() {
3545         try {
3546             final PhylogenyNode n1 = PhylogenyNode
3547                     .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]" );
3548             final PhylogenyNode n2 = n1.copyNodeData();
3549             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3550                 return false;
3551             }
3552         }
3553         catch ( final Exception e ) {
3554             e.printStackTrace();
3555             return false;
3556         }
3557         return true;
3558     }
3559
3560     private static boolean testCreateBalancedPhylogeny() {
3561         try {
3562             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3563             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3564                 return false;
3565             }
3566             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3567                 return false;
3568             }
3569             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3570             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3571                 return false;
3572             }
3573             if ( p1.getNumberOfExternalNodes() != 100 ) {
3574                 return false;
3575             }
3576         }
3577         catch ( final Exception e ) {
3578             e.printStackTrace();
3579             return false;
3580         }
3581         return true;
3582     }
3583
3584     private static boolean testCreateUriForSeqWeb() {
3585         try {
3586             final PhylogenyNode n = new PhylogenyNode();
3587             n.setName( "tr|B3RJ64" );
3588             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3589                 return false;
3590             }
3591             n.setName( "B0LM41_HUMAN" );
3592             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3593                     .equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3594                 return false;
3595             }
3596             n.setName( "NP_001025424" );
3597             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3598                     .equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3599                 return false;
3600             }
3601             n.setName( "_NM_001030253-" );
3602             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3603                     .equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3604                 return false;
3605             }
3606             n.setName( "XM_002122186" );
3607             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null )
3608                     .equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3609                 return false;
3610             }
3611             n.setName( "dgh_AAA34956_gdg" );
3612             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3613                 return false;
3614             }
3615             n.setName( "AAA34956" );
3616             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3617                 return false;
3618             }
3619             n.setName( "GI:394892" );
3620             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3621                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3622                 return false;
3623             }
3624             n.setName( "gi_394892" );
3625             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3626                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3627                 return false;
3628             }
3629             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3630             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3631                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3632                 return false;
3633             }
3634             n.setName( "P12345" );
3635             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3636                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3637                 return false;
3638             }
3639             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3640             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3641                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3642                 return false;
3643             }
3644         }
3645         catch ( final Exception e ) {
3646             e.printStackTrace( System.out );
3647             return false;
3648         }
3649         return true;
3650     }
3651
3652     private static boolean testDataObjects() {
3653         try {
3654             final Confidence s0 = new Confidence();
3655             final Confidence s1 = new Confidence();
3656             if ( !s0.isEqual( s1 ) ) {
3657                 return false;
3658             }
3659             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3660             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3661             if ( s2.isEqual( s1 ) ) {
3662                 return false;
3663             }
3664             if ( !s2.isEqual( s3 ) ) {
3665                 return false;
3666             }
3667             final Confidence s4 = ( Confidence ) s3.copy();
3668             if ( !s4.isEqual( s3 ) ) {
3669                 return false;
3670             }
3671             s3.asSimpleText();
3672             s3.asText();
3673             // Taxonomy
3674             // ----------
3675             final Taxonomy t1 = new Taxonomy();
3676             final Taxonomy t2 = new Taxonomy();
3677             final Taxonomy t3 = new Taxonomy();
3678             final Taxonomy t4 = new Taxonomy();
3679             final Taxonomy t5 = new Taxonomy();
3680             t1.setIdentifier( new Identifier( "ecoli" ) );
3681             t1.setTaxonomyCode( "ECOLI" );
3682             t1.setScientificName( "E. coli" );
3683             t1.setCommonName( "coli" );
3684             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3685             if ( !t1.isEqual( t0 ) ) {
3686                 return false;
3687             }
3688             t2.setIdentifier( new Identifier( "ecoli" ) );
3689             t2.setTaxonomyCode( "OTHER" );
3690             t2.setScientificName( "what" );
3691             t2.setCommonName( "something" );
3692             if ( !t1.isEqual( t2 ) ) {
3693                 return false;
3694             }
3695             t2.setIdentifier( new Identifier( "nemve" ) );
3696             if ( t1.isEqual( t2 ) ) {
3697                 return false;
3698             }
3699             t1.setIdentifier( null );
3700             t3.setTaxonomyCode( "ECOLI" );
3701             t3.setScientificName( "what" );
3702             t3.setCommonName( "something" );
3703             if ( !t1.isEqual( t3 ) ) {
3704                 return false;
3705             }
3706             t1.setIdentifier( null );
3707             t1.setTaxonomyCode( "" );
3708             t4.setScientificName( "E. ColI" );
3709             t4.setCommonName( "something" );
3710             if ( !t1.isEqual( t4 ) ) {
3711                 return false;
3712             }
3713             t4.setScientificName( "B. subtilis" );
3714             t4.setCommonName( "something" );
3715             if ( t1.isEqual( t4 ) ) {
3716                 return false;
3717             }
3718             t1.setIdentifier( null );
3719             t1.setTaxonomyCode( "" );
3720             t1.setScientificName( "" );
3721             t5.setCommonName( "COLI" );
3722             if ( !t1.isEqual( t5 ) ) {
3723                 return false;
3724             }
3725             t5.setCommonName( "vibrio" );
3726             if ( t1.isEqual( t5 ) ) {
3727                 return false;
3728             }
3729             // Identifier
3730             // ----------
3731             final Identifier id0 = new Identifier( "123", "pfam" );
3732             final Identifier id1 = ( Identifier ) id0.copy();
3733             if ( !id1.isEqual( id1 ) ) {
3734                 return false;
3735             }
3736             if ( !id1.isEqual( id0 ) ) {
3737                 return false;
3738             }
3739             if ( !id0.isEqual( id1 ) ) {
3740                 return false;
3741             }
3742             id1.asSimpleText();
3743             id1.asText();
3744             // ProteinDomain
3745             // ---------------
3746             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3747             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3748             if ( !pd1.isEqual( pd1 ) ) {
3749                 return false;
3750             }
3751             if ( !pd1.isEqual( pd0 ) ) {
3752                 return false;
3753             }
3754             pd1.asSimpleText();
3755             pd1.asText();
3756             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3757             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3758             if ( !pd3.isEqual( pd3 ) ) {
3759                 return false;
3760             }
3761             if ( !pd2.isEqual( pd3 ) ) {
3762                 return false;
3763             }
3764             if ( !pd0.isEqual( pd3 ) ) {
3765                 return false;
3766             }
3767             pd3.asSimpleText();
3768             pd3.asText();
3769             // DomainArchitecture
3770             // ------------------
3771             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3772             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3773             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3774             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3775             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3776             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3777             domains0.add( d2 );
3778             domains0.add( d0 );
3779             domains0.add( d3 );
3780             domains0.add( d1 );
3781             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3782             if ( ds0.getNumberOfDomains() != 4 ) {
3783                 return false;
3784             }
3785             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3786             if ( !ds0.isEqual( ds0 ) ) {
3787                 return false;
3788             }
3789             if ( !ds0.isEqual( ds1 ) ) {
3790                 return false;
3791             }
3792             if ( ds1.getNumberOfDomains() != 4 ) {
3793                 return false;
3794             }
3795             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3796             domains1.add( d1 );
3797             domains1.add( d2 );
3798             domains1.add( d4 );
3799             domains1.add( d0 );
3800             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3801             if ( ds0.isEqual( ds2 ) ) {
3802                 return false;
3803             }
3804             ds1.asSimpleText();
3805             ds1.asText();
3806             ds1.toNHX();
3807             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3808             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3809                 System.out.println( ds3.toNHX() );
3810                 return false;
3811             }
3812             if ( ds3.getNumberOfDomains() != 3 ) {
3813                 return false;
3814             }
3815             // Event
3816             // -----
3817             final Event e1 = new Event( Event.EventType.fusion );
3818             if ( e1.isDuplication() ) {
3819                 return false;
3820             }
3821             if ( !e1.isFusion() ) {
3822                 return false;
3823             }
3824             if ( !e1.asText().toString().equals( "fusion" ) ) {
3825                 return false;
3826             }
3827             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3828                 return false;
3829             }
3830             final Event e11 = new Event( Event.EventType.fusion );
3831             if ( !e11.isEqual( e1 ) ) {
3832                 return false;
3833             }
3834             if ( !e11.toNHX().toString().equals( "" ) ) {
3835                 return false;
3836             }
3837             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3838             if ( e2.isDuplication() ) {
3839                 return false;
3840             }
3841             if ( !e2.isSpeciationOrDuplication() ) {
3842                 return false;
3843             }
3844             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3845                 return false;
3846             }
3847             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3848                 return false;
3849             }
3850             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3851                 return false;
3852             }
3853             if ( e11.isEqual( e2 ) ) {
3854                 return false;
3855             }
3856             final Event e2c = ( Event ) e2.copy();
3857             if ( !e2c.isEqual( e2 ) ) {
3858                 return false;
3859             }
3860             Event e3 = new Event( 1, 2, 3 );
3861             if ( e3.isDuplication() ) {
3862                 return false;
3863             }
3864             if ( e3.isSpeciation() ) {
3865                 return false;
3866             }
3867             if ( e3.isGeneLoss() ) {
3868                 return false;
3869             }
3870             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3871                 return false;
3872             }
3873             final Event e3c = ( Event ) e3.copy();
3874             final Event e3cc = ( Event ) e3c.copy();
3875             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3876                 return false;
3877             }
3878             e3 = null;
3879             if ( !e3c.isEqual( e3cc ) ) {
3880                 return false;
3881             }
3882             Event e4 = new Event( 1, 2, 3 );
3883             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3884                 return false;
3885             }
3886             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3887                 return false;
3888             }
3889             final Event e4c = ( Event ) e4.copy();
3890             e4 = null;
3891             final Event e4cc = ( Event ) e4c.copy();
3892             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3893                 return false;
3894             }
3895             if ( !e4c.isEqual( e4cc ) ) {
3896                 return false;
3897             }
3898             final Event e5 = new Event();
3899             if ( !e5.isUnassigned() ) {
3900                 return false;
3901             }
3902             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3903                 return false;
3904             }
3905             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3906                 return false;
3907             }
3908             final Event e6 = new Event( 1, 0, 0 );
3909             if ( !e6.asText().toString().equals( "duplication" ) ) {
3910                 return false;
3911             }
3912             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3913                 return false;
3914             }
3915             final Event e7 = new Event( 0, 1, 0 );
3916             if ( !e7.asText().toString().equals( "speciation" ) ) {
3917                 return false;
3918             }
3919             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3920                 return false;
3921             }
3922             final Event e8 = new Event( 0, 0, 1 );
3923             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3924                 return false;
3925             }
3926             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3927                 return false;
3928             }
3929         }
3930         catch ( final Exception e ) {
3931             e.printStackTrace( System.out );
3932             return false;
3933         }
3934         return true;
3935     }
3936
3937     private static boolean testDeletionOfExternalNodes() {
3938         try {
3939             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3940             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3941             final PhylogenyWriter w = new PhylogenyWriter();
3942             if ( t0.isEmpty() ) {
3943                 return false;
3944             }
3945             if ( t0.getNumberOfExternalNodes() != 1 ) {
3946                 return false;
3947             }
3948             t0.deleteSubtree( t0.getNode( "A" ), false );
3949             if ( t0.getNumberOfExternalNodes() != 0 ) {
3950                 return false;
3951             }
3952             if ( !t0.isEmpty() ) {
3953                 return false;
3954             }
3955             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3956             if ( t1.getNumberOfExternalNodes() != 2 ) {
3957                 return false;
3958             }
3959             t1.deleteSubtree( t1.getNode( "A" ), false );
3960             if ( t1.getNumberOfExternalNodes() != 1 ) {
3961                 return false;
3962             }
3963             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3964                 return false;
3965             }
3966             t1.deleteSubtree( t1.getNode( "B" ), false );
3967             if ( t1.getNumberOfExternalNodes() != 1 ) {
3968                 return false;
3969             }
3970             t1.deleteSubtree( t1.getNode( "r" ), false );
3971             if ( !t1.isEmpty() ) {
3972                 return false;
3973             }
3974             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3975             if ( t2.getNumberOfExternalNodes() != 3 ) {
3976                 return false;
3977             }
3978             t2.deleteSubtree( t2.getNode( "B" ), false );
3979             if ( t2.getNumberOfExternalNodes() != 2 ) {
3980                 return false;
3981             }
3982             t2.toNewHampshireX();
3983             PhylogenyNode n = t2.getNode( "A" );
3984             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3985                 return false;
3986             }
3987             t2.deleteSubtree( t2.getNode( "A" ), false );
3988             if ( t2.getNumberOfExternalNodes() != 2 ) {
3989                 return false;
3990             }
3991             t2.deleteSubtree( t2.getNode( "C" ), true );
3992             if ( t2.getNumberOfExternalNodes() != 1 ) {
3993                 return false;
3994             }
3995             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3996             if ( t3.getNumberOfExternalNodes() != 4 ) {
3997                 return false;
3998             }
3999             t3.deleteSubtree( t3.getNode( "B" ), true );
4000             if ( t3.getNumberOfExternalNodes() != 3 ) {
4001                 return false;
4002             }
4003             n = t3.getNode( "A" );
4004             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
4005                 return false;
4006             }
4007             n = n.getNextExternalNode();
4008             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
4009                 return false;
4010             }
4011             t3.deleteSubtree( t3.getNode( "A" ), true );
4012             if ( t3.getNumberOfExternalNodes() != 2 ) {
4013                 return false;
4014             }
4015             n = t3.getNode( "C" );
4016             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
4017                 return false;
4018             }
4019             t3.deleteSubtree( t3.getNode( "C" ), true );
4020             if ( t3.getNumberOfExternalNodes() != 1 ) {
4021                 return false;
4022             }
4023             t3.deleteSubtree( t3.getNode( "D" ), true );
4024             if ( t3.getNumberOfExternalNodes() != 0 ) {
4025                 return false;
4026             }
4027             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4028             if ( t4.getNumberOfExternalNodes() != 6 ) {
4029                 return false;
4030             }
4031             t4.deleteSubtree( t4.getNode( "B2" ), true );
4032             if ( t4.getNumberOfExternalNodes() != 5 ) {
4033                 return false;
4034             }
4035             String s = w.toNewHampshire( t4, true ).toString();
4036             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
4037                 return false;
4038             }
4039             t4.deleteSubtree( t4.getNode( "B11" ), true );
4040             if ( t4.getNumberOfExternalNodes() != 4 ) {
4041                 return false;
4042             }
4043             t4.deleteSubtree( t4.getNode( "C" ), true );
4044             if ( t4.getNumberOfExternalNodes() != 3 ) {
4045                 return false;
4046             }
4047             n = t4.getNode( "A" );
4048             n = n.getNextExternalNode();
4049             if ( !n.getName().equals( "B12" ) ) {
4050                 return false;
4051             }
4052             n = n.getNextExternalNode();
4053             if ( !n.getName().equals( "D" ) ) {
4054                 return false;
4055             }
4056             s = w.toNewHampshire( t4, true ).toString();
4057             if ( !s.equals( "((A,B12),D);" ) ) {
4058                 return false;
4059             }
4060             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4061             t5.deleteSubtree( t5.getNode( "A" ), true );
4062             if ( t5.getNumberOfExternalNodes() != 5 ) {
4063                 return false;
4064             }
4065             s = w.toNewHampshire( t5, true ).toString();
4066             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
4067                 return false;
4068             }
4069             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4070             t6.deleteSubtree( t6.getNode( "B11" ), true );
4071             if ( t6.getNumberOfExternalNodes() != 5 ) {
4072                 return false;
4073             }
4074             s = w.toNewHampshire( t6, false ).toString();
4075             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
4076                 return false;
4077             }
4078             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4079             t7.deleteSubtree( t7.getNode( "B12" ), true );
4080             if ( t7.getNumberOfExternalNodes() != 5 ) {
4081                 return false;
4082             }
4083             s = w.toNewHampshire( t7, true ).toString();
4084             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
4085                 return false;
4086             }
4087             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4088             t8.deleteSubtree( t8.getNode( "B2" ), true );
4089             if ( t8.getNumberOfExternalNodes() != 5 ) {
4090                 return false;
4091             }
4092             s = w.toNewHampshire( t8, false ).toString();
4093             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
4094                 return false;
4095             }
4096             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4097             t9.deleteSubtree( t9.getNode( "C" ), true );
4098             if ( t9.getNumberOfExternalNodes() != 5 ) {
4099                 return false;
4100             }
4101             s = w.toNewHampshire( t9, true ).toString();
4102             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
4103                 return false;
4104             }
4105             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4106             t10.deleteSubtree( t10.getNode( "D" ), true );
4107             if ( t10.getNumberOfExternalNodes() != 5 ) {
4108                 return false;
4109             }
4110             s = w.toNewHampshire( t10, true ).toString();
4111             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
4112                 return false;
4113             }
4114             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
4115             t11.deleteSubtree( t11.getNode( "A" ), true );
4116             if ( t11.getNumberOfExternalNodes() != 2 ) {
4117                 return false;
4118             }
4119             s = w.toNewHampshire( t11, true ).toString();
4120             if ( !s.equals( "(B,C);" ) ) {
4121                 return false;
4122             }
4123             t11.deleteSubtree( t11.getNode( "C" ), true );
4124             if ( t11.getNumberOfExternalNodes() != 1 ) {
4125                 return false;
4126             }
4127             s = w.toNewHampshire( t11, false ).toString();
4128             if ( !s.equals( "B;" ) ) {
4129                 return false;
4130             }
4131             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
4132             t12.deleteSubtree( t12.getNode( "B2" ), true );
4133             if ( t12.getNumberOfExternalNodes() != 8 ) {
4134                 return false;
4135             }
4136             s = w.toNewHampshire( t12, true ).toString();
4137             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
4138                 return false;
4139             }
4140             t12.deleteSubtree( t12.getNode( "B3" ), true );
4141             if ( t12.getNumberOfExternalNodes() != 7 ) {
4142                 return false;
4143             }
4144             s = w.toNewHampshire( t12, true ).toString();
4145             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
4146                 return false;
4147             }
4148             t12.deleteSubtree( t12.getNode( "C3" ), true );
4149             if ( t12.getNumberOfExternalNodes() != 6 ) {
4150                 return false;
4151             }
4152             s = w.toNewHampshire( t12, true ).toString();
4153             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
4154                 return false;
4155             }
4156             t12.deleteSubtree( t12.getNode( "A1" ), true );
4157             if ( t12.getNumberOfExternalNodes() != 5 ) {
4158                 return false;
4159             }
4160             s = w.toNewHampshire( t12, true ).toString();
4161             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
4162                 return false;
4163             }
4164             t12.deleteSubtree( t12.getNode( "B1" ), true );
4165             if ( t12.getNumberOfExternalNodes() != 4 ) {
4166                 return false;
4167             }
4168             s = w.toNewHampshire( t12, true ).toString();
4169             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
4170                 return false;
4171             }
4172             t12.deleteSubtree( t12.getNode( "A3" ), true );
4173             if ( t12.getNumberOfExternalNodes() != 3 ) {
4174                 return false;
4175             }
4176             s = w.toNewHampshire( t12, true ).toString();
4177             if ( !s.equals( "(A2,(C1,C2));" ) ) {
4178                 return false;
4179             }
4180             t12.deleteSubtree( t12.getNode( "A2" ), true );
4181             if ( t12.getNumberOfExternalNodes() != 2 ) {
4182                 return false;
4183             }
4184             s = w.toNewHampshire( t12, true ).toString();
4185             if ( !s.equals( "(C1,C2);" ) ) {
4186                 return false;
4187             }
4188             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
4189             t13.deleteSubtree( t13.getNode( "D" ), true );
4190             if ( t13.getNumberOfExternalNodes() != 4 ) {
4191                 return false;
4192             }
4193             s = w.toNewHampshire( t13, true ).toString();
4194             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
4195                 return false;
4196             }
4197             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
4198             t14.deleteSubtree( t14.getNode( "E" ), true );
4199             if ( t14.getNumberOfExternalNodes() != 5 ) {
4200                 return false;
4201             }
4202             s = w.toNewHampshire( t14, true ).toString();
4203             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
4204                 return false;
4205             }
4206             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
4207             t15.deleteSubtree( t15.getNode( "B2" ), true );
4208             if ( t15.getNumberOfExternalNodes() != 11 ) {
4209                 return false;
4210             }
4211             t15.deleteSubtree( t15.getNode( "B1" ), true );
4212             if ( t15.getNumberOfExternalNodes() != 10 ) {
4213                 return false;
4214             }
4215             t15.deleteSubtree( t15.getNode( "B3" ), true );
4216             if ( t15.getNumberOfExternalNodes() != 9 ) {
4217                 return false;
4218             }
4219             t15.deleteSubtree( t15.getNode( "B4" ), true );
4220             if ( t15.getNumberOfExternalNodes() != 8 ) {
4221                 return false;
4222             }
4223             t15.deleteSubtree( t15.getNode( "A1" ), true );
4224             if ( t15.getNumberOfExternalNodes() != 7 ) {
4225                 return false;
4226             }
4227             t15.deleteSubtree( t15.getNode( "C4" ), true );
4228             if ( t15.getNumberOfExternalNodes() != 6 ) {
4229                 return false;
4230             }
4231         }
4232         catch ( final Exception e ) {
4233             e.printStackTrace( System.out );
4234             return false;
4235         }
4236         return true;
4237     }
4238
4239     private static boolean testDescriptiveStatistics() {
4240         try {
4241             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
4242             dss1.addValue( 82 );
4243             dss1.addValue( 78 );
4244             dss1.addValue( 70 );
4245             dss1.addValue( 58 );
4246             dss1.addValue( 42 );
4247             if ( dss1.getN() != 5 ) {
4248                 return false;
4249             }
4250             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
4251                 return false;
4252             }
4253             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
4254                 return false;
4255             }
4256             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
4257                 return false;
4258             }
4259             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
4260                 return false;
4261             }
4262             if ( !Test.isEqual( dss1.median(), 70 ) ) {
4263                 return false;
4264             }
4265             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
4266                 return false;
4267             }
4268             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
4269                 return false;
4270             }
4271             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
4272                 return false;
4273             }
4274             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
4275                 return false;
4276             }
4277             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
4278                 return false;
4279             }
4280             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
4281                 return false;
4282             }
4283             dss1.addValue( 123 );
4284             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
4285                 return false;
4286             }
4287             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
4288                 return false;
4289             }
4290             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
4291                 return false;
4292             }
4293             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
4294             dss2.addValue( -1.85 );
4295             dss2.addValue( 57.5 );
4296             dss2.addValue( 92.78 );
4297             dss2.addValue( 57.78 );
4298             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
4299                 return false;
4300             }
4301             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
4302                 return false;
4303             }
4304             final double[] a = dss2.getDataAsDoubleArray();
4305             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
4306                 return false;
4307             }
4308             dss2.addValue( -100 );
4309             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
4310                 return false;
4311             }
4312             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
4313                 return false;
4314             }
4315             final double[] ds = new double[ 14 ];
4316             ds[ 0 ] = 34;
4317             ds[ 1 ] = 23;
4318             ds[ 2 ] = 1;
4319             ds[ 3 ] = 32;
4320             ds[ 4 ] = 11;
4321             ds[ 5 ] = 2;
4322             ds[ 6 ] = 12;
4323             ds[ 7 ] = 33;
4324             ds[ 8 ] = 13;
4325             ds[ 9 ] = 22;
4326             ds[ 10 ] = 21;
4327             ds[ 11 ] = 35;
4328             ds[ 12 ] = 24;
4329             ds[ 13 ] = 31;
4330             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
4331             if ( bins.length != 4 ) {
4332                 return false;
4333             }
4334             if ( bins[ 0 ] != 2 ) {
4335                 return false;
4336             }
4337             if ( bins[ 1 ] != 3 ) {
4338                 return false;
4339             }
4340             if ( bins[ 2 ] != 4 ) {
4341                 return false;
4342             }
4343             if ( bins[ 3 ] != 5 ) {
4344                 return false;
4345             }
4346             final double[] ds1 = new double[ 9 ];
4347             ds1[ 0 ] = 10.0;
4348             ds1[ 1 ] = 19.0;
4349             ds1[ 2 ] = 9.999;
4350             ds1[ 3 ] = 0.0;
4351             ds1[ 4 ] = 39.9;
4352             ds1[ 5 ] = 39.999;
4353             ds1[ 6 ] = 30.0;
4354             ds1[ 7 ] = 19.999;
4355             ds1[ 8 ] = 30.1;
4356             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
4357             if ( bins1.length != 4 ) {
4358                 return false;
4359             }
4360             if ( bins1[ 0 ] != 2 ) {
4361                 return false;
4362             }
4363             if ( bins1[ 1 ] != 3 ) {
4364                 return false;
4365             }
4366             if ( bins1[ 2 ] != 0 ) {
4367                 return false;
4368             }
4369             if ( bins1[ 3 ] != 4 ) {
4370                 return false;
4371             }
4372             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
4373             if ( bins1_1.length != 3 ) {
4374                 return false;
4375             }
4376             if ( bins1_1[ 0 ] != 3 ) {
4377                 return false;
4378             }
4379             if ( bins1_1[ 1 ] != 2 ) {
4380                 return false;
4381             }
4382             if ( bins1_1[ 2 ] != 4 ) {
4383                 return false;
4384             }
4385             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
4386             if ( bins1_2.length != 3 ) {
4387                 return false;
4388             }
4389             if ( bins1_2[ 0 ] != 2 ) {
4390                 return false;
4391             }
4392             if ( bins1_2[ 1 ] != 2 ) {
4393                 return false;
4394             }
4395             if ( bins1_2[ 2 ] != 2 ) {
4396                 return false;
4397             }
4398             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
4399             dss3.addValue( 1 );
4400             dss3.addValue( 1 );
4401             dss3.addValue( 1 );
4402             dss3.addValue( 2 );
4403             dss3.addValue( 3 );
4404             dss3.addValue( 4 );
4405             dss3.addValue( 5 );
4406             dss3.addValue( 5 );
4407             dss3.addValue( 5 );
4408             dss3.addValue( 6 );
4409             dss3.addValue( 7 );
4410             dss3.addValue( 8 );
4411             dss3.addValue( 9 );
4412             dss3.addValue( 10 );
4413             dss3.addValue( 10 );
4414             dss3.addValue( 10 );
4415             final AsciiHistogram histo = new AsciiHistogram( dss3 );
4416             histo.toStringBuffer( 10, '=', 40, 5 );
4417             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
4418         }
4419         catch ( final Exception e ) {
4420             e.printStackTrace( System.out );
4421             return false;
4422         }
4423         return true;
4424     }
4425
4426     private static boolean testDir( final String file ) {
4427         try {
4428             final File f = new File( file );
4429             if ( !f.exists() ) {
4430                 return false;
4431             }
4432             if ( !f.isDirectory() ) {
4433                 return false;
4434             }
4435             if ( !f.canRead() ) {
4436                 return false;
4437             }
4438         }
4439         catch ( final Exception e ) {
4440             return false;
4441         }
4442         return true;
4443     }
4444
4445     private static boolean testEbiEntryRetrieval() {
4446         try {
4447             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
4448             if ( !entry.getAccession().equals( "AAK41263" ) ) {
4449                 System.out.println( entry.getAccession() );
4450                 return false;
4451             }
4452             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
4453                 System.out.println( entry.getTaxonomyScientificName() );
4454                 return false;
4455             }
4456             if ( !entry.getSequenceName()
4457                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4458                 System.out.println( entry.getSequenceName() );
4459                 return false;
4460             }
4461             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4462                 System.out.println( entry.getGeneName() );
4463                 return false;
4464             }
4465             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4466                 System.out.println( entry.getTaxonomyIdentifier() );
4467                 return false;
4468             }
4469             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4470                 System.out.println( entry.getAnnotations().first().getRefValue() );
4471                 return false;
4472             }
4473             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4474                 System.out.println( entry.getAnnotations().first().getRefSource() );
4475                 return false;
4476             }
4477             if ( entry.getCrossReferences().size() < 1 ) {
4478                 return false;
4479             }
4480             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4481             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4482                 return false;
4483             }
4484             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4485                 System.out.println( entry1.getTaxonomyScientificName() );
4486                 return false;
4487             }
4488             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4489                 System.out.println( entry1.getSequenceName() );
4490                 return false;
4491             }
4492             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4493                 System.out.println( entry1.getTaxonomyIdentifier() );
4494                 return false;
4495             }
4496             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4497                 System.out.println( entry1.getGeneName() );
4498                 return false;
4499             }
4500             if ( entry1.getCrossReferences().size() < 1 ) {
4501                 return false;
4502             }
4503             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4504             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4505                 return false;
4506             }
4507             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4508                 System.out.println( entry2.getTaxonomyScientificName() );
4509                 return false;
4510             }
4511             if ( !entry2.getSequenceName()
4512                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4513                 System.out.println( entry2.getSequenceName() );
4514                 return false;
4515             }
4516             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4517                 System.out.println( entry2.getTaxonomyIdentifier() );
4518                 return false;
4519             }
4520             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4521                 System.out.println( entry2.getGeneName() );
4522                 return false;
4523             }
4524             if ( entry2.getCrossReferences().size() < 1 ) {
4525                 return false;
4526             }
4527             if ( !entry2.getChromosome().equals( "20" ) ) {
4528                 return false;
4529             }
4530             if ( !entry2.getMap().equals( "20q11.22" ) ) {
4531                 return false;
4532             }
4533             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4534             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4535                 return false;
4536             }
4537             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4538                 System.out.println( entry3.getTaxonomyScientificName() );
4539                 return false;
4540             }
4541             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4542                 System.out.println( entry3.getSequenceName() );
4543                 return false;
4544             }
4545             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4546                 System.out.println( entry3.getTaxonomyIdentifier() );
4547                 return false;
4548             }
4549             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4550                 System.out.println( entry3.getSequenceSymbol() );
4551                 return false;
4552             }
4553             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4554                 return false;
4555             }
4556             if ( entry3.getCrossReferences().size() < 1 ) {
4557                 return false;
4558             }
4559             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4560             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4561                 return false;
4562             }
4563             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4564                 System.out.println( entry4.getTaxonomyScientificName() );
4565                 return false;
4566             }
4567             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4568                 System.out.println( entry4.getSequenceName() );
4569                 return false;
4570             }
4571             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4572                 System.out.println( entry4.getTaxonomyIdentifier() );
4573                 return false;
4574             }
4575             if ( !entry4.getGeneName().equals( "ras" ) ) {
4576                 System.out.println( entry4.getGeneName() );
4577                 return false;
4578             }
4579             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4580             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4581                 return false;
4582             }
4583             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4584                 System.out.println( entry5.getTaxonomyScientificName() );
4585                 return false;
4586             }
4587             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4588                 System.out.println( entry5.getSequenceName() );
4589                 return false;
4590             }
4591             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4592                 System.out.println( entry5.getTaxonomyIdentifier() );
4593                 return false;
4594             }
4595             final SequenceDatabaseEntry entry6 = SequenceDbWsTools.obtainEntry( "M30539" );
4596             if ( !entry6.getAccession().equals( "M30539" ) ) {
4597                 return false;
4598             }
4599             if ( !entry6.getGeneName().equals( "ras" ) ) {
4600                 return false;
4601             }
4602             if ( !entry6.getSequenceName().equals( "Human SK2 c-Ha-ras-1 oncogene-encoded protein gene, exon 1" ) ) {
4603                 return false;
4604             }
4605             if ( !entry6.getTaxonomyIdentifier().equals( "9606" ) ) {
4606                 return false;
4607             }
4608             if ( !entry6.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4609                 return false;
4610             }
4611             if ( entry6.getCrossReferences().size() < 1 ) {
4612                 return false;
4613             }
4614         }
4615         catch ( final IOException e ) {
4616             System.out.println();
4617             System.out.println( "the following might be due to absence internet connection:" );
4618             e.printStackTrace( System.out );
4619             return true;
4620         }
4621         catch ( final Exception e ) {
4622             e.printStackTrace();
4623             return false;
4624         }
4625         return true;
4626     }
4627
4628     private static boolean testExternalNodeRelatedMethods() {
4629         try {
4630             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4631             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4632             PhylogenyNode n = t1.getNode( "A" );
4633             n = n.getNextExternalNode();
4634             if ( !n.getName().equals( "B" ) ) {
4635                 return false;
4636             }
4637             n = n.getNextExternalNode();
4638             if ( !n.getName().equals( "C" ) ) {
4639                 return false;
4640             }
4641             n = n.getNextExternalNode();
4642             if ( !n.getName().equals( "D" ) ) {
4643                 return false;
4644             }
4645             n = t1.getNode( "B" );
4646             while ( !n.isLastExternalNode() ) {
4647                 n = n.getNextExternalNode();
4648             }
4649             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4650             n = t2.getNode( "A" );
4651             n = n.getNextExternalNode();
4652             if ( !n.getName().equals( "B" ) ) {
4653                 return false;
4654             }
4655             n = n.getNextExternalNode();
4656             if ( !n.getName().equals( "C" ) ) {
4657                 return false;
4658             }
4659             n = n.getNextExternalNode();
4660             if ( !n.getName().equals( "D" ) ) {
4661                 return false;
4662             }
4663             n = t2.getNode( "B" );
4664             while ( !n.isLastExternalNode() ) {
4665                 n = n.getNextExternalNode();
4666             }
4667             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4668             n = t3.getNode( "A" );
4669             n = n.getNextExternalNode();
4670             if ( !n.getName().equals( "B" ) ) {
4671                 return false;
4672             }
4673             n = n.getNextExternalNode();
4674             if ( !n.getName().equals( "C" ) ) {
4675                 return false;
4676             }
4677             n = n.getNextExternalNode();
4678             if ( !n.getName().equals( "D" ) ) {
4679                 return false;
4680             }
4681             n = n.getNextExternalNode();
4682             if ( !n.getName().equals( "E" ) ) {
4683                 return false;
4684             }
4685             n = n.getNextExternalNode();
4686             if ( !n.getName().equals( "F" ) ) {
4687                 return false;
4688             }
4689             n = n.getNextExternalNode();
4690             if ( !n.getName().equals( "G" ) ) {
4691                 return false;
4692             }
4693             n = n.getNextExternalNode();
4694             if ( !n.getName().equals( "H" ) ) {
4695                 return false;
4696             }
4697             n = t3.getNode( "B" );
4698             while ( !n.isLastExternalNode() ) {
4699                 n = n.getNextExternalNode();
4700             }
4701             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4702             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4703                 final PhylogenyNode node = iter.next();
4704             }
4705             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4706             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4707                 final PhylogenyNode node = iter.next();
4708             }
4709             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))",
4710                                                  new NHXParser() )[ 0 ];
4711             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4712             if ( !iter.next().getName().equals( "A" ) ) {
4713                 return false;
4714             }
4715             if ( !iter.next().getName().equals( "B" ) ) {
4716                 return false;
4717             }
4718             if ( !iter.next().getName().equals( "C" ) ) {
4719                 return false;
4720             }
4721             if ( !iter.next().getName().equals( "D" ) ) {
4722                 return false;
4723             }
4724             if ( !iter.next().getName().equals( "E" ) ) {
4725                 return false;
4726             }
4727             if ( !iter.next().getName().equals( "F" ) ) {
4728                 return false;
4729             }
4730             if ( iter.hasNext() ) {
4731                 return false;
4732             }
4733         }
4734         catch ( final Exception e ) {
4735             e.printStackTrace( System.out );
4736             return false;
4737         }
4738         return true;
4739     }
4740
4741     private static boolean testExtractSNFromNodeName() {
4742         try {
4743             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4744                 return false;
4745             }
4746             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4747                 return false;
4748             }
4749             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4750                 return false;
4751             }
4752             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4753                     .equals( "Mus musculus musculus" ) ) {
4754                 return false;
4755             }
4756             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4757                     .equals( "Mus musculus musculus" ) ) {
4758                 return false;
4759             }
4760             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4761                     .equals( "Mus musculus musculus" ) ) {
4762                 return false;
4763             }
4764             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4765                     .equals( "Mus musculus musculus" ) ) {
4766                 return false;
4767             }
4768             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4769                 return false;
4770             }
4771             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4772                     .equals( "Mus musculus musculus" ) ) {
4773                 return false;
4774             }
4775             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4776                     .equals( "Mus musculus musculus" ) ) {
4777                 return false;
4778             }
4779             if ( ParserUtils
4780                     .extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4781                 return false;
4782             }
4783             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4784                 return false;
4785             }
4786             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4787                 return false;
4788             }
4789             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4790                 return false;
4791             }
4792             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4793                     .equals( "Mus musculus musculus" ) ) {
4794                 return false;
4795             }
4796             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4797                 return false;
4798             }
4799             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4800                 return false;
4801             }
4802             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4803                 return false;
4804             }
4805             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4806                 return false;
4807             }
4808             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4809                 return false;
4810             }
4811             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4812                 return false;
4813             }
4814             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4815                 return false;
4816             }
4817             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4818                 return false;
4819             }
4820             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4821                     .equals( "Mus musculus" ) ) {
4822                 return false;
4823             }
4824             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4825                     .equals( "Mus musculus" ) ) {
4826                 return false;
4827             }
4828             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4829                 return false;
4830             }
4831             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4832                     .equals( "Mus musculus musculus" ) ) {
4833                 return false;
4834             }
4835             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4836                     .equals( "Mus musculus musculus" ) ) {
4837                 return false;
4838             }
4839             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4840                     .equals( "Mus musculus musculus" ) ) {
4841                 return false;
4842             }
4843             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4844                 return false;
4845             }
4846             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4847                     .equals( "Pilostyles mexicana" ) ) {
4848                 return false;
4849             }
4850             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4851                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4852                 return false;
4853             }
4854             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4855                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4856                 return false;
4857             }
4858             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4859                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4860                 return false;
4861             }
4862             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4863                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4864                 return false;
4865             }
4866             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4867                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4868                 return false;
4869             }
4870             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4871                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4872                 return false;
4873             }
4874             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4875                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4876                 return false;
4877             }
4878             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4879                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4880                 return false;
4881             }
4882             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4883                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4884                 return false;
4885             }
4886             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4887                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4888                 return false;
4889             }
4890             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4891                     .equals( "Escherichia coli (strain K12)" ) ) {
4892                 return false;
4893             }
4894             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4895                     .equals( "Escherichia coli (strain K12)" ) ) {
4896                 return false;
4897             }
4898             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4899                     .equals( "Escherichia coli (str. K12)" ) ) {
4900                 return false;
4901             }
4902             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4903                     .equals( "Escherichia coli (str. K12)" ) ) {
4904                 return false;
4905             }
4906             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4907                     .equals( "Escherichia coli (str. K12)" ) ) {
4908                 return false;
4909             }
4910             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4911                     .equals( "Escherichia coli (var. K12)" ) ) {
4912                 return false;
4913             }
4914             if ( !ParserUtils.extractScientificNameFromNodeName( "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" )
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" )
4924                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4925                 return false;
4926             }
4927             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4928                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4929                 return false;
4930             }
4931             if ( !ParserUtils
4932                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4933                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4934                 return false;
4935             }
4936             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4937                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4938                 return false;
4939             }
4940             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4941                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4942                 return false;
4943             }
4944             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4945                 return false;
4946             }
4947             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4948                 return false;
4949             }
4950             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4951                 return false;
4952             }
4953             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4954                     .equals( "Macrocera sp." ) ) {
4955                 return false;
4956             }
4957             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4958                 return false;
4959             }
4960             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4961                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4962                 return false;
4963             }
4964             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4965                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4966                 return false;
4967             }
4968             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4969                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4970                 return false;
4971             }
4972             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4973                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4974                 return false;
4975             }
4976         }
4977         catch ( final Exception e ) {
4978             e.printStackTrace( System.out );
4979             return false;
4980         }
4981         return true;
4982     }
4983
4984     private static boolean testExtractTaxonomyDataFromNodeName() {
4985         try {
4986             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
4987             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4988                 return false;
4989             }
4990             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
4991             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4992                 return false;
4993             }
4994             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
4995             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4996                 return false;
4997             }
4998             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
4999             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5000                 return false;
5001             }
5002             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
5003             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5004                 return false;
5005             }
5006             n = new PhylogenyNode( "HNRPR_HUMAN" );
5007             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5008                 return false;
5009             }
5010             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
5011             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
5012                 return false;
5013             }
5014         }
5015         catch ( final Exception e ) {
5016             e.printStackTrace( System.out );
5017             return false;
5018         }
5019         return true;
5020     }
5021
5022     private static boolean testExtractTaxonomyCodeFromNodeName() {
5023         try {
5024             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE",
5025                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5026                 return false;
5027             }
5028             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5029                     .equals( "SOYBN" ) ) {
5030                 return false;
5031             }
5032             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
5033                     .equals( "ARATH" ) ) {
5034                 return false;
5035             }
5036             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
5037                     .equals( "ARATH" ) ) {
5038                 return false;
5039             }
5040             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE )
5041                     .equals( "RAT" ) ) {
5042                 return false;
5043             }
5044             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE )
5045                     .equals( "RAT" ) ) {
5046                 return false;
5047             }
5048             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1",
5049                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5050                 return false;
5051             }
5052             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5053                     .equals( "SOYBN" ) ) {
5054                 return false;
5055             }
5056             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5057                     .equals( "SOYBN" ) ) {
5058                 return false;
5059             }
5060             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5061                     .equals( "SOYBN" ) ) {
5062                 return false;
5063             }
5064             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5065                     .equals( "SOYBN" ) ) {
5066                 return false;
5067             }
5068             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5069                     .equals( "SOYBN" ) ) {
5070                 return false;
5071             }
5072             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
5073                     .equals( "SOYBN" ) ) {
5074                 return false;
5075             }
5076             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
5077                     .equals( "SOYBN" ) ) {
5078                 return false;
5079             }
5080             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
5081                     .equals( "SOYBN" ) ) {
5082                 return false;
5083             }
5084             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx",
5085                                                               TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
5086                 return false;
5087             }
5088             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
5089                     .equals( "SOYBN" ) ) {
5090                 return false;
5091             }
5092             if ( !ParserUtils
5093                     .extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5094                     .equals( "ECOLI" ) ) {
5095                 return false;
5096             }
5097             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blagg_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
5098                     .equals( "9YX45" ) ) {
5099                 return false;
5100             }
5101             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
5102                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5103                     .equals( "MOUSE" ) ) {
5104                 return false;
5105             }
5106             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
5107                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5108                     .equals( "MOUSE" ) ) {
5109                 return false;
5110             }
5111             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
5112                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5113                     .equals( "MOUSE" ) ) {
5114                 return false;
5115             }
5116             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
5117                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5118                 return false;
5119             }
5120             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
5121                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5122                 return false;
5123             }
5124             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5125                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5126                     .equals( "RAT" ) ) {
5127                 return false;
5128             }
5129             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5130                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5131                     .equals( "RAT" ) ) {
5132                 return false;
5133             }
5134             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
5135                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5136                     .equals( "RAT" ) ) {
5137                 return false;
5138             }
5139             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
5140                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5141                 return false;
5142             }
5143             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
5144                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5145                 return false;
5146             }
5147             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5148                     .equals( "RAT" ) ) {
5149                 return false;
5150             }
5151             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5152                     .equals( "PIG" ) ) {
5153                 return false;
5154             }
5155             if ( !ParserUtils
5156                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5157                     .equals( "MOUSE" ) ) {
5158                 return false;
5159             }
5160             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5161                     .equals( "MOUSE" ) ) {
5162                 return false;
5163             }
5164             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ",
5165                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5166                 return false;
5167             }
5168         }
5169         catch ( final Exception e ) {
5170             e.printStackTrace( System.out );
5171             return false;
5172         }
5173         return true;
5174     }
5175
5176     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
5177         try {
5178             PhylogenyNode n = new PhylogenyNode();
5179             n.setName( "tr|B3RJ64" );
5180             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5181                 return false;
5182             }
5183             n.setName( "tr.B3RJ64" );
5184             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5185                 return false;
5186             }
5187             n.setName( "tr=B3RJ64" );
5188             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5189                 return false;
5190             }
5191             n.setName( "tr-B3RJ64" );
5192             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5193                 return false;
5194             }
5195             n.setName( "tr/B3RJ64" );
5196             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5197                 return false;
5198             }
5199             n.setName( "tr\\B3RJ64" );
5200             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5201                 return false;
5202             }
5203             n.setName( "tr_B3RJ64" );
5204             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5205                 return false;
5206             }
5207             n.setName( " tr|B3RJ64 " );
5208             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5209                 return false;
5210             }
5211             n.setName( "-tr|B3RJ64-" );
5212             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5213                 return false;
5214             }
5215             n.setName( "-tr=B3RJ64-" );
5216             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5217                 return false;
5218             }
5219             n.setName( "_tr=B3RJ64_" );
5220             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5221                 return false;
5222             }
5223             n.setName( " tr_tr|B3RJ64_sp|123 " );
5224             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5225                 return false;
5226             }
5227             n.setName( "B3RJ64" );
5228             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5229                 return false;
5230             }
5231             n.setName( "sp|B3RJ64" );
5232             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5233                 return false;
5234             }
5235             n.setName( "sp|B3RJ64C" );
5236             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5237                 return false;
5238             }
5239             n.setName( "sp B3RJ64" );
5240             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5241                 return false;
5242             }
5243             n.setName( "sp|B3RJ6X" );
5244             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5245                 return false;
5246             }
5247             n.setName( "sp|B3RJ6" );
5248             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5249                 return false;
5250             }
5251             n.setName( "K1PYK7_CRAGI" );
5252             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5253                 return false;
5254             }
5255             n.setName( "K1PYK7_PEA" );
5256             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
5257                 return false;
5258             }
5259             n.setName( "K1PYK7_RAT" );
5260             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
5261                 return false;
5262             }
5263             n.setName( "K1PYK7_PIG" );
5264             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5265                 return false;
5266             }
5267             n.setName( "~K1PYK7_PIG~" );
5268             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5269                 return false;
5270             }
5271             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
5272             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5273                 return false;
5274             }
5275             n.setName( "K1PYKX_CRAGI" );
5276             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5277                 return false;
5278             }
5279             n.setName( "XXXXX_CRAGI" );
5280             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
5281                 return false;
5282             }
5283             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
5284             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
5285                 return false;
5286             }
5287             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
5288             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5289                 return false;
5290             }
5291             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
5292             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
5293                 return false;
5294             }
5295             n = new PhylogenyNode();
5296             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
5297             seq.setSymbol( "K1PYK7_CRAGI" );
5298             n.getNodeData().addSequence( seq );
5299             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5300                 return false;
5301             }
5302             seq.setSymbol( "tr|B3RJ64" );
5303             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5304                 return false;
5305             }
5306             n = new PhylogenyNode();
5307             seq = new org.forester.phylogeny.data.Sequence();
5308             seq.setName( "K1PYK7_CRAGI" );
5309             n.getNodeData().addSequence( seq );
5310             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5311                 return false;
5312             }
5313             seq.setName( "tr|B3RJ64" );
5314             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5315                 return false;
5316             }
5317             n = new PhylogenyNode();
5318             seq = new org.forester.phylogeny.data.Sequence();
5319             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
5320             n.getNodeData().addSequence( seq );
5321             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
5322                 return false;
5323             }
5324             n = new PhylogenyNode();
5325             seq = new org.forester.phylogeny.data.Sequence();
5326             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
5327             n.getNodeData().addSequence( seq );
5328             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5329                 return false;
5330             }
5331             //
5332             n = new PhylogenyNode();
5333             n.setName( "ACP19736" );
5334             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5335                 return false;
5336             }
5337             n = new PhylogenyNode();
5338             n.setName( "|ACP19736|" );
5339             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5340                 return false;
5341             }
5342         }
5343         catch ( final Exception e ) {
5344             e.printStackTrace( System.out );
5345             return false;
5346         }
5347         return true;
5348     }
5349
5350     private static boolean testFastaParser() {
5351         try {
5352             final FileInputStream fis1 = new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" );
5353             if ( !FastaParser.isLikelyFasta( fis1 ) ) {
5354                 fis1.close();
5355                 return false;
5356             }
5357             else {
5358                 fis1.close();
5359             }
5360             final FileInputStream fis2 = new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" );
5361             if ( FastaParser.isLikelyFasta( fis2 ) ) {
5362                 fis2.close();
5363                 return false;
5364             }
5365             else {
5366                 fis2.close();
5367             }
5368             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
5369             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
5370                 return false;
5371             }
5372             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
5373                 return false;
5374             }
5375             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
5376                 return false;
5377             }
5378             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
5379                 return false;
5380             }
5381             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
5382                 return false;
5383             }
5384             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
5385                 return false;
5386             }
5387         }
5388         catch ( final Exception e ) {
5389             e.printStackTrace();
5390             return false;
5391         }
5392         return true;
5393     }
5394
5395     private static boolean testGenbankAccessorParsing() {
5396         //The format for GenBank Accession numbers are:
5397         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
5398         //Protein:    3 letters + 5 numerals
5399         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
5400         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
5401             return false;
5402         }
5403         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
5404             return false;
5405         }
5406         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" )
5407                 .equals( "AY423861.24" ) ) {
5408             return false;
5409         }
5410         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
5411             return false;
5412         }
5413         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
5414             return false;
5415         }
5416         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
5417             return false;
5418         }
5419         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
5420             return false;
5421         }
5422         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
5423             return false;
5424         }
5425         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
5426             return false;
5427         }
5428         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
5429             return false;
5430         }
5431         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
5432             return false;
5433         }
5434         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
5435             return false;
5436         }
5437         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
5438             return false;
5439         }
5440         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
5441             return false;
5442         }
5443         return true;
5444     }
5445
5446     private static boolean testGeneralMsaParser() {
5447         try {
5448             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
5449             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
5450             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
5451             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
5452             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
5453             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
5454             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
5455             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
5456             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5457                 return false;
5458             }
5459             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5460                 return false;
5461             }
5462             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5463                 return false;
5464             }
5465             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5466                 return false;
5467             }
5468             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5469                 return false;
5470             }
5471             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5472                 return false;
5473             }
5474             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5475                 return false;
5476             }
5477             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5478                 return false;
5479             }
5480             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5481                 return false;
5482             }
5483             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5484                 return false;
5485             }
5486             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5487                 return false;
5488             }
5489             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5490                 return false;
5491             }
5492             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5493             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5494                 return false;
5495             }
5496             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5497                 return false;
5498             }
5499             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5500                 return false;
5501             }
5502             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5503             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5504                 return false;
5505             }
5506             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5507                 return false;
5508             }
5509             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5510                 return false;
5511             }
5512             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5513             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5514                 return false;
5515             }
5516             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5517                 return false;
5518             }
5519             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5520                 return false;
5521             }
5522         }
5523         catch ( final Exception e ) {
5524             e.printStackTrace();
5525             return false;
5526         }
5527         return true;
5528     }
5529
5530     private static boolean testGeneralTable() {
5531         try {
5532             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5533             t0.setValue( 3, 2, "23" );
5534             t0.setValue( 10, 1, "error" );
5535             t0.setValue( 10, 1, "110" );
5536             t0.setValue( 9, 1, "19" );
5537             t0.setValue( 1, 10, "101" );
5538             t0.setValue( 10, 10, "1010" );
5539             t0.setValue( 100, 10, "10100" );
5540             t0.setValue( 0, 0, "00" );
5541             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5542                 return false;
5543             }
5544             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5545                 return false;
5546             }
5547             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5548                 return false;
5549             }
5550             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5551                 return false;
5552             }
5553             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5554                 return false;
5555             }
5556             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5557                 return false;
5558             }
5559             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5560                 return false;
5561             }
5562             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5563                 return false;
5564             }
5565             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5566                 return false;
5567             }
5568             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5569             t1.setValue( "3", "2", "23" );
5570             t1.setValue( "10", "1", "error" );
5571             t1.setValue( "10", "1", "110" );
5572             t1.setValue( "9", "1", "19" );
5573             t1.setValue( "1", "10", "101" );
5574             t1.setValue( "10", "10", "1010" );
5575             t1.setValue( "100", "10", "10100" );
5576             t1.setValue( "0", "0", "00" );
5577             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5578             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5579                 return false;
5580             }
5581             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5582                 return false;
5583             }
5584             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5585                 return false;
5586             }
5587             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5588                 return false;
5589             }
5590             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5591                 return false;
5592             }
5593             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5594                 return false;
5595             }
5596             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5597                 return false;
5598             }
5599             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5600                 return false;
5601             }
5602             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5603                 return false;
5604             }
5605             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5606                 return false;
5607             }
5608         }
5609         catch ( final Exception e ) {
5610             e.printStackTrace( System.out );
5611             return false;
5612         }
5613         return true;
5614     }
5615
5616     private static boolean testGetDistance() {
5617         try {
5618             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5619             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",
5620                                                  new NHXParser() )[ 0 ];
5621             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5622                 return false;
5623             }
5624             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5625                 return false;
5626             }
5627             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5628                 return false;
5629             }
5630             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5631                 return false;
5632             }
5633             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5634                 return false;
5635             }
5636             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5637                 return false;
5638             }
5639             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5640                 return false;
5641             }
5642             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5643                 return false;
5644             }
5645             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5646                 return false;
5647             }
5648             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5649                 return false;
5650             }
5651             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5652                 return false;
5653             }
5654             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5655                 return false;
5656             }
5657             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5658                 return false;
5659             }
5660             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5661                 return false;
5662             }
5663             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5664                 return false;
5665             }
5666             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5667                 return false;
5668             }
5669             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5670                 return false;
5671             }
5672             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5673                 return false;
5674             }
5675             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5676                 return false;
5677             }
5678             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5679                 return false;
5680             }
5681             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5682                 return false;
5683             }
5684             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5685                 return false;
5686             }
5687             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5688                 return false;
5689             }
5690             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5691                 return false;
5692             }
5693             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5694                 return false;
5695             }
5696             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5697                 return false;
5698             }
5699             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5700                 return false;
5701             }
5702             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5703                 return false;
5704             }
5705             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5706                 return false;
5707             }
5708             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5709                 return false;
5710             }
5711             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5712                 return false;
5713             }
5714             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",
5715                                                  new NHXParser() )[ 0 ];
5716             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5717                 return false;
5718             }
5719             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5720                 return false;
5721             }
5722             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5723                 return false;
5724             }
5725             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5726                 return false;
5727             }
5728             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5729                 return false;
5730             }
5731             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5732                 return false;
5733             }
5734             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5735                 return false;
5736             }
5737             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5738                 return false;
5739             }
5740             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5741                 return false;
5742             }
5743             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5744                 return false;
5745             }
5746             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5747                 return false;
5748             }
5749         }
5750         catch ( final Exception e ) {
5751             e.printStackTrace( System.out );
5752             return false;
5753         }
5754         return true;
5755     }
5756
5757     private static boolean testGetLCA() {
5758         try {
5759             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5760             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5761                                                  new NHXParser() )[ 0 ];
5762             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5763             if ( !A.getName().equals( "A" ) ) {
5764                 return false;
5765             }
5766             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5767             if ( !gh.getName().equals( "gh" ) ) {
5768                 return false;
5769             }
5770             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5771             if ( !ab.getName().equals( "ab" ) ) {
5772                 return false;
5773             }
5774             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5775             if ( !ab2.getName().equals( "ab" ) ) {
5776                 return false;
5777             }
5778             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5779             if ( !gh2.getName().equals( "gh" ) ) {
5780                 return false;
5781             }
5782             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5783             if ( !gh3.getName().equals( "gh" ) ) {
5784                 return false;
5785             }
5786             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5787             if ( !abc.getName().equals( "abc" ) ) {
5788                 return false;
5789             }
5790             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5791             if ( !abc2.getName().equals( "abc" ) ) {
5792                 return false;
5793             }
5794             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5795             if ( !abcd.getName().equals( "abcd" ) ) {
5796                 return false;
5797             }
5798             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5799             if ( !abcd2.getName().equals( "abcd" ) ) {
5800                 return false;
5801             }
5802             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5803             if ( !abcdef.getName().equals( "abcdef" ) ) {
5804                 return false;
5805             }
5806             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5807             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5808                 return false;
5809             }
5810             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5811             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5812                 return false;
5813             }
5814             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5815             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5816                 return false;
5817             }
5818             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5819             if ( !abcde.getName().equals( "abcde" ) ) {
5820                 return false;
5821             }
5822             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5823             if ( !abcde2.getName().equals( "abcde" ) ) {
5824                 return false;
5825             }
5826             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5827             if ( !r.getName().equals( "abcdefgh" ) ) {
5828                 return false;
5829             }
5830             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5831             if ( !r2.getName().equals( "abcdefgh" ) ) {
5832                 return false;
5833             }
5834             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5835             if ( !r3.getName().equals( "abcdefgh" ) ) {
5836                 return false;
5837             }
5838             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5839             if ( !abcde3.getName().equals( "abcde" ) ) {
5840                 return false;
5841             }
5842             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5843             if ( !abcde4.getName().equals( "abcde" ) ) {
5844                 return false;
5845             }
5846             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5847             if ( !ab3.getName().equals( "ab" ) ) {
5848                 return false;
5849             }
5850             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5851             if ( !ab4.getName().equals( "ab" ) ) {
5852                 return false;
5853             }
5854             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5855             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5856             if ( !cd.getName().equals( "cd" ) ) {
5857                 return false;
5858             }
5859             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5860             if ( !cd2.getName().equals( "cd" ) ) {
5861                 return false;
5862             }
5863             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5864             if ( !cde.getName().equals( "cde" ) ) {
5865                 return false;
5866             }
5867             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5868             if ( !cde2.getName().equals( "cde" ) ) {
5869                 return false;
5870             }
5871             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5872             if ( !cdef.getName().equals( "cdef" ) ) {
5873                 return false;
5874             }
5875             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5876             if ( !cdef2.getName().equals( "cdef" ) ) {
5877                 return false;
5878             }
5879             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5880             if ( !cdef3.getName().equals( "cdef" ) ) {
5881                 return false;
5882             }
5883             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5884             if ( !rt.getName().equals( "r" ) ) {
5885                 return false;
5886             }
5887             final Phylogeny p3 = factory.create(
5888                                                  "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5889                                                  new NHXParser() )[ 0 ];
5890             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5891             if ( !bc_3.getName().equals( "bc" ) ) {
5892                 return false;
5893             }
5894             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5895             if ( !ac_3.getName().equals( "abc" ) ) {
5896                 return false;
5897             }
5898             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5899             if ( !ad_3.getName().equals( "abcde" ) ) {
5900                 return false;
5901             }
5902             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5903             if ( !af_3.getName().equals( "abcdef" ) ) {
5904                 return false;
5905             }
5906             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5907             if ( !ag_3.getName().equals( "" ) ) {
5908                 return false;
5909             }
5910             if ( !ag_3.isRoot() ) {
5911                 return false;
5912             }
5913             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5914             if ( !al_3.getName().equals( "" ) ) {
5915                 return false;
5916             }
5917             if ( !al_3.isRoot() ) {
5918                 return false;
5919             }
5920             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5921             if ( !kl_3.getName().equals( "" ) ) {
5922                 return false;
5923             }
5924             if ( !kl_3.isRoot() ) {
5925                 return false;
5926             }
5927             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5928             if ( !fl_3.getName().equals( "" ) ) {
5929                 return false;
5930             }
5931             if ( !fl_3.isRoot() ) {
5932                 return false;
5933             }
5934             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5935             if ( !gk_3.getName().equals( "ghijk" ) ) {
5936                 return false;
5937             }
5938             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5939             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5940             if ( !r_4.getName().equals( "r" ) ) {
5941                 return false;
5942             }
5943             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5944             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5945             if ( !r_5.getName().equals( "root" ) ) {
5946                 return false;
5947             }
5948             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5949             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5950             if ( !r_6.getName().equals( "rot" ) ) {
5951                 return false;
5952             }
5953             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5954             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5955             if ( !r_7.getName().equals( "rott" ) ) {
5956                 return false;
5957             }
5958         }
5959         catch ( final Exception e ) {
5960             e.printStackTrace( System.out );
5961             return false;
5962         }
5963         return true;
5964     }
5965
5966     private static boolean testGetLCA2() {
5967         try {
5968             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5969             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5970             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5971             PhylogenyMethods.preOrderReId( p_a );
5972             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5973                                                                                               p_a.getNode( "a" ) );
5974             if ( !p_a_1.getName().equals( "a" ) ) {
5975                 return false;
5976             }
5977             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5978             PhylogenyMethods.preOrderReId( p_b );
5979             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5980                                                                                               p_b.getNode( "a" ) );
5981             if ( !p_b_1.getName().equals( "b" ) ) {
5982                 return false;
5983             }
5984             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5985                                                                                               p_b.getNode( "b" ) );
5986             if ( !p_b_2.getName().equals( "b" ) ) {
5987                 return false;
5988             }
5989             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5990             PhylogenyMethods.preOrderReId( p_c );
5991             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5992                                                                                               p_c.getNode( "a" ) );
5993             if ( !p_c_1.getName().equals( "b" ) ) {
5994                 return false;
5995             }
5996             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5997                                                                                               p_c.getNode( "c" ) );
5998             if ( !p_c_2.getName().equals( "c" ) ) {
5999                 System.out.println( p_c_2.getName() );
6000                 System.exit( -1 );
6001                 return false;
6002             }
6003             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
6004                                                                                               p_c.getNode( "b" ) );
6005             if ( !p_c_3.getName().equals( "b" ) ) {
6006                 return false;
6007             }
6008             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
6009                                                                                               p_c.getNode( "a" ) );
6010             if ( !p_c_4.getName().equals( "c" ) ) {
6011                 return false;
6012             }
6013             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
6014                                                  new NHXParser() )[ 0 ];
6015             PhylogenyMethods.preOrderReId( p1 );
6016             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6017                                                                                           p1.getNode( "A" ) );
6018             if ( !A.getName().equals( "A" ) ) {
6019                 return false;
6020             }
6021             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
6022                                                                                            p1.getNode( "gh" ) );
6023             if ( !gh.getName().equals( "gh" ) ) {
6024                 return false;
6025             }
6026             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6027                                                                                            p1.getNode( "B" ) );
6028             if ( !ab.getName().equals( "ab" ) ) {
6029                 return false;
6030             }
6031             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
6032                                                                                             p1.getNode( "A" ) );
6033             if ( !ab2.getName().equals( "ab" ) ) {
6034                 return false;
6035             }
6036             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
6037                                                                                             p1.getNode( "G" ) );
6038             if ( !gh2.getName().equals( "gh" ) ) {
6039                 return false;
6040             }
6041             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
6042                                                                                             p1.getNode( "H" ) );
6043             if ( !gh3.getName().equals( "gh" ) ) {
6044                 return false;
6045             }
6046             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
6047                                                                                             p1.getNode( "A" ) );
6048             if ( !abc.getName().equals( "abc" ) ) {
6049                 return false;
6050             }
6051             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6052                                                                                              p1.getNode( "C" ) );
6053             if ( !abc2.getName().equals( "abc" ) ) {
6054                 return false;
6055             }
6056             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6057                                                                                              p1.getNode( "D" ) );
6058             if ( !abcd.getName().equals( "abcd" ) ) {
6059                 return false;
6060             }
6061             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
6062                                                                                               p1.getNode( "A" ) );
6063             if ( !abcd2.getName().equals( "abcd" ) ) {
6064                 return false;
6065             }
6066             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6067                                                                                                p1.getNode( "F" ) );
6068             if ( !abcdef.getName().equals( "abcdef" ) ) {
6069                 return false;
6070             }
6071             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
6072                                                                                                 p1.getNode( "A" ) );
6073             if ( !abcdef2.getName().equals( "abcdef" ) ) {
6074                 return false;
6075             }
6076             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
6077                                                                                                 p1.getNode( "F" ) );
6078             if ( !abcdef3.getName().equals( "abcdef" ) ) {
6079                 return false;
6080             }
6081             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
6082                                                                                                 p1.getNode( "ab" ) );
6083             if ( !abcdef4.getName().equals( "abcdef" ) ) {
6084                 return false;
6085             }
6086             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6087                                                                                               p1.getNode( "E" ) );
6088             if ( !abcde.getName().equals( "abcde" ) ) {
6089                 return false;
6090             }
6091             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6092                                                                                                p1.getNode( "A" ) );
6093             if ( !abcde2.getName().equals( "abcde" ) ) {
6094                 return false;
6095             }
6096             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
6097                                                                                           p1.getNode( "abcdefgh" ) );
6098             if ( !r.getName().equals( "abcdefgh" ) ) {
6099                 return false;
6100             }
6101             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6102                                                                                            p1.getNode( "H" ) );
6103             if ( !r2.getName().equals( "abcdefgh" ) ) {
6104                 return false;
6105             }
6106             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
6107                                                                                            p1.getNode( "A" ) );
6108             if ( !r3.getName().equals( "abcdefgh" ) ) {
6109                 return false;
6110             }
6111             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6112                                                                                                p1.getNode( "abcde" ) );
6113             if ( !abcde3.getName().equals( "abcde" ) ) {
6114                 return false;
6115             }
6116             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
6117                                                                                                p1.getNode( "E" ) );
6118             if ( !abcde4.getName().equals( "abcde" ) ) {
6119                 return false;
6120             }
6121             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
6122                                                                                             p1.getNode( "B" ) );
6123             if ( !ab3.getName().equals( "ab" ) ) {
6124                 return false;
6125             }
6126             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
6127                                                                                             p1.getNode( "ab" ) );
6128             if ( !ab4.getName().equals( "ab" ) ) {
6129                 return false;
6130             }
6131             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
6132             PhylogenyMethods.preOrderReId( p2 );
6133             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6134                                                                                            p2.getNode( "d" ) );
6135             if ( !cd.getName().equals( "cd" ) ) {
6136                 return false;
6137             }
6138             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6139                                                                                             p2.getNode( "c" ) );
6140             if ( !cd2.getName().equals( "cd" ) ) {
6141                 return false;
6142             }
6143             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6144                                                                                             p2.getNode( "e" ) );
6145             if ( !cde.getName().equals( "cde" ) ) {
6146                 return false;
6147             }
6148             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
6149                                                                                              p2.getNode( "c" ) );
6150             if ( !cde2.getName().equals( "cde" ) ) {
6151                 return false;
6152             }
6153             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6154                                                                                              p2.getNode( "f" ) );
6155             if ( !cdef.getName().equals( "cdef" ) ) {
6156                 return false;
6157             }
6158             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6159                                                                                               p2.getNode( "f" ) );
6160             if ( !cdef2.getName().equals( "cdef" ) ) {
6161                 return false;
6162             }
6163             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
6164                                                                                               p2.getNode( "d" ) );
6165             if ( !cdef3.getName().equals( "cdef" ) ) {
6166                 return false;
6167             }
6168             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6169                                                                                            p2.getNode( "a" ) );
6170             if ( !rt.getName().equals( "r" ) ) {
6171                 return false;
6172             }
6173             final Phylogeny p3 = factory.create(
6174                                                  "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
6175                                                  new NHXParser() )[ 0 ];
6176             PhylogenyMethods.preOrderReId( p3 );
6177             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
6178                                                                                              p3.getNode( "c" ) );
6179             if ( !bc_3.getName().equals( "bc" ) ) {
6180                 return false;
6181             }
6182             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6183                                                                                              p3.getNode( "c" ) );
6184             if ( !ac_3.getName().equals( "abc" ) ) {
6185                 return false;
6186             }
6187             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6188                                                                                              p3.getNode( "d" ) );
6189             if ( !ad_3.getName().equals( "abcde" ) ) {
6190                 return false;
6191             }
6192             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6193                                                                                              p3.getNode( "f" ) );
6194             if ( !af_3.getName().equals( "abcdef" ) ) {
6195                 return false;
6196             }
6197             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6198                                                                                              p3.getNode( "g" ) );
6199             if ( !ag_3.getName().equals( "" ) ) {
6200                 return false;
6201             }
6202             if ( !ag_3.isRoot() ) {
6203                 return false;
6204             }
6205             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6206                                                                                              p3.getNode( "l" ) );
6207             if ( !al_3.getName().equals( "" ) ) {
6208                 return false;
6209             }
6210             if ( !al_3.isRoot() ) {
6211                 return false;
6212             }
6213             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
6214                                                                                              p3.getNode( "l" ) );
6215             if ( !kl_3.getName().equals( "" ) ) {
6216                 return false;
6217             }
6218             if ( !kl_3.isRoot() ) {
6219                 return false;
6220             }
6221             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
6222                                                                                              p3.getNode( "l" ) );
6223             if ( !fl_3.getName().equals( "" ) ) {
6224                 return false;
6225             }
6226             if ( !fl_3.isRoot() ) {
6227                 return false;
6228             }
6229             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
6230                                                                                              p3.getNode( "k" ) );
6231             if ( !gk_3.getName().equals( "ghijk" ) ) {
6232                 return false;
6233             }
6234             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
6235             PhylogenyMethods.preOrderReId( p4 );
6236             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
6237                                                                                             p4.getNode( "c" ) );
6238             if ( !r_4.getName().equals( "r" ) ) {
6239                 return false;
6240             }
6241             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
6242             PhylogenyMethods.preOrderReId( p5 );
6243             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
6244                                                                                             p5.getNode( "c" ) );
6245             if ( !r_5.getName().equals( "root" ) ) {
6246                 return false;
6247             }
6248             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
6249             PhylogenyMethods.preOrderReId( p6 );
6250             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
6251                                                                                             p6.getNode( "a" ) );
6252             if ( !r_6.getName().equals( "rot" ) ) {
6253                 return false;
6254             }
6255             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
6256             PhylogenyMethods.preOrderReId( p7 );
6257             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
6258                                                                                             p7.getNode( "e" ) );
6259             if ( !r_7.getName().equals( "rott" ) ) {
6260                 return false;
6261             }
6262             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6263                                                                                              p7.getNode( "a" ) );
6264             if ( !r_71.getName().equals( "rott" ) ) {
6265                 return false;
6266             }
6267             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6268                                                                                              p7.getNode( "rott" ) );
6269             if ( !r_72.getName().equals( "rott" ) ) {
6270                 return false;
6271             }
6272             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6273                                                                                              p7.getNode( "a" ) );
6274             if ( !r_73.getName().equals( "rott" ) ) {
6275                 return false;
6276             }
6277             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6278                                                                                              p7.getNode( "rott" ) );
6279             if ( !r_74.getName().equals( "rott" ) ) {
6280                 return false;
6281             }
6282             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6283                                                                                              p7.getNode( "e" ) );
6284             if ( !r_75.getName().equals( "e" ) ) {
6285                 return false;
6286             }
6287         }
6288         catch ( final Exception e ) {
6289             e.printStackTrace( System.out );
6290             return false;
6291         }
6292         return true;
6293     }
6294
6295     private static boolean testHmmscanOutputParser() {
6296         final String test_dir = Test.PATH_TO_TEST_DATA;
6297         try {
6298             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
6299                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ),
6300                                                                                          "MONBR",
6301                                                                                          INDIVIDUAL_SCORE_CUTOFF.NONE );
6302             parser1.parse();
6303             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
6304                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ),
6305                                                                                          "MONBR",
6306                                                                                          INDIVIDUAL_SCORE_CUTOFF.NONE );
6307             final List<Protein> proteins = parser2.parse();
6308             if ( parser2.getProteinsEncountered() != 4 ) {
6309                 return false;
6310             }
6311             if ( proteins.size() != 4 ) {
6312                 return false;
6313             }
6314             if ( parser2.getDomainsEncountered() != 69 ) {
6315                 return false;
6316             }
6317             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
6318                 return false;
6319             }
6320             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
6321                 return false;
6322             }
6323             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
6324                 return false;
6325             }
6326             final Protein p1 = proteins.get( 0 );
6327             if ( p1.getNumberOfProteinDomains() != 15 ) {
6328                 return false;
6329             }
6330             if ( p1.getLength() != 850 ) {
6331                 return false;
6332             }
6333             final Protein p2 = proteins.get( 1 );
6334             if ( p2.getNumberOfProteinDomains() != 51 ) {
6335                 return false;
6336             }
6337             if ( p2.getLength() != 1291 ) {
6338                 return false;
6339             }
6340             final Protein p3 = proteins.get( 2 );
6341             if ( p3.getNumberOfProteinDomains() != 2 ) {
6342                 return false;
6343             }
6344             final Protein p4 = proteins.get( 3 );
6345             if ( p4.getNumberOfProteinDomains() != 1 ) {
6346                 return false;
6347             }
6348             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
6349                 return false;
6350             }
6351             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
6352                 return false;
6353             }
6354             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
6355                 return false;
6356             }
6357             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
6358                 return false;
6359             }
6360             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
6361                 return false;
6362             }
6363             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
6364                 return false;
6365             }
6366             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
6367                 return false;
6368             }
6369         }
6370         catch ( final Exception e ) {
6371             e.printStackTrace( System.out );
6372             return false;
6373         }
6374         return true;
6375     }
6376
6377     private static boolean testLastExternalNodeMethods() {
6378         try {
6379             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6380             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
6381             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
6382             final PhylogenyNode n1 = t0.getNode( "A" );
6383             if ( n1.isLastExternalNode() ) {
6384                 return false;
6385             }
6386             final PhylogenyNode n2 = t0.getNode( "B" );
6387             if ( n2.isLastExternalNode() ) {
6388                 return false;
6389             }
6390             final PhylogenyNode n3 = t0.getNode( "C" );
6391             if ( n3.isLastExternalNode() ) {
6392                 return false;
6393             }
6394             final PhylogenyNode n4 = t0.getNode( "D" );
6395             if ( !n4.isLastExternalNode() ) {
6396                 return false;
6397             }
6398         }
6399         catch ( final Exception e ) {
6400             e.printStackTrace( System.out );
6401             return false;
6402         }
6403         return true;
6404     }
6405
6406     private static boolean testLevelOrderIterator() {
6407         try {
6408             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6409             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
6410             PhylogenyNodeIterator it0;
6411             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
6412                 it0.next();
6413             }
6414             for( it0.reset(); it0.hasNext(); ) {
6415                 it0.next();
6416             }
6417             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
6418             if ( !it.next().getName().equals( "r" ) ) {
6419                 return false;
6420             }
6421             if ( !it.next().getName().equals( "ab" ) ) {
6422                 return false;
6423             }
6424             if ( !it.next().getName().equals( "cd" ) ) {
6425                 return false;
6426             }
6427             if ( !it.next().getName().equals( "A" ) ) {
6428                 return false;
6429             }
6430             if ( !it.next().getName().equals( "B" ) ) {
6431                 return false;
6432             }
6433             if ( !it.next().getName().equals( "C" ) ) {
6434                 return false;
6435             }
6436             if ( !it.next().getName().equals( "D" ) ) {
6437                 return false;
6438             }
6439             if ( it.hasNext() ) {
6440                 return false;
6441             }
6442             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",
6443                                                  new NHXParser() )[ 0 ];
6444             PhylogenyNodeIterator it2;
6445             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
6446                 it2.next();
6447             }
6448             for( it2.reset(); it2.hasNext(); ) {
6449                 it2.next();
6450             }
6451             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
6452             if ( !it3.next().getName().equals( "r" ) ) {
6453                 return false;
6454             }
6455             if ( !it3.next().getName().equals( "abc" ) ) {
6456                 return false;
6457             }
6458             if ( !it3.next().getName().equals( "defg" ) ) {
6459                 return false;
6460             }
6461             if ( !it3.next().getName().equals( "A" ) ) {
6462                 return false;
6463             }
6464             if ( !it3.next().getName().equals( "B" ) ) {
6465                 return false;
6466             }
6467             if ( !it3.next().getName().equals( "C" ) ) {
6468                 return false;
6469             }
6470             if ( !it3.next().getName().equals( "D" ) ) {
6471                 return false;
6472             }
6473             if ( !it3.next().getName().equals( "E" ) ) {
6474                 return false;
6475             }
6476             if ( !it3.next().getName().equals( "F" ) ) {
6477                 return false;
6478             }
6479             if ( !it3.next().getName().equals( "G" ) ) {
6480                 return false;
6481             }
6482             if ( !it3.next().getName().equals( "1" ) ) {
6483                 return false;
6484             }
6485             if ( !it3.next().getName().equals( "2" ) ) {
6486                 return false;
6487             }
6488             if ( !it3.next().getName().equals( "3" ) ) {
6489                 return false;
6490             }
6491             if ( !it3.next().getName().equals( "4" ) ) {
6492                 return false;
6493             }
6494             if ( !it3.next().getName().equals( "5" ) ) {
6495                 return false;
6496             }
6497             if ( !it3.next().getName().equals( "6" ) ) {
6498                 return false;
6499             }
6500             if ( !it3.next().getName().equals( "f1" ) ) {
6501                 return false;
6502             }
6503             if ( !it3.next().getName().equals( "f2" ) ) {
6504                 return false;
6505             }
6506             if ( !it3.next().getName().equals( "f3" ) ) {
6507                 return false;
6508             }
6509             if ( !it3.next().getName().equals( "a" ) ) {
6510                 return false;
6511             }
6512             if ( !it3.next().getName().equals( "b" ) ) {
6513                 return false;
6514             }
6515             if ( !it3.next().getName().equals( "f21" ) ) {
6516                 return false;
6517             }
6518             if ( !it3.next().getName().equals( "X" ) ) {
6519                 return false;
6520             }
6521             if ( !it3.next().getName().equals( "Y" ) ) {
6522                 return false;
6523             }
6524             if ( !it3.next().getName().equals( "Z" ) ) {
6525                 return false;
6526             }
6527             if ( it3.hasNext() ) {
6528                 return false;
6529             }
6530             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6531             PhylogenyNodeIterator it4;
6532             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6533                 it4.next();
6534             }
6535             for( it4.reset(); it4.hasNext(); ) {
6536                 it4.next();
6537             }
6538             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6539             if ( !it5.next().getName().equals( "r" ) ) {
6540                 return false;
6541             }
6542             if ( !it5.next().getName().equals( "A" ) ) {
6543                 return false;
6544             }
6545             if ( !it5.next().getName().equals( "B" ) ) {
6546                 return false;
6547             }
6548             if ( !it5.next().getName().equals( "C" ) ) {
6549                 return false;
6550             }
6551             if ( !it5.next().getName().equals( "D" ) ) {
6552                 return false;
6553             }
6554             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6555             PhylogenyNodeIterator it6;
6556             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6557                 it6.next();
6558             }
6559             for( it6.reset(); it6.hasNext(); ) {
6560                 it6.next();
6561             }
6562             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6563             if ( !it7.next().getName().equals( "A" ) ) {
6564                 return false;
6565             }
6566             if ( it.hasNext() ) {
6567                 return false;
6568             }
6569         }
6570         catch ( final Exception e ) {
6571             e.printStackTrace( System.out );
6572             return false;
6573         }
6574         return true;
6575     }
6576
6577     private static boolean testMafft( final String path ) {
6578         try {
6579             final List<String> opts = new ArrayList<String>();
6580             opts.add( "--maxiterate" );
6581             opts.add( "1000" );
6582             opts.add( "--localpair" );
6583             opts.add( "--quiet" );
6584             Msa msa = null;
6585             final MsaInferrer mafft = Mafft.createInstance( path );
6586             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6587             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6588                 return false;
6589             }
6590             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6591                 return false;
6592             }
6593         }
6594         catch ( final Exception e ) {
6595             e.printStackTrace( System.out );
6596             return false;
6597         }
6598         return true;
6599     }
6600
6601     private static boolean testMidpointrooting() {
6602         try {
6603             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6604             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6605             PhylogenyMethods.midpointRoot( t0 );
6606             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6607                 return false;
6608             }
6609             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6610                 return false;
6611             }
6612             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6613                            1 ) ) {
6614                 return false;
6615             }
6616             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",
6617                                                  new NHXParser() )[ 0 ];
6618             if ( !t1.isRooted() ) {
6619                 return false;
6620             }
6621             PhylogenyMethods.midpointRoot( t1 );
6622             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6623                 return false;
6624             }
6625             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6626                 return false;
6627             }
6628             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6629                 return false;
6630             }
6631             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6632                 return false;
6633             }
6634             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6635                 return false;
6636             }
6637             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6638                 return false;
6639             }
6640             t1.reRoot( t1.getNode( "A" ) );
6641             PhylogenyMethods.midpointRoot( t1 );
6642             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6643                 return false;
6644             }
6645             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6646                 return false;
6647             }
6648             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6649                 return false;
6650             }
6651             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6652                 return false;
6653             }
6654             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6655                 System.exit( -1 );
6656                 return false;
6657             }
6658             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6659                 return false;
6660             }
6661         }
6662         catch ( final Exception e ) {
6663             e.printStackTrace( System.out );
6664             return false;
6665         }
6666         return true;
6667     }
6668
6669     private static boolean testMsaQualityMethod() {
6670         try {
6671             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6672             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6673             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6674             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6675             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6676             l.add( s0 );
6677             l.add( s1 );
6678             l.add( s2 );
6679             l.add( s3 );
6680             final Msa msa = BasicMsa.createInstance( l );
6681             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6682                 return false;
6683             }
6684             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6685                 return false;
6686             }
6687             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6688                 return false;
6689             }
6690             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6691                 return false;
6692             }
6693             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6694                 return false;
6695             }
6696             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6697                 return false;
6698             }
6699             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6700                 return false;
6701             }
6702         }
6703         catch ( final Exception e ) {
6704             e.printStackTrace( System.out );
6705             return false;
6706         }
6707         return true;
6708     }
6709
6710     private static boolean testMsaEntropy() {
6711         try {
6712             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6713             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6714             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6715             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6716             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6717             l.add( s0 );
6718             l.add( s1 );
6719             l.add( s2 );
6720             l.add( s3 );
6721             final Msa msa = BasicMsa.createInstance( l );
6722             //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6723             //FIXME
6724             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6725             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6726             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6727             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6728             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6729             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6730             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6731             //            System.out.println();
6732             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6733             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6734             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6735             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6736             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6737             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6738             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6739             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6740             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6741             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6742             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6743             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6744             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6745             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6746             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6747             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6748             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6749             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6750             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6751             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6752             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6753             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6754             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6755             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6756             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6757             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6758             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6759             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6760             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6761             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6762             final Msa msa2 = BasicMsa.createInstance( l2 );
6763             //            System.out.println();
6764             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6765             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6766             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6767         }
6768         catch ( final Exception e ) {
6769             e.printStackTrace( System.out );
6770             return false;
6771         }
6772         return true;
6773     }
6774
6775     private static boolean testDeleteableMsa() {
6776         try {
6777             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6778             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6779             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6780             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6781             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6782             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6783             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6784             l0.add( s0 );
6785             l0.add( s1 );
6786             l0.add( s2 );
6787             l0.add( s3 );
6788             l0.add( s4 );
6789             l0.add( s5 );
6790             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6791             dmsa0.deleteRow( "b", false );
6792             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6793                 return false;
6794             }
6795             dmsa0.deleteRow( "e", false );
6796             dmsa0.deleteRow( "a", false );
6797             dmsa0.deleteRow( "f", false );
6798             if ( dmsa0.getLength() != 4 ) {
6799                 return false;
6800             }
6801             if ( dmsa0.getNumberOfSequences() != 2 ) {
6802                 return false;
6803             }
6804             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6805                 return false;
6806             }
6807             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6808                 return false;
6809             }
6810             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6811                 return false;
6812             }
6813             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6814                 return false;
6815             }
6816             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6817                 return false;
6818             }
6819             dmsa0.deleteRow( "c", false );
6820             dmsa0.deleteRow( "d", false );
6821             if ( dmsa0.getNumberOfSequences() != 0 ) {
6822                 return false;
6823             }
6824             //
6825             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6826             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6827             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6828             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6829             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6830             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6831             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6832             l1.add( s_0 );
6833             l1.add( s_1 );
6834             l1.add( s_2 );
6835             l1.add( s_3 );
6836             l1.add( s_4 );
6837             l1.add( s_5 );
6838             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6839             dmsa1.deleteGapOnlyColumns();
6840             dmsa1.deleteRow( "a", false );
6841             dmsa1.deleteRow( "f", false );
6842             dmsa1.deleteRow( "d", false );
6843             dmsa1.deleteGapOnlyColumns();
6844             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6845                 return false;
6846             }
6847             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6848                 return false;
6849             }
6850             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6851                 return false;
6852             }
6853             dmsa1.deleteRow( "c", false );
6854             dmsa1.deleteGapOnlyColumns();
6855             final Writer w0 = new StringWriter();
6856             dmsa1.write( w0, MSA_FORMAT.FASTA );
6857             final Writer w1 = new StringWriter();
6858             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6859             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6860                 return false;
6861             }
6862             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6863                 return false;
6864             }
6865             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6866             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6867             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6868             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6869             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6870             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6871             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6872             l2.add( s__0 );
6873             l2.add( s__1 );
6874             l2.add( s__2 );
6875             l2.add( s__3 );
6876             l2.add( s__4 );
6877             l2.add( s__5 );
6878             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6879             dmsa2.deleteGapColumns( 0.5 );
6880             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6881                 return false;
6882             }
6883             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6884                 return false;
6885             }
6886             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6887                 return false;
6888             }
6889             dmsa2.deleteGapColumns( 0.2 );
6890             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6891                 return false;
6892             }
6893             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6894                 return false;
6895             }
6896             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6897                 return false;
6898             }
6899             dmsa2.deleteGapColumns( 0 );
6900             dmsa2.deleteRow( "a", false );
6901             dmsa2.deleteRow( "b", false );
6902             dmsa2.deleteRow( "f", false );
6903             dmsa2.deleteRow( "e", false );
6904             dmsa2.setIdentifier( 0, "new_c" );
6905             dmsa2.setIdentifier( 1, "new_d" );
6906             dmsa2.setResidueAt( 0, 0, 'x' );
6907             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6908             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6909                 return false;
6910             }
6911             final Writer w = new StringWriter();
6912             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6913             final String phylip = w.toString();
6914             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6915                 System.out.println( phylip );
6916                 return false;
6917             }
6918             final Writer w2 = new StringWriter();
6919             dmsa2.write( w2, MSA_FORMAT.FASTA );
6920             final String fasta = w2.toString();
6921             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6922                 System.out.println( fasta );
6923                 return false;
6924             }
6925         }
6926         catch ( final Exception e ) {
6927             e.printStackTrace( System.out );
6928             return false;
6929         }
6930         return true;
6931     }
6932
6933     private static boolean testNextNodeWithCollapsing() {
6934         try {
6935             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6936             PhylogenyNode n;
6937             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6938             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6939             final Phylogeny t0 = factory.create( sb0.toString(), new NHXParser() )[ 0 ];
6940             t0.getNode( "cd" ).setCollapse( true );
6941             t0.getNode( "cde" ).setCollapse( true );
6942             n = t0.getFirstExternalNode();
6943             while ( n != null ) {
6944                 ext.add( n );
6945                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6946             }
6947             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6948                 return false;
6949             }
6950             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6951                 return false;
6952             }
6953             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6954                 return false;
6955             }
6956             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6957                 return false;
6958             }
6959             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6960                 return false;
6961             }
6962             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6963                 return false;
6964             }
6965             ext.clear();
6966             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6967             final Phylogeny t1 = factory.create( sb1.toString(), new NHXParser() )[ 0 ];
6968             t1.getNode( "ab" ).setCollapse( true );
6969             t1.getNode( "cd" ).setCollapse( true );
6970             t1.getNode( "cde" ).setCollapse( true );
6971             n = t1.getNode( "ab" );
6972             ext = new ArrayList<PhylogenyNode>();
6973             while ( n != null ) {
6974                 ext.add( n );
6975                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6976             }
6977             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6978                 return false;
6979             }
6980             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6981                 return false;
6982             }
6983             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6984                 return false;
6985             }
6986             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6987                 return false;
6988             }
6989             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6990                 return false;
6991             }
6992             ext.clear();
6993             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6994             final Phylogeny t2 = factory.create( sb2.toString(), new NHXParser() )[ 0 ];
6995             t2.getNode( "ab" ).setCollapse( true );
6996             t2.getNode( "cd" ).setCollapse( true );
6997             t2.getNode( "cde" ).setCollapse( true );
6998             t2.getNode( "c" ).setCollapse( true );
6999             t2.getNode( "d" ).setCollapse( true );
7000             t2.getNode( "e" ).setCollapse( true );
7001             t2.getNode( "gh" ).setCollapse( true );
7002             n = t2.getNode( "ab" );
7003             ext = new ArrayList<PhylogenyNode>();
7004             while ( n != null ) {
7005                 ext.add( n );
7006                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7007             }
7008             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7009                 return false;
7010             }
7011             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7012                 return false;
7013             }
7014             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
7015                 return false;
7016             }
7017             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
7018                 return false;
7019             }
7020             ext.clear();
7021             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7022             final Phylogeny t3 = factory.create( sb3.toString(), new NHXParser() )[ 0 ];
7023             t3.getNode( "ab" ).setCollapse( true );
7024             t3.getNode( "cd" ).setCollapse( true );
7025             t3.getNode( "cde" ).setCollapse( true );
7026             t3.getNode( "c" ).setCollapse( true );
7027             t3.getNode( "d" ).setCollapse( true );
7028             t3.getNode( "e" ).setCollapse( true );
7029             t3.getNode( "gh" ).setCollapse( true );
7030             t3.getNode( "fgh" ).setCollapse( true );
7031             n = t3.getNode( "ab" );
7032             ext = new ArrayList<PhylogenyNode>();
7033             while ( n != null ) {
7034                 ext.add( n );
7035                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7036             }
7037             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7038                 return false;
7039             }
7040             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7041                 return false;
7042             }
7043             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
7044                 return false;
7045             }
7046             ext.clear();
7047             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7048             final Phylogeny t4 = factory.create( sb4.toString(), new NHXParser() )[ 0 ];
7049             t4.getNode( "ab" ).setCollapse( true );
7050             t4.getNode( "cd" ).setCollapse( true );
7051             t4.getNode( "cde" ).setCollapse( true );
7052             t4.getNode( "c" ).setCollapse( true );
7053             t4.getNode( "d" ).setCollapse( true );
7054             t4.getNode( "e" ).setCollapse( true );
7055             t4.getNode( "gh" ).setCollapse( true );
7056             t4.getNode( "fgh" ).setCollapse( true );
7057             t4.getNode( "abcdefgh" ).setCollapse( true );
7058             n = t4.getNode( "abcdefgh" );
7059             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
7060                 return false;
7061             }
7062             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7063             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
7064             ext.clear();
7065             n = t5.getFirstExternalNode();
7066             while ( n != null ) {
7067                 ext.add( n );
7068                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7069             }
7070             if ( ext.size() != 8 ) {
7071                 return false;
7072             }
7073             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7074                 return false;
7075             }
7076             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7077                 return false;
7078             }
7079             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7080                 return false;
7081             }
7082             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7083                 return false;
7084             }
7085             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7086                 return false;
7087             }
7088             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7089                 return false;
7090             }
7091             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
7092                 return false;
7093             }
7094             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
7095                 return false;
7096             }
7097             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7098             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
7099             ext.clear();
7100             t6.getNode( "ab" ).setCollapse( true );
7101             n = t6.getNode( "ab" );
7102             while ( n != null ) {
7103                 ext.add( n );
7104                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7105             }
7106             if ( ext.size() != 7 ) {
7107                 return false;
7108             }
7109             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7110                 return false;
7111             }
7112             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7113                 return false;
7114             }
7115             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7116                 return false;
7117             }
7118             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7119                 return false;
7120             }
7121             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7122                 return false;
7123             }
7124             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7125                 return false;
7126             }
7127             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7128                 return false;
7129             }
7130             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7131             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
7132             ext.clear();
7133             t7.getNode( "cd" ).setCollapse( true );
7134             n = t7.getNode( "a" );
7135             while ( n != null ) {
7136                 ext.add( n );
7137                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7138             }
7139             if ( ext.size() != 7 ) {
7140                 return false;
7141             }
7142             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7143                 return false;
7144             }
7145             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7146                 return false;
7147             }
7148             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7149                 return false;
7150             }
7151             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7152                 return false;
7153             }
7154             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7155                 return false;
7156             }
7157             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7158                 return false;
7159             }
7160             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7161                 return false;
7162             }
7163             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7164             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
7165             ext.clear();
7166             t8.getNode( "cd" ).setCollapse( true );
7167             t8.getNode( "c" ).setCollapse( true );
7168             t8.getNode( "d" ).setCollapse( true );
7169             n = t8.getNode( "a" );
7170             while ( n != null ) {
7171                 ext.add( n );
7172                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7173             }
7174             if ( ext.size() != 7 ) {
7175                 return false;
7176             }
7177             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7178                 return false;
7179             }
7180             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7181                 return false;
7182             }
7183             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7184                 System.out.println( "2 fail" );
7185                 return false;
7186             }
7187             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7188                 return false;
7189             }
7190             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7191                 return false;
7192             }
7193             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7194                 return false;
7195             }
7196             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7197                 return false;
7198             }
7199             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7200             final Phylogeny t9 = factory.create( sb9.toString(), new NHXParser() )[ 0 ];
7201             ext.clear();
7202             t9.getNode( "gh" ).setCollapse( true );
7203             n = t9.getNode( "a" );
7204             while ( n != null ) {
7205                 ext.add( n );
7206                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7207             }
7208             if ( ext.size() != 7 ) {
7209                 return false;
7210             }
7211             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7212                 return false;
7213             }
7214             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7215                 return false;
7216             }
7217             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7218                 return false;
7219             }
7220             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7221                 return false;
7222             }
7223             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7224                 return false;
7225             }
7226             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7227                 return false;
7228             }
7229             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7230                 return false;
7231             }
7232             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7233             final Phylogeny t10 = factory.create( sb10.toString(), new NHXParser() )[ 0 ];
7234             ext.clear();
7235             t10.getNode( "gh" ).setCollapse( true );
7236             t10.getNode( "g" ).setCollapse( true );
7237             t10.getNode( "h" ).setCollapse( true );
7238             n = t10.getNode( "a" );
7239             while ( n != null ) {
7240                 ext.add( n );
7241                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7242             }
7243             if ( ext.size() != 7 ) {
7244                 return false;
7245             }
7246             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7247                 return false;
7248             }
7249             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7250                 return false;
7251             }
7252             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7253                 return false;
7254             }
7255             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7256                 return false;
7257             }
7258             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7259                 return false;
7260             }
7261             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7262                 return false;
7263             }
7264             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7265                 return false;
7266             }
7267             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7268             final Phylogeny t11 = factory.create( sb11.toString(), new NHXParser() )[ 0 ];
7269             ext.clear();
7270             t11.getNode( "gh" ).setCollapse( true );
7271             t11.getNode( "fgh" ).setCollapse( true );
7272             n = t11.getNode( "a" );
7273             while ( n != null ) {
7274                 ext.add( n );
7275                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7276             }
7277             if ( ext.size() != 6 ) {
7278                 return false;
7279             }
7280             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7281                 return false;
7282             }
7283             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7284                 return false;
7285             }
7286             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7287                 return false;
7288             }
7289             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7290                 return false;
7291             }
7292             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7293                 return false;
7294             }
7295             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7296                 return false;
7297             }
7298             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7299             final Phylogeny t12 = factory.create( sb12.toString(), new NHXParser() )[ 0 ];
7300             ext.clear();
7301             t12.getNode( "gh" ).setCollapse( true );
7302             t12.getNode( "fgh" ).setCollapse( true );
7303             t12.getNode( "g" ).setCollapse( true );
7304             t12.getNode( "h" ).setCollapse( true );
7305             t12.getNode( "f" ).setCollapse( true );
7306             n = t12.getNode( "a" );
7307             while ( n != null ) {
7308                 ext.add( n );
7309                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7310             }
7311             if ( ext.size() != 6 ) {
7312                 return false;
7313             }
7314             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7315                 return false;
7316             }
7317             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7318                 return false;
7319             }
7320             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7321                 return false;
7322             }
7323             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7324                 return false;
7325             }
7326             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7327                 return false;
7328             }
7329             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7330                 return false;
7331             }
7332             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7333             final Phylogeny t13 = factory.create( sb13.toString(), new NHXParser() )[ 0 ];
7334             ext.clear();
7335             t13.getNode( "ab" ).setCollapse( true );
7336             t13.getNode( "b" ).setCollapse( true );
7337             t13.getNode( "fgh" ).setCollapse( true );
7338             t13.getNode( "gh" ).setCollapse( true );
7339             n = t13.getNode( "ab" );
7340             while ( n != null ) {
7341                 ext.add( n );
7342                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7343             }
7344             if ( ext.size() != 5 ) {
7345                 return false;
7346             }
7347             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7348                 return false;
7349             }
7350             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7351                 return false;
7352             }
7353             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7354                 return false;
7355             }
7356             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7357                 return false;
7358             }
7359             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7360                 return false;
7361             }
7362             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
7363             final Phylogeny t14 = factory.create( sb14.toString(), new NHXParser() )[ 0 ];
7364             ext.clear();
7365             t14.getNode( "ab" ).setCollapse( true );
7366             t14.getNode( "a" ).setCollapse( true );
7367             t14.getNode( "fgh" ).setCollapse( true );
7368             t14.getNode( "gh" ).setCollapse( true );
7369             n = t14.getNode( "ab" );
7370             while ( n != null ) {
7371                 ext.add( n );
7372                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7373             }
7374             if ( ext.size() != 5 ) {
7375                 return false;
7376             }
7377             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7378                 return false;
7379             }
7380             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7381                 return false;
7382             }
7383             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7384                 return false;
7385             }
7386             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7387                 return false;
7388             }
7389             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7390                 return false;
7391             }
7392             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" );
7393             final Phylogeny t15 = factory.create( sb15.toString(), new NHXParser() )[ 0 ];
7394             ext.clear();
7395             t15.getNode( "ab" ).setCollapse( true );
7396             t15.getNode( "a" ).setCollapse( true );
7397             t15.getNode( "fgh" ).setCollapse( true );
7398             t15.getNode( "gh" ).setCollapse( true );
7399             n = t15.getNode( "ab" );
7400             while ( n != null ) {
7401                 ext.add( n );
7402                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7403             }
7404             if ( ext.size() != 6 ) {
7405                 return false;
7406             }
7407             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7408                 return false;
7409             }
7410             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7411                 return false;
7412             }
7413             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7414                 return false;
7415             }
7416             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7417                 return false;
7418             }
7419             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
7420                 return false;
7421             }
7422             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7423                 return false;
7424             }
7425             //
7426             //
7427             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" );
7428             final Phylogeny t16 = factory.create( sb16.toString(), new NHXParser() )[ 0 ];
7429             ext.clear();
7430             t16.getNode( "ab" ).setCollapse( true );
7431             t16.getNode( "a" ).setCollapse( true );
7432             t16.getNode( "fgh" ).setCollapse( true );
7433             t16.getNode( "gh" ).setCollapse( true );
7434             t16.getNode( "cd" ).setCollapse( true );
7435             t16.getNode( "cde" ).setCollapse( true );
7436             t16.getNode( "d" ).setCollapse( true );
7437             t16.getNode( "x" ).setCollapse( true );
7438             n = t16.getNode( "ab" );
7439             while ( n != null ) {
7440                 ext.add( n );
7441                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7442             }
7443             if ( ext.size() != 4 ) {
7444                 return false;
7445             }
7446             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7447                 return false;
7448             }
7449             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7450                 return false;
7451             }
7452             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
7453                 return false;
7454             }
7455             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
7456                 return false;
7457             }
7458         }
7459         catch ( final Exception e ) {
7460             e.printStackTrace( System.out );
7461             return false;
7462         }
7463         return true;
7464     }
7465
7466     private static boolean testNexusCharactersParsing() {
7467         try {
7468             final NexusCharactersParser parser = new NexusCharactersParser();
7469             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
7470             parser.parse();
7471             String[] labels = parser.getCharStateLabels();
7472             if ( labels.length != 7 ) {
7473                 return false;
7474             }
7475             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7476                 return false;
7477             }
7478             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7479                 return false;
7480             }
7481             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7482                 return false;
7483             }
7484             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7485                 return false;
7486             }
7487             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7488                 return false;
7489             }
7490             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7491                 return false;
7492             }
7493             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7494                 return false;
7495             }
7496             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7497             parser.parse();
7498             labels = parser.getCharStateLabels();
7499             if ( labels.length != 7 ) {
7500                 return false;
7501             }
7502             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7503                 return false;
7504             }
7505             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7506                 return false;
7507             }
7508             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7509                 return false;
7510             }
7511             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7512                 return false;
7513             }
7514             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7515                 return false;
7516             }
7517             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7518                 return false;
7519             }
7520             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7521                 return false;
7522             }
7523         }
7524         catch ( final Exception e ) {
7525             e.printStackTrace( System.out );
7526             return false;
7527         }
7528         return true;
7529     }
7530
7531     private static boolean testNexusMatrixParsing() {
7532         try {
7533             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7534             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7535             parser.parse();
7536             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7537             if ( m.getNumberOfCharacters() != 9 ) {
7538                 return false;
7539             }
7540             if ( m.getNumberOfIdentifiers() != 5 ) {
7541                 return false;
7542             }
7543             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7544                 return false;
7545             }
7546             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7547                 return false;
7548             }
7549             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7550                 return false;
7551             }
7552             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7553                 return false;
7554             }
7555             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7556                 return false;
7557             }
7558             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7559                 return false;
7560             }
7561             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7562                 return false;
7563             }
7564             //            if ( labels.length != 7 ) {
7565             //                return false;
7566             //            }
7567             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7568             //                return false;
7569             //            }
7570             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7571             //                return false;
7572             //            }
7573             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7574             //                return false;
7575             //            }
7576             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7577             //                return false;
7578             //            }
7579             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7580             //                return false;
7581             //            }
7582             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7583             //                return false;
7584             //            }
7585             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7586             //                return false;
7587             //            }
7588             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7589             //            parser.parse();
7590             //            labels = parser.getCharStateLabels();
7591             //            if ( labels.length != 7 ) {
7592             //                return false;
7593             //            }
7594             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7595             //                return false;
7596             //            }
7597             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7598             //                return false;
7599             //            }
7600             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7601             //                return false;
7602             //            }
7603             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7604             //                return false;
7605             //            }
7606             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7607             //                return false;
7608             //            }
7609             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7610             //                return false;
7611             //            }
7612             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7613             //                return false;
7614             //            }
7615         }
7616         catch ( final Exception e ) {
7617             e.printStackTrace( System.out );
7618             return false;
7619         }
7620         return true;
7621     }
7622
7623     private static boolean testNexusTreeParsing() {
7624         try {
7625             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7626             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7627             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7628             if ( phylogenies.length != 1 ) {
7629                 return false;
7630             }
7631             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7632                 return false;
7633             }
7634             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7635                 return false;
7636             }
7637             phylogenies = null;
7638             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7639             if ( phylogenies.length != 1 ) {
7640                 return false;
7641             }
7642             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7643                 return false;
7644             }
7645             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7646                 return false;
7647             }
7648             phylogenies = null;
7649             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7650             if ( phylogenies.length != 1 ) {
7651                 return false;
7652             }
7653             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7654                 return false;
7655             }
7656             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7657                 return false;
7658             }
7659             if ( phylogenies[ 0 ].isRooted() ) {
7660                 return false;
7661             }
7662             phylogenies = null;
7663             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7664             if ( phylogenies.length != 18 ) {
7665                 return false;
7666             }
7667             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7668                 return false;
7669             }
7670             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7671                 return false;
7672             }
7673             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7674                 return false;
7675             }
7676             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7677                 return false;
7678             }
7679             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7680                 return false;
7681             }
7682             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7683                 return false;
7684             }
7685             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7686                 return false;
7687             }
7688             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7689                 return false;
7690             }
7691             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7692                 return false;
7693             }
7694             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7695                 return false;
7696             }
7697             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7698                 return false;
7699             }
7700             if ( phylogenies[ 8 ].isRooted() ) {
7701                 return false;
7702             }
7703             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7704                 return false;
7705             }
7706             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7707                 return false;
7708             }
7709             if ( !phylogenies[ 9 ].isRooted() ) {
7710                 return false;
7711             }
7712             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7713                 return false;
7714             }
7715             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7716                 return false;
7717             }
7718             if ( !phylogenies[ 10 ].isRooted() ) {
7719                 return false;
7720             }
7721             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7722                 return false;
7723             }
7724             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7725                 return false;
7726             }
7727             if ( phylogenies[ 11 ].isRooted() ) {
7728                 return false;
7729             }
7730             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7731                 return false;
7732             }
7733             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7734                 return false;
7735             }
7736             if ( !phylogenies[ 12 ].isRooted() ) {
7737                 return false;
7738             }
7739             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7740                 return false;
7741             }
7742             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7743                 return false;
7744             }
7745             if ( !phylogenies[ 13 ].isRooted() ) {
7746                 return false;
7747             }
7748             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7749                 return false;
7750             }
7751             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7752                 return false;
7753             }
7754             if ( !phylogenies[ 14 ].isRooted() ) {
7755                 return false;
7756             }
7757             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7758                 return false;
7759             }
7760             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7761                 return false;
7762             }
7763             if ( phylogenies[ 15 ].isRooted() ) {
7764                 return false;
7765             }
7766             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7767                 return false;
7768             }
7769             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7770                 return false;
7771             }
7772             if ( !phylogenies[ 16 ].isRooted() ) {
7773                 return false;
7774             }
7775             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7776                 return false;
7777             }
7778             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7779                 return false;
7780             }
7781             if ( phylogenies[ 17 ].isRooted() ) {
7782                 return false;
7783             }
7784             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7785                 return false;
7786             }
7787             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7788             phylogenies = null;
7789             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7790             if ( phylogenies.length != 9 ) {
7791                 return false;
7792             }
7793             if ( !isEqual( 0.48039661496919533,
7794                            phylogenies[ 0 ].getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7795                 return false;
7796             }
7797             if ( !isEqual( 0.3959796191512233,
7798                            phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7799                 return false;
7800             }
7801             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7802                 return false;
7803             }
7804             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7805                 return false;
7806             }
7807             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7808                 return false;
7809             }
7810             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7811                 return false;
7812             }
7813             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7814                 return false;
7815             }
7816         }
7817         catch ( final Exception e ) {
7818             e.printStackTrace( System.out );
7819             return false;
7820         }
7821         return true;
7822     }
7823
7824     private static boolean testNexusTreeParsingIterating() {
7825         try {
7826             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7827             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7828             if ( !p.hasNext() ) {
7829                 return false;
7830             }
7831             Phylogeny phy = p.next();
7832             if ( phy == null ) {
7833                 return false;
7834             }
7835             if ( phy.getNumberOfExternalNodes() != 25 ) {
7836                 return false;
7837             }
7838             if ( !phy.getName().equals( "" ) ) {
7839                 return false;
7840             }
7841             if ( p.hasNext() ) {
7842                 return false;
7843             }
7844             phy = p.next();
7845             if ( phy != null ) {
7846                 return false;
7847             }
7848             p.reset();
7849             if ( !p.hasNext() ) {
7850                 return false;
7851             }
7852             phy = p.next();
7853             if ( phy == null ) {
7854                 return false;
7855             }
7856             if ( phy.getNumberOfExternalNodes() != 25 ) {
7857                 return false;
7858             }
7859             if ( !phy.getName().equals( "" ) ) {
7860                 return false;
7861             }
7862             if ( p.hasNext() ) {
7863                 return false;
7864             }
7865             phy = p.next();
7866             if ( phy != null ) {
7867                 return false;
7868             }
7869             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7870             if ( !p.hasNext() ) {
7871                 return false;
7872             }
7873             phy = p.next();
7874             if ( phy == null ) {
7875                 return false;
7876             }
7877             if ( phy.getNumberOfExternalNodes() != 10 ) {
7878                 return false;
7879             }
7880             if ( !phy.getName().equals( "name" ) ) {
7881                 return false;
7882             }
7883             if ( p.hasNext() ) {
7884                 return false;
7885             }
7886             phy = p.next();
7887             if ( phy != null ) {
7888                 return false;
7889             }
7890             p.reset();
7891             if ( !p.hasNext() ) {
7892                 return false;
7893             }
7894             phy = p.next();
7895             if ( phy == null ) {
7896                 return false;
7897             }
7898             if ( phy.getNumberOfExternalNodes() != 10 ) {
7899                 return false;
7900             }
7901             if ( !phy.getName().equals( "name" ) ) {
7902                 return false;
7903             }
7904             if ( p.hasNext() ) {
7905                 return false;
7906             }
7907             phy = p.next();
7908             if ( phy != null ) {
7909                 return false;
7910             }
7911             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7912             if ( !p.hasNext() ) {
7913                 return false;
7914             }
7915             phy = p.next();
7916             if ( phy == null ) {
7917                 return false;
7918             }
7919             if ( phy.getNumberOfExternalNodes() != 3 ) {
7920                 return false;
7921             }
7922             if ( !phy.getName().equals( "" ) ) {
7923                 return false;
7924             }
7925             if ( phy.isRooted() ) {
7926                 return false;
7927             }
7928             if ( p.hasNext() ) {
7929                 return false;
7930             }
7931             phy = p.next();
7932             if ( phy != null ) {
7933                 return false;
7934             }
7935             //
7936             p.reset();
7937             if ( !p.hasNext() ) {
7938                 return false;
7939             }
7940             phy = p.next();
7941             if ( phy == null ) {
7942                 return false;
7943             }
7944             if ( phy.getNumberOfExternalNodes() != 3 ) {
7945                 return false;
7946             }
7947             if ( !phy.getName().equals( "" ) ) {
7948                 return false;
7949             }
7950             if ( p.hasNext() ) {
7951                 return false;
7952             }
7953             phy = p.next();
7954             if ( phy != null ) {
7955                 return false;
7956             }
7957             //
7958             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7959             if ( !p.hasNext() ) {
7960                 return false;
7961             }
7962             //0
7963             phy = p.next();
7964             if ( phy == null ) {
7965                 return false;
7966             }
7967             if ( phy.getNumberOfExternalNodes() != 10 ) {
7968                 return false;
7969             }
7970             if ( !phy.getName().equals( "tree 0" ) ) {
7971                 return false;
7972             }
7973             //1
7974             if ( !p.hasNext() ) {
7975                 return false;
7976             }
7977             phy = p.next();
7978             if ( phy == null ) {
7979                 return false;
7980             }
7981             if ( phy.getNumberOfExternalNodes() != 10 ) {
7982                 return false;
7983             }
7984             if ( !phy.getName().equals( "tree 1" ) ) {
7985                 return false;
7986             }
7987             //2
7988             if ( !p.hasNext() ) {
7989                 return false;
7990             }
7991             phy = p.next();
7992             if ( phy == null ) {
7993                 return false;
7994             }
7995             if ( phy.getNumberOfExternalNodes() != 3 ) {
7996                 System.out.println( phy.toString() );
7997                 return false;
7998             }
7999             if ( !phy.getName().equals( "" ) ) {
8000                 return false;
8001             }
8002             if ( phy.isRooted() ) {
8003                 return false;
8004             }
8005             //3
8006             if ( !p.hasNext() ) {
8007                 return false;
8008             }
8009             phy = p.next();
8010             if ( phy == null ) {
8011                 return false;
8012             }
8013             if ( phy.getNumberOfExternalNodes() != 4 ) {
8014                 return false;
8015             }
8016             if ( !phy.getName().equals( "" ) ) {
8017                 return false;
8018             }
8019             if ( !phy.isRooted() ) {
8020                 return false;
8021             }
8022             //4
8023             if ( !p.hasNext() ) {
8024                 return false;
8025             }
8026             phy = p.next();
8027             if ( phy == null ) {
8028                 return false;
8029             }
8030             if ( phy.getNumberOfExternalNodes() != 5 ) {
8031                 System.out.println( phy.getNumberOfExternalNodes() );
8032                 return false;
8033             }
8034             if ( !phy.getName().equals( "" ) ) {
8035                 return false;
8036             }
8037             if ( !phy.isRooted() ) {
8038                 return false;
8039             }
8040             //5
8041             if ( !p.hasNext() ) {
8042                 return false;
8043             }
8044             phy = p.next();
8045             if ( phy == null ) {
8046                 return false;
8047             }
8048             if ( phy.getNumberOfExternalNodes() != 3 ) {
8049                 return false;
8050             }
8051             if ( !phy.getName().equals( "" ) ) {
8052                 return false;
8053             }
8054             if ( phy.isRooted() ) {
8055                 return false;
8056             }
8057             //6
8058             if ( !p.hasNext() ) {
8059                 return false;
8060             }
8061             phy = p.next();
8062             if ( phy == null ) {
8063                 return false;
8064             }
8065             if ( phy.getNumberOfExternalNodes() != 2 ) {
8066                 return false;
8067             }
8068             if ( !phy.getName().equals( "" ) ) {
8069                 return false;
8070             }
8071             if ( !phy.isRooted() ) {
8072                 return false;
8073             }
8074             //7
8075             if ( !p.hasNext() ) {
8076                 return false;
8077             }
8078             phy = p.next();
8079             if ( phy.getNumberOfExternalNodes() != 3 ) {
8080                 return false;
8081             }
8082             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8083                 return false;
8084             }
8085             if ( !phy.isRooted() ) {
8086                 return false;
8087             }
8088             //8
8089             if ( !p.hasNext() ) {
8090                 return false;
8091             }
8092             phy = p.next();
8093             if ( phy.getNumberOfExternalNodes() != 3 ) {
8094                 return false;
8095             }
8096             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
8097                 return false;
8098             }
8099             if ( !phy.getName().equals( "tree 8" ) ) {
8100                 return false;
8101             }
8102             //9
8103             if ( !p.hasNext() ) {
8104                 return false;
8105             }
8106             phy = p.next();
8107             if ( phy.getNumberOfExternalNodes() != 3 ) {
8108                 return false;
8109             }
8110             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
8111                 return false;
8112             }
8113             if ( !phy.getName().equals( "tree 9" ) ) {
8114                 return false;
8115             }
8116             //10
8117             if ( !p.hasNext() ) {
8118                 return false;
8119             }
8120             phy = p.next();
8121             if ( phy.getNumberOfExternalNodes() != 3 ) {
8122                 return false;
8123             }
8124             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8125                 return false;
8126             }
8127             if ( !phy.getName().equals( "tree 10" ) ) {
8128                 return false;
8129             }
8130             if ( !phy.isRooted() ) {
8131                 return false;
8132             }
8133             //11
8134             if ( !p.hasNext() ) {
8135                 return false;
8136             }
8137             phy = p.next();
8138             if ( phy.getNumberOfExternalNodes() != 3 ) {
8139                 return false;
8140             }
8141             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
8142                 return false;
8143             }
8144             if ( !phy.getName().equals( "tree 11" ) ) {
8145                 return false;
8146             }
8147             if ( phy.isRooted() ) {
8148                 return false;
8149             }
8150             //12
8151             if ( !p.hasNext() ) {
8152                 return false;
8153             }
8154             phy = p.next();
8155             if ( phy.getNumberOfExternalNodes() != 3 ) {
8156                 return false;
8157             }
8158             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
8159                 return false;
8160             }
8161             if ( !phy.getName().equals( "tree 12" ) ) {
8162                 return false;
8163             }
8164             if ( !phy.isRooted() ) {
8165                 return false;
8166             }
8167             //13
8168             if ( !p.hasNext() ) {
8169                 return false;
8170             }
8171             phy = p.next();
8172             if ( phy.getNumberOfExternalNodes() != 3 ) {
8173                 return false;
8174             }
8175             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8176                 return false;
8177             }
8178             if ( !phy.getName().equals( "tree 13" ) ) {
8179                 return false;
8180             }
8181             if ( !phy.isRooted() ) {
8182                 return false;
8183             }
8184             //14
8185             if ( !p.hasNext() ) {
8186                 return false;
8187             }
8188             phy = p.next();
8189             if ( phy.getNumberOfExternalNodes() != 10 ) {
8190                 System.out.println( phy.getNumberOfExternalNodes() );
8191                 return false;
8192             }
8193             if ( !phy.toNewHampshire()
8194                     .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;" ) ) {
8195                 System.out.println( phy.toNewHampshire() );
8196                 return false;
8197             }
8198             if ( !phy.getName().equals( "tree 14" ) ) {
8199                 return false;
8200             }
8201             if ( !phy.isRooted() ) {
8202                 return false;
8203             }
8204             //15
8205             if ( !p.hasNext() ) {
8206                 return false;
8207             }
8208             phy = p.next();
8209             if ( phy.getNumberOfExternalNodes() != 10 ) {
8210                 System.out.println( phy.getNumberOfExternalNodes() );
8211                 return false;
8212             }
8213             if ( !phy.toNewHampshire()
8214                     .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;" ) ) {
8215                 System.out.println( phy.toNewHampshire() );
8216                 return false;
8217             }
8218             if ( !phy.getName().equals( "tree 15" ) ) {
8219                 return false;
8220             }
8221             if ( phy.isRooted() ) {
8222                 return false;
8223             }
8224             //16
8225             if ( !p.hasNext() ) {
8226                 return false;
8227             }
8228             phy = p.next();
8229             if ( phy.getNumberOfExternalNodes() != 10 ) {
8230                 System.out.println( phy.getNumberOfExternalNodes() );
8231                 return false;
8232             }
8233             if ( !phy.toNewHampshire()
8234                     .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;" ) ) {
8235                 System.out.println( phy.toNewHampshire() );
8236                 return false;
8237             }
8238             if ( !phy.getName().equals( "tree 16" ) ) {
8239                 return false;
8240             }
8241             if ( !phy.isRooted() ) {
8242                 return false;
8243             }
8244             //17
8245             if ( !p.hasNext() ) {
8246                 return false;
8247             }
8248             phy = p.next();
8249             if ( phy.getNumberOfExternalNodes() != 10 ) {
8250                 System.out.println( phy.getNumberOfExternalNodes() );
8251                 return false;
8252             }
8253             if ( !phy.toNewHampshire()
8254                     .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;" ) ) {
8255                 System.out.println( phy.toNewHampshire() );
8256                 return false;
8257             }
8258             if ( !phy.getName().equals( "tree 17" ) ) {
8259                 return false;
8260             }
8261             if ( phy.isRooted() ) {
8262                 return false;
8263             }
8264             //
8265             if ( p.hasNext() ) {
8266                 return false;
8267             }
8268             phy = p.next();
8269             if ( phy != null ) {
8270                 return false;
8271             }
8272             p.reset();
8273             //0
8274             if ( !p.hasNext() ) {
8275                 return false;
8276             }
8277             phy = p.next();
8278             if ( phy == null ) {
8279                 return false;
8280             }
8281             if ( phy.getNumberOfExternalNodes() != 10 ) {
8282                 return false;
8283             }
8284             if ( !phy.getName().equals( "tree 0" ) ) {
8285                 return false;
8286             }
8287             //1
8288             if ( !p.hasNext() ) {
8289                 return false;
8290             }
8291             phy = p.next();
8292             if ( phy == null ) {
8293                 return false;
8294             }
8295             if ( phy.getNumberOfExternalNodes() != 10 ) {
8296                 return false;
8297             }
8298             if ( !phy.getName().equals( "tree 1" ) ) {
8299                 return false;
8300             }
8301             //2
8302             if ( !p.hasNext() ) {
8303                 return false;
8304             }
8305             phy = p.next();
8306             if ( phy == null ) {
8307                 return false;
8308             }
8309             if ( phy.getNumberOfExternalNodes() != 3 ) {
8310                 return false;
8311             }
8312             if ( !phy.getName().equals( "" ) ) {
8313                 return false;
8314             }
8315             if ( phy.isRooted() ) {
8316                 return false;
8317             }
8318             //3
8319             if ( !p.hasNext() ) {
8320                 return false;
8321             }
8322             phy = p.next();
8323             if ( phy == null ) {
8324                 return false;
8325             }
8326             if ( phy.getNumberOfExternalNodes() != 4 ) {
8327                 return false;
8328             }
8329             if ( !phy.getName().equals( "" ) ) {
8330                 return false;
8331             }
8332             if ( !phy.isRooted() ) {
8333                 return false;
8334             }
8335             //4
8336             if ( !p.hasNext() ) {
8337                 return false;
8338             }
8339             phy = p.next();
8340             if ( phy == null ) {
8341                 return false;
8342             }
8343             if ( phy.getNumberOfExternalNodes() != 5 ) {
8344                 System.out.println( phy.getNumberOfExternalNodes() );
8345                 return false;
8346             }
8347             if ( !phy.getName().equals( "" ) ) {
8348                 return false;
8349             }
8350             if ( !phy.isRooted() ) {
8351                 return false;
8352             }
8353             //5
8354             if ( !p.hasNext() ) {
8355                 return false;
8356             }
8357             phy = p.next();
8358             if ( phy == null ) {
8359                 return false;
8360             }
8361             if ( phy.getNumberOfExternalNodes() != 3 ) {
8362                 return false;
8363             }
8364             if ( !phy.getName().equals( "" ) ) {
8365                 return false;
8366             }
8367             if ( phy.isRooted() ) {
8368                 return false;
8369             }
8370             //
8371             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
8372             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
8373             // 0
8374             if ( !p2.hasNext() ) {
8375                 return false;
8376             }
8377             phy = p2.next();
8378             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8379                 return false;
8380             }
8381             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8382                 return false;
8383             }
8384             // 1
8385             if ( !p2.hasNext() ) {
8386                 return false;
8387             }
8388             phy = p2.next();
8389             // 2
8390             if ( !p2.hasNext() ) {
8391                 return false;
8392             }
8393             phy = p2.next();
8394             // 3
8395             if ( !p2.hasNext() ) {
8396                 return false;
8397             }
8398             phy = p2.next();
8399             // 4
8400             if ( !p2.hasNext() ) {
8401                 return false;
8402             }
8403             phy = p2.next();
8404             // 5
8405             if ( !p2.hasNext() ) {
8406                 return false;
8407             }
8408             phy = p2.next();
8409             // 6
8410             if ( !p2.hasNext() ) {
8411                 return false;
8412             }
8413             phy = p2.next();
8414             // 7
8415             if ( !p2.hasNext() ) {
8416                 return false;
8417             }
8418             phy = p2.next();
8419             // 8
8420             if ( !p2.hasNext() ) {
8421                 return false;
8422             }
8423             phy = p2.next();
8424             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
8425                 return false;
8426             }
8427             if ( p2.hasNext() ) {
8428                 return false;
8429             }
8430             phy = p2.next();
8431             if ( phy != null ) {
8432                 return false;
8433             }
8434             // 0
8435             p2.reset();
8436             if ( !p2.hasNext() ) {
8437                 return false;
8438             }
8439             phy = p2.next();
8440             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8441                 return false;
8442             }
8443             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8444                 return false;
8445             }
8446         }
8447         catch ( final Exception e ) {
8448             e.printStackTrace( System.out );
8449             return false;
8450         }
8451         return true;
8452     }
8453
8454     private static boolean testNexusTreeParsingTranslating() {
8455         try {
8456             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8457             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
8458             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
8459             if ( phylogenies.length != 1 ) {
8460                 return false;
8461             }
8462             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8463                 return false;
8464             }
8465             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8466                 return false;
8467             }
8468             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8469                 return false;
8470             }
8471             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8472                 return false;
8473             }
8474             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8475                     .equals( "Aranaeus" ) ) {
8476                 return false;
8477             }
8478             phylogenies = null;
8479             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
8480             if ( phylogenies.length != 3 ) {
8481                 return false;
8482             }
8483             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8484                 return false;
8485             }
8486             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8487                 return false;
8488             }
8489             if ( phylogenies[ 0 ].isRooted() ) {
8490                 return false;
8491             }
8492             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8493                 return false;
8494             }
8495             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8496                 return false;
8497             }
8498             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8499                     .equals( "Aranaeus" ) ) {
8500                 return false;
8501             }
8502             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8503                 return false;
8504             }
8505             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8506                 return false;
8507             }
8508             if ( phylogenies[ 1 ].isRooted() ) {
8509                 return false;
8510             }
8511             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8512                 return false;
8513             }
8514             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8515                 return false;
8516             }
8517             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8518                     .equals( "Aranaeus" ) ) {
8519                 return false;
8520             }
8521             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8522                 return false;
8523             }
8524             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8525                 return false;
8526             }
8527             if ( !phylogenies[ 2 ].isRooted() ) {
8528                 return false;
8529             }
8530             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8531                 return false;
8532             }
8533             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8534                 return false;
8535             }
8536             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8537                     .equals( "Aranaeus" ) ) {
8538                 return false;
8539             }
8540             phylogenies = null;
8541             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8542             if ( phylogenies.length != 3 ) {
8543                 return false;
8544             }
8545             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8546                 return false;
8547             }
8548             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8549                 return false;
8550             }
8551             if ( phylogenies[ 0 ].isRooted() ) {
8552                 return false;
8553             }
8554             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8555                 return false;
8556             }
8557             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8558                 return false;
8559             }
8560             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8561                     .equals( "Aranaeus" ) ) {
8562                 return false;
8563             }
8564             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8565                 return false;
8566             }
8567             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8568                 return false;
8569             }
8570             if ( phylogenies[ 1 ].isRooted() ) {
8571                 return false;
8572             }
8573             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8574                 return false;
8575             }
8576             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8577                 return false;
8578             }
8579             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8580                     .equals( "Aranaeus" ) ) {
8581                 return false;
8582             }
8583             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8584                 return false;
8585             }
8586             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8587                 return false;
8588             }
8589             if ( !phylogenies[ 2 ].isRooted() ) {
8590                 return false;
8591             }
8592             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8593                 return false;
8594             }
8595             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8596                 return false;
8597             }
8598             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8599                     .equals( "Aranaeus" ) ) {
8600                 return false;
8601             }
8602             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8603             if ( phylogenies.length != 3 ) {
8604                 return false;
8605             }
8606             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8607                            0.00100049 ) ) {
8608                 return false;
8609             }
8610         }
8611         catch ( final Exception e ) {
8612             e.printStackTrace( System.out );
8613             return false;
8614         }
8615         return true;
8616     }
8617
8618     private static boolean testNHParsing() {
8619         try {
8620             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8621             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8622             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8623                 return false;
8624             }
8625             final NHXParser nhxp = new NHXParser();
8626             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8627             nhxp.setReplaceUnderscores( true );
8628             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8629             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8630                 return false;
8631             }
8632             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8633                 return false;
8634             }
8635             final Phylogeny p1b = factory.create(
8636                                                   "   \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 ",
8637                                                   new NHXParser() )[ 0 ];
8638             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8639                 return false;
8640             }
8641             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8642                 return false;
8643             }
8644             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ).toString(), new NHXParser() )[ 0 ];
8645             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8646             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8647             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ).toString(), new NHXParser() )[ 0 ];
8648             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8649             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8650             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8651             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8652             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8653             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8654             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8655                     + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; " + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8656                                                     new NHXParser() );
8657             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8658                 return false;
8659             }
8660             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8661                 return false;
8662             }
8663             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8664                 return false;
8665             }
8666             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8667                 return false;
8668             }
8669             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8670             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8671             final String p16_S = "((A,B),C)";
8672             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8673             if ( p16.length != 1 ) {
8674                 return false;
8675             }
8676             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8677                 return false;
8678             }
8679             final String p17_S = "(C,(A,B))";
8680             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8681             if ( p17.length != 1 ) {
8682                 return false;
8683             }
8684             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8685                 return false;
8686             }
8687             final String p18_S = "((A,B),(C,D))";
8688             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8689             if ( p18.length != 1 ) {
8690                 return false;
8691             }
8692             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8693                 return false;
8694             }
8695             final String p19_S = "(((A,B),C),D)";
8696             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8697             if ( p19.length != 1 ) {
8698                 return false;
8699             }
8700             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8701                 return false;
8702             }
8703             final String p20_S = "(A,(B,(C,D)))";
8704             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8705             if ( p20.length != 1 ) {
8706                 return false;
8707             }
8708             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8709                 return false;
8710             }
8711             final String p21_S = "(A,(B,(C,(D,E))))";
8712             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8713             if ( p21.length != 1 ) {
8714                 return false;
8715             }
8716             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8717                 return false;
8718             }
8719             final String p22_S = "((((A,B),C),D),E)";
8720             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8721             if ( p22.length != 1 ) {
8722                 return false;
8723             }
8724             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8725                 return false;
8726             }
8727             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8728             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8729             if ( p23.length != 1 ) {
8730                 System.out.println( "xl=" + p23.length );
8731                 System.exit( -1 );
8732                 return false;
8733             }
8734             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8735                 return false;
8736             }
8737             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8738             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8739             if ( p24.length != 1 ) {
8740                 return false;
8741             }
8742             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8743                 return false;
8744             }
8745             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8746             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8747             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8748             if ( p241.length != 2 ) {
8749                 return false;
8750             }
8751             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8752                 return false;
8753             }
8754             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8755                 return false;
8756             }
8757             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8758                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8759                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8760                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8761                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8762                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8763                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8764                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8765             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8766             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8767                 return false;
8768             }
8769             final String p26_S = "(A,B)ab";
8770             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8771             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8772                 return false;
8773             }
8774             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8775             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8776             if ( p27s.length != 1 ) {
8777                 System.out.println( "xxl=" + p27s.length );
8778                 System.exit( -1 );
8779                 return false;
8780             }
8781             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8782                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8783                 System.exit( -1 );
8784                 return false;
8785             }
8786             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8787                                                     new NHXParser() );
8788             if ( p27.length != 1 ) {
8789                 System.out.println( "yl=" + p27.length );
8790                 System.exit( -1 );
8791                 return false;
8792             }
8793             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8794                 System.out.println( p27[ 0 ].toNewHampshireX() );
8795                 System.exit( -1 );
8796                 return false;
8797             }
8798             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8799             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8800             final String p28_S3 = "(A,B)ab";
8801             final String p28_S4 = "((((A,B),C),D),;E;)";
8802             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8803                                                     new NHXParser() );
8804             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8805                 return false;
8806             }
8807             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8808                 return false;
8809             }
8810             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8811                 return false;
8812             }
8813             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8814                 return false;
8815             }
8816             if ( p28.length != 4 ) {
8817                 return false;
8818             }
8819             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";
8820             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8821             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8822                 return false;
8823             }
8824             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";
8825             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8826             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8827                 return false;
8828             }
8829             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8830             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8831             if ( ( p32.length != 0 ) ) {
8832                 return false;
8833             }
8834             final String p33_S = "A";
8835             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8836             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8837                 return false;
8838             }
8839             final String p34_S = "B;";
8840             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8841             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8842                 return false;
8843             }
8844             final String p35_S = "B:0.2";
8845             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8846             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8847                 return false;
8848             }
8849             final String p36_S = "(A)";
8850             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8851             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8852                 return false;
8853             }
8854             final String p37_S = "((A))";
8855             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8856             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8857                 return false;
8858             }
8859             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8860             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8861             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8862                 return false;
8863             }
8864             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8865             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8866             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8867                 return false;
8868             }
8869             final String p40_S = "(A,B,C)";
8870             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8871             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8872                 return false;
8873             }
8874             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8875             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8876             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8877                 return false;
8878             }
8879             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8880             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8881             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8882                 return false;
8883             }
8884             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)";
8885             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8886             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8887                 return false;
8888             }
8889             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)))";
8890             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8891             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8892                 return false;
8893             }
8894             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8895             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8896             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8897                 return false;
8898             }
8899             final String p46_S = "";
8900             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8901             if ( p46.length != 0 ) {
8902                 return false;
8903             }
8904             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ).toString(),
8905                                                   new NHXParser() )[ 0 ];
8906             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8907                 return false;
8908             }
8909             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ).toString(),
8910                                                   new NHXParser() )[ 0 ];
8911             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8912                 return false;
8913             }
8914             final Phylogeny p49 = factory
8915                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ).toString(),
8916                              new NHXParser() )[ 0 ];
8917             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8918                 return false;
8919             }
8920             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ).toString(),
8921                                                   new NHXParser() )[ 0 ];
8922             if ( p50.getNode( "A" ) == null ) {
8923                 return false;
8924             }
8925             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8926                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8927                 return false;
8928             }
8929             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8930                 return false;
8931             }
8932             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8933                     .equals( "((A,B)88:2.0,C);" ) ) {
8934                 return false;
8935             }
8936             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ).toString(),
8937                                                   new NHXParser() )[ 0 ];
8938             if ( p51.getNode( "A(A" ) == null ) {
8939                 return false;
8940             }
8941             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ).toString(),
8942                                                   new NHXParser() )[ 0 ];
8943             if ( p52.getNode( "A(A" ) == null ) {
8944                 return false;
8945             }
8946             final Phylogeny p53 = factory
8947                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ).toString(),
8948                              new NHXParser() )[ 0 ];
8949             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8950                 return false;
8951             }
8952             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ).toString(),
8953                                                   new NHXParser() )[ 0 ];
8954             if ( p54.getNode( "A" ) == null ) {
8955                 return false;
8956             }
8957             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8958                     .equals( "((A,B)[88],C);" ) ) {
8959                 return false;
8960             }
8961             final Phylogeny p55 = factory
8962                     .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);" )
8963                             .toString(), new NHXParser() )[ 0 ];
8964             if ( !p55.toNewHampshire()
8965                     .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);" ) ) {
8966                 System.out.println( p55.toNewHampshire() );
8967                 return false;
8968             }
8969             final Phylogeny p56 = factory
8970                     .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);" )
8971                             .toString(), new NHXParser() )[ 0 ];
8972             if ( !p56.toNewHampshire()
8973                     .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);" ) ) {
8974                 System.out.println( p56.toNewHampshire() );
8975                 return false;
8976             }
8977             final Phylogeny p57 = factory
8978                     .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);" )
8979                             .toString(), new NHXParser() )[ 0 ];
8980             if ( !p57.toNewHampshire()
8981                     .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);" ) ) {
8982                 System.out.println( p56.toNewHampshire() );
8983                 return false;
8984             }
8985             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8986             final Phylogeny p58 = factory.create( s58, new NHXParser() )[ 0 ];
8987             if ( !p58.toNewHampshire().equals( s58 ) ) {
8988                 System.out.println( p58.toNewHampshire() );
8989                 return false;
8990             }
8991             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8992             final Phylogeny p59 = factory.create( s59, new NHXParser() )[ 0 ];
8993             if ( !p59.toNewHampshire().equals( s59 ) ) {
8994                 System.out.println( p59.toNewHampshire() );
8995                 return false;
8996             }
8997             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8998             final Phylogeny p60 = factory.create( s60, new NHXParser() )[ 0 ];
8999             if ( !p60.toNewHampshire().equals( s60 ) ) {
9000                 System.out.println( p60.toNewHampshire() );
9001                 return false;
9002             }
9003             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
9004             final Phylogeny p61 = factory.create( s61, new NHXParser() )[ 0 ];
9005             if ( !p61.toNewHampshire()
9006                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
9007                 System.out.println( p61.toNewHampshire() );
9008                 return false;
9009             }
9010             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;";
9011             final Phylogeny p62 = factory.create( s62, new NHXParser() )[ 0 ];
9012             if ( !p62.toNewHampshire().equals( "(1:0.003,2:0.004):0.0;" ) ) {
9013                 System.out.println( p62.toNewHampshire() );
9014                 return false;
9015             }
9016             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)\"];";
9017             final Phylogeny p63 = factory.create( s63, new NHXParser() )[ 0 ];
9018             if ( !p63.toNewHampshire().equals( "(1:0.003,2:0.004):0.0;" ) ) {
9019                 System.out.println( p63.toNewHampshire() );
9020                 return false;
9021             }
9022             final String s64 = "((1,2):[95.5],3);";
9023             final Phylogeny p64 = factory.create( s64, new NHXParser() )[ 0 ];
9024             if ( !p64.toNewHampshireX().equals( "((1,2)[&&NHX:B=95.5],3)" ) ) {
9025                 System.out.println( p64.toNewHampshireX() );
9026                 return false;
9027             }
9028             final String s65 = "((1:0.1,2:0.2):0.3[10.2],3);";
9029             final Phylogeny p65 = factory.create( s65, new NHXParser() )[ 0 ];
9030             if ( !p65.toNewHampshireX().equals( "((1:0.1,2:0.2):0.3[&&NHX:B=10.2],3)" ) ) {
9031                 System.out.println( p65.toNewHampshireX() );
9032                 return false;
9033             }
9034             final Phylogeny p66 = factory.create( "((A,B)ab:2[0.44],C)", new NHXParser() )[ 0 ];
9035             if ( !isEqual( 0.44, p66.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
9036                 return false;
9037             }
9038             final Phylogeny p67 = factory.create( "((A,B):2[0.67],C)", new NHXParser() )[ 0 ];
9039             if ( !isEqual( 0.67, p67.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9040                 return false;
9041             }
9042             final Phylogeny p68 = factory.create( "((A,B):[0.68],C)", new NHXParser() )[ 0 ];
9043             if ( !isEqual( 0.68, p68.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9044                 return false;
9045             }
9046             final Phylogeny p69 = factory.create( "((A,B)[0.69],C)", new NHXParser() )[ 0 ];
9047             if ( !isEqual( 0.69, p69.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9048                 return false;
9049             }
9050             final Phylogeny p70 = factory.create( "((A,B)[+0.7],C)", new NHXParser() )[ 0 ];
9051             if ( !isEqual( 0.7, p70.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9052                 return false;
9053             }
9054             final Phylogeny p71 = factory.create( "((A,B)[-0.71],C)", new NHXParser() )[ 0 ];
9055             if ( !isEqual( -0.71, p71.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9056                 return false;
9057             }
9058             final Phylogeny p72 = factory.create( "((A,B)[],C)", new NHXParser() )[ 0 ];
9059             if ( !p72.toNewHampshireX().equals( "((A,B),C)" ) ) {
9060                 return false;
9061             }
9062             final Phylogeny p73 = factory.create( "((A,B)[12x],C)", new NHXParser() )[ 0 ];
9063             if ( !p73.toNewHampshireX().equals( "((A,B),C)" ) ) {
9064                 return false;
9065             }
9066             final Phylogeny p74 = factory.create( "((A,B)[12+],C)", new NHXParser() )[ 0 ];
9067             if ( !p74.toNewHampshireX().equals( "((A,B),C)" ) ) {
9068                 return false;
9069             }
9070             final Phylogeny p75 = factory.create( "((A,B)ab[222]:3,C)", new NHXParser() )[ 0 ];
9071             if ( !isEqual( 222, p75.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9072                 return false;
9073             }
9074             final Phylogeny p76 = factory.create( "((A,B)[100]:12,C)", new NHXParser() )[ 0 ];
9075             if ( !isEqual( 100, p76.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9076                 return false;
9077             }
9078             final Phylogeny p77 = factory.create( "((A,B)abcde:13[77],C)", new NHXParser() )[ 0 ];
9079             if ( !isEqual( 77, p77.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9080                 return false;
9081             }
9082             final Phylogeny p78 = factory.create( "((A,B):14[0],C)", new NHXParser() )[ 0 ];
9083             if ( !isEqual( 0, p78.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() ) ) {
9084                 return false;
9085             }
9086             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];";
9087             final Phylogeny p79 = factory.create(
9088                                                   "((((((a,b)ab[2]:3,c)[100]:12,(d,e)de)abcde:13[2],f):14[0]):0[0])[0]:0;",
9089                                                   new NHXParser() )[ 0 ];
9090             final String str79 = p79.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
9091             if ( !str79.equals( the_one ) ) {
9092                 System.out.println( str79 );
9093                 return false;
9094             }
9095             final Phylogeny p80 = factory.create(
9096                                                   "((((((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;",
9097                                                   new NHXParser() )[ 0 ];
9098             final String str80 = p80.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
9099             if ( !str80.equals( the_one ) ) {
9100                 System.out.println( str80 );
9101                 return false;
9102             }
9103         }
9104         catch ( final Exception e ) {
9105             e.printStackTrace( System.out );
9106             return false;
9107         }
9108         return true;
9109     }
9110
9111     private static boolean testNHParsingSpecialChars() {
9112         try {
9113             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9114             final String i0 = "(A!+=~QWERTY!@#$%^&*-,€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ)";
9115             final Phylogeny p0 = factory.create( i0, new NHXParser() )[ 0 ];
9116             if ( !p0.toNewHampshireX().equals( i0 ) ) {
9117                 System.out.println();
9118                 System.out.println( p0.toNewHampshireX() );
9119                 System.out.println( i0 );
9120                 return false;
9121             }
9122             final String i1 = "(हिंदी,한글,ไทย,'Tiếng Việt',ひらがなカタカナ漢字,繁體字,русский)";
9123             final Phylogeny p1 = factory.create( i1, new NHXParser() )[ 0 ];
9124             if ( !p1.toNewHampshireX().equals( i1 ) ) {
9125                 System.out.println();
9126                 System.out.println( p1.toNewHampshireX() );
9127                 System.out.println( i1 );
9128                 return false;
9129             }
9130         }
9131         catch ( final Exception e ) {
9132             e.printStackTrace( System.out );
9133             return false;
9134         }
9135         return true;
9136     }
9137
9138     private static boolean testNHParsingIter() {
9139         try {
9140             final String p0_str = "(A,B);";
9141             final NHXParser p = new NHXParser();
9142             p.setSource( p0_str );
9143             if ( !p.hasNext() ) {
9144                 return false;
9145             }
9146             final Phylogeny p0 = p.next();
9147             if ( !p0.toNewHampshire().equals( p0_str ) ) {
9148                 System.out.println( p0.toNewHampshire() );
9149                 return false;
9150             }
9151             if ( p.hasNext() ) {
9152                 return false;
9153             }
9154             if ( p.next() != null ) {
9155                 return false;
9156             }
9157             //
9158             final String p00_str = "(A,B)root;";
9159             p.setSource( p00_str );
9160             final Phylogeny p00 = p.next();
9161             if ( !p00.toNewHampshire().equals( p00_str ) ) {
9162                 System.out.println( p00.toNewHampshire() );
9163                 return false;
9164             }
9165             //
9166             final String p000_str = "A;";
9167             p.setSource( p000_str );
9168             final Phylogeny p000 = p.next();
9169             if ( !p000.toNewHampshire().equals( p000_str ) ) {
9170                 System.out.println( p000.toNewHampshire() );
9171                 return false;
9172             }
9173             //
9174             final String p0000_str = "A";
9175             p.setSource( p0000_str );
9176             final Phylogeny p0000 = p.next();
9177             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
9178                 System.out.println( p0000.toNewHampshire() );
9179                 return false;
9180             }
9181             //
9182             p.setSource( "(A)" );
9183             final Phylogeny p00000 = p.next();
9184             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
9185                 System.out.println( p00000.toNewHampshire() );
9186                 return false;
9187             }
9188             //
9189             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
9190             p.setSource( p1_str );
9191             if ( !p.hasNext() ) {
9192                 return false;
9193             }
9194             final Phylogeny p1_0 = p.next();
9195             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
9196                 System.out.println( p1_0.toNewHampshire() );
9197                 return false;
9198             }
9199             if ( !p.hasNext() ) {
9200                 return false;
9201             }
9202             final Phylogeny p1_1 = p.next();
9203             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
9204                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
9205                 return false;
9206             }
9207             if ( !p.hasNext() ) {
9208                 return false;
9209             }
9210             final Phylogeny p1_2 = p.next();
9211             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
9212                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
9213                 return false;
9214             }
9215             if ( !p.hasNext() ) {
9216                 return false;
9217             }
9218             final Phylogeny p1_3 = p.next();
9219             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
9220                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
9221                 return false;
9222             }
9223             if ( p.hasNext() ) {
9224                 return false;
9225             }
9226             if ( p.next() != null ) {
9227                 return false;
9228             }
9229             //
9230             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
9231             p.setSource( p2_str );
9232             if ( !p.hasNext() ) {
9233                 return false;
9234             }
9235             Phylogeny p2_0 = p.next();
9236             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9237                 System.out.println( p2_0.toNewHampshire() );
9238                 return false;
9239             }
9240             if ( !p.hasNext() ) {
9241                 return false;
9242             }
9243             Phylogeny p2_1 = p.next();
9244             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9245                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9246                 return false;
9247             }
9248             if ( !p.hasNext() ) {
9249                 return false;
9250             }
9251             Phylogeny p2_2 = p.next();
9252             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9253                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9254                 return false;
9255             }
9256             if ( !p.hasNext() ) {
9257                 return false;
9258             }
9259             Phylogeny p2_3 = p.next();
9260             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9261                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9262                 return false;
9263             }
9264             if ( !p.hasNext() ) {
9265                 return false;
9266             }
9267             Phylogeny p2_4 = p.next();
9268             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9269                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9270                 return false;
9271             }
9272             if ( p.hasNext() ) {
9273                 return false;
9274             }
9275             if ( p.next() != null ) {
9276                 return false;
9277             }
9278             ////
9279             p.reset();
9280             if ( !p.hasNext() ) {
9281                 return false;
9282             }
9283             p2_0 = p.next();
9284             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9285                 System.out.println( p2_0.toNewHampshire() );
9286                 return false;
9287             }
9288             if ( !p.hasNext() ) {
9289                 return false;
9290             }
9291             p2_1 = p.next();
9292             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9293                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9294                 return false;
9295             }
9296             if ( !p.hasNext() ) {
9297                 return false;
9298             }
9299             p2_2 = p.next();
9300             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9301                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9302                 return false;
9303             }
9304             if ( !p.hasNext() ) {
9305                 return false;
9306             }
9307             p2_3 = p.next();
9308             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9309                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9310                 return false;
9311             }
9312             if ( !p.hasNext() ) {
9313                 return false;
9314             }
9315             p2_4 = p.next();
9316             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9317                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9318                 return false;
9319             }
9320             if ( p.hasNext() ) {
9321                 return false;
9322             }
9323             if ( p.next() != null ) {
9324                 return false;
9325             }
9326             //
9327             final String p3_str = "((A,B),C)abc";
9328             p.setSource( p3_str );
9329             if ( !p.hasNext() ) {
9330                 return false;
9331             }
9332             final Phylogeny p3_0 = p.next();
9333             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
9334                 return false;
9335             }
9336             if ( p.hasNext() ) {
9337                 return false;
9338             }
9339             if ( p.next() != null ) {
9340                 return false;
9341             }
9342             //
9343             final String p4_str = "((A,B)ab,C)abc";
9344             p.setSource( p4_str );
9345             if ( !p.hasNext() ) {
9346                 return false;
9347             }
9348             final Phylogeny p4_0 = p.next();
9349             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
9350                 return false;
9351             }
9352             if ( p.hasNext() ) {
9353                 return false;
9354             }
9355             if ( p.next() != null ) {
9356                 return false;
9357             }
9358             //
9359             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
9360             p.setSource( p5_str );
9361             if ( !p.hasNext() ) {
9362                 return false;
9363             }
9364             final Phylogeny p5_0 = p.next();
9365             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
9366                 return false;
9367             }
9368             if ( p.hasNext() ) {
9369                 return false;
9370             }
9371             if ( p.next() != null ) {
9372                 return false;
9373             }
9374             //
9375             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
9376             p.setSource( p6_str );
9377             if ( !p.hasNext() ) {
9378                 return false;
9379             }
9380             Phylogeny p6_0 = p.next();
9381             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9382                 return false;
9383             }
9384             if ( p.hasNext() ) {
9385                 return false;
9386             }
9387             if ( p.next() != null ) {
9388                 return false;
9389             }
9390             p.reset();
9391             if ( !p.hasNext() ) {
9392                 return false;
9393             }
9394             p6_0 = p.next();
9395             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9396                 return false;
9397             }
9398             if ( p.hasNext() ) {
9399                 return false;
9400             }
9401             if ( p.next() != null ) {
9402                 return false;
9403             }
9404             //
9405             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
9406             p.setSource( p7_str );
9407             if ( !p.hasNext() ) {
9408                 return false;
9409             }
9410             Phylogeny p7_0 = p.next();
9411             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9412                 return false;
9413             }
9414             if ( p.hasNext() ) {
9415                 return false;
9416             }
9417             if ( p.next() != null ) {
9418                 return false;
9419             }
9420             p.reset();
9421             if ( !p.hasNext() ) {
9422                 return false;
9423             }
9424             p7_0 = p.next();
9425             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9426                 return false;
9427             }
9428             if ( p.hasNext() ) {
9429                 return false;
9430             }
9431             if ( p.next() != null ) {
9432                 return false;
9433             }
9434             //
9435             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
9436             p.setSource( p8_str );
9437             if ( !p.hasNext() ) {
9438                 return false;
9439             }
9440             Phylogeny p8_0 = p.next();
9441             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9442                 return false;
9443             }
9444             if ( !p.hasNext() ) {
9445                 return false;
9446             }
9447             if ( !p.hasNext() ) {
9448                 return false;
9449             }
9450             Phylogeny p8_1 = p.next();
9451             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9452                 return false;
9453             }
9454             if ( p.hasNext() ) {
9455                 return false;
9456             }
9457             if ( p.next() != null ) {
9458                 return false;
9459             }
9460             p.reset();
9461             if ( !p.hasNext() ) {
9462                 return false;
9463             }
9464             p8_0 = p.next();
9465             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9466                 return false;
9467             }
9468             if ( !p.hasNext() ) {
9469                 return false;
9470             }
9471             p8_1 = p.next();
9472             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9473                 return false;
9474             }
9475             if ( p.hasNext() ) {
9476                 return false;
9477             }
9478             if ( p.next() != null ) {
9479                 return false;
9480             }
9481             p.reset();
9482             //
9483             p.setSource( "" );
9484             if ( p.hasNext() ) {
9485                 return false;
9486             }
9487             //
9488             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
9489             if ( !p.hasNext() ) {
9490                 return false;
9491             }
9492             Phylogeny p_27 = p.next();
9493             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9494                 System.out.println( p_27.toNewHampshireX() );
9495                 System.exit( -1 );
9496                 return false;
9497             }
9498             if ( p.hasNext() ) {
9499                 return false;
9500             }
9501             if ( p.next() != null ) {
9502                 return false;
9503             }
9504             p.reset();
9505             if ( !p.hasNext() ) {
9506                 return false;
9507             }
9508             p_27 = p.next();
9509             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9510                 System.out.println( p_27.toNewHampshireX() );
9511                 System.exit( -1 );
9512                 return false;
9513             }
9514             if ( p.hasNext() ) {
9515                 return false;
9516             }
9517             if ( p.next() != null ) {
9518                 return false;
9519             }
9520             //
9521             final String p30_str = "(A,B);(C,D)";
9522             final NHXParser p30 = new NHXParser();
9523             p30.setSource( p30_str );
9524             if ( !p30.hasNext() ) {
9525                 return false;
9526             }
9527             Phylogeny phy30 = p30.next();
9528             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9529                 System.out.println( phy30.toNewHampshire() );
9530                 return false;
9531             }
9532             if ( !p30.hasNext() ) {
9533                 return false;
9534             }
9535             Phylogeny phy301 = p30.next();
9536             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9537                 System.out.println( phy301.toNewHampshire() );
9538                 return false;
9539             }
9540             if ( p30.hasNext() ) {
9541                 return false;
9542             }
9543             if ( p30.hasNext() ) {
9544                 return false;
9545             }
9546             if ( p30.next() != null ) {
9547                 return false;
9548             }
9549             if ( p30.next() != null ) {
9550                 return false;
9551             }
9552             p30.reset();
9553             if ( !p30.hasNext() ) {
9554                 return false;
9555             }
9556             phy30 = p30.next();
9557             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9558                 System.out.println( phy30.toNewHampshire() );
9559                 return false;
9560             }
9561             if ( !p30.hasNext() ) {
9562                 return false;
9563             }
9564             phy301 = p30.next();
9565             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9566                 System.out.println( phy301.toNewHampshire() );
9567                 return false;
9568             }
9569             if ( p30.hasNext() ) {
9570                 return false;
9571             }
9572             if ( p30.hasNext() ) {
9573                 return false;
9574             }
9575             if ( p30.next() != null ) {
9576                 return false;
9577             }
9578             if ( p30.next() != null ) {
9579                 return false;
9580             }
9581         }
9582         catch ( final Exception e ) {
9583             e.printStackTrace( System.out );
9584             return false;
9585         }
9586         return true;
9587     }
9588
9589     private static boolean testNHXconversion() {
9590         try {
9591             final PhylogenyNode n1 = new PhylogenyNode();
9592             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9593             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9594             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9595             final PhylogenyNode n5 = PhylogenyNode
9596                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
9597             final PhylogenyNode n6 = PhylogenyNode
9598                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
9599             if ( !n1.toNewHampshireX().equals( "" ) ) {
9600                 return false;
9601             }
9602             if ( !n2.toNewHampshireX().equals( "" ) ) {
9603                 return false;
9604             }
9605             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
9606                 return false;
9607             }
9608             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
9609                 return false;
9610             }
9611             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
9612                 return false;
9613             }
9614             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9615                 System.out.println( n6.toNewHampshireX() );
9616                 return false;
9617             }
9618             final PhylogenyNode n7 = new PhylogenyNode();
9619             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9620             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9621                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9622                 System.out.println( n7
9623                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9624                 return false;
9625             }
9626         }
9627         catch ( final Exception e ) {
9628             e.printStackTrace( System.out );
9629             return false;
9630         }
9631         return true;
9632     }
9633
9634     private static boolean testNHXNodeParsing() {
9635         try {
9636             final PhylogenyNode n1 = new PhylogenyNode();
9637             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9638             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9639             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9640             final PhylogenyNode n5 = PhylogenyNode
9641                     .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]" );
9642             if ( !n3.getName().equals( "n3" ) ) {
9643                 return false;
9644             }
9645             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9646                 return false;
9647             }
9648             if ( n3.isDuplication() ) {
9649                 return false;
9650             }
9651             if ( n3.isHasAssignedEvent() ) {
9652                 return false;
9653             }
9654             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9655                 return false;
9656             }
9657             if ( !n4.getName().equals( "n4" ) ) {
9658                 return false;
9659             }
9660             if ( n4.getDistanceToParent() != 0.01 ) {
9661                 return false;
9662             }
9663             if ( !n5.getName().equals( "n5" ) ) {
9664                 return false;
9665             }
9666             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9667                 return false;
9668             }
9669             if ( n5.getDistanceToParent() != 0.1 ) {
9670                 return false;
9671             }
9672             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9673                 return false;
9674             }
9675             if ( !n5.isDuplication() ) {
9676                 return false;
9677             }
9678             if ( !n5.isHasAssignedEvent() ) {
9679                 return false;
9680             }
9681             final PhylogenyNode n8 = PhylogenyNode
9682                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9683                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9684             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9685                 return false;
9686             }
9687             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9688                 return false;
9689             }
9690             final PhylogenyNode n9 = PhylogenyNode
9691                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9692                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9693             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9694                 return false;
9695             }
9696             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9697                 return false;
9698             }
9699             final PhylogenyNode n10 = PhylogenyNode
9700                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9701             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9702                 return false;
9703             }
9704             final PhylogenyNode n20 = PhylogenyNode
9705                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9706             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9707                 return false;
9708             }
9709             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9710                 return false;
9711             }
9712             final PhylogenyNode n20x = PhylogenyNode
9713                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9714             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9715                 return false;
9716             }
9717             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9718                 return false;
9719             }
9720             final PhylogenyNode n20xx = PhylogenyNode
9721                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9722             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9723                 return false;
9724             }
9725             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9726                 return false;
9727             }
9728             final PhylogenyNode n20xxx = PhylogenyNode
9729                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9730             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9731                 return false;
9732             }
9733             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9734                 return false;
9735             }
9736             final PhylogenyNode n20xxxx = PhylogenyNode
9737                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9738             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9739                 return false;
9740             }
9741             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9742                 return false;
9743             }
9744             final PhylogenyNode n21 = PhylogenyNode
9745                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9746             if ( !n21.getName().equals( "N21_PIG" ) ) {
9747                 return false;
9748             }
9749             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9750                 return false;
9751             }
9752             final PhylogenyNode n21x = PhylogenyNode
9753                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9754             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9755                 return false;
9756             }
9757             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9758                 return false;
9759             }
9760             final PhylogenyNode n22 = PhylogenyNode
9761                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9762             if ( !n22.getName().equals( "n22/PIG" ) ) {
9763                 return false;
9764             }
9765             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9766                 return false;
9767             }
9768             final PhylogenyNode n23 = PhylogenyNode
9769                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9770             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9771                 return false;
9772             }
9773             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9774                 return false;
9775             }
9776             final PhylogenyNode a = PhylogenyNode
9777                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9778             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9779                 return false;
9780             }
9781             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9782                 return false;
9783             }
9784             final PhylogenyNode c1 = PhylogenyNode
9785                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9786                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9787             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9788                 return false;
9789             }
9790             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9791                 return false;
9792             }
9793             final PhylogenyNode c2 = PhylogenyNode
9794                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9795                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9796             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9797                 return false;
9798             }
9799             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9800                 return false;
9801             }
9802             final PhylogenyNode e3 = PhylogenyNode
9803                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9804             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9805                 return false;
9806             }
9807             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9808                 return false;
9809             }
9810             final PhylogenyNode n11 = PhylogenyNode
9811                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9812                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9813             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9814                 return false;
9815             }
9816             if ( n11.getDistanceToParent() != 0.4 ) {
9817                 return false;
9818             }
9819             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9820                 return false;
9821             }
9822             final PhylogenyNode n12 = PhylogenyNode
9823                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9824                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9825             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9826                 return false;
9827             }
9828             if ( n12.getDistanceToParent() != 0.4 ) {
9829                 return false;
9830             }
9831             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9832                 return false;
9833             }
9834             final PhylogenyNode o = PhylogenyNode
9835                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9836             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9837                 return false;
9838             }
9839             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9840                 return false;
9841             }
9842             if ( n1.getName().compareTo( "" ) != 0 ) {
9843                 return false;
9844             }
9845             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9846                 return false;
9847             }
9848             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9849                 return false;
9850             }
9851             if ( n2.getName().compareTo( "" ) != 0 ) {
9852                 return false;
9853             }
9854             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9855                 return false;
9856             }
9857             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9858                 return false;
9859             }
9860             final PhylogenyNode n00 = PhylogenyNode
9861                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9862             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9863                 return false;
9864             }
9865             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9866                 return false;
9867             }
9868             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9869             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9870                 return false;
9871             }
9872             final PhylogenyNode n13 = PhylogenyNode
9873                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9874             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9875                 return false;
9876             }
9877             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9878                 return false;
9879             }
9880             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9881                 return false;
9882             }
9883             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9884                 return false;
9885             }
9886             final PhylogenyNode n14 = PhylogenyNode
9887                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9888             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9889                 return false;
9890             }
9891             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9892                 return false;
9893             }
9894             final PhylogenyNode n15 = PhylogenyNode
9895                     .createInstanceFromNhxString( "something_wicked[123]",
9896                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9897             if ( !n15.getName().equals( "something_wicked" ) ) {
9898                 return false;
9899             }
9900             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9901                 return false;
9902             }
9903             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9904                 return false;
9905             }
9906             final PhylogenyNode n16 = PhylogenyNode
9907                     .createInstanceFromNhxString( "something_wicked2[9]",
9908                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9909             if ( !n16.getName().equals( "something_wicked2" ) ) {
9910                 return false;
9911             }
9912             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9913                 return false;
9914             }
9915             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9916                 return false;
9917             }
9918             final PhylogenyNode n17 = PhylogenyNode
9919                     .createInstanceFromNhxString( "something_wicked3[a]",
9920                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9921             if ( !n17.getName().equals( "something_wicked3" ) ) {
9922                 return false;
9923             }
9924             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9925                 return false;
9926             }
9927             final PhylogenyNode n18 = PhylogenyNode
9928                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9929             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9930                 return false;
9931             }
9932             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9933                 return false;
9934             }
9935             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9936                 return false;
9937             }
9938             final PhylogenyNode n19 = PhylogenyNode
9939                     .createInstanceFromNhxString( "BLAH_1-roejojoej",
9940                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9941             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9942                 return false;
9943             }
9944             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9945                 return false;
9946             }
9947             final PhylogenyNode n30 = PhylogenyNode
9948                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9949                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9950             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9951                 return false;
9952             }
9953             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9954                 return false;
9955             }
9956             final PhylogenyNode n31 = PhylogenyNode
9957                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9958                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9959             if ( n31.getNodeData().isHasTaxonomy() ) {
9960                 return false;
9961             }
9962             final PhylogenyNode n32 = PhylogenyNode
9963                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9964             if ( n32.getNodeData().isHasTaxonomy() ) {
9965                 return false;
9966             }
9967             final PhylogenyNode n40 = PhylogenyNode
9968                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9969             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9970                 return false;
9971             }
9972             final PhylogenyNode n41 = PhylogenyNode
9973                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9974             if ( n41.getNodeData().isHasTaxonomy() ) {
9975                 return false;
9976             }
9977             final PhylogenyNode n42 = PhylogenyNode
9978                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9979             if ( n42.getNodeData().isHasTaxonomy() ) {
9980                 return false;
9981             }
9982             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9983                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9984             if ( n43.getNodeData().isHasTaxonomy() ) {
9985                 return false;
9986             }
9987             final PhylogenyNode n44 = PhylogenyNode
9988                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9989             if ( n44.getNodeData().isHasTaxonomy() ) {
9990                 return false;
9991             }
9992         }
9993         catch ( final Exception e ) {
9994             e.printStackTrace( System.out );
9995             return false;
9996         }
9997         return true;
9998     }
9999
10000     private static boolean testNHXNodeParsing2() {
10001         try {
10002             final PhylogenyNode n0_0 = PhylogenyNode.createInstanceFromNhxString( "n0:[ignore me 123]:1E-3",
10003                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10004                                                                                   true,
10005                                                                                   true );
10006             if ( !n0_0.getName().equals( "n0" ) ) {
10007                 return false;
10008             }
10009             if ( !isEqual( n0_0.getDistanceToParent(), 0.001 ) ) {
10010                 return false;
10011             }
10012             final PhylogenyNode n0_1 = PhylogenyNode.createInstanceFromNhxString( "n0[ignore me 123]:1E-3",
10013                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10014                                                                                   true,
10015                                                                                   true );
10016             if ( !n0_1.getName().equals( "n0" ) ) {
10017                 return false;
10018             }
10019             if ( !isEqual( n0_1.getDistanceToParent(), 0.001 ) ) {
10020                 return false;
10021             }
10022             final PhylogenyNode n0_2 = PhylogenyNode.createInstanceFromNhxString( "n0:1E-3[ignore me 123]",
10023                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10024                                                                                   true,
10025                                                                                   true );
10026             if ( !n0_2.getName().equals( "n0" ) ) {
10027                 return false;
10028             }
10029             if ( !isEqual( n0_2.getDistanceToParent(), 0.001 ) ) {
10030                 return false;
10031             }
10032             final PhylogenyNode n0_3 = PhylogenyNode.createInstanceFromNhxString( "n0:1E-3:[ignore me 123]",
10033                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10034                                                                                   true,
10035                                                                                   true );
10036             if ( !n0_3.getName().equals( "n0" ) ) {
10037                 return false;
10038             }
10039             if ( !isEqual( n0_3.getDistanceToParent(), 0.001 ) ) {
10040                 return false;
10041             }
10042             final PhylogenyNode n0_4 = PhylogenyNode.createInstanceFromNhxString( "n0:0.001:[ignore me 123]",
10043                                                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10044                                                                                   true,
10045                                                                                   true );
10046             if ( !n0_4.getName().equals( "n0" ) ) {
10047                 return false;
10048             }
10049             if ( !isEqual( n0_4.getDistanceToParent(), 0.001 ) ) {
10050                 return false;
10051             }
10052             final PhylogenyNode n1_0 = PhylogenyNode
10053                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]",
10054                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10055                                                   true,
10056                                                   true );
10057             if ( !n1_0.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10058                 return false;
10059             }
10060             if ( n1_0.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10061                 return false;
10062             }
10063             final PhylogenyNode n1_1 = PhylogenyNode
10064                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]:0.001",
10065                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10066                                                   true,
10067                                                   true );
10068             if ( !n1_1.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10069                 return false;
10070             }
10071             if ( n1_1.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10072                 return false;
10073             }
10074             if ( !isEqual( n1_1.getDistanceToParent(), 0.001 ) ) {
10075                 return false;
10076             }
10077             final PhylogenyNode n1_2 = PhylogenyNode
10078                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:0.001[&!color=#FFFFFF]",
10079                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10080                                                   true,
10081                                                   true );
10082             if ( !n1_2.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10083                 return false;
10084             }
10085             if ( n1_2.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10086                 return false;
10087             }
10088             if ( !isEqual( n1_2.getDistanceToParent(), 0.001 ) ) {
10089                 return false;
10090             }
10091             final PhylogenyNode n1_3 = PhylogenyNode
10092                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[&boostrap=69,&!color=#FFFFFF]",
10093                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10094                                                   true,
10095                                                   true );
10096             if ( !n1_3.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10097                 return false;
10098             }
10099             if ( n1_3.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10100                 return false;
10101             }
10102             if ( !isEqual( n1_3.getDistanceToParent(), 0.001 ) ) {
10103                 return false;
10104             }
10105             if ( !isEqual( n1_3.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
10106                 return false;
10107             }
10108             if ( !n1_3.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
10109                 return false;
10110             }
10111             final PhylogenyNode n1_4 = PhylogenyNode
10112                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&bootstrap=69,&!colour=#FFFFFF]:1e-3",
10113                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10114                                                   true,
10115                                                   true );
10116             if ( !n1_4.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10117                 return false;
10118             }
10119             if ( n1_4.getBranchData().getBranchColor().getValue().getGreen() != 255 ) {
10120                 return false;
10121             }
10122             if ( !isEqual( n1_4.getDistanceToParent(), 0.001 ) ) {
10123                 return false;
10124             }
10125             if ( !isEqual( n1_4.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
10126                 return false;
10127             }
10128             if ( !n1_4.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
10129                 return false;
10130             }
10131             final PhylogenyNode n1_5 = PhylogenyNode
10132                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[69.0]",
10133                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10134                                                   true,
10135                                                   true );
10136             if ( !n1_5.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10137                 return false;
10138             }
10139             if ( !isEqual( n1_5.getDistanceToParent(), 0.001 ) ) {
10140                 return false;
10141             }
10142             if ( !isEqual( n1_5.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
10143                 return false;
10144             }
10145             final PhylogenyNode n1_6 = PhylogenyNode
10146                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00]:1e-3",
10147                                                   NHXParser.TAXONOMY_EXTRACTION.NO,
10148                                                   true,
10149                                                   true );
10150             if ( !n1_6.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
10151                 return false;
10152             }
10153             if ( !isEqual( n1_6.getDistanceToParent(), 0.001 ) ) {
10154                 return false;
10155             }
10156             if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getStandardDeviation(), 0.11 ) ) {
10157                 return false;
10158             }
10159             if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getValue(), 0.95 ) ) {
10160                 return false;
10161             }
10162             if ( !n1_6.getBranchData().getConfidence( 0 ).getType().equals( "posterior probability" ) ) {
10163                 return false;
10164             }
10165         }
10166         catch ( final Exception e ) {
10167             e.printStackTrace( System.out );
10168             return false;
10169         }
10170         return true;
10171     }
10172
10173     private static boolean testNHXParsing() {
10174         try {
10175             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10176             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])",
10177                                                  new NHXParser() )[ 0 ];
10178             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
10179                 return false;
10180             }
10181             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]";
10182             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
10183             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10184                 return false;
10185             }
10186             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]";
10187             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
10188             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
10189                 return false;
10190             }
10191             final Phylogeny[] p3 = factory.create(
10192                                                    "[  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]",
10193                                                    new NHXParser() );
10194             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10195                 return false;
10196             }
10197             final Phylogeny[] p4 = factory.create(
10198                                                    "(((((((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(]",
10199                                                    new NHXParser() );
10200             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10201                 return false;
10202             }
10203             final Phylogeny[] p5 = factory.create(
10204                                                    "[]  (  [][ ][   ]  ([((( &&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(((]",
10205                                                    new NHXParser() );
10206             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10207                 return false;
10208             }
10209             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)";
10210             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)";
10211             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
10212             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
10213                 return false;
10214             }
10215             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)))";
10216             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)))";
10217             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
10218             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
10219                 return false;
10220             }
10221             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])   ))[,,, ])))))))";
10222             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
10223             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
10224             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
10225                 return false;
10226             }
10227             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
10228             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10229                 return false;
10230             }
10231             final Phylogeny p10 = factory.create(
10232                                                   " [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]",
10233                                                   new NHXParser() )[ 0 ];
10234             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10235                 return false;
10236             }
10237             final Phylogeny p11 = factory.create(
10238                                                   " [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]",
10239                                                   new NHXParser() )[ 0 ];
10240             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10241                 return false;
10242             }
10243             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]",
10244                                                   new NHXParser() )[ 0 ];
10245             if ( !p12.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10246                 return false;
10247             }
10248         }
10249         catch ( final Exception e ) {
10250             e.printStackTrace( System.out );
10251             return false;
10252         }
10253         return true;
10254     }
10255
10256     private static boolean testNHXParsingMB() {
10257         try {
10258             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10259             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
10260                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10261                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
10262                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
10263                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
10264                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10265                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
10266                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
10267                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
10268             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
10269                 return false;
10270             }
10271             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
10272                 return false;
10273             }
10274             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
10275                            0.1100000000000000e+00 ) ) {
10276                 return false;
10277             }
10278             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
10279                 return false;
10280             }
10281             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
10282                 return false;
10283             }
10284             final Phylogeny p2 = factory
10285                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
10286                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10287                             + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
10288                             + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
10289                             + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
10290                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10291                             + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
10292                             + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
10293                             + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
10294             if ( p2.getNode( "1" ) == null ) {
10295                 return false;
10296             }
10297             if ( p2.getNode( "2" ) == null ) {
10298                 return false;
10299             }
10300         }
10301         catch ( final Exception e ) {
10302             e.printStackTrace( System.out );
10303             System.exit( -1 );
10304             return false;
10305         }
10306         return true;
10307     }
10308
10309     private static boolean testNHXParsingQuotes() {
10310         try {
10311             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10312             final NHXParser p = new NHXParser();
10313             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
10314             if ( phylogenies_0.length != 5 ) {
10315                 return false;
10316             }
10317             final Phylogeny phy = phylogenies_0[ 4 ];
10318             if ( phy.getNumberOfExternalNodes() != 7 ) {
10319                 return false;
10320             }
10321             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
10322                 return false;
10323             }
10324             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
10325                 return false;
10326             }
10327             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
10328                     .getScientificName().equals( "hsapiens" ) ) {
10329                 return false;
10330             }
10331             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
10332                 return false;
10333             }
10334             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
10335                 return false;
10336             }
10337             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
10338                 return false;
10339             }
10340             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
10341                 return false;
10342             }
10343             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
10344                 return false;
10345             }
10346             final NHXParser p1p = new NHXParser();
10347             p1p.setIgnoreQuotes( true );
10348             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
10349             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
10350                 return false;
10351             }
10352             final NHXParser p2p = new NHXParser();
10353             p1p.setIgnoreQuotes( false );
10354             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
10355             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
10356                 return false;
10357             }
10358             final NHXParser p3p = new NHXParser();
10359             p3p.setIgnoreQuotes( false );
10360             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
10361             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
10362                 return false;
10363             }
10364             final NHXParser p4p = new NHXParser();
10365             p4p.setIgnoreQuotes( false );
10366             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
10367             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
10368                 return false;
10369             }
10370             final Phylogeny p10 = factory.create(
10371                                                   " [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]",
10372                                                   new NHXParser() )[ 0 ];
10373             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]";
10374             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
10375                 return false;
10376             }
10377             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
10378             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
10379                 return false;
10380             }
10381             final Phylogeny p12 = factory.create(
10382                                                   " [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]",
10383                                                   new NHXParser() )[ 0 ];
10384             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]";
10385             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
10386                 return false;
10387             }
10388             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
10389             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
10390                 return false;
10391             }
10392             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;";
10393             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
10394                 return false;
10395             }
10396             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
10397             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
10398                 return false;
10399             }
10400         }
10401         catch ( final Exception e ) {
10402             e.printStackTrace( System.out );
10403             return false;
10404         }
10405         return true;
10406     }
10407
10408     private static boolean testNodeRemoval() {
10409         try {
10410             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10411             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
10412             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
10413             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
10414                 return false;
10415             }
10416             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
10417             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
10418             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
10419                 return false;
10420             }
10421             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
10422             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
10423             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
10424                 return false;
10425             }
10426         }
10427         catch ( final Exception e ) {
10428             e.printStackTrace( System.out );
10429             return false;
10430         }
10431         return true;
10432     }
10433
10434     private static boolean testPhylogenyBranch() {
10435         try {
10436             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
10437             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
10438             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
10439             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
10440             if ( !a1b1.equals( a1b1 ) ) {
10441                 return false;
10442             }
10443             if ( !a1b1.equals( b1a1 ) ) {
10444                 return false;
10445             }
10446             if ( !b1a1.equals( a1b1 ) ) {
10447                 return false;
10448             }
10449             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
10450             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
10451             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
10452             if ( a1_b1.equals( b1_a1 ) ) {
10453                 return false;
10454             }
10455             if ( a1_b1.equals( a1_b1_ ) ) {
10456                 return false;
10457             }
10458             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
10459             if ( !a1_b1.equals( b1_a1_ ) ) {
10460                 return false;
10461             }
10462             if ( a1_b1_.equals( b1_a1_ ) ) {
10463                 return false;
10464             }
10465             if ( !a1_b1_.equals( b1_a1 ) ) {
10466                 return false;
10467             }
10468         }
10469         catch ( final Exception e ) {
10470             e.printStackTrace( System.out );
10471             return false;
10472         }
10473         return true;
10474     }
10475
10476     private static boolean testPhyloXMLparsingOfDistributionElement() {
10477         try {
10478             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10479             PhyloXmlParser xml_parser = null;
10480             try {
10481                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
10482             }
10483             catch ( final Exception e ) {
10484                 // Do nothing -- means were not running from jar.
10485             }
10486             if ( xml_parser == null ) {
10487                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
10488                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
10489                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
10490                 }
10491                 else {
10492                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
10493                 }
10494             }
10495             final Phylogeny[] phylogenies_0 = factory
10496                     .create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml" ), xml_parser );
10497             if ( xml_parser.getErrorCount() > 0 ) {
10498                 System.out.println( xml_parser.getErrorMessages().toString() );
10499                 return false;
10500             }
10501             if ( phylogenies_0.length != 1 ) {
10502                 return false;
10503             }
10504             final Phylogeny t1 = phylogenies_0[ 0 ];
10505             PhylogenyNode n = null;
10506             Distribution d = null;
10507             n = t1.getNode( "root node" );
10508             if ( !n.getNodeData().isHasDistribution() ) {
10509                 return false;
10510             }
10511             if ( n.getNodeData().getDistributions().size() != 1 ) {
10512                 return false;
10513             }
10514             d = n.getNodeData().getDistribution();
10515             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10516                 return false;
10517             }
10518             if ( d.getPoints().size() != 1 ) {
10519                 return false;
10520             }
10521             if ( d.getPolygons() != null ) {
10522                 return false;
10523             }
10524             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10525                 return false;
10526             }
10527             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10528                 return false;
10529             }
10530             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10531                 return false;
10532             }
10533             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10534                 return false;
10535             }
10536             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10537                 return false;
10538             }
10539             n = t1.getNode( "node a" );
10540             if ( !n.getNodeData().isHasDistribution() ) {
10541                 return false;
10542             }
10543             if ( n.getNodeData().getDistributions().size() != 2 ) {
10544                 return false;
10545             }
10546             d = n.getNodeData().getDistribution( 1 );
10547             if ( !d.getDesc().equals( "San Diego" ) ) {
10548                 return false;
10549             }
10550             if ( d.getPoints().size() != 1 ) {
10551                 return false;
10552             }
10553             if ( d.getPolygons() != null ) {
10554                 return false;
10555             }
10556             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10557                 return false;
10558             }
10559             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10560                 return false;
10561             }
10562             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10563                 return false;
10564             }
10565             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10566                 return false;
10567             }
10568             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10569                 return false;
10570             }
10571             n = t1.getNode( "node bb" );
10572             if ( !n.getNodeData().isHasDistribution() ) {
10573                 return false;
10574             }
10575             if ( n.getNodeData().getDistributions().size() != 1 ) {
10576                 return false;
10577             }
10578             d = n.getNodeData().getDistribution( 0 );
10579             if ( d.getPoints().size() != 3 ) {
10580                 return false;
10581             }
10582             if ( d.getPolygons().size() != 2 ) {
10583                 return false;
10584             }
10585             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10586                 return false;
10587             }
10588             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10589                 return false;
10590             }
10591             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10592                 return false;
10593             }
10594             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10595                 return false;
10596             }
10597             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10598                 return false;
10599             }
10600             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10601                 return false;
10602             }
10603             Polygon p = d.getPolygons().get( 0 );
10604             if ( p.getPoints().size() != 3 ) {
10605                 return false;
10606             }
10607             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10608                 return false;
10609             }
10610             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10611                 return false;
10612             }
10613             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10614                 return false;
10615             }
10616             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10617                 return false;
10618             }
10619             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10620                 return false;
10621             }
10622             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10623                 return false;
10624             }
10625             p = d.getPolygons().get( 1 );
10626             if ( p.getPoints().size() != 3 ) {
10627                 return false;
10628             }
10629             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10630                 return false;
10631             }
10632             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10633                 return false;
10634             }
10635             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10636                 return false;
10637             }
10638             // Roundtrip:
10639             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
10640             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
10641             if ( rt.length != 1 ) {
10642                 return false;
10643             }
10644             final Phylogeny t1_rt = rt[ 0 ];
10645             n = t1_rt.getNode( "root node" );
10646             if ( !n.getNodeData().isHasDistribution() ) {
10647                 return false;
10648             }
10649             if ( n.getNodeData().getDistributions().size() != 1 ) {
10650                 return false;
10651             }
10652             d = n.getNodeData().getDistribution();
10653             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10654                 return false;
10655             }
10656             if ( d.getPoints().size() != 1 ) {
10657                 return false;
10658             }
10659             if ( d.getPolygons() != null ) {
10660                 return false;
10661             }
10662             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10663                 return false;
10664             }
10665             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10666                 return false;
10667             }
10668             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10669                 return false;
10670             }
10671             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10672                 return false;
10673             }
10674             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10675                 return false;
10676             }
10677             n = t1_rt.getNode( "node a" );
10678             if ( !n.getNodeData().isHasDistribution() ) {
10679                 return false;
10680             }
10681             if ( n.getNodeData().getDistributions().size() != 2 ) {
10682                 return false;
10683             }
10684             d = n.getNodeData().getDistribution( 1 );
10685             if ( !d.getDesc().equals( "San Diego" ) ) {
10686                 return false;
10687             }
10688             if ( d.getPoints().size() != 1 ) {
10689                 return false;
10690             }
10691             if ( d.getPolygons() != null ) {
10692                 return false;
10693             }
10694             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10695                 return false;
10696             }
10697             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10698                 return false;
10699             }
10700             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10701                 return false;
10702             }
10703             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10704                 return false;
10705             }
10706             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10707                 return false;
10708             }
10709             n = t1_rt.getNode( "node bb" );
10710             if ( !n.getNodeData().isHasDistribution() ) {
10711                 return false;
10712             }
10713             if ( n.getNodeData().getDistributions().size() != 1 ) {
10714                 return false;
10715             }
10716             d = n.getNodeData().getDistribution( 0 );
10717             if ( d.getPoints().size() != 3 ) {
10718                 return false;
10719             }
10720             if ( d.getPolygons().size() != 2 ) {
10721                 return false;
10722             }
10723             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10724                 return false;
10725             }
10726             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10727                 return false;
10728             }
10729             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10730                 return false;
10731             }
10732             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10733                 return false;
10734             }
10735             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10736                 return false;
10737             }
10738             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10739                 return false;
10740             }
10741             p = d.getPolygons().get( 0 );
10742             if ( p.getPoints().size() != 3 ) {
10743                 return false;
10744             }
10745             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10746                 return false;
10747             }
10748             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10749                 return false;
10750             }
10751             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10752                 return false;
10753             }
10754             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10755                 return false;
10756             }
10757             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10758                 return false;
10759             }
10760             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10761                 return false;
10762             }
10763             p = d.getPolygons().get( 1 );
10764             if ( p.getPoints().size() != 3 ) {
10765                 return false;
10766             }
10767             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10768                 return false;
10769             }
10770             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10771                 return false;
10772             }
10773             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10774                 return false;
10775             }
10776         }
10777         catch ( final Exception e ) {
10778             e.printStackTrace( System.out );
10779             return false;
10780         }
10781         return true;
10782     }
10783
10784     private static boolean testPostOrderIterator() {
10785         try {
10786             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10787             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10788             PhylogenyNodeIterator it0;
10789             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
10790                 it0.next();
10791             }
10792             for( it0.reset(); it0.hasNext(); ) {
10793                 it0.next();
10794             }
10795             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r",
10796                                                  new NHXParser() )[ 0 ];
10797             final PhylogenyNodeIterator it = t1.iteratorPostorder();
10798             if ( !it.next().getName().equals( "A" ) ) {
10799                 return false;
10800             }
10801             if ( !it.next().getName().equals( "B" ) ) {
10802                 return false;
10803             }
10804             if ( !it.next().getName().equals( "ab" ) ) {
10805                 return false;
10806             }
10807             if ( !it.next().getName().equals( "C" ) ) {
10808                 return false;
10809             }
10810             if ( !it.next().getName().equals( "D" ) ) {
10811                 return false;
10812             }
10813             if ( !it.next().getName().equals( "cd" ) ) {
10814                 return false;
10815             }
10816             if ( !it.next().getName().equals( "abcd" ) ) {
10817                 return false;
10818             }
10819             if ( !it.next().getName().equals( "E" ) ) {
10820                 return false;
10821             }
10822             if ( !it.next().getName().equals( "F" ) ) {
10823                 return false;
10824             }
10825             if ( !it.next().getName().equals( "ef" ) ) {
10826                 return false;
10827             }
10828             if ( !it.next().getName().equals( "G" ) ) {
10829                 return false;
10830             }
10831             if ( !it.next().getName().equals( "H" ) ) {
10832                 return false;
10833             }
10834             if ( !it.next().getName().equals( "gh" ) ) {
10835                 return false;
10836             }
10837             if ( !it.next().getName().equals( "efgh" ) ) {
10838                 return false;
10839             }
10840             if ( !it.next().getName().equals( "r" ) ) {
10841                 return false;
10842             }
10843             if ( it.hasNext() ) {
10844                 return false;
10845             }
10846         }
10847         catch ( final Exception e ) {
10848             e.printStackTrace( System.out );
10849             return false;
10850         }
10851         return true;
10852     }
10853
10854     private static boolean testPreOrderIterator() {
10855         try {
10856             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10857             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10858             PhylogenyNodeIterator it0;
10859             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10860                 it0.next();
10861             }
10862             for( it0.reset(); it0.hasNext(); ) {
10863                 it0.next();
10864             }
10865             PhylogenyNodeIterator it = t0.iteratorPreorder();
10866             if ( !it.next().getName().equals( "r" ) ) {
10867                 return false;
10868             }
10869             if ( !it.next().getName().equals( "ab" ) ) {
10870                 return false;
10871             }
10872             if ( !it.next().getName().equals( "A" ) ) {
10873                 return false;
10874             }
10875             if ( !it.next().getName().equals( "B" ) ) {
10876                 return false;
10877             }
10878             if ( !it.next().getName().equals( "cd" ) ) {
10879                 return false;
10880             }
10881             if ( !it.next().getName().equals( "C" ) ) {
10882                 return false;
10883             }
10884             if ( !it.next().getName().equals( "D" ) ) {
10885                 return false;
10886             }
10887             if ( it.hasNext() ) {
10888                 return false;
10889             }
10890             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r",
10891                                                  new NHXParser() )[ 0 ];
10892             it = t1.iteratorPreorder();
10893             if ( !it.next().getName().equals( "r" ) ) {
10894                 return false;
10895             }
10896             if ( !it.next().getName().equals( "abcd" ) ) {
10897                 return false;
10898             }
10899             if ( !it.next().getName().equals( "ab" ) ) {
10900                 return false;
10901             }
10902             if ( !it.next().getName().equals( "A" ) ) {
10903                 return false;
10904             }
10905             if ( !it.next().getName().equals( "B" ) ) {
10906                 return false;
10907             }
10908             if ( !it.next().getName().equals( "cd" ) ) {
10909                 return false;
10910             }
10911             if ( !it.next().getName().equals( "C" ) ) {
10912                 return false;
10913             }
10914             if ( !it.next().getName().equals( "D" ) ) {
10915                 return false;
10916             }
10917             if ( !it.next().getName().equals( "efgh" ) ) {
10918                 return false;
10919             }
10920             if ( !it.next().getName().equals( "ef" ) ) {
10921                 return false;
10922             }
10923             if ( !it.next().getName().equals( "E" ) ) {
10924                 return false;
10925             }
10926             if ( !it.next().getName().equals( "F" ) ) {
10927                 return false;
10928             }
10929             if ( !it.next().getName().equals( "gh" ) ) {
10930                 return false;
10931             }
10932             if ( !it.next().getName().equals( "G" ) ) {
10933                 return false;
10934             }
10935             if ( !it.next().getName().equals( "H" ) ) {
10936                 return false;
10937             }
10938             if ( it.hasNext() ) {
10939                 return false;
10940             }
10941         }
10942         catch ( final Exception e ) {
10943             e.printStackTrace( System.out );
10944             return false;
10945         }
10946         return true;
10947     }
10948
10949     private static boolean testPropertiesMap() {
10950         try {
10951             final PropertiesList pm = new PropertiesList();
10952             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10953             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10954             final Property p2 = new Property( "something:else",
10955                                               "?",
10956                                               "improbable:research",
10957                                               "xsd:decimal",
10958                                               AppliesTo.NODE );
10959             pm.addProperty( p0 );
10960             pm.addProperty( p1 );
10961             pm.addProperty( p2 );
10962             if ( !pm.getProperties( "dimensions:diameter" ).get( 0 ).getValue().equals( "1" ) ) {
10963                 return false;
10964             }
10965             if ( !pm.getProperties( "dimensions:length" ).get( 0 ).getValue().equals( "2" ) ) {
10966                 return false;
10967             }
10968             if ( pm.getProperties().size() != 3 ) {
10969                 return false;
10970             }
10971             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10972                 return false;
10973             }
10974             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10975                 return false;
10976             }
10977             if ( pm.getProperties().size() != 3 ) {
10978                 return false;
10979             }
10980         }
10981         catch ( final Exception e ) {
10982             e.printStackTrace( System.out );
10983             return false;
10984         }
10985         return true;
10986     }
10987
10988     private static boolean testProteinId() {
10989         try {
10990             final ProteinId id1 = new ProteinId( "a" );
10991             final ProteinId id2 = new ProteinId( "a" );
10992             final ProteinId id3 = new ProteinId( "A" );
10993             final ProteinId id4 = new ProteinId( "b" );
10994             if ( !id1.equals( id1 ) ) {
10995                 return false;
10996             }
10997             if ( id1.getId().equals( "x" ) ) {
10998                 return false;
10999             }
11000             if ( id1.getId().equals( null ) ) {
11001                 return false;
11002             }
11003             if ( !id1.equals( id2 ) ) {
11004                 return false;
11005             }
11006             if ( id1.equals( id3 ) ) {
11007                 return false;
11008             }
11009             if ( id1.hashCode() != id1.hashCode() ) {
11010                 return false;
11011             }
11012             if ( id1.hashCode() != id2.hashCode() ) {
11013                 return false;
11014             }
11015             if ( id1.hashCode() == id3.hashCode() ) {
11016                 return false;
11017             }
11018             if ( id1.compareTo( id1 ) != 0 ) {
11019                 return false;
11020             }
11021             if ( id1.compareTo( id2 ) != 0 ) {
11022                 return false;
11023             }
11024             if ( id1.compareTo( id3 ) != 0 ) {
11025                 return false;
11026             }
11027             if ( id1.compareTo( id4 ) >= 0 ) {
11028                 return false;
11029             }
11030             if ( id4.compareTo( id1 ) <= 0 ) {
11031                 return false;
11032             }
11033             if ( !id4.getId().equals( "b" ) ) {
11034                 return false;
11035             }
11036             final ProteinId id5 = new ProteinId( " C " );
11037             if ( !id5.getId().equals( "C" ) ) {
11038                 return false;
11039             }
11040             if ( id5.equals( id1 ) ) {
11041                 return false;
11042             }
11043         }
11044         catch ( final Exception e ) {
11045             e.printStackTrace( System.out );
11046             return false;
11047         }
11048         return true;
11049     }
11050
11051     private static boolean testReIdMethods() {
11052         try {
11053             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11054             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
11055             final long count = PhylogenyNode.getNodeCount();
11056             p.levelOrderReID();
11057             if ( p.getNode( "r" ).getId() != count ) {
11058                 return false;
11059             }
11060             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
11061                 return false;
11062             }
11063             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
11064                 return false;
11065             }
11066             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
11067                 return false;
11068             }
11069             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
11070                 return false;
11071             }
11072             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
11073                 return false;
11074             }
11075             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
11076                 return false;
11077             }
11078             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
11079                 return false;
11080             }
11081             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
11082                 return false;
11083             }
11084             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
11085                 return false;
11086             }
11087             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
11088                 return false;
11089             }
11090             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
11091                 return false;
11092             }
11093             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
11094                 return false;
11095             }
11096             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
11097                 return false;
11098             }
11099             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
11100                 return false;
11101             }
11102         }
11103         catch ( final Exception e ) {
11104             e.printStackTrace( System.out );
11105             return false;
11106         }
11107         return true;
11108     }
11109
11110     private static boolean testRerooting() {
11111         try {
11112             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11113             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",
11114                                                  new NHXParser() )[ 0 ];
11115             if ( !t1.isRooted() ) {
11116                 return false;
11117             }
11118             t1.reRoot( t1.getNode( "D" ) );
11119             t1.reRoot( t1.getNode( "CD" ) );
11120             t1.reRoot( t1.getNode( "A" ) );
11121             t1.reRoot( t1.getNode( "B" ) );
11122             t1.reRoot( t1.getNode( "AB" ) );
11123             t1.reRoot( t1.getNode( "D" ) );
11124             t1.reRoot( t1.getNode( "C" ) );
11125             t1.reRoot( t1.getNode( "CD" ) );
11126             t1.reRoot( t1.getNode( "A" ) );
11127             t1.reRoot( t1.getNode( "B" ) );
11128             t1.reRoot( t1.getNode( "AB" ) );
11129             t1.reRoot( t1.getNode( "D" ) );
11130             t1.reRoot( t1.getNode( "D" ) );
11131             t1.reRoot( t1.getNode( "C" ) );
11132             t1.reRoot( t1.getNode( "A" ) );
11133             t1.reRoot( t1.getNode( "B" ) );
11134             t1.reRoot( t1.getNode( "AB" ) );
11135             t1.reRoot( t1.getNode( "C" ) );
11136             t1.reRoot( t1.getNode( "D" ) );
11137             t1.reRoot( t1.getNode( "CD" ) );
11138             t1.reRoot( t1.getNode( "D" ) );
11139             t1.reRoot( t1.getNode( "A" ) );
11140             t1.reRoot( t1.getNode( "B" ) );
11141             t1.reRoot( t1.getNode( "AB" ) );
11142             t1.reRoot( t1.getNode( "C" ) );
11143             t1.reRoot( t1.getNode( "D" ) );
11144             t1.reRoot( t1.getNode( "CD" ) );
11145             t1.reRoot( t1.getNode( "D" ) );
11146             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
11147                 return false;
11148             }
11149             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
11150                 return false;
11151             }
11152             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
11153                 return false;
11154             }
11155             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
11156                 return false;
11157             }
11158             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
11159                 return false;
11160             }
11161             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
11162                 return false;
11163             }
11164             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",
11165                                                  new NHXParser() )[ 0 ];
11166             t2.reRoot( t2.getNode( "A" ) );
11167             t2.reRoot( t2.getNode( "D" ) );
11168             t2.reRoot( t2.getNode( "ABC" ) );
11169             t2.reRoot( t2.getNode( "A" ) );
11170             t2.reRoot( t2.getNode( "B" ) );
11171             t2.reRoot( t2.getNode( "D" ) );
11172             t2.reRoot( t2.getNode( "C" ) );
11173             t2.reRoot( t2.getNode( "ABC" ) );
11174             t2.reRoot( t2.getNode( "A" ) );
11175             t2.reRoot( t2.getNode( "B" ) );
11176             t2.reRoot( t2.getNode( "AB" ) );
11177             t2.reRoot( t2.getNode( "AB" ) );
11178             t2.reRoot( t2.getNode( "D" ) );
11179             t2.reRoot( t2.getNode( "C" ) );
11180             t2.reRoot( t2.getNode( "B" ) );
11181             t2.reRoot( t2.getNode( "AB" ) );
11182             t2.reRoot( t2.getNode( "D" ) );
11183             t2.reRoot( t2.getNode( "D" ) );
11184             t2.reRoot( t2.getNode( "ABC" ) );
11185             t2.reRoot( t2.getNode( "A" ) );
11186             t2.reRoot( t2.getNode( "B" ) );
11187             t2.reRoot( t2.getNode( "AB" ) );
11188             t2.reRoot( t2.getNode( "D" ) );
11189             t2.reRoot( t2.getNode( "C" ) );
11190             t2.reRoot( t2.getNode( "ABC" ) );
11191             t2.reRoot( t2.getNode( "A" ) );
11192             t2.reRoot( t2.getNode( "B" ) );
11193             t2.reRoot( t2.getNode( "AB" ) );
11194             t2.reRoot( t2.getNode( "D" ) );
11195             t2.reRoot( t2.getNode( "D" ) );
11196             t2.reRoot( t2.getNode( "C" ) );
11197             t2.reRoot( t2.getNode( "A" ) );
11198             t2.reRoot( t2.getNode( "B" ) );
11199             t2.reRoot( t2.getNode( "AB" ) );
11200             t2.reRoot( t2.getNode( "C" ) );
11201             t2.reRoot( t2.getNode( "D" ) );
11202             t2.reRoot( t2.getNode( "ABC" ) );
11203             t2.reRoot( t2.getNode( "D" ) );
11204             t2.reRoot( t2.getNode( "A" ) );
11205             t2.reRoot( t2.getNode( "B" ) );
11206             t2.reRoot( t2.getNode( "AB" ) );
11207             t2.reRoot( t2.getNode( "C" ) );
11208             t2.reRoot( t2.getNode( "D" ) );
11209             t2.reRoot( t2.getNode( "ABC" ) );
11210             t2.reRoot( t2.getNode( "D" ) );
11211             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11212                 return false;
11213             }
11214             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11215                 return false;
11216             }
11217             t2.reRoot( t2.getNode( "ABC" ) );
11218             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11219                 return false;
11220             }
11221             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11222                 return false;
11223             }
11224             t2.reRoot( t2.getNode( "AB" ) );
11225             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11226                 return false;
11227             }
11228             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11229                 return false;
11230             }
11231             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11232                 return false;
11233             }
11234             t2.reRoot( t2.getNode( "AB" ) );
11235             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11236                 return false;
11237             }
11238             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11239                 return false;
11240             }
11241             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11242                 return false;
11243             }
11244             t2.reRoot( t2.getNode( "D" ) );
11245             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11246                 return false;
11247             }
11248             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11249                 return false;
11250             }
11251             t2.reRoot( t2.getNode( "ABC" ) );
11252             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11253                 return false;
11254             }
11255             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11256                 return false;
11257             }
11258             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
11259                                                  new NHXParser() )[ 0 ];
11260             t3.reRoot( t3.getNode( "B" ) );
11261             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11262                 return false;
11263             }
11264             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11265                 return false;
11266             }
11267             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11268                 return false;
11269             }
11270             t3.reRoot( t3.getNode( "B" ) );
11271             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11272                 return false;
11273             }
11274             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11275                 return false;
11276             }
11277             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11278                 return false;
11279             }
11280             t3.reRoot( t3.getRoot() );
11281             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11282                 return false;
11283             }
11284             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11285                 return false;
11286             }
11287             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11288                 return false;
11289             }
11290         }
11291         catch ( final Exception e ) {
11292             e.printStackTrace( System.out );
11293             return false;
11294         }
11295         return true;
11296     }
11297
11298     private static boolean testSDIse() {
11299         try {
11300             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11301             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
11302             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
11303             gene1.setRooted( true );
11304             species1.setRooted( true );
11305             final SDI sdi = new SDI( gene1, species1 );
11306             if ( !gene1.getRoot().isDuplication() ) {
11307                 return false;
11308             }
11309             final Phylogeny species2 = factory.create(
11310                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11311                                                        new NHXParser() )[ 0 ];
11312             final Phylogeny gene2 = factory.create(
11313                                                     "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11314                                                     new NHXParser() )[ 0 ];
11315             species2.setRooted( true );
11316             gene2.setRooted( true );
11317             final SDI sdi2 = new SDI( gene2, species2 );
11318             if ( sdi2.getDuplicationsSum() != 0 ) {
11319                 return false;
11320             }
11321             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
11322                 return false;
11323             }
11324             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
11325                 return false;
11326             }
11327             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
11328                 return false;
11329             }
11330             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
11331                 return false;
11332             }
11333             if ( !gene2.getNode( "r" ).isSpeciation() ) {
11334                 return false;
11335             }
11336             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
11337                 return false;
11338             }
11339             final Phylogeny species3 = factory.create(
11340                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11341                                                        new NHXParser() )[ 0 ];
11342             final Phylogeny gene3 = factory.create(
11343                                                     "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11344                                                     new NHXParser() )[ 0 ];
11345             species3.setRooted( true );
11346             gene3.setRooted( true );
11347             final SDI sdi3 = new SDI( gene3, species3 );
11348             if ( sdi3.getDuplicationsSum() != 1 ) {
11349                 return false;
11350             }
11351             if ( !gene3.getNode( "aa" ).isDuplication() ) {
11352                 return false;
11353             }
11354             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
11355                 return false;
11356             }
11357             final Phylogeny species4 = factory.create(
11358                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11359                                                        new NHXParser() )[ 0 ];
11360             final Phylogeny gene4 = factory.create(
11361                                                     "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11362                                                     new NHXParser() )[ 0 ];
11363             species4.setRooted( true );
11364             gene4.setRooted( true );
11365             final SDI sdi4 = new SDI( gene4, species4 );
11366             if ( sdi4.getDuplicationsSum() != 1 ) {
11367                 return false;
11368             }
11369             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
11370                 return false;
11371             }
11372             if ( !gene4.getNode( "abc" ).isDuplication() ) {
11373                 return false;
11374             }
11375             if ( gene4.getNode( "abcd" ).isDuplication() ) {
11376                 return false;
11377             }
11378             if ( species4.getNumberOfExternalNodes() != 6 ) {
11379                 return false;
11380             }
11381             if ( gene4.getNumberOfExternalNodes() != 6 ) {
11382                 return false;
11383             }
11384             final Phylogeny species5 = factory.create(
11385                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11386                                                        new NHXParser() )[ 0 ];
11387             final Phylogeny gene5 = factory.create(
11388                                                     "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11389                                                     new NHXParser() )[ 0 ];
11390             species5.setRooted( true );
11391             gene5.setRooted( true );
11392             final SDI sdi5 = new SDI( gene5, species5 );
11393             if ( sdi5.getDuplicationsSum() != 2 ) {
11394                 return false;
11395             }
11396             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
11397                 return false;
11398             }
11399             if ( !gene5.getNode( "adc" ).isDuplication() ) {
11400                 return false;
11401             }
11402             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
11403                 return false;
11404             }
11405             if ( species5.getNumberOfExternalNodes() != 6 ) {
11406                 return false;
11407             }
11408             if ( gene5.getNumberOfExternalNodes() != 6 ) {
11409                 return false;
11410             }
11411             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
11412             // Conjecture for Comparing Molecular Phylogenies"
11413             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
11414             final Phylogeny species6 = factory.create(
11415                                                        "(((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,"
11416                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11417                                                        new NHXParser() )[ 0 ];
11418             final Phylogeny gene6 = factory.create(
11419                                                     "(((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,"
11420                                                             + "((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,"
11421                                                             + "(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;",
11422                                                     new NHXParser() )[ 0 ];
11423             species6.setRooted( true );
11424             gene6.setRooted( true );
11425             final SDI sdi6 = new SDI( gene6, species6 );
11426             if ( sdi6.getDuplicationsSum() != 3 ) {
11427                 return false;
11428             }
11429             if ( !gene6.getNode( "r" ).isDuplication() ) {
11430                 return false;
11431             }
11432             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
11433                 return false;
11434             }
11435             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
11436                 return false;
11437             }
11438             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
11439                 return false;
11440             }
11441             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
11442                 return false;
11443             }
11444             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
11445                 return false;
11446             }
11447             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
11448                 return false;
11449             }
11450             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
11451                 return false;
11452             }
11453             sdi6.computeMappingCostL();
11454             if ( sdi6.computeMappingCostL() != 17 ) {
11455                 return false;
11456             }
11457             if ( species6.getNumberOfExternalNodes() != 9 ) {
11458                 return false;
11459             }
11460             if ( gene6.getNumberOfExternalNodes() != 9 ) {
11461                 return false;
11462             }
11463             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
11464                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
11465                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
11466                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
11467                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
11468             species7.setRooted( true );
11469             final Phylogeny gene7_1 = Test
11470                     .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])" );
11471             gene7_1.setRooted( true );
11472             final SDI sdi7 = new SDI( gene7_1, species7 );
11473             if ( sdi7.getDuplicationsSum() != 0 ) {
11474                 return false;
11475             }
11476             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
11477                 return false;
11478             }
11479             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
11480                 return false;
11481             }
11482             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
11483                 return false;
11484             }
11485             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
11486                 return false;
11487             }
11488             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
11489                 return false;
11490             }
11491             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
11492                 return false;
11493             }
11494             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
11495                 return false;
11496             }
11497             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
11498                 return false;
11499             }
11500             final Phylogeny gene7_2 = Test
11501                     .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])" );
11502             gene7_2.setRooted( true );
11503             final SDI sdi7_2 = new SDI( gene7_2, species7 );
11504             if ( sdi7_2.getDuplicationsSum() != 1 ) {
11505                 return false;
11506             }
11507             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
11508                 return false;
11509             }
11510             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
11511                 return false;
11512             }
11513             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
11514                 return false;
11515             }
11516             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
11517                 return false;
11518             }
11519             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
11520                 return false;
11521             }
11522             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
11523                 return false;
11524             }
11525             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
11526                 return false;
11527             }
11528             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
11529                 return false;
11530             }
11531             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
11532                 return false;
11533             }
11534         }
11535         catch ( final Exception e ) {
11536             return false;
11537         }
11538         return true;
11539     }
11540
11541     private static boolean testSDIunrooted() {
11542         try {
11543             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11544             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef",
11545                                                  new NHXParser() )[ 0 ];
11546             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
11547             final Iterator<PhylogenyBranch> iter = l.iterator();
11548             PhylogenyBranch br = iter.next();
11549             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
11550                 return false;
11551             }
11552             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
11553                 return false;
11554             }
11555             br = iter.next();
11556             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11557                 return false;
11558             }
11559             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11560                 return false;
11561             }
11562             br = iter.next();
11563             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
11564                 return false;
11565             }
11566             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
11567                 return false;
11568             }
11569             br = iter.next();
11570             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11571                 return false;
11572             }
11573             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11574                 return false;
11575             }
11576             br = iter.next();
11577             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11578                 return false;
11579             }
11580             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11581                 return false;
11582             }
11583             br = iter.next();
11584             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11585                 return false;
11586             }
11587             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11588                 return false;
11589             }
11590             br = iter.next();
11591             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11592                 return false;
11593             }
11594             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11595                 return false;
11596             }
11597             br = iter.next();
11598             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11599                 return false;
11600             }
11601             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11602                 return false;
11603             }
11604             br = iter.next();
11605             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11606                 return false;
11607             }
11608             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11609                 return false;
11610             }
11611             br = iter.next();
11612             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11613                 return false;
11614             }
11615             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11616                 return false;
11617             }
11618             br = iter.next();
11619             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11620                 return false;
11621             }
11622             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11623                 return false;
11624             }
11625             br = iter.next();
11626             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
11627                 return false;
11628             }
11629             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
11630                 return false;
11631             }
11632             br = iter.next();
11633             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11634                 return false;
11635             }
11636             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11637                 return false;
11638             }
11639             br = iter.next();
11640             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
11641                 return false;
11642             }
11643             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
11644                 return false;
11645             }
11646             br = iter.next();
11647             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
11648                 return false;
11649             }
11650             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
11651                 return false;
11652             }
11653             if ( iter.hasNext() ) {
11654                 return false;
11655             }
11656             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
11657             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
11658             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
11659             br = iter1.next();
11660             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11661                 return false;
11662             }
11663             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11664                 return false;
11665             }
11666             br = iter1.next();
11667             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11668                 return false;
11669             }
11670             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11671                 return false;
11672             }
11673             br = iter1.next();
11674             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11675                 return false;
11676             }
11677             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11678                 return false;
11679             }
11680             if ( iter1.hasNext() ) {
11681                 return false;
11682             }
11683             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
11684             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
11685             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
11686             br = iter2.next();
11687             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11688                 return false;
11689             }
11690             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11691                 return false;
11692             }
11693             br = iter2.next();
11694             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11695                 return false;
11696             }
11697             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11698                 return false;
11699             }
11700             br = iter2.next();
11701             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11702                 return false;
11703             }
11704             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11705                 return false;
11706             }
11707             if ( iter2.hasNext() ) {
11708                 return false;
11709             }
11710             final Phylogeny species0 = factory.create(
11711                                                        "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11712                                                        new NHXParser() )[ 0 ];
11713             final Phylogeny gene1 = factory.create(
11714                                                     "(((((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])",
11715                                                     new NHXParser() )[ 0 ];
11716             species0.setRooted( true );
11717             gene1.setRooted( true );
11718             final SDIR sdi_unrooted = new SDIR();
11719             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
11720             if ( sdi_unrooted.getCount() != 1 ) {
11721                 return false;
11722             }
11723             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
11724                 return false;
11725             }
11726             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
11727                 return false;
11728             }
11729             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
11730                 return false;
11731             }
11732             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11733                 return false;
11734             }
11735             final Phylogeny gene2 = factory.create(
11736                                                     "(((((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])",
11737                                                     new NHXParser() )[ 0 ];
11738             gene2.setRooted( true );
11739             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
11740             if ( sdi_unrooted.getCount() != 1 ) {
11741                 return false;
11742             }
11743             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11744                 return false;
11745             }
11746             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11747                 return false;
11748             }
11749             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
11750                 return false;
11751             }
11752             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11753                 return false;
11754             }
11755             final Phylogeny species6 = factory.create(
11756                                                        "(((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,"
11757                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11758                                                        new NHXParser() )[ 0 ];
11759             final Phylogeny gene6 = factory.create(
11760                                                     "((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],"
11761                                                             + "(((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],"
11762                                                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11763                                                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11764                                                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11765                                                     new NHXParser() )[ 0 ];
11766             species6.setRooted( true );
11767             gene6.setRooted( true );
11768             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
11769             if ( sdi_unrooted.getCount() != 1 ) {
11770                 return false;
11771             }
11772             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11773                 return false;
11774             }
11775             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11776                 return false;
11777             }
11778             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11779                 return false;
11780             }
11781             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11782                 return false;
11783             }
11784             if ( !p6[ 0 ].getRoot().isDuplication() ) {
11785                 return false;
11786             }
11787             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11788                 return false;
11789             }
11790             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11791                 return false;
11792             }
11793             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11794                 return false;
11795             }
11796             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11797                 return false;
11798             }
11799             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11800                 return false;
11801             }
11802             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11803                 return false;
11804             }
11805             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11806                 return false;
11807             }
11808             p6 = null;
11809             final Phylogeny species7 = factory.create(
11810                                                        "(((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,"
11811                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11812                                                        new NHXParser() )[ 0 ];
11813             final Phylogeny gene7 = factory.create(
11814                                                     "((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],"
11815                                                             + "(((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],"
11816                                                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11817                                                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11818                                                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11819                                                     new NHXParser() )[ 0 ];
11820             species7.setRooted( true );
11821             gene7.setRooted( true );
11822             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11823             if ( sdi_unrooted.getCount() != 1 ) {
11824                 return false;
11825             }
11826             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11827                 return false;
11828             }
11829             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11830                 return false;
11831             }
11832             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11833                 return false;
11834             }
11835             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11836                 return false;
11837             }
11838             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11839                 return false;
11840             }
11841             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11842                 return false;
11843             }
11844             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11845                 return false;
11846             }
11847             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11848                 return false;
11849             }
11850             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11851                 return false;
11852             }
11853             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11854                 return false;
11855             }
11856             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11857                 return false;
11858             }
11859             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11860                 return false;
11861             }
11862             p7 = null;
11863             final Phylogeny species8 = factory.create(
11864                                                        "(((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,"
11865                                                                + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11866                                                        new NHXParser() )[ 0 ];
11867             final Phylogeny gene8 = factory.create(
11868                                                     "((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],"
11869                                                             + "(((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],"
11870                                                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11871                                                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11872                                                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11873                                                     new NHXParser() )[ 0 ];
11874             species8.setRooted( true );
11875             gene8.setRooted( true );
11876             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11877             if ( sdi_unrooted.getCount() != 1 ) {
11878                 return false;
11879             }
11880             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11881                 return false;
11882             }
11883             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11884                 return false;
11885             }
11886             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11887                 return false;
11888             }
11889             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11890                 return false;
11891             }
11892             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11893                 return false;
11894             }
11895             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11896                 return false;
11897             }
11898             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11899                 return false;
11900             }
11901             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11902                 return false;
11903             }
11904             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11905                 return false;
11906             }
11907             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11908                 return false;
11909             }
11910             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11911                 return false;
11912             }
11913             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11914                 return false;
11915             }
11916             p8 = null;
11917         }
11918         catch ( final Exception e ) {
11919             e.printStackTrace( System.out );
11920             return false;
11921         }
11922         return true;
11923     }
11924
11925     private static boolean testSequenceDbWsTools1() {
11926         try {
11927             final PhylogenyNode n = new PhylogenyNode();
11928             n.setName( "NP_001025424" );
11929             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11930             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11931                     || !acc.getValue().equals( "NP_001025424" ) ) {
11932                 return false;
11933             }
11934             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11935             acc = SequenceDbWsTools.obtainSeqAccession( n );
11936             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11937                     || !acc.getValue().equals( "NP_001025424" ) ) {
11938                 return false;
11939             }
11940             n.setName( "NP_001025424.1" );
11941             acc = SequenceDbWsTools.obtainSeqAccession( n );
11942             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11943                     || !acc.getValue().equals( "NP_001025424" ) ) {
11944                 return false;
11945             }
11946             n.setName( "NM_001030253" );
11947             acc = SequenceDbWsTools.obtainSeqAccession( n );
11948             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11949                     || !acc.getValue().equals( "NM_001030253" ) ) {
11950                 return false;
11951             }
11952             n.setName( "BCL2_HUMAN" );
11953             acc = SequenceDbWsTools.obtainSeqAccession( n );
11954             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11955                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11956                 System.out.println( acc.toString() );
11957                 return false;
11958             }
11959             n.setName( "P10415" );
11960             acc = SequenceDbWsTools.obtainSeqAccession( n );
11961             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11962                     || !acc.getValue().equals( "P10415" ) ) {
11963                 System.out.println( acc.toString() );
11964                 return false;
11965             }
11966             n.setName( " P10415 " );
11967             acc = SequenceDbWsTools.obtainSeqAccession( n );
11968             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11969                     || !acc.getValue().equals( "P10415" ) ) {
11970                 System.out.println( acc.toString() );
11971                 return false;
11972             }
11973             n.setName( "_P10415|" );
11974             acc = SequenceDbWsTools.obtainSeqAccession( n );
11975             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11976                     || !acc.getValue().equals( "P10415" ) ) {
11977                 System.out.println( acc.toString() );
11978                 return false;
11979             }
11980             n.setName( "AY695820" );
11981             acc = SequenceDbWsTools.obtainSeqAccession( n );
11982             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11983                     || !acc.getValue().equals( "AY695820" ) ) {
11984                 System.out.println( acc.toString() );
11985                 return false;
11986             }
11987             n.setName( "_AY695820_" );
11988             acc = SequenceDbWsTools.obtainSeqAccession( n );
11989             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11990                     || !acc.getValue().equals( "AY695820" ) ) {
11991                 System.out.println( acc.toString() );
11992                 return false;
11993             }
11994             n.setName( "AAA59452" );
11995             acc = SequenceDbWsTools.obtainSeqAccession( n );
11996             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11997                     || !acc.getValue().equals( "AAA59452" ) ) {
11998                 System.out.println( acc.toString() );
11999                 return false;
12000             }
12001             n.setName( "_AAA59452_" );
12002             acc = SequenceDbWsTools.obtainSeqAccession( n );
12003             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12004                     || !acc.getValue().equals( "AAA59452" ) ) {
12005                 System.out.println( acc.toString() );
12006                 return false;
12007             }
12008             n.setName( "AAA59452.1" );
12009             acc = SequenceDbWsTools.obtainSeqAccession( n );
12010             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12011                     || !acc.getValue().equals( "AAA59452.1" ) ) {
12012                 System.out.println( acc.toString() );
12013                 return false;
12014             }
12015             n.setName( "_AAA59452.1_" );
12016             acc = SequenceDbWsTools.obtainSeqAccession( n );
12017             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12018                     || !acc.getValue().equals( "AAA59452.1" ) ) {
12019                 System.out.println( acc.toString() );
12020                 return false;
12021             }
12022             n.setName( "GI:94894583" );
12023             acc = SequenceDbWsTools.obtainSeqAccession( n );
12024             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
12025                     || !acc.getValue().equals( "94894583" ) ) {
12026                 System.out.println( acc.toString() );
12027                 return false;
12028             }
12029             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
12030             acc = SequenceDbWsTools.obtainSeqAccession( n );
12031             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
12032                     || !acc.getValue().equals( "71845847" ) ) {
12033                 System.out.println( acc.toString() );
12034                 return false;
12035             }
12036             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
12037             acc = SequenceDbWsTools.obtainSeqAccession( n );
12038             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
12039                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
12040                 System.out.println( acc.toString() );
12041                 return false;
12042             }
12043         }
12044         catch ( final Exception e ) {
12045             return false;
12046         }
12047         return true;
12048     }
12049
12050     private static boolean testSequenceDbWsTools2() {
12051         try {
12052             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
12053             SequenceDbWsTools.obtainSeqInformation( n1 );
12054             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
12055                 return false;
12056             }
12057             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
12058                 return false;
12059             }
12060             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
12061                 return false;
12062             }
12063             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
12064                 return false;
12065             }
12066             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
12067             SequenceDbWsTools.obtainSeqInformation( n2 );
12068             if ( !n2.getNodeData().getSequence().getName()
12069                     .equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
12070                 return false;
12071             }
12072             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
12073                 return false;
12074             }
12075             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
12076                 return false;
12077             }
12078             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
12079                 return false;
12080             }
12081             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
12082             SequenceDbWsTools.obtainSeqInformation( n3 );
12083             if ( !n3.getNodeData().getSequence().getName()
12084                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
12085                 return false;
12086             }
12087             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
12088                 return false;
12089             }
12090             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
12091                 return false;
12092             }
12093             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
12094                 return false;
12095             }
12096         }
12097         catch ( final IOException e ) {
12098             System.out.println();
12099             System.out.println( "the following might be due to absence internet connection:" );
12100             e.printStackTrace( System.out );
12101             return true;
12102         }
12103         catch ( final Exception e ) {
12104             e.printStackTrace();
12105             return false;
12106         }
12107         return true;
12108     }
12109
12110     private static boolean testSequenceIdParsing() {
12111         try {
12112             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
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" );
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( "segmented worms gb_ADF31344 and more" );
12131             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12132                     || !id.getValue().equals( "ADF31344" ) || !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_AAA96518_1" );
12140             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12141                     || !id.getValue().equals( "AAA96518" ) || !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( "gb_EHB07727_1_rodents_" );
12149             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12150                     || !id.getValue().equals( "EHB07727" ) || !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( "dbj_BAF37827_1_turtles_" );
12158             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12159                     || !id.getValue().equals( "BAF37827" ) || !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( "emb_CAA73223_1_primates_" );
12167             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12168                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
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" );
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( "mites_ref_XP_002434188_1_bla_XP_12345" );
12185             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12186                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
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( "P4A123" );
12194             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12195                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
12196                 if ( id != null ) {
12197                     System.out.println( "value   =" + id.getValue() );
12198                     System.out.println( "provider=" + id.getSource() );
12199                 }
12200                 return false;
12201             }
12202             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
12203             if ( id != null ) {
12204                 System.out.println( "value   =" + id.getValue() );
12205                 System.out.println( "provider=" + id.getSource() );
12206                 return false;
12207             }
12208             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
12209             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12210                     || !id.getValue().equals( "N3B004Z009" ) || !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( "A4CAA4ZBB9" );
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( "ecoli_A4CAA4ZBB9_rt" );
12227             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12228                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
12229                 if ( id != null ) {
12230                     System.out.println( "value   =" + id.getValue() );
12231                     System.out.println( "provider=" + id.getSource() );
12232                 }
12233                 return false;
12234             }
12235             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
12236             if ( id != null ) {
12237                 System.out.println( "value   =" + id.getValue() );
12238                 System.out.println( "provider=" + id.getSource() );
12239                 return false;
12240             }
12241         }
12242         catch ( final Exception e ) {
12243             e.printStackTrace( System.out );
12244             return false;
12245         }
12246         return true;
12247     }
12248
12249     private static boolean testSequenceWriter() {
12250         try {
12251             final String n = ForesterUtil.LINE_SEPARATOR;
12252             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
12253                 return false;
12254             }
12255             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
12256                 return false;
12257             }
12258             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
12259                 return false;
12260             }
12261             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
12262                 return false;
12263             }
12264             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
12265                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
12266                 return false;
12267             }
12268             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
12269                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
12270                 return false;
12271             }
12272         }
12273         catch ( final Exception e ) {
12274             e.printStackTrace();
12275             return false;
12276         }
12277         return true;
12278     }
12279
12280     private static boolean testSpecies() {
12281         try {
12282             final Species s1 = new BasicSpecies( "a" );
12283             final Species s2 = new BasicSpecies( "a" );
12284             final Species s3 = new BasicSpecies( "A" );
12285             final Species s4 = new BasicSpecies( "b" );
12286             if ( !s1.equals( s1 ) ) {
12287                 return false;
12288             }
12289             if ( s1.getSpeciesId().equals( "x" ) ) {
12290                 return false;
12291             }
12292             if ( s1.getSpeciesId().equals( null ) ) {
12293                 return false;
12294             }
12295             if ( !s1.equals( s2 ) ) {
12296                 return false;
12297             }
12298             if ( s1.equals( s3 ) ) {
12299                 return false;
12300             }
12301             if ( s1.hashCode() != s1.hashCode() ) {
12302                 return false;
12303             }
12304             if ( s1.hashCode() != s2.hashCode() ) {
12305                 return false;
12306             }
12307             if ( s1.hashCode() == s3.hashCode() ) {
12308                 return false;
12309             }
12310             if ( s1.compareTo( s1 ) != 0 ) {
12311                 return false;
12312             }
12313             if ( s1.compareTo( s2 ) != 0 ) {
12314                 return false;
12315             }
12316             if ( s1.compareTo( s3 ) != 0 ) {
12317                 return false;
12318             }
12319             if ( s1.compareTo( s4 ) >= 0 ) {
12320                 return false;
12321             }
12322             if ( s4.compareTo( s1 ) <= 0 ) {
12323                 return false;
12324             }
12325             if ( !s4.getSpeciesId().equals( "b" ) ) {
12326                 return false;
12327             }
12328             final Species s5 = new BasicSpecies( " C " );
12329             if ( !s5.getSpeciesId().equals( "C" ) ) {
12330                 return false;
12331             }
12332             if ( s5.equals( s1 ) ) {
12333                 return false;
12334             }
12335         }
12336         catch ( final Exception e ) {
12337             e.printStackTrace( System.out );
12338             return false;
12339         }
12340         return true;
12341     }
12342
12343     private static boolean testSplit() {
12344         try {
12345             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12346             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12347             //Archaeopteryx.createApplication( p0 );
12348             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
12349             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12350             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12351             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12352             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12353             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12354             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12355             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12356             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12357             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12358             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
12359             // System.out.println( s0.toString() );
12360             //
12361             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12362             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12363             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12364             if ( s0.match( query_nodes ) ) {
12365                 return false;
12366             }
12367             query_nodes = new HashSet<PhylogenyNode>();
12368             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12369             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12370             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12371             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12372             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12373             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12374             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12375             if ( !s0.match( query_nodes ) ) {
12376                 return false;
12377             }
12378             //
12379             query_nodes = new HashSet<PhylogenyNode>();
12380             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12381             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12382             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12383             if ( !s0.match( query_nodes ) ) {
12384                 return false;
12385             }
12386             //
12387             query_nodes = new HashSet<PhylogenyNode>();
12388             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12389             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12390             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12391             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12392             if ( !s0.match( query_nodes ) ) {
12393                 return false;
12394             }
12395             //
12396             query_nodes = new HashSet<PhylogenyNode>();
12397             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12398             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12399             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12400             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12401             if ( !s0.match( query_nodes ) ) {
12402                 return false;
12403             }
12404             //
12405             query_nodes = new HashSet<PhylogenyNode>();
12406             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12407             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12408             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12409             if ( !s0.match( query_nodes ) ) {
12410                 return false;
12411             }
12412             query_nodes = new HashSet<PhylogenyNode>();
12413             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12414             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12415             if ( !s0.match( query_nodes ) ) {
12416                 return false;
12417             }
12418             query_nodes = new HashSet<PhylogenyNode>();
12419             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12420             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12421             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12422             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12423             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12424             if ( !s0.match( query_nodes ) ) {
12425                 return false;
12426             }
12427             query_nodes = new HashSet<PhylogenyNode>();
12428             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12429             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12430             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12431             if ( !s0.match( query_nodes ) ) {
12432                 return false;
12433             }
12434             query_nodes = new HashSet<PhylogenyNode>();
12435             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12436             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12437             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12438             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12439             if ( !s0.match( query_nodes ) ) {
12440                 return false;
12441             }
12442             query_nodes = new HashSet<PhylogenyNode>();
12443             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12444             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12445             if ( s0.match( query_nodes ) ) {
12446                 return false;
12447             }
12448             query_nodes = new HashSet<PhylogenyNode>();
12449             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12450             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12451             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
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( "F" ) );
12458             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12459             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12460             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12461             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12462             if ( s0.match( query_nodes ) ) {
12463                 return false;
12464             }
12465             query_nodes = new HashSet<PhylogenyNode>();
12466             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12467             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12468             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12469             if ( s0.match( query_nodes ) ) {
12470                 return false;
12471             }
12472             query_nodes = new HashSet<PhylogenyNode>();
12473             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12474             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12475             if ( s0.match( query_nodes ) ) {
12476                 return false;
12477             }
12478             query_nodes = new HashSet<PhylogenyNode>();
12479             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12480             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12481             if ( s0.match( query_nodes ) ) {
12482                 return false;
12483             }
12484             query_nodes = new HashSet<PhylogenyNode>();
12485             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12486             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12487             if ( s0.match( query_nodes ) ) {
12488                 return false;
12489             }
12490             query_nodes = new HashSet<PhylogenyNode>();
12491             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12492             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12493             if ( s0.match( query_nodes ) ) {
12494                 return false;
12495             }
12496             query_nodes = new HashSet<PhylogenyNode>();
12497             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12498             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12499             if ( s0.match( query_nodes ) ) {
12500                 return false;
12501             }
12502             query_nodes = new HashSet<PhylogenyNode>();
12503             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12504             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12505             if ( s0.match( query_nodes ) ) {
12506                 return false;
12507             }
12508             query_nodes = new HashSet<PhylogenyNode>();
12509             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12510             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12511             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12512             if ( s0.match( query_nodes ) ) {
12513                 return false;
12514             }
12515             query_nodes = new HashSet<PhylogenyNode>();
12516             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12517             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12518             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12519             if ( s0.match( query_nodes ) ) {
12520                 return false;
12521             }
12522             query_nodes = new HashSet<PhylogenyNode>();
12523             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12524             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12525             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12526             if ( s0.match( query_nodes ) ) {
12527                 return false;
12528             }
12529             query_nodes = new HashSet<PhylogenyNode>();
12530             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12531             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12532             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12533             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12534             if ( s0.match( query_nodes ) ) {
12535                 return false;
12536             }
12537             /////////
12538             //            query_nodes = new HashSet<PhylogenyNode>();
12539             //            query_nodes.add( new PhylogenyNode( "X" ) );
12540             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12541             //            query_nodes.add( new PhylogenyNode( "A" ) );
12542             //            query_nodes.add( new PhylogenyNode( "B" ) );
12543             //            query_nodes.add( new PhylogenyNode( "C" ) );
12544             //            query_nodes.add( new PhylogenyNode( "D" ) );
12545             //            query_nodes.add( new PhylogenyNode( "E" ) );
12546             //            query_nodes.add( new PhylogenyNode( "F" ) );
12547             //            query_nodes.add( new PhylogenyNode( "G" ) );
12548             //            if ( !s0.match( query_nodes ) ) {
12549             //                return false;
12550             //            }
12551             //            query_nodes = new HashSet<PhylogenyNode>();
12552             //            query_nodes.add( new PhylogenyNode( "X" ) );
12553             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12554             //            query_nodes.add( new PhylogenyNode( "A" ) );
12555             //            query_nodes.add( new PhylogenyNode( "B" ) );
12556             //            query_nodes.add( new PhylogenyNode( "C" ) );
12557             //            if ( !s0.match( query_nodes ) ) {
12558             //                return false;
12559             //            }
12560             //            //
12561             //            query_nodes = new HashSet<PhylogenyNode>();
12562             //            query_nodes.add( new PhylogenyNode( "X" ) );
12563             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12564             //            query_nodes.add( new PhylogenyNode( "D" ) );
12565             //            query_nodes.add( new PhylogenyNode( "E" ) );
12566             //            query_nodes.add( new PhylogenyNode( "F" ) );
12567             //            query_nodes.add( new PhylogenyNode( "G" ) );
12568             //            if ( !s0.match( query_nodes ) ) {
12569             //                return false;
12570             //            }
12571             //            //
12572             //            query_nodes = new HashSet<PhylogenyNode>();
12573             //            query_nodes.add( new PhylogenyNode( "X" ) );
12574             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12575             //            query_nodes.add( new PhylogenyNode( "A" ) );
12576             //            query_nodes.add( new PhylogenyNode( "B" ) );
12577             //            query_nodes.add( new PhylogenyNode( "C" ) );
12578             //            query_nodes.add( new PhylogenyNode( "D" ) );
12579             //            if ( !s0.match( query_nodes ) ) {
12580             //                return false;
12581             //            }
12582             //            //
12583             //            query_nodes = new HashSet<PhylogenyNode>();
12584             //            query_nodes.add( new PhylogenyNode( "X" ) );
12585             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12586             //            query_nodes.add( new PhylogenyNode( "E" ) );
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( new PhylogenyNode( "X" ) );
12595             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12596             //            query_nodes.add( new PhylogenyNode( "F" ) );
12597             //            query_nodes.add( new PhylogenyNode( "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( "E" ) );
12606             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12607             if ( s0.match( query_nodes ) ) {
12608                 return false;
12609             }
12610             //
12611             query_nodes = new HashSet<PhylogenyNode>();
12612             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12613             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12614             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12615             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12616             if ( s0.match( query_nodes ) ) {
12617                 return false;
12618             }
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( "D" ) );
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( "B" ) );
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( "C" ) );
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( "E" ) );
12653             if ( s0.match( query_nodes ) ) {
12654                 return false;
12655             }
12656             //
12657             query_nodes = new HashSet<PhylogenyNode>();
12658             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12659             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12660             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12661             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12662             if ( s0.match( query_nodes ) ) {
12663                 return false;
12664             }
12665             //
12666             query_nodes = new HashSet<PhylogenyNode>();
12667             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12668             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12669             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12670             if ( s0.match( query_nodes ) ) {
12671                 return false;
12672             }
12673             //
12674             query_nodes = new HashSet<PhylogenyNode>();
12675             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12676             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12677             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12678             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12679             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12680             if ( s0.match( query_nodes ) ) {
12681                 return false;
12682             }
12683             //
12684             query_nodes = new HashSet<PhylogenyNode>();
12685             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12686             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12688             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12689             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12690             if ( s0.match( query_nodes ) ) {
12691                 return false;
12692             }
12693             //
12694             query_nodes = new HashSet<PhylogenyNode>();
12695             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12696             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12697             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12698             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12699             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12700             if ( s0.match( query_nodes ) ) {
12701                 return false;
12702             }
12703             //
12704             query_nodes = new HashSet<PhylogenyNode>();
12705             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12706             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12707             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12708             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12709             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12710             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12711             if ( s0.match( query_nodes ) ) {
12712                 return false;
12713             }
12714         }
12715         catch ( final Exception e ) {
12716             e.printStackTrace();
12717             return false;
12718         }
12719         return true;
12720     }
12721
12722     private static boolean testSplitStrict() {
12723         try {
12724             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12725             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12726             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
12727             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12728             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12729             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12730             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12731             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12732             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12733             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12734             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
12735             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12736             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12737             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12738             if ( s0.match( query_nodes ) ) {
12739                 return false;
12740             }
12741             query_nodes = new HashSet<PhylogenyNode>();
12742             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12743             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12744             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12745             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12746             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12747             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12748             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12749             if ( !s0.match( query_nodes ) ) {
12750                 return false;
12751             }
12752             //
12753             query_nodes = new HashSet<PhylogenyNode>();
12754             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12755             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12756             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12757             if ( !s0.match( query_nodes ) ) {
12758                 return false;
12759             }
12760             //
12761             query_nodes = new HashSet<PhylogenyNode>();
12762             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12763             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12764             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12765             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12766             if ( !s0.match( query_nodes ) ) {
12767                 return false;
12768             }
12769             //
12770             query_nodes = new HashSet<PhylogenyNode>();
12771             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12772             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12773             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12774             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12775             if ( !s0.match( query_nodes ) ) {
12776                 return false;
12777             }
12778             //
12779             query_nodes = new HashSet<PhylogenyNode>();
12780             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12781             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12782             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12783             if ( !s0.match( query_nodes ) ) {
12784                 return false;
12785             }
12786             //
12787             query_nodes = new HashSet<PhylogenyNode>();
12788             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12789             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12790             if ( !s0.match( query_nodes ) ) {
12791                 return false;
12792             }
12793             //
12794             query_nodes = new HashSet<PhylogenyNode>();
12795             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12796             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12797             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12798             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12799             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12800             if ( !s0.match( query_nodes ) ) {
12801                 return false;
12802             }
12803             //
12804             query_nodes = new HashSet<PhylogenyNode>();
12805             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12806             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12807             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
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( "G" ) );
12815             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12816             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12817             if ( !s0.match( query_nodes ) ) {
12818                 return false;
12819             }
12820             //
12821             query_nodes = new HashSet<PhylogenyNode>();
12822             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12823             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12824             if ( s0.match( query_nodes ) ) {
12825                 return false;
12826             }
12827             //
12828             query_nodes = new HashSet<PhylogenyNode>();
12829             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12830             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12831             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12832             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12833             if ( s0.match( query_nodes ) ) {
12834                 return false;
12835             }
12836             //
12837             query_nodes = new HashSet<PhylogenyNode>();
12838             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12839             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12840             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12841             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12842             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12843             if ( s0.match( query_nodes ) ) {
12844                 return false;
12845             }
12846             //
12847             query_nodes = new HashSet<PhylogenyNode>();
12848             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12849             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12850             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12851             if ( s0.match( query_nodes ) ) {
12852                 return false;
12853             }
12854             //
12855             query_nodes = new HashSet<PhylogenyNode>();
12856             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12857             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12858             if ( s0.match( query_nodes ) ) {
12859                 return false;
12860             }
12861             //
12862             query_nodes = new HashSet<PhylogenyNode>();
12863             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12864             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12865             if ( s0.match( query_nodes ) ) {
12866                 return false;
12867             }
12868             //
12869             query_nodes = new HashSet<PhylogenyNode>();
12870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12872             if ( s0.match( query_nodes ) ) {
12873                 return false;
12874             }
12875             //
12876             query_nodes = new HashSet<PhylogenyNode>();
12877             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12878             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12879             if ( s0.match( query_nodes ) ) {
12880                 return false;
12881             }
12882             //
12883             query_nodes = new HashSet<PhylogenyNode>();
12884             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12885             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12886             if ( s0.match( query_nodes ) ) {
12887                 return false;
12888             }
12889             //
12890             query_nodes = new HashSet<PhylogenyNode>();
12891             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12892             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12893             if ( s0.match( query_nodes ) ) {
12894                 return false;
12895             }
12896             //
12897             query_nodes = new HashSet<PhylogenyNode>();
12898             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12899             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12900             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12901             if ( s0.match( query_nodes ) ) {
12902                 return false;
12903             }
12904             //
12905             query_nodes = new HashSet<PhylogenyNode>();
12906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12908             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12909             if ( s0.match( query_nodes ) ) {
12910                 return false;
12911             }
12912             //
12913             query_nodes = new HashSet<PhylogenyNode>();
12914             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12915             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12916             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12917             if ( s0.match( query_nodes ) ) {
12918                 return false;
12919             }
12920             //
12921             query_nodes = new HashSet<PhylogenyNode>();
12922             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12923             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12924             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12925             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12926             if ( s0.match( query_nodes ) ) {
12927                 return false;
12928             }
12929         }
12930         catch ( final Exception e ) {
12931             e.printStackTrace();
12932             return false;
12933         }
12934         return true;
12935     }
12936
12937     private static boolean testSubtreeDeletion() {
12938         try {
12939             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12940             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12941             t1.deleteSubtree( t1.getNode( "A" ), false );
12942             if ( t1.getNumberOfExternalNodes() != 5 ) {
12943                 return false;
12944             }
12945             t1.toNewHampshireX();
12946             t1.deleteSubtree( t1.getNode( "E" ), false );
12947             if ( t1.getNumberOfExternalNodes() != 4 ) {
12948                 return false;
12949             }
12950             t1.toNewHampshireX();
12951             t1.deleteSubtree( t1.getNode( "F" ), false );
12952             if ( t1.getNumberOfExternalNodes() != 3 ) {
12953                 return false;
12954             }
12955             t1.toNewHampshireX();
12956             t1.deleteSubtree( t1.getNode( "D" ), false );
12957             t1.toNewHampshireX();
12958             if ( t1.getNumberOfExternalNodes() != 3 ) {
12959                 return false;
12960             }
12961             t1.deleteSubtree( t1.getNode( "def" ), false );
12962             t1.toNewHampshireX();
12963             if ( t1.getNumberOfExternalNodes() != 2 ) {
12964                 return false;
12965             }
12966             t1.deleteSubtree( t1.getNode( "B" ), false );
12967             t1.toNewHampshireX();
12968             if ( t1.getNumberOfExternalNodes() != 1 ) {
12969                 return false;
12970             }
12971             t1.deleteSubtree( t1.getNode( "C" ), false );
12972             t1.toNewHampshireX();
12973             if ( t1.getNumberOfExternalNodes() != 1 ) {
12974                 return false;
12975             }
12976             t1.deleteSubtree( t1.getNode( "abc" ), false );
12977             t1.toNewHampshireX();
12978             if ( t1.getNumberOfExternalNodes() != 1 ) {
12979                 return false;
12980             }
12981             t1.deleteSubtree( t1.getNode( "r" ), false );
12982             if ( t1.getNumberOfExternalNodes() != 0 ) {
12983                 return false;
12984             }
12985             if ( !t1.isEmpty() ) {
12986                 return false;
12987             }
12988             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12989             t2.deleteSubtree( t2.getNode( "A" ), false );
12990             t2.toNewHampshireX();
12991             if ( t2.getNumberOfExternalNodes() != 5 ) {
12992                 return false;
12993             }
12994             t2.deleteSubtree( t2.getNode( "abc" ), false );
12995             t2.toNewHampshireX();
12996             if ( t2.getNumberOfExternalNodes() != 3 ) {
12997                 return false;
12998             }
12999             t2.deleteSubtree( t2.getNode( "def" ), false );
13000             t2.toNewHampshireX();
13001             if ( t2.getNumberOfExternalNodes() != 1 ) {
13002                 return false;
13003             }
13004         }
13005         catch ( final Exception e ) {
13006             e.printStackTrace( System.out );
13007             return false;
13008         }
13009         return true;
13010     }
13011
13012     private static boolean testSupportCount() {
13013         try {
13014             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13015             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
13016             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
13017                     + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
13018                     + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))" + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
13019                                                               new NHXParser() );
13020             SupportCount.count( t0_1, phylogenies_1, true, false );
13021             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
13022             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
13023                     + "(((((A,B),C),D),E),((F,G),X))" + "(((((A,Y),B),C),D),((F,G),E))" + "(((((A,B),C),D),E),(F,G))"
13024                     + "(((((A,B),C),D),E),(F,G))" + "(((((A,B),C),D),E),(F,G))" + "(((((A,B),C),D),E),(F,G),Z)"
13025                     + "(((((A,B),C),D),E),(F,G))" + "((((((A,B),C),D),E),F),G)" + "(((((X,Y),F,G),E),((A,B),C)),D)",
13026                                                               new NHXParser() );
13027             SupportCount.count( t0_2, phylogenies_2, true, false );
13028             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
13029             while ( it.hasNext() ) {
13030                 final PhylogenyNode n = it.next();
13031                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
13032                     return false;
13033                 }
13034             }
13035             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
13036             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
13037                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
13038             SupportCount.count( t0_3, phylogenies_3, true, false );
13039             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
13040             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
13041                 return false;
13042             }
13043             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
13044                 return false;
13045             }
13046             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
13047                 return false;
13048             }
13049             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
13050                 return false;
13051             }
13052             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
13053                 return false;
13054             }
13055             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
13056                 return false;
13057             }
13058             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
13059                 return false;
13060             }
13061             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
13062                 return false;
13063             }
13064             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
13065                 return false;
13066             }
13067             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
13068                 return false;
13069             }
13070             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13071             final Phylogeny[] phylogenies_4 = factory
13072                     .create( "((((((A,X),C),B),D),E),F) " + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
13073             SupportCount.count( t0_4, phylogenies_4, true, false );
13074             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
13075             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
13076                 return false;
13077             }
13078             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
13079                 return false;
13080             }
13081             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
13082                 return false;
13083             }
13084             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
13085                 return false;
13086             }
13087             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
13088                 return false;
13089             }
13090             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
13091                 return false;
13092             }
13093             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
13094                 return false;
13095             }
13096             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
13097                 return false;
13098             }
13099             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
13100                 return false;
13101             }
13102             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
13103                 return false;
13104             }
13105             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13106             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13107             double d = SupportCount.compare( b1, a, true, true, true );
13108             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
13109                 return false;
13110             }
13111             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13112             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13113             d = SupportCount.compare( b2, a, true, true, true );
13114             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
13115                 return false;
13116             }
13117             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
13118             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
13119             d = SupportCount.compare( b3, a, true, true, true );
13120             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
13121                 return false;
13122             }
13123             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
13124             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
13125             d = SupportCount.compare( b4, a, true, true, false );
13126             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
13127                 return false;
13128             }
13129         }
13130         catch ( final Exception e ) {
13131             e.printStackTrace( System.out );
13132             return false;
13133         }
13134         return true;
13135     }
13136
13137     private static boolean testSupportTransfer() {
13138         try {
13139             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13140             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)",
13141                                                  new NHXParser() )[ 0 ];
13142             final Phylogeny p2 = factory.create(
13143                                                  "(((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)",
13144                                                  new NHXParser() )[ 0 ];
13145             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
13146                 return false;
13147             }
13148             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
13149                 return false;
13150             }
13151             support_transfer.moveBranchLengthsToBootstrap( p1 );
13152             support_transfer.transferSupportValues( p1, p2 );
13153             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
13154                 return false;
13155             }
13156             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
13157                 return false;
13158             }
13159             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
13160                 return false;
13161             }
13162             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
13163                 return false;
13164             }
13165             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
13166                 return false;
13167             }
13168             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
13169                 return false;
13170             }
13171             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
13172                 return false;
13173             }
13174             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
13175                 return false;
13176             }
13177         }
13178         catch ( final Exception e ) {
13179             e.printStackTrace( System.out );
13180             return false;
13181         }
13182         return true;
13183     }
13184
13185     private static boolean testTaxonomyExtraction() {
13186         try {
13187             final PhylogenyNode n0 = PhylogenyNode
13188                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13189             if ( n0.getNodeData().isHasTaxonomy() ) {
13190                 return false;
13191             }
13192             final PhylogenyNode n1 = PhylogenyNode
13193                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13194             if ( n1.getNodeData().isHasTaxonomy() ) {
13195                 System.out.println( n1.toString() );
13196                 return false;
13197             }
13198             final PhylogenyNode n2x = PhylogenyNode
13199                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13200             if ( n2x.getNodeData().isHasTaxonomy() ) {
13201                 return false;
13202             }
13203             final PhylogenyNode n3 = PhylogenyNode
13204                     .createInstanceFromNhxString( "BLAGG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13205             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13206                 System.out.println( n3.toString() );
13207                 return false;
13208             }
13209             final PhylogenyNode n4 = PhylogenyNode
13210                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13211             if ( n4.getNodeData().isHasTaxonomy() ) {
13212                 System.out.println( n4.toString() );
13213                 return false;
13214             }
13215             final PhylogenyNode n5 = PhylogenyNode
13216                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13217             if ( n5.getNodeData().isHasTaxonomy() ) {
13218                 System.out.println( n5.toString() );
13219                 return false;
13220             }
13221             final PhylogenyNode n6 = PhylogenyNode
13222                     .createInstanceFromNhxString( "BLAGG-12345-blag",
13223                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13224             if ( n6.getNodeData().isHasTaxonomy() ) {
13225                 System.out.println( n6.toString() );
13226                 return false;
13227             }
13228             final PhylogenyNode n7 = PhylogenyNode
13229                     .createInstanceFromNhxString( "BL-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13230             if ( n7.getNodeData().isHasTaxonomy() ) {
13231                 System.out.println( n7.toString() );
13232                 return false;
13233             }
13234             final PhylogenyNode n8 = PhylogenyNode
13235                     .createInstanceFromNhxString( "BLAGG_12345-blag",
13236                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13237             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13238                 System.out.println( n8.toString() );
13239                 return false;
13240             }
13241             final PhylogenyNode n9 = PhylogenyNode
13242                     .createInstanceFromNhxString( "BLAGG_12345/blag",
13243                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13244             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13245                 System.out.println( n9.toString() );
13246                 return false;
13247             }
13248             final PhylogenyNode n10x = PhylogenyNode
13249                     .createInstanceFromNhxString( "BLAG!_12X45-blag",
13250                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13251             if ( n10x.getNodeData().isHasTaxonomy() ) {
13252                 System.out.println( n10x.toString() );
13253                 return false;
13254             }
13255             final PhylogenyNode n10xx = PhylogenyNode
13256                     .createInstanceFromNhxString( "BLAG!_1YX45-blag",
13257                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13258             if ( n10xx.getNodeData().isHasTaxonomy() ) {
13259                 System.out.println( n10xx.toString() );
13260                 return false;
13261             }
13262             final PhylogenyNode n10 = PhylogenyNode
13263                     .createInstanceFromNhxString( "BLAGG_9YX45-blag",
13264                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13265             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
13266                 System.out.println( n10.toString() );
13267                 return false;
13268             }
13269             final PhylogenyNode n10v = PhylogenyNode
13270                     .createInstanceFromNhxString( "BLAGG_BPM1-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13271             if ( !n10v.getNodeData().getTaxonomy().getTaxonomyCode().equals( "BPM1" ) ) {
13272                 System.out.println( n10v.toString() );
13273                 return false;
13274             }
13275             final PhylogenyNode n10v2 = PhylogenyNode
13276                     .createInstanceFromNhxString( "BLAGG_ABV-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13277             if ( !n10v2.getNodeData().getTaxonomy().getTaxonomyCode().equals( "ABV" ) ) {
13278                 System.out.println( n10v2.toString() );
13279                 return false;
13280             }
13281             final PhylogenyNode n11 = PhylogenyNode
13282                     .createInstanceFromNhxString( "BLAG@_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13283             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13284                 System.out.println( n11.toString() );
13285                 return false;
13286             }
13287             final PhylogenyNode n12 = PhylogenyNode
13288                     .createInstanceFromNhxString( "BLA_G_Mus_musculus_musculus",
13289                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13290             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13291                 System.out.println( n12.toString() );
13292                 return false;
13293             }
13294             final PhylogenyNode n13 = PhylogenyNode
13295                     .createInstanceFromNhxString( "BLAaG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13296             if ( n13.getNodeData().isHasTaxonomy() ) {
13297                 System.out.println( n13.toString() );
13298                 return false;
13299             }
13300             final PhylogenyNode n14 = PhylogenyNode
13301                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13302             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13303                 System.out.println( n14.toString() );
13304                 return false;
13305             }
13306             final PhylogenyNode n15 = PhylogenyNode
13307                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13308             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13309                 System.out.println( n15.toString() );
13310                 return false;
13311             }
13312             final PhylogenyNode n16 = PhylogenyNode
13313                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13314             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13315                 System.out.println( n16.toString() );
13316                 return false;
13317             }
13318             final PhylogenyNode n17 = PhylogenyNode
13319                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13320             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13321                 System.out.println( n17.toString() );
13322                 return false;
13323             }
13324             final PhylogenyNode n18 = PhylogenyNode
13325                     .createInstanceFromNhxString( "Mus_musculus_musculus_392",
13326                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13327             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13328                 System.out.println( n18.toString() );
13329                 return false;
13330             }
13331             final PhylogenyNode n19 = PhylogenyNode
13332                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
13333                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13334             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13335                 System.out.println( n19.toString() );
13336                 return false;
13337             }
13338             final PhylogenyNode n20 = PhylogenyNode
13339                     .createInstanceFromNhxString( "Mus musculus musculus 392",
13340                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13341             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13342                 System.out.println( n20.toString() );
13343                 return false;
13344             }
13345             final PhylogenyNode n21 = PhylogenyNode
13346                     .createInstanceFromNhxString( "Mus musculus musculus K392",
13347                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13348             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13349                 System.out.println( n21.toString() );
13350                 return false;
13351             }
13352             final PhylogenyNode n23 = PhylogenyNode
13353                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
13354                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13355             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13356                 System.out.println( n23.toString() );
13357                 return false;
13358             }
13359             final PhylogenyNode n24 = PhylogenyNode
13360                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13361             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13362                 System.out.println( n24.toString() );
13363                 return false;
13364             }
13365             //
13366             final PhylogenyNode n25 = PhylogenyNode
13367                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
13368                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13369             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
13370                 System.out.println( n25.toString() );
13371                 return false;
13372             }
13373             final PhylogenyNode n26 = PhylogenyNode
13374                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
13375                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13376             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13377                 System.out.println( n26.toString() );
13378                 return false;
13379             }
13380             final PhylogenyNode n27 = PhylogenyNode
13381                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13382             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13383                 System.out.println( n27.toString() );
13384                 return false;
13385             }
13386         }
13387         catch ( final Exception e ) {
13388             e.printStackTrace( System.out );
13389             return false;
13390         }
13391         return true;
13392     }
13393
13394     private static boolean testTreeCopy() {
13395         try {
13396             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
13397             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
13398             final Phylogeny t1 = t0.copy();
13399             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
13400                 return false;
13401             }
13402             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13403                 return false;
13404             }
13405             t0.deleteSubtree( t0.getNode( "c" ), true );
13406             t0.deleteSubtree( t0.getNode( "a" ), true );
13407             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
13408             t0.getNode( "b" ).setName( "Bee" );
13409             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
13410                 return false;
13411             }
13412             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13413                 return false;
13414             }
13415             t0.deleteSubtree( t0.getNode( "e" ), true );
13416             t0.deleteSubtree( t0.getNode( "Bee" ), true );
13417             t0.deleteSubtree( t0.getNode( "d" ), true );
13418             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13419                 return false;
13420             }
13421         }
13422         catch ( final Exception e ) {
13423             e.printStackTrace();
13424             return false;
13425         }
13426         return true;
13427     }
13428
13429     private static boolean testTreeMethods() {
13430         try {
13431             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13432             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
13433             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
13434             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
13435                 System.out.println( t0.toNewHampshireX() );
13436                 return false;
13437             }
13438             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
13439             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
13440             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
13441                 return false;
13442             }
13443             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
13444                 return false;
13445             }
13446             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
13447                 return false;
13448             }
13449         }
13450         catch ( final Exception e ) {
13451             e.printStackTrace( System.out );
13452             return false;
13453         }
13454         return true;
13455     }
13456     
13457     private static boolean testPhylogenyMethods() {
13458         try {
13459             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13460             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)r", new NHXParser() )[ 0 ];
13461           
13462             if ( PhylogenyMethods.calculateLevel( t0.getNode( "A" ) ) != 0 ) {
13463                 return false;
13464             }
13465             if ( PhylogenyMethods.calculateLevel( t0.getNode( "B" ) ) != 0 ) {
13466                 return false;
13467             }
13468             if ( PhylogenyMethods.calculateLevel( t0.getNode( "ab" ) ) != 1 ) {
13469                 return false;
13470             }
13471             if ( PhylogenyMethods.calculateLevel( t0.getNode( "C" ) ) != 0 ) {
13472                 return false;
13473             }
13474             if ( PhylogenyMethods.calculateLevel( t0.getNode( "abc" ) ) != 2 ) {
13475                 return false;
13476             }
13477             if ( PhylogenyMethods.calculateLevel( t0.getNode( "D" ) ) != 0 ) {
13478                 return false;
13479             }
13480             if ( PhylogenyMethods.calculateLevel( t0.getNode( "abcd" ) ) != 3 ) {
13481                 return false;
13482             }
13483             if ( PhylogenyMethods.calculateLevel( t0.getNode( "E" ) ) != 0 ) {
13484                 return false;
13485             }
13486             if ( PhylogenyMethods.calculateLevel( t0.getNode( "r" ) ) != 4 ) {
13487                 return false;
13488             }
13489             final Phylogeny t1 = factory.create( "((((A,B)ab,C)abc,D)abcd,E,((((((X)1)2)3)4)5)6)r", new NHXParser() )[ 0 ];
13490             if ( PhylogenyMethods.calculateLevel( t1.getNode( "r" ) ) != 7 ) {
13491                 return false;
13492             }
13493             if ( PhylogenyMethods.calculateLevel( t1.getNode( "X" ) ) != 0 ) {
13494                 return false;
13495             }
13496             if ( PhylogenyMethods.calculateLevel( t1.getNode( "6" ) ) != 6 ) {
13497                 return false;
13498             }
13499             if ( PhylogenyMethods.calculateLevel( t1.getNode( "5" ) ) != 5 ) {
13500                 return false;
13501             }
13502             if ( PhylogenyMethods.calculateLevel( t1.getNode( "4" ) ) != 4 ) {
13503                 return false;
13504             }
13505             if ( PhylogenyMethods.calculateLevel( t1.getNode( "3" ) ) != 3 ) {
13506                 return false;
13507             }
13508             if ( PhylogenyMethods.calculateLevel( t1.getNode( "2" ) ) != 2 ) {
13509                 return false;
13510             }
13511             if ( PhylogenyMethods.calculateLevel( t1.getNode( "1" ) ) != 1 ) {
13512                 return false;
13513             }
13514             if ( PhylogenyMethods.calculateLevel( t1.getNode( "abcd" ) ) != 3 ) {
13515                 return false;
13516             }
13517             
13518         }
13519         catch ( final Exception e ) {
13520             e.printStackTrace( System.out );
13521             return false;
13522         }
13523         return true;
13524     }
13525
13526     private static boolean testUniprotEntryRetrieval() {
13527         try {
13528             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 5000 );
13529             if ( !entry.getAccession().equals( "P12345" ) ) {
13530                 return false;
13531             }
13532             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
13533                 return false;
13534             }
13535             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
13536                 return false;
13537             }
13538             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
13539                 return false;
13540             }
13541             if ( !entry.getGeneName().equals( "GOT2" ) ) {
13542                 return false;
13543             }
13544             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
13545                 return false;
13546             }
13547             if ( entry.getMolecularSequence() == null ) {
13548                 return false;
13549             }
13550             if ( !entry.getMolecularSequence().getMolecularSequenceAsString()
13551                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
13552                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
13553                 System.out.println( "got: " + entry.getMolecularSequence().getMolecularSequenceAsString() );
13554                 System.out.println( "expected something else." );
13555                 return false;
13556             }
13557         }
13558         catch ( final IOException e ) {
13559             System.out.println();
13560             System.out.println( "the following might be due to absence internet connection:" );
13561             e.printStackTrace( System.out );
13562             return true;
13563         }
13564         catch ( final NullPointerException f ) {
13565             f.printStackTrace( System.out );
13566             return false;
13567         }
13568         catch ( final Exception e ) {
13569             return false;
13570         }
13571         return true;
13572     }
13573
13574     private static boolean testUniprotTaxonomySearch() {
13575         try {
13576             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
13577                                                                                                  10 );
13578             if ( results.size() != 1 ) {
13579                 return false;
13580             }
13581             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13582                 return false;
13583             }
13584             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13585                 return false;
13586             }
13587             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13588                 return false;
13589             }
13590             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13591                 return false;
13592             }
13593             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13594                 return false;
13595             }
13596             results = null;
13597             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
13598             if ( results.size() != 1 ) {
13599                 return false;
13600             }
13601             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13602                 return false;
13603             }
13604             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13605                 return false;
13606             }
13607             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13608                 return false;
13609             }
13610             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13611                 return false;
13612             }
13613             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13614                 return false;
13615             }
13616             results = null;
13617             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
13618             if ( results.size() != 1 ) {
13619                 return false;
13620             }
13621             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13622                 return false;
13623             }
13624             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13625                 return false;
13626             }
13627             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13628                 return false;
13629             }
13630             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13631                 return false;
13632             }
13633             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13634                 return false;
13635             }
13636             results = null;
13637             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
13638             if ( results.size() != 1 ) {
13639                 return false;
13640             }
13641             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13642                 return false;
13643             }
13644             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13645                 return false;
13646             }
13647             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13648                 return false;
13649             }
13650             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13651                 return false;
13652             }
13653             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13654                 return false;
13655             }
13656             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
13657                 return false;
13658             }
13659             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
13660                 return false;
13661             }
13662             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13663                     .equals( "Nematostella vectensis" ) ) {
13664                 System.out.println( results.get( 0 ).getLineage() );
13665                 return false;
13666             }
13667             //
13668             results = null;
13669             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
13670             if ( results.size() != 1 ) {
13671                 return false;
13672             }
13673             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13674                 return false;
13675             }
13676             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13677                 return false;
13678             }
13679             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13680                 return false;
13681             }
13682             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13683                 return false;
13684             }
13685             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13686                 return false;
13687             }
13688             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13689                     .equals( "Xenopus tropicalis" ) ) {
13690                 System.out.println( results.get( 0 ).getLineage() );
13691                 return false;
13692             }
13693             //
13694             results = null;
13695             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
13696             if ( results.size() != 1 ) {
13697                 return false;
13698             }
13699             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13700                 return false;
13701             }
13702             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13703                 return false;
13704             }
13705             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13706                 return false;
13707             }
13708             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13709                 return false;
13710             }
13711             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13712                 return false;
13713             }
13714             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13715                     .equals( "Xenopus tropicalis" ) ) {
13716                 System.out.println( results.get( 0 ).getLineage() );
13717                 return false;
13718             }
13719             //
13720             results = null;
13721             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
13722             if ( results.size() != 1 ) {
13723                 return false;
13724             }
13725             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13726                 return false;
13727             }
13728             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13729                 return false;
13730             }
13731             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13732                 return false;
13733             }
13734             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13735                 return false;
13736             }
13737             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13738                 return false;
13739             }
13740             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13741                     .equals( "Xenopus tropicalis" ) ) {
13742                 System.out.println( results.get( 0 ).getLineage() );
13743                 return false;
13744             }
13745         }
13746         catch ( final IOException e ) {
13747             System.out.println();
13748             System.out.println( "the following might be due to absence internet connection:" );
13749             e.printStackTrace( System.out );
13750             return true;
13751         }
13752         catch ( final Exception e ) {
13753             return false;
13754         }
13755         return true;
13756     }
13757 }