13d2f3395b4426c22fbb888a7a5847db0dc633c8
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24
25 package org.forester.test;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.StringWriter;
32 import java.io.Writer;
33 import java.net.URL;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.HashSet;
37 import java.util.Iterator;
38 import java.util.List;
39 import java.util.Locale;
40 import java.util.Set;
41 import java.util.SortedSet;
42
43 import javax.net.ssl.HttpsURLConnection;
44 import javax.net.ssl.SSLContext;
45
46 import org.forester.application.support_transfer;
47 import org.forester.archaeopteryx.AptxUtil;
48 import org.forester.archaeopteryx.TreePanelUtil;
49 import org.forester.archaeopteryx.webservices.WebserviceUtil;
50 import org.forester.development.DevelopmentTools;
51 import org.forester.evoinference.TestPhylogenyReconstruction;
52 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
53 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
54 import org.forester.go.TestGo;
55 import org.forester.io.parsers.FastaParser;
56 import org.forester.io.parsers.GeneralMsaParser;
57 import org.forester.io.parsers.HmmscanPerDomainTableParser;
58 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
59 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
60 import org.forester.io.parsers.nexus.NexusCharactersParser;
61 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
62 import org.forester.io.parsers.nhx.NHXParser;
63 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
64 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
65 import org.forester.io.parsers.tol.TolParser;
66 import org.forester.io.parsers.util.ParserUtils;
67 import org.forester.io.writers.PhylogenyWriter;
68 import org.forester.io.writers.SequenceWriter;
69 import org.forester.msa.BasicMsa;
70 import org.forester.msa.DeleteableMsa;
71 import org.forester.msa.Mafft;
72 import org.forester.msa.Msa;
73 import org.forester.msa.Msa.MSA_FORMAT;
74 import org.forester.msa.MsaInferrer;
75 import org.forester.msa.MsaMethods;
76 import org.forester.pccx.TestPccx;
77 import org.forester.phylogeny.Phylogeny;
78 import org.forester.phylogeny.PhylogenyBranch;
79 import org.forester.phylogeny.PhylogenyMethods;
80 import org.forester.phylogeny.PhylogenyNode;
81 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
82 import org.forester.phylogeny.data.Accession;
83 import org.forester.phylogeny.data.Accession.Source;
84 import org.forester.phylogeny.data.BinaryCharacters;
85 import org.forester.phylogeny.data.BranchWidth;
86 import org.forester.phylogeny.data.Confidence;
87 import org.forester.phylogeny.data.Distribution;
88 import org.forester.phylogeny.data.DomainArchitecture;
89 import org.forester.phylogeny.data.Event;
90 import org.forester.phylogeny.data.Identifier;
91 import org.forester.phylogeny.data.PhylogenyData;
92 import org.forester.phylogeny.data.PhylogenyDataUtil;
93 import org.forester.phylogeny.data.Polygon;
94 import org.forester.phylogeny.data.PropertiesMap;
95 import org.forester.phylogeny.data.Property;
96 import org.forester.phylogeny.data.Property.AppliesTo;
97 import org.forester.phylogeny.data.ProteinDomain;
98 import org.forester.phylogeny.data.Taxonomy;
99 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
100 import org.forester.phylogeny.factories.PhylogenyFactory;
101 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
102 import org.forester.protein.BasicDomain;
103 import org.forester.protein.BasicProtein;
104 import org.forester.protein.Domain;
105 import org.forester.protein.Protein;
106 import org.forester.protein.ProteinId;
107 import org.forester.rio.TestRIO;
108 import org.forester.sdi.SDI;
109 import org.forester.sdi.SDIR;
110 import org.forester.sdi.TestGSDI;
111 import org.forester.sequence.BasicSequence;
112 import org.forester.sequence.MolecularSequence;
113 import org.forester.species.BasicSpecies;
114 import org.forester.species.Species;
115 import org.forester.surfacing.TestSurfacing;
116 import org.forester.tools.ConfidenceAssessor;
117 import org.forester.tools.SupportCount;
118 import org.forester.tools.TreeSplitMatrix;
119 import org.forester.util.AsciiHistogram;
120 import org.forester.util.BasicDescriptiveStatistics;
121 import org.forester.util.BasicTable;
122 import org.forester.util.BasicTableParser;
123 import org.forester.util.DescriptiveStatistics;
124 import org.forester.util.ForesterConstants;
125 import org.forester.util.ForesterUtil;
126 import org.forester.util.GeneralTable;
127 import org.forester.util.SequenceAccessionTools;
128 import org.forester.ws.seqdb.SequenceDatabaseEntry;
129 import org.forester.ws.seqdb.SequenceDbWsTools;
130 import org.forester.ws.seqdb.UniProtTaxonomy;
131
132
133 @SuppressWarnings( "unused")
134 public final class Test {
135
136     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
137             + ForesterUtil.getFileSeparator() + "resources"
138             + ForesterUtil.getFileSeparator();
139     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
140             + ForesterUtil.getFileSeparator() + "test_data"
141             + ForesterUtil.getFileSeparator();
142     private final static boolean PERFORM_DB_TESTS          = false;
143     private static final boolean PERFORM_WEB_TREE_ACCESS   = false;
144     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
145             + ForesterConstants.PHYLO_XML_VERSION + "/"
146             + ForesterConstants.PHYLO_XML_XSD;
147     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
148             + ForesterConstants.PHYLO_XML_VERSION + "/"
149             + ForesterConstants.PHYLO_XML_XSD;
150     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
151     private final static double  ZERO_DIFF                 = 1.0E-9;
152
153     private static boolean isEqual( final double a, final double b ) {
154         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
155     }
156
157     public static void main( final String[] args ) {
158         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
159         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
160                             + "]" );
161         Locale.setDefault( Locale.US );
162         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
163         int failed = 0;
164         int succeeded = 0;
165         System.out.print( "[Test if directory with files for testing exists/is readable: " );
166         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
167             System.out.println( "OK.]" );
168         }
169         else {
170             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
171             System.out.println( "Testing aborted." );
172             System.exit( -1 );
173         }
174         System.out.print( "[Test if resources directory exists/is readable: " );
175         if ( testDir( PATH_TO_RESOURCES ) ) {
176             System.out.println( "OK.]" );
177         }
178         else {
179             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
180             System.out.println( "Testing aborted." );
181             System.exit( -1 );
182         }
183         final long start_time = new Date().getTime();
184         
185         System.out.print( "Basic node methods: " );
186         if ( Test.testBasicNodeMethods() ) {
187             System.out.println( "OK." );
188             succeeded++;
189         }
190         else {
191             System.out.println( "failed." );
192             failed++;
193         }
194         System.out.print( "Protein id: " );
195         if ( !testProteinId() ) {
196             System.out.println( "failed." );
197             failed++;
198         }
199         else {
200             succeeded++;
201         }
202         System.out.println( "OK." );
203         System.out.print( "Species: " );
204         if ( !testSpecies() ) {
205             System.out.println( "failed." );
206             failed++;
207         }
208         else {
209             succeeded++;
210         }
211         System.out.println( "OK." );
212         System.out.print( "Basic domain: " );
213         if ( !testBasicDomain() ) {
214             System.out.println( "failed." );
215             failed++;
216         }
217         else {
218             succeeded++;
219         }
220         System.out.println( "OK." );
221         System.out.print( "Basic protein: " );
222         if ( !testBasicProtein() ) {
223             System.out.println( "failed." );
224             failed++;
225         }
226         else {
227             succeeded++;
228         }
229         System.out.println( "OK." );
230         System.out.print( "Sequence writer: " );
231         if ( testSequenceWriter() ) {
232             System.out.println( "OK." );
233             succeeded++;
234         }
235         else {
236             System.out.println( "failed." );
237             failed++;
238         }
239         System.out.print( "Sequence id parsing: " );
240         if ( testSequenceIdParsing() ) {
241             System.out.println( "OK." );
242             succeeded++;
243         }
244         else {
245             System.out.println( "failed." );
246             failed++;
247         }
248         System.out.print( "UniProtKB id extraction: " );
249         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
250             System.out.println( "OK." );
251             succeeded++;
252         }
253         else {
254             System.out.println( "failed." );
255             failed++;
256         }
257         System.out.print( "Sequence DB tools 1: " );
258         if ( testSequenceDbWsTools1() ) {
259             System.out.println( "OK." );
260             succeeded++;
261         }
262         else {
263             System.out.println( "failed." );
264             failed++;
265         }
266         System.out.print( "Hmmscan output parser: " );
267         if ( testHmmscanOutputParser() ) {
268             System.out.println( "OK." );
269             succeeded++;
270         }
271         else {
272             System.out.println( "failed." );
273             failed++;
274         }
275         System.out.print( "Overlap removal: " );
276         if ( !org.forester.test.Test.testOverlapRemoval() ) {
277             System.out.println( "failed." );
278             failed++;
279         }
280         else {
281             succeeded++;
282         }
283         System.out.println( "OK." );
284         System.out.print( "Engulfing overlap removal: " );
285         if ( !Test.testEngulfingOverlapRemoval() ) {
286             System.out.println( "failed." );
287             failed++;
288         }
289         else {
290             succeeded++;
291         }
292         System.out.println( "OK." );
293         System.out.print( "Taxonomy data extraction: " );
294         if ( Test.testExtractTaxonomyDataFromNodeName() ) {
295             System.out.println( "OK." );
296             succeeded++;
297         }
298         else {
299             System.out.println( "failed." );
300             failed++;
301         }
302         System.out.print( "Taxonomy code extraction: " );
303         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
304             System.out.println( "OK." );
305             succeeded++;
306         }
307         else {
308             System.out.println( "failed." );
309             failed++;
310         }
311         System.out.print( "SN extraction: " );
312         if ( Test.testExtractSNFromNodeName() ) {
313             System.out.println( "OK." );
314             succeeded++;
315         }
316         else {
317             System.out.println( "failed." );
318             failed++;
319         }
320         System.out.print( "Taxonomy extraction (general): " );
321         if ( Test.testTaxonomyExtraction() ) {
322             System.out.println( "OK." );
323             succeeded++;
324         }
325         else {
326             System.out.println( "failed." );
327             failed++;
328         }
329         System.out.print( "Uri for Aptx web sequence accession: " );
330         if ( Test.testCreateUriForSeqWeb() ) {
331             System.out.println( "OK." );
332             succeeded++;
333         }
334         else {
335             System.out.println( "failed." );
336             failed++;
337         }
338         System.out.print( "Basic node construction and parsing of NHX (node level): " );
339         if ( Test.testNHXNodeParsing() ) {
340             System.out.println( "OK." );
341             succeeded++;
342         }
343         else {
344             System.out.println( "failed." );
345             failed++;
346         }
347         System.out.print( "Node construction and parsing of NHX (node level): " );
348         if ( Test.testNHXNodeParsing2() ) {
349             System.out.println( "OK." );
350             succeeded++;
351         }
352         else {
353             System.out.println( "failed." );
354             failed++;
355         }
356         System.out.print( "NHX parsing iterating: " );
357         if ( Test.testNHParsingIter() ) {
358             System.out.println( "OK." );
359             succeeded++;
360         }
361         else {
362             System.out.println( "failed." );
363             failed++;
364         }
365         System.out.print( "NH parsing: " );
366         if ( Test.testNHParsing() ) {
367             System.out.println( "OK." );
368             succeeded++;
369         }
370         else {
371             System.out.println( "failed." );
372             failed++;
373         }
374         System.out.print( "NH parsing - special chars: " );
375         if ( Test.testNHParsingSpecialChars() ) {
376             System.out.println( "OK." );
377             succeeded++;
378         }
379         else {
380             System.out.println( "failed." );
381             failed++;
382         }
383         System.out.print( "Conversion to NHX (node level): " );
384         if ( Test.testNHXconversion() ) {
385             System.out.println( "OK." );
386             succeeded++;
387         }
388         else {
389             System.out.println( "failed." );
390             failed++;
391         }
392         System.out.print( "NHX parsing: " );
393         if ( Test.testNHXParsing() ) {
394             System.out.println( "OK." );
395             succeeded++;
396         }
397         else {
398             System.out.println( "failed." );
399             failed++;
400         }
401         System.out.print( "NHX parsing with quotes: " );
402         if ( Test.testNHXParsingQuotes() ) {
403             System.out.println( "OK." );
404             succeeded++;
405         }
406         else {
407             System.out.println( "failed." );
408             failed++;
409         }
410         System.out.print( "NHX parsing (MrBayes): " );
411         if ( Test.testNHXParsingMB() ) {
412             System.out.println( "OK." );
413             succeeded++;
414         }
415         else {
416             System.out.println( "failed." );
417             failed++;
418         }
419         System.out.print( "Nexus characters parsing: " );
420         if ( Test.testNexusCharactersParsing() ) {
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 iterating: " );
429         if ( Test.testNexusTreeParsingIterating() ) {
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: " );
438         if ( Test.testNexusTreeParsing() ) {
439             System.out.println( "OK." );
440             succeeded++;
441         }
442         else {
443             System.out.println( "failed." );
444             failed++;
445         }
446         System.out.print( "Nexus tree parsing (translating): " );
447         if ( Test.testNexusTreeParsingTranslating() ) {
448             System.out.println( "OK." );
449             succeeded++;
450         }
451         else {
452             System.out.println( "failed." );
453             failed++;
454         }
455         System.out.print( "Nexus matrix parsing: " );
456         if ( Test.testNexusMatrixParsing() ) {
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: " );
465         if ( Test.testBasicPhyloXMLparsing() ) {
466             System.out.println( "OK." );
467             succeeded++;
468         }
469         else {
470             System.out.println( "failed." );
471             failed++;
472         }
473         System.out.print( "Basic phyloXML parsing (validating against schema): " );
474         if ( testBasicPhyloXMLparsingValidating() ) {
475             System.out.println( "OK." );
476             succeeded++;
477         }
478         else {
479             System.out.println( "failed." );
480             failed++;
481         }
482         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
483         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
484             System.out.println( "OK." );
485             succeeded++;
486         }
487         else {
488             System.out.println( "failed." );
489             failed++;
490         }
491         System.out.print( "phyloXML Distribution Element: " );
492         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
493             System.out.println( "OK." );
494             succeeded++;
495         }
496         else {
497             System.out.println( "failed." );
498             failed++;
499         }
500         System.out.print( "Tol XML parsing: " );
501         if ( Test.testBasicTolXMLparsing() ) {
502             System.out.println( "OK." );
503             succeeded++;
504         }
505         else {
506             System.out.println( "failed." );
507             failed++;
508         }
509         System.out.print( "UTF-8 parsing from file: " );
510         if ( Test.testUTF8ParsingFromFile() ) {
511             System.out.println( "OK." );
512             succeeded++;
513         }
514         else {
515             System.out.println( "failed." );
516             failed++;
517         }
518         System.out.print( "Copying of node data: " );
519         if ( Test.testCopyOfNodeData() ) {
520             System.out.println( "OK." );
521             succeeded++;
522         }
523         else {
524             System.out.println( "failed." );
525             failed++;
526         }
527         System.out.print( "Tree copy: " );
528         if ( Test.testTreeCopy() ) {
529             System.out.println( "OK." );
530             succeeded++;
531         }
532         else {
533             System.out.println( "failed." );
534             failed++;
535         }
536         System.out.print( "Basic tree methods: " );
537         if ( Test.testBasicTreeMethods() ) {
538             System.out.println( "OK." );
539             succeeded++;
540         }
541         else {
542             System.out.println( "failed." );
543             failed++;
544         }
545         System.out.print( "Tree methods: " );
546         if ( Test.testTreeMethods() ) {
547             System.out.println( "OK." );
548             succeeded++;
549         }
550         else {
551             System.out.println( "failed." );
552             failed++;
553         }
554         System.out.print( "Postorder Iterator: " );
555         if ( Test.testPostOrderIterator() ) {
556             System.out.println( "OK." );
557             succeeded++;
558         }
559         else {
560             System.out.println( "failed." );
561             failed++;
562         }
563         System.out.print( "Preorder Iterator: " );
564         if ( Test.testPreOrderIterator() ) {
565             System.out.println( "OK." );
566             succeeded++;
567         }
568         else {
569             System.out.println( "failed." );
570             failed++;
571         }
572         System.out.print( "Levelorder Iterator: " );
573         if ( Test.testLevelOrderIterator() ) {
574             System.out.println( "OK." );
575             succeeded++;
576         }
577         else {
578             System.out.println( "failed." );
579             failed++;
580         }
581         System.out.print( "Re-id methods: " );
582         if ( Test.testReIdMethods() ) {
583             System.out.println( "OK." );
584             succeeded++;
585         }
586         else {
587             System.out.println( "failed." );
588             failed++;
589         }
590         System.out.print( "Methods on last external nodes: " );
591         if ( Test.testLastExternalNodeMethods() ) {
592             System.out.println( "OK." );
593             succeeded++;
594         }
595         else {
596             System.out.println( "failed." );
597             failed++;
598         }
599         System.out.print( "Methods on external nodes: " );
600         if ( Test.testExternalNodeRelatedMethods() ) {
601             System.out.println( "OK." );
602             succeeded++;
603         }
604         else {
605             System.out.println( "failed." );
606             failed++;
607         }
608         System.out.print( "Deletion of external nodes: " );
609         if ( Test.testDeletionOfExternalNodes() ) {
610             System.out.println( "OK." );
611             succeeded++;
612         }
613         else {
614             System.out.println( "failed." );
615             failed++;
616         }
617         System.out.print( "Subtree deletion: " );
618         if ( Test.testSubtreeDeletion() ) {
619             System.out.println( "OK." );
620             succeeded++;
621         }
622         else {
623             System.out.println( "failed." );
624             failed++;
625         }
626         System.out.print( "Phylogeny branch: " );
627         if ( Test.testPhylogenyBranch() ) {
628             System.out.println( "OK." );
629             succeeded++;
630         }
631         else {
632             System.out.println( "failed." );
633             failed++;
634         }
635         System.out.print( "Rerooting: " );
636         if ( Test.testRerooting() ) {
637             System.out.println( "OK." );
638             succeeded++;
639         }
640         else {
641             System.out.println( "failed." );
642             failed++;
643         }
644         System.out.print( "Mipoint rooting: " );
645         if ( Test.testMidpointrooting() ) {
646             System.out.println( "OK." );
647             succeeded++;
648         }
649         else {
650             System.out.println( "failed." );
651             failed++;
652         }
653         System.out.print( "Node removal: " );
654         if ( Test.testNodeRemoval() ) {
655             System.out.println( "OK." );
656             succeeded++;
657         }
658         else {
659             System.out.println( "failed." );
660             failed++;
661         }
662         System.out.print( "Support count: " );
663         if ( Test.testSupportCount() ) {
664             System.out.println( "OK." );
665             succeeded++;
666         }
667         else {
668             System.out.println( "failed." );
669             failed++;
670         }
671         System.out.print( "Support transfer: " );
672         if ( Test.testSupportTransfer() ) {
673             System.out.println( "OK." );
674             succeeded++;
675         }
676         else {
677             System.out.println( "failed." );
678             failed++;
679         }
680         System.out.print( "Finding of LCA: " );
681         if ( Test.testGetLCA() ) {
682             System.out.println( "OK." );
683             succeeded++;
684         }
685         else {
686             System.out.println( "failed." );
687             failed++;
688         }
689         System.out.print( "Finding of LCA 2: " );
690         if ( Test.testGetLCA2() ) {
691             System.out.println( "OK." );
692             succeeded++;
693         }
694         else {
695             System.out.println( "failed." );
696             failed++;
697         }
698         System.out.print( "Calculation of distance between nodes: " );
699         if ( Test.testGetDistance() ) {
700             System.out.println( "OK." );
701             succeeded++;
702         }
703         else {
704             System.out.println( "failed." );
705             failed++;
706         }
707         System.out.print( "Descriptive statistics: " );
708         if ( Test.testDescriptiveStatistics() ) {
709             System.out.println( "OK." );
710             succeeded++;
711         }
712         else {
713             System.out.println( "failed." );
714             failed++;
715         }
716         System.out.print( "Data objects and methods: " );
717         if ( Test.testDataObjects() ) {
718             System.out.println( "OK." );
719             succeeded++;
720         }
721         else {
722             System.out.println( "failed." );
723             failed++;
724         }
725         System.out.print( "Properties map: " );
726         if ( Test.testPropertiesMap() ) {
727             System.out.println( "OK." );
728             succeeded++;
729         }
730         else {
731             System.out.println( "failed." );
732             failed++;
733         }
734         System.out.print( "SDIse: " );
735         if ( Test.testSDIse() ) {
736             System.out.println( "OK." );
737             succeeded++;
738         }
739         else {
740             System.out.println( "failed." );
741             failed++;
742         }
743         System.out.print( "SDIunrooted: " );
744         if ( Test.testSDIunrooted() ) {
745             System.out.println( "OK." );
746             succeeded++;
747         }
748         else {
749             System.out.println( "failed." );
750             failed++;
751         }
752         System.out.print( "GSDI: " );
753         if ( TestGSDI.test() ) {
754             System.out.println( "OK." );
755             succeeded++;
756         }
757         else {
758             System.out.println( "failed." );
759             failed++;
760         }
761         System.out.print( "RIO: " );
762         if ( TestRIO.test() ) {
763             System.out.println( "OK." );
764             succeeded++;
765         }
766         else {
767             System.out.println( "failed." );
768             failed++;
769         }
770         System.out.print( "Phylogeny reconstruction:" );
771         System.out.println();
772         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
773             System.out.println( "OK." );
774             succeeded++;
775         }
776         else {
777             System.out.println( "failed." );
778             failed++;
779         }
780         System.out.print( "Analysis of domain architectures: " );
781         System.out.println();
782         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
783             System.out.println( "OK." );
784             succeeded++;
785         }
786         else {
787             System.out.println( "failed." );
788             failed++;
789         }
790         System.out.print( "GO: " );
791         System.out.println();
792         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
793             System.out.println( "OK." );
794             succeeded++;
795         }
796         else {
797             System.out.println( "failed." );
798             failed++;
799         }
800         System.out.print( "Modeling tools: " );
801         if ( TestPccx.test() ) {
802             System.out.println( "OK." );
803             succeeded++;
804         }
805         else {
806             System.out.println( "failed." );
807             failed++;
808         }
809         System.out.print( "Split Matrix strict: " );
810         if ( Test.testSplitStrict() ) {
811             System.out.println( "OK." );
812             succeeded++;
813         }
814         else {
815             System.out.println( "failed." );
816             failed++;
817         }
818         System.out.print( "Split Matrix: " );
819         if ( Test.testSplit() ) {
820             System.out.println( "OK." );
821             succeeded++;
822         }
823         else {
824             System.out.println( "failed." );
825             failed++;
826         }
827         System.out.print( "Confidence Assessor: " );
828         if ( Test.testConfidenceAssessor() ) {
829             System.out.println( "OK." );
830             succeeded++;
831         }
832         else {
833             System.out.println( "failed." );
834             failed++;
835         }
836         System.out.print( "Basic table: " );
837         if ( Test.testBasicTable() ) {
838             System.out.println( "OK." );
839             succeeded++;
840         }
841         else {
842             System.out.println( "failed." );
843             failed++;
844         }
845         System.out.print( "General table: " );
846         if ( Test.testGeneralTable() ) {
847             System.out.println( "OK." );
848             succeeded++;
849         }
850         else {
851             System.out.println( "failed." );
852             failed++;
853         }
854         System.out.print( "Amino acid sequence: " );
855         if ( Test.testAminoAcidSequence() ) {
856             System.out.println( "OK." );
857             succeeded++;
858         }
859         else {
860             System.out.println( "failed." );
861             failed++;
862         }
863         System.out.print( "General MSA parser: " );
864         if ( Test.testGeneralMsaParser() ) {
865             System.out.println( "OK." );
866             succeeded++;
867         }
868         else {
869             System.out.println( "failed." );
870             failed++;
871         }
872         System.out.print( "Fasta parser for msa: " );
873         if ( Test.testFastaParser() ) {
874             System.out.println( "OK." );
875             succeeded++;
876         }
877         else {
878             System.out.println( "failed." );
879             failed++;
880         }
881         System.out.print( "Creation of balanced phylogeny: " );
882         if ( Test.testCreateBalancedPhylogeny() ) {
883             System.out.println( "OK." );
884             succeeded++;
885         }
886         else {
887             System.out.println( "failed." );
888             failed++;
889         }
890         System.out.print( "Genbank accessor parsing: " );
891         if ( Test.testGenbankAccessorParsing() ) {
892             System.out.println( "OK." );
893             succeeded++;
894         }
895         else {
896             System.out.println( "failed." );
897             failed++;
898         }
899         String path = "";
900         final String os = ForesterUtil.OS_NAME.toLowerCase();
901         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
902             path = "/usr/local/bin/mafft";
903         }
904         else if ( os.indexOf( "win" ) >= 0 ) {
905             path = "C:\\Program Files\\mafft-win\\mafft.bat";
906         }
907         else {
908             path = "mafft";
909             if ( !MsaInferrer.isInstalled( path ) ) {
910                 path = "/usr/bin/mafft";
911             }
912             if ( !MsaInferrer.isInstalled( path ) ) {
913                 path = "/usr/local/bin/mafft";
914             }
915         }
916         if ( MsaInferrer.isInstalled( path ) ) {
917             System.out.print( "MAFFT (external program): " );
918             if ( Test.testMafft( path ) ) {
919                 System.out.println( "OK." );
920                 succeeded++;
921             }
922             else {
923                 System.out.println( "failed [will not count towards failed tests]" );
924             }
925         }
926         System.out.print( "Next nodes with collapsed: " );
927         if ( Test.testNextNodeWithCollapsing() ) {
928             System.out.println( "OK." );
929             succeeded++;
930         }
931         else {
932             System.out.println( "failed." );
933             failed++;
934         }
935         System.out.print( "Simple MSA quality: " );
936         if ( Test.testMsaQualityMethod() ) {
937             System.out.println( "OK." );
938             succeeded++;
939         }
940         else {
941             System.out.println( "failed." );
942             failed++;
943         }
944         System.out.print( "Deleteable MSA: " );
945         if ( Test.testDeleteableMsa() ) {
946             System.out.println( "OK." );
947             succeeded++;
948         }
949         else {
950             System.out.println( "failed." );
951             failed++;
952         }
953         System.out.print( "MSA entropy: " );
954         if ( Test.testMsaEntropy() ) {
955             System.out.println( "OK." );
956             succeeded++;
957         }
958         else {
959             System.out.println( "failed." );
960             failed++;
961         }
962         if ( PERFORM_DB_TESTS ) {
963             System.out.print( "Uniprot Entry Retrieval: " );
964             if ( Test.testUniprotEntryRetrieval() ) {
965                 System.out.println( "OK." );
966                 succeeded++;
967             }
968             else {
969                 System.out.println( "failed." );
970                 failed++;
971             }
972             System.out.print( "Ebi Entry Retrieval: " );
973             if ( Test.testEbiEntryRetrieval() ) {
974                 System.out.println( "OK." );
975                 succeeded++;
976             }
977             else {
978                 System.out.println( "failed." );
979                 failed++;
980             }
981             System.out.print( "Sequence DB tools 2: " );
982             if ( testSequenceDbWsTools2() ) {
983                 System.out.println( "OK." );
984                 succeeded++;
985             }
986             else {
987                 System.out.println( "failed." );
988                 failed++;
989                 System.exit( -1 );
990             }
991             System.out.print( "Uniprot Taxonomy Search: " );
992             if ( Test.testUniprotTaxonomySearch() ) {
993                 System.out.println( "OK." );
994                 succeeded++;
995             }
996             else {
997                 System.out.println( "failed." );
998                 failed++;
999             }
1000         }
1001         if ( PERFORM_WEB_TREE_ACCESS ) {
1002             System.out.print( "TreeBase acccess: " );
1003             if ( Test.testTreeBaseReading() ) {
1004                 System.out.println( "OK." );
1005                 succeeded++;
1006             }
1007             else {
1008                 System.out.println( "failed." );
1009                 failed++;
1010             }
1011             System.out.print( "ToL access: " );
1012             if ( Test.testToLReading() ) {
1013                 System.out.println( "OK." );
1014                 succeeded++;
1015             }
1016             else {
1017                 System.out.println( "failed." );
1018                 failed++;
1019             }
1020             System.out.print( "NHX parsing from URL: " );
1021             if ( Test.testNHXparsingFromURL() ) {
1022                 System.out.println( "OK." );
1023                 succeeded++;
1024             }
1025             else {
1026                 System.out.println( "failed." );
1027                 failed++;
1028             }
1029             System.out.print( "NHX parsing from URL 2: " );
1030             if ( Test.testNHXparsingFromURL2() ) {
1031                 System.out.println( "OK." );
1032                 succeeded++;
1033             }
1034             else {
1035                 System.out.println( "failed." );
1036                 failed++;
1037             }
1038             System.out.print( "phyloXML parsing from URL: " );
1039             if ( Test.testPhyloXMLparsingFromURL() ) {
1040                 System.out.println( "OK." );
1041                 succeeded++;
1042             }
1043             else {
1044                 System.out.println( "failed." );
1045                 failed++;
1046             }
1047             System.out.print( "TreeFam access: " );
1048             if ( Test.testTreeFamReading() ) {
1049                 System.out.println( "OK." );
1050                 succeeded++;
1051             }
1052             else {
1053                 System.out.println( "failed." );
1054                 failed++;
1055             }
1056             System.out.print( "Pfam tree access: " );
1057             if ( Test.testPfamTreeReading() ) {
1058                 System.out.println( "OK." );
1059                 succeeded++;
1060             }
1061             else {
1062                 System.out.println( "failed." );
1063                 failed++;
1064             }
1065         }
1066         System.out.println();
1067         final Runtime rt = java.lang.Runtime.getRuntime();
1068         final long free_memory = rt.freeMemory() / 1000000;
1069         final long total_memory = rt.totalMemory() / 1000000;
1070         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1071                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1072         System.out.println();
1073         System.out.println( "Successful tests: " + succeeded );
1074         System.out.println( "Failed     tests: " + failed );
1075         System.out.println();
1076         if ( failed < 1 ) {
1077             System.out.println( "OK." );
1078         }
1079         else {
1080             System.out.println( "Not OK." );
1081         }
1082     }
1083
1084     private static boolean testEngulfingOverlapRemoval() {
1085         try {
1086             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1087             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1088             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1089             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1090             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1091             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1092             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1093             final List<Boolean> covered = new ArrayList<Boolean>();
1094             covered.add( true ); // 0
1095             covered.add( false ); // 1
1096             covered.add( true ); // 2
1097             covered.add( false ); // 3
1098             covered.add( true ); // 4
1099             covered.add( true ); // 5
1100             covered.add( false ); // 6
1101             covered.add( true ); // 7
1102             covered.add( true ); // 8
1103             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1104                 return false;
1105             }
1106             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1107                 return false;
1108             }
1109             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1110                 return false;
1111             }
1112             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1113                 return false;
1114             }
1115             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1116                 return false;
1117             }
1118             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1119                 return false;
1120             }
1121             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1122                 return false;
1123             }
1124             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1125             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1126             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1127             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1128             abc.addProteinDomain( a );
1129             abc.addProteinDomain( b );
1130             abc.addProteinDomain( c );
1131             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1132             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1133             if ( abc.getNumberOfProteinDomains() != 3 ) {
1134                 return false;
1135             }
1136             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1137                 return false;
1138             }
1139             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1140                 return false;
1141             }
1142             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1143                 return false;
1144             }
1145             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1146                 return false;
1147             }
1148             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1149             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1150             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1151             final Protein def = new BasicProtein( "def", "nemve", 0 );
1152             def.addProteinDomain( d );
1153             def.addProteinDomain( e );
1154             def.addProteinDomain( f );
1155             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1156             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1157             if ( def.getNumberOfProteinDomains() != 3 ) {
1158                 return false;
1159             }
1160             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1161                 return false;
1162             }
1163             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1164                 return false;
1165             }
1166             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1167                 return false;
1168             }
1169             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1170                 return false;
1171             }
1172             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1173                 return false;
1174             }
1175         }
1176         catch ( final Exception e ) {
1177             e.printStackTrace( System.out );
1178             return false;
1179         }
1180         return true;
1181     }
1182
1183     private static final boolean testNHXparsingFromURL2() {
1184         try {
1185             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1186             final Phylogeny phys[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1187                                                                       false,
1188                                                                       false,
1189                                                                       false,
1190                                                                       TAXONOMY_EXTRACTION.NO,
1191                                                                       false );
1192             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1193                 return false;
1194             }
1195             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1196                 System.out.println( phys[ 0 ].toNewHampshire() );
1197                 return false;
1198             }
1199             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1200                 System.out.println( phys[ 1 ].toNewHampshire() );
1201                 return false;
1202             }
1203             final Phylogeny phys2[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1204                                                                        false,
1205                                                                        false,
1206                                                                        false,
1207                                                                        TAXONOMY_EXTRACTION.NO,
1208                                                                        false );
1209             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1210                 return false;
1211             }
1212             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1213                 System.out.println( phys2[ 0 ].toNewHampshire() );
1214                 return false;
1215             }
1216             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1217                 System.out.println( phys2[ 1 ].toNewHampshire() );
1218                 return false;
1219             }
1220             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1221                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1222             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1223                 return false;
1224             }
1225             if ( !phys3[ 0 ]
1226                     .toNewHampshire()
1227                     .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))))));" ) ) {
1228                 System.out.println( phys3[ 0 ].toNewHampshire() );
1229                 return false;
1230             }
1231             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1232                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1233             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1234                 return false;
1235             }
1236             if ( !phys4[ 0 ]
1237                     .toNewHampshire()
1238                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1239                 System.out.println( phys4[ 0 ].toNewHampshire() );
1240                 return false;
1241             }
1242         }
1243         catch ( final Exception e ) {
1244             e.printStackTrace();
1245             return false;
1246         }
1247         return true;
1248     }
1249
1250     private static final boolean testNHXparsingFromURL() {
1251         try {
1252             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1253             final URL u = new URL( s );
1254             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1255             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1256             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1257                 return false;
1258             }
1259             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1260                 System.out.println( phys[ 0 ].toNewHampshire() );
1261                 return false;
1262             }
1263             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1264                 System.out.println( phys[ 1 ].toNewHampshire() );
1265                 return false;
1266             }
1267             final URL u2 = new URL( s );
1268             final Phylogeny[] phys2 = factory.create( u2.openStream(), new NHXParser() );
1269             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1270                 return false;
1271             }
1272             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1273                 System.out.println( phys2[ 0 ].toNewHampshire() );
1274                 return false;
1275             }
1276             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1277             final NHXParser p = new NHXParser();
1278             final URL u3 = new URL( s );
1279             p.setSource( u3 );
1280             if ( !p.hasNext() ) {
1281                 return false;
1282             }
1283             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1284                 return false;
1285             }
1286             if ( !p.hasNext() ) {
1287                 return false;
1288             }
1289             p.reset();
1290             if ( !p.hasNext() ) {
1291                 return false;
1292             }
1293             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1294                 return false;
1295             }
1296             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1297                 return false;
1298             }
1299             p.reset();
1300             if ( !p.hasNext() ) {
1301                 return false;
1302             }
1303             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1304                 return false;
1305             }
1306             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1307                 return false;
1308             }
1309         }
1310         catch ( final Exception e ) {
1311             System.out.println( e.toString() );
1312             e.printStackTrace();
1313             return false;
1314         }
1315         return true;
1316     }
1317
1318     private static boolean testOverlapRemoval() {
1319         try {
1320             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1321             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1322             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1323             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1324             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1325             final List<Boolean> covered = new ArrayList<Boolean>();
1326             covered.add( true ); // 0
1327             covered.add( false ); // 1
1328             covered.add( true ); // 2
1329             covered.add( false ); // 3
1330             covered.add( true ); // 4
1331             covered.add( true ); // 5
1332             covered.add( false ); // 6
1333             covered.add( true ); // 7
1334             covered.add( true ); // 8
1335             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1336                 return false;
1337             }
1338             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1339                 return false;
1340             }
1341             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1342                 return false;
1343             }
1344             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1345                 return false;
1346             }
1347             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1348                 return false;
1349             }
1350             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1351             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1352             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1353             ab.addProteinDomain( a );
1354             ab.addProteinDomain( b );
1355             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1356             if ( ab.getNumberOfProteinDomains() != 2 ) {
1357                 return false;
1358             }
1359             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1360                 return false;
1361             }
1362             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1363                 return false;
1364             }
1365             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1366             if ( ab.getNumberOfProteinDomains() != 2 ) {
1367                 return false;
1368             }
1369             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1370                 return false;
1371             }
1372             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1373             final Domain d = new BasicDomain( "d",
1374                                               ( short ) 10000,
1375                                               ( short ) 10500,
1376                                               ( short ) 1,
1377                                               ( short ) 1,
1378                                               0.0000001,
1379                                               1 );
1380             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1381             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1382             cde.addProteinDomain( c );
1383             cde.addProteinDomain( d );
1384             cde.addProteinDomain( e );
1385             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1386             if ( cde.getNumberOfProteinDomains() != 3 ) {
1387                 return false;
1388             }
1389             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1390                 return false;
1391             }
1392             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1393             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1394             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1395             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1396             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1397             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1398             fghi.addProteinDomain( f );
1399             fghi.addProteinDomain( g );
1400             fghi.addProteinDomain( h );
1401             fghi.addProteinDomain( i );
1402             fghi.addProteinDomain( i );
1403             fghi.addProteinDomain( i );
1404             fghi.addProteinDomain( i2 );
1405             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1406             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1407                 return false;
1408             }
1409             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1410                 return false;
1411             }
1412             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1413                 return false;
1414             }
1415             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1416             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1417                 return false;
1418             }
1419             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1420                 return false;
1421             }
1422             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1423             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1424             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1425             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1426             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1427             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1428             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1429             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1430             jklm.addProteinDomain( j );
1431             jklm.addProteinDomain( k );
1432             jklm.addProteinDomain( l );
1433             jklm.addProteinDomain( m );
1434             jklm.addProteinDomain( m0 );
1435             jklm.addProteinDomain( m1 );
1436             jklm.addProteinDomain( m2 );
1437             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1438             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1439                 return false;
1440             }
1441             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1442                 return false;
1443             }
1444             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1445                 return false;
1446             }
1447             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1448             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1449                 return false;
1450             }
1451             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1452                 return false;
1453             }
1454             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1455             final Protein od = new BasicProtein( "od", "varanus", 0 );
1456             od.addProteinDomain( only );
1457             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1458             if ( od.getNumberOfProteinDomains() != 1 ) {
1459                 return false;
1460             }
1461             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1462                 return false;
1463             }
1464         }
1465         catch ( final Exception e ) {
1466             e.printStackTrace( System.out );
1467             return false;
1468         }
1469         return true;
1470     }
1471
1472     private static final boolean testPfamTreeReading() {
1473         try {
1474             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1475             final NHXParser parser = new NHXParser();
1476             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1477             parser.setReplaceUnderscores( false );
1478             parser.setGuessRootedness( true );
1479             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser);
1480             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1481                 return false;
1482             }
1483             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1484                 return false;
1485             }
1486         }
1487         catch ( final Exception e ) {
1488             e.printStackTrace();
1489             return false;
1490         }
1491         return true;
1492     }
1493
1494     private static final boolean testPhyloXMLparsingFromURL() {
1495         try {
1496             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1497             final URL u = new URL( s );
1498             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1499             
1500             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1501                 return false;
1502             }
1503             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u, PhyloXmlParser.createPhyloXmlParser() );
1504             
1505             if ( ( phys2 == null ) || ( phys2.length != 2 ) ) {
1506                 return false;
1507             }
1508         }
1509         catch ( final Exception e ) {
1510             e.printStackTrace();
1511             return false;
1512         }
1513         return true;
1514     }
1515
1516     private static final boolean testToLReading() {
1517         try {
1518             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1519             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, new TolParser() );
1520             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1521                 return false;
1522             }
1523             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1524                 return false;
1525             }
1526             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1527                 return false;
1528             }
1529             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1530                 return false;
1531             }
1532             //
1533             final URL u2 = new URL( WebserviceUtil.TOL_URL_BASE + "17706" );
1534             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, new TolParser() );
1535             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
1536                 return false;
1537             }
1538             if ( !phys2[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "17706" ) ) {
1539                 return false;
1540             }
1541             if ( phys2[ 0 ].getNumberOfExternalNodes() < 5 ) {
1542                 return false;
1543             }
1544         }
1545         catch ( final Exception e ) {
1546             e.printStackTrace();
1547             return false;
1548         }
1549         return true;
1550     }
1551
1552     private static final boolean testTreeBaseReading() {
1553         try {
1554             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "72557?format=nexus" );  
1555             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1556             parser.setReplaceUnderscores( true );
1557             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1558             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1559                 return false;
1560             }
1561             final URL u_1 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2406?format=nexus" );  
1562             final NexusPhylogeniesParser parser_1 = new NexusPhylogeniesParser();
1563             final Phylogeny[] phys_1 = ForesterUtil.readPhylogeniesFromUrl( u_1, parser_1 );
1564             if ( ( phys_1 == null ) || ( phys_1.length != 1 ) ) {
1565                 return false;
1566             }
1567             final URL u_2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "422?format=nexus" );  
1568             final NexusPhylogeniesParser parser_2 = new NexusPhylogeniesParser();
1569             final Phylogeny[] phys_2 = ForesterUtil.readPhylogeniesFromUrl( u_2, parser_2 );
1570             if ( ( phys_2 == null ) || ( phys_2.length != 1 ) ) {
1571                 return false;
1572             }
1573             final URL u_3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "2654?format=nexus" );  
1574             final NexusPhylogeniesParser parser_3 = new NexusPhylogeniesParser();
1575             final Phylogeny[] phys_3 = ForesterUtil.readPhylogeniesFromUrl( u_3, parser_3 );
1576              if ( ( phys_3 == null ) || ( phys_3.length != 1 ) ) {
1577                 return false;
1578             }
1579             final URL u_4 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );  
1580             final NexusPhylogeniesParser parser_4 = new NexusPhylogeniesParser();
1581             final Phylogeny[] phys_4 = ForesterUtil.readPhylogeniesFromUrl( u_4, parser_4 );
1582              if ( ( phys_4 == null ) || ( phys_4.length != 1 ) ) {
1583                 return false;
1584             }
1585             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1586             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1587             parser2.setReplaceUnderscores( true );
1588             final Phylogeny[] phys2 = ForesterUtil.readPhylogeniesFromUrl( u2, parser2 );
1589             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1590                 return false;
1591             }
1592             final URL u3 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14909?format=nexus" );
1593             final NexusPhylogeniesParser parser3 = new NexusPhylogeniesParser();
1594             final Phylogeny[] phys3 = ForesterUtil.readPhylogeniesFromUrl( u3, parser3 );
1595             if ( ( phys3 == null ) || ( phys3.length != 2 ) ) {
1596                 return false;
1597             }
1598             final Phylogeny[] phys4 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "14525?format=nexus" ),
1599                     new NexusPhylogeniesParser() );
1600             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1601                 return false;
1602             }
1603             final Phylogeny[] phys5 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15632?format=nexus" ) ,
1604                     new NexusPhylogeniesParser() );
1605             if ( ( phys5 == null ) || ( phys5.length != 1 ) ) {
1606                 return false;
1607             }
1608             final Phylogeny[] phys6 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "10190?format=nexus" ) ,
1609                     new NexusPhylogeniesParser() );
1610             if ( ( phys6 == null ) || ( phys6.length != 1 ) ) {
1611                 return false;
1612             }
1613             final Phylogeny[] phys7 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "13246?format=nexus" ) ,
1614                     new NexusPhylogeniesParser() );
1615             if ( ( phys7 == null ) || ( phys7.length != 2 ) ) {
1616                 return false;
1617             }
1618             final Phylogeny[] phys8 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "11662?format=nexus" ) ,
1619                     new NexusPhylogeniesParser() );
1620             if ( ( phys8 == null ) || ( phys8.length != 2 ) ) {
1621                 return false;
1622             }
1623             final Phylogeny[] phys9 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "562?format=nexus" ) ,
1624                     new NexusPhylogeniesParser() );
1625             if ( ( phys9 == null ) || ( phys9.length != 4 ) ) {
1626                 return false;
1627             }
1628             final Phylogeny[] phys16424 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "16424?format=nexus" ) ,
1629                     new NexusPhylogeniesParser() );
1630             if ( ( phys16424 == null ) || ( phys16424.length != 1 ) ) {
1631                 return false;
1632             }
1633             final Phylogeny[] phys17878 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "17878?format=nexus" ) ,
1634                     new NexusPhylogeniesParser() );
1635             if ( ( phys17878 == null ) || ( phys17878.length != 17 ) ) {
1636                 return false;
1637             }
1638             final Phylogeny[] phys18804 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "18804?format=nexus" ) ,
1639                     new NexusPhylogeniesParser() );
1640             if ( ( phys18804 == null ) || ( phys18804.length != 2 ) ) {
1641                 return false;
1642             }
1643             final Phylogeny[] phys346 = ForesterUtil.readPhylogeniesFromUrl( new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "346?format=nexus" ) ,
1644                     new NexusPhylogeniesParser() );
1645             if ( ( phys346 == null ) || ( phys346.length != 1 ) ) {
1646                 return false;
1647             }
1648         }
1649         catch ( final Exception e ) {
1650             e.printStackTrace();
1651             return false;
1652         }
1653         return true;
1654     }
1655
1656     private static final boolean testTreeFamReading() {
1657         try {
1658             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1659             final NHXParser parser = new NHXParser();
1660             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1661             parser.setReplaceUnderscores( false );
1662             parser.setGuessRootedness( true );
1663             final Phylogeny[] phys = ForesterUtil.readPhylogeniesFromUrl( u, parser );
1664             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1665                 return false;
1666             }
1667             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1668                 return false;
1669             }
1670         }
1671         catch ( final Exception e ) {
1672             e.printStackTrace();
1673             return false;
1674         }
1675         return true;
1676     }
1677
1678     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1679         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1680         return p;
1681     }
1682
1683     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1684         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1685     }
1686
1687     private static boolean testAminoAcidSequence() {
1688         try {
1689             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1690             if ( aa1.getLength() != 13 ) {
1691                 return false;
1692             }
1693             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1694                 return false;
1695             }
1696             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1697                 return false;
1698             }
1699             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1700                 return false;
1701             }
1702             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1703             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1704                 return false;
1705             }
1706             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1707             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1708                 return false;
1709             }
1710             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1711             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1712                 return false;
1713             }
1714         }
1715         catch ( final Exception e ) {
1716             e.printStackTrace();
1717             return false;
1718         }
1719         return true;
1720     }
1721
1722     private static boolean testBasicDomain() {
1723         try {
1724             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1725             if ( !pd.getDomainId().equals( "id" ) ) {
1726                 return false;
1727             }
1728             if ( pd.getNumber() != 1 ) {
1729                 return false;
1730             }
1731             if ( pd.getTotalCount() != 4 ) {
1732                 return false;
1733             }
1734             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1735                 return false;
1736             }
1737             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1738             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1739             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1740             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1741             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1742             if ( !a1.equals( a1 ) ) {
1743                 return false;
1744             }
1745             if ( !a1.equals( a1_copy ) ) {
1746                 return false;
1747             }
1748             if ( !a1.equals( a1_equal ) ) {
1749                 return false;
1750             }
1751             if ( !a1.equals( a2 ) ) {
1752                 return false;
1753             }
1754             if ( a1.equals( a3 ) ) {
1755                 return false;
1756             }
1757             if ( a1.compareTo( a1 ) != 0 ) {
1758                 return false;
1759             }
1760             if ( a1.compareTo( a1_copy ) != 0 ) {
1761                 return false;
1762             }
1763             if ( a1.compareTo( a1_equal ) != 0 ) {
1764                 return false;
1765             }
1766             if ( a1.compareTo( a2 ) != 0 ) {
1767                 return false;
1768             }
1769             if ( a1.compareTo( a3 ) == 0 ) {
1770                 return false;
1771             }
1772         }
1773         catch ( final Exception e ) {
1774             e.printStackTrace( System.out );
1775             return false;
1776         }
1777         return true;
1778     }
1779
1780     private static boolean testBasicNodeMethods() {
1781         try {
1782             if ( PhylogenyNode.getNodeCount() != 0 ) {
1783                 return false;
1784             }
1785             final PhylogenyNode n1 = new PhylogenyNode();
1786             final PhylogenyNode n2 = PhylogenyNode
1787                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1788             final PhylogenyNode n3 = PhylogenyNode
1789                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1790             final PhylogenyNode n4 = PhylogenyNode
1791                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1792             if ( n1.isHasAssignedEvent() ) {
1793                 return false;
1794             }
1795             if ( PhylogenyNode.getNodeCount() != 4 ) {
1796                 return false;
1797             }
1798             if ( n3.getIndicator() != 0 ) {
1799                 return false;
1800             }
1801             if ( n3.getNumberOfExternalNodes() != 1 ) {
1802                 return false;
1803             }
1804             if ( !n3.isExternal() ) {
1805                 return false;
1806             }
1807             if ( !n3.isRoot() ) {
1808                 return false;
1809             }
1810             if ( !n4.getName().equals( "n4" ) ) {
1811                 return false;
1812             }
1813         }
1814         catch ( final Exception e ) {
1815             e.printStackTrace( System.out );
1816             return false;
1817         }
1818         return true;
1819     }
1820     
1821     private static boolean testUTF8ParsingFromFile() {
1822         try {
1823             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1824             final Phylogeny[] phylogenies_xml = ParserBasedPhylogenyFactory.getInstance().create( new File( Test.PATH_TO_TEST_DATA + "chars.xml" ),
1825                                                               xml_parser );
1826             if ( xml_parser.getErrorCount() > 0 ) {
1827                 System.out.println( xml_parser.getErrorMessages().toString() );
1828                 return false;
1829             }
1830             if ( phylogenies_xml.length != 1 ) {
1831                 return false;
1832             }
1833          
1834             final Phylogeny[] phylogenies_xml2 = ParserBasedPhylogenyFactory.getInstance().create( new StringBuffer( phylogenies_xml[0].toPhyloXML( 0 )),
1835                                                                                                    xml_parser );
1836             
1837             final Phylogeny[] phylogenies_nh = ParserBasedPhylogenyFactory.getInstance().create( new File( Test.PATH_TO_TEST_DATA + "chars.nh" ), new NHXParser() );
1838             if ( phylogenies_nh.length != 1 ) {
1839                 return false;
1840             }
1841            
1842             final Phylogeny[] phylogenies_nex = ParserBasedPhylogenyFactory.getInstance().create( new File( Test.PATH_TO_TEST_DATA + "chars.nex" ), new NexusPhylogeniesParser() );
1843             if ( phylogenies_nex.length != 1 ) {
1844                 return false;
1845             }
1846           
1847             final String[] xml_n = phylogenies_xml[0].getAllExternalNodeNames();
1848             final String[] xml_n2 = phylogenies_xml2[0].getAllExternalNodeNames();
1849             final String[] nh_n = phylogenies_nh[0].getAllExternalNodeNames();
1850             final String[] nex_n = phylogenies_nex[0].getAllExternalNodeNames();
1851             final String n0 = "AQ~!@#$%^&*()_+-=\\{}|;:\"<>?,./";
1852             final String n1 = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ";
1853             final String n2 = "漢字ひらがなカタカナ";
1854             final String n3 = "อักษรไทย";
1855             final String n4 = "繁體字";
1856             final String n5 = "한글";
1857             final String n6 = "देवनागरी";
1858             
1859             final String n7 = "chữ Quốc ngữ";
1860             final String n8 = "ру́сский язы́к";
1861             final String n9 = "អក្សរខ្មែរ";
1862             
1863             if ( !xml_n[0].equals( n0 ) ) {
1864                 System.out.println( xml_n[0] );
1865                 System.out.println( n0 );
1866                 return false;
1867             }
1868             if ( !xml_n2[0].equals( n0 ) ) {
1869                 System.out.println( xml_n2[0] );
1870                 System.out.println( n0 );
1871                 return false;
1872             }
1873             if ( !nh_n[0].equals( n0 ) ) {
1874                 System.out.println( nh_n[0] );
1875                 System.out.println( n0 );
1876                 return false;
1877             }
1878             if ( !nex_n[0].equals( n0 ) ) {
1879                 System.out.println( nex_n[0] );
1880                 System.out.println( n0 );
1881                 return false;
1882             }
1883             
1884             if ( !xml_n[1].equals( n1 ) ) {
1885                 System.out.println( xml_n[1] );
1886                 System.out.println( n1 );
1887                 return false;
1888             }
1889             if ( !xml_n2[1].equals( n1 ) ) {
1890                 System.out.println( xml_n2[1] );
1891                 System.out.println( n1 );
1892                 return false;
1893             }
1894             if ( !nh_n[1].equals( n1 ) ) {
1895                 System.out.println( nh_n[1] );
1896                 System.out.println( n1 );
1897                 return false;
1898             }
1899             if ( !nex_n[1].equals( n1 ) ) {
1900                 System.out.println( nex_n[1] );
1901                 System.out.println( n1 );
1902                 return false;
1903             }
1904             
1905             if ( !xml_n[2].equals( n2 ) ) {
1906                 System.out.println( xml_n[2] );
1907                 System.out.println( n2 );
1908                 return false;
1909             }
1910             if ( !xml_n2[2].equals( n2 ) ) {
1911                 System.out.println( xml_n2[2] );
1912                 System.out.println( n2 );
1913                 return false;
1914             }
1915             if ( !nh_n[2].equals( n2 ) ) {
1916                 System.out.println( nh_n[2] );
1917                 System.out.println( n2 );
1918                 return false;
1919             }
1920             if ( !nex_n[2].equals( n2 ) ) {
1921                 System.out.println( nex_n[2] );
1922                 System.out.println( n2 );
1923                 return false;
1924             }
1925             //
1926             if ( !xml_n[3].equals( n3 ) ) {
1927                 System.out.println( xml_n[3] );
1928                 System.out.println( n3 );
1929                 return false;
1930             }
1931             if ( !xml_n2[3].equals( n3 ) ) {
1932                 System.out.println( xml_n2[3] );
1933                 System.out.println( n3 );
1934                 return false;
1935             }
1936             if ( !nh_n[3].equals( n3 ) ) {
1937                 System.out.println( nh_n[3] );
1938                 System.out.println( n3 );
1939                 return false;
1940             }
1941             if ( !nex_n[3].equals( n3 ) ) {
1942                 System.out.println( nex_n[3] );
1943                 System.out.println( n3 );
1944                 return false;
1945             }
1946             //
1947             if ( !xml_n[4].equals( n4 ) ) {
1948                 System.out.println( xml_n[4] );
1949                 System.out.println( n4 );
1950                 return false;
1951             }
1952             if ( !nh_n[4].equals( n4 ) ) {
1953                 System.out.println( nh_n[4] );
1954                 System.out.println( n4 );
1955                 return false;
1956             }
1957             if ( !nex_n[4].equals( n4 ) ) {
1958                 System.out.println( nex_n[4] );
1959                 System.out.println( n4 );
1960                 return false;
1961             }
1962             //
1963             if ( !xml_n[5].equals( n5 ) ) {
1964                 System.out.println( xml_n[5] );
1965                 System.out.println( n5 );
1966                 return false;
1967             }
1968             if ( !nh_n[5].equals( n5 ) ) {
1969                 System.out.println( nh_n[5] );
1970                 System.out.println( n5 );
1971                 return false;
1972             }
1973             if ( !nex_n[5].equals( n5 ) ) {
1974                 System.out.println( nex_n[5] );
1975                 System.out.println( n5 );
1976                 return false;
1977             }
1978             //
1979             if ( !xml_n[6].equals( n6 ) ) {
1980                 System.out.println( xml_n[6] );
1981                 System.out.println( n6 );
1982                 return false;
1983             }
1984             if ( !nh_n[6].equals( n6 ) ) {
1985                 System.out.println( nh_n[6] );
1986                 System.out.println( n6 );
1987                 return false;
1988             }
1989             if ( !nex_n[6].equals( n6 ) ) {
1990                 System.out.println( nex_n[6] );
1991                 System.out.println( n6 );
1992                 return false;
1993             }
1994             //
1995             if ( !xml_n[7].equals( n7 ) ) {
1996                 System.out.println( xml_n[7] );
1997                 System.out.println( n7 );
1998                 return false;
1999             }
2000             if ( !nh_n[7].equals( n7 ) ) {
2001                 System.out.println( nh_n[7] );
2002                 System.out.println( n7 );
2003                 return false;
2004             }
2005             if ( !nex_n[7].equals( n7 ) ) {
2006                 System.out.println( nex_n[7] );
2007                 System.out.println( n7 );
2008                 return false;
2009             }
2010             if ( !xml_n[8].equals( n8 ) ) {
2011                 System.out.println( xml_n[8] );
2012                 System.out.println( n8 );
2013                 return false;
2014             }
2015             if ( !nh_n[8].equals( n8 ) ) {
2016                 System.out.println( nh_n[8] );
2017                 System.out.println( n8 );
2018                 return false;
2019             }
2020             if ( !nex_n[8].equals( n8 ) ) {
2021                 System.out.println( nex_n[8] );
2022                 System.out.println( n8 );
2023                 return false;
2024             }
2025             if ( !xml_n[9].equals( n9 ) ) {
2026                 System.out.println( xml_n[9] );
2027                 System.out.println( n9 );
2028                 return false;
2029             }
2030             if ( !xml_n2[9].equals( n9 ) ) {
2031                 System.out.println( xml_n2[9] );
2032                 System.out.println( n9 );
2033                 return false;
2034             }
2035             if ( !nh_n[9].equals( n9 ) ) {
2036                 System.out.println( nh_n[9] );
2037                 System.out.println( n9 );
2038                 return false;
2039             }
2040             if ( !nex_n[9].equals( n9 ) ) {
2041                 System.out.println( nex_n[9] );
2042                 System.out.println( n9 );
2043                 return false;
2044             }
2045             if (!phylogenies_xml[0].toNewHampshire().equals( 
2046                                                             phylogenies_nh[0].toNewHampshire() ) ) {
2047                 System.out.println( phylogenies_xml[0].toNewHampshire() );
2048                 System.out.println( phylogenies_nh[0].toNewHampshire() );
2049                 return false;
2050             }
2051             if (!phylogenies_xml[0].toNewHampshire().equals( 
2052                                                             phylogenies_nex[0].toNewHampshire() ) ) {
2053                 System.out.println( phylogenies_xml[0].toNewHampshire() );
2054                 System.out.println( phylogenies_nex[0].toNewHampshire() );
2055                 return false;
2056             }
2057         }
2058         catch ( final Exception e ) {
2059             e.printStackTrace( System.out );
2060             return false;
2061         }
2062         return true;
2063     }
2064     
2065     
2066
2067     private static boolean testBasicPhyloXMLparsing() {
2068         try {
2069             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2070             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2071             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ),
2072                                                               xml_parser );
2073             if ( xml_parser.getErrorCount() > 0 ) {
2074                 System.out.println( xml_parser.getErrorMessages().toString() );
2075                 return false;
2076             }
2077             if ( phylogenies_0.length != 4 ) {
2078                 return false;
2079             }
2080             final Phylogeny t1 = phylogenies_0[ 0 ];
2081             final Phylogeny t2 = phylogenies_0[ 1 ];
2082             final Phylogeny t3 = phylogenies_0[ 2 ];
2083             final Phylogeny t4 = phylogenies_0[ 3 ];
2084             if ( t1.getNumberOfExternalNodes() != 1 ) {
2085                 return false;
2086             }
2087             if ( !t1.isRooted() ) {
2088                 return false;
2089             }
2090             if ( t1.isRerootable() ) {
2091                 return false;
2092             }
2093             if ( !t1.getType().equals( "gene_tree" ) ) {
2094                 return false;
2095             }
2096             if ( t2.getNumberOfExternalNodes() != 2 ) {
2097                 return false;
2098             }
2099             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
2100                 return false;
2101             }
2102             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
2103                 return false;
2104             }
2105             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2106                 return false;
2107             }
2108             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2109                 return false;
2110             }
2111             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2112                 return false;
2113             }
2114             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2115                 return false;
2116             }
2117             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2118                     .startsWith( "actgtgggggt" ) ) {
2119                 return false;
2120             }
2121             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2122                     .startsWith( "ctgtgatgcat" ) ) {
2123                 return false;
2124             }
2125             if ( t3.getNumberOfExternalNodes() != 4 ) {
2126                 return false;
2127             }
2128             if ( !t1.getName().equals( "t1" ) ) {
2129                 return false;
2130             }
2131             if ( !t2.getName().equals( "t2" ) ) {
2132                 return false;
2133             }
2134             if ( !t3.getName().equals( "t3" ) ) {
2135                 return false;
2136             }
2137             if ( !t4.getName().equals( "t4" ) ) {
2138                 return false;
2139             }
2140             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
2141                 return false;
2142             }
2143             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
2144                 return false;
2145             }
2146             if ( !t3.getNode( "root node" ).isDuplication() ) {
2147                 return false;
2148             }
2149             if ( !t3.getNode( "node a" ).isDuplication() ) {
2150                 return false;
2151             }
2152             if ( t3.getNode( "node a" ).isSpeciation() ) {
2153                 return false;
2154             }
2155             if ( t3.getNode( "node bc" ).isDuplication() ) {
2156                 return false;
2157             }
2158             if ( !t3.getNode( "node bc" ).isSpeciation() ) {
2159                 return false;
2160             }
2161             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2162                 return false;
2163             }
2164             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
2165                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2166                 return false;
2167             }
2168             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2169                 return false;
2170             }
2171             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2172                 return false;
2173             }
2174             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
2175                 return false;
2176             }
2177             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2178                     .equals( "apoptosis" ) ) {
2179                 return false;
2180             }
2181             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2182                     .equals( "GO:0006915" ) ) {
2183                 return false;
2184             }
2185             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2186                     .equals( "UniProtKB" ) ) {
2187                 return false;
2188             }
2189             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2190                     .equals( "experimental" ) ) {
2191                 return false;
2192             }
2193             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2194                     .equals( "function" ) ) {
2195                 return false;
2196             }
2197             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2198                     .getValue() != 1 ) {
2199                 return false;
2200             }
2201             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2202                     .getType().equals( "ml" ) ) {
2203                 return false;
2204             }
2205             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2206                     .equals( "apoptosis" ) ) {
2207                 return false;
2208             }
2209             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2210                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2211                 return false;
2212             }
2213             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2214                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2215                 return false;
2216             }
2217             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2218                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2219                 return false;
2220             }
2221             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2222                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2223                 return false;
2224             }
2225             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2226                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2227                 return false;
2228             }
2229             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2230                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2231                 return false;
2232             }
2233             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2234                     .equals( "GO:0005829" ) ) {
2235                 return false;
2236             }
2237             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2238                     .equals( "intracellular organelle" ) ) {
2239                 return false;
2240             }
2241             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2242                 return false;
2243             }
2244             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2245                     .equals( "UniProt link" ) ) ) {
2246                 return false;
2247             }
2248             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2249                 return false;
2250             }
2251             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
2252             if ( x.size() != 4 ) {
2253                 return false;
2254             }
2255             int c = 0;
2256             for( final Accession acc : x ) {
2257                 if ( c == 0 ) {
2258                     if ( !acc.getSource().equals( "KEGG" ) ) {
2259                         return false;
2260                     }
2261                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2262                         return false;
2263                     }
2264                 }
2265                 c++;
2266             }
2267         }
2268         catch ( final Exception e ) {
2269             e.printStackTrace( System.out );
2270             return false;
2271         }
2272         return true;
2273     }
2274
2275     private static boolean testBasicPhyloXMLparsingRoundtrip() {
2276         try {
2277             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2278             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
2279             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2280                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2281             }
2282             else {
2283                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2284             }
2285             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ),
2286                                                               xml_parser );
2287             if ( xml_parser.getErrorCount() > 0 ) {
2288                 System.out.println( xml_parser.getErrorMessages().toString() );
2289                 return false;
2290             }
2291             if ( phylogenies_0.length != 4 ) {
2292                 return false;
2293             }
2294             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
2295             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
2296             if ( phylogenies_t1.length != 1 ) {
2297                 return false;
2298             }
2299             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
2300             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
2301                 return false;
2302             }
2303             if ( !t1_rt.isRooted() ) {
2304                 return false;
2305             }
2306             if ( t1_rt.isRerootable() ) {
2307                 return false;
2308             }
2309             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
2310                 return false;
2311             }
2312             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
2313             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
2314             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
2315             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
2316                 return false;
2317             }
2318             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
2319                 return false;
2320             }
2321             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
2322                 return false;
2323             }
2324             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
2325                 return false;
2326             }
2327             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
2328                     .startsWith( "actgtgggggt" ) ) {
2329                 return false;
2330             }
2331             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
2332                     .startsWith( "ctgtgatgcat" ) ) {
2333                 return false;
2334             }
2335             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
2336             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
2337             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
2338             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
2339             if ( phylogenies_1.length != 1 ) {
2340                 return false;
2341             }
2342             final Phylogeny t3_rt = phylogenies_1[ 0 ];
2343             if ( !t3_rt.getName().equals( "t3" ) ) {
2344                 return false;
2345             }
2346             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
2347                 return false;
2348             }
2349             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
2350                 return false;
2351             }
2352             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
2353                 return false;
2354             }
2355             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2356                 return false;
2357             }
2358             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
2359                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2360                 return false;
2361             }
2362             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2363                 return false;
2364             }
2365             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2366                 return false;
2367             }
2368             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2369                     .equals( "UniProtKB" ) ) {
2370                 return false;
2371             }
2372             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2373                     .equals( "apoptosis" ) ) {
2374                 return false;
2375             }
2376             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2377                     .equals( "GO:0006915" ) ) {
2378                 return false;
2379             }
2380             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2381                     .equals( "UniProtKB" ) ) {
2382                 return false;
2383             }
2384             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2385                     .equals( "experimental" ) ) {
2386                 return false;
2387             }
2388             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2389                     .equals( "function" ) ) {
2390                 return false;
2391             }
2392             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2393                     .getValue() != 1 ) {
2394                 return false;
2395             }
2396             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2397                     .getType().equals( "ml" ) ) {
2398                 return false;
2399             }
2400             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2401                     .equals( "apoptosis" ) ) {
2402                 return false;
2403             }
2404             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2405                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2406                 return false;
2407             }
2408             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2409                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2410                 return false;
2411             }
2412             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2413                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2414                 return false;
2415             }
2416             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2417                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2418                 return false;
2419             }
2420             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2421                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2422                 return false;
2423             }
2424             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2425                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2426                 return false;
2427             }
2428             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2429                     .equals( "GO:0005829" ) ) {
2430                 return false;
2431             }
2432             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2433                     .equals( "intracellular organelle" ) ) {
2434                 return false;
2435             }
2436             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2437                 return false;
2438             }
2439             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2440                     .equals( "UniProt link" ) ) ) {
2441                 return false;
2442             }
2443             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2444                 return false;
2445             }
2446             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
2447                 return false;
2448             }
2449             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2450                     .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." ) ) ) {
2451                 System.out.println( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription() );
2452                 return false;
2453             }
2454             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2455                 return false;
2456             }
2457             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2458                 return false;
2459             }
2460             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
2461                 return false;
2462             }
2463             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2464                 return false;
2465             }
2466             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2467                     .equals( "ncbi" ) ) {
2468                 return false;
2469             }
2470             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2471                 return false;
2472             }
2473             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2474                     .getName().equals( "B" ) ) {
2475                 return false;
2476             }
2477             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2478                     .getFrom() != 21 ) {
2479                 return false;
2480             }
2481             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2482                 return false;
2483             }
2484             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2485                     .getLength() != 24 ) {
2486                 return false;
2487             }
2488             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2489                     .getConfidence() != 0 ) {
2490                 return false;
2491             }
2492             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2493                     .equals( "pfam" ) ) {
2494                 return false;
2495             }
2496             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2497                 return false;
2498             }
2499             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2500                 return false;
2501             }
2502             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2503                 return false;
2504             }
2505             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2506                 return false;
2507             }
2508             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2509             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2510                 return false;
2511             }
2512             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2513                 return false;
2514             }
2515             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2516                 return false;
2517             }
2518             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2519                 return false;
2520             }
2521             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2522                 return false;
2523             }
2524             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2525                 return false;
2526             }
2527             if ( taxbb.getSynonyms().size() != 2 ) {
2528                 return false;
2529             }
2530             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2531                 return false;
2532             }
2533             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2534                 return false;
2535             }
2536             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2537                 return false;
2538             }
2539             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2540                 return false;
2541             }
2542             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2543                 return false;
2544             }
2545             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2546                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2547                 return false;
2548             }
2549             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2550                 return false;
2551             }
2552             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2553                 return false;
2554             }
2555             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2556                 return false;
2557             }
2558             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2559                 return false;
2560             }
2561             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2562                 return false;
2563             }
2564             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2565                 return false;
2566             }
2567             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2568                 return false;
2569             }
2570             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2571                 return false;
2572             }
2573             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2574                     .equalsIgnoreCase( "435" ) ) {
2575                 return false;
2576             }
2577             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2578                 return false;
2579             }
2580             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2581                     .equalsIgnoreCase( "443.7" ) ) {
2582                 return false;
2583             }
2584             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2585                 return false;
2586             }
2587             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2588                 return false;
2589             }
2590             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2591                     .equalsIgnoreCase( "433" ) ) {
2592                 return false;
2593             }
2594             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2595                     .getCrossReferences();
2596             if ( x.size() != 4 ) {
2597                 return false;
2598             }
2599             int c = 0;
2600             for( final Accession acc : x ) {
2601                 if ( c == 0 ) {
2602                     if ( !acc.getSource().equals( "KEGG" ) ) {
2603                         return false;
2604                     }
2605                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2606                         return false;
2607                     }
2608                 }
2609                 c++;
2610             }
2611         }
2612         catch ( final Exception e ) {
2613             e.printStackTrace( System.out );
2614             return false;
2615         }
2616         return true;
2617     }
2618
2619     private static boolean testBasicPhyloXMLparsingValidating() {
2620         try {
2621             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2622             PhyloXmlParser xml_parser = null;
2623             try {
2624                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2625             }
2626             catch ( final Exception e ) {
2627                 // Do nothing -- means were not running from jar.
2628             }
2629             if ( xml_parser == null ) {
2630                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2631                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2632                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2633                 }
2634                 else {
2635                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2636                 }
2637             }
2638             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml" ),
2639                                                               xml_parser );
2640             if ( xml_parser.getErrorCount() > 0 ) {
2641                 System.out.println( xml_parser.getErrorMessages().toString() );
2642                 return false;
2643             }
2644             if ( phylogenies_0.length != 4 ) {
2645                 return false;
2646             }
2647             final Phylogeny t1 = phylogenies_0[ 0 ];
2648             final Phylogeny t2 = phylogenies_0[ 1 ];
2649             final Phylogeny t3 = phylogenies_0[ 2 ];
2650             final Phylogeny t4 = phylogenies_0[ 3 ];
2651             if ( !t1.getName().equals( "t1" ) ) {
2652                 return false;
2653             }
2654             if ( !t2.getName().equals( "t2" ) ) {
2655                 return false;
2656             }
2657             if ( !t3.getName().equals( "t3" ) ) {
2658                 return false;
2659             }
2660             if ( !t4.getName().equals( "t4" ) ) {
2661                 return false;
2662             }
2663             if ( t1.getNumberOfExternalNodes() != 1 ) {
2664                 return false;
2665             }
2666             if ( t2.getNumberOfExternalNodes() != 2 ) {
2667                 return false;
2668             }
2669             if ( t3.getNumberOfExternalNodes() != 4 ) {
2670                 return false;
2671             }
2672             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2673             final Phylogeny[] phylogenies_1 = factory.create( new File( x2 ), xml_parser );
2674             if ( xml_parser.getErrorCount() > 0 ) {
2675                 System.out.println( "errors:" );
2676                 System.out.println( xml_parser.getErrorMessages().toString() );
2677                 return false;
2678             }
2679             if ( phylogenies_1.length != 4 ) {
2680                 return false;
2681             }
2682             final Phylogeny[] phylogenies_2 = factory.create( new File(Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml" ),
2683                                                               xml_parser );
2684             if ( xml_parser.getErrorCount() > 0 ) {
2685                 System.out.println( "errors:" );
2686                 System.out.println( xml_parser.getErrorMessages().toString() );
2687                 return false;
2688             }
2689             if ( phylogenies_2.length != 1 ) {
2690                 return false;
2691             }
2692             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2693                 return false;
2694             }
2695             final Phylogeny[] phylogenies_3 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml" ),
2696                                                               xml_parser );
2697             if ( xml_parser.getErrorCount() > 0 ) {
2698                 System.out.println( xml_parser.getErrorMessages().toString() );
2699                 return false;
2700             }
2701             if ( phylogenies_3.length != 2 ) {
2702                 return false;
2703             }
2704             final Phylogeny a = phylogenies_3[ 0 ];
2705             if ( !a.getName().equals( "tree 4" ) ) {
2706                 return false;
2707             }
2708             if ( a.getNumberOfExternalNodes() != 3 ) {
2709                 return false;
2710             }
2711             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2712                 return false;
2713             }
2714             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2715                 return false;
2716             }
2717             final Phylogeny[] phylogenies_4 = factory.create( new File( Test.PATH_TO_TEST_DATA + "special_characters.xml") ,
2718                                                               xml_parser );
2719             if ( xml_parser.getErrorCount() > 0 ) {
2720                 System.out.println( xml_parser.getErrorMessages().toString() );
2721                 return false;
2722             }
2723             if ( phylogenies_4.length != 1 ) {
2724                 return false;
2725             }
2726             final Phylogeny s = phylogenies_4[ 0 ];
2727             if ( s.getNumberOfExternalNodes() != 6 ) {
2728                 return false;
2729             }
2730             s.getNode( "first" );
2731             s.getNode( "<>" );
2732             s.getNode( "\"<a'b&c'd\">\"" );
2733             s.getNode( "'''\"" );
2734             s.getNode( "\"\"\"" );
2735             s.getNode( "dick & doof" );
2736         }
2737         catch ( final Exception e ) {
2738             e.printStackTrace( System.out );
2739             return false;
2740         }
2741         return true;
2742     }
2743
2744     private static boolean testBasicProtein() {
2745         try {
2746             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2747             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2748             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2749             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2750             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2751             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2752             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2753             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2754             p0.addProteinDomain( y );
2755             p0.addProteinDomain( e );
2756             p0.addProteinDomain( b );
2757             p0.addProteinDomain( c );
2758             p0.addProteinDomain( d );
2759             p0.addProteinDomain( a );
2760             p0.addProteinDomain( x );
2761             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2762                 return false;
2763             }
2764             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2765                 return false;
2766             }
2767             //
2768             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2769             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2770             aa0.addProteinDomain( a1 );
2771             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2772                 return false;
2773             }
2774             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2775                 return false;
2776             }
2777             //
2778             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2779             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2780             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2781             aa1.addProteinDomain( a11 );
2782             aa1.addProteinDomain( a12 );
2783             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2784                 return false;
2785             }
2786             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2787                 return false;
2788             }
2789             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2790             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2791                 return false;
2792             }
2793             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2794                 return false;
2795             }
2796             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2797                 return false;
2798             }
2799             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2800             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2801                 return false;
2802             }
2803             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2804                 return false;
2805             }
2806             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2807                 return false;
2808             }
2809             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2810                 return false;
2811             }
2812             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2813             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2814                 return false;
2815             }
2816             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2817                 return false;
2818             }
2819             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2820                 return false;
2821             }
2822             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2823                 return false;
2824             }
2825             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2826             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2827                 return false;
2828             }
2829             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2830                 return false;
2831             }
2832             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2833                 return false;
2834             }
2835             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2836                 return false;
2837             }
2838             //
2839             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2840             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2841             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2842             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2843             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2844             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2845             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2846             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2847             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2848             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2849             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2850             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2851             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2852             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2853             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2854             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2855             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2856             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2857             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2858             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2859             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2860             p00.addProteinDomain( y0 );
2861             p00.addProteinDomain( e0 );
2862             p00.addProteinDomain( b0 );
2863             p00.addProteinDomain( c0 );
2864             p00.addProteinDomain( d0 );
2865             p00.addProteinDomain( a0 );
2866             p00.addProteinDomain( x0 );
2867             p00.addProteinDomain( y1 );
2868             p00.addProteinDomain( y2 );
2869             p00.addProteinDomain( y3 );
2870             p00.addProteinDomain( e1 );
2871             p00.addProteinDomain( e2 );
2872             p00.addProteinDomain( e3 );
2873             p00.addProteinDomain( e4 );
2874             p00.addProteinDomain( e5 );
2875             p00.addProteinDomain( z0 );
2876             p00.addProteinDomain( z1 );
2877             p00.addProteinDomain( z2 );
2878             p00.addProteinDomain( zz0 );
2879             p00.addProteinDomain( zz1 );
2880             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2881                 return false;
2882             }
2883             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2884                 return false;
2885             }
2886             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2887                 return false;
2888             }
2889             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2890                 return false;
2891             }
2892             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" ) ) {
2893                 return false;
2894             }
2895             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2896             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2897             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2898             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2899             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2900             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2901             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2902             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2903             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2904             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2905             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2906             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2907             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2908             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2909             p.addProteinDomain( B15 );
2910             p.addProteinDomain( C50 );
2911             p.addProteinDomain( A60 );
2912             p.addProteinDomain( A30 );
2913             p.addProteinDomain( C70 );
2914             p.addProteinDomain( B35 );
2915             p.addProteinDomain( B40 );
2916             p.addProteinDomain( A0 );
2917             p.addProteinDomain( A10 );
2918             p.addProteinDomain( A20 );
2919             p.addProteinDomain( B25 );
2920             p.addProteinDomain( D80 );
2921             List<String> domains_ids = new ArrayList<String>();
2922             domains_ids.add( "A" );
2923             domains_ids.add( "B" );
2924             domains_ids.add( "C" );
2925             if ( !p.contains( domains_ids, false ) ) {
2926                 return false;
2927             }
2928             if ( !p.contains( domains_ids, true ) ) {
2929                 return false;
2930             }
2931             domains_ids.add( "X" );
2932             if ( p.contains( domains_ids, false ) ) {
2933                 return false;
2934             }
2935             if ( p.contains( domains_ids, true ) ) {
2936                 return false;
2937             }
2938             domains_ids = new ArrayList<String>();
2939             domains_ids.add( "A" );
2940             domains_ids.add( "C" );
2941             domains_ids.add( "D" );
2942             if ( !p.contains( domains_ids, false ) ) {
2943                 return false;
2944             }
2945             if ( !p.contains( domains_ids, true ) ) {
2946                 return false;
2947             }
2948             domains_ids = new ArrayList<String>();
2949             domains_ids.add( "A" );
2950             domains_ids.add( "D" );
2951             domains_ids.add( "C" );
2952             if ( !p.contains( domains_ids, false ) ) {
2953                 return false;
2954             }
2955             if ( p.contains( domains_ids, true ) ) {
2956                 return false;
2957             }
2958             domains_ids = new ArrayList<String>();
2959             domains_ids.add( "A" );
2960             domains_ids.add( "A" );
2961             domains_ids.add( "B" );
2962             if ( !p.contains( domains_ids, false ) ) {
2963                 return false;
2964             }
2965             if ( !p.contains( domains_ids, true ) ) {
2966                 return false;
2967             }
2968             domains_ids = new ArrayList<String>();
2969             domains_ids.add( "A" );
2970             domains_ids.add( "A" );
2971             domains_ids.add( "A" );
2972             domains_ids.add( "B" );
2973             domains_ids.add( "B" );
2974             if ( !p.contains( domains_ids, false ) ) {
2975                 return false;
2976             }
2977             if ( !p.contains( domains_ids, true ) ) {
2978                 return false;
2979             }
2980             domains_ids = new ArrayList<String>();
2981             domains_ids.add( "A" );
2982             domains_ids.add( "A" );
2983             domains_ids.add( "B" );
2984             domains_ids.add( "A" );
2985             domains_ids.add( "B" );
2986             domains_ids.add( "B" );
2987             domains_ids.add( "A" );
2988             domains_ids.add( "B" );
2989             domains_ids.add( "C" );
2990             domains_ids.add( "A" );
2991             domains_ids.add( "C" );
2992             domains_ids.add( "D" );
2993             if ( !p.contains( domains_ids, false ) ) {
2994                 return false;
2995             }
2996             if ( p.contains( domains_ids, true ) ) {
2997                 return false;
2998             }
2999         }
3000         catch ( final Exception e ) {
3001             e.printStackTrace( System.out );
3002             return false;
3003         }
3004         return true;
3005     }
3006
3007     private static boolean testBasicTable() {
3008         try {
3009             final BasicTable<String> t0 = new BasicTable<String>();
3010             if ( t0.getNumberOfColumns() != 0 ) {
3011                 return false;
3012             }
3013             if ( t0.getNumberOfRows() != 0 ) {
3014                 return false;
3015             }
3016             t0.setValue( 3, 2, "23" );
3017             t0.setValue( 10, 1, "error" );
3018             t0.setValue( 10, 1, "110" );
3019             t0.setValue( 9, 1, "19" );
3020             t0.setValue( 1, 10, "101" );
3021             t0.setValue( 10, 10, "1010" );
3022             t0.setValue( 100, 10, "10100" );
3023             t0.setValue( 0, 0, "00" );
3024             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3025                 return false;
3026             }
3027             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3028                 return false;
3029             }
3030             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3031                 return false;
3032             }
3033             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3034                 return false;
3035             }
3036             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3037                 return false;
3038             }
3039             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3040                 return false;
3041             }
3042             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3043                 return false;
3044             }
3045             if ( t0.getNumberOfColumns() != 101 ) {
3046                 return false;
3047             }
3048             if ( t0.getNumberOfRows() != 11 ) {
3049                 return false;
3050             }
3051             if ( t0.getValueAsString( 49, 4 ) != null ) {
3052                 return false;
3053             }
3054             final String l = ForesterUtil.getLineSeparator();
3055             final StringBuffer source = new StringBuffer();
3056             source.append( "" + l );
3057             source.append( "# 1 1 1 1 1 1 1 1" + l );
3058             source.append( " 00 01 02 03" + l );
3059             source.append( "   10 11 12 13  " + l );
3060             source.append( "20 21 22 23 " + l );
3061             source.append( "    30  31    32 33" + l );
3062             source.append( "40 41 42 43" + l );
3063             source.append( "  # 1 1 1 1 1 " + l );
3064             source.append( "50 51 52 53 54" + l );
3065             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
3066             if ( t1.getNumberOfColumns() != 5 ) {
3067                 return false;
3068             }
3069             if ( t1.getNumberOfRows() != 6 ) {
3070                 return false;
3071             }
3072             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
3073                 return false;
3074             }
3075             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
3076                 return false;
3077             }
3078             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
3079                 return false;
3080             }
3081             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
3082                 return false;
3083             }
3084             final StringBuffer source1 = new StringBuffer();
3085             source1.append( "" + l );
3086             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3087             source1.append( " 00; 01 ;02;03" + l );
3088             source1.append( "   10; 11; 12; 13  " + l );
3089             source1.append( "20; 21; 22; 23 " + l );
3090             source1.append( "    30;  31;    32; 33" + l );
3091             source1.append( "40;41;42;43" + l );
3092             source1.append( "  # 1 1 1 1 1 " + l );
3093             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
3094             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
3095             if ( t2.getNumberOfColumns() != 5 ) {
3096                 return false;
3097             }
3098             if ( t2.getNumberOfRows() != 6 ) {
3099                 return false;
3100             }
3101             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
3102                 return false;
3103             }
3104             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
3105                 return false;
3106             }
3107             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
3108                 return false;
3109             }
3110             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
3111                 return false;
3112             }
3113             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
3114                 return false;
3115             }
3116             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
3117                 return false;
3118             }
3119             final StringBuffer source2 = new StringBuffer();
3120             source2.append( "" + l );
3121             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
3122             source2.append( " 00; 01 ;02;03" + l );
3123             source2.append( "   10; 11; 12; 13  " + l );
3124             source2.append( "20; 21; 22; 23 " + l );
3125             source2.append( "                     " + l );
3126             source2.append( "    30;  31;    32; 33" + l );
3127             source2.append( "40;41;42;43" + l );
3128             source2.append( "  comment: 1 1 1 1 1 " + l );
3129             source2.append( ";;;50  ;   52; 53;;54   " + l );
3130             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
3131                                                                         ';',
3132                                                                         false,
3133                                                                         false,
3134                                                                         "comment:",
3135                                                                         false );
3136             if ( tl.size() != 2 ) {
3137                 return false;
3138             }
3139             final BasicTable<String> t3 = tl.get( 0 );
3140             final BasicTable<String> t4 = tl.get( 1 );
3141             if ( t3.getNumberOfColumns() != 4 ) {
3142                 return false;
3143             }
3144             if ( t3.getNumberOfRows() != 3 ) {
3145                 return false;
3146             }
3147             if ( t4.getNumberOfColumns() != 4 ) {
3148                 return false;
3149             }
3150             if ( t4.getNumberOfRows() != 3 ) {
3151                 return false;
3152             }
3153             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
3154                 return false;
3155             }
3156             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
3157                 return false;
3158             }
3159         }
3160         catch ( final Exception e ) {
3161             e.printStackTrace( System.out );
3162             return false;
3163         }
3164         return true;
3165     }
3166
3167     private static boolean testBasicTolXMLparsing() {
3168         try {
3169             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3170             final TolParser parser = new TolParser();
3171             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
3172             if ( parser.getErrorCount() > 0 ) {
3173                 System.out.println( parser.getErrorMessages().toString() );
3174                 return false;
3175             }
3176             if ( phylogenies_0.length != 1 ) {
3177                 return false;
3178             }
3179             final Phylogeny t1 = phylogenies_0[ 0 ];
3180             if ( t1.getNumberOfExternalNodes() != 5 ) {
3181                 return false;
3182             }
3183             if ( !t1.isRooted() ) {
3184                 return false;
3185             }
3186             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
3187                 return false;
3188             }
3189             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
3190                 return false;
3191             }
3192             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
3193                 return false;
3194             }
3195             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
3196                 return false;
3197             }
3198             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
3199             if ( parser.getErrorCount() > 0 ) {
3200                 System.out.println( parser.getErrorMessages().toString() );
3201                 return false;
3202             }
3203             if ( phylogenies_1.length != 1 ) {
3204                 return false;
3205             }
3206             final Phylogeny t2 = phylogenies_1[ 0 ];
3207             if ( t2.getNumberOfExternalNodes() != 664 ) {
3208                 return false;
3209             }
3210             if ( !t2.isRooted() ) {
3211                 return false;
3212             }
3213             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
3214                 return false;
3215             }
3216             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
3217                 return false;
3218             }
3219             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3220                 return false;
3221             }
3222             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
3223                 return false;
3224             }
3225             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
3226                 return false;
3227             }
3228             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
3229                     .equals( "Aquifex" ) ) {
3230                 return false;
3231             }
3232             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
3233             if ( parser.getErrorCount() > 0 ) {
3234                 System.out.println( parser.getErrorMessages().toString() );
3235                 return false;
3236             }
3237             if ( phylogenies_2.length != 1 ) {
3238                 return false;
3239             }
3240             final Phylogeny t3 = phylogenies_2[ 0 ];
3241             if ( t3.getNumberOfExternalNodes() != 184 ) {
3242                 return false;
3243             }
3244             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
3245                 return false;
3246             }
3247             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
3248                 return false;
3249             }
3250             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
3251                 return false;
3252             }
3253             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
3254             if ( parser.getErrorCount() > 0 ) {
3255                 System.out.println( parser.getErrorMessages().toString() );
3256                 return false;
3257             }
3258             if ( phylogenies_3.length != 1 ) {
3259                 return false;
3260             }
3261             final Phylogeny t4 = phylogenies_3[ 0 ];
3262             if ( t4.getNumberOfExternalNodes() != 1 ) {
3263                 return false;
3264             }
3265             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
3266                 return false;
3267             }
3268             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
3269                 return false;
3270             }
3271             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
3272                 return false;
3273             }
3274             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
3275             if ( parser.getErrorCount() > 0 ) {
3276                 System.out.println( parser.getErrorMessages().toString() );
3277                 return false;
3278             }
3279             if ( phylogenies_4.length != 1 ) {
3280                 return false;
3281             }
3282             final Phylogeny t5 = phylogenies_4[ 0 ];
3283             if ( t5.getNumberOfExternalNodes() != 13 ) {
3284                 return false;
3285             }
3286             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
3287                 return false;
3288             }
3289             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
3290                 return false;
3291             }
3292             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
3293                 return false;
3294             }
3295         }
3296         catch ( final Exception e ) {
3297             e.printStackTrace( System.out );
3298             return false;
3299         }
3300         return true;
3301     }
3302
3303     private static boolean testBasicTreeMethods() {
3304         try {
3305             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3306             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
3307             if ( t2.getNumberOfExternalNodes() != 4 ) {
3308                 return false;
3309             }
3310             if ( t2.getHeight() != 8.5 ) {
3311                 return false;
3312             }
3313             if ( !t2.isCompletelyBinary() ) {
3314                 return false;
3315             }
3316             if ( t2.isEmpty() ) {
3317                 return false;
3318             }
3319             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
3320             if ( t3.getNumberOfExternalNodes() != 5 ) {
3321                 return false;
3322             }
3323             if ( t3.getHeight() != 11 ) {
3324                 return false;
3325             }
3326             if ( t3.isCompletelyBinary() ) {
3327                 return false;
3328             }
3329             final PhylogenyNode n = t3.getNode( "ABC" );
3330             final Phylogeny t4 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3,(F,G,H,I))", new NHXParser() )[ 0 ];
3331             if ( t4.getNumberOfExternalNodes() != 9 ) {
3332                 return false;
3333             }
3334             if ( t4.getHeight() != 11 ) {
3335                 return false;
3336             }
3337             if ( t4.isCompletelyBinary() ) {
3338                 return false;
3339             }
3340             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)" );
3341             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
3342             if ( t5.getNumberOfExternalNodes() != 8 ) {
3343                 return false;
3344             }
3345             if ( t5.getHeight() != 15 ) {
3346                 return false;
3347             }
3348             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)" );
3349             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
3350             if ( t6.getHeight() != 15 ) {
3351                 return false;
3352             }
3353             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)" );
3354             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
3355             if ( t7.getHeight() != 15 ) {
3356                 return false;
3357             }
3358             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)" );
3359             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
3360             if ( t8.getNumberOfExternalNodes() != 10 ) {
3361                 return false;
3362             }
3363             if ( t8.getHeight() != 15 ) {
3364                 return false;
3365             }
3366             final char[] a9 = new char[] { 'a' };
3367             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
3368             if ( t9.getHeight() != 0 ) {
3369                 return false;
3370             }
3371             final char[] a10 = new char[] { 'a', ':', '6' };
3372             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
3373             if ( t10.getHeight() != 6 ) {
3374                 return false;
3375             }
3376         }
3377         catch ( final Exception e ) {
3378             e.printStackTrace( System.out );
3379             return false;
3380         }
3381         return true;
3382     }
3383
3384     private static boolean testConfidenceAssessor() {
3385         try {
3386             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3387             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3388             final Phylogeny[] ev0 = factory
3389                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3390                              new NHXParser() );
3391             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3392             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3393                 return false;
3394             }
3395             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3396                 return false;
3397             }
3398             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3399             final Phylogeny[] ev1 = factory
3400                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));",
3401                              new NHXParser() );
3402             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3403             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3404                 return false;
3405             }
3406             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3407                 return false;
3408             }
3409             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3410             final Phylogeny[] ev_b = factory
3411                     .create( "((A,C),X);((A,X),C);(A,C);((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));((((A,C)ac,D)acd,E)acde,B)abcd",
3412                              new NHXParser() );
3413             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3414             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3415                 return false;
3416             }
3417             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3418                 return false;
3419             }
3420             //
3421             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3422             final Phylogeny[] ev1x = factory
3423                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));",
3424                              new NHXParser() );
3425             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3426             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3427                 return false;
3428             }
3429             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3430                 return false;
3431             }
3432             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3433             final Phylogeny[] ev_bx = factory
3434                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));((((A,C)ac,D)acd,E)acde,B)abcd",
3435                              new NHXParser() );
3436             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3437             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3438                 return false;
3439             }
3440             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3441                 return false;
3442             }
3443             final Phylogeny[] t2 = factory
3444                     .create( "((((a,b),c),d),e);(((a,b),c),(d,e));(((((a,b),c),d),e),f);((((a,b),c),(d,e)),f);(((a,b),c),d,e);((a,b,c),d,e);",
3445                              new NHXParser() );
3446             final Phylogeny[] ev2 = factory
3447                     .create( "((((a,b),c),d),e);((((a,b),c),d),e);((((a,b),e),d),c);((((a,b),e),d),c);(((a,b),(c,d)),e);((a,b),x);((a,b),(x,y));(a,b);(a,e);(a,b,c);",
3448                              new NHXParser() );
3449             for( final Phylogeny target : t2 ) {
3450                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3451             }
3452             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3453                                                  new NHXParser() )[ 0 ];
3454             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3455             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3456             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3457                 return false;
3458             }
3459             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3460                 return false;
3461             }
3462             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3463                 return false;
3464             }
3465         }
3466         catch ( final Exception e ) {
3467             e.printStackTrace();
3468             return false;
3469         }
3470         return true;
3471     }
3472
3473     private static boolean testCopyOfNodeData() {
3474         try {
3475             final PhylogenyNode n1 = PhylogenyNode
3476                     .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]" );
3477             final PhylogenyNode n2 = n1.copyNodeData();
3478             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3479                 return false;
3480             }
3481         }
3482         catch ( final Exception e ) {
3483             e.printStackTrace();
3484             return false;
3485         }
3486         return true;
3487     }
3488
3489     private static boolean testCreateBalancedPhylogeny() {
3490         try {
3491             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3492             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3493                 return false;
3494             }
3495             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3496                 return false;
3497             }
3498             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3499             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3500                 return false;
3501             }
3502             if ( p1.getNumberOfExternalNodes() != 100 ) {
3503                 return false;
3504             }
3505         }
3506         catch ( final Exception e ) {
3507             e.printStackTrace();
3508             return false;
3509         }
3510         return true;
3511     }
3512
3513     private static boolean testCreateUriForSeqWeb() {
3514         try {
3515             final PhylogenyNode n = new PhylogenyNode();
3516             n.setName( "tr|B3RJ64" );
3517             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3518                 return false;
3519             }
3520             n.setName( "B0LM41_HUMAN" );
3521             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3522                 return false;
3523             }
3524             n.setName( "NP_001025424" );
3525             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3526                 return false;
3527             }
3528             n.setName( "_NM_001030253-" );
3529             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3530                 return false;
3531             }
3532             n.setName( "XM_002122186" );
3533             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3534                 return false;
3535             }
3536             n.setName( "dgh_AAA34956_gdg" );
3537             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3538                 return false;
3539             }
3540             n.setName( "AAA34956" );
3541             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3542                 return false;
3543             }
3544             n.setName( "GI:394892" );
3545             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3546                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3547                 return false;
3548             }
3549             n.setName( "gi_394892" );
3550             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3551                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3552                 return false;
3553             }
3554             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3555             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3556                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3557                 return false;
3558             }
3559             n.setName( "P12345" );
3560             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3561                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3562                 return false;
3563             }
3564             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3565             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3566                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3567                 return false;
3568             }
3569         }
3570         catch ( final Exception e ) {
3571             e.printStackTrace( System.out );
3572             return false;
3573         }
3574         return true;
3575     }
3576
3577     private static boolean testDataObjects() {
3578         try {
3579             final Confidence s0 = new Confidence();
3580             final Confidence s1 = new Confidence();
3581             if ( !s0.isEqual( s1 ) ) {
3582                 return false;
3583             }
3584             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3585             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3586             if ( s2.isEqual( s1 ) ) {
3587                 return false;
3588             }
3589             if ( !s2.isEqual( s3 ) ) {
3590                 return false;
3591             }
3592             final Confidence s4 = ( Confidence ) s3.copy();
3593             if ( !s4.isEqual( s3 ) ) {
3594                 return false;
3595             }
3596             s3.asSimpleText();
3597             s3.asText();
3598             // Taxonomy
3599             // ----------
3600             final Taxonomy t1 = new Taxonomy();
3601             final Taxonomy t2 = new Taxonomy();
3602             final Taxonomy t3 = new Taxonomy();
3603             final Taxonomy t4 = new Taxonomy();
3604             final Taxonomy t5 = new Taxonomy();
3605             t1.setIdentifier( new Identifier( "ecoli" ) );
3606             t1.setTaxonomyCode( "ECOLI" );
3607             t1.setScientificName( "E. coli" );
3608             t1.setCommonName( "coli" );
3609             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3610             if ( !t1.isEqual( t0 ) ) {
3611                 return false;
3612             }
3613             t2.setIdentifier( new Identifier( "ecoli" ) );
3614             t2.setTaxonomyCode( "OTHER" );
3615             t2.setScientificName( "what" );
3616             t2.setCommonName( "something" );
3617             if ( !t1.isEqual( t2 ) ) {
3618                 return false;
3619             }
3620             t2.setIdentifier( new Identifier( "nemve" ) );
3621             if ( t1.isEqual( t2 ) ) {
3622                 return false;
3623             }
3624             t1.setIdentifier( null );
3625             t3.setTaxonomyCode( "ECOLI" );
3626             t3.setScientificName( "what" );
3627             t3.setCommonName( "something" );
3628             if ( !t1.isEqual( t3 ) ) {
3629                 return false;
3630             }
3631             t1.setIdentifier( null );
3632             t1.setTaxonomyCode( "" );
3633             t4.setScientificName( "E. ColI" );
3634             t4.setCommonName( "something" );
3635             if ( !t1.isEqual( t4 ) ) {
3636                 return false;
3637             }
3638             t4.setScientificName( "B. subtilis" );
3639             t4.setCommonName( "something" );
3640             if ( t1.isEqual( t4 ) ) {
3641                 return false;
3642             }
3643             t1.setIdentifier( null );
3644             t1.setTaxonomyCode( "" );
3645             t1.setScientificName( "" );
3646             t5.setCommonName( "COLI" );
3647             if ( !t1.isEqual( t5 ) ) {
3648                 return false;
3649             }
3650             t5.setCommonName( "vibrio" );
3651             if ( t1.isEqual( t5 ) ) {
3652                 return false;
3653             }
3654             // Identifier
3655             // ----------
3656             final Identifier id0 = new Identifier( "123", "pfam" );
3657             final Identifier id1 = ( Identifier ) id0.copy();
3658             if ( !id1.isEqual( id1 ) ) {
3659                 return false;
3660             }
3661             if ( !id1.isEqual( id0 ) ) {
3662                 return false;
3663             }
3664             if ( !id0.isEqual( id1 ) ) {
3665                 return false;
3666             }
3667             id1.asSimpleText();
3668             id1.asText();
3669             // ProteinDomain
3670             // ---------------
3671             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3672             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3673             if ( !pd1.isEqual( pd1 ) ) {
3674                 return false;
3675             }
3676             if ( !pd1.isEqual( pd0 ) ) {
3677                 return false;
3678             }
3679             pd1.asSimpleText();
3680             pd1.asText();
3681             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3682             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3683             if ( !pd3.isEqual( pd3 ) ) {
3684                 return false;
3685             }
3686             if ( !pd2.isEqual( pd3 ) ) {
3687                 return false;
3688             }
3689             if ( !pd0.isEqual( pd3 ) ) {
3690                 return false;
3691             }
3692             pd3.asSimpleText();
3693             pd3.asText();
3694             // DomainArchitecture
3695             // ------------------
3696             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3697             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3698             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3699             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3700             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3701             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3702             domains0.add( d2 );
3703             domains0.add( d0 );
3704             domains0.add( d3 );
3705             domains0.add( d1 );
3706             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3707             if ( ds0.getNumberOfDomains() != 4 ) {
3708                 return false;
3709             }
3710             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3711             if ( !ds0.isEqual( ds0 ) ) {
3712                 return false;
3713             }
3714             if ( !ds0.isEqual( ds1 ) ) {
3715                 return false;
3716             }
3717             if ( ds1.getNumberOfDomains() != 4 ) {
3718                 return false;
3719             }
3720             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3721             domains1.add( d1 );
3722             domains1.add( d2 );
3723             domains1.add( d4 );
3724             domains1.add( d0 );
3725             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3726             if ( ds0.isEqual( ds2 ) ) {
3727                 return false;
3728             }
3729             ds1.asSimpleText();
3730             ds1.asText();
3731             ds1.toNHX();
3732             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3733             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3734                 System.out.println( ds3.toNHX() );
3735                 return false;
3736             }
3737             if ( ds3.getNumberOfDomains() != 3 ) {
3738                 return false;
3739             }
3740             // Event
3741             // -----
3742             final Event e1 = new Event( Event.EventType.fusion );
3743             if ( e1.isDuplication() ) {
3744                 return false;
3745             }
3746             if ( !e1.isFusion() ) {
3747                 return false;
3748             }
3749             if ( !e1.asText().toString().equals( "fusion" ) ) {
3750                 return false;
3751             }
3752             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3753                 return false;
3754             }
3755             final Event e11 = new Event( Event.EventType.fusion );
3756             if ( !e11.isEqual( e1 ) ) {
3757                 return false;
3758             }
3759             if ( !e11.toNHX().toString().equals( "" ) ) {
3760                 return false;
3761             }
3762             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3763             if ( e2.isDuplication() ) {
3764                 return false;
3765             }
3766             if ( !e2.isSpeciationOrDuplication() ) {
3767                 return false;
3768             }
3769             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3770                 return false;
3771             }
3772             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3773                 return false;
3774             }
3775             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3776                 return false;
3777             }
3778             if ( e11.isEqual( e2 ) ) {
3779                 return false;
3780             }
3781             final Event e2c = ( Event ) e2.copy();
3782             if ( !e2c.isEqual( e2 ) ) {
3783                 return false;
3784             }
3785             Event e3 = new Event( 1, 2, 3 );
3786             if ( e3.isDuplication() ) {
3787                 return false;
3788             }
3789             if ( e3.isSpeciation() ) {
3790                 return false;
3791             }
3792             if ( e3.isGeneLoss() ) {
3793                 return false;
3794             }
3795             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3796                 return false;
3797             }
3798             final Event e3c = ( Event ) e3.copy();
3799             final Event e3cc = ( Event ) e3c.copy();
3800             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3801                 return false;
3802             }
3803             e3 = null;
3804             if ( !e3c.isEqual( e3cc ) ) {
3805                 return false;
3806             }
3807             Event e4 = new Event( 1, 2, 3 );
3808             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3809                 return false;
3810             }
3811             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3812                 return false;
3813             }
3814             final Event e4c = ( Event ) e4.copy();
3815             e4 = null;
3816             final Event e4cc = ( Event ) e4c.copy();
3817             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3818                 return false;
3819             }
3820             if ( !e4c.isEqual( e4cc ) ) {
3821                 return false;
3822             }
3823             final Event e5 = new Event();
3824             if ( !e5.isUnassigned() ) {
3825                 return false;
3826             }
3827             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3828                 return false;
3829             }
3830             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3831                 return false;
3832             }
3833             final Event e6 = new Event( 1, 0, 0 );
3834             if ( !e6.asText().toString().equals( "duplication" ) ) {
3835                 return false;
3836             }
3837             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3838                 return false;
3839             }
3840             final Event e7 = new Event( 0, 1, 0 );
3841             if ( !e7.asText().toString().equals( "speciation" ) ) {
3842                 return false;
3843             }
3844             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3845                 return false;
3846             }
3847             final Event e8 = new Event( 0, 0, 1 );
3848             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3849                 return false;
3850             }
3851             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3852                 return false;
3853             }
3854         }
3855         catch ( final Exception e ) {
3856             e.printStackTrace( System.out );
3857             return false;
3858         }
3859         return true;
3860     }
3861
3862     private static boolean testDeletionOfExternalNodes() {
3863         try {
3864             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3865             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3866             final PhylogenyWriter w = new PhylogenyWriter();
3867             if ( t0.isEmpty() ) {
3868                 return false;
3869             }
3870             if ( t0.getNumberOfExternalNodes() != 1 ) {
3871                 return false;
3872             }
3873             t0.deleteSubtree( t0.getNode( "A" ), false );
3874             if ( t0.getNumberOfExternalNodes() != 0 ) {
3875                 return false;
3876             }
3877             if ( !t0.isEmpty() ) {
3878                 return false;
3879             }
3880             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3881             if ( t1.getNumberOfExternalNodes() != 2 ) {
3882                 return false;
3883             }
3884             t1.deleteSubtree( t1.getNode( "A" ), false );
3885             if ( t1.getNumberOfExternalNodes() != 1 ) {
3886                 return false;
3887             }
3888             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3889                 return false;
3890             }
3891             t1.deleteSubtree( t1.getNode( "B" ), false );
3892             if ( t1.getNumberOfExternalNodes() != 1 ) {
3893                 return false;
3894             }
3895             t1.deleteSubtree( t1.getNode( "r" ), false );
3896             if ( !t1.isEmpty() ) {
3897                 return false;
3898             }
3899             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3900             if ( t2.getNumberOfExternalNodes() != 3 ) {
3901                 return false;
3902             }
3903             t2.deleteSubtree( t2.getNode( "B" ), false );
3904             if ( t2.getNumberOfExternalNodes() != 2 ) {
3905                 return false;
3906             }
3907             t2.toNewHampshireX();
3908             PhylogenyNode n = t2.getNode( "A" );
3909             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3910                 return false;
3911             }
3912             t2.deleteSubtree( t2.getNode( "A" ), false );
3913             if ( t2.getNumberOfExternalNodes() != 2 ) {
3914                 return false;
3915             }
3916             t2.deleteSubtree( t2.getNode( "C" ), true );
3917             if ( t2.getNumberOfExternalNodes() != 1 ) {
3918                 return false;
3919             }
3920             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3921             if ( t3.getNumberOfExternalNodes() != 4 ) {
3922                 return false;
3923             }
3924             t3.deleteSubtree( t3.getNode( "B" ), true );
3925             if ( t3.getNumberOfExternalNodes() != 3 ) {
3926                 return false;
3927             }
3928             n = t3.getNode( "A" );
3929             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3930                 return false;
3931             }
3932             n = n.getNextExternalNode();
3933             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3934                 return false;
3935             }
3936             t3.deleteSubtree( t3.getNode( "A" ), true );
3937             if ( t3.getNumberOfExternalNodes() != 2 ) {
3938                 return false;
3939             }
3940             n = t3.getNode( "C" );
3941             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3942                 return false;
3943             }
3944             t3.deleteSubtree( t3.getNode( "C" ), true );
3945             if ( t3.getNumberOfExternalNodes() != 1 ) {
3946                 return false;
3947             }
3948             t3.deleteSubtree( t3.getNode( "D" ), true );
3949             if ( t3.getNumberOfExternalNodes() != 0 ) {
3950                 return false;
3951             }
3952             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3953             if ( t4.getNumberOfExternalNodes() != 6 ) {
3954                 return false;
3955             }
3956             t4.deleteSubtree( t4.getNode( "B2" ), true );
3957             if ( t4.getNumberOfExternalNodes() != 5 ) {
3958                 return false;
3959             }
3960             String s = w.toNewHampshire( t4, true ).toString();
3961             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3962                 return false;
3963             }
3964             t4.deleteSubtree( t4.getNode( "B11" ), true );
3965             if ( t4.getNumberOfExternalNodes() != 4 ) {
3966                 return false;
3967             }
3968             t4.deleteSubtree( t4.getNode( "C" ), true );
3969             if ( t4.getNumberOfExternalNodes() != 3 ) {
3970                 return false;
3971             }
3972             n = t4.getNode( "A" );
3973             n = n.getNextExternalNode();
3974             if ( !n.getName().equals( "B12" ) ) {
3975                 return false;
3976             }
3977             n = n.getNextExternalNode();
3978             if ( !n.getName().equals( "D" ) ) {
3979                 return false;
3980             }
3981             s = w.toNewHampshire( t4, true ).toString();
3982             if ( !s.equals( "((A,B12),D);" ) ) {
3983                 return false;
3984             }
3985             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3986             t5.deleteSubtree( t5.getNode( "A" ), true );
3987             if ( t5.getNumberOfExternalNodes() != 5 ) {
3988                 return false;
3989             }
3990             s = w.toNewHampshire( t5, true ).toString();
3991             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3992                 return false;
3993             }
3994             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3995             t6.deleteSubtree( t6.getNode( "B11" ), true );
3996             if ( t6.getNumberOfExternalNodes() != 5 ) {
3997                 return false;
3998             }
3999             s = w.toNewHampshire( t6, false ).toString();
4000             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
4001                 return false;
4002             }
4003             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4004             t7.deleteSubtree( t7.getNode( "B12" ), true );
4005             if ( t7.getNumberOfExternalNodes() != 5 ) {
4006                 return false;
4007             }
4008             s = w.toNewHampshire( t7, true ).toString();
4009             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
4010                 return false;
4011             }
4012             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4013             t8.deleteSubtree( t8.getNode( "B2" ), true );
4014             if ( t8.getNumberOfExternalNodes() != 5 ) {
4015                 return false;
4016             }
4017             s = w.toNewHampshire( t8, false ).toString();
4018             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
4019                 return false;
4020             }
4021             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4022             t9.deleteSubtree( t9.getNode( "C" ), true );
4023             if ( t9.getNumberOfExternalNodes() != 5 ) {
4024                 return false;
4025             }
4026             s = w.toNewHampshire( t9, true ).toString();
4027             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
4028                 return false;
4029             }
4030             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
4031             t10.deleteSubtree( t10.getNode( "D" ), true );
4032             if ( t10.getNumberOfExternalNodes() != 5 ) {
4033                 return false;
4034             }
4035             s = w.toNewHampshire( t10, true ).toString();
4036             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
4037                 return false;
4038             }
4039             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
4040             t11.deleteSubtree( t11.getNode( "A" ), true );
4041             if ( t11.getNumberOfExternalNodes() != 2 ) {
4042                 return false;
4043             }
4044             s = w.toNewHampshire( t11, true ).toString();
4045             if ( !s.equals( "(B,C);" ) ) {
4046                 return false;
4047             }
4048             t11.deleteSubtree( t11.getNode( "C" ), true );
4049             if ( t11.getNumberOfExternalNodes() != 1 ) {
4050                 return false;
4051             }
4052             s = w.toNewHampshire( t11, false ).toString();
4053             if ( !s.equals( "B;" ) ) {
4054                 return false;
4055             }
4056             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
4057             t12.deleteSubtree( t12.getNode( "B2" ), true );
4058             if ( t12.getNumberOfExternalNodes() != 8 ) {
4059                 return false;
4060             }
4061             s = w.toNewHampshire( t12, true ).toString();
4062             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
4063                 return false;
4064             }
4065             t12.deleteSubtree( t12.getNode( "B3" ), true );
4066             if ( t12.getNumberOfExternalNodes() != 7 ) {
4067                 return false;
4068             }
4069             s = w.toNewHampshire( t12, true ).toString();
4070             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
4071                 return false;
4072             }
4073             t12.deleteSubtree( t12.getNode( "C3" ), true );
4074             if ( t12.getNumberOfExternalNodes() != 6 ) {
4075                 return false;
4076             }
4077             s = w.toNewHampshire( t12, true ).toString();
4078             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
4079                 return false;
4080             }
4081             t12.deleteSubtree( t12.getNode( "A1" ), true );
4082             if ( t12.getNumberOfExternalNodes() != 5 ) {
4083                 return false;
4084             }
4085             s = w.toNewHampshire( t12, true ).toString();
4086             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
4087                 return false;
4088             }
4089             t12.deleteSubtree( t12.getNode( "B1" ), true );
4090             if ( t12.getNumberOfExternalNodes() != 4 ) {
4091                 return false;
4092             }
4093             s = w.toNewHampshire( t12, true ).toString();
4094             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
4095                 return false;
4096             }
4097             t12.deleteSubtree( t12.getNode( "A3" ), true );
4098             if ( t12.getNumberOfExternalNodes() != 3 ) {
4099                 return false;
4100             }
4101             s = w.toNewHampshire( t12, true ).toString();
4102             if ( !s.equals( "(A2,(C1,C2));" ) ) {
4103                 return false;
4104             }
4105             t12.deleteSubtree( t12.getNode( "A2" ), true );
4106             if ( t12.getNumberOfExternalNodes() != 2 ) {
4107                 return false;
4108             }
4109             s = w.toNewHampshire( t12, true ).toString();
4110             if ( !s.equals( "(C1,C2);" ) ) {
4111                 return false;
4112             }
4113             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
4114             t13.deleteSubtree( t13.getNode( "D" ), true );
4115             if ( t13.getNumberOfExternalNodes() != 4 ) {
4116                 return false;
4117             }
4118             s = w.toNewHampshire( t13, true ).toString();
4119             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
4120                 return false;
4121             }
4122             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
4123             t14.deleteSubtree( t14.getNode( "E" ), true );
4124             if ( t14.getNumberOfExternalNodes() != 5 ) {
4125                 return false;
4126             }
4127             s = w.toNewHampshire( t14, true ).toString();
4128             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
4129                 return false;
4130             }
4131             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
4132             t15.deleteSubtree( t15.getNode( "B2" ), true );
4133             if ( t15.getNumberOfExternalNodes() != 11 ) {
4134                 return false;
4135             }
4136             t15.deleteSubtree( t15.getNode( "B1" ), true );
4137             if ( t15.getNumberOfExternalNodes() != 10 ) {
4138                 return false;
4139             }
4140             t15.deleteSubtree( t15.getNode( "B3" ), true );
4141             if ( t15.getNumberOfExternalNodes() != 9 ) {
4142                 return false;
4143             }
4144             t15.deleteSubtree( t15.getNode( "B4" ), true );
4145             if ( t15.getNumberOfExternalNodes() != 8 ) {
4146                 return false;
4147             }
4148             t15.deleteSubtree( t15.getNode( "A1" ), true );
4149             if ( t15.getNumberOfExternalNodes() != 7 ) {
4150                 return false;
4151             }
4152             t15.deleteSubtree( t15.getNode( "C4" ), true );
4153             if ( t15.getNumberOfExternalNodes() != 6 ) {
4154                 return false;
4155             }
4156         }
4157         catch ( final Exception e ) {
4158             e.printStackTrace( System.out );
4159             return false;
4160         }
4161         return true;
4162     }
4163
4164     private static boolean testDescriptiveStatistics() {
4165         try {
4166             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
4167             dss1.addValue( 82 );
4168             dss1.addValue( 78 );
4169             dss1.addValue( 70 );
4170             dss1.addValue( 58 );
4171             dss1.addValue( 42 );
4172             if ( dss1.getN() != 5 ) {
4173                 return false;
4174             }
4175             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
4176                 return false;
4177             }
4178             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
4179                 return false;
4180             }
4181             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
4182                 return false;
4183             }
4184             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
4185                 return false;
4186             }
4187             if ( !Test.isEqual( dss1.median(), 70 ) ) {
4188                 return false;
4189             }
4190             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
4191                 return false;
4192             }
4193             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
4194                 return false;
4195             }
4196             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
4197                 return false;
4198             }
4199             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
4200                 return false;
4201             }
4202             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
4203                 return false;
4204             }
4205             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
4206                 return false;
4207             }
4208             dss1.addValue( 123 );
4209             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
4210                 return false;
4211             }
4212             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
4213                 return false;
4214             }
4215             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
4216                 return false;
4217             }
4218             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
4219             dss2.addValue( -1.85 );
4220             dss2.addValue( 57.5 );
4221             dss2.addValue( 92.78 );
4222             dss2.addValue( 57.78 );
4223             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
4224                 return false;
4225             }
4226             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
4227                 return false;
4228             }
4229             final double[] a = dss2.getDataAsDoubleArray();
4230             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
4231                 return false;
4232             }
4233             dss2.addValue( -100 );
4234             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
4235                 return false;
4236             }
4237             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
4238                 return false;
4239             }
4240             final double[] ds = new double[ 14 ];
4241             ds[ 0 ] = 34;
4242             ds[ 1 ] = 23;
4243             ds[ 2 ] = 1;
4244             ds[ 3 ] = 32;
4245             ds[ 4 ] = 11;
4246             ds[ 5 ] = 2;
4247             ds[ 6 ] = 12;
4248             ds[ 7 ] = 33;
4249             ds[ 8 ] = 13;
4250             ds[ 9 ] = 22;
4251             ds[ 10 ] = 21;
4252             ds[ 11 ] = 35;
4253             ds[ 12 ] = 24;
4254             ds[ 13 ] = 31;
4255             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
4256             if ( bins.length != 4 ) {
4257                 return false;
4258             }
4259             if ( bins[ 0 ] != 2 ) {
4260                 return false;
4261             }
4262             if ( bins[ 1 ] != 3 ) {
4263                 return false;
4264             }
4265             if ( bins[ 2 ] != 4 ) {
4266                 return false;
4267             }
4268             if ( bins[ 3 ] != 5 ) {
4269                 return false;
4270             }
4271             final double[] ds1 = new double[ 9 ];
4272             ds1[ 0 ] = 10.0;
4273             ds1[ 1 ] = 19.0;
4274             ds1[ 2 ] = 9.999;
4275             ds1[ 3 ] = 0.0;
4276             ds1[ 4 ] = 39.9;
4277             ds1[ 5 ] = 39.999;
4278             ds1[ 6 ] = 30.0;
4279             ds1[ 7 ] = 19.999;
4280             ds1[ 8 ] = 30.1;
4281             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
4282             if ( bins1.length != 4 ) {
4283                 return false;
4284             }
4285             if ( bins1[ 0 ] != 2 ) {
4286                 return false;
4287             }
4288             if ( bins1[ 1 ] != 3 ) {
4289                 return false;
4290             }
4291             if ( bins1[ 2 ] != 0 ) {
4292                 return false;
4293             }
4294             if ( bins1[ 3 ] != 4 ) {
4295                 return false;
4296             }
4297             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
4298             if ( bins1_1.length != 3 ) {
4299                 return false;
4300             }
4301             if ( bins1_1[ 0 ] != 3 ) {
4302                 return false;
4303             }
4304             if ( bins1_1[ 1 ] != 2 ) {
4305                 return false;
4306             }
4307             if ( bins1_1[ 2 ] != 4 ) {
4308                 return false;
4309             }
4310             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
4311             if ( bins1_2.length != 3 ) {
4312                 return false;
4313             }
4314             if ( bins1_2[ 0 ] != 2 ) {
4315                 return false;
4316             }
4317             if ( bins1_2[ 1 ] != 2 ) {
4318                 return false;
4319             }
4320             if ( bins1_2[ 2 ] != 2 ) {
4321                 return false;
4322             }
4323             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
4324             dss3.addValue( 1 );
4325             dss3.addValue( 1 );
4326             dss3.addValue( 1 );
4327             dss3.addValue( 2 );
4328             dss3.addValue( 3 );
4329             dss3.addValue( 4 );
4330             dss3.addValue( 5 );
4331             dss3.addValue( 5 );
4332             dss3.addValue( 5 );
4333             dss3.addValue( 6 );
4334             dss3.addValue( 7 );
4335             dss3.addValue( 8 );
4336             dss3.addValue( 9 );
4337             dss3.addValue( 10 );
4338             dss3.addValue( 10 );
4339             dss3.addValue( 10 );
4340             final AsciiHistogram histo = new AsciiHistogram( dss3 );
4341             histo.toStringBuffer( 10, '=', 40, 5 );
4342             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
4343         }
4344         catch ( final Exception e ) {
4345             e.printStackTrace( System.out );
4346             return false;
4347         }
4348         return true;
4349     }
4350
4351     private static boolean testDir( final String file ) {
4352         try {
4353             final File f = new File( file );
4354             if ( !f.exists() ) {
4355                 return false;
4356             }
4357             if ( !f.isDirectory() ) {
4358                 return false;
4359             }
4360             if ( !f.canRead() ) {
4361                 return false;
4362             }
4363         }
4364         catch ( final Exception e ) {
4365             return false;
4366         }
4367         return true;
4368     }
4369
4370     private static boolean testEbiEntryRetrieval() {
4371         try {
4372             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
4373             if ( !entry.getAccession().equals( "AAK41263" ) ) {
4374                 System.out.println( entry.getAccession() );
4375                 return false;
4376             }
4377             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
4378                 System.out.println( entry.getTaxonomyScientificName() );
4379                 return false;
4380             }
4381             if ( !entry.getSequenceName()
4382                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4383                 System.out.println( entry.getSequenceName() );
4384                 return false;
4385             }
4386             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4387                 System.out.println( entry.getGeneName() );
4388                 return false;
4389             }
4390             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4391                 System.out.println( entry.getTaxonomyIdentifier() );
4392                 return false;
4393             }
4394             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4395                 System.out.println( entry.getAnnotations().first().getRefValue() );
4396                 return false;
4397             }
4398             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4399                 System.out.println( entry.getAnnotations().first().getRefSource() );
4400                 return false;
4401             }
4402             if ( entry.getCrossReferences().size() < 1 ) {
4403                 return false;
4404             }
4405             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4406             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4407                 return false;
4408             }
4409             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4410                 System.out.println( entry1.getTaxonomyScientificName() );
4411                 return false;
4412             }
4413             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4414                 System.out.println( entry1.getSequenceName() );
4415                 return false;
4416             }
4417             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4418                 System.out.println( entry1.getTaxonomyIdentifier() );
4419                 return false;
4420             }
4421             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4422                 System.out.println( entry1.getGeneName() );
4423                 return false;
4424             }
4425             if ( entry1.getCrossReferences().size() < 1 ) {
4426                 return false;
4427             }
4428             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4429             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4430                 return false;
4431             }
4432             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4433                 System.out.println( entry2.getTaxonomyScientificName() );
4434                 return false;
4435             }
4436             if ( !entry2.getSequenceName()
4437                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4438                 System.out.println( entry2.getSequenceName() );
4439                 return false;
4440             }
4441             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4442                 System.out.println( entry2.getTaxonomyIdentifier() );
4443                 return false;
4444             }
4445             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4446                 System.out.println( entry2.getGeneName() );
4447                 return false;
4448             }
4449             if ( entry2.getCrossReferences().size() < 1 ) {
4450                 return false;
4451             }
4452             if ( !entry2.getChromosome().equals( "20" ) ) {
4453                 return false;
4454             }
4455             if ( !entry2.getMap().equals( "20q11.22" ) ) {
4456                 return false;
4457             }
4458             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4459             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4460                 return false;
4461             }
4462             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4463                 System.out.println( entry3.getTaxonomyScientificName() );
4464                 return false;
4465             }
4466             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4467                 System.out.println( entry3.getSequenceName() );
4468                 return false;
4469             }
4470             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4471                 System.out.println( entry3.getTaxonomyIdentifier() );
4472                 return false;
4473             }
4474             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4475                 System.out.println( entry3.getSequenceSymbol() );
4476                 return false;
4477             }
4478             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4479                 return false;
4480             }
4481             if ( entry3.getCrossReferences().size() < 1 ) {
4482                 return false;
4483             }
4484             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4485             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4486                 return false;
4487             }
4488             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4489                 System.out.println( entry4.getTaxonomyScientificName() );
4490                 return false;
4491             }
4492             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4493                 System.out.println( entry4.getSequenceName() );
4494                 return false;
4495             }
4496             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4497                 System.out.println( entry4.getTaxonomyIdentifier() );
4498                 return false;
4499             }
4500             if ( !entry4.getGeneName().equals( "ras" ) ) {
4501                 System.out.println( entry4.getGeneName() );
4502                 return false;
4503             }
4504             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4505             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4506                 return false;
4507             }
4508             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4509                 System.out.println( entry5.getTaxonomyScientificName() );
4510                 return false;
4511             }
4512             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4513                 System.out.println( entry5.getSequenceName() );
4514                 return false;
4515             }
4516             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4517                 System.out.println( entry5.getTaxonomyIdentifier() );
4518                 return false;
4519             }
4520             final SequenceDatabaseEntry entry6 = SequenceDbWsTools.obtainEntry( "M30539" );
4521             if ( !entry6.getAccession().equals( "M30539" ) ) {
4522                 return false;
4523             }
4524             if ( !entry6.getGeneName().equals( "ras" ) ) {
4525                 return false;
4526             }
4527             if ( !entry6.getSequenceName().equals( "Human SK2 c-Ha-ras-1 oncogene-encoded protein gene, exon 1" ) ) {
4528                 return false;
4529             }
4530             if ( !entry6.getTaxonomyIdentifier().equals( "9606" ) ) {
4531                 return false;
4532             }
4533             if ( !entry6.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4534                 return false;
4535             }
4536             if ( entry6.getCrossReferences().size() < 1 ) {
4537                 return false;
4538             }
4539         }
4540         catch ( final IOException e ) {
4541             System.out.println();
4542             System.out.println( "the following might be due to absence internet connection:" );
4543             e.printStackTrace( System.out );
4544             return true;
4545         }
4546         catch ( final Exception e ) {
4547             e.printStackTrace();
4548             return false;
4549         }
4550         return true;
4551     }
4552
4553     private static boolean testExternalNodeRelatedMethods() {
4554         try {
4555             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4556             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4557             PhylogenyNode n = t1.getNode( "A" );
4558             n = n.getNextExternalNode();
4559             if ( !n.getName().equals( "B" ) ) {
4560                 return false;
4561             }
4562             n = n.getNextExternalNode();
4563             if ( !n.getName().equals( "C" ) ) {
4564                 return false;
4565             }
4566             n = n.getNextExternalNode();
4567             if ( !n.getName().equals( "D" ) ) {
4568                 return false;
4569             }
4570             n = t1.getNode( "B" );
4571             while ( !n.isLastExternalNode() ) {
4572                 n = n.getNextExternalNode();
4573             }
4574             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4575             n = t2.getNode( "A" );
4576             n = n.getNextExternalNode();
4577             if ( !n.getName().equals( "B" ) ) {
4578                 return false;
4579             }
4580             n = n.getNextExternalNode();
4581             if ( !n.getName().equals( "C" ) ) {
4582                 return false;
4583             }
4584             n = n.getNextExternalNode();
4585             if ( !n.getName().equals( "D" ) ) {
4586                 return false;
4587             }
4588             n = t2.getNode( "B" );
4589             while ( !n.isLastExternalNode() ) {
4590                 n = n.getNextExternalNode();
4591             }
4592             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4593             n = t3.getNode( "A" );
4594             n = n.getNextExternalNode();
4595             if ( !n.getName().equals( "B" ) ) {
4596                 return false;
4597             }
4598             n = n.getNextExternalNode();
4599             if ( !n.getName().equals( "C" ) ) {
4600                 return false;
4601             }
4602             n = n.getNextExternalNode();
4603             if ( !n.getName().equals( "D" ) ) {
4604                 return false;
4605             }
4606             n = n.getNextExternalNode();
4607             if ( !n.getName().equals( "E" ) ) {
4608                 return false;
4609             }
4610             n = n.getNextExternalNode();
4611             if ( !n.getName().equals( "F" ) ) {
4612                 return false;
4613             }
4614             n = n.getNextExternalNode();
4615             if ( !n.getName().equals( "G" ) ) {
4616                 return false;
4617             }
4618             n = n.getNextExternalNode();
4619             if ( !n.getName().equals( "H" ) ) {
4620                 return false;
4621             }
4622             n = t3.getNode( "B" );
4623             while ( !n.isLastExternalNode() ) {
4624                 n = n.getNextExternalNode();
4625             }
4626             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4627             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4628                 final PhylogenyNode node = iter.next();
4629             }
4630             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4631             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4632                 final PhylogenyNode node = iter.next();
4633             }
4634             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4635             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4636             if ( !iter.next().getName().equals( "A" ) ) {
4637                 return false;
4638             }
4639             if ( !iter.next().getName().equals( "B" ) ) {
4640                 return false;
4641             }
4642             if ( !iter.next().getName().equals( "C" ) ) {
4643                 return false;
4644             }
4645             if ( !iter.next().getName().equals( "D" ) ) {
4646                 return false;
4647             }
4648             if ( !iter.next().getName().equals( "E" ) ) {
4649                 return false;
4650             }
4651             if ( !iter.next().getName().equals( "F" ) ) {
4652                 return false;
4653             }
4654             if ( iter.hasNext() ) {
4655                 return false;
4656             }
4657         }
4658         catch ( final Exception e ) {
4659             e.printStackTrace( System.out );
4660             return false;
4661         }
4662         return true;
4663     }
4664
4665     private static boolean testExtractSNFromNodeName() {
4666         try {
4667             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4668                 return false;
4669             }
4670             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4671                 return false;
4672             }
4673             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4674                 return false;
4675             }
4676             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4677                     .equals( "Mus musculus musculus" ) ) {
4678                 return false;
4679             }
4680             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4681                     .equals( "Mus musculus musculus" ) ) {
4682                 return false;
4683             }
4684             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4685                     .equals( "Mus musculus musculus" ) ) {
4686                 return false;
4687             }
4688             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4689                     .equals( "Mus musculus musculus" ) ) {
4690                 return false;
4691             }
4692             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4693                 return false;
4694             }
4695             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4696                     .equals( "Mus musculus musculus" ) ) {
4697                 return false;
4698             }
4699             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4700                     .equals( "Mus musculus musculus" ) ) {
4701                 return false;
4702             }
4703             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4704                 return false;
4705             }
4706             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4707                 return false;
4708             }
4709             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4710                 return false;
4711             }
4712             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4713                 return false;
4714             }
4715             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4716                     .equals( "Mus musculus musculus" ) ) {
4717                 return false;
4718             }
4719             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4720                 return false;
4721             }
4722             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4723                 return false;
4724             }
4725             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4726                 return false;
4727             }
4728             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4729                 return false;
4730             }
4731             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4732                 return false;
4733             }
4734             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4735                 return false;
4736             }
4737             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4738                 return false;
4739             }
4740             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4741                 return false;
4742             }
4743             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4744                     .equals( "Mus musculus" ) ) {
4745                 return false;
4746             }
4747             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4748                     .equals( "Mus musculus" ) ) {
4749                 return false;
4750             }
4751             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4752                 return false;
4753             }
4754             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4755                     .equals( "Mus musculus musculus" ) ) {
4756                 return false;
4757             }
4758             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4759                     .equals( "Mus musculus musculus" ) ) {
4760                 return false;
4761             }
4762             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4763                     .equals( "Mus musculus musculus" ) ) {
4764                 return false;
4765             }
4766             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4767                 return false;
4768             }
4769             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4770                     .equals( "Pilostyles mexicana" ) ) {
4771                 return false;
4772             }
4773             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4774                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4775                 return false;
4776             }
4777             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4778                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4779                 return false;
4780             }
4781             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4782                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4783                 return false;
4784             }
4785             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4786                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4787                 return false;
4788             }
4789             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4790                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4791                 return false;
4792             }
4793             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4794                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4795                 return false;
4796             }
4797             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4798                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4799                 return false;
4800             }
4801             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4802                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4803                 return false;
4804             }
4805             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4806                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4807                 return false;
4808             }
4809             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4810                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4811                 return false;
4812             }
4813             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4814                     .equals( "Escherichia coli (strain K12)" ) ) {
4815                 return false;
4816             }
4817             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4818                     .equals( "Escherichia coli (strain K12)" ) ) {
4819                 return false;
4820             }
4821             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4822                     .equals( "Escherichia coli (str. K12)" ) ) {
4823                 return false;
4824             }
4825             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4826                     .equals( "Escherichia coli (str. K12)" ) ) {
4827                 return false;
4828             }
4829             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4830                     .equals( "Escherichia coli (str. K12)" ) ) {
4831                 return false;
4832             }
4833             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4834                     .equals( "Escherichia coli (var. K12)" ) ) {
4835                 return false;
4836             }
4837             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4838                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4839                 return false;
4840             }
4841             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4842                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4843                 return false;
4844             }
4845             if ( !ParserUtils
4846                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4847                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4848                 return false;
4849             }
4850             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4851                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4852                 return false;
4853             }
4854             if ( !ParserUtils
4855                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4856                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4857                 return false;
4858             }
4859             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4860                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4861                 return false;
4862             }
4863             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4864                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4865                 return false;
4866             }
4867             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4868                 return false;
4869             }
4870             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4871                 return false;
4872             }
4873             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4874                 return false;
4875             }
4876             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4877                     .equals( "Macrocera sp." ) ) {
4878                 return false;
4879             }
4880             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4881                 return false;
4882             }
4883             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4884                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4885                 return false;
4886             }
4887             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4888                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4889                 return false;
4890             }
4891             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4892                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4893                 return false;
4894             }
4895             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4896                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4897                 return false;
4898             }
4899         }
4900         catch ( final Exception e ) {
4901             e.printStackTrace( System.out );
4902             return false;
4903         }
4904         return true;
4905     }
4906
4907     private static boolean testExtractTaxonomyDataFromNodeName() {
4908         try {
4909             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
4910             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4911                 return false;
4912             }
4913             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
4914             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4915                 return false;
4916             }
4917             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
4918             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4919                 return false;
4920             }
4921             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
4922             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4923                 return false;
4924             }
4925             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
4926             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4927                 return false;
4928             }
4929             n = new PhylogenyNode( "HNRPR_HUMAN" );
4930             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4931                 return false;
4932             }
4933             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
4934             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4935                 return false;
4936             }
4937         }
4938         catch ( final Exception e ) {
4939             e.printStackTrace( System.out );
4940             return false;
4941         }
4942         return true;
4943     }
4944
4945     private static boolean testExtractTaxonomyCodeFromNodeName() {
4946         try {
4947             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4948                 return false;
4949             }
4950             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4951                     .equals( "SOYBN" ) ) {
4952                 return false;
4953             }
4954             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4955                     .equals( "ARATH" ) ) {
4956                 return false;
4957             }
4958             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4959                     .equals( "ARATH" ) ) {
4960                 return false;
4961             }
4962             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4963                 return false;
4964             }
4965             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4966                 return false;
4967             }
4968             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4969                 return false;
4970             }
4971             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4972                     .equals( "SOYBN" ) ) {
4973                 return false;
4974             }
4975             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4976                     .equals( "SOYBN" ) ) {
4977                 return false;
4978             }
4979             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4980                     .equals( "SOYBN" ) ) {
4981                 return false;
4982             }
4983             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4984                     .equals( "SOYBN" ) ) {
4985                 return false;
4986             }
4987             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4988                     .equals( "SOYBN" ) ) {
4989                 return false;
4990             }
4991             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4992                     .equals( "SOYBN" ) ) {
4993                 return false;
4994             }
4995             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4996                     .equals( "SOYBN" ) ) {
4997                 return false;
4998             }
4999             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
5000                     .equals( "SOYBN" ) ) {
5001                 return false;
5002             }
5003             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
5004                 return false;
5005             }
5006             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
5007                     .equals( "SOYBN" ) ) {
5008                 return false;
5009             }
5010             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
5011                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
5012                 return false;
5013             }
5014             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
5015                     .equals( "9YX45" ) ) {
5016                 return false;
5017             }
5018             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
5019                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5020                                                                .equals( "MOUSE" ) ) {
5021                 return false;
5022             }
5023             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
5024                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5025                                                                .equals( "MOUSE" ) ) {
5026                 return false;
5027             }
5028             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
5029                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5030                                                                .equals( "MOUSE" ) ) {
5031                 return false;
5032             }
5033             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
5034                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5035                 return false;
5036             }
5037             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
5038                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5039                 return false;
5040             }
5041             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5042                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
5043                 return false;
5044             }
5045             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
5046                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
5047                 return false;
5048             }
5049             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
5050                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
5051                 return false;
5052             }
5053             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
5054                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5055                 return false;
5056             }
5057             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
5058                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5059                 return false;
5060             }
5061             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5062                     .equals( "RAT" ) ) {
5063                 return false;
5064             }
5065             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5066                     .equals( "PIG" ) ) {
5067                 return false;
5068             }
5069             if ( !ParserUtils
5070                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
5071                     .equals( "MOUSE" ) ) {
5072                 return false;
5073             }
5074             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
5075                     .equals( "MOUSE" ) ) {
5076                 return false;
5077             }
5078             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
5079                 return false;
5080             }
5081         }
5082         catch ( final Exception e ) {
5083             e.printStackTrace( System.out );
5084             return false;
5085         }
5086         return true;
5087     }
5088
5089     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
5090         try {
5091             PhylogenyNode n = new PhylogenyNode();
5092             n.setName( "tr|B3RJ64" );
5093             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5094                 return false;
5095             }
5096             n.setName( "tr.B3RJ64" );
5097             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5098                 return false;
5099             }
5100             n.setName( "tr=B3RJ64" );
5101             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5102                 return false;
5103             }
5104             n.setName( "tr-B3RJ64" );
5105             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5106                 return false;
5107             }
5108             n.setName( "tr/B3RJ64" );
5109             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5110                 return false;
5111             }
5112             n.setName( "tr\\B3RJ64" );
5113             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5114                 return false;
5115             }
5116             n.setName( "tr_B3RJ64" );
5117             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5118                 return false;
5119             }
5120             n.setName( " tr|B3RJ64 " );
5121             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5122                 return false;
5123             }
5124             n.setName( "-tr|B3RJ64-" );
5125             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5126                 return false;
5127             }
5128             n.setName( "-tr=B3RJ64-" );
5129             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5130                 return false;
5131             }
5132             n.setName( "_tr=B3RJ64_" );
5133             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5134                 return false;
5135             }
5136             n.setName( " tr_tr|B3RJ64_sp|123 " );
5137             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5138                 return false;
5139             }
5140             n.setName( "B3RJ64" );
5141             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5142                 return false;
5143             }
5144             n.setName( "sp|B3RJ64" );
5145             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5146                 return false;
5147             }
5148             n.setName( "sp|B3RJ64C" );
5149             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5150                 return false;
5151             }
5152             n.setName( "sp B3RJ64" );
5153             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5154                 return false;
5155             }
5156             n.setName( "sp|B3RJ6X" );
5157             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5158                 return false;
5159             }
5160             n.setName( "sp|B3RJ6" );
5161             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5162                 return false;
5163             }
5164             n.setName( "K1PYK7_CRAGI" );
5165             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5166                 return false;
5167             }
5168             n.setName( "K1PYK7_PEA" );
5169             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
5170                 return false;
5171             }
5172             n.setName( "K1PYK7_RAT" );
5173             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
5174                 return false;
5175             }
5176             n.setName( "K1PYK7_PIG" );
5177             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5178                 return false;
5179             }
5180             n.setName( "~K1PYK7_PIG~" );
5181             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
5182                 return false;
5183             }
5184             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
5185             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5186                 return false;
5187             }
5188             n.setName( "K1PYKX_CRAGI" );
5189             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5190                 return false;
5191             }
5192             n.setName( "XXXXX_CRAGI" );
5193             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
5194                 return false;
5195             }
5196             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
5197             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
5198                 return false;
5199             }
5200             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
5201             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
5202                 return false;
5203             }
5204             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
5205             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
5206                 return false;
5207             }
5208             n = new PhylogenyNode();
5209             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
5210             seq.setSymbol( "K1PYK7_CRAGI" );
5211             n.getNodeData().addSequence( seq );
5212             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5213                 return false;
5214             }
5215             seq.setSymbol( "tr|B3RJ64" );
5216             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5217                 return false;
5218             }
5219             n = new PhylogenyNode();
5220             seq = new org.forester.phylogeny.data.Sequence();
5221             seq.setName( "K1PYK7_CRAGI" );
5222             n.getNodeData().addSequence( seq );
5223             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
5224                 return false;
5225             }
5226             seq.setName( "tr|B3RJ64" );
5227             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5228                 return false;
5229             }
5230             n = new PhylogenyNode();
5231             seq = new org.forester.phylogeny.data.Sequence();
5232             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
5233             n.getNodeData().addSequence( seq );
5234             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
5235                 return false;
5236             }
5237             n = new PhylogenyNode();
5238             seq = new org.forester.phylogeny.data.Sequence();
5239             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
5240             n.getNodeData().addSequence( seq );
5241             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
5242                 return false;
5243             }
5244             //
5245             n = new PhylogenyNode();
5246             n.setName( "ACP19736" );
5247             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5248                 return false;
5249             }
5250             n = new PhylogenyNode();
5251             n.setName( "|ACP19736|" );
5252             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
5253                 return false;
5254             }
5255         }
5256         catch ( final Exception e ) {
5257             e.printStackTrace( System.out );
5258             return false;
5259         }
5260         return true;
5261     }
5262
5263     private static boolean testFastaParser() {
5264         try {
5265             FileInputStream fis1 = new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" );
5266             if ( !FastaParser.isLikelyFasta( fis1 ) ) {
5267                 fis1.close();
5268                 return false;
5269             }
5270             else {
5271                 fis1.close();
5272             }
5273             FileInputStream fis2 = new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" );
5274             if ( FastaParser.isLikelyFasta( fis2 ) ) {
5275                 fis2.close();
5276                 return false;
5277             }
5278             else {
5279                 fis2.close();
5280             }
5281             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
5282             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
5283                 return false;
5284             }
5285             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
5286                 return false;
5287             }
5288             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
5289                 return false;
5290             }
5291             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
5292                 return false;
5293             }
5294             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
5295                 return false;
5296             }
5297             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
5298                 return false;
5299             }
5300         }
5301         catch ( final Exception e ) {
5302             e.printStackTrace();
5303             return false;
5304         }
5305         return true;
5306     }
5307
5308     private static boolean testGenbankAccessorParsing() {
5309         //The format for GenBank Accession numbers are:
5310         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
5311         //Protein:    3 letters + 5 numerals
5312         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
5313         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
5314             return false;
5315         }
5316         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
5317             return false;
5318         }
5319         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
5320             return false;
5321         }
5322         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
5323             return false;
5324         }
5325         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
5326             return false;
5327         }
5328         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
5329             return false;
5330         }
5331         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
5332             return false;
5333         }
5334         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
5335             return false;
5336         }
5337         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
5338             return false;
5339         }
5340         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
5341             return false;
5342         }
5343         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
5344             return false;
5345         }
5346         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
5347             return false;
5348         }
5349         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
5350             return false;
5351         }
5352         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
5353             return false;
5354         }
5355         return true;
5356     }
5357
5358     private static boolean testGeneralMsaParser() {
5359         try {
5360             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
5361             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
5362             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
5363             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
5364             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
5365             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
5366             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
5367             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
5368             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5369                 return false;
5370             }
5371             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5372                 return false;
5373             }
5374             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5375                 return false;
5376             }
5377             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5378                 return false;
5379             }
5380             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5381                 return false;
5382             }
5383             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5384                 return false;
5385             }
5386             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5387                 return false;
5388             }
5389             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5390                 return false;
5391             }
5392             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5393                 return false;
5394             }
5395             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5396                 return false;
5397             }
5398             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5399                 return false;
5400             }
5401             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5402                 return false;
5403             }
5404             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5405             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5406                 return false;
5407             }
5408             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5409                 return false;
5410             }
5411             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5412                 return false;
5413             }
5414             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5415             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5416                 return false;
5417             }
5418             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5419                 return false;
5420             }
5421             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5422                 return false;
5423             }
5424             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5425             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5426                 return false;
5427             }
5428             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5429                 return false;
5430             }
5431             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5432                 return false;
5433             }
5434         }
5435         catch ( final Exception e ) {
5436             e.printStackTrace();
5437             return false;
5438         }
5439         return true;
5440     }
5441
5442     private static boolean testGeneralTable() {
5443         try {
5444             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5445             t0.setValue( 3, 2, "23" );
5446             t0.setValue( 10, 1, "error" );
5447             t0.setValue( 10, 1, "110" );
5448             t0.setValue( 9, 1, "19" );
5449             t0.setValue( 1, 10, "101" );
5450             t0.setValue( 10, 10, "1010" );
5451             t0.setValue( 100, 10, "10100" );
5452             t0.setValue( 0, 0, "00" );
5453             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5454                 return false;
5455             }
5456             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5457                 return false;
5458             }
5459             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5460                 return false;
5461             }
5462             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5463                 return false;
5464             }
5465             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5466                 return false;
5467             }
5468             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5469                 return false;
5470             }
5471             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5472                 return false;
5473             }
5474             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5475                 return false;
5476             }
5477             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5478                 return false;
5479             }
5480             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5481             t1.setValue( "3", "2", "23" );
5482             t1.setValue( "10", "1", "error" );
5483             t1.setValue( "10", "1", "110" );
5484             t1.setValue( "9", "1", "19" );
5485             t1.setValue( "1", "10", "101" );
5486             t1.setValue( "10", "10", "1010" );
5487             t1.setValue( "100", "10", "10100" );
5488             t1.setValue( "0", "0", "00" );
5489             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5490             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5491                 return false;
5492             }
5493             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5494                 return false;
5495             }
5496             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5497                 return false;
5498             }
5499             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5500                 return false;
5501             }
5502             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5503                 return false;
5504             }
5505             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5506                 return false;
5507             }
5508             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5509                 return false;
5510             }
5511             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5512                 return false;
5513             }
5514             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5515                 return false;
5516             }
5517             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5518                 return false;
5519             }
5520         }
5521         catch ( final Exception e ) {
5522             e.printStackTrace( System.out );
5523             return false;
5524         }
5525         return true;
5526     }
5527
5528     private static boolean testGetDistance() {
5529         try {
5530             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5531             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",
5532                                                  new NHXParser() )[ 0 ];
5533             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5534                 return false;
5535             }
5536             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5537                 return false;
5538             }
5539             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5540                 return false;
5541             }
5542             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5543                 return false;
5544             }
5545             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5546                 return false;
5547             }
5548             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5549                 return false;
5550             }
5551             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5552                 return false;
5553             }
5554             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5555                 return false;
5556             }
5557             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5558                 return false;
5559             }
5560             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5561                 return false;
5562             }
5563             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5564                 return false;
5565             }
5566             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5567                 return false;
5568             }
5569             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5570                 return false;
5571             }
5572             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5573                 return false;
5574             }
5575             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5576                 return false;
5577             }
5578             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5579                 return false;
5580             }
5581             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5582                 return false;
5583             }
5584             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5585                 return false;
5586             }
5587             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5588                 return false;
5589             }
5590             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5591                 return false;
5592             }
5593             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5594                 return false;
5595             }
5596             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5597                 return false;
5598             }
5599             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5600                 return false;
5601             }
5602             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5603                 return false;
5604             }
5605             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5606                 return false;
5607             }
5608             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5609                 return false;
5610             }
5611             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5612                 return false;
5613             }
5614             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5615                 return false;
5616             }
5617             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5618                 return false;
5619             }
5620             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5621                 return false;
5622             }
5623             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5624                 return false;
5625             }
5626             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",
5627                                                  new NHXParser() )[ 0 ];
5628             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5629                 return false;
5630             }
5631             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5632                 return false;
5633             }
5634             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5635                 return false;
5636             }
5637             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5638                 return false;
5639             }
5640             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5641                 return false;
5642             }
5643             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5644                 return false;
5645             }
5646             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5647                 return false;
5648             }
5649             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5650                 return false;
5651             }
5652             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5653                 return false;
5654             }
5655             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5656                 return false;
5657             }
5658             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5659                 return false;
5660             }
5661         }
5662         catch ( final Exception e ) {
5663             e.printStackTrace( System.out );
5664             return false;
5665         }
5666         return true;
5667     }
5668
5669     private static boolean testGetLCA() {
5670         try {
5671             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5672             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5673                                                  new NHXParser() )[ 0 ];
5674             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5675             if ( !A.getName().equals( "A" ) ) {
5676                 return false;
5677             }
5678             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5679             if ( !gh.getName().equals( "gh" ) ) {
5680                 return false;
5681             }
5682             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5683             if ( !ab.getName().equals( "ab" ) ) {
5684                 return false;
5685             }
5686             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5687             if ( !ab2.getName().equals( "ab" ) ) {
5688                 return false;
5689             }
5690             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5691             if ( !gh2.getName().equals( "gh" ) ) {
5692                 return false;
5693             }
5694             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5695             if ( !gh3.getName().equals( "gh" ) ) {
5696                 return false;
5697             }
5698             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5699             if ( !abc.getName().equals( "abc" ) ) {
5700                 return false;
5701             }
5702             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5703             if ( !abc2.getName().equals( "abc" ) ) {
5704                 return false;
5705             }
5706             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5707             if ( !abcd.getName().equals( "abcd" ) ) {
5708                 return false;
5709             }
5710             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5711             if ( !abcd2.getName().equals( "abcd" ) ) {
5712                 return false;
5713             }
5714             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5715             if ( !abcdef.getName().equals( "abcdef" ) ) {
5716                 return false;
5717             }
5718             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5719             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5720                 return false;
5721             }
5722             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5723             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5724                 return false;
5725             }
5726             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5727             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5728                 return false;
5729             }
5730             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5731             if ( !abcde.getName().equals( "abcde" ) ) {
5732                 return false;
5733             }
5734             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5735             if ( !abcde2.getName().equals( "abcde" ) ) {
5736                 return false;
5737             }
5738             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5739             if ( !r.getName().equals( "abcdefgh" ) ) {
5740                 return false;
5741             }
5742             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5743             if ( !r2.getName().equals( "abcdefgh" ) ) {
5744                 return false;
5745             }
5746             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5747             if ( !r3.getName().equals( "abcdefgh" ) ) {
5748                 return false;
5749             }
5750             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5751             if ( !abcde3.getName().equals( "abcde" ) ) {
5752                 return false;
5753             }
5754             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5755             if ( !abcde4.getName().equals( "abcde" ) ) {
5756                 return false;
5757             }
5758             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5759             if ( !ab3.getName().equals( "ab" ) ) {
5760                 return false;
5761             }
5762             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5763             if ( !ab4.getName().equals( "ab" ) ) {
5764                 return false;
5765             }
5766             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5767             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5768             if ( !cd.getName().equals( "cd" ) ) {
5769                 return false;
5770             }
5771             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5772             if ( !cd2.getName().equals( "cd" ) ) {
5773                 return false;
5774             }
5775             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5776             if ( !cde.getName().equals( "cde" ) ) {
5777                 return false;
5778             }
5779             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5780             if ( !cde2.getName().equals( "cde" ) ) {
5781                 return false;
5782             }
5783             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5784             if ( !cdef.getName().equals( "cdef" ) ) {
5785                 return false;
5786             }
5787             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5788             if ( !cdef2.getName().equals( "cdef" ) ) {
5789                 return false;
5790             }
5791             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5792             if ( !cdef3.getName().equals( "cdef" ) ) {
5793                 return false;
5794             }
5795             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5796             if ( !rt.getName().equals( "r" ) ) {
5797                 return false;
5798             }
5799             final Phylogeny p3 = factory
5800                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5801                              new NHXParser() )[ 0 ];
5802             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5803             if ( !bc_3.getName().equals( "bc" ) ) {
5804                 return false;
5805             }
5806             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5807             if ( !ac_3.getName().equals( "abc" ) ) {
5808                 return false;
5809             }
5810             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5811             if ( !ad_3.getName().equals( "abcde" ) ) {
5812                 return false;
5813             }
5814             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5815             if ( !af_3.getName().equals( "abcdef" ) ) {
5816                 return false;
5817             }
5818             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5819             if ( !ag_3.getName().equals( "" ) ) {
5820                 return false;
5821             }
5822             if ( !ag_3.isRoot() ) {
5823                 return false;
5824             }
5825             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5826             if ( !al_3.getName().equals( "" ) ) {
5827                 return false;
5828             }
5829             if ( !al_3.isRoot() ) {
5830                 return false;
5831             }
5832             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5833             if ( !kl_3.getName().equals( "" ) ) {
5834                 return false;
5835             }
5836             if ( !kl_3.isRoot() ) {
5837                 return false;
5838             }
5839             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5840             if ( !fl_3.getName().equals( "" ) ) {
5841                 return false;
5842             }
5843             if ( !fl_3.isRoot() ) {
5844                 return false;
5845             }
5846             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5847             if ( !gk_3.getName().equals( "ghijk" ) ) {
5848                 return false;
5849             }
5850             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5851             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5852             if ( !r_4.getName().equals( "r" ) ) {
5853                 return false;
5854             }
5855             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5856             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5857             if ( !r_5.getName().equals( "root" ) ) {
5858                 return false;
5859             }
5860             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5861             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5862             if ( !r_6.getName().equals( "rot" ) ) {
5863                 return false;
5864             }
5865             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5866             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5867             if ( !r_7.getName().equals( "rott" ) ) {
5868                 return false;
5869             }
5870         }
5871         catch ( final Exception e ) {
5872             e.printStackTrace( System.out );
5873             return false;
5874         }
5875         return true;
5876     }
5877
5878     private static boolean testGetLCA2() {
5879         try {
5880             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5881             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5882             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5883             PhylogenyMethods.preOrderReId( p_a );
5884             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5885                                                                                               p_a.getNode( "a" ) );
5886             if ( !p_a_1.getName().equals( "a" ) ) {
5887                 return false;
5888             }
5889             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5890             PhylogenyMethods.preOrderReId( p_b );
5891             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5892                                                                                               p_b.getNode( "a" ) );
5893             if ( !p_b_1.getName().equals( "b" ) ) {
5894                 return false;
5895             }
5896             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5897                                                                                               p_b.getNode( "b" ) );
5898             if ( !p_b_2.getName().equals( "b" ) ) {
5899                 return false;
5900             }
5901             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5902             PhylogenyMethods.preOrderReId( p_c );
5903             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5904                                                                                               p_c.getNode( "a" ) );
5905             if ( !p_c_1.getName().equals( "b" ) ) {
5906                 return false;
5907             }
5908             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5909                                                                                               p_c.getNode( "c" ) );
5910             if ( !p_c_2.getName().equals( "c" ) ) {
5911                 System.out.println( p_c_2.getName() );
5912                 System.exit( -1 );
5913                 return false;
5914             }
5915             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5916                                                                                               p_c.getNode( "b" ) );
5917             if ( !p_c_3.getName().equals( "b" ) ) {
5918                 return false;
5919             }
5920             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5921                                                                                               p_c.getNode( "a" ) );
5922             if ( !p_c_4.getName().equals( "c" ) ) {
5923                 return false;
5924             }
5925             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5926                                                  new NHXParser() )[ 0 ];
5927             PhylogenyMethods.preOrderReId( p1 );
5928             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5929                                                                                           p1.getNode( "A" ) );
5930             if ( !A.getName().equals( "A" ) ) {
5931                 return false;
5932             }
5933             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5934                                                                                            p1.getNode( "gh" ) );
5935             if ( !gh.getName().equals( "gh" ) ) {
5936                 return false;
5937             }
5938             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5939                                                                                            p1.getNode( "B" ) );
5940             if ( !ab.getName().equals( "ab" ) ) {
5941                 return false;
5942             }
5943             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5944                                                                                             p1.getNode( "A" ) );
5945             if ( !ab2.getName().equals( "ab" ) ) {
5946                 return false;
5947             }
5948             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5949                                                                                             p1.getNode( "G" ) );
5950             if ( !gh2.getName().equals( "gh" ) ) {
5951                 return false;
5952             }
5953             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5954                                                                                             p1.getNode( "H" ) );
5955             if ( !gh3.getName().equals( "gh" ) ) {
5956                 return false;
5957             }
5958             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5959                                                                                             p1.getNode( "A" ) );
5960             if ( !abc.getName().equals( "abc" ) ) {
5961                 return false;
5962             }
5963             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5964                                                                                              p1.getNode( "C" ) );
5965             if ( !abc2.getName().equals( "abc" ) ) {
5966                 return false;
5967             }
5968             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5969                                                                                              p1.getNode( "D" ) );
5970             if ( !abcd.getName().equals( "abcd" ) ) {
5971                 return false;
5972             }
5973             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5974                                                                                               p1.getNode( "A" ) );
5975             if ( !abcd2.getName().equals( "abcd" ) ) {
5976                 return false;
5977             }
5978             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5979                                                                                                p1.getNode( "F" ) );
5980             if ( !abcdef.getName().equals( "abcdef" ) ) {
5981                 return false;
5982             }
5983             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5984                                                                                                 p1.getNode( "A" ) );
5985             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5986                 return false;
5987             }
5988             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5989                                                                                                 p1.getNode( "F" ) );
5990             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5991                 return false;
5992             }
5993             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5994                                                                                                 p1.getNode( "ab" ) );
5995             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5996                 return false;
5997             }
5998             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5999                                                                                               p1.getNode( "E" ) );
6000             if ( !abcde.getName().equals( "abcde" ) ) {
6001                 return false;
6002             }
6003             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6004                                                                                                p1.getNode( "A" ) );
6005             if ( !abcde2.getName().equals( "abcde" ) ) {
6006                 return false;
6007             }
6008             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
6009                                                                                           p1.getNode( "abcdefgh" ) );
6010             if ( !r.getName().equals( "abcdefgh" ) ) {
6011                 return false;
6012             }
6013             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
6014                                                                                            p1.getNode( "H" ) );
6015             if ( !r2.getName().equals( "abcdefgh" ) ) {
6016                 return false;
6017             }
6018             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
6019                                                                                            p1.getNode( "A" ) );
6020             if ( !r3.getName().equals( "abcdefgh" ) ) {
6021                 return false;
6022             }
6023             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
6024                                                                                                p1.getNode( "abcde" ) );
6025             if ( !abcde3.getName().equals( "abcde" ) ) {
6026                 return false;
6027             }
6028             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
6029                                                                                                p1.getNode( "E" ) );
6030             if ( !abcde4.getName().equals( "abcde" ) ) {
6031                 return false;
6032             }
6033             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
6034                                                                                             p1.getNode( "B" ) );
6035             if ( !ab3.getName().equals( "ab" ) ) {
6036                 return false;
6037             }
6038             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
6039                                                                                             p1.getNode( "ab" ) );
6040             if ( !ab4.getName().equals( "ab" ) ) {
6041                 return false;
6042             }
6043             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
6044             PhylogenyMethods.preOrderReId( p2 );
6045             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6046                                                                                            p2.getNode( "d" ) );
6047             if ( !cd.getName().equals( "cd" ) ) {
6048                 return false;
6049             }
6050             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6051                                                                                             p2.getNode( "c" ) );
6052             if ( !cd2.getName().equals( "cd" ) ) {
6053                 return false;
6054             }
6055             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6056                                                                                             p2.getNode( "e" ) );
6057             if ( !cde.getName().equals( "cde" ) ) {
6058                 return false;
6059             }
6060             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
6061                                                                                              p2.getNode( "c" ) );
6062             if ( !cde2.getName().equals( "cde" ) ) {
6063                 return false;
6064             }
6065             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6066                                                                                              p2.getNode( "f" ) );
6067             if ( !cdef.getName().equals( "cdef" ) ) {
6068                 return false;
6069             }
6070             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
6071                                                                                               p2.getNode( "f" ) );
6072             if ( !cdef2.getName().equals( "cdef" ) ) {
6073                 return false;
6074             }
6075             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
6076                                                                                               p2.getNode( "d" ) );
6077             if ( !cdef3.getName().equals( "cdef" ) ) {
6078                 return false;
6079             }
6080             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
6081                                                                                            p2.getNode( "a" ) );
6082             if ( !rt.getName().equals( "r" ) ) {
6083                 return false;
6084             }
6085             final Phylogeny p3 = factory
6086                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
6087                              new NHXParser() )[ 0 ];
6088             PhylogenyMethods.preOrderReId( p3 );
6089             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
6090                                                                                              p3.getNode( "c" ) );
6091             if ( !bc_3.getName().equals( "bc" ) ) {
6092                 return false;
6093             }
6094             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6095                                                                                              p3.getNode( "c" ) );
6096             if ( !ac_3.getName().equals( "abc" ) ) {
6097                 return false;
6098             }
6099             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6100                                                                                              p3.getNode( "d" ) );
6101             if ( !ad_3.getName().equals( "abcde" ) ) {
6102                 return false;
6103             }
6104             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6105                                                                                              p3.getNode( "f" ) );
6106             if ( !af_3.getName().equals( "abcdef" ) ) {
6107                 return false;
6108             }
6109             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6110                                                                                              p3.getNode( "g" ) );
6111             if ( !ag_3.getName().equals( "" ) ) {
6112                 return false;
6113             }
6114             if ( !ag_3.isRoot() ) {
6115                 return false;
6116             }
6117             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
6118                                                                                              p3.getNode( "l" ) );
6119             if ( !al_3.getName().equals( "" ) ) {
6120                 return false;
6121             }
6122             if ( !al_3.isRoot() ) {
6123                 return false;
6124             }
6125             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
6126                                                                                              p3.getNode( "l" ) );
6127             if ( !kl_3.getName().equals( "" ) ) {
6128                 return false;
6129             }
6130             if ( !kl_3.isRoot() ) {
6131                 return false;
6132             }
6133             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
6134                                                                                              p3.getNode( "l" ) );
6135             if ( !fl_3.getName().equals( "" ) ) {
6136                 return false;
6137             }
6138             if ( !fl_3.isRoot() ) {
6139                 return false;
6140             }
6141             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
6142                                                                                              p3.getNode( "k" ) );
6143             if ( !gk_3.getName().equals( "ghijk" ) ) {
6144                 return false;
6145             }
6146             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
6147             PhylogenyMethods.preOrderReId( p4 );
6148             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
6149                                                                                             p4.getNode( "c" ) );
6150             if ( !r_4.getName().equals( "r" ) ) {
6151                 return false;
6152             }
6153             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
6154             PhylogenyMethods.preOrderReId( p5 );
6155             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
6156                                                                                             p5.getNode( "c" ) );
6157             if ( !r_5.getName().equals( "root" ) ) {
6158                 return false;
6159             }
6160             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
6161             PhylogenyMethods.preOrderReId( p6 );
6162             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
6163                                                                                             p6.getNode( "a" ) );
6164             if ( !r_6.getName().equals( "rot" ) ) {
6165                 return false;
6166             }
6167             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
6168             PhylogenyMethods.preOrderReId( p7 );
6169             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
6170                                                                                             p7.getNode( "e" ) );
6171             if ( !r_7.getName().equals( "rott" ) ) {
6172                 return false;
6173             }
6174             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6175                                                                                              p7.getNode( "a" ) );
6176             if ( !r_71.getName().equals( "rott" ) ) {
6177                 return false;
6178             }
6179             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6180                                                                                              p7.getNode( "rott" ) );
6181             if ( !r_72.getName().equals( "rott" ) ) {
6182                 return false;
6183             }
6184             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6185                                                                                              p7.getNode( "a" ) );
6186             if ( !r_73.getName().equals( "rott" ) ) {
6187                 return false;
6188             }
6189             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
6190                                                                                              p7.getNode( "rott" ) );
6191             if ( !r_74.getName().equals( "rott" ) ) {
6192                 return false;
6193             }
6194             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
6195                                                                                              p7.getNode( "e" ) );
6196             if ( !r_75.getName().equals( "e" ) ) {
6197                 return false;
6198             }
6199         }
6200         catch ( final Exception e ) {
6201             e.printStackTrace( System.out );
6202             return false;
6203         }
6204         return true;
6205     }
6206
6207     private static boolean testHmmscanOutputParser() {
6208         final String test_dir = Test.PATH_TO_TEST_DATA;
6209         try {
6210             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
6211                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
6212             parser1.parse();
6213             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
6214                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
6215             final List<Protein> proteins = parser2.parse();
6216             if ( parser2.getProteinsEncountered() != 4 ) {
6217                 return false;
6218             }
6219             if ( proteins.size() != 4 ) {
6220                 return false;
6221             }
6222             if ( parser2.getDomainsEncountered() != 69 ) {
6223                 return false;
6224             }
6225             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
6226                 return false;
6227             }
6228             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
6229                 return false;
6230             }
6231             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
6232                 return false;
6233             }
6234             final Protein p1 = proteins.get( 0 );
6235             if ( p1.getNumberOfProteinDomains() != 15 ) {
6236                 return false;
6237             }
6238             if ( p1.getLength() != 850 ) {
6239                 return false;
6240             }
6241             final Protein p2 = proteins.get( 1 );
6242             if ( p2.getNumberOfProteinDomains() != 51 ) {
6243                 return false;
6244             }
6245             if ( p2.getLength() != 1291 ) {
6246                 return false;
6247             }
6248             final Protein p3 = proteins.get( 2 );
6249             if ( p3.getNumberOfProteinDomains() != 2 ) {
6250                 return false;
6251             }
6252             final Protein p4 = proteins.get( 3 );
6253             if ( p4.getNumberOfProteinDomains() != 1 ) {
6254                 return false;
6255             }
6256             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
6257                 return false;
6258             }
6259             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
6260                 return false;
6261             }
6262             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
6263                 return false;
6264             }
6265             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
6266                 return false;
6267             }
6268             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
6269                 return false;
6270             }
6271             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
6272                 return false;
6273             }
6274             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
6275                 return false;
6276             }
6277         }
6278         catch ( final Exception e ) {
6279             e.printStackTrace( System.out );
6280             return false;
6281         }
6282         return true;
6283     }
6284
6285     private static boolean testLastExternalNodeMethods() {
6286         try {
6287             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6288             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
6289             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
6290             final PhylogenyNode n1 = t0.getNode( "A" );
6291             if ( n1.isLastExternalNode() ) {
6292                 return false;
6293             }
6294             final PhylogenyNode n2 = t0.getNode( "B" );
6295             if ( n2.isLastExternalNode() ) {
6296                 return false;
6297             }
6298             final PhylogenyNode n3 = t0.getNode( "C" );
6299             if ( n3.isLastExternalNode() ) {
6300                 return false;
6301             }
6302             final PhylogenyNode n4 = t0.getNode( "D" );
6303             if ( !n4.isLastExternalNode() ) {
6304                 return false;
6305             }
6306         }
6307         catch ( final Exception e ) {
6308             e.printStackTrace( System.out );
6309             return false;
6310         }
6311         return true;
6312     }
6313
6314     private static boolean testLevelOrderIterator() {
6315         try {
6316             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6317             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
6318             PhylogenyNodeIterator it0;
6319             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
6320                 it0.next();
6321             }
6322             for( it0.reset(); it0.hasNext(); ) {
6323                 it0.next();
6324             }
6325             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
6326             if ( !it.next().getName().equals( "r" ) ) {
6327                 return false;
6328             }
6329             if ( !it.next().getName().equals( "ab" ) ) {
6330                 return false;
6331             }
6332             if ( !it.next().getName().equals( "cd" ) ) {
6333                 return false;
6334             }
6335             if ( !it.next().getName().equals( "A" ) ) {
6336                 return false;
6337             }
6338             if ( !it.next().getName().equals( "B" ) ) {
6339                 return false;
6340             }
6341             if ( !it.next().getName().equals( "C" ) ) {
6342                 return false;
6343             }
6344             if ( !it.next().getName().equals( "D" ) ) {
6345                 return false;
6346             }
6347             if ( it.hasNext() ) {
6348                 return false;
6349             }
6350             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",
6351                                                  new NHXParser() )[ 0 ];
6352             PhylogenyNodeIterator it2;
6353             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
6354                 it2.next();
6355             }
6356             for( it2.reset(); it2.hasNext(); ) {
6357                 it2.next();
6358             }
6359             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
6360             if ( !it3.next().getName().equals( "r" ) ) {
6361                 return false;
6362             }
6363             if ( !it3.next().getName().equals( "abc" ) ) {
6364                 return false;
6365             }
6366             if ( !it3.next().getName().equals( "defg" ) ) {
6367                 return false;
6368             }
6369             if ( !it3.next().getName().equals( "A" ) ) {
6370                 return false;
6371             }
6372             if ( !it3.next().getName().equals( "B" ) ) {
6373                 return false;
6374             }
6375             if ( !it3.next().getName().equals( "C" ) ) {
6376                 return false;
6377             }
6378             if ( !it3.next().getName().equals( "D" ) ) {
6379                 return false;
6380             }
6381             if ( !it3.next().getName().equals( "E" ) ) {
6382                 return false;
6383             }
6384             if ( !it3.next().getName().equals( "F" ) ) {
6385                 return false;
6386             }
6387             if ( !it3.next().getName().equals( "G" ) ) {
6388                 return false;
6389             }
6390             if ( !it3.next().getName().equals( "1" ) ) {
6391                 return false;
6392             }
6393             if ( !it3.next().getName().equals( "2" ) ) {
6394                 return false;
6395             }
6396             if ( !it3.next().getName().equals( "3" ) ) {
6397                 return false;
6398             }
6399             if ( !it3.next().getName().equals( "4" ) ) {
6400                 return false;
6401             }
6402             if ( !it3.next().getName().equals( "5" ) ) {
6403                 return false;
6404             }
6405             if ( !it3.next().getName().equals( "6" ) ) {
6406                 return false;
6407             }
6408             if ( !it3.next().getName().equals( "f1" ) ) {
6409                 return false;
6410             }
6411             if ( !it3.next().getName().equals( "f2" ) ) {
6412                 return false;
6413             }
6414             if ( !it3.next().getName().equals( "f3" ) ) {
6415                 return false;
6416             }
6417             if ( !it3.next().getName().equals( "a" ) ) {
6418                 return false;
6419             }
6420             if ( !it3.next().getName().equals( "b" ) ) {
6421                 return false;
6422             }
6423             if ( !it3.next().getName().equals( "f21" ) ) {
6424                 return false;
6425             }
6426             if ( !it3.next().getName().equals( "X" ) ) {
6427                 return false;
6428             }
6429             if ( !it3.next().getName().equals( "Y" ) ) {
6430                 return false;
6431             }
6432             if ( !it3.next().getName().equals( "Z" ) ) {
6433                 return false;
6434             }
6435             if ( it3.hasNext() ) {
6436                 return false;
6437             }
6438             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6439             PhylogenyNodeIterator it4;
6440             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6441                 it4.next();
6442             }
6443             for( it4.reset(); it4.hasNext(); ) {
6444                 it4.next();
6445             }
6446             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6447             if ( !it5.next().getName().equals( "r" ) ) {
6448                 return false;
6449             }
6450             if ( !it5.next().getName().equals( "A" ) ) {
6451                 return false;
6452             }
6453             if ( !it5.next().getName().equals( "B" ) ) {
6454                 return false;
6455             }
6456             if ( !it5.next().getName().equals( "C" ) ) {
6457                 return false;
6458             }
6459             if ( !it5.next().getName().equals( "D" ) ) {
6460                 return false;
6461             }
6462             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6463             PhylogenyNodeIterator it6;
6464             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6465                 it6.next();
6466             }
6467             for( it6.reset(); it6.hasNext(); ) {
6468                 it6.next();
6469             }
6470             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6471             if ( !it7.next().getName().equals( "A" ) ) {
6472                 return false;
6473             }
6474             if ( it.hasNext() ) {
6475                 return false;
6476             }
6477         }
6478         catch ( final Exception e ) {
6479             e.printStackTrace( System.out );
6480             return false;
6481         }
6482         return true;
6483     }
6484
6485     private static boolean testMafft( final String path ) {
6486         try {
6487             final List<String> opts = new ArrayList<String>();
6488             opts.add( "--maxiterate" );
6489             opts.add( "1000" );
6490             opts.add( "--localpair" );
6491             opts.add( "--quiet" );
6492             Msa msa = null;
6493             final MsaInferrer mafft = Mafft.createInstance( path );
6494             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6495             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6496                 return false;
6497             }
6498             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6499                 return false;
6500             }
6501         }
6502         catch ( final Exception e ) {
6503             e.printStackTrace( System.out );
6504             return false;
6505         }
6506         return true;
6507     }
6508
6509     private static boolean testMidpointrooting() {
6510         try {
6511             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6512             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6513             PhylogenyMethods.midpointRoot( t0 );
6514             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6515                 return false;
6516             }
6517             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6518                 return false;
6519             }
6520             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6521                            1 ) ) {
6522                 return false;
6523             }
6524             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",
6525                                                  new NHXParser() )[ 0 ];
6526             if ( !t1.isRooted() ) {
6527                 return false;
6528             }
6529             PhylogenyMethods.midpointRoot( t1 );
6530             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6531                 return false;
6532             }
6533             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6534                 return false;
6535             }
6536             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6537                 return false;
6538             }
6539             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6540                 return false;
6541             }
6542             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6543                 return false;
6544             }
6545             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6546                 return false;
6547             }
6548             t1.reRoot( t1.getNode( "A" ) );
6549             PhylogenyMethods.midpointRoot( t1 );
6550             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6551                 return false;
6552             }
6553             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6554                 return false;
6555             }
6556             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6557                 return false;
6558             }
6559             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6560                 return false;
6561             }
6562             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6563                 System.exit( -1 );
6564                 return false;
6565             }
6566             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
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 testMsaQualityMethod() {
6578         try {
6579             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6580             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6581             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6582             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6583             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6584             l.add( s0 );
6585             l.add( s1 );
6586             l.add( s2 );
6587             l.add( s3 );
6588             final Msa msa = BasicMsa.createInstance( l );
6589             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6590                 return false;
6591             }
6592             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6593                 return false;
6594             }
6595             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6596                 return false;
6597             }
6598             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6599                 return false;
6600             }
6601             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6602                 return false;
6603             }
6604             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6605                 return false;
6606             }
6607             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6608                 return false;
6609             }
6610         }
6611         catch ( final Exception e ) {
6612             e.printStackTrace( System.out );
6613             return false;
6614         }
6615         return true;
6616     }
6617
6618     private static boolean testMsaEntropy() {
6619         try {
6620             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6621             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6622             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6623             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6624             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6625             l.add( s0 );
6626             l.add( s1 );
6627             l.add( s2 );
6628             l.add( s3 );
6629             final Msa msa = BasicMsa.createInstance( l );
6630             //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6631             //FIXME
6632             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6633             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6634             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6635             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6636             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6637             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6638             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6639             //            System.out.println();
6640             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6641             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6642             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6643             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6644             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6645             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6646             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6647             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6648             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6649             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6650             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6651             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6652             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6653             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6654             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6655             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6656             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6657             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6658             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6659             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6660             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6661             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6662             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6663             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6664             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6665             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6666             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6667             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6668             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6669             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6670             final Msa msa2 = BasicMsa.createInstance( l2 );
6671             //            System.out.println();
6672             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6673             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6674             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6675         }
6676         catch ( final Exception e ) {
6677             e.printStackTrace( System.out );
6678             return false;
6679         }
6680         return true;
6681     }
6682
6683     private static boolean testDeleteableMsa() {
6684         try {
6685             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6686             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6687             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6688             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6689             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6690             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6691             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6692             l0.add( s0 );
6693             l0.add( s1 );
6694             l0.add( s2 );
6695             l0.add( s3 );
6696             l0.add( s4 );
6697             l0.add( s5 );
6698             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6699             dmsa0.deleteRow( "b", false );
6700             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6701                 return false;
6702             }
6703             dmsa0.deleteRow( "e", false );
6704             dmsa0.deleteRow( "a", false );
6705             dmsa0.deleteRow( "f", false );
6706             if ( dmsa0.getLength() != 4 ) {
6707                 return false;
6708             }
6709             if ( dmsa0.getNumberOfSequences() != 2 ) {
6710                 return false;
6711             }
6712             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6713                 return false;
6714             }
6715             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6716                 return false;
6717             }
6718             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6719                 return false;
6720             }
6721             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6722                 return false;
6723             }
6724             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6725                 return false;
6726             }
6727             dmsa0.deleteRow( "c", false );
6728             dmsa0.deleteRow( "d", false );
6729             if ( dmsa0.getNumberOfSequences() != 0 ) {
6730                 return false;
6731             }
6732             //
6733             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6734             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6735             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6736             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6737             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6738             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6739             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6740             l1.add( s_0 );
6741             l1.add( s_1 );
6742             l1.add( s_2 );
6743             l1.add( s_3 );
6744             l1.add( s_4 );
6745             l1.add( s_5 );
6746             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6747             dmsa1.deleteGapOnlyColumns();
6748             dmsa1.deleteRow( "a", false );
6749             dmsa1.deleteRow( "f", false );
6750             dmsa1.deleteRow( "d", false );
6751             dmsa1.deleteGapOnlyColumns();
6752             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6753                 return false;
6754             }
6755             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6756                 return false;
6757             }
6758             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6759                 return false;
6760             }
6761             dmsa1.deleteRow( "c", false );
6762             dmsa1.deleteGapOnlyColumns();
6763             final Writer w0 = new StringWriter();
6764             dmsa1.write( w0, MSA_FORMAT.FASTA );
6765             final Writer w1 = new StringWriter();
6766             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6767             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6768                 return false;
6769             }
6770             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6771                 return false;
6772             }
6773             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6774             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6775             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6776             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6777             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6778             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6779             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6780             l2.add( s__0 );
6781             l2.add( s__1 );
6782             l2.add( s__2 );
6783             l2.add( s__3 );
6784             l2.add( s__4 );
6785             l2.add( s__5 );
6786             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6787             dmsa2.deleteGapColumns( 0.5 );
6788             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6789                 return false;
6790             }
6791             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6792                 return false;
6793             }
6794             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6795                 return false;
6796             }
6797             dmsa2.deleteGapColumns( 0.2 );
6798             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6799                 return false;
6800             }
6801             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6802                 return false;
6803             }
6804             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6805                 return false;
6806             }
6807             dmsa2.deleteGapColumns( 0 );
6808             dmsa2.deleteRow( "a", false );
6809             dmsa2.deleteRow( "b", false );
6810             dmsa2.deleteRow( "f", false );
6811             dmsa2.deleteRow( "e", false );
6812             dmsa2.setIdentifier( 0, "new_c" );
6813             dmsa2.setIdentifier( 1, "new_d" );
6814             dmsa2.setResidueAt( 0, 0, 'x' );
6815             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6816             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6817                 return false;
6818             }
6819             final Writer w = new StringWriter();
6820             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6821             final String phylip = w.toString();
6822             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6823                 System.out.println( phylip );
6824                 return false;
6825             }
6826             final Writer w2 = new StringWriter();
6827             dmsa2.write( w2, MSA_FORMAT.FASTA );
6828             final String fasta = w2.toString();
6829             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6830                 System.out.println( fasta );
6831                 return false;
6832             }
6833         }
6834         catch ( final Exception e ) {
6835             e.printStackTrace( System.out );
6836             return false;
6837         }
6838         return true;
6839     }
6840
6841     private static boolean testNextNodeWithCollapsing() {
6842         try {
6843             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6844             PhylogenyNode n;
6845             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6846             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6847             final Phylogeny t0 = factory.create( sb0.toString(), new NHXParser() )[ 0 ];
6848             t0.getNode( "cd" ).setCollapse( true );
6849             t0.getNode( "cde" ).setCollapse( true );
6850             n = t0.getFirstExternalNode();
6851             while ( n != null ) {
6852                 ext.add( n );
6853                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6854             }
6855             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6856                 return false;
6857             }
6858             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6859                 return false;
6860             }
6861             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6862                 return false;
6863             }
6864             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6865                 return false;
6866             }
6867             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6868                 return false;
6869             }
6870             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6871                 return false;
6872             }
6873             ext.clear();
6874             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6875             final Phylogeny t1 = factory.create( sb1.toString(), new NHXParser() )[ 0 ];
6876             t1.getNode( "ab" ).setCollapse( true );
6877             t1.getNode( "cd" ).setCollapse( true );
6878             t1.getNode( "cde" ).setCollapse( true );
6879             n = t1.getNode( "ab" );
6880             ext = new ArrayList<PhylogenyNode>();
6881             while ( n != null ) {
6882                 ext.add( n );
6883                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6884             }
6885             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6886                 return false;
6887             }
6888             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6889                 return false;
6890             }
6891             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6892                 return false;
6893             }
6894             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6895                 return false;
6896             }
6897             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6898                 return false;
6899             }
6900             ext.clear();
6901             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6902             final Phylogeny t2 = factory.create( sb2.toString(), new NHXParser() )[ 0 ];
6903             t2.getNode( "ab" ).setCollapse( true );
6904             t2.getNode( "cd" ).setCollapse( true );
6905             t2.getNode( "cde" ).setCollapse( true );
6906             t2.getNode( "c" ).setCollapse( true );
6907             t2.getNode( "d" ).setCollapse( true );
6908             t2.getNode( "e" ).setCollapse( true );
6909             t2.getNode( "gh" ).setCollapse( true );
6910             n = t2.getNode( "ab" );
6911             ext = new ArrayList<PhylogenyNode>();
6912             while ( n != null ) {
6913                 ext.add( n );
6914                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6915             }
6916             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6917                 return false;
6918             }
6919             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6920                 return false;
6921             }
6922             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6923                 return false;
6924             }
6925             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6926                 return false;
6927             }
6928             ext.clear();
6929             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6930             final Phylogeny t3 = factory.create( sb3.toString(), new NHXParser() )[ 0 ];
6931             t3.getNode( "ab" ).setCollapse( true );
6932             t3.getNode( "cd" ).setCollapse( true );
6933             t3.getNode( "cde" ).setCollapse( true );
6934             t3.getNode( "c" ).setCollapse( true );
6935             t3.getNode( "d" ).setCollapse( true );
6936             t3.getNode( "e" ).setCollapse( true );
6937             t3.getNode( "gh" ).setCollapse( true );
6938             t3.getNode( "fgh" ).setCollapse( true );
6939             n = t3.getNode( "ab" );
6940             ext = new ArrayList<PhylogenyNode>();
6941             while ( n != null ) {
6942                 ext.add( n );
6943                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6944             }
6945             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6946                 return false;
6947             }
6948             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6949                 return false;
6950             }
6951             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6952                 return false;
6953             }
6954             ext.clear();
6955             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6956             final Phylogeny t4 = factory.create( sb4.toString(), new NHXParser() )[ 0 ];
6957             t4.getNode( "ab" ).setCollapse( true );
6958             t4.getNode( "cd" ).setCollapse( true );
6959             t4.getNode( "cde" ).setCollapse( true );
6960             t4.getNode( "c" ).setCollapse( true );
6961             t4.getNode( "d" ).setCollapse( true );
6962             t4.getNode( "e" ).setCollapse( true );
6963             t4.getNode( "gh" ).setCollapse( true );
6964             t4.getNode( "fgh" ).setCollapse( true );
6965             t4.getNode( "abcdefgh" ).setCollapse( true );
6966             n = t4.getNode( "abcdefgh" );
6967             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6968                 return false;
6969             }
6970             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6971             final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
6972             ext.clear();
6973             n = t5.getFirstExternalNode();
6974             while ( n != null ) {
6975                 ext.add( n );
6976                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6977             }
6978             if ( ext.size() != 8 ) {
6979                 return false;
6980             }
6981             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6982                 return false;
6983             }
6984             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6985                 return false;
6986             }
6987             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6988                 return false;
6989             }
6990             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6991                 return false;
6992             }
6993             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6994                 return false;
6995             }
6996             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6997                 return false;
6998             }
6999             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
7000                 return false;
7001             }
7002             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
7003                 return false;
7004             }
7005             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7006             final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
7007             ext.clear();
7008             t6.getNode( "ab" ).setCollapse( true );
7009             n = t6.getNode( "ab" );
7010             while ( n != null ) {
7011                 ext.add( n );
7012                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7013             }
7014             if ( ext.size() != 7 ) {
7015                 return false;
7016             }
7017             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7018                 return false;
7019             }
7020             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7021                 return false;
7022             }
7023             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7024                 return false;
7025             }
7026             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7027                 return false;
7028             }
7029             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7030                 return false;
7031             }
7032             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7033                 return false;
7034             }
7035             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7036                 return false;
7037             }
7038             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7039             final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
7040             ext.clear();
7041             t7.getNode( "cd" ).setCollapse( true );
7042             n = t7.getNode( "a" );
7043             while ( n != null ) {
7044                 ext.add( n );
7045                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7046             }
7047             if ( ext.size() != 7 ) {
7048                 return false;
7049             }
7050             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7051                 return false;
7052             }
7053             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7054                 return false;
7055             }
7056             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7057                 return false;
7058             }
7059             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7060                 return false;
7061             }
7062             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7063                 return false;
7064             }
7065             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7066                 return false;
7067             }
7068             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7069                 return false;
7070             }
7071             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
7072             final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
7073             ext.clear();
7074             t8.getNode( "cd" ).setCollapse( true );
7075             t8.getNode( "c" ).setCollapse( true );
7076             t8.getNode( "d" ).setCollapse( true );
7077             n = t8.getNode( "a" );
7078             while ( n != null ) {
7079                 ext.add( n );
7080                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7081             }
7082             if ( ext.size() != 7 ) {
7083                 return false;
7084             }
7085             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7086                 return false;
7087             }
7088             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7089                 return false;
7090             }
7091             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
7092                 System.out.println( "2 fail" );
7093                 return false;
7094             }
7095             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7096                 return false;
7097             }
7098             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
7099                 return false;
7100             }
7101             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
7102                 return false;
7103             }
7104             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
7105                 return false;
7106             }
7107             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7108             final Phylogeny t9 = factory.create( sb9.toString(), new NHXParser() )[ 0 ];
7109             ext.clear();
7110             t9.getNode( "gh" ).setCollapse( true );
7111             n = t9.getNode( "a" );
7112             while ( n != null ) {
7113                 ext.add( n );
7114                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7115             }
7116             if ( ext.size() != 7 ) {
7117                 return false;
7118             }
7119             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7120                 return false;
7121             }
7122             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7123                 return false;
7124             }
7125             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7126                 return false;
7127             }
7128             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7129                 return false;
7130             }
7131             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7132                 return false;
7133             }
7134             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7135                 return false;
7136             }
7137             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7138                 return false;
7139             }
7140             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7141             final Phylogeny t10 = factory.create( sb10.toString(), new NHXParser() )[ 0 ];
7142             ext.clear();
7143             t10.getNode( "gh" ).setCollapse( true );
7144             t10.getNode( "g" ).setCollapse( true );
7145             t10.getNode( "h" ).setCollapse( true );
7146             n = t10.getNode( "a" );
7147             while ( n != null ) {
7148                 ext.add( n );
7149                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7150             }
7151             if ( ext.size() != 7 ) {
7152                 return false;
7153             }
7154             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7155                 return false;
7156             }
7157             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7158                 return false;
7159             }
7160             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7161                 return false;
7162             }
7163             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7164                 return false;
7165             }
7166             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7167                 return false;
7168             }
7169             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
7170                 return false;
7171             }
7172             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
7173                 return false;
7174             }
7175             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7176             final Phylogeny t11 = factory.create( sb11.toString(), new NHXParser() )[ 0 ];
7177             ext.clear();
7178             t11.getNode( "gh" ).setCollapse( true );
7179             t11.getNode( "fgh" ).setCollapse( true );
7180             n = t11.getNode( "a" );
7181             while ( n != null ) {
7182                 ext.add( n );
7183                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7184             }
7185             if ( ext.size() != 6 ) {
7186                 return false;
7187             }
7188             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7189                 return false;
7190             }
7191             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7192                 return false;
7193             }
7194             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7195                 return false;
7196             }
7197             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7198                 return false;
7199             }
7200             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7201                 return false;
7202             }
7203             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7204                 return false;
7205             }
7206             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7207             final Phylogeny t12 = factory.create( sb12.toString(), new NHXParser() )[ 0 ];
7208             ext.clear();
7209             t12.getNode( "gh" ).setCollapse( true );
7210             t12.getNode( "fgh" ).setCollapse( true );
7211             t12.getNode( "g" ).setCollapse( true );
7212             t12.getNode( "h" ).setCollapse( true );
7213             t12.getNode( "f" ).setCollapse( true );
7214             n = t12.getNode( "a" );
7215             while ( n != null ) {
7216                 ext.add( n );
7217                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7218             }
7219             if ( ext.size() != 6 ) {
7220                 return false;
7221             }
7222             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
7223                 return false;
7224             }
7225             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
7226                 return false;
7227             }
7228             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
7229                 return false;
7230             }
7231             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
7232                 return false;
7233             }
7234             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
7235                 return false;
7236             }
7237             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7238                 return false;
7239             }
7240             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
7241             final Phylogeny t13 = factory.create( sb13.toString(), new NHXParser() )[ 0 ];
7242             ext.clear();
7243             t13.getNode( "ab" ).setCollapse( true );
7244             t13.getNode( "b" ).setCollapse( true );
7245             t13.getNode( "fgh" ).setCollapse( true );
7246             t13.getNode( "gh" ).setCollapse( true );
7247             n = t13.getNode( "ab" );
7248             while ( n != null ) {
7249                 ext.add( n );
7250                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7251             }
7252             if ( ext.size() != 5 ) {
7253                 return false;
7254             }
7255             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7256                 return false;
7257             }
7258             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7259                 return false;
7260             }
7261             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7262                 return false;
7263             }
7264             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7265                 return false;
7266             }
7267             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7268                 return false;
7269             }
7270             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
7271             final Phylogeny t14 = factory.create( sb14.toString(), new NHXParser() )[ 0 ];
7272             ext.clear();
7273             t14.getNode( "ab" ).setCollapse( true );
7274             t14.getNode( "a" ).setCollapse( true );
7275             t14.getNode( "fgh" ).setCollapse( true );
7276             t14.getNode( "gh" ).setCollapse( true );
7277             n = t14.getNode( "ab" );
7278             while ( n != null ) {
7279                 ext.add( n );
7280                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7281             }
7282             if ( ext.size() != 5 ) {
7283                 return false;
7284             }
7285             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7286                 return false;
7287             }
7288             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7289                 return false;
7290             }
7291             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7292                 return false;
7293             }
7294             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7295                 return false;
7296             }
7297             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
7298                 return false;
7299             }
7300             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" );
7301             final Phylogeny t15 = factory.create( sb15.toString(), new NHXParser() )[ 0 ];
7302             ext.clear();
7303             t15.getNode( "ab" ).setCollapse( true );
7304             t15.getNode( "a" ).setCollapse( true );
7305             t15.getNode( "fgh" ).setCollapse( true );
7306             t15.getNode( "gh" ).setCollapse( true );
7307             n = t15.getNode( "ab" );
7308             while ( n != null ) {
7309                 ext.add( n );
7310                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7311             }
7312             if ( ext.size() != 6 ) {
7313                 return false;
7314             }
7315             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7316                 return false;
7317             }
7318             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
7319                 return false;
7320             }
7321             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
7322                 return false;
7323             }
7324             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
7325                 return false;
7326             }
7327             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
7328                 return false;
7329             }
7330             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
7331                 return false;
7332             }
7333             //
7334             //
7335             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" );
7336             final Phylogeny t16 = factory.create( sb16.toString(), new NHXParser() )[ 0 ];
7337             ext.clear();
7338             t16.getNode( "ab" ).setCollapse( true );
7339             t16.getNode( "a" ).setCollapse( true );
7340             t16.getNode( "fgh" ).setCollapse( true );
7341             t16.getNode( "gh" ).setCollapse( true );
7342             t16.getNode( "cd" ).setCollapse( true );
7343             t16.getNode( "cde" ).setCollapse( true );
7344             t16.getNode( "d" ).setCollapse( true );
7345             t16.getNode( "x" ).setCollapse( true );
7346             n = t16.getNode( "ab" );
7347             while ( n != null ) {
7348                 ext.add( n );
7349                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
7350             }
7351             if ( ext.size() != 4 ) {
7352                 return false;
7353             }
7354             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7355                 return false;
7356             }
7357             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7358                 return false;
7359             }
7360             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
7361                 return false;
7362             }
7363             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
7364                 return false;
7365             }
7366         }
7367         catch ( final Exception e ) {
7368             e.printStackTrace( System.out );
7369             return false;
7370         }
7371         return true;
7372     }
7373
7374     private static boolean testNexusCharactersParsing() {
7375         try {
7376             final NexusCharactersParser parser = new NexusCharactersParser();
7377             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
7378             parser.parse();
7379             String[] labels = parser.getCharStateLabels();
7380             if ( labels.length != 7 ) {
7381                 return false;
7382             }
7383             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7384                 return false;
7385             }
7386             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7387                 return false;
7388             }
7389             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7390                 return false;
7391             }
7392             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7393                 return false;
7394             }
7395             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7396                 return false;
7397             }
7398             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7399                 return false;
7400             }
7401             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7402                 return false;
7403             }
7404             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7405             parser.parse();
7406             labels = parser.getCharStateLabels();
7407             if ( labels.length != 7 ) {
7408                 return false;
7409             }
7410             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7411                 return false;
7412             }
7413             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7414                 return false;
7415             }
7416             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7417                 return false;
7418             }
7419             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7420                 return false;
7421             }
7422             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7423                 return false;
7424             }
7425             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7426                 return false;
7427             }
7428             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7429                 return false;
7430             }
7431         }
7432         catch ( final Exception e ) {
7433             e.printStackTrace( System.out );
7434             return false;
7435         }
7436         return true;
7437     }
7438
7439     private static boolean testNexusMatrixParsing() {
7440         try {
7441             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7442             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7443             parser.parse();
7444             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7445             if ( m.getNumberOfCharacters() != 9 ) {
7446                 return false;
7447             }
7448             if ( m.getNumberOfIdentifiers() != 5 ) {
7449                 return false;
7450             }
7451             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7452                 return false;
7453             }
7454             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7455                 return false;
7456             }
7457             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7458                 return false;
7459             }
7460             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7461                 return false;
7462             }
7463             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7464                 return false;
7465             }
7466             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7467                 return false;
7468             }
7469             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7470                 return false;
7471             }
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 testNexusTreeParsing() {
7532         try {
7533             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7534             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7535             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7536             if ( phylogenies.length != 1 ) {
7537                 return false;
7538             }
7539             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7540                 return false;
7541             }
7542             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7543                 return false;
7544             }
7545             phylogenies = null;
7546             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7547             if ( phylogenies.length != 1 ) {
7548                 return false;
7549             }
7550             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7551                 return false;
7552             }
7553             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7554                 return false;
7555             }
7556             phylogenies = null;
7557             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7558             if ( phylogenies.length != 1 ) {
7559                 return false;
7560             }
7561             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7562                 return false;
7563             }
7564             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7565                 return false;
7566             }
7567             if ( phylogenies[ 0 ].isRooted() ) {
7568                 return false;
7569             }
7570             phylogenies = null;
7571             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7572             if ( phylogenies.length != 18 ) {
7573                 return false;
7574             }
7575             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7576                 return false;
7577             }
7578             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7579                 return false;
7580             }
7581             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7582                 return false;
7583             }
7584             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7585                 return false;
7586             }
7587             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7588                 return false;
7589             }
7590             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7591                 return false;
7592             }
7593             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7594                 return false;
7595             }
7596             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7597                 return false;
7598             }
7599             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7600                 return false;
7601             }
7602             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7603                 return false;
7604             }
7605             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7606                 return false;
7607             }
7608             if ( phylogenies[ 8 ].isRooted() ) {
7609                 return false;
7610             }
7611             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7612                 return false;
7613             }
7614             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7615                 return false;
7616             }
7617             if ( !phylogenies[ 9 ].isRooted() ) {
7618                 return false;
7619             }
7620             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7621                 return false;
7622             }
7623             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7624                 return false;
7625             }
7626             if ( !phylogenies[ 10 ].isRooted() ) {
7627                 return false;
7628             }
7629             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7630                 return false;
7631             }
7632             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7633                 return false;
7634             }
7635             if ( phylogenies[ 11 ].isRooted() ) {
7636                 return false;
7637             }
7638             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7639                 return false;
7640             }
7641             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7642                 return false;
7643             }
7644             if ( !phylogenies[ 12 ].isRooted() ) {
7645                 return false;
7646             }
7647             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7648                 return false;
7649             }
7650             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7651                 return false;
7652             }
7653             if ( !phylogenies[ 13 ].isRooted() ) {
7654                 return false;
7655             }
7656             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7657                 return false;
7658             }
7659             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7660                 return false;
7661             }
7662             if ( !phylogenies[ 14 ].isRooted() ) {
7663                 return false;
7664             }
7665             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7666                 return false;
7667             }
7668             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7669                 return false;
7670             }
7671             if ( phylogenies[ 15 ].isRooted() ) {
7672                 return false;
7673             }
7674             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7675                 return false;
7676             }
7677             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7678                 return false;
7679             }
7680             if ( !phylogenies[ 16 ].isRooted() ) {
7681                 return false;
7682             }
7683             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7684                 return false;
7685             }
7686             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7687                 return false;
7688             }
7689             if ( phylogenies[ 17 ].isRooted() ) {
7690                 return false;
7691             }
7692             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7693                 return false;
7694             }
7695             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7696             phylogenies = null;
7697             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7698             if ( phylogenies.length != 9 ) {
7699                 return false;
7700             }
7701             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7702                            .getDistanceToParent() ) ) {
7703                 return false;
7704             }
7705             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7706                            .getDistanceToParent() ) ) {
7707                 return false;
7708             }
7709             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7710                 return false;
7711             }
7712             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7713                 return false;
7714             }
7715             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7716                 return false;
7717             }
7718             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7719                 return false;
7720             }
7721             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7722                 return false;
7723             }
7724         }
7725         catch ( final Exception e ) {
7726             e.printStackTrace( System.out );
7727             return false;
7728         }
7729         return true;
7730     }
7731
7732     private static boolean testNexusTreeParsingIterating() {
7733         try {
7734             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7735             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7736             if ( !p.hasNext() ) {
7737                 return false;
7738             }
7739             Phylogeny phy = p.next();
7740             if ( phy == null ) {
7741                 return false;
7742             }
7743             if ( phy.getNumberOfExternalNodes() != 25 ) {
7744                 return false;
7745             }
7746             if ( !phy.getName().equals( "" ) ) {
7747                 return false;
7748             }
7749             if ( p.hasNext() ) {
7750                 return false;
7751             }
7752             phy = p.next();
7753             if ( phy != null ) {
7754                 return false;
7755             }
7756             p.reset();
7757             if ( !p.hasNext() ) {
7758                 return false;
7759             }
7760             phy = p.next();
7761             if ( phy == null ) {
7762                 return false;
7763             }
7764             if ( phy.getNumberOfExternalNodes() != 25 ) {
7765                 return false;
7766             }
7767             if ( !phy.getName().equals( "" ) ) {
7768                 return false;
7769             }
7770             if ( p.hasNext() ) {
7771                 return false;
7772             }
7773             phy = p.next();
7774             if ( phy != null ) {
7775                 return false;
7776             }
7777             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7778             if ( !p.hasNext() ) {
7779                 return false;
7780             }
7781             phy = p.next();
7782             if ( phy == null ) {
7783                 return false;
7784             }
7785             if ( phy.getNumberOfExternalNodes() != 10 ) {
7786                 return false;
7787             }
7788             if ( !phy.getName().equals( "name" ) ) {
7789                 return false;
7790             }
7791             if ( p.hasNext() ) {
7792                 return false;
7793             }
7794             phy = p.next();
7795             if ( phy != null ) {
7796                 return false;
7797             }
7798             p.reset();
7799             if ( !p.hasNext() ) {
7800                 return false;
7801             }
7802             phy = p.next();
7803             if ( phy == null ) {
7804                 return false;
7805             }
7806             if ( phy.getNumberOfExternalNodes() != 10 ) {
7807                 return false;
7808             }
7809             if ( !phy.getName().equals( "name" ) ) {
7810                 return false;
7811             }
7812             if ( p.hasNext() ) {
7813                 return false;
7814             }
7815             phy = p.next();
7816             if ( phy != null ) {
7817                 return false;
7818             }
7819             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7820             if ( !p.hasNext() ) {
7821                 return false;
7822             }
7823             phy = p.next();
7824             if ( phy == null ) {
7825                 return false;
7826             }
7827             if ( phy.getNumberOfExternalNodes() != 3 ) {
7828                 return false;
7829             }
7830             if ( !phy.getName().equals( "" ) ) {
7831                 return false;
7832             }
7833             if ( phy.isRooted() ) {
7834                 return false;
7835             }
7836             if ( p.hasNext() ) {
7837                 return false;
7838             }
7839             phy = p.next();
7840             if ( phy != null ) {
7841                 return false;
7842             }
7843             //
7844             p.reset();
7845             if ( !p.hasNext() ) {
7846                 return false;
7847             }
7848             phy = p.next();
7849             if ( phy == null ) {
7850                 return false;
7851             }
7852             if ( phy.getNumberOfExternalNodes() != 3 ) {
7853                 return false;
7854             }
7855             if ( !phy.getName().equals( "" ) ) {
7856                 return false;
7857             }
7858             if ( p.hasNext() ) {
7859                 return false;
7860             }
7861             phy = p.next();
7862             if ( phy != null ) {
7863                 return false;
7864             }
7865             //
7866             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7867             if ( !p.hasNext() ) {
7868                 return false;
7869             }
7870             //0
7871             phy = p.next();
7872             if ( phy == null ) {
7873                 return false;
7874             }
7875             if ( phy.getNumberOfExternalNodes() != 10 ) {
7876                 return false;
7877             }
7878             if ( !phy.getName().equals( "tree 0" ) ) {
7879                 return false;
7880             }
7881             //1
7882             if ( !p.hasNext() ) {
7883                 return false;
7884             }
7885             phy = p.next();
7886             if ( phy == null ) {
7887                 return false;
7888             }
7889             if ( phy.getNumberOfExternalNodes() != 10 ) {
7890                 return false;
7891             }
7892             if ( !phy.getName().equals( "tree 1" ) ) {
7893                 return false;
7894             }
7895             //2
7896             if ( !p.hasNext() ) {
7897                 return false;
7898             }
7899             phy = p.next();
7900             if ( phy == null ) {
7901                 return false;
7902             }
7903             if ( phy.getNumberOfExternalNodes() != 3 ) {
7904                 System.out.println( phy.toString() );
7905                 return false;
7906             }
7907             if ( !phy.getName().equals( "" ) ) {
7908                 return false;
7909             }
7910             if ( phy.isRooted() ) {
7911                 return false;
7912             }
7913             //3
7914             if ( !p.hasNext() ) {
7915                 return false;
7916             }
7917             phy = p.next();
7918             if ( phy == null ) {
7919                 return false;
7920             }
7921             if ( phy.getNumberOfExternalNodes() != 4 ) {
7922                 return false;
7923             }
7924             if ( !phy.getName().equals( "" ) ) {
7925                 return false;
7926             }
7927             if ( !phy.isRooted() ) {
7928                 return false;
7929             }
7930             //4
7931             if ( !p.hasNext() ) {
7932                 return false;
7933             }
7934             phy = p.next();
7935             if ( phy == null ) {
7936                 return false;
7937             }
7938             if ( phy.getNumberOfExternalNodes() != 5 ) {
7939                 System.out.println( phy.getNumberOfExternalNodes() );
7940                 return false;
7941             }
7942             if ( !phy.getName().equals( "" ) ) {
7943                 return false;
7944             }
7945             if ( !phy.isRooted() ) {
7946                 return false;
7947             }
7948             //5
7949             if ( !p.hasNext() ) {
7950                 return false;
7951             }
7952             phy = p.next();
7953             if ( phy == null ) {
7954                 return false;
7955             }
7956             if ( phy.getNumberOfExternalNodes() != 3 ) {
7957                 return false;
7958             }
7959             if ( !phy.getName().equals( "" ) ) {
7960                 return false;
7961             }
7962             if ( phy.isRooted() ) {
7963                 return false;
7964             }
7965             //6
7966             if ( !p.hasNext() ) {
7967                 return false;
7968             }
7969             phy = p.next();
7970             if ( phy == null ) {
7971                 return false;
7972             }
7973             if ( phy.getNumberOfExternalNodes() != 2 ) {
7974                 return false;
7975             }
7976             if ( !phy.getName().equals( "" ) ) {
7977                 return false;
7978             }
7979             if ( !phy.isRooted() ) {
7980                 return false;
7981             }
7982             //7
7983             if ( !p.hasNext() ) {
7984                 return false;
7985             }
7986             phy = p.next();
7987             if ( phy.getNumberOfExternalNodes() != 3 ) {
7988                 return false;
7989             }
7990             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7991                 return false;
7992             }
7993             if ( !phy.isRooted() ) {
7994                 return false;
7995             }
7996             //8
7997             if ( !p.hasNext() ) {
7998                 return false;
7999             }
8000             phy = p.next();
8001             if ( phy.getNumberOfExternalNodes() != 3 ) {
8002                 return false;
8003             }
8004             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
8005                 return false;
8006             }
8007             if ( !phy.getName().equals( "tree 8" ) ) {
8008                 return false;
8009             }
8010             //9
8011             if ( !p.hasNext() ) {
8012                 return false;
8013             }
8014             phy = p.next();
8015             if ( phy.getNumberOfExternalNodes() != 3 ) {
8016                 return false;
8017             }
8018             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
8019                 return false;
8020             }
8021             if ( !phy.getName().equals( "tree 9" ) ) {
8022                 return false;
8023             }
8024             //10
8025             if ( !p.hasNext() ) {
8026                 return false;
8027             }
8028             phy = p.next();
8029             if ( phy.getNumberOfExternalNodes() != 3 ) {
8030                 return false;
8031             }
8032             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8033                 return false;
8034             }
8035             if ( !phy.getName().equals( "tree 10" ) ) {
8036                 return false;
8037             }
8038             if ( !phy.isRooted() ) {
8039                 return false;
8040             }
8041             //11
8042             if ( !p.hasNext() ) {
8043                 return false;
8044             }
8045             phy = p.next();
8046             if ( phy.getNumberOfExternalNodes() != 3 ) {
8047                 return false;
8048             }
8049             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
8050                 return false;
8051             }
8052             if ( !phy.getName().equals( "tree 11" ) ) {
8053                 return false;
8054             }
8055             if ( phy.isRooted() ) {
8056                 return false;
8057             }
8058             //12
8059             if ( !p.hasNext() ) {
8060                 return false;
8061             }
8062             phy = p.next();
8063             if ( phy.getNumberOfExternalNodes() != 3 ) {
8064                 return false;
8065             }
8066             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
8067                 return false;
8068             }
8069             if ( !phy.getName().equals( "tree 12" ) ) {
8070                 return false;
8071             }
8072             if ( !phy.isRooted() ) {
8073                 return false;
8074             }
8075             //13
8076             if ( !p.hasNext() ) {
8077                 return false;
8078             }
8079             phy = p.next();
8080             if ( phy.getNumberOfExternalNodes() != 3 ) {
8081                 return false;
8082             }
8083             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
8084                 return false;
8085             }
8086             if ( !phy.getName().equals( "tree 13" ) ) {
8087                 return false;
8088             }
8089             if ( !phy.isRooted() ) {
8090                 return false;
8091             }
8092             //14
8093             if ( !p.hasNext() ) {
8094                 return false;
8095             }
8096             phy = p.next();
8097             if ( phy.getNumberOfExternalNodes() != 10 ) {
8098                 System.out.println( phy.getNumberOfExternalNodes() );
8099                 return false;
8100             }
8101             if ( !phy
8102                     .toNewHampshire()
8103                     .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;" ) ) {
8104                 System.out.println( phy.toNewHampshire() );
8105                 return false;
8106             }
8107             if ( !phy.getName().equals( "tree 14" ) ) {
8108                 return false;
8109             }
8110             if ( !phy.isRooted() ) {
8111                 return false;
8112             }
8113             //15
8114             if ( !p.hasNext() ) {
8115                 return false;
8116             }
8117             phy = p.next();
8118             if ( phy.getNumberOfExternalNodes() != 10 ) {
8119                 System.out.println( phy.getNumberOfExternalNodes() );
8120                 return false;
8121             }
8122             if ( !phy
8123                     .toNewHampshire()
8124                     .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;" ) ) {
8125                 System.out.println( phy.toNewHampshire() );
8126                 return false;
8127             }
8128             if ( !phy.getName().equals( "tree 15" ) ) {
8129                 return false;
8130             }
8131             if ( phy.isRooted() ) {
8132                 return false;
8133             }
8134             //16
8135             if ( !p.hasNext() ) {
8136                 return false;
8137             }
8138             phy = p.next();
8139             if ( phy.getNumberOfExternalNodes() != 10 ) {
8140                 System.out.println( phy.getNumberOfExternalNodes() );
8141                 return false;
8142             }
8143             if ( !phy
8144                     .toNewHampshire()
8145                     .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;" ) ) {
8146                 System.out.println( phy.toNewHampshire() );
8147                 return false;
8148             }
8149             if ( !phy.getName().equals( "tree 16" ) ) {
8150                 return false;
8151             }
8152             if ( !phy.isRooted() ) {
8153                 return false;
8154             }
8155             //17
8156             if ( !p.hasNext() ) {
8157                 return false;
8158             }
8159             phy = p.next();
8160             if ( phy.getNumberOfExternalNodes() != 10 ) {
8161                 System.out.println( phy.getNumberOfExternalNodes() );
8162                 return false;
8163             }
8164             if ( !phy
8165                     .toNewHampshire()
8166                     .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;" ) ) {
8167                 System.out.println( phy.toNewHampshire() );
8168                 return false;
8169             }
8170             if ( !phy.getName().equals( "tree 17" ) ) {
8171                 return false;
8172             }
8173             if ( phy.isRooted() ) {
8174                 return false;
8175             }
8176             //
8177             if ( p.hasNext() ) {
8178                 return false;
8179             }
8180             phy = p.next();
8181             if ( phy != null ) {
8182                 return false;
8183             }
8184             p.reset();
8185             //0
8186             if ( !p.hasNext() ) {
8187                 return false;
8188             }
8189             phy = p.next();
8190             if ( phy == null ) {
8191                 return false;
8192             }
8193             if ( phy.getNumberOfExternalNodes() != 10 ) {
8194                 return false;
8195             }
8196             if ( !phy.getName().equals( "tree 0" ) ) {
8197                 return false;
8198             }
8199             //1
8200             if ( !p.hasNext() ) {
8201                 return false;
8202             }
8203             phy = p.next();
8204             if ( phy == null ) {
8205                 return false;
8206             }
8207             if ( phy.getNumberOfExternalNodes() != 10 ) {
8208                 return false;
8209             }
8210             if ( !phy.getName().equals( "tree 1" ) ) {
8211                 return false;
8212             }
8213             //2
8214             if ( !p.hasNext() ) {
8215                 return false;
8216             }
8217             phy = p.next();
8218             if ( phy == null ) {
8219                 return false;
8220             }
8221             if ( phy.getNumberOfExternalNodes() != 3 ) {
8222                 return false;
8223             }
8224             if ( !phy.getName().equals( "" ) ) {
8225                 return false;
8226             }
8227             if ( phy.isRooted() ) {
8228                 return false;
8229             }
8230             //3
8231             if ( !p.hasNext() ) {
8232                 return false;
8233             }
8234             phy = p.next();
8235             if ( phy == null ) {
8236                 return false;
8237             }
8238             if ( phy.getNumberOfExternalNodes() != 4 ) {
8239                 return false;
8240             }
8241             if ( !phy.getName().equals( "" ) ) {
8242                 return false;
8243             }
8244             if ( !phy.isRooted() ) {
8245                 return false;
8246             }
8247             //4
8248             if ( !p.hasNext() ) {
8249                 return false;
8250             }
8251             phy = p.next();
8252             if ( phy == null ) {
8253                 return false;
8254             }
8255             if ( phy.getNumberOfExternalNodes() != 5 ) {
8256                 System.out.println( phy.getNumberOfExternalNodes() );
8257                 return false;
8258             }
8259             if ( !phy.getName().equals( "" ) ) {
8260                 return false;
8261             }
8262             if ( !phy.isRooted() ) {
8263                 return false;
8264             }
8265             //5
8266             if ( !p.hasNext() ) {
8267                 return false;
8268             }
8269             phy = p.next();
8270             if ( phy == null ) {
8271                 return false;
8272             }
8273             if ( phy.getNumberOfExternalNodes() != 3 ) {
8274                 return false;
8275             }
8276             if ( !phy.getName().equals( "" ) ) {
8277                 return false;
8278             }
8279             if ( phy.isRooted() ) {
8280                 return false;
8281             }
8282             //
8283             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
8284             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
8285             // 0
8286             if ( !p2.hasNext() ) {
8287                 return false;
8288             }
8289             phy = p2.next();
8290             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8291                 return false;
8292             }
8293             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8294                 return false;
8295             }
8296             // 1
8297             if ( !p2.hasNext() ) {
8298                 return false;
8299             }
8300             phy = p2.next();
8301             // 2
8302             if ( !p2.hasNext() ) {
8303                 return false;
8304             }
8305             phy = p2.next();
8306             // 3
8307             if ( !p2.hasNext() ) {
8308                 return false;
8309             }
8310             phy = p2.next();
8311             // 4
8312             if ( !p2.hasNext() ) {
8313                 return false;
8314             }
8315             phy = p2.next();
8316             // 5
8317             if ( !p2.hasNext() ) {
8318                 return false;
8319             }
8320             phy = p2.next();
8321             // 6
8322             if ( !p2.hasNext() ) {
8323                 return false;
8324             }
8325             phy = p2.next();
8326             // 7
8327             if ( !p2.hasNext() ) {
8328                 return false;
8329             }
8330             phy = p2.next();
8331             // 8
8332             if ( !p2.hasNext() ) {
8333                 return false;
8334             }
8335             phy = p2.next();
8336             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
8337                 return false;
8338             }
8339             if ( p2.hasNext() ) {
8340                 return false;
8341             }
8342             phy = p2.next();
8343             if ( phy != null ) {
8344                 return false;
8345             }
8346             // 0
8347             p2.reset();
8348             if ( !p2.hasNext() ) {
8349                 return false;
8350             }
8351             phy = p2.next();
8352             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8353                 return false;
8354             }
8355             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8356                 return false;
8357             }
8358         }
8359         catch ( final Exception e ) {
8360             e.printStackTrace( System.out );
8361             return false;
8362         }
8363         return true;
8364     }
8365
8366     private static boolean testNexusTreeParsingTranslating() {
8367         try {
8368             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8369             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
8370             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
8371             if ( phylogenies.length != 1 ) {
8372                 return false;
8373             }
8374             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8375                 return false;
8376             }
8377             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8378                 return false;
8379             }
8380             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8381                 return false;
8382             }
8383             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8384                 return false;
8385             }
8386             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8387                     .equals( "Aranaeus" ) ) {
8388                 return false;
8389             }
8390             phylogenies = null;
8391             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
8392             if ( phylogenies.length != 3 ) {
8393                 return false;
8394             }
8395             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8396                 return false;
8397             }
8398             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8399                 return false;
8400             }
8401             if ( phylogenies[ 0 ].isRooted() ) {
8402                 return false;
8403             }
8404             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8405                 return false;
8406             }
8407             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8408                 return false;
8409             }
8410             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8411                     .equals( "Aranaeus" ) ) {
8412                 return false;
8413             }
8414             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8415                 return false;
8416             }
8417             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8418                 return false;
8419             }
8420             if ( phylogenies[ 1 ].isRooted() ) {
8421                 return false;
8422             }
8423             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8424                 return false;
8425             }
8426             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8427                 return false;
8428             }
8429             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8430                     .equals( "Aranaeus" ) ) {
8431                 return false;
8432             }
8433             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8434                 return false;
8435             }
8436             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8437                 return false;
8438             }
8439             if ( !phylogenies[ 2 ].isRooted() ) {
8440                 return false;
8441             }
8442             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8443                 return false;
8444             }
8445             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8446                 return false;
8447             }
8448             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8449                     .equals( "Aranaeus" ) ) {
8450                 return false;
8451             }
8452             phylogenies = null;
8453             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8454             if ( phylogenies.length != 3 ) {
8455                 return false;
8456             }
8457             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8458                 return false;
8459             }
8460             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8461                 return false;
8462             }
8463             if ( phylogenies[ 0 ].isRooted() ) {
8464                 return false;
8465             }
8466             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8467                 return false;
8468             }
8469             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8470                 return false;
8471             }
8472             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8473                     .equals( "Aranaeus" ) ) {
8474                 return false;
8475             }
8476             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8477                 return false;
8478             }
8479             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8480                 return false;
8481             }
8482             if ( phylogenies[ 1 ].isRooted() ) {
8483                 return false;
8484             }
8485             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8486                 return false;
8487             }
8488             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8489                 return false;
8490             }
8491             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8492                     .equals( "Aranaeus" ) ) {
8493                 return false;
8494             }
8495             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8496                 return false;
8497             }
8498             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8499                 return false;
8500             }
8501             if ( !phylogenies[ 2 ].isRooted() ) {
8502                 return false;
8503             }
8504             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8505                 return false;
8506             }
8507             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8508                 return false;
8509             }
8510             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8511                     .equals( "Aranaeus" ) ) {
8512                 return false;
8513             }
8514             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8515             if ( phylogenies.length != 3 ) {
8516                 return false;
8517             }
8518             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8519                            0.00100049 ) ) {
8520                 return false;
8521             }
8522         }
8523         catch ( final Exception e ) {
8524             e.printStackTrace( System.out );
8525             return false;
8526         }
8527         return true;
8528     }
8529
8530     private static boolean testNHParsing() {
8531         try {
8532             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8533             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8534             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8535                 return false;
8536             }
8537             final NHXParser nhxp = new NHXParser();
8538             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8539             nhxp.setReplaceUnderscores( true );
8540             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8541             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8542                 return false;
8543             }
8544             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8545                 return false;
8546             }
8547             final Phylogeny p1b = factory
8548                     .create( "   \n  \t  \b   \r \f   ; (  \n  \t  \b   \r \f; A ;  \n  \t  \b   \r \f,  \n  \t  \b   \r \f; B ;   \n  \t  \b   \r \f 1  \n  \t  \b   \r \f ;  \n  \t  \b   \r \f );;;;; \n  \t  \b   \r \f;;;  \n  \t  \b   \r \f ",
8549                              new NHXParser() )[ 0 ];
8550             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8551                 return false;
8552             }
8553             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8554                 return false;
8555             }
8556             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ).toString(), new NHXParser() )[ 0 ];
8557             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8558             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8559             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ).toString(), new NHXParser() )[ 0 ];
8560             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8561             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8562             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8563             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8564             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8565             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8566             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8567                     + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8568                     + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8569                     new NHXParser() );
8570             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8571                 return false;
8572             }
8573             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8574                 return false;
8575             }
8576             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8577                 return false;
8578             }
8579             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8580                 return false;
8581             }
8582             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8583             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8584             final String p16_S = "((A,B),C)";
8585             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8586             if ( p16.length != 1 ) {
8587                 return false;
8588             }
8589             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8590                 return false;
8591             }
8592             final String p17_S = "(C,(A,B))";
8593             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8594             if ( p17.length != 1 ) {
8595                 return false;
8596             }
8597             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8598                 return false;
8599             }
8600             final String p18_S = "((A,B),(C,D))";
8601             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8602             if ( p18.length != 1 ) {
8603                 return false;
8604             }
8605             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8606                 return false;
8607             }
8608             final String p19_S = "(((A,B),C),D)";
8609             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8610             if ( p19.length != 1 ) {
8611                 return false;
8612             }
8613             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8614                 return false;
8615             }
8616             final String p20_S = "(A,(B,(C,D)))";
8617             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8618             if ( p20.length != 1 ) {
8619                 return false;
8620             }
8621             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8622                 return false;
8623             }
8624             final String p21_S = "(A,(B,(C,(D,E))))";
8625             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8626             if ( p21.length != 1 ) {
8627                 return false;
8628             }
8629             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8630                 return false;
8631             }
8632             final String p22_S = "((((A,B),C),D),E)";
8633             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8634             if ( p22.length != 1 ) {
8635                 return false;
8636             }
8637             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8638                 return false;
8639             }
8640             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8641             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8642             if ( p23.length != 1 ) {
8643                 System.out.println( "xl=" + p23.length );
8644                 System.exit( -1 );
8645                 return false;
8646             }
8647             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8648                 return false;
8649             }
8650             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8651             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8652             if ( p24.length != 1 ) {
8653                 return false;
8654             }
8655             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8656                 return false;
8657             }
8658             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8659             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8660             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8661             if ( p241.length != 2 ) {
8662                 return false;
8663             }
8664             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8665                 return false;
8666             }
8667             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8668                 return false;
8669             }
8670             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8671                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8672                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8673                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8674                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8675                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8676                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8677                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8678             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8679             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8680                 return false;
8681             }
8682             final String p26_S = "(A,B)ab";
8683             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8684             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8685                 return false;
8686             }
8687             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8688             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8689             if ( p27s.length != 1 ) {
8690                 System.out.println( "xxl=" + p27s.length );
8691                 System.exit( -1 );
8692                 return false;
8693             }
8694             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8695                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8696                 System.exit( -1 );
8697                 return false;
8698             }
8699             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8700                                                     new NHXParser() );
8701             if ( p27.length != 1 ) {
8702                 System.out.println( "yl=" + p27.length );
8703                 System.exit( -1 );
8704                 return false;
8705             }
8706             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8707                 System.out.println( p27[ 0 ].toNewHampshireX() );
8708                 System.exit( -1 );
8709                 return false;
8710             }
8711             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8712             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8713             final String p28_S3 = "(A,B)ab";
8714             final String p28_S4 = "((((A,B),C),D),;E;)";
8715             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8716                                                     new NHXParser() );
8717             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8718                 return false;
8719             }
8720             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8721                 return false;
8722             }
8723             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8724                 return false;
8725             }
8726             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8727                 return false;
8728             }
8729             if ( p28.length != 4 ) {
8730                 return false;
8731             }
8732             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";
8733             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8734             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8735                 return false;
8736             }
8737             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";
8738             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8739             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8740                 return false;
8741             }
8742             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8743             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8744             if ( ( p32.length != 0 ) ) {
8745                 return false;
8746             }
8747             final String p33_S = "A";
8748             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8749             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8750                 return false;
8751             }
8752             final String p34_S = "B;";
8753             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8754             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8755                 return false;
8756             }
8757             final String p35_S = "B:0.2";
8758             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8759             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8760                 return false;
8761             }
8762             final String p36_S = "(A)";
8763             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8764             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8765                 return false;
8766             }
8767             final String p37_S = "((A))";
8768             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8769             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8770                 return false;
8771             }
8772             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8773             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8774             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8775                 return false;
8776             }
8777             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8778             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8779             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8780                 return false;
8781             }
8782             final String p40_S = "(A,B,C)";
8783             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8784             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8785                 return false;
8786             }
8787             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8788             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8789             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8790                 return false;
8791             }
8792             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8793             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8794             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8795                 return false;
8796             }
8797             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)";
8798             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8799             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8800                 return false;
8801             }
8802             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)))";
8803             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8804             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8805                 return false;
8806             }
8807             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8808             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8809             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8810                 return false;
8811             }
8812             final String p46_S = "";
8813             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8814             if ( p46.length != 0 ) {
8815                 return false;
8816             }
8817             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ).toString(), new NHXParser() )[ 0 ];
8818             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8819                 return false;
8820             }
8821             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8822             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8823                 return false;
8824             }
8825             final Phylogeny p49 = factory
8826                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ).toString(),
8827                              new NHXParser() )[ 0 ];
8828             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8829                 return false;
8830             }
8831             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8832             if ( p50.getNode( "A" ) == null ) {
8833                 return false;
8834             }
8835             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8836                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8837                 return false;
8838             }
8839             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8840                 return false;
8841             }
8842             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8843                     .equals( "((A,B)88:2.0,C);" ) ) {
8844                 return false;
8845             }
8846             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8847             if ( p51.getNode( "A(A" ) == null ) {
8848                 return false;
8849             }
8850             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ).toString(), new NHXParser() )[ 0 ];
8851             if ( p52.getNode( "A(A" ) == null ) {
8852                 return false;
8853             }
8854             final Phylogeny p53 = factory
8855                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ).toString(),
8856                              new NHXParser() )[ 0 ];
8857             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8858                 return false;
8859             }
8860             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ).toString(), new NHXParser() )[ 0 ];
8861             if ( p54.getNode( "A" ) == null ) {
8862                 return false;
8863             }
8864             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8865                 return false;
8866             }
8867             final Phylogeny p55 = factory
8868                     .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);" ).toString(),
8869                              new NHXParser() )[ 0 ];
8870             if ( !p55
8871                     .toNewHampshire()
8872                     .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);" ) ) {
8873                 System.out.println( p55.toNewHampshire() );
8874                 return false;
8875             }
8876             final Phylogeny p56 = factory
8877                     .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);" ).toString(),
8878                              new NHXParser() )[ 0 ];
8879             if ( !p56
8880                     .toNewHampshire()
8881                     .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);" ) ) {
8882                 System.out.println( p56.toNewHampshire() );
8883                 return false;
8884             }
8885             final Phylogeny p57 = factory
8886                     .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);" ).toString(),
8887                              new NHXParser() )[ 0 ];
8888             if ( !p57
8889                     .toNewHampshire()
8890                     .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);" ) ) {
8891                 System.out.println( p56.toNewHampshire() );
8892                 return false;
8893             }
8894             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8895             final Phylogeny p58 = factory.create( s58, new NHXParser() )[ 0 ];
8896             if ( !p58.toNewHampshire().equals( s58 ) ) {
8897                 System.out.println( p58.toNewHampshire() );
8898                 return false;
8899             }
8900             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8901             final Phylogeny p59 = factory.create( s59 , new NHXParser() )[ 0 ];
8902             if ( !p59.toNewHampshire().equals( s59 ) ) {
8903                 System.out.println( p59.toNewHampshire() );
8904                 return false;
8905             }
8906             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8907             final Phylogeny p60 = factory.create( s60, new NHXParser() )[ 0 ];
8908             if ( !p60.toNewHampshire().equals( s60 ) ) {
8909                 System.out.println( p60.toNewHampshire() );
8910                 return false;
8911             }
8912             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8913             final Phylogeny p61 = factory.create( s61, new NHXParser() )[ 0 ];
8914             if ( !p61.toNewHampshire()
8915                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8916                 System.out.println( p61.toNewHampshire() );
8917                 return false;
8918             }
8919             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;";
8920             final Phylogeny p62 = factory.create( s62, new NHXParser() )[ 0 ];
8921             if ( !p62.toNewHampshire()
8922                     .equals( "(1:0.003,2:0.004):0.0;" ) ) {
8923                 System.out.println( p62.toNewHampshire() );
8924                 return false;
8925             }
8926             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)\"];";
8927             final Phylogeny p63 = factory.create( s63, new NHXParser() )[ 0 ];
8928             if ( !p63.toNewHampshire()
8929                     .equals( "(1:0.003,2:0.004):0.0;" ) ) {
8930                 System.out.println( p63.toNewHampshire() );
8931                 return false;
8932             }
8933             final String s64 = "((1,2):[95.5],3);";
8934             final Phylogeny p64 = factory.create( s64, new NHXParser() )[ 0 ];
8935             if ( !p64.toNewHampshireX()
8936                     .equals( "((1,2)[&&NHX:B=95.5],3)" ) ) {
8937                 System.out.println( p64.toNewHampshireX() );
8938                 return false;
8939             }
8940             final String s65 = "((1:0.1,2:0.2):0.3[10.2],3);";
8941             final Phylogeny p65 = factory.create( s65, new NHXParser() )[ 0 ];
8942             if ( !p65.toNewHampshireX()
8943                     .equals( "((1:0.1,2:0.2):0.3[&&NHX:B=10.2],3)" ) ) {
8944                 System.out.println( p65.toNewHampshireX() );
8945                 return false;
8946             }
8947         }
8948         catch ( final Exception e ) {
8949             e.printStackTrace( System.out );
8950             return false;
8951         }
8952         return true;
8953     }
8954     
8955     private static boolean testNHParsingSpecialChars() {
8956         try {
8957             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();   
8958             final String i0 = "(A!+=~QWERTY!@#$%^&*-,€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ)";
8959             final Phylogeny p0 = factory.create( i0, new NHXParser() )[ 0 ];
8960             if ( !p0.toNewHampshireX().equals( i0 ) ) {
8961                 System.out.println();
8962                 System.out.println( p0.toNewHampshireX() );
8963                 System.out.println( i0 );
8964                 return false;
8965             }
8966             final String i1 = "(हिंदी,한글,ไทย,'Tiếng Việt',ひらがなカタカナ漢字,繁體字,русский)";
8967             final Phylogeny p1 = factory.create( i1, new NHXParser() )[ 0 ];
8968             if ( !p1.toNewHampshireX().equals( i1 ) ) {
8969                 System.out.println();
8970                 System.out.println( p1.toNewHampshireX() );
8971                 System.out.println( i1 );
8972                 return false;
8973             }
8974         }
8975         catch ( final Exception e ) {
8976             e.printStackTrace( System.out );
8977             return false;
8978         }
8979         return true;
8980     }
8981     
8982     
8983     
8984     private static boolean testNHParsingIter() {
8985         try {
8986             final String p0_str = "(A,B);";
8987             final NHXParser p = new NHXParser();
8988             p.setSource( p0_str );
8989             if ( !p.hasNext() ) {
8990                 return false;
8991             }
8992             final Phylogeny p0 = p.next();
8993             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8994                 System.out.println( p0.toNewHampshire() );
8995                 return false;
8996             }
8997             if ( p.hasNext() ) {
8998                 return false;
8999             }
9000             if ( p.next() != null ) {
9001                 return false;
9002             }
9003             //
9004             final String p00_str = "(A,B)root;";
9005             p.setSource( p00_str );
9006             final Phylogeny p00 = p.next();
9007             if ( !p00.toNewHampshire().equals( p00_str ) ) {
9008                 System.out.println( p00.toNewHampshire() );
9009                 return false;
9010             }
9011             //
9012             final String p000_str = "A;";
9013             p.setSource( p000_str );
9014             final Phylogeny p000 = p.next();
9015             if ( !p000.toNewHampshire().equals( p000_str ) ) {
9016                 System.out.println( p000.toNewHampshire() );
9017                 return false;
9018             }
9019             //
9020             final String p0000_str = "A";
9021             p.setSource( p0000_str );
9022             final Phylogeny p0000 = p.next();
9023             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
9024                 System.out.println( p0000.toNewHampshire() );
9025                 return false;
9026             }
9027             //
9028             p.setSource( "(A)" );
9029             final Phylogeny p00000 = p.next();
9030             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
9031                 System.out.println( p00000.toNewHampshire() );
9032                 return false;
9033             }
9034             //
9035             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
9036             p.setSource( p1_str );
9037             if ( !p.hasNext() ) {
9038                 return false;
9039             }
9040             final Phylogeny p1_0 = p.next();
9041             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
9042                 System.out.println( p1_0.toNewHampshire() );
9043                 return false;
9044             }
9045             if ( !p.hasNext() ) {
9046                 return false;
9047             }
9048             final Phylogeny p1_1 = p.next();
9049             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
9050                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
9051                 return false;
9052             }
9053             if ( !p.hasNext() ) {
9054                 return false;
9055             }
9056             final Phylogeny p1_2 = p.next();
9057             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
9058                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
9059                 return false;
9060             }
9061             if ( !p.hasNext() ) {
9062                 return false;
9063             }
9064             final Phylogeny p1_3 = p.next();
9065             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
9066                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
9067                 return false;
9068             }
9069             if ( p.hasNext() ) {
9070                 return false;
9071             }
9072             if ( p.next() != null ) {
9073                 return false;
9074             }
9075             //
9076             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
9077             p.setSource( p2_str );
9078             if ( !p.hasNext() ) {
9079                 return false;
9080             }
9081             Phylogeny p2_0 = p.next();
9082             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9083                 System.out.println( p2_0.toNewHampshire() );
9084                 return false;
9085             }
9086             if ( !p.hasNext() ) {
9087                 return false;
9088             }
9089             Phylogeny p2_1 = p.next();
9090             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9091                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9092                 return false;
9093             }
9094             if ( !p.hasNext() ) {
9095                 return false;
9096             }
9097             Phylogeny p2_2 = p.next();
9098             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9099                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9100                 return false;
9101             }
9102             if ( !p.hasNext() ) {
9103                 return false;
9104             }
9105             Phylogeny p2_3 = p.next();
9106             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9107                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9108                 return false;
9109             }
9110             if ( !p.hasNext() ) {
9111                 return false;
9112             }
9113             Phylogeny p2_4 = p.next();
9114             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9115                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9116                 return false;
9117             }
9118             if ( p.hasNext() ) {
9119                 return false;
9120             }
9121             if ( p.next() != null ) {
9122                 return false;
9123             }
9124             ////
9125             p.reset();
9126             if ( !p.hasNext() ) {
9127                 return false;
9128             }
9129             p2_0 = p.next();
9130             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
9131                 System.out.println( p2_0.toNewHampshire() );
9132                 return false;
9133             }
9134             if ( !p.hasNext() ) {
9135                 return false;
9136             }
9137             p2_1 = p.next();
9138             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
9139                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
9140                 return false;
9141             }
9142             if ( !p.hasNext() ) {
9143                 return false;
9144             }
9145             p2_2 = p.next();
9146             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
9147                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
9148                 return false;
9149             }
9150             if ( !p.hasNext() ) {
9151                 return false;
9152             }
9153             p2_3 = p.next();
9154             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
9155                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
9156                 return false;
9157             }
9158             if ( !p.hasNext() ) {
9159                 return false;
9160             }
9161             p2_4 = p.next();
9162             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
9163                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
9164                 return false;
9165             }
9166             if ( p.hasNext() ) {
9167                 return false;
9168             }
9169             if ( p.next() != null ) {
9170                 return false;
9171             }
9172             //
9173             final String p3_str = "((A,B),C)abc";
9174             p.setSource( p3_str );
9175             if ( !p.hasNext() ) {
9176                 return false;
9177             }
9178             final Phylogeny p3_0 = p.next();
9179             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
9180                 return false;
9181             }
9182             if ( p.hasNext() ) {
9183                 return false;
9184             }
9185             if ( p.next() != null ) {
9186                 return false;
9187             }
9188             //
9189             final String p4_str = "((A,B)ab,C)abc";
9190             p.setSource( p4_str );
9191             if ( !p.hasNext() ) {
9192                 return false;
9193             }
9194             final Phylogeny p4_0 = p.next();
9195             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
9196                 return false;
9197             }
9198             if ( p.hasNext() ) {
9199                 return false;
9200             }
9201             if ( p.next() != null ) {
9202                 return false;
9203             }
9204             //
9205             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
9206             p.setSource( p5_str );
9207             if ( !p.hasNext() ) {
9208                 return false;
9209             }
9210             final Phylogeny p5_0 = p.next();
9211             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
9212                 return false;
9213             }
9214             if ( p.hasNext() ) {
9215                 return false;
9216             }
9217             if ( p.next() != null ) {
9218                 return false;
9219             }
9220             //
9221             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
9222             p.setSource( p6_str );
9223             if ( !p.hasNext() ) {
9224                 return false;
9225             }
9226             Phylogeny p6_0 = p.next();
9227             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9228                 return false;
9229             }
9230             if ( p.hasNext() ) {
9231                 return false;
9232             }
9233             if ( p.next() != null ) {
9234                 return false;
9235             }
9236             p.reset();
9237             if ( !p.hasNext() ) {
9238                 return false;
9239             }
9240             p6_0 = p.next();
9241             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
9242                 return false;
9243             }
9244             if ( p.hasNext() ) {
9245                 return false;
9246             }
9247             if ( p.next() != null ) {
9248                 return false;
9249             }
9250             //
9251             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
9252             p.setSource( p7_str );
9253             if ( !p.hasNext() ) {
9254                 return false;
9255             }
9256             Phylogeny p7_0 = p.next();
9257             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9258                 return false;
9259             }
9260             if ( p.hasNext() ) {
9261                 return false;
9262             }
9263             if ( p.next() != null ) {
9264                 return false;
9265             }
9266             p.reset();
9267             if ( !p.hasNext() ) {
9268                 return false;
9269             }
9270             p7_0 = p.next();
9271             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9272                 return false;
9273             }
9274             if ( p.hasNext() ) {
9275                 return false;
9276             }
9277             if ( p.next() != null ) {
9278                 return false;
9279             }
9280             //
9281             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
9282             p.setSource( p8_str );
9283             if ( !p.hasNext() ) {
9284                 return false;
9285             }
9286             Phylogeny p8_0 = p.next();
9287             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9288                 return false;
9289             }
9290             if ( !p.hasNext() ) {
9291                 return false;
9292             }
9293             if ( !p.hasNext() ) {
9294                 return false;
9295             }
9296             Phylogeny p8_1 = p.next();
9297             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9298                 return false;
9299             }
9300             if ( p.hasNext() ) {
9301                 return false;
9302             }
9303             if ( p.next() != null ) {
9304                 return false;
9305             }
9306             p.reset();
9307             if ( !p.hasNext() ) {
9308                 return false;
9309             }
9310             p8_0 = p.next();
9311             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
9312                 return false;
9313             }
9314             if ( !p.hasNext() ) {
9315                 return false;
9316             }
9317             p8_1 = p.next();
9318             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
9319                 return false;
9320             }
9321             if ( p.hasNext() ) {
9322                 return false;
9323             }
9324             if ( p.next() != null ) {
9325                 return false;
9326             }
9327             p.reset();
9328             //
9329             p.setSource( "" );
9330             if ( p.hasNext() ) {
9331                 return false;
9332             }
9333             //
9334             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
9335             if ( !p.hasNext() ) {
9336                 return false;
9337             }
9338             Phylogeny p_27 = p.next();
9339             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9340                 System.out.println( p_27.toNewHampshireX() );
9341                 System.exit( -1 );
9342                 return false;
9343             }
9344             if ( p.hasNext() ) {
9345                 return false;
9346             }
9347             if ( p.next() != null ) {
9348                 return false;
9349             }
9350             p.reset();
9351             if ( !p.hasNext() ) {
9352                 return false;
9353             }
9354             p_27 = p.next();
9355             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
9356                 System.out.println( p_27.toNewHampshireX() );
9357                 System.exit( -1 );
9358                 return false;
9359             }
9360             if ( p.hasNext() ) {
9361                 return false;
9362             }
9363             if ( p.next() != null ) {
9364                 return false;
9365             }
9366             //
9367             final String p30_str = "(A,B);(C,D)";
9368             final NHXParser p30 = new NHXParser();
9369             p30.setSource( p30_str );
9370             if ( !p30.hasNext() ) {
9371                 return false;
9372             }
9373             Phylogeny phy30 = p30.next();
9374             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9375                 System.out.println( phy30.toNewHampshire() );
9376                 return false;
9377             }
9378             if ( !p30.hasNext() ) {
9379                 return false;
9380             }
9381             Phylogeny phy301 = p30.next();
9382             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9383                 System.out.println( phy301.toNewHampshire() );
9384                 return false;
9385             }
9386             if ( p30.hasNext() ) {
9387                 return false;
9388             }
9389             if ( p30.hasNext() ) {
9390                 return false;
9391             }
9392             if ( p30.next() != null ) {
9393                 return false;
9394             }
9395             if ( p30.next() != null ) {
9396                 return false;
9397             }
9398             p30.reset();
9399             if ( !p30.hasNext() ) {
9400                 return false;
9401             }
9402             phy30 = p30.next();
9403             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
9404                 System.out.println( phy30.toNewHampshire() );
9405                 return false;
9406             }
9407             if ( !p30.hasNext() ) {
9408                 return false;
9409             }
9410             phy301 = p30.next();
9411             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9412                 System.out.println( phy301.toNewHampshire() );
9413                 return false;
9414             }
9415             if ( p30.hasNext() ) {
9416                 return false;
9417             }
9418             if ( p30.hasNext() ) {
9419                 return false;
9420             }
9421             if ( p30.next() != null ) {
9422                 return false;
9423             }
9424             if ( p30.next() != null ) {
9425                 return false;
9426             }
9427         }
9428         catch ( final Exception e ) {
9429             e.printStackTrace( System.out );
9430             return false;
9431         }
9432         return true;
9433     }
9434
9435     private static boolean testNHXconversion() {
9436         try {
9437             final PhylogenyNode n1 = new PhylogenyNode();
9438             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9439             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9440             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9441             final PhylogenyNode n5 = PhylogenyNode
9442                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
9443             final PhylogenyNode n6 = PhylogenyNode
9444                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
9445             if ( !n1.toNewHampshireX().equals( "" ) ) {
9446                 return false;
9447             }
9448             if ( !n2.toNewHampshireX().equals( "" ) ) {
9449                 return false;
9450             }
9451             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
9452                 return false;
9453             }
9454             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
9455                 return false;
9456             }
9457             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
9458                 return false;
9459             }
9460             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9461                 System.out.println( n6.toNewHampshireX() );
9462                 return false;
9463             }
9464             final PhylogenyNode n7 = new PhylogenyNode();
9465             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9466             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9467                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9468                 System.out.println( n7
9469                                     .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9470                 return false;
9471             }
9472         }
9473         catch ( final Exception e ) {
9474             e.printStackTrace( System.out );
9475             return false;
9476         }
9477         return true;
9478     }
9479
9480     private static boolean testNHXNodeParsing() {
9481         try {
9482             final PhylogenyNode n1 = new PhylogenyNode();
9483             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9484             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9485             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9486             final PhylogenyNode n5 = PhylogenyNode
9487                     .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]" );
9488             if ( !n3.getName().equals( "n3" ) ) {
9489                 return false;
9490             }
9491             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9492                 return false;
9493             }
9494             if ( n3.isDuplication() ) {
9495                 return false;
9496             }
9497             if ( n3.isHasAssignedEvent() ) {
9498                 return false;
9499             }
9500             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9501                 return false;
9502             }
9503             if ( !n4.getName().equals( "n4" ) ) {
9504                 return false;
9505             }
9506             if ( n4.getDistanceToParent() != 0.01 ) {
9507                 return false;
9508             }
9509             if ( !n5.getName().equals( "n5" ) ) {
9510                 return false;
9511             }
9512             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9513                 return false;
9514             }
9515             if ( n5.getDistanceToParent() != 0.1 ) {
9516                 return false;
9517             }
9518             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9519                 return false;
9520             }
9521             if ( !n5.isDuplication() ) {
9522                 return false;
9523             }
9524             if ( !n5.isHasAssignedEvent() ) {
9525                 return false;
9526             }
9527             final PhylogenyNode n8 = PhylogenyNode
9528                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9529                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9530             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9531                 return false;
9532             }
9533             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9534                 return false;
9535             }
9536             final PhylogenyNode n9 = PhylogenyNode
9537                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9538                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9539             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9540                 return false;
9541             }
9542             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9543                 return false;
9544             }
9545             final PhylogenyNode n10 = PhylogenyNode
9546                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9547             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9548                 return false;
9549             }
9550             final PhylogenyNode n20 = PhylogenyNode
9551                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9552             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9553                 return false;
9554             }
9555             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9556                 return false;
9557             }
9558             final PhylogenyNode n20x = PhylogenyNode
9559                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9560             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9561                 return false;
9562             }
9563             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9564                 return false;
9565             }
9566             final PhylogenyNode n20xx = PhylogenyNode
9567                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9568             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9569                 return false;
9570             }
9571             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9572                 return false;
9573             }
9574             final PhylogenyNode n20xxx = PhylogenyNode
9575                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9576             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9577                 return false;
9578             }
9579             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9580                 return false;
9581             }
9582             final PhylogenyNode n20xxxx = PhylogenyNode
9583                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9584             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9585                 return false;
9586             }
9587             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9588                 return false;
9589             }
9590             final PhylogenyNode n21 = PhylogenyNode
9591                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9592             if ( !n21.getName().equals( "N21_PIG" ) ) {
9593                 return false;
9594             }
9595             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9596                 return false;
9597             }
9598             final PhylogenyNode n21x = PhylogenyNode
9599                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9600             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9601                 return false;
9602             }
9603             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9604                 return false;
9605             }
9606             final PhylogenyNode n22 = PhylogenyNode
9607                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9608             if ( !n22.getName().equals( "n22/PIG" ) ) {
9609                 return false;
9610             }
9611             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9612                 return false;
9613             }
9614             final PhylogenyNode n23 = PhylogenyNode
9615                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9616             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9617                 return false;
9618             }
9619             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9620                 return false;
9621             }
9622             final PhylogenyNode a = PhylogenyNode
9623                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9624             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9625                 return false;
9626             }
9627             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9628                 return false;
9629             }
9630             final PhylogenyNode c1 = PhylogenyNode
9631                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9632                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9633             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9634                 return false;
9635             }
9636             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9637                 return false;
9638             }
9639             final PhylogenyNode c2 = PhylogenyNode
9640                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9641                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9642             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9643                 return false;
9644             }
9645             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9646                 return false;
9647             }
9648             final PhylogenyNode e3 = PhylogenyNode
9649                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9650             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9651                 return false;
9652             }
9653             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9654                 return false;
9655             }
9656             final PhylogenyNode n11 = PhylogenyNode
9657                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9658                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9659             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9660                 return false;
9661             }
9662             if ( n11.getDistanceToParent() != 0.4 ) {
9663                 return false;
9664             }
9665             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9666                 return false;
9667             }
9668             final PhylogenyNode n12 = PhylogenyNode
9669                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9670                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9671             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9672                 return false;
9673             }
9674             if ( n12.getDistanceToParent() != 0.4 ) {
9675                 return false;
9676             }
9677             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9678                 return false;
9679             }
9680             final PhylogenyNode o = PhylogenyNode
9681                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9682             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9683                 return false;
9684             }
9685             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9686                 return false;
9687             }
9688             if ( n1.getName().compareTo( "" ) != 0 ) {
9689                 return false;
9690             }
9691             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9692                 return false;
9693             }
9694             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9695                 return false;
9696             }
9697             if ( n2.getName().compareTo( "" ) != 0 ) {
9698                 return false;
9699             }
9700             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9701                 return false;
9702             }
9703             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9704                 return false;
9705             }
9706             final PhylogenyNode n00 = PhylogenyNode
9707                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9708             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9709                 return false;
9710             }
9711             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9712                 return false;
9713             }
9714             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9715             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9716                 return false;
9717             }
9718             final PhylogenyNode n13 = PhylogenyNode
9719                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9720             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9721                 return false;
9722             }
9723             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9724                 return false;
9725             }
9726             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9727                 return false;
9728             }
9729             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9730                 return false;
9731             }
9732             final PhylogenyNode n14 = PhylogenyNode
9733                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9734             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9735                 return false;
9736             }
9737             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9738                 return false;
9739             }
9740             final PhylogenyNode n15 = PhylogenyNode
9741                     .createInstanceFromNhxString( "something_wicked[123]",
9742                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9743             if ( !n15.getName().equals( "something_wicked" ) ) {
9744                 return false;
9745             }
9746             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9747                 return false;
9748             }
9749             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9750                 return false;
9751             }
9752             final PhylogenyNode n16 = PhylogenyNode
9753                     .createInstanceFromNhxString( "something_wicked2[9]",
9754                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9755             if ( !n16.getName().equals( "something_wicked2" ) ) {
9756                 return false;
9757             }
9758             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9759                 return false;
9760             }
9761             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9762                 return false;
9763             }
9764             final PhylogenyNode n17 = PhylogenyNode
9765                     .createInstanceFromNhxString( "something_wicked3[a]",
9766                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9767             if ( !n17.getName().equals( "something_wicked3" ) ) {
9768                 return false;
9769             }
9770             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9771                 return false;
9772             }
9773             final PhylogenyNode n18 = PhylogenyNode
9774                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9775             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9776                 return false;
9777             }
9778             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9779                 return false;
9780             }
9781             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9782                 return false;
9783             }
9784             final PhylogenyNode n19 = PhylogenyNode
9785                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9786             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9787                 return false;
9788             }
9789             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9790                 return false;
9791             }
9792             final PhylogenyNode n30 = PhylogenyNode
9793                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9794                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9795             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9796                 return false;
9797             }
9798             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9799                 return false;
9800             }
9801             final PhylogenyNode n31 = PhylogenyNode
9802                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9803                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9804             if ( n31.getNodeData().isHasTaxonomy() ) {
9805                 return false;
9806             }
9807             final PhylogenyNode n32 = PhylogenyNode
9808                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9809             if ( n32.getNodeData().isHasTaxonomy() ) {
9810                 return false;
9811             }
9812             final PhylogenyNode n40 = PhylogenyNode
9813                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9814             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9815                 return false;
9816             }
9817             final PhylogenyNode n41 = PhylogenyNode
9818                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9819             if ( n41.getNodeData().isHasTaxonomy() ) {
9820                 return false;
9821             }
9822             final PhylogenyNode n42 = PhylogenyNode
9823                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9824             if ( n42.getNodeData().isHasTaxonomy() ) {
9825                 return false;
9826             }
9827             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9828                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9829             if ( n43.getNodeData().isHasTaxonomy() ) {
9830                 return false;
9831             }
9832             final PhylogenyNode n44 = PhylogenyNode
9833                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9834             if ( n44.getNodeData().isHasTaxonomy() ) {
9835                 return false;
9836             }
9837         }
9838         catch ( final Exception e ) {
9839             e.printStackTrace( System.out );
9840             return false;
9841         }
9842         return true;
9843     }
9844
9845     
9846     private static boolean testNHXNodeParsing2() {
9847         try {
9848           
9849             final PhylogenyNode n0_0 = PhylogenyNode
9850                     .createInstanceFromNhxString( "n0:[ignore me 123]:1E-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9851             if ( !n0_0.getName().equals( "n0" ) ) {
9852                 return false;
9853             }
9854             if ( !isEqual( n0_0.getDistanceToParent(), 0.001 ) ) {
9855                 return false;
9856             }
9857             final PhylogenyNode n0_1 = PhylogenyNode
9858                     .createInstanceFromNhxString( "n0[ignore me 123]:1E-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9859             if ( !n0_1.getName().equals( "n0" ) ) {
9860                 return false;
9861             }
9862             if ( !isEqual( n0_1.getDistanceToParent(), 0.001 ) ) {
9863                 return false;
9864             }
9865             final PhylogenyNode n0_2 = PhylogenyNode
9866                     .createInstanceFromNhxString( "n0:1E-3[ignore me 123]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9867             if ( !n0_2.getName().equals( "n0" ) ) {
9868                 return false;
9869             }
9870             if ( !isEqual( n0_2.getDistanceToParent(), 0.001 ) ) {
9871                 return false;
9872             }
9873             final PhylogenyNode n0_3 = PhylogenyNode
9874                     .createInstanceFromNhxString( "n0:1E-3:[ignore me 123]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9875             if ( !n0_3.getName().equals( "n0" ) ) {
9876                 return false;
9877             }
9878             if ( !isEqual( n0_3.getDistanceToParent(), 0.001 ) ) {
9879                 return false;
9880             }
9881             final PhylogenyNode n0_4 = PhylogenyNode
9882                     .createInstanceFromNhxString( "n0:0.001:[ignore me 123]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9883             if ( !n0_4.getName().equals( "n0" ) ) {
9884                 return false;
9885             }
9886             if ( !isEqual( n0_4.getDistanceToParent(), 0.001 ) ) {
9887                 return false;
9888             }
9889             final PhylogenyNode n1_0 = PhylogenyNode
9890                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9891             if ( !n1_0.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9892                 return false;
9893             }
9894             if ( n1_0.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
9895                return false;
9896             }
9897             final PhylogenyNode n1_1 = PhylogenyNode
9898                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]:0.001", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9899             if ( !n1_1.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9900                 return false;
9901             }
9902             if ( n1_1.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
9903                return false;
9904             }
9905             if ( !isEqual( n1_1.getDistanceToParent(), 0.001 ) ) {
9906                 return false;
9907             }
9908             final PhylogenyNode n1_2 = PhylogenyNode
9909                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:0.001[&!color=#FFFFFF]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9910             if ( !n1_2.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9911                 return false;
9912             }
9913             if ( n1_2.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
9914                return false;
9915             }
9916             if ( !isEqual( n1_2.getDistanceToParent(), 0.001 ) ) {
9917                 return false;
9918             }
9919             final PhylogenyNode n1_3 = PhylogenyNode
9920                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[&boostrap=69,&!color=#FFFFFF]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9921             if ( !n1_3.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9922                 return false;
9923             }
9924             if ( n1_3.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
9925                return false;
9926             }
9927             if ( !isEqual( n1_3.getDistanceToParent(), 0.001 ) ) {
9928                 return false;
9929             }
9930             if ( !isEqual( n1_3.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
9931                 return false;
9932             }
9933             if ( !n1_3.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
9934                 return false;
9935             }
9936             final PhylogenyNode n1_4 = PhylogenyNode
9937                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&bootstrap=69,&!colour=#FFFFFF]:1e-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9938             if ( !n1_4.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9939                 return false;
9940             }
9941             if ( n1_4.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
9942                return false;
9943             }
9944             if ( !isEqual( n1_4.getDistanceToParent(), 0.001 ) ) {
9945                 return false;
9946             }
9947             if ( !isEqual( n1_4.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
9948                 return false;
9949             }
9950             if ( !n1_4.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
9951                 return false;
9952             }
9953             final PhylogenyNode n1_5 = PhylogenyNode
9954                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[69.0]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9955             if ( !n1_5.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9956                 return false;
9957             }
9958             if ( !isEqual( n1_5.getDistanceToParent(), 0.001 ) ) {
9959                 return false;
9960             }
9961             if ( !isEqual( n1_5.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
9962                 return false;
9963             }       
9964             final PhylogenyNode n1_6 = PhylogenyNode
9965                     .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00]:1e-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
9966             if ( !n1_6.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
9967                 return false;
9968             }
9969            
9970             if ( !isEqual( n1_6.getDistanceToParent(), 0.001 ) ) {
9971                 return false;
9972             }
9973             if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getStandardDeviation(), 0.11 ) ) {
9974                 return false;
9975             }
9976             if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getValue(), 0.95 ) ) {
9977                 return false;
9978             }
9979             if ( !n1_6.getBranchData().getConfidence( 0 ).getType().equals( "posterior probability" ) ) {
9980                 return false;
9981             }
9982         }
9983         catch ( final Exception e ) {
9984             e.printStackTrace( System.out );
9985             return false;
9986         }
9987         return true;
9988     }
9989     
9990     private static boolean testNHXParsing() {
9991         try {
9992             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9993             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9994             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9995                 return false;
9996             }
9997             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]";
9998             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9999             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10000                 return false;
10001             }
10002             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]";
10003             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
10004             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
10005                 return false;
10006             }
10007             final Phylogeny[] p3 = factory
10008                     .create( "[  comment&&NHX,())))](((((((A:0.2[&&NHX:S=qwerty]):0.2[&&NHX:S=uiop]):0.3[&&NHX:S=asdf]):0.4[&&NHX:S=zxc]):0.5[&&NHX:S=a]):0.6[&&NHX:S=asd]):0.7[&&NHX:S=za]):0.8[&&NHX:S=zaq]",
10009                              new NHXParser() );
10010             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10011                 return false;
10012             }
10013             final Phylogeny[] p4 = factory
10014                     .create( "(((((((A:0.2[&&NHX:S=qwerty]):0.2[&&NHX:S=uiop]):0.3[&&NHX:S=asdf]):0.4[&&NHX:S=zxc]):0.5[&&NHX:S=a]):0.6[&&NHX:S=asd]):0.7[&&NHX:S=za]):0.8[&&NHX:S=zaq][comment(]",
10015                              new NHXParser() );
10016             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10017                 return false;
10018             }
10019             final Phylogeny[] p5 = factory
10020                     .create( "[]  (  [][ ][   ]  ([((( &&NHXcomment only![[[[[[]([]((((A:0.2[&&NHX:S=q[comment )))]werty][,,,,))]):0.2[&&NHX:S=uiop]):0.3[&&NHX:S=a[comment,,))]sdf])[comment(((]:0.4[&&NHX:S=zxc][comment(((][comment(((]):0.5[&&NHX:S=a]):0.6[&&NHX:S=a[comment(((]sd]):0.7[&&NHX:S=za]):0.8[&&NHX:S=zaq][comment(((]",
10021                              new NHXParser() );
10022             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
10023                 return false;
10024             }
10025             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)";
10026             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)";
10027             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
10028             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
10029                 return false;
10030             }
10031             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)))";
10032             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)))";
10033             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
10034             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
10035                 return false;
10036             }
10037             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])   ))[,,, ])))))))";
10038             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
10039             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
10040             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
10041                 return false;
10042             }
10043             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
10044             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10045                 return false;
10046             }
10047             final Phylogeny p10 = factory
10048                     .create( " [79]   ( (A [co mment] :0 .2[comment],B:0.3[com])[com ment]: 0. 5 \t[ 9 1 ][ comment],C: 0.1)[comment]root:0.1[100] [comment]",
10049                              new NHXParser() )[ 0 ];
10050             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10051                 return false;
10052             }
10053             final Phylogeny p11 = factory
10054                     .create( " [79]   ( ('A: \" ' [co mment] :0 .2[comment],B:0.3[com])[com ment]: 0. 5 \t[ 9 1 ][ comment],C: 0.1)[comment]root:0.1[100] [comment]",
10055                              new NHXParser() )[ 0 ];
10056             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10057                 return false;
10058             }
10059             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]",
10060                                                   new NHXParser() )[ 0 ];
10061             if ( !p12.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
10062                 return false;
10063             }
10064         }
10065         catch ( final Exception e ) {
10066             e.printStackTrace( System.out );
10067             return false;
10068         }
10069         return true;
10070     }
10071
10072     private static boolean testNHXParsingMB() {
10073         try {
10074             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10075             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
10076                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10077                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
10078                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
10079                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
10080                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10081                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
10082                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
10083                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
10084             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
10085                 return false;
10086             }
10087             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
10088                 return false;
10089             }
10090             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
10091                            0.1100000000000000e+00 ) ) {
10092                 return false;
10093             }
10094             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
10095                 return false;
10096             }
10097             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
10098                 return false;
10099             }
10100             final Phylogeny p2 = factory
10101                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
10102                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10103                             + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
10104                             + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
10105                             + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
10106                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
10107                             + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
10108                             + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
10109                             + "7.369400000000000e-02}])",
10110                             new NHXParser() )[ 0 ];
10111             if ( p2.getNode( "1" ) == null ) {
10112                 return false;
10113             }
10114             if ( p2.getNode( "2" ) == null ) {
10115                 return false;
10116             }
10117         }
10118         catch ( final Exception e ) {
10119             e.printStackTrace( System.out );
10120             System.exit( -1 );
10121             return false;
10122         }
10123         return true;
10124     }
10125
10126     private static boolean testNHXParsingQuotes() {
10127         try {
10128             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10129             final NHXParser p = new NHXParser();
10130             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
10131             if ( phylogenies_0.length != 5 ) {
10132                 return false;
10133             }
10134             final Phylogeny phy = phylogenies_0[ 4 ];
10135             if ( phy.getNumberOfExternalNodes() != 7 ) {
10136                 return false;
10137             }
10138             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
10139                 return false;
10140             }
10141             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
10142                 return false;
10143             }
10144             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
10145                     .getScientificName().equals( "hsapiens" ) ) {
10146                 return false;
10147             }
10148             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
10149                 return false;
10150             }
10151             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
10152                 return false;
10153             }
10154             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
10155                 return false;
10156             }
10157             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
10158                 return false;
10159             }
10160             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
10161                 return false;
10162             }
10163             final NHXParser p1p = new NHXParser();
10164             p1p.setIgnoreQuotes( true );
10165             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
10166             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
10167                 return false;
10168             }
10169             final NHXParser p2p = new NHXParser();
10170             p1p.setIgnoreQuotes( false );
10171             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
10172             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
10173                 return false;
10174             }
10175             final NHXParser p3p = new NHXParser();
10176             p3p.setIgnoreQuotes( false );
10177             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
10178             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
10179                 return false;
10180             }
10181             final NHXParser p4p = new NHXParser();
10182             p4p.setIgnoreQuotes( false );
10183             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
10184             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
10185                 return false;
10186             }
10187             final Phylogeny p10 = factory
10188                     .create( " [79]   ( (\"A \n\tB \" [co mment] :0 .2[comment],'B':0.3[com])[com ment]: 0. 5 \t[ 9 1 ][ comment],'C (or D?\\//;,))': 0.1)[comment]'\nroot is here (cool,  was! ) ':0.1[100] [comment]",
10189                              new NHXParser() )[ 0 ];
10190             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]";
10191             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
10192                 return false;
10193             }
10194             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
10195             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
10196                 return false;
10197             }
10198             final Phylogeny p12 = factory
10199                     .create( " [79]   ( (\"A \n\tB \" [[][] :0 .2[comment][\t&\t&\n N\tH\tX:S=mo\tnkey !],'\tB\t\b\t\n\f\rB B ':0.0\b3[])\t[com ment]: 0. 5 \t[ 9 1 ][ \ncomment],'C\t (or D?\\//;,))': 0.\b1)[comment]'\nroot \tis here (cool, \b\t\n\f\r was! ) ':0.1[100] [comment]",
10200                              new NHXParser() )[ 0 ];
10201             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]";
10202             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
10203                 return false;
10204             }
10205             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
10206             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
10207                 return false;
10208             }
10209             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;";
10210             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
10211                 return false;
10212             }
10213             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
10214             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
10215                 return false;
10216             }
10217         }
10218         catch ( final Exception e ) {
10219             e.printStackTrace( System.out );
10220             return false;
10221         }
10222         return true;
10223     }
10224
10225     private static boolean testNodeRemoval() {
10226         try {
10227             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10228             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
10229             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
10230             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
10231                 return false;
10232             }
10233             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
10234             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
10235             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
10236                 return false;
10237             }
10238             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
10239             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
10240             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
10241                 return false;
10242             }
10243         }
10244         catch ( final Exception e ) {
10245             e.printStackTrace( System.out );
10246             return false;
10247         }
10248         return true;
10249     }
10250
10251     private static boolean testPhylogenyBranch() {
10252         try {
10253             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
10254             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
10255             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
10256             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
10257             if ( !a1b1.equals( a1b1 ) ) {
10258                 return false;
10259             }
10260             if ( !a1b1.equals( b1a1 ) ) {
10261                 return false;
10262             }
10263             if ( !b1a1.equals( a1b1 ) ) {
10264                 return false;
10265             }
10266             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
10267             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
10268             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
10269             if ( a1_b1.equals( b1_a1 ) ) {
10270                 return false;
10271             }
10272             if ( a1_b1.equals( a1_b1_ ) ) {
10273                 return false;
10274             }
10275             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
10276             if ( !a1_b1.equals( b1_a1_ ) ) {
10277                 return false;
10278             }
10279             if ( a1_b1_.equals( b1_a1_ ) ) {
10280                 return false;
10281             }
10282             if ( !a1_b1_.equals( b1_a1 ) ) {
10283                 return false;
10284             }
10285         }
10286         catch ( final Exception e ) {
10287             e.printStackTrace( System.out );
10288             return false;
10289         }
10290         return true;
10291     }
10292
10293     private static boolean testPhyloXMLparsingOfDistributionElement() {
10294         try {
10295             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10296             PhyloXmlParser xml_parser = null;
10297             try {
10298                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
10299             }
10300             catch ( final Exception e ) {
10301                 // Do nothing -- means were not running from jar.
10302             }
10303             if ( xml_parser == null ) {
10304                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
10305                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
10306                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
10307                 }
10308                 else {
10309                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
10310                 }
10311             }
10312             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml" ),
10313                                                               xml_parser );
10314             if ( xml_parser.getErrorCount() > 0 ) {
10315                 System.out.println( xml_parser.getErrorMessages().toString() );
10316                 return false;
10317             }
10318             if ( phylogenies_0.length != 1 ) {
10319                 return false;
10320             }
10321             final Phylogeny t1 = phylogenies_0[ 0 ];
10322             PhylogenyNode n = null;
10323             Distribution d = null;
10324             n = t1.getNode( "root node" );
10325             if ( !n.getNodeData().isHasDistribution() ) {
10326                 return false;
10327             }
10328             if ( n.getNodeData().getDistributions().size() != 1 ) {
10329                 return false;
10330             }
10331             d = n.getNodeData().getDistribution();
10332             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10333                 return false;
10334             }
10335             if ( d.getPoints().size() != 1 ) {
10336                 return false;
10337             }
10338             if ( d.getPolygons() != null ) {
10339                 return false;
10340             }
10341             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10342                 return false;
10343             }
10344             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10345                 return false;
10346             }
10347             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10348                 return false;
10349             }
10350             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10351                 return false;
10352             }
10353             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10354                 return false;
10355             }
10356             n = t1.getNode( "node a" );
10357             if ( !n.getNodeData().isHasDistribution() ) {
10358                 return false;
10359             }
10360             if ( n.getNodeData().getDistributions().size() != 2 ) {
10361                 return false;
10362             }
10363             d = n.getNodeData().getDistribution( 1 );
10364             if ( !d.getDesc().equals( "San Diego" ) ) {
10365                 return false;
10366             }
10367             if ( d.getPoints().size() != 1 ) {
10368                 return false;
10369             }
10370             if ( d.getPolygons() != null ) {
10371                 return false;
10372             }
10373             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10374                 return false;
10375             }
10376             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10377                 return false;
10378             }
10379             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10380                 return false;
10381             }
10382             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10383                 return false;
10384             }
10385             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10386                 return false;
10387             }
10388             n = t1.getNode( "node bb" );
10389             if ( !n.getNodeData().isHasDistribution() ) {
10390                 return false;
10391             }
10392             if ( n.getNodeData().getDistributions().size() != 1 ) {
10393                 return false;
10394             }
10395             d = n.getNodeData().getDistribution( 0 );
10396             if ( d.getPoints().size() != 3 ) {
10397                 return false;
10398             }
10399             if ( d.getPolygons().size() != 2 ) {
10400                 return false;
10401             }
10402             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10403                 return false;
10404             }
10405             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10406                 return false;
10407             }
10408             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10409                 return false;
10410             }
10411             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10412                 return false;
10413             }
10414             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10415                 return false;
10416             }
10417             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10418                 return false;
10419             }
10420             Polygon p = d.getPolygons().get( 0 );
10421             if ( p.getPoints().size() != 3 ) {
10422                 return false;
10423             }
10424             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10425                 return false;
10426             }
10427             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10428                 return false;
10429             }
10430             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10431                 return false;
10432             }
10433             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10434                 return false;
10435             }
10436             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10437                 return false;
10438             }
10439             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10440                 return false;
10441             }
10442             p = d.getPolygons().get( 1 );
10443             if ( p.getPoints().size() != 3 ) {
10444                 return false;
10445             }
10446             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10447                 return false;
10448             }
10449             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10450                 return false;
10451             }
10452             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10453                 return false;
10454             }
10455             // Roundtrip:
10456             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
10457             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
10458             if ( rt.length != 1 ) {
10459                 return false;
10460             }
10461             final Phylogeny t1_rt = rt[ 0 ];
10462             n = t1_rt.getNode( "root node" );
10463             if ( !n.getNodeData().isHasDistribution() ) {
10464                 return false;
10465             }
10466             if ( n.getNodeData().getDistributions().size() != 1 ) {
10467                 return false;
10468             }
10469             d = n.getNodeData().getDistribution();
10470             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
10471                 return false;
10472             }
10473             if ( d.getPoints().size() != 1 ) {
10474                 return false;
10475             }
10476             if ( d.getPolygons() != null ) {
10477                 return false;
10478             }
10479             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
10480                 return false;
10481             }
10482             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10483                 return false;
10484             }
10485             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10486                 return false;
10487             }
10488             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
10489                 return false;
10490             }
10491             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
10492                 return false;
10493             }
10494             n = t1_rt.getNode( "node a" );
10495             if ( !n.getNodeData().isHasDistribution() ) {
10496                 return false;
10497             }
10498             if ( n.getNodeData().getDistributions().size() != 2 ) {
10499                 return false;
10500             }
10501             d = n.getNodeData().getDistribution( 1 );
10502             if ( !d.getDesc().equals( "San Diego" ) ) {
10503                 return false;
10504             }
10505             if ( d.getPoints().size() != 1 ) {
10506                 return false;
10507             }
10508             if ( d.getPolygons() != null ) {
10509                 return false;
10510             }
10511             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
10512                 return false;
10513             }
10514             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
10515                 return false;
10516             }
10517             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
10518                 return false;
10519             }
10520             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
10521                 return false;
10522             }
10523             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
10524                 return false;
10525             }
10526             n = t1_rt.getNode( "node bb" );
10527             if ( !n.getNodeData().isHasDistribution() ) {
10528                 return false;
10529             }
10530             if ( n.getNodeData().getDistributions().size() != 1 ) {
10531                 return false;
10532             }
10533             d = n.getNodeData().getDistribution( 0 );
10534             if ( d.getPoints().size() != 3 ) {
10535                 return false;
10536             }
10537             if ( d.getPolygons().size() != 2 ) {
10538                 return false;
10539             }
10540             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
10541                 return false;
10542             }
10543             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
10544                 return false;
10545             }
10546             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
10547                 return false;
10548             }
10549             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
10550                 return false;
10551             }
10552             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
10553                 return false;
10554             }
10555             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10556                 return false;
10557             }
10558             p = d.getPolygons().get( 0 );
10559             if ( p.getPoints().size() != 3 ) {
10560                 return false;
10561             }
10562             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10563                 return false;
10564             }
10565             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10566                 return false;
10567             }
10568             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10569                 return false;
10570             }
10571             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10572                 return false;
10573             }
10574             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10575                 return false;
10576             }
10577             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10578                 return false;
10579             }
10580             p = d.getPolygons().get( 1 );
10581             if ( p.getPoints().size() != 3 ) {
10582                 return false;
10583             }
10584             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10585                 return false;
10586             }
10587             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10588                 return false;
10589             }
10590             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10591                 return false;
10592             }
10593         }
10594         catch ( final Exception e ) {
10595             e.printStackTrace( System.out );
10596             return false;
10597         }
10598         return true;
10599     }
10600
10601     private static boolean testPostOrderIterator() {
10602         try {
10603             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10604             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10605             PhylogenyNodeIterator it0;
10606             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
10607                 it0.next();
10608             }
10609             for( it0.reset(); it0.hasNext(); ) {
10610                 it0.next();
10611             }
10612             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10613             final PhylogenyNodeIterator it = t1.iteratorPostorder();
10614             if ( !it.next().getName().equals( "A" ) ) {
10615                 return false;
10616             }
10617             if ( !it.next().getName().equals( "B" ) ) {
10618                 return false;
10619             }
10620             if ( !it.next().getName().equals( "ab" ) ) {
10621                 return false;
10622             }
10623             if ( !it.next().getName().equals( "C" ) ) {
10624                 return false;
10625             }
10626             if ( !it.next().getName().equals( "D" ) ) {
10627                 return false;
10628             }
10629             if ( !it.next().getName().equals( "cd" ) ) {
10630                 return false;
10631             }
10632             if ( !it.next().getName().equals( "abcd" ) ) {
10633                 return false;
10634             }
10635             if ( !it.next().getName().equals( "E" ) ) {
10636                 return false;
10637             }
10638             if ( !it.next().getName().equals( "F" ) ) {
10639                 return false;
10640             }
10641             if ( !it.next().getName().equals( "ef" ) ) {
10642                 return false;
10643             }
10644             if ( !it.next().getName().equals( "G" ) ) {
10645                 return false;
10646             }
10647             if ( !it.next().getName().equals( "H" ) ) {
10648                 return false;
10649             }
10650             if ( !it.next().getName().equals( "gh" ) ) {
10651                 return false;
10652             }
10653             if ( !it.next().getName().equals( "efgh" ) ) {
10654                 return false;
10655             }
10656             if ( !it.next().getName().equals( "r" ) ) {
10657                 return false;
10658             }
10659             if ( it.hasNext() ) {
10660                 return false;
10661             }
10662         }
10663         catch ( final Exception e ) {
10664             e.printStackTrace( System.out );
10665             return false;
10666         }
10667         return true;
10668     }
10669
10670     private static boolean testPreOrderIterator() {
10671         try {
10672             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10673             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10674             PhylogenyNodeIterator it0;
10675             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10676                 it0.next();
10677             }
10678             for( it0.reset(); it0.hasNext(); ) {
10679                 it0.next();
10680             }
10681             PhylogenyNodeIterator it = t0.iteratorPreorder();
10682             if ( !it.next().getName().equals( "r" ) ) {
10683                 return false;
10684             }
10685             if ( !it.next().getName().equals( "ab" ) ) {
10686                 return false;
10687             }
10688             if ( !it.next().getName().equals( "A" ) ) {
10689                 return false;
10690             }
10691             if ( !it.next().getName().equals( "B" ) ) {
10692                 return false;
10693             }
10694             if ( !it.next().getName().equals( "cd" ) ) {
10695                 return false;
10696             }
10697             if ( !it.next().getName().equals( "C" ) ) {
10698                 return false;
10699             }
10700             if ( !it.next().getName().equals( "D" ) ) {
10701                 return false;
10702             }
10703             if ( it.hasNext() ) {
10704                 return false;
10705             }
10706             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10707             it = t1.iteratorPreorder();
10708             if ( !it.next().getName().equals( "r" ) ) {
10709                 return false;
10710             }
10711             if ( !it.next().getName().equals( "abcd" ) ) {
10712                 return false;
10713             }
10714             if ( !it.next().getName().equals( "ab" ) ) {
10715                 return false;
10716             }
10717             if ( !it.next().getName().equals( "A" ) ) {
10718                 return false;
10719             }
10720             if ( !it.next().getName().equals( "B" ) ) {
10721                 return false;
10722             }
10723             if ( !it.next().getName().equals( "cd" ) ) {
10724                 return false;
10725             }
10726             if ( !it.next().getName().equals( "C" ) ) {
10727                 return false;
10728             }
10729             if ( !it.next().getName().equals( "D" ) ) {
10730                 return false;
10731             }
10732             if ( !it.next().getName().equals( "efgh" ) ) {
10733                 return false;
10734             }
10735             if ( !it.next().getName().equals( "ef" ) ) {
10736                 return false;
10737             }
10738             if ( !it.next().getName().equals( "E" ) ) {
10739                 return false;
10740             }
10741             if ( !it.next().getName().equals( "F" ) ) {
10742                 return false;
10743             }
10744             if ( !it.next().getName().equals( "gh" ) ) {
10745                 return false;
10746             }
10747             if ( !it.next().getName().equals( "G" ) ) {
10748                 return false;
10749             }
10750             if ( !it.next().getName().equals( "H" ) ) {
10751                 return false;
10752             }
10753             if ( it.hasNext() ) {
10754                 return false;
10755             }
10756         }
10757         catch ( final Exception e ) {
10758             e.printStackTrace( System.out );
10759             return false;
10760         }
10761         return true;
10762     }
10763
10764     private static boolean testPropertiesMap() {
10765         try {
10766             final PropertiesMap pm = new PropertiesMap();
10767             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10768             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10769             final Property p2 = new Property( "something:else",
10770                                               "?",
10771                                               "improbable:research",
10772                                               "xsd:decimal",
10773                                               AppliesTo.NODE );
10774             pm.addProperty( p0 );
10775             pm.addProperty( p1 );
10776             pm.addProperty( p2 );
10777             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10778                 return false;
10779             }
10780             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10781                 return false;
10782             }
10783             if ( pm.getProperties().size() != 3 ) {
10784                 return false;
10785             }
10786             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10787                 return false;
10788             }
10789             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10790                 return false;
10791             }
10792             if ( pm.getProperties().size() != 3 ) {
10793                 return false;
10794             }
10795             pm.removeProperty( "dimensions:diameter" );
10796             if ( pm.getProperties().size() != 2 ) {
10797                 return false;
10798             }
10799             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10800                 return false;
10801             }
10802             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10803                 return false;
10804             }
10805         }
10806         catch ( final Exception e ) {
10807             e.printStackTrace( System.out );
10808             return false;
10809         }
10810         return true;
10811     }
10812
10813     private static boolean testProteinId() {
10814         try {
10815             final ProteinId id1 = new ProteinId( "a" );
10816             final ProteinId id2 = new ProteinId( "a" );
10817             final ProteinId id3 = new ProteinId( "A" );
10818             final ProteinId id4 = new ProteinId( "b" );
10819             if ( !id1.equals( id1 ) ) {
10820                 return false;
10821             }
10822             if ( id1.getId().equals( "x" ) ) {
10823                 return false;
10824             }
10825             if ( id1.getId().equals( null ) ) {
10826                 return false;
10827             }
10828             if ( !id1.equals( id2 ) ) {
10829                 return false;
10830             }
10831             if ( id1.equals( id3 ) ) {
10832                 return false;
10833             }
10834             if ( id1.hashCode() != id1.hashCode() ) {
10835                 return false;
10836             }
10837             if ( id1.hashCode() != id2.hashCode() ) {
10838                 return false;
10839             }
10840             if ( id1.hashCode() == id3.hashCode() ) {
10841                 return false;
10842             }
10843             if ( id1.compareTo( id1 ) != 0 ) {
10844                 return false;
10845             }
10846             if ( id1.compareTo( id2 ) != 0 ) {
10847                 return false;
10848             }
10849             if ( id1.compareTo( id3 ) != 0 ) {
10850                 return false;
10851             }
10852             if ( id1.compareTo( id4 ) >= 0 ) {
10853                 return false;
10854             }
10855             if ( id4.compareTo( id1 ) <= 0 ) {
10856                 return false;
10857             }
10858             if ( !id4.getId().equals( "b" ) ) {
10859                 return false;
10860             }
10861             final ProteinId id5 = new ProteinId( " C " );
10862             if ( !id5.getId().equals( "C" ) ) {
10863                 return false;
10864             }
10865             if ( id5.equals( id1 ) ) {
10866                 return false;
10867             }
10868         }
10869         catch ( final Exception e ) {
10870             e.printStackTrace( System.out );
10871             return false;
10872         }
10873         return true;
10874     }
10875
10876     private static boolean testReIdMethods() {
10877         try {
10878             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10879             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10880             final long count = PhylogenyNode.getNodeCount();
10881             p.levelOrderReID();
10882             if ( p.getNode( "r" ).getId() != count ) {
10883                 return false;
10884             }
10885             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10886                 return false;
10887             }
10888             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10889                 return false;
10890             }
10891             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10892                 return false;
10893             }
10894             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10895                 return false;
10896             }
10897             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10898                 return false;
10899             }
10900             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10901                 return false;
10902             }
10903             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10904                 return false;
10905             }
10906             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10907                 return false;
10908             }
10909             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10910                 return false;
10911             }
10912             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10913                 return false;
10914             }
10915             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10916                 return false;
10917             }
10918             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10919                 return false;
10920             }
10921             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10922                 return false;
10923             }
10924             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10925                 return false;
10926             }
10927         }
10928         catch ( final Exception e ) {
10929             e.printStackTrace( System.out );
10930             return false;
10931         }
10932         return true;
10933     }
10934
10935     private static boolean testRerooting() {
10936         try {
10937             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10938             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",
10939                                                  new NHXParser() )[ 0 ];
10940             if ( !t1.isRooted() ) {
10941                 return false;
10942             }
10943             t1.reRoot( t1.getNode( "D" ) );
10944             t1.reRoot( t1.getNode( "CD" ) );
10945             t1.reRoot( t1.getNode( "A" ) );
10946             t1.reRoot( t1.getNode( "B" ) );
10947             t1.reRoot( t1.getNode( "AB" ) );
10948             t1.reRoot( t1.getNode( "D" ) );
10949             t1.reRoot( t1.getNode( "C" ) );
10950             t1.reRoot( t1.getNode( "CD" ) );
10951             t1.reRoot( t1.getNode( "A" ) );
10952             t1.reRoot( t1.getNode( "B" ) );
10953             t1.reRoot( t1.getNode( "AB" ) );
10954             t1.reRoot( t1.getNode( "D" ) );
10955             t1.reRoot( t1.getNode( "D" ) );
10956             t1.reRoot( t1.getNode( "C" ) );
10957             t1.reRoot( t1.getNode( "A" ) );
10958             t1.reRoot( t1.getNode( "B" ) );
10959             t1.reRoot( t1.getNode( "AB" ) );
10960             t1.reRoot( t1.getNode( "C" ) );
10961             t1.reRoot( t1.getNode( "D" ) );
10962             t1.reRoot( t1.getNode( "CD" ) );
10963             t1.reRoot( t1.getNode( "D" ) );
10964             t1.reRoot( t1.getNode( "A" ) );
10965             t1.reRoot( t1.getNode( "B" ) );
10966             t1.reRoot( t1.getNode( "AB" ) );
10967             t1.reRoot( t1.getNode( "C" ) );
10968             t1.reRoot( t1.getNode( "D" ) );
10969             t1.reRoot( t1.getNode( "CD" ) );
10970             t1.reRoot( t1.getNode( "D" ) );
10971             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10972                 return false;
10973             }
10974             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10975                 return false;
10976             }
10977             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10978                 return false;
10979             }
10980             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10981                 return false;
10982             }
10983             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10984                 return false;
10985             }
10986             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10987                 return false;
10988             }
10989             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",
10990                                                  new NHXParser() )[ 0 ];
10991             t2.reRoot( t2.getNode( "A" ) );
10992             t2.reRoot( t2.getNode( "D" ) );
10993             t2.reRoot( t2.getNode( "ABC" ) );
10994             t2.reRoot( t2.getNode( "A" ) );
10995             t2.reRoot( t2.getNode( "B" ) );
10996             t2.reRoot( t2.getNode( "D" ) );
10997             t2.reRoot( t2.getNode( "C" ) );
10998             t2.reRoot( t2.getNode( "ABC" ) );
10999             t2.reRoot( t2.getNode( "A" ) );
11000             t2.reRoot( t2.getNode( "B" ) );
11001             t2.reRoot( t2.getNode( "AB" ) );
11002             t2.reRoot( t2.getNode( "AB" ) );
11003             t2.reRoot( t2.getNode( "D" ) );
11004             t2.reRoot( t2.getNode( "C" ) );
11005             t2.reRoot( t2.getNode( "B" ) );
11006             t2.reRoot( t2.getNode( "AB" ) );
11007             t2.reRoot( t2.getNode( "D" ) );
11008             t2.reRoot( t2.getNode( "D" ) );
11009             t2.reRoot( t2.getNode( "ABC" ) );
11010             t2.reRoot( t2.getNode( "A" ) );
11011             t2.reRoot( t2.getNode( "B" ) );
11012             t2.reRoot( t2.getNode( "AB" ) );
11013             t2.reRoot( t2.getNode( "D" ) );
11014             t2.reRoot( t2.getNode( "C" ) );
11015             t2.reRoot( t2.getNode( "ABC" ) );
11016             t2.reRoot( t2.getNode( "A" ) );
11017             t2.reRoot( t2.getNode( "B" ) );
11018             t2.reRoot( t2.getNode( "AB" ) );
11019             t2.reRoot( t2.getNode( "D" ) );
11020             t2.reRoot( t2.getNode( "D" ) );
11021             t2.reRoot( t2.getNode( "C" ) );
11022             t2.reRoot( t2.getNode( "A" ) );
11023             t2.reRoot( t2.getNode( "B" ) );
11024             t2.reRoot( t2.getNode( "AB" ) );
11025             t2.reRoot( t2.getNode( "C" ) );
11026             t2.reRoot( t2.getNode( "D" ) );
11027             t2.reRoot( t2.getNode( "ABC" ) );
11028             t2.reRoot( t2.getNode( "D" ) );
11029             t2.reRoot( t2.getNode( "A" ) );
11030             t2.reRoot( t2.getNode( "B" ) );
11031             t2.reRoot( t2.getNode( "AB" ) );
11032             t2.reRoot( t2.getNode( "C" ) );
11033             t2.reRoot( t2.getNode( "D" ) );
11034             t2.reRoot( t2.getNode( "ABC" ) );
11035             t2.reRoot( t2.getNode( "D" ) );
11036             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11037                 return false;
11038             }
11039             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11040                 return false;
11041             }
11042             t2.reRoot( t2.getNode( "ABC" ) );
11043             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11044                 return false;
11045             }
11046             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11047                 return false;
11048             }
11049             t2.reRoot( t2.getNode( "AB" ) );
11050             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11051                 return false;
11052             }
11053             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11054                 return false;
11055             }
11056             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11057                 return false;
11058             }
11059             t2.reRoot( t2.getNode( "AB" ) );
11060             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11061                 return false;
11062             }
11063             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11064                 return false;
11065             }
11066             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11067                 return false;
11068             }
11069             t2.reRoot( t2.getNode( "D" ) );
11070             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11071                 return false;
11072             }
11073             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11074                 return false;
11075             }
11076             t2.reRoot( t2.getNode( "ABC" ) );
11077             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
11078                 return false;
11079             }
11080             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
11081                 return false;
11082             }
11083             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
11084                                                  new NHXParser() )[ 0 ];
11085             t3.reRoot( t3.getNode( "B" ) );
11086             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11087                 return false;
11088             }
11089             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11090                 return false;
11091             }
11092             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11093                 return false;
11094             }
11095             t3.reRoot( t3.getNode( "B" ) );
11096             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11097                 return false;
11098             }
11099             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11100                 return false;
11101             }
11102             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11103                 return false;
11104             }
11105             t3.reRoot( t3.getRoot() );
11106             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11107                 return false;
11108             }
11109             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
11110                 return false;
11111             }
11112             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
11113                 return false;
11114             }
11115         }
11116         catch ( final Exception e ) {
11117             e.printStackTrace( System.out );
11118             return false;
11119         }
11120         return true;
11121     }
11122
11123     private static boolean testSDIse() {
11124         try {
11125             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11126             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
11127             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
11128             gene1.setRooted( true );
11129             species1.setRooted( true );
11130             final SDI sdi = new SDI( gene1, species1 );
11131             if ( !gene1.getRoot().isDuplication() ) {
11132                 return false;
11133             }
11134             final Phylogeny species2 = factory
11135                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11136                              new NHXParser() )[ 0 ];
11137             final Phylogeny gene2 = factory
11138                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11139                              new NHXParser() )[ 0 ];
11140             species2.setRooted( true );
11141             gene2.setRooted( true );
11142             final SDI sdi2 = new SDI( gene2, species2 );
11143             if ( sdi2.getDuplicationsSum() != 0 ) {
11144                 return false;
11145             }
11146             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
11147                 return false;
11148             }
11149             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
11150                 return false;
11151             }
11152             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
11153                 return false;
11154             }
11155             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
11156                 return false;
11157             }
11158             if ( !gene2.getNode( "r" ).isSpeciation() ) {
11159                 return false;
11160             }
11161             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
11162                 return false;
11163             }
11164             final Phylogeny species3 = factory
11165                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11166                              new NHXParser() )[ 0 ];
11167             final Phylogeny gene3 = factory
11168                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11169                              new NHXParser() )[ 0 ];
11170             species3.setRooted( true );
11171             gene3.setRooted( true );
11172             final SDI sdi3 = new SDI( gene3, species3 );
11173             if ( sdi3.getDuplicationsSum() != 1 ) {
11174                 return false;
11175             }
11176             if ( !gene3.getNode( "aa" ).isDuplication() ) {
11177                 return false;
11178             }
11179             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
11180                 return false;
11181             }
11182             final Phylogeny species4 = factory
11183                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11184                              new NHXParser() )[ 0 ];
11185             final Phylogeny gene4 = factory
11186                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11187                              new NHXParser() )[ 0 ];
11188             species4.setRooted( true );
11189             gene4.setRooted( true );
11190             final SDI sdi4 = new SDI( gene4, species4 );
11191             if ( sdi4.getDuplicationsSum() != 1 ) {
11192                 return false;
11193             }
11194             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
11195                 return false;
11196             }
11197             if ( !gene4.getNode( "abc" ).isDuplication() ) {
11198                 return false;
11199             }
11200             if ( gene4.getNode( "abcd" ).isDuplication() ) {
11201                 return false;
11202             }
11203             if ( species4.getNumberOfExternalNodes() != 6 ) {
11204                 return false;
11205             }
11206             if ( gene4.getNumberOfExternalNodes() != 6 ) {
11207                 return false;
11208             }
11209             final Phylogeny species5 = factory
11210                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11211                              new NHXParser() )[ 0 ];
11212             final Phylogeny gene5 = factory
11213                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
11214                              new NHXParser() )[ 0 ];
11215             species5.setRooted( true );
11216             gene5.setRooted( true );
11217             final SDI sdi5 = new SDI( gene5, species5 );
11218             if ( sdi5.getDuplicationsSum() != 2 ) {
11219                 return false;
11220             }
11221             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
11222                 return false;
11223             }
11224             if ( !gene5.getNode( "adc" ).isDuplication() ) {
11225                 return false;
11226             }
11227             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
11228                 return false;
11229             }
11230             if ( species5.getNumberOfExternalNodes() != 6 ) {
11231                 return false;
11232             }
11233             if ( gene5.getNumberOfExternalNodes() != 6 ) {
11234                 return false;
11235             }
11236             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
11237             // Conjecture for Comparing Molecular Phylogenies"
11238             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
11239             final Phylogeny species6 = factory
11240                     .create( "(((1:[&&NHX:S=1],5:[&&NHX:S=5])1-5,((4:[&&NHX:S=4],6:[&&NHX:S=6])4-6,2:[&&NHX:S=2])4-6-2)1-5-4-6-2,"
11241                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11242                             new NHXParser() )[ 0 ];
11243             final Phylogeny gene6 = factory
11244                     .create( "(((1:0.1[&&NHX:S=1],2:0.1[&&NHX:S=2])1-2:0.1,3:0.1[&&NHX:S=3])1-2-3:0.1,"
11245                             + "((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,"
11246                             + "(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;",
11247                             new NHXParser() )[ 0 ];
11248             species6.setRooted( true );
11249             gene6.setRooted( true );
11250             final SDI sdi6 = new SDI( gene6, species6 );
11251             if ( sdi6.getDuplicationsSum() != 3 ) {
11252                 return false;
11253             }
11254             if ( !gene6.getNode( "r" ).isDuplication() ) {
11255                 return false;
11256             }
11257             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
11258                 return false;
11259             }
11260             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
11261                 return false;
11262             }
11263             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
11264                 return false;
11265             }
11266             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
11267                 return false;
11268             }
11269             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
11270                 return false;
11271             }
11272             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
11273                 return false;
11274             }
11275             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
11276                 return false;
11277             }
11278             sdi6.computeMappingCostL();
11279             if ( sdi6.computeMappingCostL() != 17 ) {
11280                 return false;
11281             }
11282             if ( species6.getNumberOfExternalNodes() != 9 ) {
11283                 return false;
11284             }
11285             if ( gene6.getNumberOfExternalNodes() != 9 ) {
11286                 return false;
11287             }
11288             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
11289                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
11290                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
11291                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
11292                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
11293             species7.setRooted( true );
11294             final Phylogeny gene7_1 = Test
11295                     .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])" );
11296             gene7_1.setRooted( true );
11297             final SDI sdi7 = new SDI( gene7_1, species7 );
11298             if ( sdi7.getDuplicationsSum() != 0 ) {
11299                 return false;
11300             }
11301             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
11302                 return false;
11303             }
11304             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
11305                 return false;
11306             }
11307             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
11308                 return false;
11309             }
11310             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
11311                 return false;
11312             }
11313             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
11314                 return false;
11315             }
11316             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
11317                 return false;
11318             }
11319             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
11320                 return false;
11321             }
11322             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
11323                 return false;
11324             }
11325             final Phylogeny gene7_2 = Test
11326                     .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])" );
11327             gene7_2.setRooted( true );
11328             final SDI sdi7_2 = new SDI( gene7_2, species7 );
11329             if ( sdi7_2.getDuplicationsSum() != 1 ) {
11330                 return false;
11331             }
11332             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
11333                 return false;
11334             }
11335             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
11336                 return false;
11337             }
11338             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
11339                 return false;
11340             }
11341             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
11342                 return false;
11343             }
11344             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
11345                 return false;
11346             }
11347             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
11348                 return false;
11349             }
11350             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
11351                 return false;
11352             }
11353             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
11354                 return false;
11355             }
11356             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
11357                 return false;
11358             }
11359         }
11360         catch ( final Exception e ) {
11361             return false;
11362         }
11363         return true;
11364     }
11365
11366     private static boolean testSDIunrooted() {
11367         try {
11368             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11369             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
11370             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
11371             final Iterator<PhylogenyBranch> iter = l.iterator();
11372             PhylogenyBranch br = iter.next();
11373             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
11374                 return false;
11375             }
11376             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
11377                 return false;
11378             }
11379             br = iter.next();
11380             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11381                 return false;
11382             }
11383             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11384                 return false;
11385             }
11386             br = iter.next();
11387             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
11388                 return false;
11389             }
11390             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
11391                 return false;
11392             }
11393             br = iter.next();
11394             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11395                 return false;
11396             }
11397             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11398                 return false;
11399             }
11400             br = iter.next();
11401             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11402                 return false;
11403             }
11404             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11405                 return false;
11406             }
11407             br = iter.next();
11408             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
11409                 return false;
11410             }
11411             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
11412                 return false;
11413             }
11414             br = iter.next();
11415             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11416                 return false;
11417             }
11418             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11419                 return false;
11420             }
11421             br = iter.next();
11422             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11423                 return false;
11424             }
11425             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11426                 return false;
11427             }
11428             br = iter.next();
11429             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11430                 return false;
11431             }
11432             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11433                 return false;
11434             }
11435             br = iter.next();
11436             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
11437                 return false;
11438             }
11439             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
11440                 return false;
11441             }
11442             br = iter.next();
11443             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11444                 return false;
11445             }
11446             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11447                 return false;
11448             }
11449             br = iter.next();
11450             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
11451                 return false;
11452             }
11453             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
11454                 return false;
11455             }
11456             br = iter.next();
11457             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
11458                 return false;
11459             }
11460             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
11461                 return false;
11462             }
11463             br = iter.next();
11464             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
11465                 return false;
11466             }
11467             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
11468                 return false;
11469             }
11470             br = iter.next();
11471             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
11472                 return false;
11473             }
11474             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
11475                 return false;
11476             }
11477             if ( iter.hasNext() ) {
11478                 return false;
11479             }
11480             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
11481             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
11482             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
11483             br = iter1.next();
11484             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11485                 return false;
11486             }
11487             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11488                 return false;
11489             }
11490             br = iter1.next();
11491             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11492                 return false;
11493             }
11494             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11495                 return false;
11496             }
11497             br = iter1.next();
11498             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11499                 return false;
11500             }
11501             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11502                 return false;
11503             }
11504             if ( iter1.hasNext() ) {
11505                 return false;
11506             }
11507             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
11508             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
11509             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
11510             br = iter2.next();
11511             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
11512                 return false;
11513             }
11514             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
11515                 return false;
11516             }
11517             br = iter2.next();
11518             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
11519                 return false;
11520             }
11521             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
11522                 return false;
11523             }
11524             br = iter2.next();
11525             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
11526                 return false;
11527             }
11528             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
11529                 return false;
11530             }
11531             if ( iter2.hasNext() ) {
11532                 return false;
11533             }
11534             final Phylogeny species0 = factory
11535                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
11536                              new NHXParser() )[ 0 ];
11537             final Phylogeny gene1 = factory
11538                     .create( "(((((A:0.6[&&NHX:S=A],B:0.1[&&NHX:S=B])ab:0.1,C:0.1[&&NHX:S=C])abc:0.3,D:1.0[&&NHX:S=D])abcd:0.2,E:0.1[&&NHX:S=E])abcde:0.2,F:0.2[&&NHX:S=F])",
11539                              new NHXParser() )[ 0 ];
11540             species0.setRooted( true );
11541             gene1.setRooted( true );
11542             final SDIR sdi_unrooted = new SDIR();
11543             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
11544             if ( sdi_unrooted.getCount() != 1 ) {
11545                 return false;
11546             }
11547             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
11548                 return false;
11549             }
11550             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
11551                 return false;
11552             }
11553             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
11554                 return false;
11555             }
11556             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11557                 return false;
11558             }
11559             final Phylogeny gene2 = factory
11560                     .create( "(((((A:2.6[&&NHX:S=A],B:0.1[&&NHX:S=B])ab:0.1,C:0.1[&&NHX:S=C])abc:0.3,D:1.0[&&NHX:S=D])abcd:0.2,E:0.1[&&NHX:S=E])abcde:0.2,F:0.2[&&NHX:S=F])",
11561                              new NHXParser() )[ 0 ];
11562             gene2.setRooted( true );
11563             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
11564             if ( sdi_unrooted.getCount() != 1 ) {
11565                 return false;
11566             }
11567             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11568                 return false;
11569             }
11570             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11571                 return false;
11572             }
11573             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
11574                 return false;
11575             }
11576             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11577                 return false;
11578             }
11579             final Phylogeny species6 = factory
11580                     .create( "(((1:[&&NHX:S=1],5:[&&NHX:S=5])1-5,((4:[&&NHX:S=4],6:[&&NHX:S=6])4-6,2:[&&NHX:S=2])4-6-2)1-5-4-6-2,"
11581                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11582                             new NHXParser() )[ 0 ];
11583             final Phylogeny gene6 = factory
11584                     .create( "((5:0.1[&&NHX:S=5],6:0.1[&&NHX:S=6])5-6:0.05[&&NHX:S=6],(4:0.1[&&NHX:S=4],"
11585                             + "(((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],"
11586                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11587                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11588                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11589                             new NHXParser() )[ 0 ];
11590             species6.setRooted( true );
11591             gene6.setRooted( true );
11592             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
11593             if ( sdi_unrooted.getCount() != 1 ) {
11594                 return false;
11595             }
11596             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11597                 return false;
11598             }
11599             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11600                 return false;
11601             }
11602             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11603                 return false;
11604             }
11605             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11606                 return false;
11607             }
11608             if ( !p6[ 0 ].getRoot().isDuplication() ) {
11609                 return false;
11610             }
11611             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11612                 return false;
11613             }
11614             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11615                 return false;
11616             }
11617             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11618                 return false;
11619             }
11620             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11621                 return false;
11622             }
11623             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11624                 return false;
11625             }
11626             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11627                 return false;
11628             }
11629             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11630                 return false;
11631             }
11632             p6 = null;
11633             final Phylogeny species7 = factory
11634                     .create( "(((1:[&&NHX:S=1],5:[&&NHX:S=5])1-5,((4:[&&NHX:S=4],6:[&&NHX:S=6])4-6,2:[&&NHX:S=2])4-6-2)1-5-4-6-2,"
11635                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11636                             new NHXParser() )[ 0 ];
11637             final Phylogeny gene7 = factory
11638                     .create( "((5:0.1[&&NHX:S=5],6:0.1[&&NHX:S=6])5-6:0.05[&&NHX:S=6],(4:0.1[&&NHX:S=4],"
11639                             + "(((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],"
11640                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11641                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11642                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11643                             new NHXParser() )[ 0 ];
11644             species7.setRooted( true );
11645             gene7.setRooted( true );
11646             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11647             if ( sdi_unrooted.getCount() != 1 ) {
11648                 return false;
11649             }
11650             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11651                 return false;
11652             }
11653             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11654                 return false;
11655             }
11656             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11657                 return false;
11658             }
11659             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11660                 return false;
11661             }
11662             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11663                 return false;
11664             }
11665             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11666                 return false;
11667             }
11668             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11669                 return false;
11670             }
11671             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11672                 return false;
11673             }
11674             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11675                 return false;
11676             }
11677             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11678                 return false;
11679             }
11680             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11681                 return false;
11682             }
11683             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11684                 return false;
11685             }
11686             p7 = null;
11687             final Phylogeny species8 = factory
11688                     .create( "(((1:[&&NHX:S=1],5:[&&NHX:S=5])1-5,((4:[&&NHX:S=4],6:[&&NHX:S=6])4-6,2:[&&NHX:S=2])4-6-2)1-5-4-6-2,"
11689                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11690                             new NHXParser() )[ 0 ];
11691             final Phylogeny gene8 = factory
11692                     .create( "((5:0.1[&&NHX:S=5],6:0.1[&&NHX:S=6])5-6:0.05[&&NHX:S=6],(4:0.1[&&NHX:S=4],"
11693                             + "(((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],"
11694                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11695                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11696                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11697                             new NHXParser() )[ 0 ];
11698             species8.setRooted( true );
11699             gene8.setRooted( true );
11700             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11701             if ( sdi_unrooted.getCount() != 1 ) {
11702                 return false;
11703             }
11704             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11705                 return false;
11706             }
11707             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11708                 return false;
11709             }
11710             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11711                 return false;
11712             }
11713             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11714                 return false;
11715             }
11716             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11717                 return false;
11718             }
11719             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11720                 return false;
11721             }
11722             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11723                 return false;
11724             }
11725             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11726                 return false;
11727             }
11728             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11729                 return false;
11730             }
11731             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11732                 return false;
11733             }
11734             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11735                 return false;
11736             }
11737             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11738                 return false;
11739             }
11740             p8 = null;
11741         }
11742         catch ( final Exception e ) {
11743             e.printStackTrace( System.out );
11744             return false;
11745         }
11746         return true;
11747     }
11748
11749     private static boolean testSequenceDbWsTools1() {
11750         try {
11751             final PhylogenyNode n = new PhylogenyNode();
11752             n.setName( "NP_001025424" );
11753             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11754             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11755                     || !acc.getValue().equals( "NP_001025424" ) ) {
11756                 return false;
11757             }
11758             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11759             acc = SequenceDbWsTools.obtainSeqAccession( n );
11760             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11761                     || !acc.getValue().equals( "NP_001025424" ) ) {
11762                 return false;
11763             }
11764             n.setName( "NP_001025424.1" );
11765             acc = SequenceDbWsTools.obtainSeqAccession( n );
11766             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11767                     || !acc.getValue().equals( "NP_001025424" ) ) {
11768                 return false;
11769             }
11770             n.setName( "NM_001030253" );
11771             acc = SequenceDbWsTools.obtainSeqAccession( n );
11772             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11773                     || !acc.getValue().equals( "NM_001030253" ) ) {
11774                 return false;
11775             }
11776             n.setName( "BCL2_HUMAN" );
11777             acc = SequenceDbWsTools.obtainSeqAccession( n );
11778             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11779                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11780                 System.out.println( acc.toString() );
11781                 return false;
11782             }
11783             n.setName( "P10415" );
11784             acc = SequenceDbWsTools.obtainSeqAccession( n );
11785             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11786                     || !acc.getValue().equals( "P10415" ) ) {
11787                 System.out.println( acc.toString() );
11788                 return false;
11789             }
11790             n.setName( " P10415 " );
11791             acc = SequenceDbWsTools.obtainSeqAccession( n );
11792             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11793                     || !acc.getValue().equals( "P10415" ) ) {
11794                 System.out.println( acc.toString() );
11795                 return false;
11796             }
11797             n.setName( "_P10415|" );
11798             acc = SequenceDbWsTools.obtainSeqAccession( n );
11799             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11800                     || !acc.getValue().equals( "P10415" ) ) {
11801                 System.out.println( acc.toString() );
11802                 return false;
11803             }
11804             n.setName( "AY695820" );
11805             acc = SequenceDbWsTools.obtainSeqAccession( n );
11806             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11807                     || !acc.getValue().equals( "AY695820" ) ) {
11808                 System.out.println( acc.toString() );
11809                 return false;
11810             }
11811             n.setName( "_AY695820_" );
11812             acc = SequenceDbWsTools.obtainSeqAccession( n );
11813             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11814                     || !acc.getValue().equals( "AY695820" ) ) {
11815                 System.out.println( acc.toString() );
11816                 return false;
11817             }
11818             n.setName( "AAA59452" );
11819             acc = SequenceDbWsTools.obtainSeqAccession( n );
11820             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11821                     || !acc.getValue().equals( "AAA59452" ) ) {
11822                 System.out.println( acc.toString() );
11823                 return false;
11824             }
11825             n.setName( "_AAA59452_" );
11826             acc = SequenceDbWsTools.obtainSeqAccession( n );
11827             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11828                     || !acc.getValue().equals( "AAA59452" ) ) {
11829                 System.out.println( acc.toString() );
11830                 return false;
11831             }
11832             n.setName( "AAA59452.1" );
11833             acc = SequenceDbWsTools.obtainSeqAccession( n );
11834             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11835                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11836                 System.out.println( acc.toString() );
11837                 return false;
11838             }
11839             n.setName( "_AAA59452.1_" );
11840             acc = SequenceDbWsTools.obtainSeqAccession( n );
11841             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11842                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11843                 System.out.println( acc.toString() );
11844                 return false;
11845             }
11846             n.setName( "GI:94894583" );
11847             acc = SequenceDbWsTools.obtainSeqAccession( n );
11848             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11849                     || !acc.getValue().equals( "94894583" ) ) {
11850                 System.out.println( acc.toString() );
11851                 return false;
11852             }
11853             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11854             acc = SequenceDbWsTools.obtainSeqAccession( n );
11855             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11856                     || !acc.getValue().equals( "71845847" ) ) {
11857                 System.out.println( acc.toString() );
11858                 return false;
11859             }
11860             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11861             acc = SequenceDbWsTools.obtainSeqAccession( n );
11862             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11863                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11864                 System.out.println( acc.toString() );
11865                 return false;
11866             }
11867         }
11868         catch ( final Exception e ) {
11869             return false;
11870         }
11871         return true;
11872     }
11873
11874     private static boolean testSequenceDbWsTools2() {
11875         try {
11876             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11877             SequenceDbWsTools.obtainSeqInformation( n1 );
11878             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11879                 return false;
11880             }
11881             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11882                 return false;
11883             }
11884             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11885                 return false;
11886             }
11887             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11888                 return false;
11889             }
11890             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11891             SequenceDbWsTools.obtainSeqInformation( n2 );
11892             if ( !n2.getNodeData().getSequence().getName().equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
11893                 return false;
11894             }
11895             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11896                 return false;
11897             }
11898             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11899                 return false;
11900             }
11901             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11902                 return false;
11903             }
11904             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11905             SequenceDbWsTools.obtainSeqInformation( n3 );
11906             if ( !n3.getNodeData().getSequence().getName()
11907                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11908                 return false;
11909             }
11910             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11911                 return false;
11912             }
11913             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11914                 return false;
11915             }
11916             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11917                 return false;
11918             }
11919         }
11920         catch ( final IOException e ) {
11921             System.out.println();
11922             System.out.println( "the following might be due to absence internet connection:" );
11923             e.printStackTrace( System.out );
11924             return true;
11925         }
11926         catch ( final Exception e ) {
11927             e.printStackTrace();
11928             return false;
11929         }
11930         return true;
11931     }
11932
11933     private static boolean testSequenceIdParsing() {
11934         try {
11935             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11936             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11937                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11938                 if ( id != null ) {
11939                     System.out.println( "value   =" + id.getValue() );
11940                     System.out.println( "provider=" + id.getSource() );
11941                 }
11942                 return false;
11943             }
11944             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11945             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11946                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11947                 if ( id != null ) {
11948                     System.out.println( "value   =" + id.getValue() );
11949                     System.out.println( "provider=" + id.getSource() );
11950                 }
11951                 return false;
11952             }
11953             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11954             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11955                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11956                 if ( id != null ) {
11957                     System.out.println( "value   =" + id.getValue() );
11958                     System.out.println( "provider=" + id.getSource() );
11959                 }
11960                 return false;
11961             }
11962             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11963             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11964                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11965                 if ( id != null ) {
11966                     System.out.println( "value   =" + id.getValue() );
11967                     System.out.println( "provider=" + id.getSource() );
11968                 }
11969                 return false;
11970             }
11971             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11972             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11973                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11974                 if ( id != null ) {
11975                     System.out.println( "value   =" + id.getValue() );
11976                     System.out.println( "provider=" + id.getSource() );
11977                 }
11978                 return false;
11979             }
11980             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11981             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11982                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11983                 if ( id != null ) {
11984                     System.out.println( "value   =" + id.getValue() );
11985                     System.out.println( "provider=" + id.getSource() );
11986                 }
11987                 return false;
11988             }
11989             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11990             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11991                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11992                 if ( id != null ) {
11993                     System.out.println( "value   =" + id.getValue() );
11994                     System.out.println( "provider=" + id.getSource() );
11995                 }
11996                 return false;
11997             }
11998             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11999             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12000                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
12001                 if ( id != null ) {
12002                     System.out.println( "value   =" + id.getValue() );
12003                     System.out.println( "provider=" + id.getSource() );
12004                 }
12005                 return false;
12006             }
12007             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
12008             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12009                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
12010                 if ( id != null ) {
12011                     System.out.println( "value   =" + id.getValue() );
12012                     System.out.println( "provider=" + id.getSource() );
12013                 }
12014                 return false;
12015             }
12016             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
12017             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12018                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
12019                 if ( id != null ) {
12020                     System.out.println( "value   =" + id.getValue() );
12021                     System.out.println( "provider=" + id.getSource() );
12022                 }
12023                 return false;
12024             }
12025             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
12026             if ( id != null ) {
12027                 System.out.println( "value   =" + id.getValue() );
12028                 System.out.println( "provider=" + id.getSource() );
12029                 return false;
12030             }
12031             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
12032             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12033                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
12034                 if ( id != null ) {
12035                     System.out.println( "value   =" + id.getValue() );
12036                     System.out.println( "provider=" + id.getSource() );
12037                 }
12038                 return false;
12039             }
12040             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
12041             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12042                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
12043                 if ( id != null ) {
12044                     System.out.println( "value   =" + id.getValue() );
12045                     System.out.println( "provider=" + id.getSource() );
12046                 }
12047                 return false;
12048             }
12049             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
12050             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
12051                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
12052                 if ( id != null ) {
12053                     System.out.println( "value   =" + id.getValue() );
12054                     System.out.println( "provider=" + id.getSource() );
12055                 }
12056                 return false;
12057             }
12058             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
12059             if ( id != null ) {
12060                 System.out.println( "value   =" + id.getValue() );
12061                 System.out.println( "provider=" + id.getSource() );
12062                 return false;
12063             }
12064         }
12065         catch ( final Exception e ) {
12066             e.printStackTrace( System.out );
12067             return false;
12068         }
12069         return true;
12070     }
12071
12072     private static boolean testSequenceWriter() {
12073         try {
12074             final String n = ForesterUtil.LINE_SEPARATOR;
12075             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
12076                 return false;
12077             }
12078             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
12079                 return false;
12080             }
12081             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
12082                 return false;
12083             }
12084             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
12085                 return false;
12086             }
12087             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
12088                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
12089                 return false;
12090             }
12091             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
12092                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
12093                 return false;
12094             }
12095         }
12096         catch ( final Exception e ) {
12097             e.printStackTrace();
12098             return false;
12099         }
12100         return true;
12101     }
12102
12103     private static boolean testSpecies() {
12104         try {
12105             final Species s1 = new BasicSpecies( "a" );
12106             final Species s2 = new BasicSpecies( "a" );
12107             final Species s3 = new BasicSpecies( "A" );
12108             final Species s4 = new BasicSpecies( "b" );
12109             if ( !s1.equals( s1 ) ) {
12110                 return false;
12111             }
12112             if ( s1.getSpeciesId().equals( "x" ) ) {
12113                 return false;
12114             }
12115             if ( s1.getSpeciesId().equals( null ) ) {
12116                 return false;
12117             }
12118             if ( !s1.equals( s2 ) ) {
12119                 return false;
12120             }
12121             if ( s1.equals( s3 ) ) {
12122                 return false;
12123             }
12124             if ( s1.hashCode() != s1.hashCode() ) {
12125                 return false;
12126             }
12127             if ( s1.hashCode() != s2.hashCode() ) {
12128                 return false;
12129             }
12130             if ( s1.hashCode() == s3.hashCode() ) {
12131                 return false;
12132             }
12133             if ( s1.compareTo( s1 ) != 0 ) {
12134                 return false;
12135             }
12136             if ( s1.compareTo( s2 ) != 0 ) {
12137                 return false;
12138             }
12139             if ( s1.compareTo( s3 ) != 0 ) {
12140                 return false;
12141             }
12142             if ( s1.compareTo( s4 ) >= 0 ) {
12143                 return false;
12144             }
12145             if ( s4.compareTo( s1 ) <= 0 ) {
12146                 return false;
12147             }
12148             if ( !s4.getSpeciesId().equals( "b" ) ) {
12149                 return false;
12150             }
12151             final Species s5 = new BasicSpecies( " C " );
12152             if ( !s5.getSpeciesId().equals( "C" ) ) {
12153                 return false;
12154             }
12155             if ( s5.equals( s1 ) ) {
12156                 return false;
12157             }
12158         }
12159         catch ( final Exception e ) {
12160             e.printStackTrace( System.out );
12161             return false;
12162         }
12163         return true;
12164     }
12165
12166     private static boolean testSplit() {
12167         try {
12168             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12169             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12170             //Archaeopteryx.createApplication( p0 );
12171             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
12172             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12173             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12174             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12175             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12176             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12177             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12178             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12179             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12180             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12181             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
12182             // System.out.println( s0.toString() );
12183             //
12184             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12185             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12186             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12187             if ( s0.match( query_nodes ) ) {
12188                 return false;
12189             }
12190             query_nodes = new HashSet<PhylogenyNode>();
12191             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12192             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12193             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12194             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12195             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12196             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12197             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12198             if ( !s0.match( query_nodes ) ) {
12199                 return false;
12200             }
12201             //
12202             query_nodes = new HashSet<PhylogenyNode>();
12203             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12204             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12205             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12206             if ( !s0.match( query_nodes ) ) {
12207                 return false;
12208             }
12209             //
12210             query_nodes = new HashSet<PhylogenyNode>();
12211             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12212             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12213             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12214             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12215             if ( !s0.match( query_nodes ) ) {
12216                 return false;
12217             }
12218             //
12219             query_nodes = new HashSet<PhylogenyNode>();
12220             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12221             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12222             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12223             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12224             if ( !s0.match( query_nodes ) ) {
12225                 return false;
12226             }
12227             //
12228             query_nodes = new HashSet<PhylogenyNode>();
12229             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12230             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12231             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12232             if ( !s0.match( query_nodes ) ) {
12233                 return false;
12234             }
12235             query_nodes = new HashSet<PhylogenyNode>();
12236             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12237             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12238             if ( !s0.match( query_nodes ) ) {
12239                 return false;
12240             }
12241             query_nodes = new HashSet<PhylogenyNode>();
12242             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12243             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12244             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12245             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12246             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12247             if ( !s0.match( query_nodes ) ) {
12248                 return false;
12249             }
12250             query_nodes = new HashSet<PhylogenyNode>();
12251             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12252             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12253             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12254             if ( !s0.match( query_nodes ) ) {
12255                 return false;
12256             }
12257             query_nodes = new HashSet<PhylogenyNode>();
12258             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12259             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12260             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12261             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12262             if ( !s0.match( query_nodes ) ) {
12263                 return false;
12264             }
12265             query_nodes = new HashSet<PhylogenyNode>();
12266             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12267             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12268             if ( s0.match( query_nodes ) ) {
12269                 return false;
12270             }
12271             query_nodes = new HashSet<PhylogenyNode>();
12272             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12273             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12274             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12275             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12276             if ( s0.match( query_nodes ) ) {
12277                 return false;
12278             }
12279             query_nodes = new HashSet<PhylogenyNode>();
12280             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12281             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12282             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12283             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12284             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12285             if ( s0.match( query_nodes ) ) {
12286                 return false;
12287             }
12288             query_nodes = new HashSet<PhylogenyNode>();
12289             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12290             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12291             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12292             if ( s0.match( query_nodes ) ) {
12293                 return false;
12294             }
12295             query_nodes = new HashSet<PhylogenyNode>();
12296             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12297             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12298             if ( s0.match( query_nodes ) ) {
12299                 return false;
12300             }
12301             query_nodes = new HashSet<PhylogenyNode>();
12302             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12303             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12304             if ( s0.match( query_nodes ) ) {
12305                 return false;
12306             }
12307             query_nodes = new HashSet<PhylogenyNode>();
12308             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12309             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12310             if ( s0.match( query_nodes ) ) {
12311                 return false;
12312             }
12313             query_nodes = new HashSet<PhylogenyNode>();
12314             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12315             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12316             if ( s0.match( query_nodes ) ) {
12317                 return false;
12318             }
12319             query_nodes = new HashSet<PhylogenyNode>();
12320             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12321             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12322             if ( s0.match( query_nodes ) ) {
12323                 return false;
12324             }
12325             query_nodes = new HashSet<PhylogenyNode>();
12326             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12327             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12328             if ( s0.match( query_nodes ) ) {
12329                 return false;
12330             }
12331             query_nodes = new HashSet<PhylogenyNode>();
12332             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12333             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12334             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12335             if ( s0.match( query_nodes ) ) {
12336                 return false;
12337             }
12338             query_nodes = new HashSet<PhylogenyNode>();
12339             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12340             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12341             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12342             if ( s0.match( query_nodes ) ) {
12343                 return false;
12344             }
12345             query_nodes = new HashSet<PhylogenyNode>();
12346             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12347             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12348             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12349             if ( s0.match( query_nodes ) ) {
12350                 return false;
12351             }
12352             query_nodes = new HashSet<PhylogenyNode>();
12353             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12354             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12355             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12356             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12357             if ( s0.match( query_nodes ) ) {
12358                 return false;
12359             }
12360             /////////
12361             //            query_nodes = new HashSet<PhylogenyNode>();
12362             //            query_nodes.add( new PhylogenyNode( "X" ) );
12363             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12364             //            query_nodes.add( new PhylogenyNode( "A" ) );
12365             //            query_nodes.add( new PhylogenyNode( "B" ) );
12366             //            query_nodes.add( new PhylogenyNode( "C" ) );
12367             //            query_nodes.add( new PhylogenyNode( "D" ) );
12368             //            query_nodes.add( new PhylogenyNode( "E" ) );
12369             //            query_nodes.add( new PhylogenyNode( "F" ) );
12370             //            query_nodes.add( new PhylogenyNode( "G" ) );
12371             //            if ( !s0.match( query_nodes ) ) {
12372             //                return false;
12373             //            }
12374             //            query_nodes = new HashSet<PhylogenyNode>();
12375             //            query_nodes.add( new PhylogenyNode( "X" ) );
12376             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12377             //            query_nodes.add( new PhylogenyNode( "A" ) );
12378             //            query_nodes.add( new PhylogenyNode( "B" ) );
12379             //            query_nodes.add( new PhylogenyNode( "C" ) );
12380             //            if ( !s0.match( query_nodes ) ) {
12381             //                return false;
12382             //            }
12383             //            //
12384             //            query_nodes = new HashSet<PhylogenyNode>();
12385             //            query_nodes.add( new PhylogenyNode( "X" ) );
12386             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12387             //            query_nodes.add( new PhylogenyNode( "D" ) );
12388             //            query_nodes.add( new PhylogenyNode( "E" ) );
12389             //            query_nodes.add( new PhylogenyNode( "F" ) );
12390             //            query_nodes.add( new PhylogenyNode( "G" ) );
12391             //            if ( !s0.match( query_nodes ) ) {
12392             //                return false;
12393             //            }
12394             //            //
12395             //            query_nodes = new HashSet<PhylogenyNode>();
12396             //            query_nodes.add( new PhylogenyNode( "X" ) );
12397             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12398             //            query_nodes.add( new PhylogenyNode( "A" ) );
12399             //            query_nodes.add( new PhylogenyNode( "B" ) );
12400             //            query_nodes.add( new PhylogenyNode( "C" ) );
12401             //            query_nodes.add( new PhylogenyNode( "D" ) );
12402             //            if ( !s0.match( query_nodes ) ) {
12403             //                return false;
12404             //            }
12405             //            //
12406             //            query_nodes = new HashSet<PhylogenyNode>();
12407             //            query_nodes.add( new PhylogenyNode( "X" ) );
12408             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12409             //            query_nodes.add( new PhylogenyNode( "E" ) );
12410             //            query_nodes.add( new PhylogenyNode( "F" ) );
12411             //            query_nodes.add( new PhylogenyNode( "G" ) );
12412             //            if ( !s0.match( query_nodes ) ) {
12413             //                return false;
12414             //            }
12415             //            //
12416             //            query_nodes = new HashSet<PhylogenyNode>();
12417             //            query_nodes.add( new PhylogenyNode( "X" ) );
12418             //            query_nodes.add( new PhylogenyNode( "Y" ) );
12419             //            query_nodes.add( new PhylogenyNode( "F" ) );
12420             //            query_nodes.add( new PhylogenyNode( "G" ) );
12421             //            if ( !s0.match( query_nodes ) ) {
12422             //                return false;
12423             //            }
12424             //
12425             query_nodes = new HashSet<PhylogenyNode>();
12426             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12427             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12428             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12429             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12430             if ( s0.match( query_nodes ) ) {
12431                 return false;
12432             }
12433             //
12434             query_nodes = new HashSet<PhylogenyNode>();
12435             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12436             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12437             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12438             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12439             if ( s0.match( query_nodes ) ) {
12440                 return false;
12441             }
12442             ///////////////////////////
12443             //
12444             query_nodes = new HashSet<PhylogenyNode>();
12445             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12446             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12447             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12448             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12449             if ( s0.match( query_nodes ) ) {
12450                 return false;
12451             }
12452             //
12453             query_nodes = new HashSet<PhylogenyNode>();
12454             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12455             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12456             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12457             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12458             if ( s0.match( query_nodes ) ) {
12459                 return false;
12460             }
12461             //
12462             query_nodes = new HashSet<PhylogenyNode>();
12463             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12464             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12465             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12466             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12467             if ( s0.match( query_nodes ) ) {
12468                 return false;
12469             }
12470             //
12471             query_nodes = new HashSet<PhylogenyNode>();
12472             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12473             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12474             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12475             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12476             if ( s0.match( query_nodes ) ) {
12477                 return false;
12478             }
12479             //
12480             query_nodes = new HashSet<PhylogenyNode>();
12481             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12482             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12483             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12484             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12485             if ( s0.match( query_nodes ) ) {
12486                 return false;
12487             }
12488             //
12489             query_nodes = new HashSet<PhylogenyNode>();
12490             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12491             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12492             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12493             if ( s0.match( query_nodes ) ) {
12494                 return false;
12495             }
12496             //
12497             query_nodes = new HashSet<PhylogenyNode>();
12498             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12499             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12500             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12501             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12502             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12503             if ( s0.match( query_nodes ) ) {
12504                 return false;
12505             }
12506             //
12507             query_nodes = new HashSet<PhylogenyNode>();
12508             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12509             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12510             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12511             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12512             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12513             if ( s0.match( query_nodes ) ) {
12514                 return false;
12515             }
12516             //
12517             query_nodes = new HashSet<PhylogenyNode>();
12518             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12519             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
12520             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12521             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12522             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12523             if ( s0.match( query_nodes ) ) {
12524                 return false;
12525             }
12526             //
12527             query_nodes = new HashSet<PhylogenyNode>();
12528             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
12529             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
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         catch ( final Exception e ) {
12539             e.printStackTrace();
12540             return false;
12541         }
12542         return true;
12543     }
12544
12545     private static boolean testSplitStrict() {
12546         try {
12547             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12548             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
12549             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
12550             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12551             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12552             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12553             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12554             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12555             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12556             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12557             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
12558             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12559             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12560             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12561             if ( s0.match( query_nodes ) ) {
12562                 return false;
12563             }
12564             query_nodes = new HashSet<PhylogenyNode>();
12565             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12566             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12567             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12568             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12569             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12570             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12571             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12572             if ( !s0.match( query_nodes ) ) {
12573                 return false;
12574             }
12575             //
12576             query_nodes = new HashSet<PhylogenyNode>();
12577             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12578             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12579             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12580             if ( !s0.match( query_nodes ) ) {
12581                 return false;
12582             }
12583             //
12584             query_nodes = new HashSet<PhylogenyNode>();
12585             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12586             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12587             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12589             if ( !s0.match( query_nodes ) ) {
12590                 return false;
12591             }
12592             //
12593             query_nodes = new HashSet<PhylogenyNode>();
12594             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12595             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12596             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12597             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12598             if ( !s0.match( query_nodes ) ) {
12599                 return false;
12600             }
12601             //
12602             query_nodes = new HashSet<PhylogenyNode>();
12603             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12604             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12605             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12606             if ( !s0.match( query_nodes ) ) {
12607                 return false;
12608             }
12609             //
12610             query_nodes = new HashSet<PhylogenyNode>();
12611             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12612             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12613             if ( !s0.match( query_nodes ) ) {
12614                 return false;
12615             }
12616             //
12617             query_nodes = new HashSet<PhylogenyNode>();
12618             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12619             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12620             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12621             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12622             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12623             if ( !s0.match( query_nodes ) ) {
12624                 return false;
12625             }
12626             //
12627             query_nodes = new HashSet<PhylogenyNode>();
12628             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12629             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12630             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12631             if ( !s0.match( query_nodes ) ) {
12632                 return false;
12633             }
12634             //
12635             query_nodes = new HashSet<PhylogenyNode>();
12636             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12637             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12638             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12640             if ( !s0.match( query_nodes ) ) {
12641                 return false;
12642             }
12643             //
12644             query_nodes = new HashSet<PhylogenyNode>();
12645             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12646             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12647             if ( s0.match( query_nodes ) ) {
12648                 return false;
12649             }
12650             //
12651             query_nodes = new HashSet<PhylogenyNode>();
12652             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12653             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12654             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12655             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12656             if ( s0.match( query_nodes ) ) {
12657                 return false;
12658             }
12659             //
12660             query_nodes = new HashSet<PhylogenyNode>();
12661             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12662             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12663             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12664             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12665             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12666             if ( s0.match( query_nodes ) ) {
12667                 return false;
12668             }
12669             //
12670             query_nodes = new HashSet<PhylogenyNode>();
12671             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12672             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12673             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12674             if ( s0.match( query_nodes ) ) {
12675                 return false;
12676             }
12677             //
12678             query_nodes = new HashSet<PhylogenyNode>();
12679             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12680             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12681             if ( s0.match( query_nodes ) ) {
12682                 return false;
12683             }
12684             //
12685             query_nodes = new HashSet<PhylogenyNode>();
12686             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12688             if ( s0.match( query_nodes ) ) {
12689                 return false;
12690             }
12691             //
12692             query_nodes = new HashSet<PhylogenyNode>();
12693             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12694             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12695             if ( s0.match( query_nodes ) ) {
12696                 return false;
12697             }
12698             //
12699             query_nodes = new HashSet<PhylogenyNode>();
12700             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12701             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12702             if ( s0.match( query_nodes ) ) {
12703                 return false;
12704             }
12705             //
12706             query_nodes = new HashSet<PhylogenyNode>();
12707             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12708             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12709             if ( s0.match( query_nodes ) ) {
12710                 return false;
12711             }
12712             //
12713             query_nodes = new HashSet<PhylogenyNode>();
12714             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12715             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12716             if ( s0.match( query_nodes ) ) {
12717                 return false;
12718             }
12719             //
12720             query_nodes = new HashSet<PhylogenyNode>();
12721             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12724             if ( s0.match( query_nodes ) ) {
12725                 return false;
12726             }
12727             //
12728             query_nodes = new HashSet<PhylogenyNode>();
12729             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12730             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12731             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12732             if ( s0.match( query_nodes ) ) {
12733                 return false;
12734             }
12735             //
12736             query_nodes = new HashSet<PhylogenyNode>();
12737             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12738             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12739             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12740             if ( s0.match( query_nodes ) ) {
12741                 return false;
12742             }
12743             //
12744             query_nodes = new HashSet<PhylogenyNode>();
12745             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12746             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12747             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12748             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12749             if ( s0.match( query_nodes ) ) {
12750                 return false;
12751             }
12752         }
12753         catch ( final Exception e ) {
12754             e.printStackTrace();
12755             return false;
12756         }
12757         return true;
12758     }
12759
12760     private static boolean testSubtreeDeletion() {
12761         try {
12762             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12763             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12764             t1.deleteSubtree( t1.getNode( "A" ), false );
12765             if ( t1.getNumberOfExternalNodes() != 5 ) {
12766                 return false;
12767             }
12768             t1.toNewHampshireX();
12769             t1.deleteSubtree( t1.getNode( "E" ), false );
12770             if ( t1.getNumberOfExternalNodes() != 4 ) {
12771                 return false;
12772             }
12773             t1.toNewHampshireX();
12774             t1.deleteSubtree( t1.getNode( "F" ), false );
12775             if ( t1.getNumberOfExternalNodes() != 3 ) {
12776                 return false;
12777             }
12778             t1.toNewHampshireX();
12779             t1.deleteSubtree( t1.getNode( "D" ), false );
12780             t1.toNewHampshireX();
12781             if ( t1.getNumberOfExternalNodes() != 3 ) {
12782                 return false;
12783             }
12784             t1.deleteSubtree( t1.getNode( "def" ), false );
12785             t1.toNewHampshireX();
12786             if ( t1.getNumberOfExternalNodes() != 2 ) {
12787                 return false;
12788             }
12789             t1.deleteSubtree( t1.getNode( "B" ), false );
12790             t1.toNewHampshireX();
12791             if ( t1.getNumberOfExternalNodes() != 1 ) {
12792                 return false;
12793             }
12794             t1.deleteSubtree( t1.getNode( "C" ), false );
12795             t1.toNewHampshireX();
12796             if ( t1.getNumberOfExternalNodes() != 1 ) {
12797                 return false;
12798             }
12799             t1.deleteSubtree( t1.getNode( "abc" ), false );
12800             t1.toNewHampshireX();
12801             if ( t1.getNumberOfExternalNodes() != 1 ) {
12802                 return false;
12803             }
12804             t1.deleteSubtree( t1.getNode( "r" ), false );
12805             if ( t1.getNumberOfExternalNodes() != 0 ) {
12806                 return false;
12807             }
12808             if ( !t1.isEmpty() ) {
12809                 return false;
12810             }
12811             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12812             t2.deleteSubtree( t2.getNode( "A" ), false );
12813             t2.toNewHampshireX();
12814             if ( t2.getNumberOfExternalNodes() != 5 ) {
12815                 return false;
12816             }
12817             t2.deleteSubtree( t2.getNode( "abc" ), false );
12818             t2.toNewHampshireX();
12819             if ( t2.getNumberOfExternalNodes() != 3 ) {
12820                 return false;
12821             }
12822             t2.deleteSubtree( t2.getNode( "def" ), false );
12823             t2.toNewHampshireX();
12824             if ( t2.getNumberOfExternalNodes() != 1 ) {
12825                 return false;
12826             }
12827         }
12828         catch ( final Exception e ) {
12829             e.printStackTrace( System.out );
12830             return false;
12831         }
12832         return true;
12833     }
12834
12835     private static boolean testSupportCount() {
12836         try {
12837             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12838             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12839             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12840                     + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12841                     + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12842                     + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12843                     + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12844                     new NHXParser() );
12845             SupportCount.count( t0_1, phylogenies_1, true, false );
12846             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12847             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12848                     + "(((((A,B),C),D),E),((F,G),X))"
12849                     + "(((((A,Y),B),C),D),((F,G),E))"
12850                     + "(((((A,B),C),D),E),(F,G))"
12851                     + "(((((A,B),C),D),E),(F,G))"
12852                     + "(((((A,B),C),D),E),(F,G))"
12853                     + "(((((A,B),C),D),E),(F,G),Z)"
12854                     + "(((((A,B),C),D),E),(F,G))"
12855                     + "((((((A,B),C),D),E),F),G)"
12856                     + "(((((X,Y),F,G),E),((A,B),C)),D)",
12857                     new NHXParser() );
12858             SupportCount.count( t0_2, phylogenies_2, true, false );
12859             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12860             while ( it.hasNext() ) {
12861                 final PhylogenyNode n = it.next();
12862                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12863                     return false;
12864                 }
12865             }
12866             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12867             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12868                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12869             SupportCount.count( t0_3, phylogenies_3, true, false );
12870             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12871             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12872                 return false;
12873             }
12874             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12875                 return false;
12876             }
12877             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12878                 return false;
12879             }
12880             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12881                 return false;
12882             }
12883             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12884                 return false;
12885             }
12886             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12887                 return false;
12888             }
12889             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12890                 return false;
12891             }
12892             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12893                 return false;
12894             }
12895             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12896                 return false;
12897             }
12898             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12899                 return false;
12900             }
12901             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12902             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12903                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12904             SupportCount.count( t0_4, phylogenies_4, true, false );
12905             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12906             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12907                 return false;
12908             }
12909             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12910                 return false;
12911             }
12912             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12913                 return false;
12914             }
12915             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12916                 return false;
12917             }
12918             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12919                 return false;
12920             }
12921             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12922                 return false;
12923             }
12924             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12925                 return false;
12926             }
12927             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12928                 return false;
12929             }
12930             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12931                 return false;
12932             }
12933             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12934                 return false;
12935             }
12936             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12937             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12938             double d = SupportCount.compare( b1, a, true, true, true );
12939             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12940                 return false;
12941             }
12942             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12943             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12944             d = SupportCount.compare( b2, a, true, true, true );
12945             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12946                 return false;
12947             }
12948             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12949             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12950             d = SupportCount.compare( b3, a, true, true, true );
12951             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12952                 return false;
12953             }
12954             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12955             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12956             d = SupportCount.compare( b4, a, true, true, false );
12957             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12958                 return false;
12959             }
12960         }
12961         catch ( final Exception e ) {
12962             e.printStackTrace( System.out );
12963             return false;
12964         }
12965         return true;
12966     }
12967
12968     private static boolean testSupportTransfer() {
12969         try {
12970             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12971             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)",
12972                                                  new NHXParser() )[ 0 ];
12973             final Phylogeny p2 = factory
12974                     .create( "(((A:0.1,B:0.3)ab:0.4,C)abc:0.5,((D,E)de,(F,G)fg,(H,I)hi:0.59)defghi)", new NHXParser() )[ 0 ];
12975             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12976                 return false;
12977             }
12978             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12979                 return false;
12980             }
12981             support_transfer.moveBranchLengthsToBootstrap( p1 );
12982             support_transfer.transferSupportValues( p1, p2 );
12983             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12984                 return false;
12985             }
12986             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12987                 return false;
12988             }
12989             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12990                 return false;
12991             }
12992             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12993                 return false;
12994             }
12995             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12996                 return false;
12997             }
12998             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12999                 return false;
13000             }
13001             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
13002                 return false;
13003             }
13004             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
13005                 return false;
13006             }
13007         }
13008         catch ( final Exception e ) {
13009             e.printStackTrace( System.out );
13010             return false;
13011         }
13012         return true;
13013     }
13014
13015     private static boolean testTaxonomyExtraction() {
13016         try {
13017             final PhylogenyNode n0 = PhylogenyNode
13018                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13019             if ( n0.getNodeData().isHasTaxonomy() ) {
13020                 return false;
13021             }
13022             final PhylogenyNode n1 = PhylogenyNode
13023                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13024             if ( n1.getNodeData().isHasTaxonomy() ) {
13025                 System.out.println( n1.toString() );
13026                 return false;
13027             }
13028             final PhylogenyNode n2x = PhylogenyNode
13029                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13030             if ( n2x.getNodeData().isHasTaxonomy() ) {
13031                 return false;
13032             }
13033             final PhylogenyNode n3 = PhylogenyNode
13034                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13035             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13036                 System.out.println( n3.toString() );
13037                 return false;
13038             }
13039             final PhylogenyNode n4 = PhylogenyNode
13040                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13041             if ( n4.getNodeData().isHasTaxonomy() ) {
13042                 System.out.println( n4.toString() );
13043                 return false;
13044             }
13045             final PhylogenyNode n5 = PhylogenyNode
13046                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13047             if ( n5.getNodeData().isHasTaxonomy() ) {
13048                 System.out.println( n5.toString() );
13049                 return false;
13050             }
13051             final PhylogenyNode n6 = PhylogenyNode
13052                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13053             if ( n6.getNodeData().isHasTaxonomy() ) {
13054                 System.out.println( n6.toString() );
13055                 return false;
13056             }
13057             final PhylogenyNode n7 = PhylogenyNode
13058                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13059             if ( n7.getNodeData().isHasTaxonomy() ) {
13060                 System.out.println( n7.toString() );
13061                 return false;
13062             }
13063             final PhylogenyNode n8 = PhylogenyNode
13064                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13065             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13066                 System.out.println( n8.toString() );
13067                 return false;
13068             }
13069             final PhylogenyNode n9 = PhylogenyNode
13070                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13071             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
13072                 System.out.println( n9.toString() );
13073                 return false;
13074             }
13075             final PhylogenyNode n10x = PhylogenyNode
13076                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13077             if ( n10x.getNodeData().isHasTaxonomy() ) {
13078                 System.out.println( n10x.toString() );
13079                 return false;
13080             }
13081             final PhylogenyNode n10xx = PhylogenyNode
13082                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13083             if ( n10xx.getNodeData().isHasTaxonomy() ) {
13084                 System.out.println( n10xx.toString() );
13085                 return false;
13086             }
13087             final PhylogenyNode n10 = PhylogenyNode
13088                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
13089             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
13090                 System.out.println( n10.toString() );
13091                 return false;
13092             }
13093             final PhylogenyNode n11 = PhylogenyNode
13094                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13095             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13096                 System.out.println( n11.toString() );
13097                 return false;
13098             }
13099             final PhylogenyNode n12 = PhylogenyNode
13100                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
13101                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13102             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13103                 System.out.println( n12.toString() );
13104                 return false;
13105             }
13106             final PhylogenyNode n13 = PhylogenyNode
13107                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13108             if ( n13.getNodeData().isHasTaxonomy() ) {
13109                 System.out.println( n13.toString() );
13110                 return false;
13111             }
13112             final PhylogenyNode n14 = PhylogenyNode
13113                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13114             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13115                 System.out.println( n14.toString() );
13116                 return false;
13117             }
13118             final PhylogenyNode n15 = PhylogenyNode
13119                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13120             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13121                 System.out.println( n15.toString() );
13122                 return false;
13123             }
13124             final PhylogenyNode n16 = PhylogenyNode
13125                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13126             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13127                 System.out.println( n16.toString() );
13128                 return false;
13129             }
13130             final PhylogenyNode n17 = PhylogenyNode
13131                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13132             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
13133                 System.out.println( n17.toString() );
13134                 return false;
13135             }
13136             final PhylogenyNode n18 = PhylogenyNode
13137                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13138             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13139                 System.out.println( n18.toString() );
13140                 return false;
13141             }
13142             final PhylogenyNode n19 = PhylogenyNode
13143                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
13144                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13145             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13146                 System.out.println( n19.toString() );
13147                 return false;
13148             }
13149             final PhylogenyNode n20 = PhylogenyNode
13150                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13151             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13152                 System.out.println( n20.toString() );
13153                 return false;
13154             }
13155             final PhylogenyNode n21 = PhylogenyNode
13156                     .createInstanceFromNhxString( "Mus musculus musculus K392",
13157                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13158             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
13159                 System.out.println( n21.toString() );
13160                 return false;
13161             }
13162             final PhylogenyNode n23 = PhylogenyNode
13163                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
13164                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13165             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13166                 System.out.println( n23.toString() );
13167                 return false;
13168             }
13169             final PhylogenyNode n24 = PhylogenyNode
13170                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13171             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13172                 System.out.println( n24.toString() );
13173                 return false;
13174             }
13175             //
13176             final PhylogenyNode n25 = PhylogenyNode
13177                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
13178                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13179             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
13180                 System.out.println( n25.toString() );
13181                 return false;
13182             }
13183             final PhylogenyNode n26 = PhylogenyNode
13184                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
13185                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13186             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
13187                 System.out.println( n26.toString() );
13188                 return false;
13189             }
13190             final PhylogenyNode n27 = PhylogenyNode
13191                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
13192             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
13193                 System.out.println( n27.toString() );
13194                 return false;
13195             }
13196         }
13197         catch ( final Exception e ) {
13198             e.printStackTrace( System.out );
13199             return false;
13200         }
13201         return true;
13202     }
13203
13204     private static boolean testTreeCopy() {
13205         try {
13206             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
13207             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
13208             final Phylogeny t1 = t0.copy();
13209             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
13210                 return false;
13211             }
13212             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13213                 return false;
13214             }
13215             t0.deleteSubtree( t0.getNode( "c" ), true );
13216             t0.deleteSubtree( t0.getNode( "a" ), true );
13217             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
13218             t0.getNode( "b" ).setName( "Bee" );
13219             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
13220                 return false;
13221             }
13222             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13223                 return false;
13224             }
13225             t0.deleteSubtree( t0.getNode( "e" ), true );
13226             t0.deleteSubtree( t0.getNode( "Bee" ), true );
13227             t0.deleteSubtree( t0.getNode( "d" ), true );
13228             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
13229                 return false;
13230             }
13231         }
13232         catch ( final Exception e ) {
13233             e.printStackTrace();
13234             return false;
13235         }
13236         return true;
13237     }
13238
13239     private static boolean testTreeMethods() {
13240         try {
13241             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
13242             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
13243             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
13244             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
13245                 System.out.println( t0.toNewHampshireX() );
13246                 return false;
13247             }
13248             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
13249             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
13250             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
13251                 return false;
13252             }
13253             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
13254                 return false;
13255             }
13256             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
13257                 return false;
13258             }
13259         }
13260         catch ( final Exception e ) {
13261             e.printStackTrace( System.out );
13262             return false;
13263         }
13264         return true;
13265     }
13266
13267     private static boolean testUniprotEntryRetrieval() {
13268         try {
13269             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 5000 );
13270             if ( !entry.getAccession().equals( "P12345" ) ) {
13271                 return false;
13272             }
13273             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
13274                 return false;
13275             }
13276             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
13277                 return false;
13278             }
13279             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
13280                 return false;
13281             }
13282             if ( !entry.getGeneName().equals( "GOT2" ) ) {
13283                 return false;
13284             }
13285             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
13286                 return false;
13287             }
13288             if ( entry.getMolecularSequence() == null ) {
13289                 return false;
13290             }
13291             if ( !entry
13292                     .getMolecularSequence()
13293                     .getMolecularSequenceAsString()
13294                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
13295                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
13296                 System.out.println( "got: " + entry.getMolecularSequence().getMolecularSequenceAsString() );
13297                 System.out.println( "expected something else." );
13298                 return false;
13299             }
13300         }
13301         catch ( final IOException e ) {
13302             System.out.println();
13303             System.out.println( "the following might be due to absence internet connection:" );
13304             e.printStackTrace( System.out );
13305             return true;
13306         }
13307         catch ( final NullPointerException f ) {
13308             f.printStackTrace( System.out );
13309             return false;
13310         }
13311         catch ( final Exception e ) {
13312             return false;
13313         }
13314         return true;
13315     }
13316
13317     private static boolean testUniprotTaxonomySearch() {
13318         try {
13319             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
13320                                                                                                  10 );
13321             if ( results.size() != 1 ) {
13322                 return false;
13323             }
13324             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13325                 return false;
13326             }
13327             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13328                 return false;
13329             }
13330             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13331                 return false;
13332             }
13333             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13334                 return false;
13335             }
13336             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13337                 return false;
13338             }
13339             results = null;
13340             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
13341             if ( results.size() != 1 ) {
13342                 return false;
13343             }
13344             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13345                 return false;
13346             }
13347             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13348                 return false;
13349             }
13350             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13351                 return false;
13352             }
13353             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13354                 return false;
13355             }
13356             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13357                 return false;
13358             }
13359             results = null;
13360             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
13361             if ( results.size() != 1 ) {
13362                 return false;
13363             }
13364             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13365                 return false;
13366             }
13367             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13368                 return false;
13369             }
13370             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13371                 return false;
13372             }
13373             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13374                 return false;
13375             }
13376             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13377                 return false;
13378             }
13379             results = null;
13380             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
13381             if ( results.size() != 1 ) {
13382                 return false;
13383             }
13384             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
13385                 return false;
13386             }
13387             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
13388                 return false;
13389             }
13390             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
13391                 return false;
13392             }
13393             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13394                 return false;
13395             }
13396             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
13397                 return false;
13398             }
13399             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
13400                 return false;
13401             }
13402             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
13403                 return false;
13404             }
13405             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13406                     .equals( "Nematostella vectensis" ) ) {
13407                 System.out.println( results.get( 0 ).getLineage() );
13408                 return false;
13409             }
13410             //
13411             results = null;
13412             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
13413             if ( results.size() != 1 ) {
13414                 return false;
13415             }
13416             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13417                 return false;
13418             }
13419             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13420                 return false;
13421             }
13422             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13423                 return false;
13424             }
13425             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13426                 return false;
13427             }
13428             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13429                 return false;
13430             }
13431             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13432                     .equals( "Xenopus tropicalis" ) ) {
13433                 System.out.println( results.get( 0 ).getLineage() );
13434                 return false;
13435             }
13436             //
13437             results = null;
13438             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
13439             if ( results.size() != 1 ) {
13440                 return false;
13441             }
13442             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13443                 return false;
13444             }
13445             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13446                 return false;
13447             }
13448             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13449                 return false;
13450             }
13451             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13452                 return false;
13453             }
13454             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13455                 return false;
13456             }
13457             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13458                     .equals( "Xenopus tropicalis" ) ) {
13459                 System.out.println( results.get( 0 ).getLineage() );
13460                 return false;
13461             }
13462             //
13463             results = null;
13464             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
13465             if ( results.size() != 1 ) {
13466                 return false;
13467             }
13468             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
13469                 return false;
13470             }
13471             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
13472                 return false;
13473             }
13474             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
13475                 return false;
13476             }
13477             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
13478                 return false;
13479             }
13480             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
13481                 return false;
13482             }
13483             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
13484                     .equals( "Xenopus tropicalis" ) ) {
13485                 System.out.println( results.get( 0 ).getLineage() );
13486                 return false;
13487             }
13488         }
13489         catch ( final IOException e ) {
13490             System.out.println();
13491             System.out.println( "the following might be due to absence internet connection:" );
13492             e.printStackTrace( System.out );
13493             return true;
13494         }
13495         catch ( final Exception e ) {
13496             return false;
13497         }
13498         return true;
13499     }
13500     
13501     
13502 }