0f565a426f497d5af00b4fefac88bdbd7dab8b14
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.test;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.File;
30 import java.io.FileInputStream;
31 import java.io.IOException;
32 import java.net.URL;
33 import java.util.ArrayList;
34 import java.util.Date;
35 import java.util.HashSet;
36 import java.util.Iterator;
37 import java.util.List;
38 import java.util.Locale;
39 import java.util.Set;
40 import java.util.SortedSet;
41
42 import org.forester.application.support_transfer;
43 import org.forester.archaeopteryx.TreePanelUtil;
44 import org.forester.archaeopteryx.webservices.WebserviceUtil;
45 import org.forester.development.DevelopmentTools;
46 import org.forester.evoinference.TestPhylogenyReconstruction;
47 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
48 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
49 import org.forester.go.TestGo;
50 import org.forester.io.parsers.FastaParser;
51 import org.forester.io.parsers.GeneralMsaParser;
52 import org.forester.io.parsers.HmmscanPerDomainTableParser;
53 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
54 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
55 import org.forester.io.parsers.nexus.NexusCharactersParser;
56 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
57 import org.forester.io.parsers.nhx.NHXParser;
58 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
59 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
60 import org.forester.io.parsers.tol.TolParser;
61 import org.forester.io.parsers.util.ParserUtils;
62 import org.forester.io.writers.PhylogenyWriter;
63 import org.forester.io.writers.SequenceWriter;
64 import org.forester.msa.BasicMsa;
65 import org.forester.msa.Mafft;
66 import org.forester.msa.Msa;
67 import org.forester.msa.MsaInferrer;
68 import org.forester.msa.MsaMethods;
69 import org.forester.pccx.TestPccx;
70 import org.forester.phylogeny.Phylogeny;
71 import org.forester.phylogeny.PhylogenyBranch;
72 import org.forester.phylogeny.PhylogenyMethods;
73 import org.forester.phylogeny.PhylogenyNode;
74 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
75 import org.forester.phylogeny.data.Accession;
76 import org.forester.phylogeny.data.Accession.Source;
77 import org.forester.phylogeny.data.BinaryCharacters;
78 import org.forester.phylogeny.data.BranchWidth;
79 import org.forester.phylogeny.data.Confidence;
80 import org.forester.phylogeny.data.Distribution;
81 import org.forester.phylogeny.data.DomainArchitecture;
82 import org.forester.phylogeny.data.Event;
83 import org.forester.phylogeny.data.Identifier;
84 import org.forester.phylogeny.data.PhylogenyData;
85 import org.forester.phylogeny.data.PhylogenyDataUtil;
86 import org.forester.phylogeny.data.Polygon;
87 import org.forester.phylogeny.data.PropertiesMap;
88 import org.forester.phylogeny.data.Property;
89 import org.forester.phylogeny.data.Property.AppliesTo;
90 import org.forester.phylogeny.data.ProteinDomain;
91 import org.forester.phylogeny.data.Taxonomy;
92 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
93 import org.forester.phylogeny.factories.PhylogenyFactory;
94 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
95 import org.forester.protein.BasicDomain;
96 import org.forester.protein.BasicProtein;
97 import org.forester.protein.Domain;
98 import org.forester.protein.Protein;
99 import org.forester.protein.ProteinId;
100 import org.forester.rio.TestRIO;
101 import org.forester.sdi.SDI;
102 import org.forester.sdi.SDIR;
103 import org.forester.sdi.TestGSDI;
104 import org.forester.sequence.BasicSequence;
105 import org.forester.sequence.Sequence;
106 import org.forester.species.BasicSpecies;
107 import org.forester.species.Species;
108 import org.forester.surfacing.TestSurfacing;
109 import org.forester.tools.ConfidenceAssessor;
110 import org.forester.tools.SupportCount;
111 import org.forester.tools.TreeSplitMatrix;
112 import org.forester.util.AsciiHistogram;
113 import org.forester.util.BasicDescriptiveStatistics;
114 import org.forester.util.BasicTable;
115 import org.forester.util.BasicTableParser;
116 import org.forester.util.DescriptiveStatistics;
117 import org.forester.util.ForesterConstants;
118 import org.forester.util.ForesterUtil;
119 import org.forester.util.GeneralTable;
120 import org.forester.util.SequenceAccessionTools;
121 import org.forester.ws.seqdb.SequenceDatabaseEntry;
122 import org.forester.ws.seqdb.SequenceDbWsTools;
123 import org.forester.ws.seqdb.UniProtTaxonomy;
124 import org.forester.ws.wabi.TxSearch;
125 import org.forester.ws.wabi.TxSearch.RANKS;
126 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
127 import org.forester.ws.wabi.TxSearch.TAX_RANK;
128
129 @SuppressWarnings( "unused")
130 public final class Test {
131
132     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
133                                                                    + ForesterUtil.getFileSeparator() + "resources"
134                                                                    + ForesterUtil.getFileSeparator();
135     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
136                                                                    + ForesterUtil.getFileSeparator() + "test_data"
137                                                                    + ForesterUtil.getFileSeparator();
138     private final static boolean PERFORM_DB_TESTS          = false;
139     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
140     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
141                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
142                                                                    + ForesterConstants.PHYLO_XML_XSD;
143     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
144                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
145                                                                    + ForesterConstants.PHYLO_XML_XSD;
146     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
147     private final static double  ZERO_DIFF                 = 1.0E-9;
148
149     public static boolean isEqual( final double a, final double b ) {
150         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
151     }
152
153     public static void main( final String[] args ) {
154         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
155         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
156                 + "]" );
157         Locale.setDefault( Locale.US );
158         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
159         int failed = 0;
160         int succeeded = 0;
161         System.out.print( "[Test if directory with files for testing exists/is readable: " );
162         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
163             System.out.println( "OK.]" );
164         }
165         else {
166             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
167             System.out.println( "Testing aborted." );
168             System.exit( -1 );
169         }
170         System.out.print( "[Test if resources directory exists/is readable: " );
171         if ( testDir( PATH_TO_RESOURCES ) ) {
172             System.out.println( "OK.]" );
173         }
174         else {
175             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
176             System.out.println( "Testing aborted." );
177             System.exit( -1 );
178         }
179         final long start_time = new Date().getTime();
180         System.out.print( "Basic node methods: " );
181         if ( Test.testBasicNodeMethods() ) {
182             System.out.println( "OK." );
183             succeeded++;
184         }
185         else {
186             System.out.println( "failed." );
187             failed++;
188         }
189         System.out.print( "Protein id: " );
190         if ( !testProteinId() ) {
191             System.out.println( "failed." );
192             failed++;
193         }
194         else {
195             succeeded++;
196         }
197         System.out.println( "OK." );
198         System.out.print( "Species: " );
199         if ( !testSpecies() ) {
200             System.out.println( "failed." );
201             failed++;
202         }
203         else {
204             succeeded++;
205         }
206         System.out.println( "OK." );
207         System.out.print( "Basic domain: " );
208         if ( !testBasicDomain() ) {
209             System.out.println( "failed." );
210             failed++;
211         }
212         else {
213             succeeded++;
214         }
215         System.out.println( "OK." );
216         System.out.print( "Basic protein: " );
217         if ( !testBasicProtein() ) {
218             System.out.println( "failed." );
219             failed++;
220         }
221         else {
222             succeeded++;
223         }
224         System.out.println( "OK." );
225         System.out.print( "Sequence writer: " );
226         if ( testSequenceWriter() ) {
227             System.out.println( "OK." );
228             succeeded++;
229         }
230         else {
231             System.out.println( "failed." );
232             failed++;
233         }
234         System.out.print( "Sequence id parsing: " );
235         if ( testSequenceIdParsing() ) {
236             System.out.println( "OK." );
237             succeeded++;
238         }
239         else {
240             System.out.println( "failed." );
241             failed++;
242         }
243         System.out.print( "UniProtKB id extraction: " );
244         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
245             System.out.println( "OK." );
246             succeeded++;
247         }
248         else {
249             System.out.println( "failed." );
250             failed++;
251         }
252         System.out.print( "Sequence DB tools 1: " );
253         if ( testSequenceDbWsTools1() ) {
254             System.out.println( "OK." );
255             succeeded++;
256         }
257         else {
258             System.out.println( "failed." );
259             failed++;
260         }
261         System.out.print( "Hmmscan output parser: " );
262         if ( testHmmscanOutputParser() ) {
263             System.out.println( "OK." );
264             succeeded++;
265         }
266         else {
267             System.out.println( "failed." );
268             failed++;
269         }
270         System.out.print( "Overlap removal: " );
271         if ( !org.forester.test.Test.testOverlapRemoval() ) {
272             System.out.println( "failed." );
273             failed++;
274         }
275         else {
276             succeeded++;
277         }
278         System.out.println( "OK." );
279         System.out.print( "Engulfing overlap removal: " );
280         if ( !Test.testEngulfingOverlapRemoval() ) {
281             System.out.println( "failed." );
282             failed++;
283         }
284         else {
285             succeeded++;
286         }
287         System.out.println( "OK." );
288         System.out.print( "Taxonomy code extraction: " );
289         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
290             System.out.println( "OK." );
291             succeeded++;
292         }
293         else {
294             System.out.println( "failed." );
295             failed++;
296         }
297         System.out.print( "SN extraction: " );
298         if ( Test.testExtractSNFromNodeName() ) {
299             System.out.println( "OK." );
300             succeeded++;
301         }
302         else {
303             System.out.println( "failed." );
304             failed++;
305         }
306         System.out.print( "Taxonomy extraction (general): " );
307         if ( Test.testTaxonomyExtraction() ) {
308             System.out.println( "OK." );
309             succeeded++;
310         }
311         else {
312             System.out.println( "failed." );
313             failed++;
314         }
315         System.exit( -1 );
316         System.out.print( "Uri for Aptx web sequence accession: " );
317         if ( Test.testCreateUriForSeqWeb() ) {
318             System.out.println( "OK." );
319             succeeded++;
320         }
321         else {
322             System.out.println( "failed." );
323             failed++;
324         }
325         System.out.print( "Basic node construction and parsing of NHX (node level): " );
326         if ( Test.testNHXNodeParsing() ) {
327             System.out.println( "OK." );
328             succeeded++;
329         }
330         else {
331             System.out.println( "failed." );
332             failed++;
333         }
334         System.out.print( "NHX parsing iterating: " );
335         if ( Test.testNHParsingIter() ) {
336             System.out.println( "OK." );
337             succeeded++;
338         }
339         else {
340             System.out.println( "failed." );
341             failed++;
342         }
343         System.out.print( "NH parsing: " );
344         if ( Test.testNHParsing() ) {
345             System.out.println( "OK." );
346             succeeded++;
347         }
348         else {
349             System.out.println( "failed." );
350             failed++;
351         }
352         System.out.print( "Conversion to NHX (node level): " );
353         if ( Test.testNHXconversion() ) {
354             System.out.println( "OK." );
355             succeeded++;
356         }
357         else {
358             System.out.println( "failed." );
359             failed++;
360         }
361         System.out.print( "NHX parsing: " );
362         if ( Test.testNHXParsing() ) {
363             System.out.println( "OK." );
364             succeeded++;
365         }
366         else {
367             System.out.println( "failed." );
368             failed++;
369         }
370         System.out.print( "NHX parsing with quotes: " );
371         if ( Test.testNHXParsingQuotes() ) {
372             System.out.println( "OK." );
373             succeeded++;
374         }
375         else {
376             System.out.println( "failed." );
377             failed++;
378         }
379         System.out.print( "NHX parsing (MrBayes): " );
380         if ( Test.testNHXParsingMB() ) {
381             System.out.println( "OK." );
382             succeeded++;
383         }
384         else {
385             System.out.println( "failed." );
386             failed++;
387         }
388         System.out.print( "Nexus characters parsing: " );
389         if ( Test.testNexusCharactersParsing() ) {
390             System.out.println( "OK." );
391             succeeded++;
392         }
393         else {
394             System.out.println( "failed." );
395             failed++;
396         }
397         System.out.print( "Nexus tree parsing iterating: " );
398         if ( Test.testNexusTreeParsingIterating() ) {
399             System.out.println( "OK." );
400             succeeded++;
401         }
402         else {
403             System.out.println( "failed." );
404             failed++;
405         }
406         System.out.print( "Nexus tree parsing: " );
407         if ( Test.testNexusTreeParsing() ) {
408             System.out.println( "OK." );
409             succeeded++;
410         }
411         else {
412             System.out.println( "failed." );
413             failed++;
414         }
415         System.out.print( "Nexus tree parsing (translating): " );
416         if ( Test.testNexusTreeParsingTranslating() ) {
417             System.out.println( "OK." );
418             succeeded++;
419         }
420         else {
421             System.out.println( "failed." );
422             failed++;
423         }
424         System.out.print( "Nexus matrix parsing: " );
425         if ( Test.testNexusMatrixParsing() ) {
426             System.out.println( "OK." );
427             succeeded++;
428         }
429         else {
430             System.out.println( "failed." );
431             failed++;
432         }
433         System.out.print( "Basic phyloXML parsing: " );
434         if ( Test.testBasicPhyloXMLparsing() ) {
435             System.out.println( "OK." );
436             succeeded++;
437         }
438         else {
439             System.out.println( "failed." );
440             failed++;
441         }
442         System.out.print( "Basic phyloXML parsing (validating against schema): " );
443         if ( testBasicPhyloXMLparsingValidating() ) {
444             System.out.println( "OK." );
445             succeeded++;
446         }
447         else {
448             System.out.println( "failed." );
449             failed++;
450         }
451         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
452         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
453             System.out.println( "OK." );
454             succeeded++;
455         }
456         else {
457             System.out.println( "failed." );
458             failed++;
459         }
460         System.out.print( "phyloXML Distribution Element: " );
461         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
462             System.out.println( "OK." );
463             succeeded++;
464         }
465         else {
466             System.out.println( "failed." );
467             failed++;
468         }
469         System.out.print( "Tol XML parsing: " );
470         if ( Test.testBasicTolXMLparsing() ) {
471             System.out.println( "OK." );
472             succeeded++;
473         }
474         else {
475             System.out.println( "failed." );
476             failed++;
477         }
478         System.out.print( "Copying of node data: " );
479         if ( Test.testCopyOfNodeData() ) {
480             System.out.println( "OK." );
481             succeeded++;
482         }
483         else {
484             System.out.println( "failed." );
485             failed++;
486         }
487         System.out.print( "Tree copy: " );
488         if ( Test.testTreeCopy() ) {
489             System.out.println( "OK." );
490             succeeded++;
491         }
492         else {
493             System.out.println( "failed." );
494             failed++;
495         }
496         System.out.print( "Basic tree methods: " );
497         if ( Test.testBasicTreeMethods() ) {
498             System.out.println( "OK." );
499             succeeded++;
500         }
501         else {
502             System.out.println( "failed." );
503             failed++;
504         }
505         System.out.print( "Tree methods: " );
506         if ( Test.testTreeMethods() ) {
507             System.out.println( "OK." );
508             succeeded++;
509         }
510         else {
511             System.out.println( "failed." );
512             failed++;
513         }
514         System.out.print( "Postorder Iterator: " );
515         if ( Test.testPostOrderIterator() ) {
516             System.out.println( "OK." );
517             succeeded++;
518         }
519         else {
520             System.out.println( "failed." );
521             failed++;
522         }
523         System.out.print( "Preorder Iterator: " );
524         if ( Test.testPreOrderIterator() ) {
525             System.out.println( "OK." );
526             succeeded++;
527         }
528         else {
529             System.out.println( "failed." );
530             failed++;
531         }
532         System.out.print( "Levelorder Iterator: " );
533         if ( Test.testLevelOrderIterator() ) {
534             System.out.println( "OK." );
535             succeeded++;
536         }
537         else {
538             System.out.println( "failed." );
539             failed++;
540         }
541         System.out.print( "Re-id methods: " );
542         if ( Test.testReIdMethods() ) {
543             System.out.println( "OK." );
544             succeeded++;
545         }
546         else {
547             System.out.println( "failed." );
548             failed++;
549         }
550         System.out.print( "Methods on last external nodes: " );
551         if ( Test.testLastExternalNodeMethods() ) {
552             System.out.println( "OK." );
553             succeeded++;
554         }
555         else {
556             System.out.println( "failed." );
557             failed++;
558         }
559         System.out.print( "Methods on external nodes: " );
560         if ( Test.testExternalNodeRelatedMethods() ) {
561             System.out.println( "OK." );
562             succeeded++;
563         }
564         else {
565             System.out.println( "failed." );
566             failed++;
567         }
568         System.out.print( "Deletion of external nodes: " );
569         if ( Test.testDeletionOfExternalNodes() ) {
570             System.out.println( "OK." );
571             succeeded++;
572         }
573         else {
574             System.out.println( "failed." );
575             failed++;
576         }
577         System.out.print( "Subtree deletion: " );
578         if ( Test.testSubtreeDeletion() ) {
579             System.out.println( "OK." );
580             succeeded++;
581         }
582         else {
583             System.out.println( "failed." );
584             failed++;
585         }
586         System.out.print( "Phylogeny branch: " );
587         if ( Test.testPhylogenyBranch() ) {
588             System.out.println( "OK." );
589             succeeded++;
590         }
591         else {
592             System.out.println( "failed." );
593             failed++;
594         }
595         System.out.print( "Rerooting: " );
596         if ( Test.testRerooting() ) {
597             System.out.println( "OK." );
598             succeeded++;
599         }
600         else {
601             System.out.println( "failed." );
602             failed++;
603         }
604         System.out.print( "Mipoint rooting: " );
605         if ( Test.testMidpointrooting() ) {
606             System.out.println( "OK." );
607             succeeded++;
608         }
609         else {
610             System.out.println( "failed." );
611             failed++;
612         }
613         System.out.print( "Node removal: " );
614         if ( Test.testNodeRemoval() ) {
615             System.out.println( "OK." );
616             succeeded++;
617         }
618         else {
619             System.out.println( "failed." );
620             failed++;
621         }
622         System.out.print( "Support count: " );
623         if ( Test.testSupportCount() ) {
624             System.out.println( "OK." );
625             succeeded++;
626         }
627         else {
628             System.out.println( "failed." );
629             failed++;
630         }
631         System.out.print( "Support transfer: " );
632         if ( Test.testSupportTransfer() ) {
633             System.out.println( "OK." );
634             succeeded++;
635         }
636         else {
637             System.out.println( "failed." );
638             failed++;
639         }
640         System.out.print( "Finding of LCA: " );
641         if ( Test.testGetLCA() ) {
642             System.out.println( "OK." );
643             succeeded++;
644         }
645         else {
646             System.out.println( "failed." );
647             failed++;
648         }
649         System.out.print( "Finding of LCA 2: " );
650         if ( Test.testGetLCA2() ) {
651             System.out.println( "OK." );
652             succeeded++;
653         }
654         else {
655             System.out.println( "failed." );
656             failed++;
657         }
658         System.out.print( "Calculation of distance between nodes: " );
659         if ( Test.testGetDistance() ) {
660             System.out.println( "OK." );
661             succeeded++;
662         }
663         else {
664             System.out.println( "failed." );
665             failed++;
666         }
667         System.out.print( "Descriptive statistics: " );
668         if ( Test.testDescriptiveStatistics() ) {
669             System.out.println( "OK." );
670             succeeded++;
671         }
672         else {
673             System.out.println( "failed." );
674             failed++;
675         }
676         System.out.print( "Data objects and methods: " );
677         if ( Test.testDataObjects() ) {
678             System.out.println( "OK." );
679             succeeded++;
680         }
681         else {
682             System.out.println( "failed." );
683             failed++;
684         }
685         System.out.print( "Properties map: " );
686         if ( Test.testPropertiesMap() ) {
687             System.out.println( "OK." );
688             succeeded++;
689         }
690         else {
691             System.out.println( "failed." );
692             failed++;
693         }
694         System.out.print( "SDIse: " );
695         if ( Test.testSDIse() ) {
696             System.out.println( "OK." );
697             succeeded++;
698         }
699         else {
700             System.out.println( "failed." );
701             failed++;
702         }
703         System.out.print( "SDIunrooted: " );
704         if ( Test.testSDIunrooted() ) {
705             System.out.println( "OK." );
706             succeeded++;
707         }
708         else {
709             System.out.println( "failed." );
710             failed++;
711         }
712         System.out.print( "GSDI: " );
713         if ( TestGSDI.test() ) {
714             System.out.println( "OK." );
715             succeeded++;
716         }
717         else {
718             System.out.println( "failed." );
719             failed++;
720         }
721         System.out.print( "RIO: " );
722         if ( TestRIO.test() ) {
723             System.out.println( "OK." );
724             succeeded++;
725         }
726         else {
727             System.out.println( "failed." );
728             failed++;
729         }
730         System.out.print( "Phylogeny reconstruction:" );
731         System.out.println();
732         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
733             System.out.println( "OK." );
734             succeeded++;
735         }
736         else {
737             System.out.println( "failed." );
738             failed++;
739         }
740         System.out.print( "Analysis of domain architectures: " );
741         System.out.println();
742         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
743             System.out.println( "OK." );
744             succeeded++;
745         }
746         else {
747             System.out.println( "failed." );
748             failed++;
749         }
750         System.out.print( "GO: " );
751         System.out.println();
752         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
753             System.out.println( "OK." );
754             succeeded++;
755         }
756         else {
757             System.out.println( "failed." );
758             failed++;
759         }
760         System.out.print( "Modeling tools: " );
761         if ( TestPccx.test() ) {
762             System.out.println( "OK." );
763             succeeded++;
764         }
765         else {
766             System.out.println( "failed." );
767             failed++;
768         }
769         System.out.print( "Split Matrix strict: " );
770         if ( Test.testSplitStrict() ) {
771             System.out.println( "OK." );
772             succeeded++;
773         }
774         else {
775             System.out.println( "failed." );
776             failed++;
777         }
778         System.out.print( "Split Matrix: " );
779         if ( Test.testSplit() ) {
780             System.out.println( "OK." );
781             succeeded++;
782         }
783         else {
784             System.out.println( "failed." );
785             failed++;
786         }
787         System.out.print( "Confidence Assessor: " );
788         if ( Test.testConfidenceAssessor() ) {
789             System.out.println( "OK." );
790             succeeded++;
791         }
792         else {
793             System.out.println( "failed." );
794             failed++;
795         }
796         System.out.print( "Basic table: " );
797         if ( Test.testBasicTable() ) {
798             System.out.println( "OK." );
799             succeeded++;
800         }
801         else {
802             System.out.println( "failed." );
803             failed++;
804         }
805         System.out.print( "General table: " );
806         if ( Test.testGeneralTable() ) {
807             System.out.println( "OK." );
808             succeeded++;
809         }
810         else {
811             System.out.println( "failed." );
812             failed++;
813         }
814         System.out.print( "Amino acid sequence: " );
815         if ( Test.testAminoAcidSequence() ) {
816             System.out.println( "OK." );
817             succeeded++;
818         }
819         else {
820             System.out.println( "failed." );
821             failed++;
822         }
823         System.out.print( "General MSA parser: " );
824         if ( Test.testGeneralMsaParser() ) {
825             System.out.println( "OK." );
826             succeeded++;
827         }
828         else {
829             System.out.println( "failed." );
830             failed++;
831         }
832         System.out.print( "Fasta parser for msa: " );
833         if ( Test.testFastaParser() ) {
834             System.out.println( "OK." );
835             succeeded++;
836         }
837         else {
838             System.out.println( "failed." );
839             failed++;
840         }
841         System.out.print( "Creation of balanced phylogeny: " );
842         if ( Test.testCreateBalancedPhylogeny() ) {
843             System.out.println( "OK." );
844             succeeded++;
845         }
846         else {
847             System.out.println( "failed." );
848             failed++;
849         }
850         System.out.print( "Genbank accessor parsing: " );
851         if ( Test.testGenbankAccessorParsing() ) {
852             System.out.println( "OK." );
853             succeeded++;
854         }
855         else {
856             System.out.println( "failed." );
857             failed++;
858         }
859         String path = "";
860         final String os = ForesterUtil.OS_NAME.toLowerCase();
861         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
862             path = "/usr/local/bin/mafft";
863         }
864         else if ( os.indexOf( "win" ) >= 0 ) {
865             path = "C:\\Program Files\\mafft-win\\mafft.bat";
866         }
867         else {
868             path = "mafft";
869             if ( !MsaInferrer.isInstalled( path ) ) {
870                 path = "/usr/bin/mafft";
871             }
872             if ( !MsaInferrer.isInstalled( path ) ) {
873                 path = "/usr/local/bin/mafft";
874             }
875         }
876         if ( MsaInferrer.isInstalled( path ) ) {
877             System.out.print( "MAFFT (external program): " );
878             if ( Test.testMafft( path ) ) {
879                 System.out.println( "OK." );
880                 succeeded++;
881             }
882             else {
883                 System.out.println( "failed [will not count towards failed tests]" );
884             }
885         }
886         System.out.print( "Next nodes with collapsed: " );
887         if ( Test.testNextNodeWithCollapsing() ) {
888             System.out.println( "OK." );
889             succeeded++;
890         }
891         else {
892             System.out.println( "failed." );
893             failed++;
894         }
895         System.out.print( "Simple MSA quality: " );
896         if ( Test.testMsaQualityMethod() ) {
897             System.out.println( "OK." );
898             succeeded++;
899         }
900         else {
901             System.out.println( "failed." );
902             failed++;
903         }
904         if ( PERFORM_DB_TESTS ) {
905             System.out.print( "Uniprot Entry Retrieval: " );
906             if ( Test.testUniprotEntryRetrieval() ) {
907                 System.out.println( "OK." );
908                 succeeded++;
909             }
910             else {
911                 System.out.println( "failed." );
912                 failed++;
913             }
914             System.out.print( "Ebi Entry Retrieval: " );
915             if ( Test.testEbiEntryRetrieval() ) {
916                 System.out.println( "OK." );
917                 succeeded++;
918             }
919             else {
920                 System.out.println( "failed." );
921                 failed++;
922             }
923             System.out.print( "Sequence DB tools 2: " );
924             if ( testSequenceDbWsTools2() ) {
925                 System.out.println( "OK." );
926                 succeeded++;
927             }
928             else {
929                 System.out.println( "failed." );
930                 failed++;
931                 System.exit( -1 );
932             }
933             System.out.print( "Uniprot Taxonomy Search: " );
934             if ( Test.testUniprotTaxonomySearch() ) {
935                 System.out.println( "OK." );
936                 succeeded++;
937             }
938             else {
939                 System.out.println( "failed." );
940                 failed++;
941             }
942         }
943         if ( PERFORM_WEB_TREE_ACCESS ) {
944             System.out.print( "NHX parsing from URL: " );
945             if ( Test.testNHXparsingFromURL() ) {
946                 System.out.println( "OK." );
947                 succeeded++;
948             }
949             else {
950                 System.out.println( "failed." );
951                 failed++;
952             }
953             System.out.print( "phyloXML parsing from URL: " );
954             if ( Test.testPhyloXMLparsingFromURL() ) {
955                 System.out.println( "OK." );
956                 succeeded++;
957             }
958             else {
959                 System.out.println( "failed." );
960                 failed++;
961             }
962             System.out.print( "TreeBase acccess: " );
963             if ( Test.testTreeBaseReading() ) {
964                 System.out.println( "OK." );
965                 succeeded++;
966             }
967             else {
968                 System.out.println( "failed." );
969                 failed++;
970             }
971             //
972             System.out.print( "ToL access: " );
973             if ( Test.testToLReading() ) {
974                 System.out.println( "OK." );
975                 succeeded++;
976             }
977             else {
978                 System.out.println( "failed." );
979                 failed++;
980             }
981             //
982             System.out.print( "TreeFam access: " );
983             if ( Test.testTreeFamReading() ) {
984                 System.out.println( "OK." );
985                 succeeded++;
986             }
987             else {
988                 System.out.println( "failed." );
989                 failed++;
990             }
991             //
992             //
993             System.out.print( "Pfam tree access: " );
994             if ( Test.testPfamTreeReading() ) {
995                 System.out.println( "OK." );
996                 succeeded++;
997             }
998             else {
999                 System.out.println( "failed." );
1000                 failed++;
1001             }
1002         }
1003         System.out.println();
1004         final Runtime rt = java.lang.Runtime.getRuntime();
1005         final long free_memory = rt.freeMemory() / 1000000;
1006         final long total_memory = rt.totalMemory() / 1000000;
1007         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1008                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1009         System.out.println();
1010         System.out.println( "Successful tests: " + succeeded );
1011         System.out.println( "Failed     tests: " + failed );
1012         System.out.println();
1013         if ( failed < 1 ) {
1014             System.out.println( "OK." );
1015         }
1016         else {
1017             System.out.println( "Not OK." );
1018         }
1019     }
1020
1021     public static boolean testEngulfingOverlapRemoval() {
1022         try {
1023             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1024             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1025             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1026             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1027             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1028             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1029             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1030             final List<Boolean> covered = new ArrayList<Boolean>();
1031             covered.add( true ); // 0
1032             covered.add( false ); // 1
1033             covered.add( true ); // 2
1034             covered.add( false ); // 3
1035             covered.add( true ); // 4
1036             covered.add( true ); // 5
1037             covered.add( false ); // 6
1038             covered.add( true ); // 7
1039             covered.add( true ); // 8
1040             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1041                 return false;
1042             }
1043             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1044                 return false;
1045             }
1046             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1047                 return false;
1048             }
1049             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1050                 return false;
1051             }
1052             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1053                 return false;
1054             }
1055             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1056                 return false;
1057             }
1058             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1059                 return false;
1060             }
1061             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1062             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1063             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1064             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1065             abc.addProteinDomain( a );
1066             abc.addProteinDomain( b );
1067             abc.addProteinDomain( c );
1068             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1069             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1070             if ( abc.getNumberOfProteinDomains() != 3 ) {
1071                 return false;
1072             }
1073             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1074                 return false;
1075             }
1076             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1077                 return false;
1078             }
1079             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1080                 return false;
1081             }
1082             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1083                 return false;
1084             }
1085             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1086             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1087             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1088             final Protein def = new BasicProtein( "def", "nemve", 0 );
1089             def.addProteinDomain( d );
1090             def.addProteinDomain( e );
1091             def.addProteinDomain( f );
1092             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1093             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1094             if ( def.getNumberOfProteinDomains() != 3 ) {
1095                 return false;
1096             }
1097             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1098                 return false;
1099             }
1100             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1101                 return false;
1102             }
1103             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1104                 return false;
1105             }
1106             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1107                 return false;
1108             }
1109             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1110                 return false;
1111             }
1112         }
1113         catch ( final Exception e ) {
1114             e.printStackTrace( System.out );
1115             return false;
1116         }
1117         return true;
1118     }
1119
1120     public static final boolean testNHXparsingFromURL() {
1121         try {
1122             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1123             final URL u = new URL( s );
1124             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1125             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1126             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1127                 return false;
1128             }
1129             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1130                 System.out.println( phys[ 0 ].toNewHampshire() );
1131                 return false;
1132             }
1133             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1134                 System.out.println( phys[ 1 ].toNewHampshire() );
1135                 return false;
1136             }
1137             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1138             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1139                 return false;
1140             }
1141             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1142                 System.out.println( phys2[ 0 ].toNewHampshire() );
1143                 return false;
1144             }
1145             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1146             final NHXParser p = new NHXParser();
1147             final URL u2 = new URL( s );
1148             p.setSource( u2 );
1149             if ( !p.hasNext() ) {
1150                 return false;
1151             }
1152             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1153                 return false;
1154             }
1155             if ( !p.hasNext() ) {
1156                 return false;
1157             }
1158             p.reset();
1159             if ( !p.hasNext() ) {
1160                 return false;
1161             }
1162             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1163                 return false;
1164             }
1165             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1166                 return false;
1167             }
1168             p.reset();
1169             if ( !p.hasNext() ) {
1170                 return false;
1171             }
1172             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1173                 return false;
1174             }
1175             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1176                 return false;
1177             }
1178         }
1179         catch ( final Exception e ) {
1180             e.printStackTrace();
1181         }
1182         return true;
1183     }
1184
1185     public static boolean testOverlapRemoval() {
1186         try {
1187             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1188             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1189             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1190             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1191             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1192             final List<Boolean> covered = new ArrayList<Boolean>();
1193             covered.add( true ); // 0
1194             covered.add( false ); // 1
1195             covered.add( true ); // 2
1196             covered.add( false ); // 3
1197             covered.add( true ); // 4
1198             covered.add( true ); // 5
1199             covered.add( false ); // 6
1200             covered.add( true ); // 7
1201             covered.add( true ); // 8
1202             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1203                 return false;
1204             }
1205             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1206                 return false;
1207             }
1208             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1209                 return false;
1210             }
1211             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1212                 return false;
1213             }
1214             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1215                 return false;
1216             }
1217             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1218             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1219             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1220             ab.addProteinDomain( a );
1221             ab.addProteinDomain( b );
1222             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1223             if ( ab.getNumberOfProteinDomains() != 2 ) {
1224                 return false;
1225             }
1226             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1227                 return false;
1228             }
1229             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1230                 return false;
1231             }
1232             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1233             if ( ab.getNumberOfProteinDomains() != 2 ) {
1234                 return false;
1235             }
1236             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1237                 return false;
1238             }
1239             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1240             final Domain d = new BasicDomain( "d",
1241                                               ( short ) 10000,
1242                                               ( short ) 10500,
1243                                               ( short ) 1,
1244                                               ( short ) 1,
1245                                               0.0000001,
1246                                               1 );
1247             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1248             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1249             cde.addProteinDomain( c );
1250             cde.addProteinDomain( d );
1251             cde.addProteinDomain( e );
1252             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1253             if ( cde.getNumberOfProteinDomains() != 3 ) {
1254                 return false;
1255             }
1256             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1257                 return false;
1258             }
1259             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1260             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1261             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1262             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1263             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1264             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1265             fghi.addProteinDomain( f );
1266             fghi.addProteinDomain( g );
1267             fghi.addProteinDomain( h );
1268             fghi.addProteinDomain( i );
1269             fghi.addProteinDomain( i );
1270             fghi.addProteinDomain( i );
1271             fghi.addProteinDomain( i2 );
1272             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1273             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1274                 return false;
1275             }
1276             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1277                 return false;
1278             }
1279             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1280                 return false;
1281             }
1282             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1283             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1284                 return false;
1285             }
1286             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1287                 return false;
1288             }
1289             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1290             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1291             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1292             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1293             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1294             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1295             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1296             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1297             jklm.addProteinDomain( j );
1298             jklm.addProteinDomain( k );
1299             jklm.addProteinDomain( l );
1300             jklm.addProteinDomain( m );
1301             jklm.addProteinDomain( m0 );
1302             jklm.addProteinDomain( m1 );
1303             jklm.addProteinDomain( m2 );
1304             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1305             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1306                 return false;
1307             }
1308             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1309                 return false;
1310             }
1311             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1312                 return false;
1313             }
1314             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1315             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1316                 return false;
1317             }
1318             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1319                 return false;
1320             }
1321             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1322             final Protein od = new BasicProtein( "od", "varanus", 0 );
1323             od.addProteinDomain( only );
1324             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1325             if ( od.getNumberOfProteinDomains() != 1 ) {
1326                 return false;
1327             }
1328             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1329                 return false;
1330             }
1331         }
1332         catch ( final Exception e ) {
1333             e.printStackTrace( System.out );
1334             return false;
1335         }
1336         return true;
1337     }
1338
1339     public static final boolean testPfamTreeReading() {
1340         try {
1341             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1342             final NHXParser parser = new NHXParser();
1343             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1344             parser.setReplaceUnderscores( false );
1345             parser.setGuessRootedness( true );
1346             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1347             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1348             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1349                 return false;
1350             }
1351             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1352                 return false;
1353             }
1354         }
1355         catch ( final Exception e ) {
1356             e.printStackTrace();
1357         }
1358         return true;
1359     }
1360
1361     public static final boolean testPhyloXMLparsingFromURL() {
1362         try {
1363             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1364             final URL u = new URL( s );
1365             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1366             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1367             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1368                 return false;
1369             }
1370         }
1371         catch ( final Exception e ) {
1372             e.printStackTrace();
1373         }
1374         return true;
1375     }
1376
1377     public static final boolean testToLReading() {
1378         try {
1379             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1380             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1381             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1382             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1383                 return false;
1384             }
1385             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1386                 return false;
1387             }
1388             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1389                 return false;
1390             }
1391             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1392                 return false;
1393             }
1394         }
1395         catch ( final Exception e ) {
1396             e.printStackTrace();
1397         }
1398         return true;
1399     }
1400
1401     public static final boolean testTreeBaseReading() {
1402         try {
1403             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1404             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1405             parser.setReplaceUnderscores( true );
1406             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1407             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1408             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1409                 return false;
1410             }
1411             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1412             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1413             parser2.setReplaceUnderscores( true );
1414             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1415             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1416             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1417                 return false;
1418             }
1419         }
1420         catch ( final Exception e ) {
1421             e.printStackTrace();
1422         }
1423         return true;
1424     }
1425
1426     public static final boolean testTreeFamReading() {
1427         try {
1428             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1429             final NHXParser parser = new NHXParser();
1430             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1431             parser.setReplaceUnderscores( false );
1432             parser.setGuessRootedness( true );
1433             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1434             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1435             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1436                 return false;
1437             }
1438             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1439                 return false;
1440             }
1441         }
1442         catch ( final Exception e ) {
1443             e.printStackTrace();
1444         }
1445         return true;
1446     }
1447
1448     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1449         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1450         return p;
1451     }
1452
1453     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1454         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1455     }
1456
1457     private static boolean testAminoAcidSequence() {
1458         try {
1459             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1460             if ( aa1.getLength() != 13 ) {
1461                 return false;
1462             }
1463             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1464                 return false;
1465             }
1466             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1467                 return false;
1468             }
1469             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1470                 return false;
1471             }
1472             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1473             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1474                 return false;
1475             }
1476             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1477             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1478                 return false;
1479             }
1480             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1481             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1482                 return false;
1483             }
1484         }
1485         catch ( final Exception e ) {
1486             e.printStackTrace();
1487             return false;
1488         }
1489         return true;
1490     }
1491
1492     private static boolean testBasicDomain() {
1493         try {
1494             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1495             if ( !pd.getDomainId().equals( "id" ) ) {
1496                 return false;
1497             }
1498             if ( pd.getNumber() != 1 ) {
1499                 return false;
1500             }
1501             if ( pd.getTotalCount() != 4 ) {
1502                 return false;
1503             }
1504             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1505                 return false;
1506             }
1507             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1508             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1509             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1510             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1511             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1512             if ( !a1.equals( a1 ) ) {
1513                 return false;
1514             }
1515             if ( !a1.equals( a1_copy ) ) {
1516                 return false;
1517             }
1518             if ( !a1.equals( a1_equal ) ) {
1519                 return false;
1520             }
1521             if ( !a1.equals( a2 ) ) {
1522                 return false;
1523             }
1524             if ( a1.equals( a3 ) ) {
1525                 return false;
1526             }
1527             if ( a1.compareTo( a1 ) != 0 ) {
1528                 return false;
1529             }
1530             if ( a1.compareTo( a1_copy ) != 0 ) {
1531                 return false;
1532             }
1533             if ( a1.compareTo( a1_equal ) != 0 ) {
1534                 return false;
1535             }
1536             if ( a1.compareTo( a2 ) != 0 ) {
1537                 return false;
1538             }
1539             if ( a1.compareTo( a3 ) == 0 ) {
1540                 return false;
1541             }
1542         }
1543         catch ( final Exception e ) {
1544             e.printStackTrace( System.out );
1545             return false;
1546         }
1547         return true;
1548     }
1549
1550     private static boolean testBasicNodeMethods() {
1551         try {
1552             if ( PhylogenyNode.getNodeCount() != 0 ) {
1553                 return false;
1554             }
1555             final PhylogenyNode n1 = new PhylogenyNode();
1556             final PhylogenyNode n2 = PhylogenyNode
1557                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1558             final PhylogenyNode n3 = PhylogenyNode
1559                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1560             final PhylogenyNode n4 = PhylogenyNode
1561                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1562             if ( n1.isHasAssignedEvent() ) {
1563                 return false;
1564             }
1565             if ( PhylogenyNode.getNodeCount() != 4 ) {
1566                 return false;
1567             }
1568             if ( n3.getIndicator() != 0 ) {
1569                 return false;
1570             }
1571             if ( n3.getNumberOfExternalNodes() != 1 ) {
1572                 return false;
1573             }
1574             if ( !n3.isExternal() ) {
1575                 return false;
1576             }
1577             if ( !n3.isRoot() ) {
1578                 return false;
1579             }
1580             if ( !n4.getName().equals( "n4" ) ) {
1581                 return false;
1582             }
1583         }
1584         catch ( final Exception e ) {
1585             e.printStackTrace( System.out );
1586             return false;
1587         }
1588         return true;
1589     }
1590
1591     private static boolean testBasicPhyloXMLparsing() {
1592         try {
1593             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1594             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1595             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1596                                                               xml_parser );
1597             if ( xml_parser.getErrorCount() > 0 ) {
1598                 System.out.println( xml_parser.getErrorMessages().toString() );
1599                 return false;
1600             }
1601             if ( phylogenies_0.length != 4 ) {
1602                 return false;
1603             }
1604             final Phylogeny t1 = phylogenies_0[ 0 ];
1605             final Phylogeny t2 = phylogenies_0[ 1 ];
1606             final Phylogeny t3 = phylogenies_0[ 2 ];
1607             final Phylogeny t4 = phylogenies_0[ 3 ];
1608             if ( t1.getNumberOfExternalNodes() != 1 ) {
1609                 return false;
1610             }
1611             if ( !t1.isRooted() ) {
1612                 return false;
1613             }
1614             if ( t1.isRerootable() ) {
1615                 return false;
1616             }
1617             if ( !t1.getType().equals( "gene_tree" ) ) {
1618                 return false;
1619             }
1620             if ( t2.getNumberOfExternalNodes() != 2 ) {
1621                 return false;
1622             }
1623             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1624                 return false;
1625             }
1626             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1627                 return false;
1628             }
1629             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1630                 return false;
1631             }
1632             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1633                 return false;
1634             }
1635             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1636                 return false;
1637             }
1638             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1639                 return false;
1640             }
1641             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1642                     .startsWith( "actgtgggggt" ) ) {
1643                 return false;
1644             }
1645             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1646                     .startsWith( "ctgtgatgcat" ) ) {
1647                 return false;
1648             }
1649             if ( t3.getNumberOfExternalNodes() != 4 ) {
1650                 return false;
1651             }
1652             if ( !t1.getName().equals( "t1" ) ) {
1653                 return false;
1654             }
1655             if ( !t2.getName().equals( "t2" ) ) {
1656                 return false;
1657             }
1658             if ( !t3.getName().equals( "t3" ) ) {
1659                 return false;
1660             }
1661             if ( !t4.getName().equals( "t4" ) ) {
1662                 return false;
1663             }
1664             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1665                 return false;
1666             }
1667             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1668                 return false;
1669             }
1670             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1671                 return false;
1672             }
1673             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1674                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1675                 return false;
1676             }
1677             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1678                 return false;
1679             }
1680             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1681                 return false;
1682             }
1683             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1684                 return false;
1685             }
1686             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1687                     .equals( "apoptosis" ) ) {
1688                 return false;
1689             }
1690             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1691                     .equals( "GO:0006915" ) ) {
1692                 return false;
1693             }
1694             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1695                     .equals( "UniProtKB" ) ) {
1696                 return false;
1697             }
1698             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1699                     .equals( "experimental" ) ) {
1700                 return false;
1701             }
1702             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1703                     .equals( "function" ) ) {
1704                 return false;
1705             }
1706             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1707                     .getValue() != 1 ) {
1708                 return false;
1709             }
1710             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1711                     .getType().equals( "ml" ) ) {
1712                 return false;
1713             }
1714             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1715                     .equals( "apoptosis" ) ) {
1716                 return false;
1717             }
1718             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1719                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1720                 return false;
1721             }
1722             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1723                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1724                 return false;
1725             }
1726             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1727                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1728                 return false;
1729             }
1730             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1731                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1732                 return false;
1733             }
1734             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1735                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1736                 return false;
1737             }
1738             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1739                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1740                 return false;
1741             }
1742             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1743                     .equals( "GO:0005829" ) ) {
1744                 return false;
1745             }
1746             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1747                     .equals( "intracellular organelle" ) ) {
1748                 return false;
1749             }
1750             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1751                 return false;
1752             }
1753             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1754                     .equals( "UniProt link" ) ) ) {
1755                 return false;
1756             }
1757             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1758                 return false;
1759             }
1760             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1761             if ( x.size() != 4 ) {
1762                 return false;
1763             }
1764             int c = 0;
1765             for( final Accession acc : x ) {
1766                 if ( c == 0 ) {
1767                     if ( !acc.getSource().equals( "KEGG" ) ) {
1768                         return false;
1769                     }
1770                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1771                         return false;
1772                     }
1773                 }
1774                 c++;
1775             }
1776         }
1777         catch ( final Exception e ) {
1778             e.printStackTrace( System.out );
1779             return false;
1780         }
1781         return true;
1782     }
1783
1784     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1785         try {
1786             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1787             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1788             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1789                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1790             }
1791             else {
1792                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1793             }
1794             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1795                                                               xml_parser );
1796             if ( xml_parser.getErrorCount() > 0 ) {
1797                 System.out.println( xml_parser.getErrorMessages().toString() );
1798                 return false;
1799             }
1800             if ( phylogenies_0.length != 4 ) {
1801                 return false;
1802             }
1803             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1804             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1805             if ( phylogenies_t1.length != 1 ) {
1806                 return false;
1807             }
1808             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1809             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1810                 return false;
1811             }
1812             if ( !t1_rt.isRooted() ) {
1813                 return false;
1814             }
1815             if ( t1_rt.isRerootable() ) {
1816                 return false;
1817             }
1818             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1819                 return false;
1820             }
1821             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1822             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1823             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1824             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1825                 return false;
1826             }
1827             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1828                 return false;
1829             }
1830             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1831                 return false;
1832             }
1833             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1834                 return false;
1835             }
1836             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1837                     .startsWith( "actgtgggggt" ) ) {
1838                 return false;
1839             }
1840             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1841                     .startsWith( "ctgtgatgcat" ) ) {
1842                 return false;
1843             }
1844             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1845             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1846             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1847             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1848             if ( phylogenies_1.length != 1 ) {
1849                 return false;
1850             }
1851             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1852             if ( !t3_rt.getName().equals( "t3" ) ) {
1853                 return false;
1854             }
1855             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1856                 return false;
1857             }
1858             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1859                 return false;
1860             }
1861             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1862                 return false;
1863             }
1864             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1865                 return false;
1866             }
1867             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1868                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1869                 return false;
1870             }
1871             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1872                 return false;
1873             }
1874             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1875                 return false;
1876             }
1877             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1878                     .equals( "UniProtKB" ) ) {
1879                 return false;
1880             }
1881             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1882                     .equals( "apoptosis" ) ) {
1883                 return false;
1884             }
1885             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1886                     .equals( "GO:0006915" ) ) {
1887                 return false;
1888             }
1889             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1890                     .equals( "UniProtKB" ) ) {
1891                 return false;
1892             }
1893             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1894                     .equals( "experimental" ) ) {
1895                 return false;
1896             }
1897             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1898                     .equals( "function" ) ) {
1899                 return false;
1900             }
1901             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1902                     .getValue() != 1 ) {
1903                 return false;
1904             }
1905             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1906                     .getType().equals( "ml" ) ) {
1907                 return false;
1908             }
1909             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1910                     .equals( "apoptosis" ) ) {
1911                 return false;
1912             }
1913             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1914                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1915                 return false;
1916             }
1917             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1918                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1919                 return false;
1920             }
1921             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1922                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1923                 return false;
1924             }
1925             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1926                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1927                 return false;
1928             }
1929             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1930                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1931                 return false;
1932             }
1933             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1934                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1935                 return false;
1936             }
1937             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1938                     .equals( "GO:0005829" ) ) {
1939                 return false;
1940             }
1941             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1942                     .equals( "intracellular organelle" ) ) {
1943                 return false;
1944             }
1945             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1946                 return false;
1947             }
1948             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1949                     .equals( "UniProt link" ) ) ) {
1950                 return false;
1951             }
1952             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1953                 return false;
1954             }
1955             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1956                 return false;
1957             }
1958             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1959                     .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." ) ) ) {
1960                 return false;
1961             }
1962             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1963                 return false;
1964             }
1965             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1966                 return false;
1967             }
1968             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1969                 return false;
1970             }
1971             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1972                 return false;
1973             }
1974             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1975                     .equals( "ncbi" ) ) {
1976                 return false;
1977             }
1978             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1979                 return false;
1980             }
1981             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1982                     .getName().equals( "B" ) ) {
1983                 return false;
1984             }
1985             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1986                     .getFrom() != 21 ) {
1987                 return false;
1988             }
1989             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1990                 return false;
1991             }
1992             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1993                     .getLength() != 24 ) {
1994                 return false;
1995             }
1996             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1997                     .getConfidence() != 2144 ) {
1998                 return false;
1999             }
2000             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2001                     .equals( "pfam" ) ) {
2002                 return false;
2003             }
2004             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2005                 return false;
2006             }
2007             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2008                 return false;
2009             }
2010             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2011                 return false;
2012             }
2013             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2014                 return false;
2015             }
2016             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2017             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2018                 return false;
2019             }
2020             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2021                 return false;
2022             }
2023             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2024                 return false;
2025             }
2026             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2027                 return false;
2028             }
2029             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2030                 return false;
2031             }
2032             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2033                 return false;
2034             }
2035             if ( taxbb.getSynonyms().size() != 2 ) {
2036                 return false;
2037             }
2038             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2039                 return false;
2040             }
2041             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2042                 return false;
2043             }
2044             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2045                 return false;
2046             }
2047             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2048                 return false;
2049             }
2050             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2051                 return false;
2052             }
2053             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2054                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2055                 return false;
2056             }
2057             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2058                 return false;
2059             }
2060             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2061                 return false;
2062             }
2063             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2064                 return false;
2065             }
2066             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2067                 return false;
2068             }
2069             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2070                 return false;
2071             }
2072             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2073                 return false;
2074             }
2075             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2076                 return false;
2077             }
2078             //
2079             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2080                 return false;
2081             }
2082             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2083                     .equalsIgnoreCase( "435" ) ) {
2084                 return false;
2085             }
2086             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2087                 return false;
2088             }
2089             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2090                     .equalsIgnoreCase( "443.7" ) ) {
2091                 return false;
2092             }
2093             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2094                 return false;
2095             }
2096             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2097                 return false;
2098             }
2099             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2100                     .equalsIgnoreCase( "433" ) ) {
2101                 return false;
2102             }
2103             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2104                     .getCrossReferences();
2105             if ( x.size() != 4 ) {
2106                 return false;
2107             }
2108             int c = 0;
2109             for( final Accession acc : x ) {
2110                 if ( c == 0 ) {
2111                     if ( !acc.getSource().equals( "KEGG" ) ) {
2112                         return false;
2113                     }
2114                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2115                         return false;
2116                     }
2117                 }
2118                 c++;
2119             }
2120         }
2121         catch ( final Exception e ) {
2122             e.printStackTrace( System.out );
2123             return false;
2124         }
2125         return true;
2126     }
2127
2128     private static boolean testBasicPhyloXMLparsingValidating() {
2129         try {
2130             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2131             PhyloXmlParser xml_parser = null;
2132             try {
2133                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2134             }
2135             catch ( final Exception e ) {
2136                 // Do nothing -- means were not running from jar.
2137             }
2138             if ( xml_parser == null ) {
2139                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2140                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2141                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2142                 }
2143                 else {
2144                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2145                 }
2146             }
2147             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2148                                                               xml_parser );
2149             if ( xml_parser.getErrorCount() > 0 ) {
2150                 System.out.println( xml_parser.getErrorMessages().toString() );
2151                 return false;
2152             }
2153             if ( phylogenies_0.length != 4 ) {
2154                 return false;
2155             }
2156             final Phylogeny t1 = phylogenies_0[ 0 ];
2157             final Phylogeny t2 = phylogenies_0[ 1 ];
2158             final Phylogeny t3 = phylogenies_0[ 2 ];
2159             final Phylogeny t4 = phylogenies_0[ 3 ];
2160             if ( !t1.getName().equals( "t1" ) ) {
2161                 return false;
2162             }
2163             if ( !t2.getName().equals( "t2" ) ) {
2164                 return false;
2165             }
2166             if ( !t3.getName().equals( "t3" ) ) {
2167                 return false;
2168             }
2169             if ( !t4.getName().equals( "t4" ) ) {
2170                 return false;
2171             }
2172             if ( t1.getNumberOfExternalNodes() != 1 ) {
2173                 return false;
2174             }
2175             if ( t2.getNumberOfExternalNodes() != 2 ) {
2176                 return false;
2177             }
2178             if ( t3.getNumberOfExternalNodes() != 4 ) {
2179                 return false;
2180             }
2181             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2182             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2183             if ( xml_parser.getErrorCount() > 0 ) {
2184                 System.out.println( "errors:" );
2185                 System.out.println( xml_parser.getErrorMessages().toString() );
2186                 return false;
2187             }
2188             if ( phylogenies_1.length != 4 ) {
2189                 return false;
2190             }
2191             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2192                                                               xml_parser );
2193             if ( xml_parser.getErrorCount() > 0 ) {
2194                 System.out.println( "errors:" );
2195                 System.out.println( xml_parser.getErrorMessages().toString() );
2196                 return false;
2197             }
2198             if ( phylogenies_2.length != 1 ) {
2199                 return false;
2200             }
2201             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2202                 return false;
2203             }
2204             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2205                                                               xml_parser );
2206             if ( xml_parser.getErrorCount() > 0 ) {
2207                 System.out.println( xml_parser.getErrorMessages().toString() );
2208                 return false;
2209             }
2210             if ( phylogenies_3.length != 2 ) {
2211                 return false;
2212             }
2213             final Phylogeny a = phylogenies_3[ 0 ];
2214             if ( !a.getName().equals( "tree 4" ) ) {
2215                 return false;
2216             }
2217             if ( a.getNumberOfExternalNodes() != 3 ) {
2218                 return false;
2219             }
2220             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2221                 return false;
2222             }
2223             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2224                 return false;
2225             }
2226             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2227                                                               xml_parser );
2228             if ( xml_parser.getErrorCount() > 0 ) {
2229                 System.out.println( xml_parser.getErrorMessages().toString() );
2230                 return false;
2231             }
2232             if ( phylogenies_4.length != 1 ) {
2233                 return false;
2234             }
2235             final Phylogeny s = phylogenies_4[ 0 ];
2236             if ( s.getNumberOfExternalNodes() != 6 ) {
2237                 return false;
2238             }
2239             s.getNode( "first" );
2240             s.getNode( "<>" );
2241             s.getNode( "\"<a'b&c'd\">\"" );
2242             s.getNode( "'''\"" );
2243             s.getNode( "\"\"\"" );
2244             s.getNode( "dick & doof" );
2245         }
2246         catch ( final Exception e ) {
2247             e.printStackTrace( System.out );
2248             return false;
2249         }
2250         return true;
2251     }
2252
2253     private static boolean testBasicProtein() {
2254         try {
2255             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2256             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2257             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2258             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2259             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2260             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2261             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2262             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2263             p0.addProteinDomain( y );
2264             p0.addProteinDomain( e );
2265             p0.addProteinDomain( b );
2266             p0.addProteinDomain( c );
2267             p0.addProteinDomain( d );
2268             p0.addProteinDomain( a );
2269             p0.addProteinDomain( x );
2270             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2271                 return false;
2272             }
2273             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2274                 return false;
2275             }
2276             //
2277             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2278             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2279             aa0.addProteinDomain( a1 );
2280             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2281                 return false;
2282             }
2283             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2284                 return false;
2285             }
2286             //
2287             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2288             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2289             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2290             aa1.addProteinDomain( a11 );
2291             aa1.addProteinDomain( a12 );
2292             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2293                 return false;
2294             }
2295             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2296                 return false;
2297             }
2298             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2299             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2300                 return false;
2301             }
2302             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2303                 return false;
2304             }
2305             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2306                 return false;
2307             }
2308             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2309             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2310                 return false;
2311             }
2312             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2313                 return false;
2314             }
2315             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2316                 return false;
2317             }
2318             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2319                 return false;
2320             }
2321             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2322             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2323                 return false;
2324             }
2325             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2326                 return false;
2327             }
2328             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2329                 return false;
2330             }
2331             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2332                 return false;
2333             }
2334             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2335             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2336                 return false;
2337             }
2338             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2339                 return false;
2340             }
2341             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2342                 return false;
2343             }
2344             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2345                 return false;
2346             }
2347             //
2348             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2349             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2350             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2351             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2352             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2353             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2354             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2355             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2356             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2357             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2358             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2359             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2360             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2361             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2362             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2363             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2364             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2365             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2366             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2367             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2368             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2369             p00.addProteinDomain( y0 );
2370             p00.addProteinDomain( e0 );
2371             p00.addProteinDomain( b0 );
2372             p00.addProteinDomain( c0 );
2373             p00.addProteinDomain( d0 );
2374             p00.addProteinDomain( a0 );
2375             p00.addProteinDomain( x0 );
2376             p00.addProteinDomain( y1 );
2377             p00.addProteinDomain( y2 );
2378             p00.addProteinDomain( y3 );
2379             p00.addProteinDomain( e1 );
2380             p00.addProteinDomain( e2 );
2381             p00.addProteinDomain( e3 );
2382             p00.addProteinDomain( e4 );
2383             p00.addProteinDomain( e5 );
2384             p00.addProteinDomain( z0 );
2385             p00.addProteinDomain( z1 );
2386             p00.addProteinDomain( z2 );
2387             p00.addProteinDomain( zz0 );
2388             p00.addProteinDomain( zz1 );
2389             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2390                 return false;
2391             }
2392             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2393                 return false;
2394             }
2395             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2396                 return false;
2397             }
2398             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2399                 return false;
2400             }
2401             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" ) ) {
2402                 return false;
2403             }
2404             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2405             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2406             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2407             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2408             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2409             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2410             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2411             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2412             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2413             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2414             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2415             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2416             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2417             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2418             p.addProteinDomain( B15 );
2419             p.addProteinDomain( C50 );
2420             p.addProteinDomain( A60 );
2421             p.addProteinDomain( A30 );
2422             p.addProteinDomain( C70 );
2423             p.addProteinDomain( B35 );
2424             p.addProteinDomain( B40 );
2425             p.addProteinDomain( A0 );
2426             p.addProteinDomain( A10 );
2427             p.addProteinDomain( A20 );
2428             p.addProteinDomain( B25 );
2429             p.addProteinDomain( D80 );
2430             List<String> domains_ids = new ArrayList<String>();
2431             domains_ids.add( "A" );
2432             domains_ids.add( "B" );
2433             domains_ids.add( "C" );
2434             if ( !p.contains( domains_ids, false ) ) {
2435                 return false;
2436             }
2437             if ( !p.contains( domains_ids, true ) ) {
2438                 return false;
2439             }
2440             domains_ids.add( "X" );
2441             if ( p.contains( domains_ids, false ) ) {
2442                 return false;
2443             }
2444             if ( p.contains( domains_ids, true ) ) {
2445                 return false;
2446             }
2447             domains_ids = new ArrayList<String>();
2448             domains_ids.add( "A" );
2449             domains_ids.add( "C" );
2450             domains_ids.add( "D" );
2451             if ( !p.contains( domains_ids, false ) ) {
2452                 return false;
2453             }
2454             if ( !p.contains( domains_ids, true ) ) {
2455                 return false;
2456             }
2457             domains_ids = new ArrayList<String>();
2458             domains_ids.add( "A" );
2459             domains_ids.add( "D" );
2460             domains_ids.add( "C" );
2461             if ( !p.contains( domains_ids, false ) ) {
2462                 return false;
2463             }
2464             if ( p.contains( domains_ids, true ) ) {
2465                 return false;
2466             }
2467             domains_ids = new ArrayList<String>();
2468             domains_ids.add( "A" );
2469             domains_ids.add( "A" );
2470             domains_ids.add( "B" );
2471             if ( !p.contains( domains_ids, false ) ) {
2472                 return false;
2473             }
2474             if ( !p.contains( domains_ids, true ) ) {
2475                 return false;
2476             }
2477             domains_ids = new ArrayList<String>();
2478             domains_ids.add( "A" );
2479             domains_ids.add( "A" );
2480             domains_ids.add( "A" );
2481             domains_ids.add( "B" );
2482             domains_ids.add( "B" );
2483             if ( !p.contains( domains_ids, false ) ) {
2484                 return false;
2485             }
2486             if ( !p.contains( domains_ids, true ) ) {
2487                 return false;
2488             }
2489             domains_ids = new ArrayList<String>();
2490             domains_ids.add( "A" );
2491             domains_ids.add( "A" );
2492             domains_ids.add( "B" );
2493             domains_ids.add( "A" );
2494             domains_ids.add( "B" );
2495             domains_ids.add( "B" );
2496             domains_ids.add( "A" );
2497             domains_ids.add( "B" );
2498             domains_ids.add( "C" );
2499             domains_ids.add( "A" );
2500             domains_ids.add( "C" );
2501             domains_ids.add( "D" );
2502             if ( !p.contains( domains_ids, false ) ) {
2503                 return false;
2504             }
2505             if ( p.contains( domains_ids, true ) ) {
2506                 return false;
2507             }
2508         }
2509         catch ( final Exception e ) {
2510             e.printStackTrace( System.out );
2511             return false;
2512         }
2513         return true;
2514     }
2515
2516     private static boolean testBasicTable() {
2517         try {
2518             final BasicTable<String> t0 = new BasicTable<String>();
2519             if ( t0.getNumberOfColumns() != 0 ) {
2520                 return false;
2521             }
2522             if ( t0.getNumberOfRows() != 0 ) {
2523                 return false;
2524             }
2525             t0.setValue( 3, 2, "23" );
2526             t0.setValue( 10, 1, "error" );
2527             t0.setValue( 10, 1, "110" );
2528             t0.setValue( 9, 1, "19" );
2529             t0.setValue( 1, 10, "101" );
2530             t0.setValue( 10, 10, "1010" );
2531             t0.setValue( 100, 10, "10100" );
2532             t0.setValue( 0, 0, "00" );
2533             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2534                 return false;
2535             }
2536             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2537                 return false;
2538             }
2539             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2540                 return false;
2541             }
2542             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2543                 return false;
2544             }
2545             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2546                 return false;
2547             }
2548             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2549                 return false;
2550             }
2551             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2552                 return false;
2553             }
2554             if ( t0.getNumberOfColumns() != 101 ) {
2555                 return false;
2556             }
2557             if ( t0.getNumberOfRows() != 11 ) {
2558                 return false;
2559             }
2560             if ( t0.getValueAsString( 49, 4 ) != null ) {
2561                 return false;
2562             }
2563             final String l = ForesterUtil.getLineSeparator();
2564             final StringBuffer source = new StringBuffer();
2565             source.append( "" + l );
2566             source.append( "# 1 1 1 1 1 1 1 1" + l );
2567             source.append( " 00 01 02 03" + l );
2568             source.append( "   10 11 12 13  " + l );
2569             source.append( "20 21 22 23 " + l );
2570             source.append( "    30  31    32 33" + l );
2571             source.append( "40 41 42 43" + l );
2572             source.append( "  # 1 1 1 1 1 " + l );
2573             source.append( "50 51 52 53 54" + l );
2574             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2575             if ( t1.getNumberOfColumns() != 5 ) {
2576                 return false;
2577             }
2578             if ( t1.getNumberOfRows() != 6 ) {
2579                 return false;
2580             }
2581             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2582                 return false;
2583             }
2584             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2585                 return false;
2586             }
2587             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2588                 return false;
2589             }
2590             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2591                 return false;
2592             }
2593             final StringBuffer source1 = new StringBuffer();
2594             source1.append( "" + l );
2595             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2596             source1.append( " 00; 01 ;02;03" + l );
2597             source1.append( "   10; 11; 12; 13  " + l );
2598             source1.append( "20; 21; 22; 23 " + l );
2599             source1.append( "    30;  31;    32; 33" + l );
2600             source1.append( "40;41;42;43" + l );
2601             source1.append( "  # 1 1 1 1 1 " + l );
2602             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2603             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2604             if ( t2.getNumberOfColumns() != 5 ) {
2605                 return false;
2606             }
2607             if ( t2.getNumberOfRows() != 6 ) {
2608                 return false;
2609             }
2610             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2611                 return false;
2612             }
2613             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2614                 return false;
2615             }
2616             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2617                 return false;
2618             }
2619             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2620                 return false;
2621             }
2622             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2623                 return false;
2624             }
2625             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2626                 return false;
2627             }
2628             final StringBuffer source2 = new StringBuffer();
2629             source2.append( "" + l );
2630             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2631             source2.append( " 00; 01 ;02;03" + l );
2632             source2.append( "   10; 11; 12; 13  " + l );
2633             source2.append( "20; 21; 22; 23 " + l );
2634             source2.append( "                     " + l );
2635             source2.append( "    30;  31;    32; 33" + l );
2636             source2.append( "40;41;42;43" + l );
2637             source2.append( "  comment: 1 1 1 1 1 " + l );
2638             source2.append( ";;;50  ;   52; 53;;54   " + l );
2639             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2640                                                                         ';',
2641                                                                         false,
2642                                                                         false,
2643                                                                         "comment:",
2644                                                                         false );
2645             if ( tl.size() != 2 ) {
2646                 return false;
2647             }
2648             final BasicTable<String> t3 = tl.get( 0 );
2649             final BasicTable<String> t4 = tl.get( 1 );
2650             if ( t3.getNumberOfColumns() != 4 ) {
2651                 return false;
2652             }
2653             if ( t3.getNumberOfRows() != 3 ) {
2654                 return false;
2655             }
2656             if ( t4.getNumberOfColumns() != 4 ) {
2657                 return false;
2658             }
2659             if ( t4.getNumberOfRows() != 3 ) {
2660                 return false;
2661             }
2662             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2663                 return false;
2664             }
2665             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2666                 return false;
2667             }
2668         }
2669         catch ( final Exception e ) {
2670             e.printStackTrace( System.out );
2671             return false;
2672         }
2673         return true;
2674     }
2675
2676     private static boolean testBasicTolXMLparsing() {
2677         try {
2678             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2679             final TolParser parser = new TolParser();
2680             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2681             if ( parser.getErrorCount() > 0 ) {
2682                 System.out.println( parser.getErrorMessages().toString() );
2683                 return false;
2684             }
2685             if ( phylogenies_0.length != 1 ) {
2686                 return false;
2687             }
2688             final Phylogeny t1 = phylogenies_0[ 0 ];
2689             if ( t1.getNumberOfExternalNodes() != 5 ) {
2690                 return false;
2691             }
2692             if ( !t1.isRooted() ) {
2693                 return false;
2694             }
2695             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2696                 return false;
2697             }
2698             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2699                 return false;
2700             }
2701             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2702                 return false;
2703             }
2704             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2705                 return false;
2706             }
2707             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2708             if ( parser.getErrorCount() > 0 ) {
2709                 System.out.println( parser.getErrorMessages().toString() );
2710                 return false;
2711             }
2712             if ( phylogenies_1.length != 1 ) {
2713                 return false;
2714             }
2715             final Phylogeny t2 = phylogenies_1[ 0 ];
2716             if ( t2.getNumberOfExternalNodes() != 664 ) {
2717                 return false;
2718             }
2719             if ( !t2.isRooted() ) {
2720                 return false;
2721             }
2722             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2723                 return false;
2724             }
2725             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2726                 return false;
2727             }
2728             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2729                 return false;
2730             }
2731             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2732                 return false;
2733             }
2734             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2735                 return false;
2736             }
2737             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2738                     .equals( "Aquifex" ) ) {
2739                 return false;
2740             }
2741             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2742             if ( parser.getErrorCount() > 0 ) {
2743                 System.out.println( parser.getErrorMessages().toString() );
2744                 return false;
2745             }
2746             if ( phylogenies_2.length != 1 ) {
2747                 return false;
2748             }
2749             final Phylogeny t3 = phylogenies_2[ 0 ];
2750             if ( t3.getNumberOfExternalNodes() != 184 ) {
2751                 return false;
2752             }
2753             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2754                 return false;
2755             }
2756             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2757                 return false;
2758             }
2759             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2760                 return false;
2761             }
2762             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2763             if ( parser.getErrorCount() > 0 ) {
2764                 System.out.println( parser.getErrorMessages().toString() );
2765                 return false;
2766             }
2767             if ( phylogenies_3.length != 1 ) {
2768                 return false;
2769             }
2770             final Phylogeny t4 = phylogenies_3[ 0 ];
2771             if ( t4.getNumberOfExternalNodes() != 1 ) {
2772                 return false;
2773             }
2774             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2775                 return false;
2776             }
2777             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2778                 return false;
2779             }
2780             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2781                 return false;
2782             }
2783             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2784             if ( parser.getErrorCount() > 0 ) {
2785                 System.out.println( parser.getErrorMessages().toString() );
2786                 return false;
2787             }
2788             if ( phylogenies_4.length != 1 ) {
2789                 return false;
2790             }
2791             final Phylogeny t5 = phylogenies_4[ 0 ];
2792             if ( t5.getNumberOfExternalNodes() != 13 ) {
2793                 return false;
2794             }
2795             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2796                 return false;
2797             }
2798             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2799                 return false;
2800             }
2801             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2802                 return false;
2803             }
2804         }
2805         catch ( final Exception e ) {
2806             e.printStackTrace( System.out );
2807             return false;
2808         }
2809         return true;
2810     }
2811
2812     private static boolean testBasicTreeMethods() {
2813         try {
2814             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2815             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2816             if ( t2.getNumberOfExternalNodes() != 4 ) {
2817                 return false;
2818             }
2819             if ( t2.getHeight() != 8.5 ) {
2820                 return false;
2821             }
2822             if ( !t2.isCompletelyBinary() ) {
2823                 return false;
2824             }
2825             if ( t2.isEmpty() ) {
2826                 return false;
2827             }
2828             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2829             if ( t3.getNumberOfExternalNodes() != 5 ) {
2830                 return false;
2831             }
2832             if ( t3.getHeight() != 11 ) {
2833                 return false;
2834             }
2835             if ( t3.isCompletelyBinary() ) {
2836                 return false;
2837             }
2838             final PhylogenyNode n = t3.getNode( "ABC" );
2839             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 ];
2840             if ( t4.getNumberOfExternalNodes() != 9 ) {
2841                 return false;
2842             }
2843             if ( t4.getHeight() != 11 ) {
2844                 return false;
2845             }
2846             if ( t4.isCompletelyBinary() ) {
2847                 return false;
2848             }
2849             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)" );
2850             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2851             if ( t5.getNumberOfExternalNodes() != 8 ) {
2852                 return false;
2853             }
2854             if ( t5.getHeight() != 15 ) {
2855                 return false;
2856             }
2857             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)" );
2858             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2859             if ( t6.getHeight() != 15 ) {
2860                 return false;
2861             }
2862             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)" );
2863             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2864             if ( t7.getHeight() != 15 ) {
2865                 return false;
2866             }
2867             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)" );
2868             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2869             if ( t8.getNumberOfExternalNodes() != 10 ) {
2870                 return false;
2871             }
2872             if ( t8.getHeight() != 15 ) {
2873                 return false;
2874             }
2875             final char[] a9 = new char[] { 'a' };
2876             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2877             if ( t9.getHeight() != 0 ) {
2878                 return false;
2879             }
2880             final char[] a10 = new char[] { 'a', ':', '6' };
2881             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2882             if ( t10.getHeight() != 6 ) {
2883                 return false;
2884             }
2885         }
2886         catch ( final Exception e ) {
2887             e.printStackTrace( System.out );
2888             return false;
2889         }
2890         return true;
2891     }
2892
2893     private static boolean testConfidenceAssessor() {
2894         try {
2895             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2896             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2897             final Phylogeny[] ev0 = factory
2898                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2899                              new NHXParser() );
2900             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2901             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2902                 return false;
2903             }
2904             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2905                 return false;
2906             }
2907             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2908             final Phylogeny[] ev1 = factory
2909                     .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)));",
2910                              new NHXParser() );
2911             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2912             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2913                 return false;
2914             }
2915             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2916                 return false;
2917             }
2918             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2919             final Phylogeny[] ev_b = factory
2920                     .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",
2921                              new NHXParser() );
2922             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2923             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2924                 return false;
2925             }
2926             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2927                 return false;
2928             }
2929             //
2930             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2931             final Phylogeny[] ev1x = factory
2932                     .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)));",
2933                              new NHXParser() );
2934             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2935             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2936                 return false;
2937             }
2938             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2939                 return false;
2940             }
2941             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2942             final Phylogeny[] ev_bx = factory
2943                     .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",
2944                              new NHXParser() );
2945             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2946             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2947                 return false;
2948             }
2949             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2950                 return false;
2951             }
2952             //
2953             final Phylogeny[] t2 = factory
2954                     .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);",
2955                              new NHXParser() );
2956             final Phylogeny[] ev2 = factory
2957                     .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);",
2958                              new NHXParser() );
2959             for( final Phylogeny target : t2 ) {
2960                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2961             }
2962             //
2963             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2964                                                  new NHXParser() )[ 0 ];
2965             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2966             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2967             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2968                 return false;
2969             }
2970             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2971                 return false;
2972             }
2973             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2974                 return false;
2975             }
2976         }
2977         catch ( final Exception e ) {
2978             e.printStackTrace();
2979             return false;
2980         }
2981         return true;
2982     }
2983
2984     private static boolean testCopyOfNodeData() {
2985         try {
2986             final PhylogenyNode n1 = PhylogenyNode
2987                     .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]" );
2988             final PhylogenyNode n2 = n1.copyNodeData();
2989             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2990                 return false;
2991             }
2992         }
2993         catch ( final Exception e ) {
2994             e.printStackTrace();
2995             return false;
2996         }
2997         return true;
2998     }
2999
3000     private static boolean testCreateBalancedPhylogeny() {
3001         try {
3002             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3003             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3004                 return false;
3005             }
3006             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3007                 return false;
3008             }
3009             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3010             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3011                 return false;
3012             }
3013             if ( p1.getNumberOfExternalNodes() != 100 ) {
3014                 return false;
3015             }
3016         }
3017         catch ( final Exception e ) {
3018             e.printStackTrace();
3019             return false;
3020         }
3021         return true;
3022     }
3023
3024     private static boolean testCreateUriForSeqWeb() {
3025         try {
3026             final PhylogenyNode n = new PhylogenyNode();
3027             n.setName( "tr|B3RJ64" );
3028             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3029                 return false;
3030             }
3031             n.setName( "B0LM41_HUMAN" );
3032             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3033                 return false;
3034             }
3035             n.setName( "NP_001025424" );
3036             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3037                 return false;
3038             }
3039             n.setName( "_NM_001030253-" );
3040             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3041                 return false;
3042             }
3043             n.setName( "XM_002122186" );
3044             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3045                 return false;
3046             }
3047             n.setName( "dgh_AAA34956_gdg" );
3048             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3049                 return false;
3050             }
3051             n.setName( "AAA34956" );
3052             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3053                 return false;
3054             }
3055             n.setName( "GI:394892" );
3056             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3057                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3058                 return false;
3059             }
3060             n.setName( "gi_394892" );
3061             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3062                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3063                 return false;
3064             }
3065             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3066             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3067                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3068                 return false;
3069             }
3070             n.setName( "P12345" );
3071             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3072                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3073                 return false;
3074             }
3075             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3076             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3077                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3078                 return false;
3079             }
3080         }
3081         catch ( final Exception e ) {
3082             e.printStackTrace( System.out );
3083             return false;
3084         }
3085         return true;
3086     }
3087
3088     private static boolean testDataObjects() {
3089         try {
3090             final Confidence s0 = new Confidence();
3091             final Confidence s1 = new Confidence();
3092             if ( !s0.isEqual( s1 ) ) {
3093                 return false;
3094             }
3095             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3096             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3097             if ( s2.isEqual( s1 ) ) {
3098                 return false;
3099             }
3100             if ( !s2.isEqual( s3 ) ) {
3101                 return false;
3102             }
3103             final Confidence s4 = ( Confidence ) s3.copy();
3104             if ( !s4.isEqual( s3 ) ) {
3105                 return false;
3106             }
3107             s3.asSimpleText();
3108             s3.asText();
3109             // Taxonomy
3110             // ----------
3111             final Taxonomy t1 = new Taxonomy();
3112             final Taxonomy t2 = new Taxonomy();
3113             final Taxonomy t3 = new Taxonomy();
3114             final Taxonomy t4 = new Taxonomy();
3115             final Taxonomy t5 = new Taxonomy();
3116             t1.setIdentifier( new Identifier( "ecoli" ) );
3117             t1.setTaxonomyCode( "ECOLI" );
3118             t1.setScientificName( "E. coli" );
3119             t1.setCommonName( "coli" );
3120             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3121             if ( !t1.isEqual( t0 ) ) {
3122                 return false;
3123             }
3124             t2.setIdentifier( new Identifier( "ecoli" ) );
3125             t2.setTaxonomyCode( "OTHER" );
3126             t2.setScientificName( "what" );
3127             t2.setCommonName( "something" );
3128             if ( !t1.isEqual( t2 ) ) {
3129                 return false;
3130             }
3131             t2.setIdentifier( new Identifier( "nemve" ) );
3132             if ( t1.isEqual( t2 ) ) {
3133                 return false;
3134             }
3135             t1.setIdentifier( null );
3136             t3.setTaxonomyCode( "ECOLI" );
3137             t3.setScientificName( "what" );
3138             t3.setCommonName( "something" );
3139             if ( !t1.isEqual( t3 ) ) {
3140                 return false;
3141             }
3142             t1.setIdentifier( null );
3143             t1.setTaxonomyCode( "" );
3144             t4.setScientificName( "E. ColI" );
3145             t4.setCommonName( "something" );
3146             if ( !t1.isEqual( t4 ) ) {
3147                 return false;
3148             }
3149             t4.setScientificName( "B. subtilis" );
3150             t4.setCommonName( "something" );
3151             if ( t1.isEqual( t4 ) ) {
3152                 return false;
3153             }
3154             t1.setIdentifier( null );
3155             t1.setTaxonomyCode( "" );
3156             t1.setScientificName( "" );
3157             t5.setCommonName( "COLI" );
3158             if ( !t1.isEqual( t5 ) ) {
3159                 return false;
3160             }
3161             t5.setCommonName( "vibrio" );
3162             if ( t1.isEqual( t5 ) ) {
3163                 return false;
3164             }
3165             // Identifier
3166             // ----------
3167             final Identifier id0 = new Identifier( "123", "pfam" );
3168             final Identifier id1 = ( Identifier ) id0.copy();
3169             if ( !id1.isEqual( id1 ) ) {
3170                 return false;
3171             }
3172             if ( !id1.isEqual( id0 ) ) {
3173                 return false;
3174             }
3175             if ( !id0.isEqual( id1 ) ) {
3176                 return false;
3177             }
3178             id1.asSimpleText();
3179             id1.asText();
3180             // ProteinDomain
3181             // ---------------
3182             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3183             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3184             if ( !pd1.isEqual( pd1 ) ) {
3185                 return false;
3186             }
3187             if ( !pd1.isEqual( pd0 ) ) {
3188                 return false;
3189             }
3190             pd1.asSimpleText();
3191             pd1.asText();
3192             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3193             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3194             if ( !pd3.isEqual( pd3 ) ) {
3195                 return false;
3196             }
3197             if ( !pd2.isEqual( pd3 ) ) {
3198                 return false;
3199             }
3200             if ( !pd0.isEqual( pd3 ) ) {
3201                 return false;
3202             }
3203             pd3.asSimpleText();
3204             pd3.asText();
3205             // DomainArchitecture
3206             // ------------------
3207             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3208             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3209             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3210             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3211             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3212             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3213             domains0.add( d2 );
3214             domains0.add( d0 );
3215             domains0.add( d3 );
3216             domains0.add( d1 );
3217             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3218             if ( ds0.getNumberOfDomains() != 4 ) {
3219                 return false;
3220             }
3221             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3222             if ( !ds0.isEqual( ds0 ) ) {
3223                 return false;
3224             }
3225             if ( !ds0.isEqual( ds1 ) ) {
3226                 return false;
3227             }
3228             if ( ds1.getNumberOfDomains() != 4 ) {
3229                 return false;
3230             }
3231             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3232             domains1.add( d1 );
3233             domains1.add( d2 );
3234             domains1.add( d4 );
3235             domains1.add( d0 );
3236             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3237             if ( ds0.isEqual( ds2 ) ) {
3238                 return false;
3239             }
3240             ds1.asSimpleText();
3241             ds1.asText();
3242             ds1.toNHX();
3243             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3244             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3245                 System.out.println( ds3.toNHX() );
3246                 return false;
3247             }
3248             if ( ds3.getNumberOfDomains() != 3 ) {
3249                 return false;
3250             }
3251             // Event
3252             // -----
3253             final Event e1 = new Event( Event.EventType.fusion );
3254             if ( e1.isDuplication() ) {
3255                 return false;
3256             }
3257             if ( !e1.isFusion() ) {
3258                 return false;
3259             }
3260             if ( !e1.asText().toString().equals( "fusion" ) ) {
3261                 return false;
3262             }
3263             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3264                 return false;
3265             }
3266             final Event e11 = new Event( Event.EventType.fusion );
3267             if ( !e11.isEqual( e1 ) ) {
3268                 return false;
3269             }
3270             if ( !e11.toNHX().toString().equals( "" ) ) {
3271                 return false;
3272             }
3273             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3274             if ( e2.isDuplication() ) {
3275                 return false;
3276             }
3277             if ( !e2.isSpeciationOrDuplication() ) {
3278                 return false;
3279             }
3280             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3281                 return false;
3282             }
3283             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3284                 return false;
3285             }
3286             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3287                 return false;
3288             }
3289             if ( e11.isEqual( e2 ) ) {
3290                 return false;
3291             }
3292             final Event e2c = ( Event ) e2.copy();
3293             if ( !e2c.isEqual( e2 ) ) {
3294                 return false;
3295             }
3296             Event e3 = new Event( 1, 2, 3 );
3297             if ( e3.isDuplication() ) {
3298                 return false;
3299             }
3300             if ( e3.isSpeciation() ) {
3301                 return false;
3302             }
3303             if ( e3.isGeneLoss() ) {
3304                 return false;
3305             }
3306             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3307                 return false;
3308             }
3309             final Event e3c = ( Event ) e3.copy();
3310             final Event e3cc = ( Event ) e3c.copy();
3311             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3312                 return false;
3313             }
3314             e3 = null;
3315             if ( !e3c.isEqual( e3cc ) ) {
3316                 return false;
3317             }
3318             Event e4 = new Event( 1, 2, 3 );
3319             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3320                 return false;
3321             }
3322             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3323                 return false;
3324             }
3325             final Event e4c = ( Event ) e4.copy();
3326             e4 = null;
3327             final Event e4cc = ( Event ) e4c.copy();
3328             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3329                 return false;
3330             }
3331             if ( !e4c.isEqual( e4cc ) ) {
3332                 return false;
3333             }
3334             final Event e5 = new Event();
3335             if ( !e5.isUnassigned() ) {
3336                 return false;
3337             }
3338             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3339                 return false;
3340             }
3341             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3342                 return false;
3343             }
3344             final Event e6 = new Event( 1, 0, 0 );
3345             if ( !e6.asText().toString().equals( "duplication" ) ) {
3346                 return false;
3347             }
3348             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3349                 return false;
3350             }
3351             final Event e7 = new Event( 0, 1, 0 );
3352             if ( !e7.asText().toString().equals( "speciation" ) ) {
3353                 return false;
3354             }
3355             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3356                 return false;
3357             }
3358             final Event e8 = new Event( 0, 0, 1 );
3359             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3360                 return false;
3361             }
3362             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3363                 return false;
3364             }
3365         }
3366         catch ( final Exception e ) {
3367             e.printStackTrace( System.out );
3368             return false;
3369         }
3370         return true;
3371     }
3372
3373     private static boolean testDeletionOfExternalNodes() {
3374         try {
3375             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3376             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3377             final PhylogenyWriter w = new PhylogenyWriter();
3378             if ( t0.isEmpty() ) {
3379                 return false;
3380             }
3381             if ( t0.getNumberOfExternalNodes() != 1 ) {
3382                 return false;
3383             }
3384             t0.deleteSubtree( t0.getNode( "A" ), false );
3385             if ( t0.getNumberOfExternalNodes() != 0 ) {
3386                 return false;
3387             }
3388             if ( !t0.isEmpty() ) {
3389                 return false;
3390             }
3391             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3392             if ( t1.getNumberOfExternalNodes() != 2 ) {
3393                 return false;
3394             }
3395             t1.deleteSubtree( t1.getNode( "A" ), false );
3396             if ( t1.getNumberOfExternalNodes() != 1 ) {
3397                 return false;
3398             }
3399             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3400                 return false;
3401             }
3402             t1.deleteSubtree( t1.getNode( "B" ), false );
3403             if ( t1.getNumberOfExternalNodes() != 1 ) {
3404                 return false;
3405             }
3406             t1.deleteSubtree( t1.getNode( "r" ), false );
3407             if ( !t1.isEmpty() ) {
3408                 return false;
3409             }
3410             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3411             if ( t2.getNumberOfExternalNodes() != 3 ) {
3412                 return false;
3413             }
3414             t2.deleteSubtree( t2.getNode( "B" ), false );
3415             if ( t2.getNumberOfExternalNodes() != 2 ) {
3416                 return false;
3417             }
3418             t2.toNewHampshireX();
3419             PhylogenyNode n = t2.getNode( "A" );
3420             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3421                 return false;
3422             }
3423             t2.deleteSubtree( t2.getNode( "A" ), false );
3424             if ( t2.getNumberOfExternalNodes() != 2 ) {
3425                 return false;
3426             }
3427             t2.deleteSubtree( t2.getNode( "C" ), true );
3428             if ( t2.getNumberOfExternalNodes() != 1 ) {
3429                 return false;
3430             }
3431             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3432             if ( t3.getNumberOfExternalNodes() != 4 ) {
3433                 return false;
3434             }
3435             t3.deleteSubtree( t3.getNode( "B" ), true );
3436             if ( t3.getNumberOfExternalNodes() != 3 ) {
3437                 return false;
3438             }
3439             n = t3.getNode( "A" );
3440             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3441                 return false;
3442             }
3443             n = n.getNextExternalNode();
3444             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3445                 return false;
3446             }
3447             t3.deleteSubtree( t3.getNode( "A" ), true );
3448             if ( t3.getNumberOfExternalNodes() != 2 ) {
3449                 return false;
3450             }
3451             n = t3.getNode( "C" );
3452             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3453                 return false;
3454             }
3455             t3.deleteSubtree( t3.getNode( "C" ), true );
3456             if ( t3.getNumberOfExternalNodes() != 1 ) {
3457                 return false;
3458             }
3459             t3.deleteSubtree( t3.getNode( "D" ), true );
3460             if ( t3.getNumberOfExternalNodes() != 0 ) {
3461                 return false;
3462             }
3463             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3464             if ( t4.getNumberOfExternalNodes() != 6 ) {
3465                 return false;
3466             }
3467             t4.deleteSubtree( t4.getNode( "B2" ), true );
3468             if ( t4.getNumberOfExternalNodes() != 5 ) {
3469                 return false;
3470             }
3471             String s = w.toNewHampshire( t4, false, true ).toString();
3472             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3473                 return false;
3474             }
3475             t4.deleteSubtree( t4.getNode( "B11" ), true );
3476             if ( t4.getNumberOfExternalNodes() != 4 ) {
3477                 return false;
3478             }
3479             t4.deleteSubtree( t4.getNode( "C" ), true );
3480             if ( t4.getNumberOfExternalNodes() != 3 ) {
3481                 return false;
3482             }
3483             n = t4.getNode( "A" );
3484             n = n.getNextExternalNode();
3485             if ( !n.getName().equals( "B12" ) ) {
3486                 return false;
3487             }
3488             n = n.getNextExternalNode();
3489             if ( !n.getName().equals( "D" ) ) {
3490                 return false;
3491             }
3492             s = w.toNewHampshire( t4, false, true ).toString();
3493             if ( !s.equals( "((A,B12),D);" ) ) {
3494                 return false;
3495             }
3496             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3497             t5.deleteSubtree( t5.getNode( "A" ), true );
3498             if ( t5.getNumberOfExternalNodes() != 5 ) {
3499                 return false;
3500             }
3501             s = w.toNewHampshire( t5, false, true ).toString();
3502             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3503                 return false;
3504             }
3505             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3506             t6.deleteSubtree( t6.getNode( "B11" ), true );
3507             if ( t6.getNumberOfExternalNodes() != 5 ) {
3508                 return false;
3509             }
3510             s = w.toNewHampshire( t6, false, false ).toString();
3511             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3512                 return false;
3513             }
3514             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3515             t7.deleteSubtree( t7.getNode( "B12" ), true );
3516             if ( t7.getNumberOfExternalNodes() != 5 ) {
3517                 return false;
3518             }
3519             s = w.toNewHampshire( t7, false, true ).toString();
3520             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3521                 return false;
3522             }
3523             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3524             t8.deleteSubtree( t8.getNode( "B2" ), true );
3525             if ( t8.getNumberOfExternalNodes() != 5 ) {
3526                 return false;
3527             }
3528             s = w.toNewHampshire( t8, false, false ).toString();
3529             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3530                 return false;
3531             }
3532             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3533             t9.deleteSubtree( t9.getNode( "C" ), true );
3534             if ( t9.getNumberOfExternalNodes() != 5 ) {
3535                 return false;
3536             }
3537             s = w.toNewHampshire( t9, false, true ).toString();
3538             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3539                 return false;
3540             }
3541             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3542             t10.deleteSubtree( t10.getNode( "D" ), true );
3543             if ( t10.getNumberOfExternalNodes() != 5 ) {
3544                 return false;
3545             }
3546             s = w.toNewHampshire( t10, false, true ).toString();
3547             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3548                 return false;
3549             }
3550             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3551             t11.deleteSubtree( t11.getNode( "A" ), true );
3552             if ( t11.getNumberOfExternalNodes() != 2 ) {
3553                 return false;
3554             }
3555             s = w.toNewHampshire( t11, false, true ).toString();
3556             if ( !s.equals( "(B,C);" ) ) {
3557                 return false;
3558             }
3559             t11.deleteSubtree( t11.getNode( "C" ), true );
3560             if ( t11.getNumberOfExternalNodes() != 1 ) {
3561                 return false;
3562             }
3563             s = w.toNewHampshire( t11, false, false ).toString();
3564             if ( !s.equals( "B;" ) ) {
3565                 return false;
3566             }
3567             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3568             t12.deleteSubtree( t12.getNode( "B2" ), true );
3569             if ( t12.getNumberOfExternalNodes() != 8 ) {
3570                 return false;
3571             }
3572             s = w.toNewHampshire( t12, false, true ).toString();
3573             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3574                 return false;
3575             }
3576             t12.deleteSubtree( t12.getNode( "B3" ), true );
3577             if ( t12.getNumberOfExternalNodes() != 7 ) {
3578                 return false;
3579             }
3580             s = w.toNewHampshire( t12, false, true ).toString();
3581             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3582                 return false;
3583             }
3584             t12.deleteSubtree( t12.getNode( "C3" ), true );
3585             if ( t12.getNumberOfExternalNodes() != 6 ) {
3586                 return false;
3587             }
3588             s = w.toNewHampshire( t12, false, true ).toString();
3589             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3590                 return false;
3591             }
3592             t12.deleteSubtree( t12.getNode( "A1" ), true );
3593             if ( t12.getNumberOfExternalNodes() != 5 ) {
3594                 return false;
3595             }
3596             s = w.toNewHampshire( t12, false, true ).toString();
3597             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3598                 return false;
3599             }
3600             t12.deleteSubtree( t12.getNode( "B1" ), true );
3601             if ( t12.getNumberOfExternalNodes() != 4 ) {
3602                 return false;
3603             }
3604             s = w.toNewHampshire( t12, false, true ).toString();
3605             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3606                 return false;
3607             }
3608             t12.deleteSubtree( t12.getNode( "A3" ), true );
3609             if ( t12.getNumberOfExternalNodes() != 3 ) {
3610                 return false;
3611             }
3612             s = w.toNewHampshire( t12, false, true ).toString();
3613             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3614                 return false;
3615             }
3616             t12.deleteSubtree( t12.getNode( "A2" ), true );
3617             if ( t12.getNumberOfExternalNodes() != 2 ) {
3618                 return false;
3619             }
3620             s = w.toNewHampshire( t12, false, true ).toString();
3621             if ( !s.equals( "(C1,C2);" ) ) {
3622                 return false;
3623             }
3624             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3625             t13.deleteSubtree( t13.getNode( "D" ), true );
3626             if ( t13.getNumberOfExternalNodes() != 4 ) {
3627                 return false;
3628             }
3629             s = w.toNewHampshire( t13, false, true ).toString();
3630             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3631                 return false;
3632             }
3633             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3634             t14.deleteSubtree( t14.getNode( "E" ), true );
3635             if ( t14.getNumberOfExternalNodes() != 5 ) {
3636                 return false;
3637             }
3638             s = w.toNewHampshire( t14, false, true ).toString();
3639             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3640                 return false;
3641             }
3642             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3643             t15.deleteSubtree( t15.getNode( "B2" ), true );
3644             if ( t15.getNumberOfExternalNodes() != 11 ) {
3645                 return false;
3646             }
3647             t15.deleteSubtree( t15.getNode( "B1" ), true );
3648             if ( t15.getNumberOfExternalNodes() != 10 ) {
3649                 return false;
3650             }
3651             t15.deleteSubtree( t15.getNode( "B3" ), true );
3652             if ( t15.getNumberOfExternalNodes() != 9 ) {
3653                 return false;
3654             }
3655             t15.deleteSubtree( t15.getNode( "B4" ), true );
3656             if ( t15.getNumberOfExternalNodes() != 8 ) {
3657                 return false;
3658             }
3659             t15.deleteSubtree( t15.getNode( "A1" ), true );
3660             if ( t15.getNumberOfExternalNodes() != 7 ) {
3661                 return false;
3662             }
3663             t15.deleteSubtree( t15.getNode( "C4" ), true );
3664             if ( t15.getNumberOfExternalNodes() != 6 ) {
3665                 return false;
3666             }
3667         }
3668         catch ( final Exception e ) {
3669             e.printStackTrace( System.out );
3670             return false;
3671         }
3672         return true;
3673     }
3674
3675     private static boolean testDescriptiveStatistics() {
3676         try {
3677             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3678             dss1.addValue( 82 );
3679             dss1.addValue( 78 );
3680             dss1.addValue( 70 );
3681             dss1.addValue( 58 );
3682             dss1.addValue( 42 );
3683             if ( dss1.getN() != 5 ) {
3684                 return false;
3685             }
3686             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3687                 return false;
3688             }
3689             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3690                 return false;
3691             }
3692             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3693                 return false;
3694             }
3695             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3696                 return false;
3697             }
3698             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3699                 return false;
3700             }
3701             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3702                 return false;
3703             }
3704             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3705                 return false;
3706             }
3707             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3708                 return false;
3709             }
3710             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3711                 return false;
3712             }
3713             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3714                 return false;
3715             }
3716             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3717                 return false;
3718             }
3719             dss1.addValue( 123 );
3720             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3721                 return false;
3722             }
3723             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3724                 return false;
3725             }
3726             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3727                 return false;
3728             }
3729             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3730             dss2.addValue( -1.85 );
3731             dss2.addValue( 57.5 );
3732             dss2.addValue( 92.78 );
3733             dss2.addValue( 57.78 );
3734             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3735                 return false;
3736             }
3737             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3738                 return false;
3739             }
3740             final double[] a = dss2.getDataAsDoubleArray();
3741             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3742                 return false;
3743             }
3744             dss2.addValue( -100 );
3745             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3746                 return false;
3747             }
3748             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3749                 return false;
3750             }
3751             final double[] ds = new double[ 14 ];
3752             ds[ 0 ] = 34;
3753             ds[ 1 ] = 23;
3754             ds[ 2 ] = 1;
3755             ds[ 3 ] = 32;
3756             ds[ 4 ] = 11;
3757             ds[ 5 ] = 2;
3758             ds[ 6 ] = 12;
3759             ds[ 7 ] = 33;
3760             ds[ 8 ] = 13;
3761             ds[ 9 ] = 22;
3762             ds[ 10 ] = 21;
3763             ds[ 11 ] = 35;
3764             ds[ 12 ] = 24;
3765             ds[ 13 ] = 31;
3766             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3767             if ( bins.length != 4 ) {
3768                 return false;
3769             }
3770             if ( bins[ 0 ] != 2 ) {
3771                 return false;
3772             }
3773             if ( bins[ 1 ] != 3 ) {
3774                 return false;
3775             }
3776             if ( bins[ 2 ] != 4 ) {
3777                 return false;
3778             }
3779             if ( bins[ 3 ] != 5 ) {
3780                 return false;
3781             }
3782             final double[] ds1 = new double[ 9 ];
3783             ds1[ 0 ] = 10.0;
3784             ds1[ 1 ] = 19.0;
3785             ds1[ 2 ] = 9.999;
3786             ds1[ 3 ] = 0.0;
3787             ds1[ 4 ] = 39.9;
3788             ds1[ 5 ] = 39.999;
3789             ds1[ 6 ] = 30.0;
3790             ds1[ 7 ] = 19.999;
3791             ds1[ 8 ] = 30.1;
3792             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3793             if ( bins1.length != 4 ) {
3794                 return false;
3795             }
3796             if ( bins1[ 0 ] != 2 ) {
3797                 return false;
3798             }
3799             if ( bins1[ 1 ] != 3 ) {
3800                 return false;
3801             }
3802             if ( bins1[ 2 ] != 0 ) {
3803                 return false;
3804             }
3805             if ( bins1[ 3 ] != 4 ) {
3806                 return false;
3807             }
3808             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3809             if ( bins1_1.length != 3 ) {
3810                 return false;
3811             }
3812             if ( bins1_1[ 0 ] != 3 ) {
3813                 return false;
3814             }
3815             if ( bins1_1[ 1 ] != 2 ) {
3816                 return false;
3817             }
3818             if ( bins1_1[ 2 ] != 4 ) {
3819                 return false;
3820             }
3821             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3822             if ( bins1_2.length != 3 ) {
3823                 return false;
3824             }
3825             if ( bins1_2[ 0 ] != 2 ) {
3826                 return false;
3827             }
3828             if ( bins1_2[ 1 ] != 2 ) {
3829                 return false;
3830             }
3831             if ( bins1_2[ 2 ] != 2 ) {
3832                 return false;
3833             }
3834             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3835             dss3.addValue( 1 );
3836             dss3.addValue( 1 );
3837             dss3.addValue( 1 );
3838             dss3.addValue( 2 );
3839             dss3.addValue( 3 );
3840             dss3.addValue( 4 );
3841             dss3.addValue( 5 );
3842             dss3.addValue( 5 );
3843             dss3.addValue( 5 );
3844             dss3.addValue( 6 );
3845             dss3.addValue( 7 );
3846             dss3.addValue( 8 );
3847             dss3.addValue( 9 );
3848             dss3.addValue( 10 );
3849             dss3.addValue( 10 );
3850             dss3.addValue( 10 );
3851             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3852             histo.toStringBuffer( 10, '=', 40, 5 );
3853             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3854         }
3855         catch ( final Exception e ) {
3856             e.printStackTrace( System.out );
3857             return false;
3858         }
3859         return true;
3860     }
3861
3862     private static boolean testDir( final String file ) {
3863         try {
3864             final File f = new File( file );
3865             if ( !f.exists() ) {
3866                 return false;
3867             }
3868             if ( !f.isDirectory() ) {
3869                 return false;
3870             }
3871             if ( !f.canRead() ) {
3872                 return false;
3873             }
3874         }
3875         catch ( final Exception e ) {
3876             return false;
3877         }
3878         return true;
3879     }
3880
3881     private static boolean testEbiEntryRetrieval() {
3882         try {
3883             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3884             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3885                 System.out.println( entry.getAccession() );
3886                 return false;
3887             }
3888             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3889                 System.out.println( entry.getTaxonomyScientificName() );
3890                 return false;
3891             }
3892             if ( !entry.getSequenceName()
3893                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3894                 System.out.println( entry.getSequenceName() );
3895                 return false;
3896             }
3897             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
3898             //     System.out.println( entry.getSequenceSymbol() );
3899             //     return false;
3900             // }
3901             if ( !entry.getGeneName().equals( "treX-like" ) ) {
3902                 System.out.println( entry.getGeneName() );
3903                 return false;
3904             }
3905             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
3906                 System.out.println( entry.getTaxonomyIdentifier() );
3907                 return false;
3908             }
3909             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
3910                 System.out.println( entry.getAnnotations().first().getRefValue() );
3911                 return false;
3912             }
3913             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
3914                 System.out.println( entry.getAnnotations().first().getRefSource() );
3915                 return false;
3916             }
3917             if ( entry.getCrossReferences().size() != 5 ) {
3918                 return false;
3919             }
3920             //
3921             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
3922             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
3923                 return false;
3924             }
3925             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
3926                 System.out.println( entry1.getTaxonomyScientificName() );
3927                 return false;
3928             }
3929             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
3930                 System.out.println( entry1.getSequenceName() );
3931                 return false;
3932             }
3933             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
3934                 System.out.println( entry1.getTaxonomyIdentifier() );
3935                 return false;
3936             }
3937             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
3938                 System.out.println( entry1.getGeneName() );
3939                 return false;
3940             }
3941             if ( entry1.getCrossReferences().size() != 6 ) {
3942                 return false;
3943             }
3944             //
3945             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
3946             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
3947                 return false;
3948             }
3949             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3950                 System.out.println( entry2.getTaxonomyScientificName() );
3951                 return false;
3952             }
3953             if ( !entry2.getSequenceName()
3954                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
3955                 System.out.println( entry2.getSequenceName() );
3956                 return false;
3957             }
3958             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
3959                 System.out.println( entry2.getTaxonomyIdentifier() );
3960                 return false;
3961             }
3962             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
3963                 System.out.println( entry2.getGeneName() );
3964                 return false;
3965             }
3966             if ( entry2.getCrossReferences().size() != 3 ) {
3967                 return false;
3968             }
3969             //
3970             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
3971             if ( !entry3.getAccession().equals( "HM043801" ) ) {
3972                 return false;
3973             }
3974             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
3975                 System.out.println( entry3.getTaxonomyScientificName() );
3976                 return false;
3977             }
3978             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
3979                 System.out.println( entry3.getSequenceName() );
3980                 return false;
3981             }
3982             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
3983                 System.out.println( entry3.getTaxonomyIdentifier() );
3984                 return false;
3985             }
3986             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
3987                 System.out.println( entry3.getSequenceSymbol() );
3988                 return false;
3989             }
3990             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
3991                 return false;
3992             }
3993             if ( entry3.getCrossReferences().size() != 8 ) {
3994                 return false;
3995             }
3996             //
3997             //
3998             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
3999             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4000                 return false;
4001             }
4002             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4003                 System.out.println( entry4.getTaxonomyScientificName() );
4004                 return false;
4005             }
4006             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4007                 System.out.println( entry4.getSequenceName() );
4008                 return false;
4009             }
4010             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4011                 System.out.println( entry4.getTaxonomyIdentifier() );
4012                 return false;
4013             }
4014             if ( !entry4.getGeneName().equals( "ras" ) ) {
4015                 System.out.println( entry4.getGeneName() );
4016                 return false;
4017             }
4018             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
4019             //     System.out.println( entry4.getChromosome() );
4020             //     return false;
4021             // }
4022             // if ( !entry4.getMap().equals( "ras" ) ) {
4023             //     System.out.println( entry4.getMap() );
4024             //     return false;
4025             // }
4026             //TODO FIXME gi...
4027             //
4028             //TODO fails:
4029             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
4030             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
4031             //                return false;
4032             //            }
4033             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4034             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4035                 return false;
4036             }
4037             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4038                 System.out.println( entry5.getTaxonomyScientificName() );
4039                 return false;
4040             }
4041             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4042                 System.out.println( entry5.getSequenceName() );
4043                 return false;
4044             }
4045             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4046                 System.out.println( entry5.getTaxonomyIdentifier() );
4047                 return false;
4048             }
4049         }
4050         catch ( final IOException e ) {
4051             System.out.println();
4052             System.out.println( "the following might be due to absence internet connection:" );
4053             e.printStackTrace( System.out );
4054             return true;
4055         }
4056         catch ( final Exception e ) {
4057             e.printStackTrace();
4058             return false;
4059         }
4060         return true;
4061     }
4062
4063     private static boolean testExternalNodeRelatedMethods() {
4064         try {
4065             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4066             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4067             PhylogenyNode n = t1.getNode( "A" );
4068             n = n.getNextExternalNode();
4069             if ( !n.getName().equals( "B" ) ) {
4070                 return false;
4071             }
4072             n = n.getNextExternalNode();
4073             if ( !n.getName().equals( "C" ) ) {
4074                 return false;
4075             }
4076             n = n.getNextExternalNode();
4077             if ( !n.getName().equals( "D" ) ) {
4078                 return false;
4079             }
4080             n = t1.getNode( "B" );
4081             while ( !n.isLastExternalNode() ) {
4082                 n = n.getNextExternalNode();
4083             }
4084             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4085             n = t2.getNode( "A" );
4086             n = n.getNextExternalNode();
4087             if ( !n.getName().equals( "B" ) ) {
4088                 return false;
4089             }
4090             n = n.getNextExternalNode();
4091             if ( !n.getName().equals( "C" ) ) {
4092                 return false;
4093             }
4094             n = n.getNextExternalNode();
4095             if ( !n.getName().equals( "D" ) ) {
4096                 return false;
4097             }
4098             n = t2.getNode( "B" );
4099             while ( !n.isLastExternalNode() ) {
4100                 n = n.getNextExternalNode();
4101             }
4102             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4103             n = t3.getNode( "A" );
4104             n = n.getNextExternalNode();
4105             if ( !n.getName().equals( "B" ) ) {
4106                 return false;
4107             }
4108             n = n.getNextExternalNode();
4109             if ( !n.getName().equals( "C" ) ) {
4110                 return false;
4111             }
4112             n = n.getNextExternalNode();
4113             if ( !n.getName().equals( "D" ) ) {
4114                 return false;
4115             }
4116             n = n.getNextExternalNode();
4117             if ( !n.getName().equals( "E" ) ) {
4118                 return false;
4119             }
4120             n = n.getNextExternalNode();
4121             if ( !n.getName().equals( "F" ) ) {
4122                 return false;
4123             }
4124             n = n.getNextExternalNode();
4125             if ( !n.getName().equals( "G" ) ) {
4126                 return false;
4127             }
4128             n = n.getNextExternalNode();
4129             if ( !n.getName().equals( "H" ) ) {
4130                 return false;
4131             }
4132             n = t3.getNode( "B" );
4133             while ( !n.isLastExternalNode() ) {
4134                 n = n.getNextExternalNode();
4135             }
4136             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4137             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4138                 final PhylogenyNode node = iter.next();
4139             }
4140             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4141             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4142                 final PhylogenyNode node = iter.next();
4143             }
4144             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4145             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4146             if ( !iter.next().getName().equals( "A" ) ) {
4147                 return false;
4148             }
4149             if ( !iter.next().getName().equals( "B" ) ) {
4150                 return false;
4151             }
4152             if ( !iter.next().getName().equals( "C" ) ) {
4153                 return false;
4154             }
4155             if ( !iter.next().getName().equals( "D" ) ) {
4156                 return false;
4157             }
4158             if ( !iter.next().getName().equals( "E" ) ) {
4159                 return false;
4160             }
4161             if ( !iter.next().getName().equals( "F" ) ) {
4162                 return false;
4163             }
4164             if ( iter.hasNext() ) {
4165                 return false;
4166             }
4167         }
4168         catch ( final Exception e ) {
4169             e.printStackTrace( System.out );
4170             return false;
4171         }
4172         return true;
4173     }
4174
4175     private static boolean testExtractSNFromNodeName() {
4176         try {
4177             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4178                 return false;
4179             }
4180             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
4181                     .equals( "Mus musculus musculus" ) ) {
4182                 return false;
4183             }
4184             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
4185                     .equals( "Mus musculus musculus" ) ) {
4186                 return false;
4187             }
4188             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
4189                 return false;
4190             }
4191             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
4192                     .equals( "Mus musculus" ) ) {
4193                 return false;
4194             }
4195             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4196                 return false;
4197             }
4198             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus" )
4199                     .equals( "Mus musculus musculus" ) ) {
4200                 return false;
4201             }
4202             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4203                     .equals( "Mus musculus musculus" ) ) {
4204                 return false;
4205             }
4206             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4207                 return false;
4208             }
4209             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4210                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4211                 return false;
4212             }
4213             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4214                     .equals( "Escherichia coli str K12/DH10B" ) ) {
4215                 return false;
4216             }
4217             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4218                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4219                 return false;
4220             }
4221             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4222                     .equals( "Arabidopsis lyrata subsp lyrata" ) ) {
4223                 return false;
4224             }
4225             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4226                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4227                 return false;
4228             }
4229             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4230                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4231                 return false;
4232             }
4233             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4234                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4235                 return false;
4236             }
4237             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4238                     .equals( "Arabidopsis lyrata subsp lyrata" ) ) {
4239                 return false;
4240             }
4241             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4242                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4243                 return false;
4244             }
4245             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4246                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4247                 return false;
4248             }
4249             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) " )
4250                     .equals( "Escherichia coli (strain K12)" ) ) {
4251                 System.out.println( ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" ) );
4252                 return false;
4253             }
4254         }
4255         catch ( final Exception e ) {
4256             e.printStackTrace( System.out );
4257             return false;
4258         }
4259         return true;
4260     }
4261
4262     private static boolean testExtractTaxonomyCodeFromNodeName() {
4263         try {
4264             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4265                 return false;
4266             }
4267             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4268                     .equals( "SOYBN" ) ) {
4269                 return false;
4270             }
4271             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4272                     .equals( "ARATH" ) ) {
4273                 return false;
4274             }
4275             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4276                     .equals( "ARATH" ) ) {
4277                 return false;
4278             }
4279             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4280                 return false;
4281             }
4282             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4283                 return false;
4284             }
4285             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4286                 return false;
4287             }
4288             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4289                     .equals( "SOYBN" ) ) {
4290                 return false;
4291             }
4292             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4293                     .equals( "SOYBN" ) ) {
4294                 return false;
4295             }
4296             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4297                     .equals( "SOYBN" ) ) {
4298                 return false;
4299             }
4300             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4301                     .equals( "SOYBN" ) ) {
4302                 return false;
4303             }
4304             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4305                     .equals( "SOYBN" ) ) {
4306                 return false;
4307             }
4308             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4309                     .equals( "SOYBN" ) ) {
4310                 return false;
4311             }
4312             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4313                     .equals( "SOYBN" ) ) {
4314                 return false;
4315             }
4316             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4317                     .equals( "SOYBN" ) ) {
4318                 return false;
4319             }
4320             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4321                 return false;
4322             }
4323             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4324                     .equals( "SOYBN" ) ) {
4325                 return false;
4326             }
4327             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4328                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4329                 return false;
4330             }
4331             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4332                     .equals( "9YX45" ) ) {
4333                 return false;
4334             }
4335             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4336                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4337                     .equals( "MOUSE" ) ) {
4338                 return false;
4339             }
4340             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4341                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4342                     .equals( "MOUSE" ) ) {
4343                 return false;
4344             }
4345             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4346                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4347                     .equals( "MOUSE" ) ) {
4348                 return false;
4349             }
4350             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4351                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4352                 return false;
4353             }
4354             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4355                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4356                 return false;
4357             }
4358             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4359                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4360                 return false;
4361             }
4362             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4363                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4364                 return false;
4365             }
4366             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4367                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4368                 return false;
4369             }
4370             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4371                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4372                 return false;
4373             }
4374             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4375                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4376                 return false;
4377             }
4378             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4379                     .equals( "RAT" ) ) {
4380                 return false;
4381             }
4382             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4383                     .equals( "PIG" ) ) {
4384                 return false;
4385             }
4386             if ( !ParserUtils
4387                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4388                     .equals( "MOUSE" ) ) {
4389                 return false;
4390             }
4391             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4392                     .equals( "MOUSE" ) ) {
4393                 return false;
4394             }
4395             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4396                 return false;
4397             }
4398         }
4399         catch ( final Exception e ) {
4400             e.printStackTrace( System.out );
4401             return false;
4402         }
4403         return true;
4404     }
4405
4406     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4407         try {
4408             PhylogenyNode n = new PhylogenyNode();
4409             n.setName( "tr|B3RJ64" );
4410             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4411                 return false;
4412             }
4413             n.setName( "tr.B3RJ64" );
4414             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4415                 return false;
4416             }
4417             n.setName( "tr=B3RJ64" );
4418             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4419                 return false;
4420             }
4421             n.setName( "tr-B3RJ64" );
4422             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4423                 return false;
4424             }
4425             n.setName( "tr/B3RJ64" );
4426             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4427                 return false;
4428             }
4429             n.setName( "tr\\B3RJ64" );
4430             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4431                 return false;
4432             }
4433             n.setName( "tr_B3RJ64" );
4434             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4435                 return false;
4436             }
4437             n.setName( " tr|B3RJ64 " );
4438             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4439                 return false;
4440             }
4441             n.setName( "-tr|B3RJ64-" );
4442             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4443                 return false;
4444             }
4445             n.setName( "-tr=B3RJ64-" );
4446             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4447                 return false;
4448             }
4449             n.setName( "_tr=B3RJ64_" );
4450             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4451                 return false;
4452             }
4453             n.setName( " tr_tr|B3RJ64_sp|123 " );
4454             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4455                 return false;
4456             }
4457             n.setName( "B3RJ64" );
4458             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4459                 return false;
4460             }
4461             n.setName( "sp|B3RJ64" );
4462             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4463                 return false;
4464             }
4465             n.setName( "sp|B3RJ64C" );
4466             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4467                 return false;
4468             }
4469             n.setName( "sp B3RJ64" );
4470             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4471                 return false;
4472             }
4473             n.setName( "sp|B3RJ6X" );
4474             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4475                 return false;
4476             }
4477             n.setName( "sp|B3RJ6" );
4478             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4479                 return false;
4480             }
4481             n.setName( "K1PYK7_CRAGI" );
4482             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4483                 return false;
4484             }
4485             n.setName( "K1PYK7_PEA" );
4486             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4487                 return false;
4488             }
4489             n.setName( "K1PYK7_RAT" );
4490             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4491                 return false;
4492             }
4493             n.setName( "K1PYK7_PIG" );
4494             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4495                 return false;
4496             }
4497             n.setName( "~K1PYK7_PIG~" );
4498             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4499                 return false;
4500             }
4501             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4502             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4503                 return false;
4504             }
4505             n.setName( "K1PYKX_CRAGI" );
4506             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4507                 return false;
4508             }
4509             n.setName( "XXXXX_CRAGI" );
4510             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4511                 return false;
4512             }
4513             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4514             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4515                 return false;
4516             }
4517             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4518             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4519                 return false;
4520             }
4521             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4522             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4523                 return false;
4524             }
4525             n = new PhylogenyNode();
4526             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4527             seq.setSymbol( "K1PYK7_CRAGI" );
4528             n.getNodeData().addSequence( seq );
4529             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4530                 return false;
4531             }
4532             seq.setSymbol( "tr|B3RJ64" );
4533             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4534                 return false;
4535             }
4536             n = new PhylogenyNode();
4537             seq = new org.forester.phylogeny.data.Sequence();
4538             seq.setName( "K1PYK7_CRAGI" );
4539             n.getNodeData().addSequence( seq );
4540             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4541                 return false;
4542             }
4543             seq.setName( "tr|B3RJ64" );
4544             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4545                 return false;
4546             }
4547             n = new PhylogenyNode();
4548             seq = new org.forester.phylogeny.data.Sequence();
4549             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4550             n.getNodeData().addSequence( seq );
4551             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4552                 return false;
4553             }
4554             n = new PhylogenyNode();
4555             seq = new org.forester.phylogeny.data.Sequence();
4556             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4557             n.getNodeData().addSequence( seq );
4558             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4559                 return false;
4560             }
4561             //
4562             n = new PhylogenyNode();
4563             n.setName( "ACP19736" );
4564             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4565                 return false;
4566             }
4567             n = new PhylogenyNode();
4568             n.setName( "|ACP19736|" );
4569             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4570                 return false;
4571             }
4572         }
4573         catch ( final Exception e ) {
4574             e.printStackTrace( System.out );
4575             return false;
4576         }
4577         return true;
4578     }
4579
4580     private static boolean testFastaParser() {
4581         try {
4582             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4583                 return false;
4584             }
4585             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4586                 return false;
4587             }
4588             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4589             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4590                 return false;
4591             }
4592             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4593                 return false;
4594             }
4595             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4596                 return false;
4597             }
4598             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4599                 return false;
4600             }
4601             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4602                 return false;
4603             }
4604             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4605                 return false;
4606             }
4607         }
4608         catch ( final Exception e ) {
4609             e.printStackTrace();
4610             return false;
4611         }
4612         return true;
4613     }
4614
4615     private static boolean testGenbankAccessorParsing() {
4616         //The format for GenBank Accession numbers are:
4617         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4618         //Protein:    3 letters + 5 numerals
4619         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4620         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4621             return false;
4622         }
4623         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4624             return false;
4625         }
4626         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4627             return false;
4628         }
4629         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4630             return false;
4631         }
4632         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4633             return false;
4634         }
4635         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4636             return false;
4637         }
4638         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4639             return false;
4640         }
4641         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4642             return false;
4643         }
4644         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4645             return false;
4646         }
4647         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4648             return false;
4649         }
4650         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4651             return false;
4652         }
4653         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4654             return false;
4655         }
4656         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4657             return false;
4658         }
4659         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4660             return false;
4661         }
4662         return true;
4663     }
4664
4665     private static boolean testGeneralMsaParser() {
4666         try {
4667             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4668             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4669             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4670             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4671             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4672             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4673             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4674             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4675             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4676                 return false;
4677             }
4678             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4679                 return false;
4680             }
4681             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4682                 return false;
4683             }
4684             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4685                 return false;
4686             }
4687             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4688                 return false;
4689             }
4690             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4691                 return false;
4692             }
4693             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4694                 return false;
4695             }
4696             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4697                 return false;
4698             }
4699             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4700                 return false;
4701             }
4702             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4703                 return false;
4704             }
4705             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4706                 return false;
4707             }
4708             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4709                 return false;
4710             }
4711             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4712             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4713                 return false;
4714             }
4715             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4716                 return false;
4717             }
4718             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4719                 return false;
4720             }
4721             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4722             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4723                 return false;
4724             }
4725             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4726                 return false;
4727             }
4728             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4729                 return false;
4730             }
4731             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4732             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4733                 return false;
4734             }
4735             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4736                 return false;
4737             }
4738             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4739                 return false;
4740             }
4741         }
4742         catch ( final Exception e ) {
4743             e.printStackTrace();
4744             return false;
4745         }
4746         return true;
4747     }
4748
4749     private static boolean testGeneralTable() {
4750         try {
4751             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4752             t0.setValue( 3, 2, "23" );
4753             t0.setValue( 10, 1, "error" );
4754             t0.setValue( 10, 1, "110" );
4755             t0.setValue( 9, 1, "19" );
4756             t0.setValue( 1, 10, "101" );
4757             t0.setValue( 10, 10, "1010" );
4758             t0.setValue( 100, 10, "10100" );
4759             t0.setValue( 0, 0, "00" );
4760             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4761                 return false;
4762             }
4763             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4764                 return false;
4765             }
4766             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4767                 return false;
4768             }
4769             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4770                 return false;
4771             }
4772             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4773                 return false;
4774             }
4775             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4776                 return false;
4777             }
4778             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4779                 return false;
4780             }
4781             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4782                 return false;
4783             }
4784             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4785                 return false;
4786             }
4787             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4788             t1.setValue( "3", "2", "23" );
4789             t1.setValue( "10", "1", "error" );
4790             t1.setValue( "10", "1", "110" );
4791             t1.setValue( "9", "1", "19" );
4792             t1.setValue( "1", "10", "101" );
4793             t1.setValue( "10", "10", "1010" );
4794             t1.setValue( "100", "10", "10100" );
4795             t1.setValue( "0", "0", "00" );
4796             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4797             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4798                 return false;
4799             }
4800             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4801                 return false;
4802             }
4803             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4804                 return false;
4805             }
4806             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4807                 return false;
4808             }
4809             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4810                 return false;
4811             }
4812             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4813                 return false;
4814             }
4815             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4816                 return false;
4817             }
4818             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4819                 return false;
4820             }
4821             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4822                 return false;
4823             }
4824             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4825                 return false;
4826             }
4827         }
4828         catch ( final Exception e ) {
4829             e.printStackTrace( System.out );
4830             return false;
4831         }
4832         return true;
4833     }
4834
4835     private static boolean testGetDistance() {
4836         try {
4837             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4838             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",
4839                                                  new NHXParser() )[ 0 ];
4840             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4841                 return false;
4842             }
4843             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4844                 return false;
4845             }
4846             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
4847                 return false;
4848             }
4849             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
4850                 return false;
4851             }
4852             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
4853                 return false;
4854             }
4855             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
4856                 return false;
4857             }
4858             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
4859                 return false;
4860             }
4861             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
4862                 return false;
4863             }
4864             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
4865                 return false;
4866             }
4867             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
4868                 return false;
4869             }
4870             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
4871                 return false;
4872             }
4873             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
4874                 return false;
4875             }
4876             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
4877                 return false;
4878             }
4879             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
4880                 return false;
4881             }
4882             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
4883                 return false;
4884             }
4885             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
4886                 return false;
4887             }
4888             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
4889                 return false;
4890             }
4891             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
4892                 return false;
4893             }
4894             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
4895                 return false;
4896             }
4897             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
4898                 return false;
4899             }
4900             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
4901                 return false;
4902             }
4903             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
4904                 return false;
4905             }
4906             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
4907                 return false;
4908             }
4909             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
4910                 return false;
4911             }
4912             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
4913                 return false;
4914             }
4915             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
4916                 return false;
4917             }
4918             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
4919                 return false;
4920             }
4921             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
4922                 return false;
4923             }
4924             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
4925                 return false;
4926             }
4927             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
4928                 return false;
4929             }
4930             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
4931                 return false;
4932             }
4933             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",
4934                                                  new NHXParser() )[ 0 ];
4935             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
4936                 return false;
4937             }
4938             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
4939                 return false;
4940             }
4941             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
4942                 return false;
4943             }
4944             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
4945                 return false;
4946             }
4947             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
4948                 return false;
4949             }
4950             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
4951                 return false;
4952             }
4953             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
4954                 return false;
4955             }
4956             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
4957                 return false;
4958             }
4959             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
4960                 return false;
4961             }
4962             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
4963                 return false;
4964             }
4965             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
4966                 return false;
4967             }
4968         }
4969         catch ( final Exception e ) {
4970             e.printStackTrace( System.out );
4971             return false;
4972         }
4973         return true;
4974     }
4975
4976     private static boolean testGetLCA() {
4977         try {
4978             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4979             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4980                                                  new NHXParser() )[ 0 ];
4981             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
4982             if ( !A.getName().equals( "A" ) ) {
4983                 return false;
4984             }
4985             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
4986             if ( !gh.getName().equals( "gh" ) ) {
4987                 return false;
4988             }
4989             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
4990             if ( !ab.getName().equals( "ab" ) ) {
4991                 return false;
4992             }
4993             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
4994             if ( !ab2.getName().equals( "ab" ) ) {
4995                 return false;
4996             }
4997             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
4998             if ( !gh2.getName().equals( "gh" ) ) {
4999                 return false;
5000             }
5001             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5002             if ( !gh3.getName().equals( "gh" ) ) {
5003                 return false;
5004             }
5005             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5006             if ( !abc.getName().equals( "abc" ) ) {
5007                 return false;
5008             }
5009             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5010             if ( !abc2.getName().equals( "abc" ) ) {
5011                 return false;
5012             }
5013             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5014             if ( !abcd.getName().equals( "abcd" ) ) {
5015                 return false;
5016             }
5017             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5018             if ( !abcd2.getName().equals( "abcd" ) ) {
5019                 return false;
5020             }
5021             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5022             if ( !abcdef.getName().equals( "abcdef" ) ) {
5023                 return false;
5024             }
5025             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5026             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5027                 return false;
5028             }
5029             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5030             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5031                 return false;
5032             }
5033             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5034             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5035                 return false;
5036             }
5037             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5038             if ( !abcde.getName().equals( "abcde" ) ) {
5039                 return false;
5040             }
5041             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5042             if ( !abcde2.getName().equals( "abcde" ) ) {
5043                 return false;
5044             }
5045             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5046             if ( !r.getName().equals( "abcdefgh" ) ) {
5047                 return false;
5048             }
5049             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5050             if ( !r2.getName().equals( "abcdefgh" ) ) {
5051                 return false;
5052             }
5053             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5054             if ( !r3.getName().equals( "abcdefgh" ) ) {
5055                 return false;
5056             }
5057             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5058             if ( !abcde3.getName().equals( "abcde" ) ) {
5059                 return false;
5060             }
5061             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5062             if ( !abcde4.getName().equals( "abcde" ) ) {
5063                 return false;
5064             }
5065             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5066             if ( !ab3.getName().equals( "ab" ) ) {
5067                 return false;
5068             }
5069             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5070             if ( !ab4.getName().equals( "ab" ) ) {
5071                 return false;
5072             }
5073             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5074             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5075             if ( !cd.getName().equals( "cd" ) ) {
5076                 return false;
5077             }
5078             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5079             if ( !cd2.getName().equals( "cd" ) ) {
5080                 return false;
5081             }
5082             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5083             if ( !cde.getName().equals( "cde" ) ) {
5084                 return false;
5085             }
5086             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5087             if ( !cde2.getName().equals( "cde" ) ) {
5088                 return false;
5089             }
5090             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5091             if ( !cdef.getName().equals( "cdef" ) ) {
5092                 return false;
5093             }
5094             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5095             if ( !cdef2.getName().equals( "cdef" ) ) {
5096                 return false;
5097             }
5098             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5099             if ( !cdef3.getName().equals( "cdef" ) ) {
5100                 return false;
5101             }
5102             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5103             if ( !rt.getName().equals( "r" ) ) {
5104                 return false;
5105             }
5106             final Phylogeny p3 = factory
5107                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5108                              new NHXParser() )[ 0 ];
5109             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5110             if ( !bc_3.getName().equals( "bc" ) ) {
5111                 return false;
5112             }
5113             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5114             if ( !ac_3.getName().equals( "abc" ) ) {
5115                 return false;
5116             }
5117             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5118             if ( !ad_3.getName().equals( "abcde" ) ) {
5119                 return false;
5120             }
5121             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5122             if ( !af_3.getName().equals( "abcdef" ) ) {
5123                 return false;
5124             }
5125             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5126             if ( !ag_3.getName().equals( "" ) ) {
5127                 return false;
5128             }
5129             if ( !ag_3.isRoot() ) {
5130                 return false;
5131             }
5132             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5133             if ( !al_3.getName().equals( "" ) ) {
5134                 return false;
5135             }
5136             if ( !al_3.isRoot() ) {
5137                 return false;
5138             }
5139             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5140             if ( !kl_3.getName().equals( "" ) ) {
5141                 return false;
5142             }
5143             if ( !kl_3.isRoot() ) {
5144                 return false;
5145             }
5146             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5147             if ( !fl_3.getName().equals( "" ) ) {
5148                 return false;
5149             }
5150             if ( !fl_3.isRoot() ) {
5151                 return false;
5152             }
5153             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5154             if ( !gk_3.getName().equals( "ghijk" ) ) {
5155                 return false;
5156             }
5157             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5158             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5159             if ( !r_4.getName().equals( "r" ) ) {
5160                 return false;
5161             }
5162             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5163             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5164             if ( !r_5.getName().equals( "root" ) ) {
5165                 return false;
5166             }
5167             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5168             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5169             if ( !r_6.getName().equals( "rot" ) ) {
5170                 return false;
5171             }
5172             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5173             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5174             if ( !r_7.getName().equals( "rott" ) ) {
5175                 return false;
5176             }
5177         }
5178         catch ( final Exception e ) {
5179             e.printStackTrace( System.out );
5180             return false;
5181         }
5182         return true;
5183     }
5184
5185     private static boolean testGetLCA2() {
5186         try {
5187             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5188             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5189             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5190             PhylogenyMethods.preOrderReId( p_a );
5191             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5192                                                                                               p_a.getNode( "a" ) );
5193             if ( !p_a_1.getName().equals( "a" ) ) {
5194                 return false;
5195             }
5196             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5197             PhylogenyMethods.preOrderReId( p_b );
5198             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5199                                                                                               p_b.getNode( "a" ) );
5200             if ( !p_b_1.getName().equals( "b" ) ) {
5201                 return false;
5202             }
5203             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5204                                                                                               p_b.getNode( "b" ) );
5205             if ( !p_b_2.getName().equals( "b" ) ) {
5206                 return false;
5207             }
5208             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5209             PhylogenyMethods.preOrderReId( p_c );
5210             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5211                                                                                               p_c.getNode( "a" ) );
5212             if ( !p_c_1.getName().equals( "b" ) ) {
5213                 return false;
5214             }
5215             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5216                                                                                               p_c.getNode( "c" ) );
5217             if ( !p_c_2.getName().equals( "c" ) ) {
5218                 System.out.println( p_c_2.getName() );
5219                 System.exit( -1 );
5220                 return false;
5221             }
5222             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5223                                                                                               p_c.getNode( "b" ) );
5224             if ( !p_c_3.getName().equals( "b" ) ) {
5225                 return false;
5226             }
5227             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5228                                                                                               p_c.getNode( "a" ) );
5229             if ( !p_c_4.getName().equals( "c" ) ) {
5230                 return false;
5231             }
5232             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5233                                                  new NHXParser() )[ 0 ];
5234             PhylogenyMethods.preOrderReId( p1 );
5235             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5236                                                                                           p1.getNode( "A" ) );
5237             if ( !A.getName().equals( "A" ) ) {
5238                 return false;
5239             }
5240             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5241                                                                                            p1.getNode( "gh" ) );
5242             if ( !gh.getName().equals( "gh" ) ) {
5243                 return false;
5244             }
5245             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5246                                                                                            p1.getNode( "B" ) );
5247             if ( !ab.getName().equals( "ab" ) ) {
5248                 return false;
5249             }
5250             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5251                                                                                             p1.getNode( "A" ) );
5252             if ( !ab2.getName().equals( "ab" ) ) {
5253                 return false;
5254             }
5255             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5256                                                                                             p1.getNode( "G" ) );
5257             if ( !gh2.getName().equals( "gh" ) ) {
5258                 return false;
5259             }
5260             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5261                                                                                             p1.getNode( "H" ) );
5262             if ( !gh3.getName().equals( "gh" ) ) {
5263                 return false;
5264             }
5265             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5266                                                                                             p1.getNode( "A" ) );
5267             if ( !abc.getName().equals( "abc" ) ) {
5268                 return false;
5269             }
5270             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5271                                                                                              p1.getNode( "C" ) );
5272             if ( !abc2.getName().equals( "abc" ) ) {
5273                 return false;
5274             }
5275             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5276                                                                                              p1.getNode( "D" ) );
5277             if ( !abcd.getName().equals( "abcd" ) ) {
5278                 return false;
5279             }
5280             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5281                                                                                               p1.getNode( "A" ) );
5282             if ( !abcd2.getName().equals( "abcd" ) ) {
5283                 return false;
5284             }
5285             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5286                                                                                                p1.getNode( "F" ) );
5287             if ( !abcdef.getName().equals( "abcdef" ) ) {
5288                 return false;
5289             }
5290             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5291                                                                                                 p1.getNode( "A" ) );
5292             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5293                 return false;
5294             }
5295             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5296                                                                                                 p1.getNode( "F" ) );
5297             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5298                 return false;
5299             }
5300             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5301                                                                                                 p1.getNode( "ab" ) );
5302             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5303                 return false;
5304             }
5305             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5306                                                                                               p1.getNode( "E" ) );
5307             if ( !abcde.getName().equals( "abcde" ) ) {
5308                 return false;
5309             }
5310             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5311                                                                                                p1.getNode( "A" ) );
5312             if ( !abcde2.getName().equals( "abcde" ) ) {
5313                 return false;
5314             }
5315             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5316                                                                                           p1.getNode( "abcdefgh" ) );
5317             if ( !r.getName().equals( "abcdefgh" ) ) {
5318                 return false;
5319             }
5320             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5321                                                                                            p1.getNode( "H" ) );
5322             if ( !r2.getName().equals( "abcdefgh" ) ) {
5323                 return false;
5324             }
5325             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5326                                                                                            p1.getNode( "A" ) );
5327             if ( !r3.getName().equals( "abcdefgh" ) ) {
5328                 return false;
5329             }
5330             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5331                                                                                                p1.getNode( "abcde" ) );
5332             if ( !abcde3.getName().equals( "abcde" ) ) {
5333                 return false;
5334             }
5335             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5336                                                                                                p1.getNode( "E" ) );
5337             if ( !abcde4.getName().equals( "abcde" ) ) {
5338                 return false;
5339             }
5340             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5341                                                                                             p1.getNode( "B" ) );
5342             if ( !ab3.getName().equals( "ab" ) ) {
5343                 return false;
5344             }
5345             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5346                                                                                             p1.getNode( "ab" ) );
5347             if ( !ab4.getName().equals( "ab" ) ) {
5348                 return false;
5349             }
5350             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5351             PhylogenyMethods.preOrderReId( p2 );
5352             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5353                                                                                            p2.getNode( "d" ) );
5354             if ( !cd.getName().equals( "cd" ) ) {
5355                 return false;
5356             }
5357             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5358                                                                                             p2.getNode( "c" ) );
5359             if ( !cd2.getName().equals( "cd" ) ) {
5360                 return false;
5361             }
5362             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5363                                                                                             p2.getNode( "e" ) );
5364             if ( !cde.getName().equals( "cde" ) ) {
5365                 return false;
5366             }
5367             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5368                                                                                              p2.getNode( "c" ) );
5369             if ( !cde2.getName().equals( "cde" ) ) {
5370                 return false;
5371             }
5372             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5373                                                                                              p2.getNode( "f" ) );
5374             if ( !cdef.getName().equals( "cdef" ) ) {
5375                 return false;
5376             }
5377             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5378                                                                                               p2.getNode( "f" ) );
5379             if ( !cdef2.getName().equals( "cdef" ) ) {
5380                 return false;
5381             }
5382             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5383                                                                                               p2.getNode( "d" ) );
5384             if ( !cdef3.getName().equals( "cdef" ) ) {
5385                 return false;
5386             }
5387             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5388                                                                                            p2.getNode( "a" ) );
5389             if ( !rt.getName().equals( "r" ) ) {
5390                 return false;
5391             }
5392             final Phylogeny p3 = factory
5393                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5394                              new NHXParser() )[ 0 ];
5395             PhylogenyMethods.preOrderReId( p3 );
5396             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5397                                                                                              p3.getNode( "c" ) );
5398             if ( !bc_3.getName().equals( "bc" ) ) {
5399                 return false;
5400             }
5401             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5402                                                                                              p3.getNode( "c" ) );
5403             if ( !ac_3.getName().equals( "abc" ) ) {
5404                 return false;
5405             }
5406             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5407                                                                                              p3.getNode( "d" ) );
5408             if ( !ad_3.getName().equals( "abcde" ) ) {
5409                 return false;
5410             }
5411             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5412                                                                                              p3.getNode( "f" ) );
5413             if ( !af_3.getName().equals( "abcdef" ) ) {
5414                 return false;
5415             }
5416             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5417                                                                                              p3.getNode( "g" ) );
5418             if ( !ag_3.getName().equals( "" ) ) {
5419                 return false;
5420             }
5421             if ( !ag_3.isRoot() ) {
5422                 return false;
5423             }
5424             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5425                                                                                              p3.getNode( "l" ) );
5426             if ( !al_3.getName().equals( "" ) ) {
5427                 return false;
5428             }
5429             if ( !al_3.isRoot() ) {
5430                 return false;
5431             }
5432             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5433                                                                                              p3.getNode( "l" ) );
5434             if ( !kl_3.getName().equals( "" ) ) {
5435                 return false;
5436             }
5437             if ( !kl_3.isRoot() ) {
5438                 return false;
5439             }
5440             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5441                                                                                              p3.getNode( "l" ) );
5442             if ( !fl_3.getName().equals( "" ) ) {
5443                 return false;
5444             }
5445             if ( !fl_3.isRoot() ) {
5446                 return false;
5447             }
5448             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5449                                                                                              p3.getNode( "k" ) );
5450             if ( !gk_3.getName().equals( "ghijk" ) ) {
5451                 return false;
5452             }
5453             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5454             PhylogenyMethods.preOrderReId( p4 );
5455             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5456                                                                                             p4.getNode( "c" ) );
5457             if ( !r_4.getName().equals( "r" ) ) {
5458                 return false;
5459             }
5460             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5461             PhylogenyMethods.preOrderReId( p5 );
5462             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5463                                                                                             p5.getNode( "c" ) );
5464             if ( !r_5.getName().equals( "root" ) ) {
5465                 return false;
5466             }
5467             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5468             PhylogenyMethods.preOrderReId( p6 );
5469             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5470                                                                                             p6.getNode( "a" ) );
5471             if ( !r_6.getName().equals( "rot" ) ) {
5472                 return false;
5473             }
5474             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5475             PhylogenyMethods.preOrderReId( p7 );
5476             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5477                                                                                             p7.getNode( "e" ) );
5478             if ( !r_7.getName().equals( "rott" ) ) {
5479                 return false;
5480             }
5481             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5482                                                                                              p7.getNode( "a" ) );
5483             if ( !r_71.getName().equals( "rott" ) ) {
5484                 return false;
5485             }
5486             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5487                                                                                              p7.getNode( "rott" ) );
5488             if ( !r_72.getName().equals( "rott" ) ) {
5489                 return false;
5490             }
5491             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5492                                                                                              p7.getNode( "a" ) );
5493             if ( !r_73.getName().equals( "rott" ) ) {
5494                 return false;
5495             }
5496             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5497                                                                                              p7.getNode( "rott" ) );
5498             if ( !r_74.getName().equals( "rott" ) ) {
5499                 return false;
5500             }
5501             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5502                                                                                              p7.getNode( "e" ) );
5503             if ( !r_75.getName().equals( "e" ) ) {
5504                 return false;
5505             }
5506         }
5507         catch ( final Exception e ) {
5508             e.printStackTrace( System.out );
5509             return false;
5510         }
5511         return true;
5512     }
5513
5514     private static boolean testHmmscanOutputParser() {
5515         final String test_dir = Test.PATH_TO_TEST_DATA;
5516         try {
5517             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5518                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5519             parser1.parse();
5520             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5521                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5522             final List<Protein> proteins = parser2.parse();
5523             if ( parser2.getProteinsEncountered() != 4 ) {
5524                 return false;
5525             }
5526             if ( proteins.size() != 4 ) {
5527                 return false;
5528             }
5529             if ( parser2.getDomainsEncountered() != 69 ) {
5530                 return false;
5531             }
5532             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5533                 return false;
5534             }
5535             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5536                 return false;
5537             }
5538             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5539                 return false;
5540             }
5541             final Protein p1 = proteins.get( 0 );
5542             if ( p1.getNumberOfProteinDomains() != 15 ) {
5543                 return false;
5544             }
5545             if ( p1.getLength() != 850 ) {
5546                 return false;
5547             }
5548             final Protein p2 = proteins.get( 1 );
5549             if ( p2.getNumberOfProteinDomains() != 51 ) {
5550                 return false;
5551             }
5552             if ( p2.getLength() != 1291 ) {
5553                 return false;
5554             }
5555             final Protein p3 = proteins.get( 2 );
5556             if ( p3.getNumberOfProteinDomains() != 2 ) {
5557                 return false;
5558             }
5559             final Protein p4 = proteins.get( 3 );
5560             if ( p4.getNumberOfProteinDomains() != 1 ) {
5561                 return false;
5562             }
5563             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5564                 return false;
5565             }
5566             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5567                 return false;
5568             }
5569             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5570                 return false;
5571             }
5572             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5573                 return false;
5574             }
5575             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5576                 return false;
5577             }
5578             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5579                 return false;
5580             }
5581             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5582                 return false;
5583             }
5584         }
5585         catch ( final Exception e ) {
5586             e.printStackTrace( System.out );
5587             return false;
5588         }
5589         return true;
5590     }
5591
5592     private static boolean testLastExternalNodeMethods() {
5593         try {
5594             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5595             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5596             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5597             final PhylogenyNode n1 = t0.getNode( "A" );
5598             if ( n1.isLastExternalNode() ) {
5599                 return false;
5600             }
5601             final PhylogenyNode n2 = t0.getNode( "B" );
5602             if ( n2.isLastExternalNode() ) {
5603                 return false;
5604             }
5605             final PhylogenyNode n3 = t0.getNode( "C" );
5606             if ( n3.isLastExternalNode() ) {
5607                 return false;
5608             }
5609             final PhylogenyNode n4 = t0.getNode( "D" );
5610             if ( !n4.isLastExternalNode() ) {
5611                 return false;
5612             }
5613         }
5614         catch ( final Exception e ) {
5615             e.printStackTrace( System.out );
5616             return false;
5617         }
5618         return true;
5619     }
5620
5621     private static boolean testLevelOrderIterator() {
5622         try {
5623             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5624             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5625             PhylogenyNodeIterator it0;
5626             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5627                 it0.next();
5628             }
5629             for( it0.reset(); it0.hasNext(); ) {
5630                 it0.next();
5631             }
5632             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5633             if ( !it.next().getName().equals( "r" ) ) {
5634                 return false;
5635             }
5636             if ( !it.next().getName().equals( "ab" ) ) {
5637                 return false;
5638             }
5639             if ( !it.next().getName().equals( "cd" ) ) {
5640                 return false;
5641             }
5642             if ( !it.next().getName().equals( "A" ) ) {
5643                 return false;
5644             }
5645             if ( !it.next().getName().equals( "B" ) ) {
5646                 return false;
5647             }
5648             if ( !it.next().getName().equals( "C" ) ) {
5649                 return false;
5650             }
5651             if ( !it.next().getName().equals( "D" ) ) {
5652                 return false;
5653             }
5654             if ( it.hasNext() ) {
5655                 return false;
5656             }
5657             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",
5658                                                  new NHXParser() )[ 0 ];
5659             PhylogenyNodeIterator it2;
5660             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5661                 it2.next();
5662             }
5663             for( it2.reset(); it2.hasNext(); ) {
5664                 it2.next();
5665             }
5666             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5667             if ( !it3.next().getName().equals( "r" ) ) {
5668                 return false;
5669             }
5670             if ( !it3.next().getName().equals( "abc" ) ) {
5671                 return false;
5672             }
5673             if ( !it3.next().getName().equals( "defg" ) ) {
5674                 return false;
5675             }
5676             if ( !it3.next().getName().equals( "A" ) ) {
5677                 return false;
5678             }
5679             if ( !it3.next().getName().equals( "B" ) ) {
5680                 return false;
5681             }
5682             if ( !it3.next().getName().equals( "C" ) ) {
5683                 return false;
5684             }
5685             if ( !it3.next().getName().equals( "D" ) ) {
5686                 return false;
5687             }
5688             if ( !it3.next().getName().equals( "E" ) ) {
5689                 return false;
5690             }
5691             if ( !it3.next().getName().equals( "F" ) ) {
5692                 return false;
5693             }
5694             if ( !it3.next().getName().equals( "G" ) ) {
5695                 return false;
5696             }
5697             if ( !it3.next().getName().equals( "1" ) ) {
5698                 return false;
5699             }
5700             if ( !it3.next().getName().equals( "2" ) ) {
5701                 return false;
5702             }
5703             if ( !it3.next().getName().equals( "3" ) ) {
5704                 return false;
5705             }
5706             if ( !it3.next().getName().equals( "4" ) ) {
5707                 return false;
5708             }
5709             if ( !it3.next().getName().equals( "5" ) ) {
5710                 return false;
5711             }
5712             if ( !it3.next().getName().equals( "6" ) ) {
5713                 return false;
5714             }
5715             if ( !it3.next().getName().equals( "f1" ) ) {
5716                 return false;
5717             }
5718             if ( !it3.next().getName().equals( "f2" ) ) {
5719                 return false;
5720             }
5721             if ( !it3.next().getName().equals( "f3" ) ) {
5722                 return false;
5723             }
5724             if ( !it3.next().getName().equals( "a" ) ) {
5725                 return false;
5726             }
5727             if ( !it3.next().getName().equals( "b" ) ) {
5728                 return false;
5729             }
5730             if ( !it3.next().getName().equals( "f21" ) ) {
5731                 return false;
5732             }
5733             if ( !it3.next().getName().equals( "X" ) ) {
5734                 return false;
5735             }
5736             if ( !it3.next().getName().equals( "Y" ) ) {
5737                 return false;
5738             }
5739             if ( !it3.next().getName().equals( "Z" ) ) {
5740                 return false;
5741             }
5742             if ( it3.hasNext() ) {
5743                 return false;
5744             }
5745             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5746             PhylogenyNodeIterator it4;
5747             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5748                 it4.next();
5749             }
5750             for( it4.reset(); it4.hasNext(); ) {
5751                 it4.next();
5752             }
5753             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5754             if ( !it5.next().getName().equals( "r" ) ) {
5755                 return false;
5756             }
5757             if ( !it5.next().getName().equals( "A" ) ) {
5758                 return false;
5759             }
5760             if ( !it5.next().getName().equals( "B" ) ) {
5761                 return false;
5762             }
5763             if ( !it5.next().getName().equals( "C" ) ) {
5764                 return false;
5765             }
5766             if ( !it5.next().getName().equals( "D" ) ) {
5767                 return false;
5768             }
5769             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5770             PhylogenyNodeIterator it6;
5771             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5772                 it6.next();
5773             }
5774             for( it6.reset(); it6.hasNext(); ) {
5775                 it6.next();
5776             }
5777             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5778             if ( !it7.next().getName().equals( "A" ) ) {
5779                 return false;
5780             }
5781             if ( it.hasNext() ) {
5782                 return false;
5783             }
5784         }
5785         catch ( final Exception e ) {
5786             e.printStackTrace( System.out );
5787             return false;
5788         }
5789         return true;
5790     }
5791
5792     private static boolean testMafft( final String path ) {
5793         try {
5794             final List<String> opts = new ArrayList<String>();
5795             opts.add( "--maxiterate" );
5796             opts.add( "1000" );
5797             opts.add( "--localpair" );
5798             opts.add( "--quiet" );
5799             Msa msa = null;
5800             final MsaInferrer mafft = Mafft.createInstance( path );
5801             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5802             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5803                 return false;
5804             }
5805             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5806                 return false;
5807             }
5808         }
5809         catch ( final Exception e ) {
5810             e.printStackTrace( System.out );
5811             return false;
5812         }
5813         return true;
5814     }
5815
5816     private static boolean testMidpointrooting() {
5817         try {
5818             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5819             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5820             PhylogenyMethods.midpointRoot( t0 );
5821             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5822                 return false;
5823             }
5824             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5825                 return false;
5826             }
5827             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5828                            1 ) ) {
5829                 return false;
5830             }
5831             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",
5832                                                  new NHXParser() )[ 0 ];
5833             if ( !t1.isRooted() ) {
5834                 return false;
5835             }
5836             PhylogenyMethods.midpointRoot( t1 );
5837             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5838                 return false;
5839             }
5840             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5841                 return false;
5842             }
5843             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5844                 return false;
5845             }
5846             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5847                 return false;
5848             }
5849             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5850                 return false;
5851             }
5852             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5853                 return false;
5854             }
5855             t1.reRoot( t1.getNode( "A" ) );
5856             PhylogenyMethods.midpointRoot( t1 );
5857             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5858                 return false;
5859             }
5860             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5861                 return false;
5862             }
5863             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5864                 return false;
5865             }
5866             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5867                 return false;
5868             }
5869             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5870                 System.exit( -1 );
5871                 return false;
5872             }
5873             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5874                 return false;
5875             }
5876         }
5877         catch ( final Exception e ) {
5878             e.printStackTrace( System.out );
5879             return false;
5880         }
5881         return true;
5882     }
5883
5884     private static boolean testMsaQualityMethod() {
5885         try {
5886             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
5887             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
5888             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
5889             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
5890             final List<Sequence> l = new ArrayList<Sequence>();
5891             l.add( s0 );
5892             l.add( s1 );
5893             l.add( s2 );
5894             l.add( s3 );
5895             final Msa msa = BasicMsa.createInstance( l );
5896             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
5897                 return false;
5898             }
5899             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
5900                 return false;
5901             }
5902             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
5903                 return false;
5904             }
5905             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
5906                 return false;
5907             }
5908             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
5909                 return false;
5910             }
5911             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
5912                 return false;
5913             }
5914             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
5915                 return false;
5916             }
5917         }
5918         catch ( final Exception e ) {
5919             e.printStackTrace( System.out );
5920             return false;
5921         }
5922         return true;
5923     }
5924
5925     private static boolean testNextNodeWithCollapsing() {
5926         try {
5927             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5928             PhylogenyNode n;
5929             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
5930             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5931             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
5932             t0.getNode( "cd" ).setCollapse( true );
5933             t0.getNode( "cde" ).setCollapse( true );
5934             n = t0.getFirstExternalNode();
5935             while ( n != null ) {
5936                 ext.add( n );
5937                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5938             }
5939             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5940                 return false;
5941             }
5942             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5943                 return false;
5944             }
5945             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
5946                 return false;
5947             }
5948             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
5949                 return false;
5950             }
5951             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
5952                 return false;
5953             }
5954             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
5955                 return false;
5956             }
5957             ext.clear();
5958             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5959             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
5960             t1.getNode( "ab" ).setCollapse( true );
5961             t1.getNode( "cd" ).setCollapse( true );
5962             t1.getNode( "cde" ).setCollapse( true );
5963             n = t1.getNode( "ab" );
5964             ext = new ArrayList<PhylogenyNode>();
5965             while ( n != null ) {
5966                 ext.add( n );
5967                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5968             }
5969             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5970                 return false;
5971             }
5972             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5973                 return false;
5974             }
5975             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5976                 return false;
5977             }
5978             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
5979                 return false;
5980             }
5981             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
5982                 return false;
5983             }
5984             //
5985             //
5986             ext.clear();
5987             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5988             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
5989             t2.getNode( "ab" ).setCollapse( true );
5990             t2.getNode( "cd" ).setCollapse( true );
5991             t2.getNode( "cde" ).setCollapse( true );
5992             t2.getNode( "c" ).setCollapse( true );
5993             t2.getNode( "d" ).setCollapse( true );
5994             t2.getNode( "e" ).setCollapse( true );
5995             t2.getNode( "gh" ).setCollapse( true );
5996             n = t2.getNode( "ab" );
5997             ext = new ArrayList<PhylogenyNode>();
5998             while ( n != null ) {
5999                 ext.add( n );
6000                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6001             }
6002             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6003                 return false;
6004             }
6005             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6006                 return false;
6007             }
6008             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6009                 return false;
6010             }
6011             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6012                 return false;
6013             }
6014             //
6015             //
6016             ext.clear();
6017             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6018             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6019             t3.getNode( "ab" ).setCollapse( true );
6020             t3.getNode( "cd" ).setCollapse( true );
6021             t3.getNode( "cde" ).setCollapse( true );
6022             t3.getNode( "c" ).setCollapse( true );
6023             t3.getNode( "d" ).setCollapse( true );
6024             t3.getNode( "e" ).setCollapse( true );
6025             t3.getNode( "gh" ).setCollapse( true );
6026             t3.getNode( "fgh" ).setCollapse( true );
6027             n = t3.getNode( "ab" );
6028             ext = new ArrayList<PhylogenyNode>();
6029             while ( n != null ) {
6030                 ext.add( n );
6031                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6032             }
6033             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6034                 return false;
6035             }
6036             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6037                 return false;
6038             }
6039             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6040                 return false;
6041             }
6042             //
6043             //
6044             ext.clear();
6045             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6046             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6047             t4.getNode( "ab" ).setCollapse( true );
6048             t4.getNode( "cd" ).setCollapse( true );
6049             t4.getNode( "cde" ).setCollapse( true );
6050             t4.getNode( "c" ).setCollapse( true );
6051             t4.getNode( "d" ).setCollapse( true );
6052             t4.getNode( "e" ).setCollapse( true );
6053             t4.getNode( "gh" ).setCollapse( true );
6054             t4.getNode( "fgh" ).setCollapse( true );
6055             t4.getNode( "abcdefgh" ).setCollapse( true );
6056             n = t4.getNode( "abcdefgh" );
6057             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6058                 return false;
6059             }
6060             //
6061             //
6062             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6063             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6064             ext.clear();
6065             n = t5.getFirstExternalNode();
6066             while ( n != null ) {
6067                 ext.add( n );
6068                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6069             }
6070             if ( ext.size() != 8 ) {
6071                 return false;
6072             }
6073             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6074                 return false;
6075             }
6076             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6077                 return false;
6078             }
6079             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6080                 return false;
6081             }
6082             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6083                 return false;
6084             }
6085             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6086                 return false;
6087             }
6088             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6089                 return false;
6090             }
6091             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6092                 return false;
6093             }
6094             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6095                 return false;
6096             }
6097             //
6098             //
6099             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6100             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6101             ext.clear();
6102             t6.getNode( "ab" ).setCollapse( true );
6103             n = t6.getNode( "ab" );
6104             while ( n != null ) {
6105                 ext.add( n );
6106                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6107             }
6108             if ( ext.size() != 7 ) {
6109                 return false;
6110             }
6111             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6112                 return false;
6113             }
6114             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6115                 return false;
6116             }
6117             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6118                 return false;
6119             }
6120             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6121                 return false;
6122             }
6123             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6124                 return false;
6125             }
6126             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6127                 return false;
6128             }
6129             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6130                 return false;
6131             }
6132             //
6133             //
6134             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6135             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6136             ext.clear();
6137             t7.getNode( "cd" ).setCollapse( true );
6138             n = t7.getNode( "a" );
6139             while ( n != null ) {
6140                 ext.add( n );
6141                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6142             }
6143             if ( ext.size() != 7 ) {
6144                 return false;
6145             }
6146             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6147                 return false;
6148             }
6149             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6150                 return false;
6151             }
6152             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6153                 return false;
6154             }
6155             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6156                 return false;
6157             }
6158             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6159                 return false;
6160             }
6161             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6162                 return false;
6163             }
6164             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6165                 return false;
6166             }
6167             //
6168             //
6169             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6170             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6171             ext.clear();
6172             t8.getNode( "cd" ).setCollapse( true );
6173             t8.getNode( "c" ).setCollapse( true );
6174             t8.getNode( "d" ).setCollapse( true );
6175             n = t8.getNode( "a" );
6176             while ( n != null ) {
6177                 ext.add( n );
6178                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6179             }
6180             if ( ext.size() != 7 ) {
6181                 return false;
6182             }
6183             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6184                 return false;
6185             }
6186             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6187                 return false;
6188             }
6189             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6190                 System.out.println( "2 fail" );
6191                 return false;
6192             }
6193             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6194                 return false;
6195             }
6196             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6197                 return false;
6198             }
6199             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6200                 return false;
6201             }
6202             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6203                 return false;
6204             }
6205             //
6206             //
6207             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6208             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6209             ext.clear();
6210             t9.getNode( "gh" ).setCollapse( true );
6211             n = t9.getNode( "a" );
6212             while ( n != null ) {
6213                 ext.add( n );
6214                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6215             }
6216             if ( ext.size() != 7 ) {
6217                 return false;
6218             }
6219             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6220                 return false;
6221             }
6222             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6223                 return false;
6224             }
6225             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6226                 return false;
6227             }
6228             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6229                 return false;
6230             }
6231             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6232                 return false;
6233             }
6234             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6235                 return false;
6236             }
6237             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6238                 return false;
6239             }
6240             //
6241             //
6242             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6243             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6244             ext.clear();
6245             t10.getNode( "gh" ).setCollapse( true );
6246             t10.getNode( "g" ).setCollapse( true );
6247             t10.getNode( "h" ).setCollapse( true );
6248             n = t10.getNode( "a" );
6249             while ( n != null ) {
6250                 ext.add( n );
6251                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6252             }
6253             if ( ext.size() != 7 ) {
6254                 return false;
6255             }
6256             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6257                 return false;
6258             }
6259             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6260                 return false;
6261             }
6262             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6263                 return false;
6264             }
6265             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6266                 return false;
6267             }
6268             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6269                 return false;
6270             }
6271             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6272                 return false;
6273             }
6274             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6275                 return false;
6276             }
6277             //
6278             //
6279             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6280             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6281             ext.clear();
6282             t11.getNode( "gh" ).setCollapse( true );
6283             t11.getNode( "fgh" ).setCollapse( true );
6284             n = t11.getNode( "a" );
6285             while ( n != null ) {
6286                 ext.add( n );
6287                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6288             }
6289             if ( ext.size() != 6 ) {
6290                 return false;
6291             }
6292             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6293                 return false;
6294             }
6295             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6296                 return false;
6297             }
6298             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6299                 return false;
6300             }
6301             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6302                 return false;
6303             }
6304             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6305                 return false;
6306             }
6307             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6308                 return false;
6309             }
6310             //
6311             //
6312             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6313             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6314             ext.clear();
6315             t12.getNode( "gh" ).setCollapse( true );
6316             t12.getNode( "fgh" ).setCollapse( true );
6317             t12.getNode( "g" ).setCollapse( true );
6318             t12.getNode( "h" ).setCollapse( true );
6319             t12.getNode( "f" ).setCollapse( true );
6320             n = t12.getNode( "a" );
6321             while ( n != null ) {
6322                 ext.add( n );
6323                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6324             }
6325             if ( ext.size() != 6 ) {
6326                 return false;
6327             }
6328             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6329                 return false;
6330             }
6331             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6332                 return false;
6333             }
6334             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6335                 return false;
6336             }
6337             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6338                 return false;
6339             }
6340             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6341                 return false;
6342             }
6343             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6344                 return false;
6345             }
6346             //
6347             //
6348             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6349             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6350             ext.clear();
6351             t13.getNode( "ab" ).setCollapse( true );
6352             t13.getNode( "b" ).setCollapse( true );
6353             t13.getNode( "fgh" ).setCollapse( true );
6354             t13.getNode( "gh" ).setCollapse( true );
6355             n = t13.getNode( "ab" );
6356             while ( n != null ) {
6357                 ext.add( n );
6358                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6359             }
6360             if ( ext.size() != 5 ) {
6361                 return false;
6362             }
6363             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6364                 return false;
6365             }
6366             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6367                 return false;
6368             }
6369             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6370                 return false;
6371             }
6372             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6373                 return false;
6374             }
6375             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6376                 return false;
6377             }
6378             //
6379             //
6380             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6381             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6382             ext.clear();
6383             t14.getNode( "ab" ).setCollapse( true );
6384             t14.getNode( "a" ).setCollapse( true );
6385             t14.getNode( "fgh" ).setCollapse( true );
6386             t14.getNode( "gh" ).setCollapse( true );
6387             n = t14.getNode( "ab" );
6388             while ( n != null ) {
6389                 ext.add( n );
6390                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6391             }
6392             if ( ext.size() != 5 ) {
6393                 return false;
6394             }
6395             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6396                 return false;
6397             }
6398             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6399                 return false;
6400             }
6401             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6402                 return false;
6403             }
6404             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6405                 return false;
6406             }
6407             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6408                 return false;
6409             }
6410             //
6411             //
6412             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" );
6413             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6414             ext.clear();
6415             t15.getNode( "ab" ).setCollapse( true );
6416             t15.getNode( "a" ).setCollapse( true );
6417             t15.getNode( "fgh" ).setCollapse( true );
6418             t15.getNode( "gh" ).setCollapse( true );
6419             n = t15.getNode( "ab" );
6420             while ( n != null ) {
6421                 ext.add( n );
6422                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6423             }
6424             if ( ext.size() != 6 ) {
6425                 return false;
6426             }
6427             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6428                 return false;
6429             }
6430             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6431                 return false;
6432             }
6433             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6434                 return false;
6435             }
6436             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6437                 return false;
6438             }
6439             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6440                 return false;
6441             }
6442             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6443                 return false;
6444             }
6445             //
6446             //
6447             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" );
6448             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6449             ext.clear();
6450             t16.getNode( "ab" ).setCollapse( true );
6451             t16.getNode( "a" ).setCollapse( true );
6452             t16.getNode( "fgh" ).setCollapse( true );
6453             t16.getNode( "gh" ).setCollapse( true );
6454             t16.getNode( "cd" ).setCollapse( true );
6455             t16.getNode( "cde" ).setCollapse( true );
6456             t16.getNode( "d" ).setCollapse( true );
6457             t16.getNode( "x" ).setCollapse( true );
6458             n = t16.getNode( "ab" );
6459             while ( n != null ) {
6460                 ext.add( n );
6461                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6462             }
6463             if ( ext.size() != 4 ) {
6464                 return false;
6465             }
6466             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6467                 return false;
6468             }
6469             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6470                 return false;
6471             }
6472             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6473                 return false;
6474             }
6475             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6476                 return false;
6477             }
6478         }
6479         catch ( final Exception e ) {
6480             e.printStackTrace( System.out );
6481             return false;
6482         }
6483         return true;
6484     }
6485
6486     private static boolean testNexusCharactersParsing() {
6487         try {
6488             final NexusCharactersParser parser = new NexusCharactersParser();
6489             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6490             parser.parse();
6491             String[] labels = parser.getCharStateLabels();
6492             if ( labels.length != 7 ) {
6493                 return false;
6494             }
6495             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6496                 return false;
6497             }
6498             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6499                 return false;
6500             }
6501             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6502                 return false;
6503             }
6504             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6505                 return false;
6506             }
6507             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6508                 return false;
6509             }
6510             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6511                 return false;
6512             }
6513             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6514                 return false;
6515             }
6516             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6517             parser.parse();
6518             labels = parser.getCharStateLabels();
6519             if ( labels.length != 7 ) {
6520                 return false;
6521             }
6522             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6523                 return false;
6524             }
6525             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6526                 return false;
6527             }
6528             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6529                 return false;
6530             }
6531             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6532                 return false;
6533             }
6534             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6535                 return false;
6536             }
6537             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6538                 return false;
6539             }
6540             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6541                 return false;
6542             }
6543         }
6544         catch ( final Exception e ) {
6545             e.printStackTrace( System.out );
6546             return false;
6547         }
6548         return true;
6549     }
6550
6551     private static boolean testNexusMatrixParsing() {
6552         try {
6553             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
6554             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
6555             parser.parse();
6556             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
6557             if ( m.getNumberOfCharacters() != 9 ) {
6558                 return false;
6559             }
6560             if ( m.getNumberOfIdentifiers() != 5 ) {
6561                 return false;
6562             }
6563             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
6564                 return false;
6565             }
6566             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
6567                 return false;
6568             }
6569             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
6570                 return false;
6571             }
6572             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
6573                 return false;
6574             }
6575             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
6576                 return false;
6577             }
6578             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6579                 return false;
6580             }
6581             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
6582                 return false;
6583             }
6584             //            if ( labels.length != 7 ) {
6585             //                return false;
6586             //            }
6587             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6588             //                return false;
6589             //            }
6590             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6591             //                return false;
6592             //            }
6593             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6594             //                return false;
6595             //            }
6596             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6597             //                return false;
6598             //            }
6599             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6600             //                return false;
6601             //            }
6602             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6603             //                return false;
6604             //            }
6605             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6606             //                return false;
6607             //            }
6608             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6609             //            parser.parse();
6610             //            labels = parser.getCharStateLabels();
6611             //            if ( labels.length != 7 ) {
6612             //                return false;
6613             //            }
6614             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6615             //                return false;
6616             //            }
6617             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6618             //                return false;
6619             //            }
6620             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6621             //                return false;
6622             //            }
6623             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6624             //                return false;
6625             //            }
6626             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6627             //                return false;
6628             //            }
6629             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6630             //                return false;
6631             //            }
6632             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6633             //                return false;
6634             //            }
6635         }
6636         catch ( final Exception e ) {
6637             e.printStackTrace( System.out );
6638             return false;
6639         }
6640         return true;
6641     }
6642
6643     private static boolean testNexusTreeParsing() {
6644         try {
6645             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6646             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6647             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
6648             if ( phylogenies.length != 1 ) {
6649                 return false;
6650             }
6651             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
6652                 return false;
6653             }
6654             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6655                 return false;
6656             }
6657             phylogenies = null;
6658             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
6659             if ( phylogenies.length != 1 ) {
6660                 return false;
6661             }
6662             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6663                 return false;
6664             }
6665             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
6666                 return false;
6667             }
6668             phylogenies = null;
6669             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
6670             if ( phylogenies.length != 1 ) {
6671                 return false;
6672             }
6673             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6674                 return false;
6675             }
6676             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6677                 return false;
6678             }
6679             if ( phylogenies[ 0 ].isRooted() ) {
6680                 return false;
6681             }
6682             phylogenies = null;
6683             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
6684             if ( phylogenies.length != 18 ) {
6685                 return false;
6686             }
6687             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6688                 return false;
6689             }
6690             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
6691                 return false;
6692             }
6693             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
6694                 return false;
6695             }
6696             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
6697                 return false;
6698             }
6699             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6700                 return false;
6701             }
6702             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
6703                 return false;
6704             }
6705             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
6706                 return false;
6707             }
6708             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
6709                 return false;
6710             }
6711             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
6712                 return false;
6713             }
6714             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
6715                 return false;
6716             }
6717             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
6718                 return false;
6719             }
6720             if ( phylogenies[ 8 ].isRooted() ) {
6721                 return false;
6722             }
6723             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
6724                 return false;
6725             }
6726             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
6727                 return false;
6728             }
6729             if ( !phylogenies[ 9 ].isRooted() ) {
6730                 return false;
6731             }
6732             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
6733                 return false;
6734             }
6735             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
6736                 return false;
6737             }
6738             if ( !phylogenies[ 10 ].isRooted() ) {
6739                 return false;
6740             }
6741             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
6742                 return false;
6743             }
6744             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
6745                 return false;
6746             }
6747             if ( phylogenies[ 11 ].isRooted() ) {
6748                 return false;
6749             }
6750             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
6751                 return false;
6752             }
6753             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
6754                 return false;
6755             }
6756             if ( !phylogenies[ 12 ].isRooted() ) {
6757                 return false;
6758             }
6759             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
6760                 return false;
6761             }
6762             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
6763                 return false;
6764             }
6765             if ( !phylogenies[ 13 ].isRooted() ) {
6766                 return false;
6767             }
6768             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
6769                 return false;
6770             }
6771             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
6772                 return false;
6773             }
6774             if ( !phylogenies[ 14 ].isRooted() ) {
6775                 return false;
6776             }
6777             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
6778                 return false;
6779             }
6780             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
6781                 return false;
6782             }
6783             if ( phylogenies[ 15 ].isRooted() ) {
6784                 return false;
6785             }
6786             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
6787                 return false;
6788             }
6789             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
6790                 return false;
6791             }
6792             if ( !phylogenies[ 16 ].isRooted() ) {
6793                 return false;
6794             }
6795             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
6796                 return false;
6797             }
6798             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
6799                 return false;
6800             }
6801             if ( phylogenies[ 17 ].isRooted() ) {
6802                 return false;
6803             }
6804             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
6805                 return false;
6806             }
6807             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
6808             phylogenies = null;
6809             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
6810             if ( phylogenies.length != 9 ) {
6811                 return false;
6812             }
6813             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
6814                     .getDistanceToParent() ) ) {
6815                 return false;
6816             }
6817             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
6818                     .getDistanceToParent() ) ) {
6819                 return false;
6820             }
6821             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
6822                 return false;
6823             }
6824             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
6825                 return false;
6826             }
6827             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
6828                 return false;
6829             }
6830             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
6831                 return false;
6832             }
6833             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
6834                 return false;
6835             }
6836         }
6837         catch ( final Exception e ) {
6838             e.printStackTrace( System.out );
6839             return false;
6840         }
6841         return true;
6842     }
6843
6844     private static boolean testNexusTreeParsingIterating() {
6845         try {
6846             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
6847             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
6848             if ( !p.hasNext() ) {
6849                 return false;
6850             }
6851             Phylogeny phy = p.next();
6852             if ( phy == null ) {
6853                 return false;
6854             }
6855             if ( phy.getNumberOfExternalNodes() != 25 ) {
6856                 return false;
6857             }
6858             if ( !phy.getName().equals( "" ) ) {
6859                 return false;
6860             }
6861             if ( p.hasNext() ) {
6862                 return false;
6863             }
6864             phy = p.next();
6865             if ( phy != null ) {
6866                 return false;
6867             }
6868             //
6869             p.reset();
6870             if ( !p.hasNext() ) {
6871                 return false;
6872             }
6873             phy = p.next();
6874             if ( phy == null ) {
6875                 return false;
6876             }
6877             if ( phy.getNumberOfExternalNodes() != 25 ) {
6878                 return false;
6879             }
6880             if ( !phy.getName().equals( "" ) ) {
6881                 return false;
6882             }
6883             if ( p.hasNext() ) {
6884                 return false;
6885             }
6886             phy = p.next();
6887             if ( phy != null ) {
6888                 return false;
6889             }
6890             ////
6891             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
6892             if ( !p.hasNext() ) {
6893                 return false;
6894             }
6895             phy = p.next();
6896             if ( phy == null ) {
6897                 return false;
6898             }
6899             if ( phy.getNumberOfExternalNodes() != 10 ) {
6900                 return false;
6901             }
6902             if ( !phy.getName().equals( "name" ) ) {
6903                 return false;
6904             }
6905             if ( p.hasNext() ) {
6906                 return false;
6907             }
6908             phy = p.next();
6909             if ( phy != null ) {
6910                 return false;
6911             }
6912             //
6913             p.reset();
6914             if ( !p.hasNext() ) {
6915                 return false;
6916             }
6917             phy = p.next();
6918             if ( phy == null ) {
6919                 return false;
6920             }
6921             if ( phy.getNumberOfExternalNodes() != 10 ) {
6922                 return false;
6923             }
6924             if ( !phy.getName().equals( "name" ) ) {
6925                 return false;
6926             }
6927             if ( p.hasNext() ) {
6928                 return false;
6929             }
6930             phy = p.next();
6931             if ( phy != null ) {
6932                 return false;
6933             }
6934             //
6935             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
6936             if ( !p.hasNext() ) {
6937                 return false;
6938             }
6939             phy = p.next();
6940             if ( phy == null ) {
6941                 return false;
6942             }
6943             if ( phy.getNumberOfExternalNodes() != 3 ) {
6944                 return false;
6945             }
6946             if ( !phy.getName().equals( "" ) ) {
6947                 return false;
6948             }
6949             if ( phy.isRooted() ) {
6950                 return false;
6951             }
6952             if ( p.hasNext() ) {
6953                 return false;
6954             }
6955             phy = p.next();
6956             if ( phy != null ) {
6957                 return false;
6958             }
6959             //
6960             p.reset();
6961             if ( !p.hasNext() ) {
6962                 return false;
6963             }
6964             phy = p.next();
6965             if ( phy == null ) {
6966                 return false;
6967             }
6968             if ( phy.getNumberOfExternalNodes() != 3 ) {
6969                 return false;
6970             }
6971             if ( !phy.getName().equals( "" ) ) {
6972                 return false;
6973             }
6974             if ( p.hasNext() ) {
6975                 return false;
6976             }
6977             phy = p.next();
6978             if ( phy != null ) {
6979                 return false;
6980             }
6981             //
6982             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
6983             if ( !p.hasNext() ) {
6984                 return false;
6985             }
6986             //0
6987             phy = p.next();
6988             if ( phy == null ) {
6989                 return false;
6990             }
6991             if ( phy.getNumberOfExternalNodes() != 10 ) {
6992                 return false;
6993             }
6994             if ( !phy.getName().equals( "tree 0" ) ) {
6995                 return false;
6996             }
6997             //1
6998             if ( !p.hasNext() ) {
6999                 return false;
7000             }
7001             phy = p.next();
7002             if ( phy == null ) {
7003                 return false;
7004             }
7005             if ( phy.getNumberOfExternalNodes() != 10 ) {
7006                 return false;
7007             }
7008             if ( !phy.getName().equals( "tree 1" ) ) {
7009                 return false;
7010             }
7011             //2
7012             if ( !p.hasNext() ) {
7013                 return false;
7014             }
7015             phy = p.next();
7016             if ( phy == null ) {
7017                 return false;
7018             }
7019             if ( phy.getNumberOfExternalNodes() != 3 ) {
7020                 System.out.println( phy.toString() );
7021                 return false;
7022             }
7023             if ( !phy.getName().equals( "" ) ) {
7024                 return false;
7025             }
7026             if ( phy.isRooted() ) {
7027                 return false;
7028             }
7029             //3
7030             if ( !p.hasNext() ) {
7031                 return false;
7032             }
7033             phy = p.next();
7034             if ( phy == null ) {
7035                 return false;
7036             }
7037             if ( phy.getNumberOfExternalNodes() != 4 ) {
7038                 return false;
7039             }
7040             if ( !phy.getName().equals( "" ) ) {
7041                 return false;
7042             }
7043             if ( !phy.isRooted() ) {
7044                 return false;
7045             }
7046             //4
7047             if ( !p.hasNext() ) {
7048                 return false;
7049             }
7050             phy = p.next();
7051             if ( phy == null ) {
7052                 return false;
7053             }
7054             if ( phy.getNumberOfExternalNodes() != 5 ) {
7055                 System.out.println( phy.getNumberOfExternalNodes() );
7056                 return false;
7057             }
7058             if ( !phy.getName().equals( "" ) ) {
7059                 return false;
7060             }
7061             if ( !phy.isRooted() ) {
7062                 return false;
7063             }
7064             //5
7065             if ( !p.hasNext() ) {
7066                 return false;
7067             }
7068             phy = p.next();
7069             if ( phy == null ) {
7070                 return false;
7071             }
7072             if ( phy.getNumberOfExternalNodes() != 3 ) {
7073                 return false;
7074             }
7075             if ( !phy.getName().equals( "" ) ) {
7076                 return false;
7077             }
7078             if ( phy.isRooted() ) {
7079                 return false;
7080             }
7081             //6
7082             if ( !p.hasNext() ) {
7083                 return false;
7084             }
7085             phy = p.next();
7086             if ( phy == null ) {
7087                 return false;
7088             }
7089             if ( phy.getNumberOfExternalNodes() != 2 ) {
7090                 return false;
7091             }
7092             if ( !phy.getName().equals( "" ) ) {
7093                 return false;
7094             }
7095             if ( !phy.isRooted() ) {
7096                 return false;
7097             }
7098             //7
7099             if ( !p.hasNext() ) {
7100                 return false;
7101             }
7102             phy = p.next();
7103             if ( phy.getNumberOfExternalNodes() != 3 ) {
7104                 return false;
7105             }
7106             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7107                 return false;
7108             }
7109             if ( !phy.isRooted() ) {
7110                 return false;
7111             }
7112             //8
7113             if ( !p.hasNext() ) {
7114                 return false;
7115             }
7116             phy = p.next();
7117             if ( phy.getNumberOfExternalNodes() != 3 ) {
7118                 return false;
7119             }
7120             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7121                 return false;
7122             }
7123             if ( !phy.getName().equals( "tree 8" ) ) {
7124                 return false;
7125             }
7126             //9
7127             if ( !p.hasNext() ) {
7128                 return false;
7129             }
7130             phy = p.next();
7131             if ( phy.getNumberOfExternalNodes() != 3 ) {
7132                 return false;
7133             }
7134             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7135                 return false;
7136             }
7137             if ( !phy.getName().equals( "tree 9" ) ) {
7138                 return false;
7139             }
7140             //10
7141             if ( !p.hasNext() ) {
7142                 return false;
7143             }
7144             phy = p.next();
7145             if ( phy.getNumberOfExternalNodes() != 3 ) {
7146                 return false;
7147             }
7148             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7149                 return false;
7150             }
7151             if ( !phy.getName().equals( "tree 10" ) ) {
7152                 return false;
7153             }
7154             if ( !phy.isRooted() ) {
7155                 return false;
7156             }
7157             //11
7158             if ( !p.hasNext() ) {
7159                 return false;
7160             }
7161             phy = p.next();
7162             if ( phy.getNumberOfExternalNodes() != 3 ) {
7163                 return false;
7164             }
7165             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7166                 return false;
7167             }
7168             if ( !phy.getName().equals( "tree 11" ) ) {
7169                 return false;
7170             }
7171             if ( phy.isRooted() ) {
7172                 return false;
7173             }
7174             //12
7175             if ( !p.hasNext() ) {
7176                 return false;
7177             }
7178             phy = p.next();
7179             if ( phy.getNumberOfExternalNodes() != 3 ) {
7180                 return false;
7181             }
7182             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7183                 return false;
7184             }
7185             if ( !phy.getName().equals( "tree 12" ) ) {
7186                 return false;
7187             }
7188             if ( !phy.isRooted() ) {
7189                 return false;
7190             }
7191             //13
7192             if ( !p.hasNext() ) {
7193                 return false;
7194             }
7195             phy = p.next();
7196             if ( phy.getNumberOfExternalNodes() != 3 ) {
7197                 return false;
7198             }
7199             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7200                 return false;
7201             }
7202             if ( !phy.getName().equals( "tree 13" ) ) {
7203                 return false;
7204             }
7205             if ( !phy.isRooted() ) {
7206                 return false;
7207             }
7208             //14
7209             if ( !p.hasNext() ) {
7210                 return false;
7211             }
7212             phy = p.next();
7213             if ( phy.getNumberOfExternalNodes() != 10 ) {
7214                 System.out.println( phy.getNumberOfExternalNodes() );
7215                 return false;
7216             }
7217             if ( !phy
7218                     .toNewHampshire()
7219                     .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;" ) ) {
7220                 System.out.println( phy.toNewHampshire() );
7221                 return false;
7222             }
7223             if ( !phy.getName().equals( "tree 14" ) ) {
7224                 return false;
7225             }
7226             if ( !phy.isRooted() ) {
7227                 return false;
7228             }
7229             //15
7230             if ( !p.hasNext() ) {
7231                 return false;
7232             }
7233             phy = p.next();
7234             if ( phy.getNumberOfExternalNodes() != 10 ) {
7235                 System.out.println( phy.getNumberOfExternalNodes() );
7236                 return false;
7237             }
7238             if ( !phy
7239                     .toNewHampshire()
7240                     .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;" ) ) {
7241                 System.out.println( phy.toNewHampshire() );
7242                 return false;
7243             }
7244             if ( !phy.getName().equals( "tree 15" ) ) {
7245                 return false;
7246             }
7247             if ( phy.isRooted() ) {
7248                 return false;
7249             }
7250             //16
7251             if ( !p.hasNext() ) {
7252                 return false;
7253             }
7254             phy = p.next();
7255             if ( phy.getNumberOfExternalNodes() != 10 ) {
7256                 System.out.println( phy.getNumberOfExternalNodes() );
7257                 return false;
7258             }
7259             if ( !phy
7260                     .toNewHampshire()
7261                     .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;" ) ) {
7262                 System.out.println( phy.toNewHampshire() );
7263                 return false;
7264             }
7265             if ( !phy.getName().equals( "tree 16" ) ) {
7266                 return false;
7267             }
7268             if ( !phy.isRooted() ) {
7269                 return false;
7270             }
7271             //17
7272             if ( !p.hasNext() ) {
7273                 return false;
7274             }
7275             phy = p.next();
7276             if ( phy.getNumberOfExternalNodes() != 10 ) {
7277                 System.out.println( phy.getNumberOfExternalNodes() );
7278                 return false;
7279             }
7280             if ( !phy
7281                     .toNewHampshire()
7282                     .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;" ) ) {
7283                 System.out.println( phy.toNewHampshire() );
7284                 return false;
7285             }
7286             if ( !phy.getName().equals( "tree 17" ) ) {
7287                 return false;
7288             }
7289             if ( phy.isRooted() ) {
7290                 return false;
7291             }
7292             //
7293             if ( p.hasNext() ) {
7294                 return false;
7295             }
7296             phy = p.next();
7297             if ( phy != null ) {
7298                 return false;
7299             }
7300             p.reset();
7301             //0
7302             if ( !p.hasNext() ) {
7303                 return false;
7304             }
7305             phy = p.next();
7306             if ( phy == null ) {
7307                 return false;
7308             }
7309             if ( phy.getNumberOfExternalNodes() != 10 ) {
7310                 return false;
7311             }
7312             if ( !phy.getName().equals( "tree 0" ) ) {
7313                 return false;
7314             }
7315             //1
7316             if ( !p.hasNext() ) {
7317                 return false;
7318             }
7319             phy = p.next();
7320             if ( phy == null ) {
7321                 return false;
7322             }
7323             if ( phy.getNumberOfExternalNodes() != 10 ) {
7324                 return false;
7325             }
7326             if ( !phy.getName().equals( "tree 1" ) ) {
7327                 return false;
7328             }
7329             //2
7330             if ( !p.hasNext() ) {
7331                 return false;
7332             }
7333             phy = p.next();
7334             if ( phy == null ) {
7335                 return false;
7336             }
7337             if ( phy.getNumberOfExternalNodes() != 3 ) {
7338                 return false;
7339             }
7340             if ( !phy.getName().equals( "" ) ) {
7341                 return false;
7342             }
7343             if ( phy.isRooted() ) {
7344                 return false;
7345             }
7346             //3
7347             if ( !p.hasNext() ) {
7348                 return false;
7349             }
7350             phy = p.next();
7351             if ( phy == null ) {
7352                 return false;
7353             }
7354             if ( phy.getNumberOfExternalNodes() != 4 ) {
7355                 return false;
7356             }
7357             if ( !phy.getName().equals( "" ) ) {
7358                 return false;
7359             }
7360             if ( !phy.isRooted() ) {
7361                 return false;
7362             }
7363             //4
7364             if ( !p.hasNext() ) {
7365                 return false;
7366             }
7367             phy = p.next();
7368             if ( phy == null ) {
7369                 return false;
7370             }
7371             if ( phy.getNumberOfExternalNodes() != 5 ) {
7372                 System.out.println( phy.getNumberOfExternalNodes() );
7373                 return false;
7374             }
7375             if ( !phy.getName().equals( "" ) ) {
7376                 return false;
7377             }
7378             if ( !phy.isRooted() ) {
7379                 return false;
7380             }
7381             //5
7382             if ( !p.hasNext() ) {
7383                 return false;
7384             }
7385             phy = p.next();
7386             if ( phy == null ) {
7387                 return false;
7388             }
7389             if ( phy.getNumberOfExternalNodes() != 3 ) {
7390                 return false;
7391             }
7392             if ( !phy.getName().equals( "" ) ) {
7393                 return false;
7394             }
7395             if ( phy.isRooted() ) {
7396                 return false;
7397             }
7398             //
7399             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7400             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7401             // 0
7402             if ( !p2.hasNext() ) {
7403                 return false;
7404             }
7405             phy = p2.next();
7406             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7407                 return false;
7408             }
7409             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7410                 return false;
7411             }
7412             // 1
7413             if ( !p2.hasNext() ) {
7414                 return false;
7415             }
7416             phy = p2.next();
7417             // 2
7418             if ( !p2.hasNext() ) {
7419                 return false;
7420             }
7421             phy = p2.next();
7422             // 3
7423             if ( !p2.hasNext() ) {
7424                 return false;
7425             }
7426             phy = p2.next();
7427             // 4
7428             if ( !p2.hasNext() ) {
7429                 return false;
7430             }
7431             phy = p2.next();
7432             // 5
7433             if ( !p2.hasNext() ) {
7434                 return false;
7435             }
7436             phy = p2.next();
7437             // 6
7438             if ( !p2.hasNext() ) {
7439                 return false;
7440             }
7441             phy = p2.next();
7442             // 7
7443             if ( !p2.hasNext() ) {
7444                 return false;
7445             }
7446             phy = p2.next();
7447             // 8
7448             if ( !p2.hasNext() ) {
7449                 return false;
7450             }
7451             phy = p2.next();
7452             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7453                 return false;
7454             }
7455             if ( p2.hasNext() ) {
7456                 return false;
7457             }
7458             phy = p2.next();
7459             if ( phy != null ) {
7460                 return false;
7461             }
7462             // 0
7463             p2.reset();
7464             if ( !p2.hasNext() ) {
7465                 return false;
7466             }
7467             phy = p2.next();
7468             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7469                 return false;
7470             }
7471             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7472                 return false;
7473             }
7474         }
7475         catch ( final Exception e ) {
7476             e.printStackTrace( System.out );
7477             return false;
7478         }
7479         return true;
7480     }
7481
7482     private static boolean testNexusTreeParsingTranslating() {
7483         try {
7484             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7485             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7486             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7487             if ( phylogenies.length != 1 ) {
7488                 return false;
7489             }
7490             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7491                 return false;
7492             }
7493             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7494                 return false;
7495             }
7496             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7497                 return false;
7498             }
7499             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7500                 return false;
7501             }
7502             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7503                     .equals( "Aranaeus" ) ) {
7504                 return false;
7505             }
7506             phylogenies = null;
7507             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7508             if ( phylogenies.length != 3 ) {
7509                 return false;
7510             }
7511             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7512                 return false;
7513             }
7514             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7515                 return false;
7516             }
7517             if ( phylogenies[ 0 ].isRooted() ) {
7518                 return false;
7519             }
7520             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7521                 return false;
7522             }
7523             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7524                 return false;
7525             }
7526             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7527                     .equals( "Aranaeus" ) ) {
7528                 return false;
7529             }
7530             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7531                 return false;
7532             }
7533             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7534                 return false;
7535             }
7536             if ( phylogenies[ 1 ].isRooted() ) {
7537                 return false;
7538             }
7539             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7540                 return false;
7541             }
7542             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7543                 return false;
7544             }
7545             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7546                     .equals( "Aranaeus" ) ) {
7547                 return false;
7548             }
7549             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7550                 return false;
7551             }
7552             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7553                 return false;
7554             }
7555             if ( !phylogenies[ 2 ].isRooted() ) {
7556                 return false;
7557             }
7558             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7559                 return false;
7560             }
7561             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7562                 return false;
7563             }
7564             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7565                     .equals( "Aranaeus" ) ) {
7566                 return false;
7567             }
7568             phylogenies = null;
7569             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
7570             if ( phylogenies.length != 3 ) {
7571                 return false;
7572             }
7573             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7574                 return false;
7575             }
7576             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7577                 return false;
7578             }
7579             if ( phylogenies[ 0 ].isRooted() ) {
7580                 return false;
7581             }
7582             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7583                 return false;
7584             }
7585             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7586                 return false;
7587             }
7588             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7589                     .equals( "Aranaeus" ) ) {
7590                 return false;
7591             }
7592             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7593                 return false;
7594             }
7595             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7596                 return false;
7597             }
7598             if ( phylogenies[ 1 ].isRooted() ) {
7599                 return false;
7600             }
7601             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7602                 return false;
7603             }
7604             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7605                 return false;
7606             }
7607             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7608                     .equals( "Aranaeus" ) ) {
7609                 return false;
7610             }
7611             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7612                 return false;
7613             }
7614             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7615                 return false;
7616             }
7617             if ( !phylogenies[ 2 ].isRooted() ) {
7618                 return false;
7619             }
7620             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7621                 return false;
7622             }
7623             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7624                 return false;
7625             }
7626             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7627                     .equals( "Aranaeus" ) ) {
7628                 return false;
7629             }
7630             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
7631             if ( phylogenies.length != 3 ) {
7632                 return false;
7633             }
7634             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
7635                            0.00100049 ) ) {
7636                 return false;
7637             }
7638         }
7639         catch ( final Exception e ) {
7640             e.printStackTrace( System.out );
7641             return false;
7642         }
7643         return true;
7644     }
7645
7646     private static boolean testNHParsing() {
7647         try {
7648             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7649             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
7650             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
7651                 return false;
7652             }
7653             final NHXParser nhxp = new NHXParser();
7654             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
7655             nhxp.setReplaceUnderscores( true );
7656             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
7657             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
7658                 return false;
7659             }
7660             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
7661                 return false;
7662             }
7663             final Phylogeny p1b = factory
7664                     .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 ",
7665                              new NHXParser() )[ 0 ];
7666             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
7667                 return false;
7668             }
7669             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
7670                 return false;
7671             }
7672             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
7673             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
7674             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
7675             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
7676             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
7677             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
7678             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
7679             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
7680             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
7681             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
7682             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
7683                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
7684                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
7685                                                     new NHXParser() );
7686             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
7687                 return false;
7688             }
7689             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
7690                 return false;
7691             }
7692             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
7693                 return false;
7694             }
7695             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
7696                 return false;
7697             }
7698             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
7699             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
7700             final String p16_S = "((A,B),C)";
7701             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
7702             if ( p16.length != 1 ) {
7703                 return false;
7704             }
7705             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
7706                 return false;
7707             }
7708             final String p17_S = "(C,(A,B))";
7709             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
7710             if ( p17.length != 1 ) {
7711                 return false;
7712             }
7713             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
7714                 return false;
7715             }
7716             final String p18_S = "((A,B),(C,D))";
7717             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
7718             if ( p18.length != 1 ) {
7719                 return false;
7720             }
7721             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
7722                 return false;
7723             }
7724             final String p19_S = "(((A,B),C),D)";
7725             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
7726             if ( p19.length != 1 ) {
7727                 return false;
7728             }
7729             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
7730                 return false;
7731             }
7732             final String p20_S = "(A,(B,(C,D)))";
7733             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
7734             if ( p20.length != 1 ) {
7735                 return false;
7736             }
7737             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
7738                 return false;
7739             }
7740             final String p21_S = "(A,(B,(C,(D,E))))";
7741             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
7742             if ( p21.length != 1 ) {
7743                 return false;
7744             }
7745             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
7746                 return false;
7747             }
7748             final String p22_S = "((((A,B),C),D),E)";
7749             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
7750             if ( p22.length != 1 ) {
7751                 return false;
7752             }
7753             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
7754                 return false;
7755             }
7756             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7757             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
7758             if ( p23.length != 1 ) {
7759                 System.out.println( "xl=" + p23.length );
7760                 System.exit( -1 );
7761                 return false;
7762             }
7763             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
7764                 return false;
7765             }
7766             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7767             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
7768             if ( p24.length != 1 ) {
7769                 return false;
7770             }
7771             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
7772                 return false;
7773             }
7774             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7775             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7776             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
7777             if ( p241.length != 2 ) {
7778                 return false;
7779             }
7780             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
7781                 return false;
7782             }
7783             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
7784                 return false;
7785             }
7786             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
7787                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
7788                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
7789                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
7790                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
7791                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
7792                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
7793                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
7794             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
7795             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
7796                 return false;
7797             }
7798             final String p26_S = "(A,B)ab";
7799             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
7800             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
7801                 return false;
7802             }
7803             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7804             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
7805             if ( p27s.length != 1 ) {
7806                 System.out.println( "xxl=" + p27s.length );
7807                 System.exit( -1 );
7808                 return false;
7809             }
7810             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7811                 System.out.println( p27s[ 0 ].toNewHampshireX() );
7812                 System.exit( -1 );
7813                 return false;
7814             }
7815             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
7816                                                     new NHXParser() );
7817             if ( p27.length != 1 ) {
7818                 System.out.println( "yl=" + p27.length );
7819                 System.exit( -1 );
7820                 return false;
7821             }
7822             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7823                 System.out.println( p27[ 0 ].toNewHampshireX() );
7824                 System.exit( -1 );
7825                 return false;
7826             }
7827             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7828             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7829             final String p28_S3 = "(A,B)ab";
7830             final String p28_S4 = "((((A,B),C),D),;E;)";
7831             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
7832                                                     new NHXParser() );
7833             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
7834                 return false;
7835             }
7836             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
7837                 return false;
7838             }
7839             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
7840                 return false;
7841             }
7842             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
7843                 return false;
7844             }
7845             if ( p28.length != 4 ) {
7846                 return false;
7847             }
7848             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";
7849             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
7850             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
7851                 return false;
7852             }
7853             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";
7854             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
7855             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
7856                 return false;
7857             }
7858             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
7859             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
7860             if ( ( p32.length != 0 ) ) {
7861                 return false;
7862             }
7863             final String p33_S = "A";
7864             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
7865             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
7866                 return false;
7867             }
7868             final String p34_S = "B;";
7869             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
7870             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
7871                 return false;
7872             }
7873             final String p35_S = "B:0.2";
7874             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
7875             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
7876                 return false;
7877             }
7878             final String p36_S = "(A)";
7879             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
7880             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
7881                 return false;
7882             }
7883             final String p37_S = "((A))";
7884             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
7885             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
7886                 return false;
7887             }
7888             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7889             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
7890             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
7891                 return false;
7892             }
7893             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7894             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
7895             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
7896                 return false;
7897             }
7898             final String p40_S = "(A,B,C)";
7899             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
7900             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
7901                 return false;
7902             }
7903             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
7904             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
7905             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
7906                 return false;
7907             }
7908             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
7909             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
7910             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
7911                 return false;
7912             }
7913             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)";
7914             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
7915             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
7916                 return false;
7917             }
7918             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)))";
7919             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
7920             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
7921                 return false;
7922             }
7923             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
7924             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
7925             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
7926                 return false;
7927             }
7928             final String p46_S = "";
7929             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
7930             if ( p46.length != 0 ) {
7931                 return false;
7932             }
7933             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
7934             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7935                 return false;
7936             }
7937             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7938             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7939                 return false;
7940             }
7941             final Phylogeny p49 = factory
7942                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
7943                              new NHXParser() )[ 0 ];
7944             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7945                 return false;
7946             }
7947             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7948             if ( p50.getNode( "A" ) == null ) {
7949                 return false;
7950             }
7951             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7952                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
7953                 return false;
7954             }
7955             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
7956                 return false;
7957             }
7958             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
7959                     .equals( "((A,B)88:2.0,C);" ) ) {
7960                 return false;
7961             }
7962             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7963             if ( p51.getNode( "A(A" ) == null ) {
7964                 return false;
7965             }
7966             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7967             if ( p52.getNode( "A(A" ) == null ) {
7968                 return false;
7969             }
7970             final Phylogeny p53 = factory
7971                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
7972                              new NHXParser() )[ 0 ];
7973             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
7974                 return false;
7975             }
7976             // 
7977             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
7978             if ( p54.getNode( "A" ) == null ) {
7979                 return false;
7980             }
7981             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7982                     .equals( "((A,B)[88],C);" ) ) {
7983                 return false;
7984             }
7985         }
7986         catch ( final Exception e ) {
7987             e.printStackTrace( System.out );
7988             return false;
7989         }
7990         return true;
7991     }
7992
7993     private static boolean testNHParsingIter() {
7994         try {
7995             final String p0_str = "(A,B);";
7996             final NHXParser p = new NHXParser();
7997             p.setSource( p0_str );
7998             if ( !p.hasNext() ) {
7999                 return false;
8000             }
8001             final Phylogeny p0 = p.next();
8002             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8003                 System.out.println( p0.toNewHampshire() );
8004                 return false;
8005             }
8006             if ( p.hasNext() ) {
8007                 return false;
8008             }
8009             if ( p.next() != null ) {
8010                 return false;
8011             }
8012             //
8013             final String p00_str = "(A,B)root;";
8014             p.setSource( p00_str );
8015             final Phylogeny p00 = p.next();
8016             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8017                 System.out.println( p00.toNewHampshire() );
8018                 return false;
8019             }
8020             //
8021             final String p000_str = "A;";
8022             p.setSource( p000_str );
8023             final Phylogeny p000 = p.next();
8024             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8025                 System.out.println( p000.toNewHampshire() );
8026                 return false;
8027             }
8028             //
8029             final String p0000_str = "A";
8030             p.setSource( p0000_str );
8031             final Phylogeny p0000 = p.next();
8032             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8033                 System.out.println( p0000.toNewHampshire() );
8034                 return false;
8035             }
8036             //
8037             p.setSource( "(A)" );
8038             final Phylogeny p00000 = p.next();
8039             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8040                 System.out.println( p00000.toNewHampshire() );
8041                 return false;
8042             }
8043             //
8044             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8045             p.setSource( p1_str );
8046             if ( !p.hasNext() ) {
8047                 return false;
8048             }
8049             final Phylogeny p1_0 = p.next();
8050             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8051                 System.out.println( p1_0.toNewHampshire() );
8052                 return false;
8053             }
8054             if ( !p.hasNext() ) {
8055                 return false;
8056             }
8057             final Phylogeny p1_1 = p.next();
8058             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8059                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8060                 return false;
8061             }
8062             if ( !p.hasNext() ) {
8063                 return false;
8064             }
8065             final Phylogeny p1_2 = p.next();
8066             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8067                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8068                 return false;
8069             }
8070             if ( !p.hasNext() ) {
8071                 return false;
8072             }
8073             final Phylogeny p1_3 = p.next();
8074             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8075                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8076                 return false;
8077             }
8078             if ( p.hasNext() ) {
8079                 return false;
8080             }
8081             if ( p.next() != null ) {
8082                 return false;
8083             }
8084             //
8085             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8086             p.setSource( p2_str );
8087             if ( !p.hasNext() ) {
8088                 return false;
8089             }
8090             Phylogeny p2_0 = p.next();
8091             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8092                 System.out.println( p2_0.toNewHampshire() );
8093                 return false;
8094             }
8095             if ( !p.hasNext() ) {
8096                 return false;
8097             }
8098             Phylogeny p2_1 = p.next();
8099             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8100                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8101                 return false;
8102             }
8103             if ( !p.hasNext() ) {
8104                 return false;
8105             }
8106             Phylogeny p2_2 = p.next();
8107             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8108                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8109                 return false;
8110             }
8111             if ( !p.hasNext() ) {
8112                 return false;
8113             }
8114             Phylogeny p2_3 = p.next();
8115             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8116                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8117                 return false;
8118             }
8119             if ( !p.hasNext() ) {
8120                 return false;
8121             }
8122             Phylogeny p2_4 = p.next();
8123             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8124                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8125                 return false;
8126             }
8127             if ( p.hasNext() ) {
8128                 return false;
8129             }
8130             if ( p.next() != null ) {
8131                 return false;
8132             }
8133             ////
8134             p.reset();
8135             if ( !p.hasNext() ) {
8136                 return false;
8137             }
8138             p2_0 = p.next();
8139             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8140                 System.out.println( p2_0.toNewHampshire() );
8141                 return false;
8142             }
8143             if ( !p.hasNext() ) {
8144                 return false;
8145             }
8146             p2_1 = p.next();
8147             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8148                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8149                 return false;
8150             }
8151             if ( !p.hasNext() ) {
8152                 return false;
8153             }
8154             p2_2 = p.next();
8155             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8156                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8157                 return false;
8158             }
8159             if ( !p.hasNext() ) {
8160                 return false;
8161             }
8162             p2_3 = p.next();
8163             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8164                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8165                 return false;
8166             }
8167             if ( !p.hasNext() ) {
8168                 return false;
8169             }
8170             p2_4 = p.next();
8171             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8172                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8173                 return false;
8174             }
8175             if ( p.hasNext() ) {
8176                 return false;
8177             }
8178             if ( p.next() != null ) {
8179                 return false;
8180             }
8181             //
8182             final String p3_str = "((A,B),C)abc";
8183             p.setSource( p3_str );
8184             if ( !p.hasNext() ) {
8185                 return false;
8186             }
8187             final Phylogeny p3_0 = p.next();
8188             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8189                 return false;
8190             }
8191             if ( p.hasNext() ) {
8192                 return false;
8193             }
8194             if ( p.next() != null ) {
8195                 return false;
8196             }
8197             //
8198             final String p4_str = "((A,B)ab,C)abc";
8199             p.setSource( p4_str );
8200             if ( !p.hasNext() ) {
8201                 return false;
8202             }
8203             final Phylogeny p4_0 = p.next();
8204             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8205                 return false;
8206             }
8207             if ( p.hasNext() ) {
8208                 return false;
8209             }
8210             if ( p.next() != null ) {
8211                 return false;
8212             }
8213             //
8214             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8215             p.setSource( p5_str );
8216             if ( !p.hasNext() ) {
8217                 return false;
8218             }
8219             final Phylogeny p5_0 = p.next();
8220             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8221                 return false;
8222             }
8223             if ( p.hasNext() ) {
8224                 return false;
8225             }
8226             if ( p.next() != null ) {
8227                 return false;
8228             }
8229             //
8230             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8231             p.setSource( p6_str );
8232             if ( !p.hasNext() ) {
8233                 return false;
8234             }
8235             Phylogeny p6_0 = p.next();
8236             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8237                 return false;
8238             }
8239             if ( p.hasNext() ) {
8240                 return false;
8241             }
8242             if ( p.next() != null ) {
8243                 return false;
8244             }
8245             p.reset();
8246             if ( !p.hasNext() ) {
8247                 return false;
8248             }
8249             p6_0 = p.next();
8250             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8251                 return false;
8252             }
8253             if ( p.hasNext() ) {
8254                 return false;
8255             }
8256             if ( p.next() != null ) {
8257                 return false;
8258             }
8259             //
8260             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8261             p.setSource( p7_str );
8262             if ( !p.hasNext() ) {
8263                 return false;
8264             }
8265             Phylogeny p7_0 = p.next();
8266             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8267                 return false;
8268             }
8269             if ( p.hasNext() ) {
8270                 return false;
8271             }
8272             if ( p.next() != null ) {
8273                 return false;
8274             }
8275             p.reset();
8276             if ( !p.hasNext() ) {
8277                 return false;
8278             }
8279             p7_0 = p.next();
8280             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8281                 return false;
8282             }
8283             if ( p.hasNext() ) {
8284                 return false;
8285             }
8286             if ( p.next() != null ) {
8287                 return false;
8288             }
8289             //
8290             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8291             p.setSource( p8_str );
8292             if ( !p.hasNext() ) {
8293                 return false;
8294             }
8295             Phylogeny p8_0 = p.next();
8296             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8297                 return false;
8298             }
8299             if ( !p.hasNext() ) {
8300                 return false;
8301             }
8302             if ( !p.hasNext() ) {
8303                 return false;
8304             }
8305             Phylogeny p8_1 = p.next();
8306             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8307                 return false;
8308             }
8309             if ( p.hasNext() ) {
8310                 return false;
8311             }
8312             if ( p.next() != null ) {
8313                 return false;
8314             }
8315             p.reset();
8316             if ( !p.hasNext() ) {
8317                 return false;
8318             }
8319             p8_0 = p.next();
8320             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8321                 return false;
8322             }
8323             if ( !p.hasNext() ) {
8324                 return false;
8325             }
8326             p8_1 = p.next();
8327             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8328                 return false;
8329             }
8330             if ( p.hasNext() ) {
8331                 return false;
8332             }
8333             if ( p.next() != null ) {
8334                 return false;
8335             }
8336             p.reset();
8337             //
8338             p.setSource( "" );
8339             if ( p.hasNext() ) {
8340                 return false;
8341             }
8342             //
8343             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8344             if ( !p.hasNext() ) {
8345                 return false;
8346             }
8347             Phylogeny p_27 = p.next();
8348             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8349                 System.out.println( p_27.toNewHampshireX() );
8350                 System.exit( -1 );
8351                 return false;
8352             }
8353             if ( p.hasNext() ) {
8354                 return false;
8355             }
8356             if ( p.next() != null ) {
8357                 return false;
8358             }
8359             p.reset();
8360             if ( !p.hasNext() ) {
8361                 return false;
8362             }
8363             p_27 = p.next();
8364             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8365                 System.out.println( p_27.toNewHampshireX() );
8366                 System.exit( -1 );
8367                 return false;
8368             }
8369             if ( p.hasNext() ) {
8370                 return false;
8371             }
8372             if ( p.next() != null ) {
8373                 return false;
8374             }
8375             //
8376             final String p30_str = "(A,B);(C,D)";
8377             final NHXParser p30 = new NHXParser();
8378             p30.setSource( p30_str );
8379             if ( !p30.hasNext() ) {
8380                 return false;
8381             }
8382             Phylogeny phy30 = p30.next();
8383             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8384                 System.out.println( phy30.toNewHampshire() );
8385                 return false;
8386             }
8387             if ( !p30.hasNext() ) {
8388                 return false;
8389             }
8390             Phylogeny phy301 = p30.next();
8391             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8392                 System.out.println( phy301.toNewHampshire() );
8393                 return false;
8394             }
8395             if ( p30.hasNext() ) {
8396                 return false;
8397             }
8398             if ( p30.hasNext() ) {
8399                 return false;
8400             }
8401             if ( p30.next() != null ) {
8402                 return false;
8403             }
8404             if ( p30.next() != null ) {
8405                 return false;
8406             }
8407             p30.reset();
8408             if ( !p30.hasNext() ) {
8409                 return false;
8410             }
8411             phy30 = p30.next();
8412             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8413                 System.out.println( phy30.toNewHampshire() );
8414                 return false;
8415             }
8416             if ( !p30.hasNext() ) {
8417                 return false;
8418             }
8419             phy301 = p30.next();
8420             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8421                 System.out.println( phy301.toNewHampshire() );
8422                 return false;
8423             }
8424             if ( p30.hasNext() ) {
8425                 return false;
8426             }
8427             if ( p30.hasNext() ) {
8428                 return false;
8429             }
8430             if ( p30.next() != null ) {
8431                 return false;
8432             }
8433             if ( p30.next() != null ) {
8434                 return false;
8435             }
8436         }
8437         catch ( final Exception e ) {
8438             e.printStackTrace( System.out );
8439             return false;
8440         }
8441         return true;
8442     }
8443
8444     private static boolean testNHXconversion() {
8445         try {
8446             final PhylogenyNode n1 = new PhylogenyNode();
8447             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8448             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8449             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8450             final PhylogenyNode n5 = PhylogenyNode
8451                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8452             final PhylogenyNode n6 = PhylogenyNode
8453                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8454             if ( !n1.toNewHampshireX().equals( "" ) ) {
8455                 return false;
8456             }
8457             if ( !n2.toNewHampshireX().equals( "" ) ) {
8458                 return false;
8459             }
8460             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8461                 return false;
8462             }
8463             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8464                 return false;
8465             }
8466             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8467                 return false;
8468             }
8469             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8470                 System.out.println( n6.toNewHampshireX() );
8471                 return false;
8472             }
8473         }
8474         catch ( final Exception e ) {
8475             e.printStackTrace( System.out );
8476             return false;
8477         }
8478         return true;
8479     }
8480
8481     private static boolean testNHXNodeParsing() {
8482         try {
8483             final PhylogenyNode n1 = new PhylogenyNode();
8484             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8485             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8486             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8487             final PhylogenyNode n5 = PhylogenyNode
8488                     .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]" );
8489             if ( !n3.getName().equals( "n3" ) ) {
8490                 return false;
8491             }
8492             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8493                 return false;
8494             }
8495             if ( n3.isDuplication() ) {
8496                 return false;
8497             }
8498             if ( n3.isHasAssignedEvent() ) {
8499                 return false;
8500             }
8501             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
8502                 return false;
8503             }
8504             if ( !n4.getName().equals( "n4" ) ) {
8505                 return false;
8506             }
8507             if ( n4.getDistanceToParent() != 0.01 ) {
8508                 return false;
8509             }
8510             if ( !n5.getName().equals( "n5" ) ) {
8511                 return false;
8512             }
8513             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
8514                 return false;
8515             }
8516             if ( n5.getDistanceToParent() != 0.1 ) {
8517                 return false;
8518             }
8519             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
8520                 return false;
8521             }
8522             if ( !n5.isDuplication() ) {
8523                 return false;
8524             }
8525             if ( !n5.isHasAssignedEvent() ) {
8526                 return false;
8527             }
8528             final PhylogenyNode n8 = PhylogenyNode
8529                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
8530                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8531             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8532                 return false;
8533             }
8534             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
8535                 return false;
8536             }
8537             final PhylogenyNode n9 = PhylogenyNode
8538                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
8539                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8540             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
8541                 return false;
8542             }
8543             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
8544                 return false;
8545             }
8546             final PhylogenyNode n10 = PhylogenyNode
8547                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8548             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
8549                 return false;
8550             }
8551             final PhylogenyNode n20 = PhylogenyNode
8552                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8553             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8554                 return false;
8555             }
8556             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
8557                 return false;
8558             }
8559             final PhylogenyNode n20x = PhylogenyNode
8560                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8561             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
8562                 return false;
8563             }
8564             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
8565                 return false;
8566             }
8567             final PhylogenyNode n20xx = PhylogenyNode
8568                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8569             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
8570                 return false;
8571             }
8572             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
8573                 return false;
8574             }
8575             final PhylogenyNode n20xxx = PhylogenyNode
8576                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8577             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
8578                 return false;
8579             }
8580             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
8581                 return false;
8582             }
8583             final PhylogenyNode n20xxxx = PhylogenyNode
8584                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8585             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
8586                 return false;
8587             }
8588             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
8589                 return false;
8590             }
8591             final PhylogenyNode n21 = PhylogenyNode
8592                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8593             if ( !n21.getName().equals( "N21_PIG" ) ) {
8594                 return false;
8595             }
8596             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
8597                 return false;
8598             }
8599             final PhylogenyNode n21x = PhylogenyNode
8600                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8601             if ( !n21x.getName().equals( "n21_PIG" ) ) {
8602                 return false;
8603             }
8604             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
8605                 return false;
8606             }
8607             final PhylogenyNode n22 = PhylogenyNode
8608                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8609             if ( !n22.getName().equals( "n22/PIG" ) ) {
8610                 return false;
8611             }
8612             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
8613                 return false;
8614             }
8615             final PhylogenyNode n23 = PhylogenyNode
8616                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8617             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
8618                 return false;
8619             }
8620             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
8621                 return false;
8622             }
8623             final PhylogenyNode a = PhylogenyNode
8624                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8625             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8626                 return false;
8627             }
8628             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
8629                 return false;
8630             }
8631             final PhylogenyNode c1 = PhylogenyNode
8632                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
8633                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8634             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
8635                 return false;
8636             }
8637             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
8638                 return false;
8639             }
8640             final PhylogenyNode c2 = PhylogenyNode
8641                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
8642                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8643             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
8644                 return false;
8645             }
8646             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
8647                 return false;
8648             }
8649             final PhylogenyNode e3 = PhylogenyNode
8650                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8651             if ( !e3.getName().equals( "n10_RAT~" ) ) {
8652                 return false;
8653             }
8654             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
8655                 return false;
8656             }
8657             final PhylogenyNode n11 = PhylogenyNode
8658                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
8659                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8660             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
8661                 return false;
8662             }
8663             if ( n11.getDistanceToParent() != 0.4 ) {
8664                 return false;
8665             }
8666             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
8667                 return false;
8668             }
8669             final PhylogenyNode n12 = PhylogenyNode
8670                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
8671                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8672             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
8673                 return false;
8674             }
8675             if ( n12.getDistanceToParent() != 0.4 ) {
8676                 return false;
8677             }
8678             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
8679                 return false;
8680             }
8681             final PhylogenyNode o = PhylogenyNode
8682                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8683             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
8684                 return false;
8685             }
8686             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
8687                 return false;
8688             }
8689             if ( n1.getName().compareTo( "" ) != 0 ) {
8690                 return false;
8691             }
8692             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8693                 return false;
8694             }
8695             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8696                 return false;
8697             }
8698             if ( n2.getName().compareTo( "" ) != 0 ) {
8699                 return false;
8700             }
8701             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8702                 return false;
8703             }
8704             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8705                 return false;
8706             }
8707             final PhylogenyNode n00 = PhylogenyNode
8708                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
8709             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
8710                 return false;
8711             }
8712             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
8713                 return false;
8714             }
8715             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
8716             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
8717                 return false;
8718             }
8719             final PhylogenyNode n13 = PhylogenyNode
8720                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8721             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
8722                 return false;
8723             }
8724             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
8725                 return false;
8726             }
8727             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8728                 return false;
8729             }
8730             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8731                 return false;
8732             }
8733             final PhylogenyNode n14 = PhylogenyNode
8734                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8735             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
8736                 return false;
8737             }
8738             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
8739                 return false;
8740             }
8741             final PhylogenyNode n15 = PhylogenyNode
8742                     .createInstanceFromNhxString( "something_wicked[123]",
8743                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8744             if ( !n15.getName().equals( "something_wicked" ) ) {
8745                 return false;
8746             }
8747             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
8748                 return false;
8749             }
8750             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
8751                 return false;
8752             }
8753             final PhylogenyNode n16 = PhylogenyNode
8754                     .createInstanceFromNhxString( "something_wicked2[9]",
8755                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8756             if ( !n16.getName().equals( "something_wicked2" ) ) {
8757                 return false;
8758             }
8759             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
8760                 return false;
8761             }
8762             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
8763                 return false;
8764             }
8765             final PhylogenyNode n17 = PhylogenyNode
8766                     .createInstanceFromNhxString( "something_wicked3[a]",
8767                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8768             if ( !n17.getName().equals( "something_wicked3" ) ) {
8769                 return false;
8770             }
8771             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
8772                 return false;
8773             }
8774             final PhylogenyNode n18 = PhylogenyNode
8775                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8776             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
8777                 return false;
8778             }
8779             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
8780                 return false;
8781             }
8782             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
8783                 return false;
8784             }
8785             final PhylogenyNode n19 = PhylogenyNode
8786                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8787             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
8788                 return false;
8789             }
8790             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8791                 return false;
8792             }
8793             final PhylogenyNode n30 = PhylogenyNode
8794                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
8795                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8796             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
8797                 return false;
8798             }
8799             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8800                 return false;
8801             }
8802             final PhylogenyNode n31 = PhylogenyNode
8803                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
8804                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8805             if ( n31.getNodeData().isHasTaxonomy() ) {
8806                 return false;
8807             }
8808             final PhylogenyNode n32 = PhylogenyNode
8809                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8810             if ( n32.getNodeData().isHasTaxonomy() ) {
8811                 return false;
8812             }
8813             final PhylogenyNode n40 = PhylogenyNode
8814                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8815             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8816                 return false;
8817             }
8818             final PhylogenyNode n41 = PhylogenyNode
8819                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8820             if ( n41.getNodeData().isHasTaxonomy() ) {
8821                 return false;
8822             }
8823             final PhylogenyNode n42 = PhylogenyNode
8824                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8825             if ( n42.getNodeData().isHasTaxonomy() ) {
8826                 return false;
8827             }
8828             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
8829                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
8830             if ( n43.getNodeData().isHasTaxonomy() ) {
8831                 return false;
8832             }
8833             final PhylogenyNode n44 = PhylogenyNode
8834                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8835             if ( n44.getNodeData().isHasTaxonomy() ) {
8836                 return false;
8837             }
8838         }
8839         catch ( final Exception e ) {
8840             e.printStackTrace( System.out );
8841             return false;
8842         }
8843         return true;
8844     }
8845
8846     private static boolean testNHXParsing() {
8847         try {
8848             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8849             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
8850             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
8851                 return false;
8852             }
8853             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]";
8854             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
8855             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8856                 return false;
8857             }
8858             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]";
8859             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
8860             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
8861                 return false;
8862             }
8863             final Phylogeny[] p3 = factory
8864                     .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]",
8865                              new NHXParser() );
8866             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8867                 return false;
8868             }
8869             final Phylogeny[] p4 = factory
8870                     .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(]",
8871                              new NHXParser() );
8872             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8873                 return false;
8874             }
8875             final Phylogeny[] p5 = factory
8876                     .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(((]",
8877                              new NHXParser() );
8878             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8879                 return false;
8880             }
8881             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)";
8882             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)";
8883             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
8884             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
8885                 return false;
8886             }
8887             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)))";
8888             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)))";
8889             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
8890             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
8891                 return false;
8892             }
8893             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])   ))[,,, ])))))))";
8894             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
8895             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
8896             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
8897                 return false;
8898             }
8899             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
8900             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8901                 return false;
8902             }
8903             final Phylogeny p10 = factory
8904                     .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]",
8905                              new NHXParser() )[ 0 ];
8906             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8907                 return false;
8908             }
8909         }
8910         catch ( final Exception e ) {
8911             e.printStackTrace( System.out );
8912             return false;
8913         }
8914         return true;
8915     }
8916
8917     private static boolean testNHXParsingMB() {
8918         try {
8919             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8920             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
8921                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8922                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8923                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8924                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8925                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8926                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8927                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8928                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
8929             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
8930                 return false;
8931             }
8932             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
8933                 return false;
8934             }
8935             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
8936                            0.1100000000000000e+00 ) ) {
8937                 return false;
8938             }
8939             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
8940                 return false;
8941             }
8942             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
8943                 return false;
8944             }
8945             final Phylogeny p2 = factory
8946                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
8947                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8948                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8949                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8950                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8951                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8952                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8953                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8954                                      + "7.369400000000000e-02}])",
8955                              new NHXParser() )[ 0 ];
8956             if ( p2.getNode( "1" ) == null ) {
8957                 return false;
8958             }
8959             if ( p2.getNode( "2" ) == null ) {
8960                 return false;
8961             }
8962         }
8963         catch ( final Exception e ) {
8964             e.printStackTrace( System.out );
8965             System.exit( -1 );
8966             return false;
8967         }
8968         return true;
8969     }
8970
8971     private static boolean testNHXParsingQuotes() {
8972         try {
8973             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8974             final NHXParser p = new NHXParser();
8975             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
8976             if ( phylogenies_0.length != 5 ) {
8977                 return false;
8978             }
8979             final Phylogeny phy = phylogenies_0[ 4 ];
8980             if ( phy.getNumberOfExternalNodes() != 7 ) {
8981                 return false;
8982             }
8983             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
8984                 return false;
8985             }
8986             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
8987                 return false;
8988             }
8989             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
8990                     .getScientificName().equals( "hsapiens" ) ) {
8991                 return false;
8992             }
8993             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
8994                 return false;
8995             }
8996             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
8997                 return false;
8998             }
8999             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
9000                 return false;
9001             }
9002             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9003                 return false;
9004             }
9005             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
9006                 return false;
9007             }
9008             final NHXParser p1p = new NHXParser();
9009             p1p.setIgnoreQuotes( true );
9010             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9011             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9012                 return false;
9013             }
9014             final NHXParser p2p = new NHXParser();
9015             p1p.setIgnoreQuotes( false );
9016             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9017             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9018                 return false;
9019             }
9020             final NHXParser p3p = new NHXParser();
9021             p3p.setIgnoreQuotes( false );
9022             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9023             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9024                 return false;
9025             }
9026             final NHXParser p4p = new NHXParser();
9027             p4p.setIgnoreQuotes( false );
9028             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9029             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9030                 return false;
9031             }
9032             final Phylogeny p10 = factory
9033                     .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]",
9034                              new NHXParser() )[ 0 ];
9035             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]";
9036             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9037                 return false;
9038             }
9039             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9040             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9041                 return false;
9042             }
9043             //
9044             final Phylogeny p12 = factory
9045                     .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]",
9046                              new NHXParser() )[ 0 ];
9047             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]";
9048             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9049                 return false;
9050             }
9051             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9052             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9053                 return false;
9054             }
9055             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;";
9056             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9057                 return false;
9058             }
9059             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9060             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9061                 return false;
9062             }
9063         }
9064         catch ( final Exception e ) {
9065             e.printStackTrace( System.out );
9066             return false;
9067         }
9068         return true;
9069     }
9070
9071     private static boolean testNodeRemoval() {
9072         try {
9073             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9074             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9075             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9076             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9077                 return false;
9078             }
9079             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9080             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9081             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9082                 return false;
9083             }
9084             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9085             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9086             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9087                 return false;
9088             }
9089         }
9090         catch ( final Exception e ) {
9091             e.printStackTrace( System.out );
9092             return false;
9093         }
9094         return true;
9095     }
9096
9097     private static boolean testPhylogenyBranch() {
9098         try {
9099             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9100             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9101             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9102             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9103             if ( !a1b1.equals( a1b1 ) ) {
9104                 return false;
9105             }
9106             if ( !a1b1.equals( b1a1 ) ) {
9107                 return false;
9108             }
9109             if ( !b1a1.equals( a1b1 ) ) {
9110                 return false;
9111             }
9112             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9113             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9114             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9115             if ( a1_b1.equals( b1_a1 ) ) {
9116                 return false;
9117             }
9118             if ( a1_b1.equals( a1_b1_ ) ) {
9119                 return false;
9120             }
9121             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9122             if ( !a1_b1.equals( b1_a1_ ) ) {
9123                 return false;
9124             }
9125             if ( a1_b1_.equals( b1_a1_ ) ) {
9126                 return false;
9127             }
9128             if ( !a1_b1_.equals( b1_a1 ) ) {
9129                 return false;
9130             }
9131         }
9132         catch ( final Exception e ) {
9133             e.printStackTrace( System.out );
9134             return false;
9135         }
9136         return true;
9137     }
9138
9139     private static boolean testPhyloXMLparsingOfDistributionElement() {
9140         try {
9141             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9142             PhyloXmlParser xml_parser = null;
9143             try {
9144                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9145             }
9146             catch ( final Exception e ) {
9147                 // Do nothing -- means were not running from jar.
9148             }
9149             if ( xml_parser == null ) {
9150                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9151                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9152                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9153                 }
9154                 else {
9155                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9156                 }
9157             }
9158             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9159                                                               xml_parser );
9160             if ( xml_parser.getErrorCount() > 0 ) {
9161                 System.out.println( xml_parser.getErrorMessages().toString() );
9162                 return false;
9163             }
9164             if ( phylogenies_0.length != 1 ) {
9165                 return false;
9166             }
9167             final Phylogeny t1 = phylogenies_0[ 0 ];
9168             PhylogenyNode n = null;
9169             Distribution d = null;
9170             n = t1.getNode( "root node" );
9171             if ( !n.getNodeData().isHasDistribution() ) {
9172                 return false;
9173             }
9174             if ( n.getNodeData().getDistributions().size() != 1 ) {
9175                 return false;
9176             }
9177             d = n.getNodeData().getDistribution();
9178             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9179                 return false;
9180             }
9181             if ( d.getPoints().size() != 1 ) {
9182                 return false;
9183             }
9184             if ( d.getPolygons() != null ) {
9185                 return false;
9186             }
9187             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9188                 return false;
9189             }
9190             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9191                 return false;
9192             }
9193             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9194                 return false;
9195             }
9196             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9197                 return false;
9198             }
9199             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9200                 return false;
9201             }
9202             n = t1.getNode( "node a" );
9203             if ( !n.getNodeData().isHasDistribution() ) {
9204                 return false;
9205             }
9206             if ( n.getNodeData().getDistributions().size() != 2 ) {
9207                 return false;
9208             }
9209             d = n.getNodeData().getDistribution( 1 );
9210             if ( !d.getDesc().equals( "San Diego" ) ) {
9211                 return false;
9212             }
9213             if ( d.getPoints().size() != 1 ) {
9214                 return false;
9215             }
9216             if ( d.getPolygons() != null ) {
9217                 return false;
9218             }
9219             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9220                 return false;
9221             }
9222             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9223                 return false;
9224             }
9225             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9226                 return false;
9227             }
9228             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9229                 return false;
9230             }
9231             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9232                 return false;
9233             }
9234             n = t1.getNode( "node bb" );
9235             if ( !n.getNodeData().isHasDistribution() ) {
9236                 return false;
9237             }
9238             if ( n.getNodeData().getDistributions().size() != 1 ) {
9239                 return false;
9240             }
9241             d = n.getNodeData().getDistribution( 0 );
9242             if ( d.getPoints().size() != 3 ) {
9243                 return false;
9244             }
9245             if ( d.getPolygons().size() != 2 ) {
9246                 return false;
9247             }
9248             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9249                 return false;
9250             }
9251             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9252                 return false;
9253             }
9254             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9255                 return false;
9256             }
9257             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9258                 return false;
9259             }
9260             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9261                 return false;
9262             }
9263             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9264                 return false;
9265             }
9266             Polygon p = d.getPolygons().get( 0 );
9267             if ( p.getPoints().size() != 3 ) {
9268                 return false;
9269             }
9270             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9271                 return false;
9272             }
9273             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9274                 return false;
9275             }
9276             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9277                 return false;
9278             }
9279             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9280                 return false;
9281             }
9282             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9283                 return false;
9284             }
9285             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9286                 return false;
9287             }
9288             p = d.getPolygons().get( 1 );
9289             if ( p.getPoints().size() != 3 ) {
9290                 return false;
9291             }
9292             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9293                 return false;
9294             }
9295             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9296                 return false;
9297             }
9298             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9299                 return false;
9300             }
9301             // Roundtrip:
9302             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9303             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9304             if ( rt.length != 1 ) {
9305                 return false;
9306             }
9307             final Phylogeny t1_rt = rt[ 0 ];
9308             n = t1_rt.getNode( "root node" );
9309             if ( !n.getNodeData().isHasDistribution() ) {
9310                 return false;
9311             }
9312             if ( n.getNodeData().getDistributions().size() != 1 ) {
9313                 return false;
9314             }
9315             d = n.getNodeData().getDistribution();
9316             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9317                 return false;
9318             }
9319             if ( d.getPoints().size() != 1 ) {
9320                 return false;
9321             }
9322             if ( d.getPolygons() != null ) {
9323                 return false;
9324             }
9325             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9326                 return false;
9327             }
9328             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9329                 return false;
9330             }
9331             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9332                 return false;
9333             }
9334             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9335                 return false;
9336             }
9337             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9338                 return false;
9339             }
9340             n = t1_rt.getNode( "node a" );
9341             if ( !n.getNodeData().isHasDistribution() ) {
9342                 return false;
9343             }
9344             if ( n.getNodeData().getDistributions().size() != 2 ) {
9345                 return false;
9346             }
9347             d = n.getNodeData().getDistribution( 1 );
9348             if ( !d.getDesc().equals( "San Diego" ) ) {
9349                 return false;
9350             }
9351             if ( d.getPoints().size() != 1 ) {
9352                 return false;
9353             }
9354             if ( d.getPolygons() != null ) {
9355                 return false;
9356             }
9357             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9358                 return false;
9359             }
9360             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9361                 return false;
9362             }
9363             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9364                 return false;
9365             }
9366             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9367                 return false;
9368             }
9369             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9370                 return false;
9371             }
9372             n = t1_rt.getNode( "node bb" );
9373             if ( !n.getNodeData().isHasDistribution() ) {
9374                 return false;
9375             }
9376             if ( n.getNodeData().getDistributions().size() != 1 ) {
9377                 return false;
9378             }
9379             d = n.getNodeData().getDistribution( 0 );
9380             if ( d.getPoints().size() != 3 ) {
9381                 return false;
9382             }
9383             if ( d.getPolygons().size() != 2 ) {
9384                 return false;
9385             }
9386             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9387                 return false;
9388             }
9389             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9390                 return false;
9391             }
9392             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9393                 return false;
9394             }
9395             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9396                 return false;
9397             }
9398             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9399                 return false;
9400             }
9401             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9402                 return false;
9403             }
9404             p = d.getPolygons().get( 0 );
9405             if ( p.getPoints().size() != 3 ) {
9406                 return false;
9407             }
9408             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9409                 return false;
9410             }
9411             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9412                 return false;
9413             }
9414             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9415                 return false;
9416             }
9417             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9418                 return false;
9419             }
9420             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9421                 return false;
9422             }
9423             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9424                 return false;
9425             }
9426             p = d.getPolygons().get( 1 );
9427             if ( p.getPoints().size() != 3 ) {
9428                 return false;
9429             }
9430             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9431                 return false;
9432             }
9433             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9434                 return false;
9435             }
9436             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9437                 return false;
9438             }
9439         }
9440         catch ( final Exception e ) {
9441             e.printStackTrace( System.out );
9442             return false;
9443         }
9444         return true;
9445     }
9446
9447     private static boolean testPostOrderIterator() {
9448         try {
9449             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9450             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9451             PhylogenyNodeIterator it0;
9452             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9453                 it0.next();
9454             }
9455             for( it0.reset(); it0.hasNext(); ) {
9456                 it0.next();
9457             }
9458             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9459             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9460             if ( !it.next().getName().equals( "A" ) ) {
9461                 return false;
9462             }
9463             if ( !it.next().getName().equals( "B" ) ) {
9464                 return false;
9465             }
9466             if ( !it.next().getName().equals( "ab" ) ) {
9467                 return false;
9468             }
9469             if ( !it.next().getName().equals( "C" ) ) {
9470                 return false;
9471             }
9472             if ( !it.next().getName().equals( "D" ) ) {
9473                 return false;
9474             }
9475             if ( !it.next().getName().equals( "cd" ) ) {
9476                 return false;
9477             }
9478             if ( !it.next().getName().equals( "abcd" ) ) {
9479                 return false;
9480             }
9481             if ( !it.next().getName().equals( "E" ) ) {
9482                 return false;
9483             }
9484             if ( !it.next().getName().equals( "F" ) ) {
9485                 return false;
9486             }
9487             if ( !it.next().getName().equals( "ef" ) ) {
9488                 return false;
9489             }
9490             if ( !it.next().getName().equals( "G" ) ) {
9491                 return false;
9492             }
9493             if ( !it.next().getName().equals( "H" ) ) {
9494                 return false;
9495             }
9496             if ( !it.next().getName().equals( "gh" ) ) {
9497                 return false;
9498             }
9499             if ( !it.next().getName().equals( "efgh" ) ) {
9500                 return false;
9501             }
9502             if ( !it.next().getName().equals( "r" ) ) {
9503                 return false;
9504             }
9505             if ( it.hasNext() ) {
9506                 return false;
9507             }
9508         }
9509         catch ( final Exception e ) {
9510             e.printStackTrace( System.out );
9511             return false;
9512         }
9513         return true;
9514     }
9515
9516     private static boolean testPreOrderIterator() {
9517         try {
9518             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9519             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9520             PhylogenyNodeIterator it0;
9521             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
9522                 it0.next();
9523             }
9524             for( it0.reset(); it0.hasNext(); ) {
9525                 it0.next();
9526             }
9527             PhylogenyNodeIterator it = t0.iteratorPreorder();
9528             if ( !it.next().getName().equals( "r" ) ) {
9529                 return false;
9530             }
9531             if ( !it.next().getName().equals( "ab" ) ) {
9532                 return false;
9533             }
9534             if ( !it.next().getName().equals( "A" ) ) {
9535                 return false;
9536             }
9537             if ( !it.next().getName().equals( "B" ) ) {
9538                 return false;
9539             }
9540             if ( !it.next().getName().equals( "cd" ) ) {
9541                 return false;
9542             }
9543             if ( !it.next().getName().equals( "C" ) ) {
9544                 return false;
9545             }
9546             if ( !it.next().getName().equals( "D" ) ) {
9547                 return false;
9548             }
9549             if ( it.hasNext() ) {
9550                 return false;
9551             }
9552             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9553             it = t1.iteratorPreorder();
9554             if ( !it.next().getName().equals( "r" ) ) {
9555                 return false;
9556             }
9557             if ( !it.next().getName().equals( "abcd" ) ) {
9558                 return false;
9559             }
9560             if ( !it.next().getName().equals( "ab" ) ) {
9561                 return false;
9562             }
9563             if ( !it.next().getName().equals( "A" ) ) {
9564                 return false;
9565             }
9566             if ( !it.next().getName().equals( "B" ) ) {
9567                 return false;
9568             }
9569             if ( !it.next().getName().equals( "cd" ) ) {
9570                 return false;
9571             }
9572             if ( !it.next().getName().equals( "C" ) ) {
9573                 return false;
9574             }
9575             if ( !it.next().getName().equals( "D" ) ) {
9576                 return false;
9577             }
9578             if ( !it.next().getName().equals( "efgh" ) ) {
9579                 return false;
9580             }
9581             if ( !it.next().getName().equals( "ef" ) ) {
9582                 return false;
9583             }
9584             if ( !it.next().getName().equals( "E" ) ) {
9585                 return false;
9586             }
9587             if ( !it.next().getName().equals( "F" ) ) {
9588                 return false;
9589             }
9590             if ( !it.next().getName().equals( "gh" ) ) {
9591                 return false;
9592             }
9593             if ( !it.next().getName().equals( "G" ) ) {
9594                 return false;
9595             }
9596             if ( !it.next().getName().equals( "H" ) ) {
9597                 return false;
9598             }
9599             if ( it.hasNext() ) {
9600                 return false;
9601             }
9602         }
9603         catch ( final Exception e ) {
9604             e.printStackTrace( System.out );
9605             return false;
9606         }
9607         return true;
9608     }
9609
9610     private static boolean testPropertiesMap() {
9611         try {
9612             final PropertiesMap pm = new PropertiesMap();
9613             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9614             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9615             final Property p2 = new Property( "something:else",
9616                                               "?",
9617                                               "improbable:research",
9618                                               "xsd:decimal",
9619                                               AppliesTo.NODE );
9620             pm.addProperty( p0 );
9621             pm.addProperty( p1 );
9622             pm.addProperty( p2 );
9623             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
9624                 return false;
9625             }
9626             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
9627                 return false;
9628             }
9629             if ( pm.getProperties().size() != 3 ) {
9630                 return false;
9631             }
9632             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
9633                 return false;
9634             }
9635             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9636                 return false;
9637             }
9638             if ( pm.getProperties().size() != 3 ) {
9639                 return false;
9640             }
9641             pm.removeProperty( "dimensions:diameter" );
9642             if ( pm.getProperties().size() != 2 ) {
9643                 return false;
9644             }
9645             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
9646                 return false;
9647             }
9648             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9649                 return false;
9650             }
9651         }
9652         catch ( final Exception e ) {
9653             e.printStackTrace( System.out );
9654             return false;
9655         }
9656         return true;
9657     }
9658
9659     private static boolean testProteinId() {
9660         try {
9661             final ProteinId id1 = new ProteinId( "a" );
9662             final ProteinId id2 = new ProteinId( "a" );
9663             final ProteinId id3 = new ProteinId( "A" );
9664             final ProteinId id4 = new ProteinId( "b" );
9665             if ( !id1.equals( id1 ) ) {
9666                 return false;
9667             }
9668             if ( id1.getId().equals( "x" ) ) {
9669                 return false;
9670             }
9671             if ( id1.getId().equals( null ) ) {
9672                 return false;
9673             }
9674             if ( !id1.equals( id2 ) ) {
9675                 return false;
9676             }
9677             if ( id1.equals( id3 ) ) {
9678                 return false;
9679             }
9680             if ( id1.hashCode() != id1.hashCode() ) {
9681                 return false;
9682             }
9683             if ( id1.hashCode() != id2.hashCode() ) {
9684                 return false;
9685             }
9686             if ( id1.hashCode() == id3.hashCode() ) {
9687                 return false;
9688             }
9689             if ( id1.compareTo( id1 ) != 0 ) {
9690                 return false;
9691             }
9692             if ( id1.compareTo( id2 ) != 0 ) {
9693                 return false;
9694             }
9695             if ( id1.compareTo( id3 ) != 0 ) {
9696                 return false;
9697             }
9698             if ( id1.compareTo( id4 ) >= 0 ) {
9699                 return false;
9700             }
9701             if ( id4.compareTo( id1 ) <= 0 ) {
9702                 return false;
9703             }
9704             if ( !id4.getId().equals( "b" ) ) {
9705                 return false;
9706             }
9707             final ProteinId id5 = new ProteinId( " C " );
9708             if ( !id5.getId().equals( "C" ) ) {
9709                 return false;
9710             }
9711             if ( id5.equals( id1 ) ) {
9712                 return false;
9713             }
9714         }
9715         catch ( final Exception e ) {
9716             e.printStackTrace( System.out );
9717             return false;
9718         }
9719         return true;
9720     }
9721
9722     private static boolean testReIdMethods() {
9723         try {
9724             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9725             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
9726             final long count = PhylogenyNode.getNodeCount();
9727             p.levelOrderReID();
9728             if ( p.getNode( "r" ).getId() != count ) {
9729                 return false;
9730             }
9731             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
9732                 return false;
9733             }
9734             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
9735                 return false;
9736             }
9737             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
9738                 return false;
9739             }
9740             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
9741                 return false;
9742             }
9743             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
9744                 return false;
9745             }
9746             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
9747                 return false;
9748             }
9749             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
9750                 return false;
9751             }
9752             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
9753                 return false;
9754             }
9755             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
9756                 return false;
9757             }
9758             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
9759                 return false;
9760             }
9761             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
9762                 return false;
9763             }
9764             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
9765                 return false;
9766             }
9767             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
9768                 return false;
9769             }
9770             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
9771                 return false;
9772             }
9773         }
9774         catch ( final Exception e ) {
9775             e.printStackTrace( System.out );
9776             return false;
9777         }
9778         return true;
9779     }
9780
9781     private static boolean testRerooting() {
9782         try {
9783             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9784             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",
9785                                                  new NHXParser() )[ 0 ];
9786             if ( !t1.isRooted() ) {
9787                 return false;
9788             }
9789             t1.reRoot( t1.getNode( "D" ) );
9790             t1.reRoot( t1.getNode( "CD" ) );
9791             t1.reRoot( t1.getNode( "A" ) );
9792             t1.reRoot( t1.getNode( "B" ) );
9793             t1.reRoot( t1.getNode( "AB" ) );
9794             t1.reRoot( t1.getNode( "D" ) );
9795             t1.reRoot( t1.getNode( "C" ) );
9796             t1.reRoot( t1.getNode( "CD" ) );
9797             t1.reRoot( t1.getNode( "A" ) );
9798             t1.reRoot( t1.getNode( "B" ) );
9799             t1.reRoot( t1.getNode( "AB" ) );
9800             t1.reRoot( t1.getNode( "D" ) );
9801             t1.reRoot( t1.getNode( "D" ) );
9802             t1.reRoot( t1.getNode( "C" ) );
9803             t1.reRoot( t1.getNode( "A" ) );
9804             t1.reRoot( t1.getNode( "B" ) );
9805             t1.reRoot( t1.getNode( "AB" ) );
9806             t1.reRoot( t1.getNode( "C" ) );
9807             t1.reRoot( t1.getNode( "D" ) );
9808             t1.reRoot( t1.getNode( "CD" ) );
9809             t1.reRoot( t1.getNode( "D" ) );
9810             t1.reRoot( t1.getNode( "A" ) );
9811             t1.reRoot( t1.getNode( "B" ) );
9812             t1.reRoot( t1.getNode( "AB" ) );
9813             t1.reRoot( t1.getNode( "C" ) );
9814             t1.reRoot( t1.getNode( "D" ) );
9815             t1.reRoot( t1.getNode( "CD" ) );
9816             t1.reRoot( t1.getNode( "D" ) );
9817             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
9818                 return false;
9819             }
9820             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
9821                 return false;
9822             }
9823             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
9824                 return false;
9825             }
9826             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
9827                 return false;
9828             }
9829             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
9830                 return false;
9831             }
9832             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
9833                 return false;
9834             }
9835             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",
9836                                                  new NHXParser() )[ 0 ];
9837             t2.reRoot( t2.getNode( "A" ) );
9838             t2.reRoot( t2.getNode( "D" ) );
9839             t2.reRoot( t2.getNode( "ABC" ) );
9840             t2.reRoot( t2.getNode( "A" ) );
9841             t2.reRoot( t2.getNode( "B" ) );
9842             t2.reRoot( t2.getNode( "D" ) );
9843             t2.reRoot( t2.getNode( "C" ) );
9844             t2.reRoot( t2.getNode( "ABC" ) );
9845             t2.reRoot( t2.getNode( "A" ) );
9846             t2.reRoot( t2.getNode( "B" ) );
9847             t2.reRoot( t2.getNode( "AB" ) );
9848             t2.reRoot( t2.getNode( "AB" ) );
9849             t2.reRoot( t2.getNode( "D" ) );
9850             t2.reRoot( t2.getNode( "C" ) );
9851             t2.reRoot( t2.getNode( "B" ) );
9852             t2.reRoot( t2.getNode( "AB" ) );
9853             t2.reRoot( t2.getNode( "D" ) );
9854             t2.reRoot( t2.getNode( "D" ) );
9855             t2.reRoot( t2.getNode( "ABC" ) );
9856             t2.reRoot( t2.getNode( "A" ) );
9857             t2.reRoot( t2.getNode( "B" ) );
9858             t2.reRoot( t2.getNode( "AB" ) );
9859             t2.reRoot( t2.getNode( "D" ) );
9860             t2.reRoot( t2.getNode( "C" ) );
9861             t2.reRoot( t2.getNode( "ABC" ) );
9862             t2.reRoot( t2.getNode( "A" ) );
9863             t2.reRoot( t2.getNode( "B" ) );
9864             t2.reRoot( t2.getNode( "AB" ) );
9865             t2.reRoot( t2.getNode( "D" ) );
9866             t2.reRoot( t2.getNode( "D" ) );
9867             t2.reRoot( t2.getNode( "C" ) );
9868             t2.reRoot( t2.getNode( "A" ) );
9869             t2.reRoot( t2.getNode( "B" ) );
9870             t2.reRoot( t2.getNode( "AB" ) );
9871             t2.reRoot( t2.getNode( "C" ) );
9872             t2.reRoot( t2.getNode( "D" ) );
9873             t2.reRoot( t2.getNode( "ABC" ) );
9874             t2.reRoot( t2.getNode( "D" ) );
9875             t2.reRoot( t2.getNode( "A" ) );
9876             t2.reRoot( t2.getNode( "B" ) );
9877             t2.reRoot( t2.getNode( "AB" ) );
9878             t2.reRoot( t2.getNode( "C" ) );
9879             t2.reRoot( t2.getNode( "D" ) );
9880             t2.reRoot( t2.getNode( "ABC" ) );
9881             t2.reRoot( t2.getNode( "D" ) );
9882             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9883                 return false;
9884             }
9885             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9886                 return false;
9887             }
9888             t2.reRoot( t2.getNode( "ABC" ) );
9889             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9890                 return false;
9891             }
9892             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9893                 return false;
9894             }
9895             t2.reRoot( t2.getNode( "AB" ) );
9896             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9897                 return false;
9898             }
9899             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9900                 return false;
9901             }
9902             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9903                 return false;
9904             }
9905             t2.reRoot( t2.getNode( "AB" ) );
9906             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9907                 return false;
9908             }
9909             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9910                 return false;
9911             }
9912             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9913                 return false;
9914             }
9915             t2.reRoot( t2.getNode( "D" ) );
9916             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9917                 return false;
9918             }
9919             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9920                 return false;
9921             }
9922             t2.reRoot( t2.getNode( "ABC" ) );
9923             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9924                 return false;
9925             }
9926             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9927                 return false;
9928             }
9929             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
9930                                                  new NHXParser() )[ 0 ];
9931             t3.reRoot( t3.getNode( "B" ) );
9932             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9933                 return false;
9934             }
9935             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9936                 return false;
9937             }
9938             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9939                 return false;
9940             }
9941             t3.reRoot( t3.getNode( "B" ) );
9942             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9943                 return false;
9944             }
9945             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9946                 return false;
9947             }
9948             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9949                 return false;
9950             }
9951             t3.reRoot( t3.getRoot() );
9952             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9953                 return false;
9954             }
9955             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9956                 return false;
9957             }
9958             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9959                 return false;
9960             }
9961         }
9962         catch ( final Exception e ) {
9963             e.printStackTrace( System.out );
9964             return false;
9965         }
9966         return true;
9967     }
9968
9969     private static boolean testSDIse() {
9970         try {
9971             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9972             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
9973             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
9974             gene1.setRooted( true );
9975             species1.setRooted( true );
9976             final SDI sdi = new SDI( gene1, species1 );
9977             if ( !gene1.getRoot().isDuplication() ) {
9978                 return false;
9979             }
9980             final Phylogeny species2 = factory
9981                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9982                              new NHXParser() )[ 0 ];
9983             final Phylogeny gene2 = factory
9984                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9985                              new NHXParser() )[ 0 ];
9986             species2.setRooted( true );
9987             gene2.setRooted( true );
9988             final SDI sdi2 = new SDI( gene2, species2 );
9989             if ( sdi2.getDuplicationsSum() != 0 ) {
9990                 return false;
9991             }
9992             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
9993                 return false;
9994             }
9995             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
9996                 return false;
9997             }
9998             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
9999                 return false;
10000             }
10001             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10002                 return false;
10003             }
10004             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10005                 return false;
10006             }
10007             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10008                 return false;
10009             }
10010             final Phylogeny species3 = factory
10011                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10012                              new NHXParser() )[ 0 ];
10013             final Phylogeny gene3 = factory
10014                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10015                              new NHXParser() )[ 0 ];
10016             species3.setRooted( true );
10017             gene3.setRooted( true );
10018             final SDI sdi3 = new SDI( gene3, species3 );
10019             if ( sdi3.getDuplicationsSum() != 1 ) {
10020                 return false;
10021             }
10022             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10023                 return false;
10024             }
10025             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10026                 return false;
10027             }
10028             final Phylogeny species4 = factory
10029                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10030                              new NHXParser() )[ 0 ];
10031             final Phylogeny gene4 = factory
10032                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10033                              new NHXParser() )[ 0 ];
10034             species4.setRooted( true );
10035             gene4.setRooted( true );
10036             final SDI sdi4 = new SDI( gene4, species4 );
10037             if ( sdi4.getDuplicationsSum() != 1 ) {
10038                 return false;
10039             }
10040             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10041                 return false;
10042             }
10043             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10044                 return false;
10045             }
10046             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10047                 return false;
10048             }
10049             if ( species4.getNumberOfExternalNodes() != 6 ) {
10050                 return false;
10051             }
10052             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10053                 return false;
10054             }
10055             final Phylogeny species5 = factory
10056                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10057                              new NHXParser() )[ 0 ];
10058             final Phylogeny gene5 = factory
10059                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10060                              new NHXParser() )[ 0 ];
10061             species5.setRooted( true );
10062             gene5.setRooted( true );
10063             final SDI sdi5 = new SDI( gene5, species5 );
10064             if ( sdi5.getDuplicationsSum() != 2 ) {
10065                 return false;
10066             }
10067             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10068                 return false;
10069             }
10070             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10071                 return false;
10072             }
10073             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10074                 return false;
10075             }
10076             if ( species5.getNumberOfExternalNodes() != 6 ) {
10077                 return false;
10078             }
10079             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10080                 return false;
10081             }
10082             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10083             // Conjecture for Comparing Molecular Phylogenies"
10084             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10085             final Phylogeny species6 = factory
10086                     .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,"
10087                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10088                              new NHXParser() )[ 0 ];
10089             final Phylogeny gene6 = factory
10090                     .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,"
10091                                      + "((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,"
10092                                      + "(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;",
10093                              new NHXParser() )[ 0 ];
10094             species6.setRooted( true );
10095             gene6.setRooted( true );
10096             final SDI sdi6 = new SDI( gene6, species6 );
10097             if ( sdi6.getDuplicationsSum() != 3 ) {
10098                 return false;
10099             }
10100             if ( !gene6.getNode( "r" ).isDuplication() ) {
10101                 return false;
10102             }
10103             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10104                 return false;
10105             }
10106             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10107                 return false;
10108             }
10109             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10110                 return false;
10111             }
10112             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10113                 return false;
10114             }
10115             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10116                 return false;
10117             }
10118             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10119                 return false;
10120             }
10121             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10122                 return false;
10123             }
10124             sdi6.computeMappingCostL();
10125             if ( sdi6.computeMappingCostL() != 17 ) {
10126                 return false;
10127             }
10128             if ( species6.getNumberOfExternalNodes() != 9 ) {
10129                 return false;
10130             }
10131             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10132                 return false;
10133             }
10134             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10135                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10136                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10137                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10138                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10139             species7.setRooted( true );
10140             final Phylogeny gene7_1 = Test
10141                     .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])" );
10142             gene7_1.setRooted( true );
10143             final SDI sdi7 = new SDI( gene7_1, species7 );
10144             if ( sdi7.getDuplicationsSum() != 0 ) {
10145                 return false;
10146             }
10147             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10148                 return false;
10149             }
10150             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10151                 return false;
10152             }
10153             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10154                 return false;
10155             }
10156             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10157                 return false;
10158             }
10159             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10160                 return false;
10161             }
10162             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10163                 return false;
10164             }
10165             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10166                 return false;
10167             }
10168             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10169                 return false;
10170             }
10171             final Phylogeny gene7_2 = Test
10172                     .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])" );
10173             gene7_2.setRooted( true );
10174             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10175             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10176                 return false;
10177             }
10178             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10179                 return false;
10180             }
10181             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10182                 return false;
10183             }
10184             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10185                 return false;
10186             }
10187             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10188                 return false;
10189             }
10190             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10191                 return false;
10192             }
10193             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10194                 return false;
10195             }
10196             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10197                 return false;
10198             }
10199             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10200                 return false;
10201             }
10202             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10203                 return false;
10204             }
10205         }
10206         catch ( final Exception e ) {
10207             return false;
10208         }
10209         return true;
10210     }
10211
10212     private static boolean testSDIunrooted() {
10213         try {
10214             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10215             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10216             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10217             final Iterator<PhylogenyBranch> iter = l.iterator();
10218             PhylogenyBranch br = iter.next();
10219             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10220                 return false;
10221             }
10222             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10223                 return false;
10224             }
10225             br = iter.next();
10226             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10227                 return false;
10228             }
10229             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10230                 return false;
10231             }
10232             br = iter.next();
10233             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10234                 return false;
10235             }
10236             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10237                 return false;
10238             }
10239             br = iter.next();
10240             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10241                 return false;
10242             }
10243             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10244                 return false;
10245             }
10246             br = iter.next();
10247             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10248                 return false;
10249             }
10250             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10251                 return false;
10252             }
10253             br = iter.next();
10254             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10255                 return false;
10256             }
10257             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10258                 return false;
10259             }
10260             br = iter.next();
10261             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10262                 return false;
10263             }
10264             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10265                 return false;
10266             }
10267             br = iter.next();
10268             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10269                 return false;
10270             }
10271             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10272                 return false;
10273             }
10274             br = iter.next();
10275             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10276                 return false;
10277             }
10278             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10279                 return false;
10280             }
10281             br = iter.next();
10282             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10283                 return false;
10284             }
10285             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10286                 return false;
10287             }
10288             br = iter.next();
10289             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10290                 return false;
10291             }
10292             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10293                 return false;
10294             }
10295             br = iter.next();
10296             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10297                 return false;
10298             }
10299             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10300                 return false;
10301             }
10302             br = iter.next();
10303             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10304                 return false;
10305             }
10306             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10307                 return false;
10308             }
10309             br = iter.next();
10310             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10311                 return false;
10312             }
10313             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10314                 return false;
10315             }
10316             br = iter.next();
10317             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10318                 return false;
10319             }
10320             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10321                 return false;
10322             }
10323             if ( iter.hasNext() ) {
10324                 return false;
10325             }
10326             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10327             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10328             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10329             br = iter1.next();
10330             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10331                 return false;
10332             }
10333             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10334                 return false;
10335             }
10336             br = iter1.next();
10337             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10338                 return false;
10339             }
10340             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10341                 return false;
10342             }
10343             br = iter1.next();
10344             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10345                 return false;
10346             }
10347             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10348                 return false;
10349             }
10350             if ( iter1.hasNext() ) {
10351                 return false;
10352             }
10353             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10354             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10355             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10356             br = iter2.next();
10357             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10358                 return false;
10359             }
10360             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10361                 return false;
10362             }
10363             br = iter2.next();
10364             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10365                 return false;
10366             }
10367             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10368                 return false;
10369             }
10370             br = iter2.next();
10371             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10372                 return false;
10373             }
10374             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10375                 return false;
10376             }
10377             if ( iter2.hasNext() ) {
10378                 return false;
10379             }
10380             final Phylogeny species0 = factory
10381                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10382                              new NHXParser() )[ 0 ];
10383             final Phylogeny gene1 = factory
10384                     .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])",
10385                              new NHXParser() )[ 0 ];
10386             species0.setRooted( true );
10387             gene1.setRooted( true );
10388             final SDIR sdi_unrooted = new SDIR();
10389             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10390             if ( sdi_unrooted.getCount() != 1 ) {
10391                 return false;
10392             }
10393             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10394                 return false;
10395             }
10396             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10397                 return false;
10398             }
10399             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10400                 return false;
10401             }
10402             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10403                 return false;
10404             }
10405             final Phylogeny gene2 = factory
10406                     .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])",
10407                              new NHXParser() )[ 0 ];
10408             gene2.setRooted( true );
10409             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10410             if ( sdi_unrooted.getCount() != 1 ) {
10411                 return false;
10412             }
10413             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10414                 return false;
10415             }
10416             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10417                 return false;
10418             }
10419             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10420                 return false;
10421             }
10422             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10423                 return false;
10424             }
10425             final Phylogeny species6 = factory
10426                     .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,"
10427                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10428                              new NHXParser() )[ 0 ];
10429             final Phylogeny gene6 = factory
10430                     .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],"
10431                                      + "(((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],"
10432                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10433                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10434                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10435                              new NHXParser() )[ 0 ];
10436             species6.setRooted( true );
10437             gene6.setRooted( true );
10438             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10439             if ( sdi_unrooted.getCount() != 1 ) {
10440                 return false;
10441             }
10442             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10443                 return false;
10444             }
10445             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10446                 return false;
10447             }
10448             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10449                 return false;
10450             }
10451             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10452                 return false;
10453             }
10454             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10455                 return false;
10456             }
10457             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10458                 return false;
10459             }
10460             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10461                 return false;
10462             }
10463             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
10464                 return false;
10465             }
10466             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10467                 return false;
10468             }
10469             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
10470                 return false;
10471             }
10472             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
10473                 return false;
10474             }
10475             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10476                 return false;
10477             }
10478             p6 = null;
10479             final Phylogeny species7 = factory
10480                     .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,"
10481                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10482                              new NHXParser() )[ 0 ];
10483             final Phylogeny gene7 = factory
10484                     .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],"
10485                                      + "(((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],"
10486                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10487                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10488                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10489                              new NHXParser() )[ 0 ];
10490             species7.setRooted( true );
10491             gene7.setRooted( true );
10492             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
10493             if ( sdi_unrooted.getCount() != 1 ) {
10494                 return false;
10495             }
10496             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10497                 return false;
10498             }
10499             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10500                 return false;
10501             }
10502             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10503                 return false;
10504             }
10505             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
10506                 return false;
10507             }
10508             if ( !p7[ 0 ].getRoot().isDuplication() ) {
10509                 return false;
10510             }
10511             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10512                 return false;
10513             }
10514             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10515                 return false;
10516             }
10517             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
10518                 return false;
10519             }
10520             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10521                 return false;
10522             }
10523             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
10524                 return false;
10525             }
10526             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
10527                 return false;
10528             }
10529             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10530                 return false;
10531             }
10532             p7 = null;
10533             final Phylogeny species8 = factory
10534                     .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,"
10535                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10536                              new NHXParser() )[ 0 ];
10537             final Phylogeny gene8 = factory
10538                     .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],"
10539                                      + "(((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],"
10540                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10541                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10542                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10543                              new NHXParser() )[ 0 ];
10544             species8.setRooted( true );
10545             gene8.setRooted( true );
10546             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
10547             if ( sdi_unrooted.getCount() != 1 ) {
10548                 return false;
10549             }
10550             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10551                 return false;
10552             }
10553             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10554                 return false;
10555             }
10556             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10557                 return false;
10558             }
10559             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10560                 return false;
10561             }
10562             if ( !p8[ 0 ].getRoot().isDuplication() ) {
10563                 return false;
10564             }
10565             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10566                 return false;
10567             }
10568             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10569                 return false;
10570             }
10571             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
10572                 return false;
10573             }
10574             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10575                 return false;
10576             }
10577             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
10578                 return false;
10579             }
10580             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
10581                 return false;
10582             }
10583             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10584                 return false;
10585             }
10586             p8 = null;
10587         }
10588         catch ( final Exception e ) {
10589             e.printStackTrace( System.out );
10590             return false;
10591         }
10592         return true;
10593     }
10594
10595     private static boolean testSequenceDbWsTools1() {
10596         try {
10597             final PhylogenyNode n = new PhylogenyNode();
10598             n.setName( "NP_001025424" );
10599             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
10600             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10601                     || !acc.getValue().equals( "NP_001025424" ) ) {
10602                 return false;
10603             }
10604             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
10605             acc = SequenceDbWsTools.obtainSeqAccession( n );
10606             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10607                     || !acc.getValue().equals( "NP_001025424" ) ) {
10608                 return false;
10609             }
10610             n.setName( "NP_001025424.1" );
10611             acc = SequenceDbWsTools.obtainSeqAccession( n );
10612             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10613                     || !acc.getValue().equals( "NP_001025424" ) ) {
10614                 return false;
10615             }
10616             n.setName( "NM_001030253" );
10617             acc = SequenceDbWsTools.obtainSeqAccession( n );
10618             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10619                     || !acc.getValue().equals( "NM_001030253" ) ) {
10620                 return false;
10621             }
10622             n.setName( "BCL2_HUMAN" );
10623             acc = SequenceDbWsTools.obtainSeqAccession( n );
10624             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10625                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
10626                 System.out.println( acc.toString() );
10627                 return false;
10628             }
10629             n.setName( "P10415" );
10630             acc = SequenceDbWsTools.obtainSeqAccession( n );
10631             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10632                     || !acc.getValue().equals( "P10415" ) ) {
10633                 System.out.println( acc.toString() );
10634                 return false;
10635             }
10636             n.setName( " P10415 " );
10637             acc = SequenceDbWsTools.obtainSeqAccession( n );
10638             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10639                     || !acc.getValue().equals( "P10415" ) ) {
10640                 System.out.println( acc.toString() );
10641                 return false;
10642             }
10643             n.setName( "_P10415|" );
10644             acc = SequenceDbWsTools.obtainSeqAccession( n );
10645             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10646                     || !acc.getValue().equals( "P10415" ) ) {
10647                 System.out.println( acc.toString() );
10648                 return false;
10649             }
10650             n.setName( "AY695820" );
10651             acc = SequenceDbWsTools.obtainSeqAccession( n );
10652             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10653                     || !acc.getValue().equals( "AY695820" ) ) {
10654                 System.out.println( acc.toString() );
10655                 return false;
10656             }
10657             n.setName( "_AY695820_" );
10658             acc = SequenceDbWsTools.obtainSeqAccession( n );
10659             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10660                     || !acc.getValue().equals( "AY695820" ) ) {
10661                 System.out.println( acc.toString() );
10662                 return false;
10663             }
10664             n.setName( "AAA59452" );
10665             acc = SequenceDbWsTools.obtainSeqAccession( n );
10666             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10667                     || !acc.getValue().equals( "AAA59452" ) ) {
10668                 System.out.println( acc.toString() );
10669                 return false;
10670             }
10671             n.setName( "_AAA59452_" );
10672             acc = SequenceDbWsTools.obtainSeqAccession( n );
10673             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10674                     || !acc.getValue().equals( "AAA59452" ) ) {
10675                 System.out.println( acc.toString() );
10676                 return false;
10677             }
10678             n.setName( "AAA59452.1" );
10679             acc = SequenceDbWsTools.obtainSeqAccession( n );
10680             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10681                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10682                 System.out.println( acc.toString() );
10683                 return false;
10684             }
10685             n.setName( "_AAA59452.1_" );
10686             acc = SequenceDbWsTools.obtainSeqAccession( n );
10687             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10688                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10689                 System.out.println( acc.toString() );
10690                 return false;
10691             }
10692             n.setName( "GI:94894583" );
10693             acc = SequenceDbWsTools.obtainSeqAccession( n );
10694             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10695                     || !acc.getValue().equals( "94894583" ) ) {
10696                 System.out.println( acc.toString() );
10697                 return false;
10698             }
10699             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10700             acc = SequenceDbWsTools.obtainSeqAccession( n );
10701             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10702                     || !acc.getValue().equals( "71845847" ) ) {
10703                 System.out.println( acc.toString() );
10704                 return false;
10705             }
10706             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10707             acc = SequenceDbWsTools.obtainSeqAccession( n );
10708             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10709                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
10710                 System.out.println( acc.toString() );
10711                 return false;
10712             }
10713         }
10714         catch ( final Exception e ) {
10715             return false;
10716         }
10717         return true;
10718     }
10719
10720     private static boolean testSequenceDbWsTools2() {
10721         try {
10722             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
10723             SequenceDbWsTools.obtainSeqInformation( n1 );
10724             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
10725                 return false;
10726             }
10727             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10728                 return false;
10729             }
10730             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10731                 return false;
10732             }
10733             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
10734                 return false;
10735             }
10736             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
10737             SequenceDbWsTools.obtainSeqInformation( n2 );
10738             if ( !n2.getNodeData().getSequence().getName()
10739                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
10740                 return false;
10741             }
10742             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10743                 return false;
10744             }
10745             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10746                 return false;
10747             }
10748             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
10749                 return false;
10750             }
10751             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
10752             SequenceDbWsTools.obtainSeqInformation( n3 );
10753             if ( !n3.getNodeData().getSequence().getName()
10754                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
10755                 return false;
10756             }
10757             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
10758                 return false;
10759             }
10760             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10761                 return false;
10762             }
10763             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
10764                 return false;
10765             }
10766         }
10767         catch ( final IOException e ) {
10768             System.out.println();
10769             System.out.println( "the following might be due to absence internet connection:" );
10770             e.printStackTrace( System.out );
10771             return true;
10772         }
10773         catch ( final Exception e ) {
10774             e.printStackTrace();
10775             return false;
10776         }
10777         return true;
10778     }
10779
10780     private static boolean testSequenceIdParsing() {
10781         try {
10782             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
10783             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10784                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10785                 if ( id != null ) {
10786                     System.out.println( "value   =" + id.getValue() );
10787                     System.out.println( "provider=" + id.getSource() );
10788                 }
10789                 return false;
10790             }
10791             //
10792             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
10793             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10794                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10795                 if ( id != null ) {
10796                     System.out.println( "value   =" + id.getValue() );
10797                     System.out.println( "provider=" + id.getSource() );
10798                 }
10799                 return false;
10800             }
10801             //
10802             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
10803             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10804                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10805                 if ( id != null ) {
10806                     System.out.println( "value   =" + id.getValue() );
10807                     System.out.println( "provider=" + id.getSource() );
10808                 }
10809                 return false;
10810             }
10811             // 
10812             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
10813             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10814                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
10815                 if ( id != null ) {
10816                     System.out.println( "value   =" + id.getValue() );
10817                     System.out.println( "provider=" + id.getSource() );
10818                 }
10819                 return false;
10820             }
10821             // 
10822             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
10823             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10824                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
10825                 if ( id != null ) {
10826                     System.out.println( "value   =" + id.getValue() );
10827                     System.out.println( "provider=" + id.getSource() );
10828                 }
10829                 return false;
10830             }
10831             // 
10832             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
10833             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10834                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
10835                 if ( id != null ) {
10836                     System.out.println( "value   =" + id.getValue() );
10837                     System.out.println( "provider=" + id.getSource() );
10838                 }
10839                 return false;
10840             }
10841             // 
10842             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
10843             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10844                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
10845                 if ( id != null ) {
10846                     System.out.println( "value   =" + id.getValue() );
10847                     System.out.println( "provider=" + id.getSource() );
10848                 }
10849                 return false;
10850             }
10851             // 
10852             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
10853             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10854                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
10855                 if ( id != null ) {
10856                     System.out.println( "value   =" + id.getValue() );
10857                     System.out.println( "provider=" + id.getSource() );
10858                 }
10859                 return false;
10860             }
10861             // 
10862             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
10863             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10864                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
10865                 if ( id != null ) {
10866                     System.out.println( "value   =" + id.getValue() );
10867                     System.out.println( "provider=" + id.getSource() );
10868                 }
10869                 return false;
10870             }
10871             // 
10872             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
10873             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10874                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
10875                 if ( id != null ) {
10876                     System.out.println( "value   =" + id.getValue() );
10877                     System.out.println( "provider=" + id.getSource() );
10878                 }
10879                 return false;
10880             }
10881             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
10882             if ( id != null ) {
10883                 System.out.println( "value   =" + id.getValue() );
10884                 System.out.println( "provider=" + id.getSource() );
10885                 return false;
10886             }
10887         }
10888         catch ( final Exception e ) {
10889             e.printStackTrace( System.out );
10890             return false;
10891         }
10892         return true;
10893     }
10894
10895     private static boolean testSequenceWriter() {
10896         try {
10897             final String n = ForesterUtil.LINE_SEPARATOR;
10898             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
10899                 return false;
10900             }
10901             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
10902                 return false;
10903             }
10904             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
10905                 return false;
10906             }
10907             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
10908                 return false;
10909             }
10910             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
10911                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
10912                 return false;
10913             }
10914             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
10915                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
10916                 return false;
10917             }
10918         }
10919         catch ( final Exception e ) {
10920             e.printStackTrace();
10921             return false;
10922         }
10923         return true;
10924     }
10925
10926     private static boolean testSpecies() {
10927         try {
10928             final Species s1 = new BasicSpecies( "a" );
10929             final Species s2 = new BasicSpecies( "a" );
10930             final Species s3 = new BasicSpecies( "A" );
10931             final Species s4 = new BasicSpecies( "b" );
10932             if ( !s1.equals( s1 ) ) {
10933                 return false;
10934             }
10935             if ( s1.getSpeciesId().equals( "x" ) ) {
10936                 return false;
10937             }
10938             if ( s1.getSpeciesId().equals( null ) ) {
10939                 return false;
10940             }
10941             if ( !s1.equals( s2 ) ) {
10942                 return false;
10943             }
10944             if ( s1.equals( s3 ) ) {
10945                 return false;
10946             }
10947             if ( s1.hashCode() != s1.hashCode() ) {
10948                 return false;
10949             }
10950             if ( s1.hashCode() != s2.hashCode() ) {
10951                 return false;
10952             }
10953             if ( s1.hashCode() == s3.hashCode() ) {
10954                 return false;
10955             }
10956             if ( s1.compareTo( s1 ) != 0 ) {
10957                 return false;
10958             }
10959             if ( s1.compareTo( s2 ) != 0 ) {
10960                 return false;
10961             }
10962             if ( s1.compareTo( s3 ) != 0 ) {
10963                 return false;
10964             }
10965             if ( s1.compareTo( s4 ) >= 0 ) {
10966                 return false;
10967             }
10968             if ( s4.compareTo( s1 ) <= 0 ) {
10969                 return false;
10970             }
10971             if ( !s4.getSpeciesId().equals( "b" ) ) {
10972                 return false;
10973             }
10974             final Species s5 = new BasicSpecies( " C " );
10975             if ( !s5.getSpeciesId().equals( "C" ) ) {
10976                 return false;
10977             }
10978             if ( s5.equals( s1 ) ) {
10979                 return false;
10980             }
10981         }
10982         catch ( final Exception e ) {
10983             e.printStackTrace( System.out );
10984             return false;
10985         }
10986         return true;
10987     }
10988
10989     private static boolean testSplit() {
10990         try {
10991             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10992             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10993             //Archaeopteryx.createApplication( p0 );
10994             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10995             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10996             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10997             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10998             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10999             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11000             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11001             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11002             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11003             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11004             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11005             // System.out.println( s0.toString() );
11006             //
11007             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11008             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11009             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11010             if ( s0.match( query_nodes ) ) {
11011                 return false;
11012             }
11013             query_nodes = new HashSet<PhylogenyNode>();
11014             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11015             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11016             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11017             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11018             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11019             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11020             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11021             if ( !s0.match( query_nodes ) ) {
11022                 return false;
11023             }
11024             //
11025             query_nodes = new HashSet<PhylogenyNode>();
11026             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11027             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11028             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11029             if ( !s0.match( query_nodes ) ) {
11030                 return false;
11031             }
11032             //
11033             query_nodes = new HashSet<PhylogenyNode>();
11034             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11035             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11036             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11037             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11038             if ( !s0.match( query_nodes ) ) {
11039                 return false;
11040             }
11041             //
11042             query_nodes = new HashSet<PhylogenyNode>();
11043             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11044             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11045             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11046             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11047             if ( !s0.match( query_nodes ) ) {
11048                 return false;
11049             }
11050             //
11051             query_nodes = new HashSet<PhylogenyNode>();
11052             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11053             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11054             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11055             if ( !s0.match( query_nodes ) ) {
11056                 return false;
11057             }
11058             //
11059             query_nodes = new HashSet<PhylogenyNode>();
11060             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11061             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11062             if ( !s0.match( query_nodes ) ) {
11063                 return false;
11064             }
11065             //
11066             query_nodes = new HashSet<PhylogenyNode>();
11067             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11068             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11069             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11070             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11071             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11072             if ( !s0.match( query_nodes ) ) {
11073                 return false;
11074             }
11075             //
11076             query_nodes = new HashSet<PhylogenyNode>();
11077             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11078             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11079             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11080             if ( !s0.match( query_nodes ) ) {
11081                 return false;
11082             }
11083             //
11084             query_nodes = new HashSet<PhylogenyNode>();
11085             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11086             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11087             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11088             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11089             if ( !s0.match( query_nodes ) ) {
11090                 return false;
11091             }
11092             //
11093             query_nodes = new HashSet<PhylogenyNode>();
11094             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11095             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11096             if ( s0.match( query_nodes ) ) {
11097                 return false;
11098             }
11099             //
11100             query_nodes = new HashSet<PhylogenyNode>();
11101             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11102             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11103             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11104             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11105             if ( s0.match( query_nodes ) ) {
11106                 return false;
11107             }
11108             //
11109             query_nodes = new HashSet<PhylogenyNode>();
11110             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11111             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11112             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11113             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11114             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11115             if ( s0.match( query_nodes ) ) {
11116                 return false;
11117             }
11118             //
11119             query_nodes = new HashSet<PhylogenyNode>();
11120             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11121             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11122             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11123             if ( s0.match( query_nodes ) ) {
11124                 return false;
11125             }
11126             //
11127             query_nodes = new HashSet<PhylogenyNode>();
11128             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11129             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11130             if ( s0.match( query_nodes ) ) {
11131                 return false;
11132             }
11133             //
11134             query_nodes = new HashSet<PhylogenyNode>();
11135             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11136             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11137             if ( s0.match( query_nodes ) ) {
11138                 return false;
11139             }
11140             //
11141             query_nodes = new HashSet<PhylogenyNode>();
11142             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11143             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11144             if ( s0.match( query_nodes ) ) {
11145                 return false;
11146             }
11147             //
11148             query_nodes = new HashSet<PhylogenyNode>();
11149             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11150             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11151             if ( s0.match( query_nodes ) ) {
11152                 return false;
11153             }
11154             //
11155             query_nodes = new HashSet<PhylogenyNode>();
11156             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11157             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11158             if ( s0.match( query_nodes ) ) {
11159                 return false;
11160             }
11161             //
11162             query_nodes = new HashSet<PhylogenyNode>();
11163             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11164             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11165             if ( s0.match( query_nodes ) ) {
11166                 return false;
11167             }
11168             //
11169             query_nodes = new HashSet<PhylogenyNode>();
11170             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11171             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11172             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11173             if ( s0.match( query_nodes ) ) {
11174                 return false;
11175             }
11176             //
11177             query_nodes = new HashSet<PhylogenyNode>();
11178             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11179             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11180             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11181             if ( s0.match( query_nodes ) ) {
11182                 return false;
11183             }
11184             //
11185             query_nodes = new HashSet<PhylogenyNode>();
11186             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11187             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11188             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11189             if ( s0.match( query_nodes ) ) {
11190                 return false;
11191             }
11192             //
11193             query_nodes = new HashSet<PhylogenyNode>();
11194             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11195             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11196             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11197             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11198             if ( s0.match( query_nodes ) ) {
11199                 return false;
11200             }
11201             /////////
11202             //            query_nodes = new HashSet<PhylogenyNode>();
11203             //            query_nodes.add( new PhylogenyNode( "X" ) );
11204             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11205             //            query_nodes.add( new PhylogenyNode( "A" ) );
11206             //            query_nodes.add( new PhylogenyNode( "B" ) );
11207             //            query_nodes.add( new PhylogenyNode( "C" ) );
11208             //            query_nodes.add( new PhylogenyNode( "D" ) );
11209             //            query_nodes.add( new PhylogenyNode( "E" ) );
11210             //            query_nodes.add( new PhylogenyNode( "F" ) );
11211             //            query_nodes.add( new PhylogenyNode( "G" ) );
11212             //            if ( !s0.match( query_nodes ) ) {
11213             //                return false;
11214             //            }
11215             //            query_nodes = new HashSet<PhylogenyNode>();
11216             //            query_nodes.add( new PhylogenyNode( "X" ) );
11217             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11218             //            query_nodes.add( new PhylogenyNode( "A" ) );
11219             //            query_nodes.add( new PhylogenyNode( "B" ) );
11220             //            query_nodes.add( new PhylogenyNode( "C" ) );
11221             //            if ( !s0.match( query_nodes ) ) {
11222             //                return false;
11223             //            }
11224             //            //
11225             //            query_nodes = new HashSet<PhylogenyNode>();
11226             //            query_nodes.add( new PhylogenyNode( "X" ) );
11227             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11228             //            query_nodes.add( new PhylogenyNode( "D" ) );
11229             //            query_nodes.add( new PhylogenyNode( "E" ) );
11230             //            query_nodes.add( new PhylogenyNode( "F" ) );
11231             //            query_nodes.add( new PhylogenyNode( "G" ) );
11232             //            if ( !s0.match( query_nodes ) ) {
11233             //                return false;
11234             //            }
11235             //            //
11236             //            query_nodes = new HashSet<PhylogenyNode>();
11237             //            query_nodes.add( new PhylogenyNode( "X" ) );
11238             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11239             //            query_nodes.add( new PhylogenyNode( "A" ) );
11240             //            query_nodes.add( new PhylogenyNode( "B" ) );
11241             //            query_nodes.add( new PhylogenyNode( "C" ) );
11242             //            query_nodes.add( new PhylogenyNode( "D" ) );
11243             //            if ( !s0.match( query_nodes ) ) {
11244             //                return false;
11245             //            }
11246             //            //
11247             //            query_nodes = new HashSet<PhylogenyNode>();
11248             //            query_nodes.add( new PhylogenyNode( "X" ) );
11249             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11250             //            query_nodes.add( new PhylogenyNode( "E" ) );
11251             //            query_nodes.add( new PhylogenyNode( "F" ) );
11252             //            query_nodes.add( new PhylogenyNode( "G" ) );
11253             //            if ( !s0.match( query_nodes ) ) {
11254             //                return false;
11255             //            }
11256             //            //
11257             //            query_nodes = new HashSet<PhylogenyNode>();
11258             //            query_nodes.add( new PhylogenyNode( "X" ) );
11259             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11260             //            query_nodes.add( new PhylogenyNode( "F" ) );
11261             //            query_nodes.add( new PhylogenyNode( "G" ) );
11262             //            if ( !s0.match( query_nodes ) ) {
11263             //                return false;
11264             //            }
11265             //
11266             query_nodes = new HashSet<PhylogenyNode>();
11267             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11268             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11269             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11270             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11271             if ( s0.match( query_nodes ) ) {
11272                 return false;
11273             }
11274             //
11275             query_nodes = new HashSet<PhylogenyNode>();
11276             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11277             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11278             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11279             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11280             if ( s0.match( query_nodes ) ) {
11281                 return false;
11282             }
11283             ///////////////////////////
11284             //
11285             query_nodes = new HashSet<PhylogenyNode>();
11286             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11287             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11288             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11289             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11290             if ( s0.match( query_nodes ) ) {
11291                 return false;
11292             }
11293             //
11294             query_nodes = new HashSet<PhylogenyNode>();
11295             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11296             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11297             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11298             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11299             if ( s0.match( query_nodes ) ) {
11300                 return false;
11301             }
11302             //
11303             query_nodes = new HashSet<PhylogenyNode>();
11304             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11305             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11306             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11307             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11308             if ( s0.match( query_nodes ) ) {
11309                 return false;
11310             }
11311             //
11312             query_nodes = new HashSet<PhylogenyNode>();
11313             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11314             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11315             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11316             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11317             if ( s0.match( query_nodes ) ) {
11318                 return false;
11319             }
11320             //
11321             query_nodes = new HashSet<PhylogenyNode>();
11322             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11323             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11324             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11325             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11326             if ( s0.match( query_nodes ) ) {
11327                 return false;
11328             }
11329             //
11330             query_nodes = new HashSet<PhylogenyNode>();
11331             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11332             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11333             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11334             if ( s0.match( query_nodes ) ) {
11335                 return false;
11336             }
11337             //
11338             query_nodes = new HashSet<PhylogenyNode>();
11339             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11340             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11341             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11342             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11343             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11344             if ( s0.match( query_nodes ) ) {
11345                 return false;
11346             }
11347             //
11348             query_nodes = new HashSet<PhylogenyNode>();
11349             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11350             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11351             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11352             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11353             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11354             if ( s0.match( query_nodes ) ) {
11355                 return false;
11356             }
11357             //
11358             query_nodes = new HashSet<PhylogenyNode>();
11359             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11360             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11361             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11362             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11363             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11364             if ( s0.match( query_nodes ) ) {
11365                 return false;
11366             }
11367             //
11368             query_nodes = new HashSet<PhylogenyNode>();
11369             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11370             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11371             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11372             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11373             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11374             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11375             if ( s0.match( query_nodes ) ) {
11376                 return false;
11377             }
11378         }
11379         catch ( final Exception e ) {
11380             e.printStackTrace();
11381             return false;
11382         }
11383         return true;
11384     }
11385
11386     private static boolean testSplitStrict() {
11387         try {
11388             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11389             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11390             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11391             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11392             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11393             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11394             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11395             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11396             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11397             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11398             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11399             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11400             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11401             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11402             if ( s0.match( query_nodes ) ) {
11403                 return false;
11404             }
11405             query_nodes = new HashSet<PhylogenyNode>();
11406             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11407             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11408             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11409             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11410             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11411             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11412             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11413             if ( !s0.match( query_nodes ) ) {
11414                 return false;
11415             }
11416             //
11417             query_nodes = new HashSet<PhylogenyNode>();
11418             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11419             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11420             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11421             if ( !s0.match( query_nodes ) ) {
11422                 return false;
11423             }
11424             //
11425             query_nodes = new HashSet<PhylogenyNode>();
11426             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11427             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11428             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11429             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11430             if ( !s0.match( query_nodes ) ) {
11431                 return false;
11432             }
11433             //
11434             query_nodes = new HashSet<PhylogenyNode>();
11435             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11436             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11437             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11438             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11439             if ( !s0.match( query_nodes ) ) {
11440                 return false;
11441             }
11442             //
11443             query_nodes = new HashSet<PhylogenyNode>();
11444             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11445             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11446             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11447             if ( !s0.match( query_nodes ) ) {
11448                 return false;
11449             }
11450             //
11451             query_nodes = new HashSet<PhylogenyNode>();
11452             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11453             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11454             if ( !s0.match( query_nodes ) ) {
11455                 return false;
11456             }
11457             //
11458             query_nodes = new HashSet<PhylogenyNode>();
11459             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11460             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11461             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11462             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11463             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11464             if ( !s0.match( query_nodes ) ) {
11465                 return false;
11466             }
11467             //
11468             query_nodes = new HashSet<PhylogenyNode>();
11469             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11470             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11471             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11472             if ( !s0.match( query_nodes ) ) {
11473                 return false;
11474             }
11475             //
11476             query_nodes = new HashSet<PhylogenyNode>();
11477             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11478             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11479             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11480             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11481             if ( !s0.match( query_nodes ) ) {
11482                 return false;
11483             }
11484             //
11485             query_nodes = new HashSet<PhylogenyNode>();
11486             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11487             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11488             if ( s0.match( query_nodes ) ) {
11489                 return false;
11490             }
11491             //
11492             query_nodes = new HashSet<PhylogenyNode>();
11493             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11494             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11495             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11496             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11497             if ( s0.match( query_nodes ) ) {
11498                 return false;
11499             }
11500             //
11501             query_nodes = new HashSet<PhylogenyNode>();
11502             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11503             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11504             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11505             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11506             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11507             if ( s0.match( query_nodes ) ) {
11508                 return false;
11509             }
11510             //
11511             query_nodes = new HashSet<PhylogenyNode>();
11512             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11513             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11514             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11515             if ( s0.match( query_nodes ) ) {
11516                 return false;
11517             }
11518             //
11519             query_nodes = new HashSet<PhylogenyNode>();
11520             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11521             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11522             if ( s0.match( query_nodes ) ) {
11523                 return false;
11524             }
11525             //
11526             query_nodes = new HashSet<PhylogenyNode>();
11527             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11528             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11529             if ( s0.match( query_nodes ) ) {
11530                 return false;
11531             }
11532             //
11533             query_nodes = new HashSet<PhylogenyNode>();
11534             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11535             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11536             if ( s0.match( query_nodes ) ) {
11537                 return false;
11538             }
11539             //
11540             query_nodes = new HashSet<PhylogenyNode>();
11541             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11542             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11543             if ( s0.match( query_nodes ) ) {
11544                 return false;
11545             }
11546             //
11547             query_nodes = new HashSet<PhylogenyNode>();
11548             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11549             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11550             if ( s0.match( query_nodes ) ) {
11551                 return false;
11552             }
11553             //
11554             query_nodes = new HashSet<PhylogenyNode>();
11555             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11556             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11557             if ( s0.match( query_nodes ) ) {
11558                 return false;
11559             }
11560             //
11561             query_nodes = new HashSet<PhylogenyNode>();
11562             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11563             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11564             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11565             if ( s0.match( query_nodes ) ) {
11566                 return false;
11567             }
11568             //
11569             query_nodes = new HashSet<PhylogenyNode>();
11570             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11571             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11572             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11573             if ( s0.match( query_nodes ) ) {
11574                 return false;
11575             }
11576             //
11577             query_nodes = new HashSet<PhylogenyNode>();
11578             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11579             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11580             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11581             if ( s0.match( query_nodes ) ) {
11582                 return false;
11583             }
11584             //
11585             query_nodes = new HashSet<PhylogenyNode>();
11586             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11587             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11589             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11590             if ( s0.match( query_nodes ) ) {
11591                 return false;
11592             }
11593         }
11594         catch ( final Exception e ) {
11595             e.printStackTrace();
11596             return false;
11597         }
11598         return true;
11599     }
11600
11601     private static boolean testSubtreeDeletion() {
11602         try {
11603             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11604             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11605             t1.deleteSubtree( t1.getNode( "A" ), false );
11606             if ( t1.getNumberOfExternalNodes() != 5 ) {
11607                 return false;
11608             }
11609             t1.toNewHampshireX();
11610             t1.deleteSubtree( t1.getNode( "E" ), false );
11611             if ( t1.getNumberOfExternalNodes() != 4 ) {
11612                 return false;
11613             }
11614             t1.toNewHampshireX();
11615             t1.deleteSubtree( t1.getNode( "F" ), false );
11616             if ( t1.getNumberOfExternalNodes() != 3 ) {
11617                 return false;
11618             }
11619             t1.toNewHampshireX();
11620             t1.deleteSubtree( t1.getNode( "D" ), false );
11621             t1.toNewHampshireX();
11622             if ( t1.getNumberOfExternalNodes() != 3 ) {
11623                 return false;
11624             }
11625             t1.deleteSubtree( t1.getNode( "def" ), false );
11626             t1.toNewHampshireX();
11627             if ( t1.getNumberOfExternalNodes() != 2 ) {
11628                 return false;
11629             }
11630             t1.deleteSubtree( t1.getNode( "B" ), false );
11631             t1.toNewHampshireX();
11632             if ( t1.getNumberOfExternalNodes() != 1 ) {
11633                 return false;
11634             }
11635             t1.deleteSubtree( t1.getNode( "C" ), false );
11636             t1.toNewHampshireX();
11637             if ( t1.getNumberOfExternalNodes() != 1 ) {
11638                 return false;
11639             }
11640             t1.deleteSubtree( t1.getNode( "abc" ), false );
11641             t1.toNewHampshireX();
11642             if ( t1.getNumberOfExternalNodes() != 1 ) {
11643                 return false;
11644             }
11645             t1.deleteSubtree( t1.getNode( "r" ), false );
11646             if ( t1.getNumberOfExternalNodes() != 0 ) {
11647                 return false;
11648             }
11649             if ( !t1.isEmpty() ) {
11650                 return false;
11651             }
11652             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11653             t2.deleteSubtree( t2.getNode( "A" ), false );
11654             t2.toNewHampshireX();
11655             if ( t2.getNumberOfExternalNodes() != 5 ) {
11656                 return false;
11657             }
11658             t2.deleteSubtree( t2.getNode( "abc" ), false );
11659             t2.toNewHampshireX();
11660             if ( t2.getNumberOfExternalNodes() != 3 ) {
11661                 return false;
11662             }
11663             t2.deleteSubtree( t2.getNode( "def" ), false );
11664             t2.toNewHampshireX();
11665             if ( t2.getNumberOfExternalNodes() != 1 ) {
11666                 return false;
11667             }
11668         }
11669         catch ( final Exception e ) {
11670             e.printStackTrace( System.out );
11671             return false;
11672         }
11673         return true;
11674     }
11675
11676     private static boolean testSupportCount() {
11677         try {
11678             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11679             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
11680             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
11681                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
11682                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
11683                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
11684                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
11685                                                               new NHXParser() );
11686             SupportCount.count( t0_1, phylogenies_1, true, false );
11687             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
11688             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
11689                                                                       + "(((((A,B),C),D),E),((F,G),X))"
11690                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
11691                                                                       + "(((((A,B),C),D),E),(F,G))"
11692                                                                       + "(((((A,B),C),D),E),(F,G))"
11693                                                                       + "(((((A,B),C),D),E),(F,G))"
11694                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
11695                                                                       + "(((((A,B),C),D),E),(F,G))"
11696                                                                       + "((((((A,B),C),D),E),F),G)"
11697                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
11698                                                               new NHXParser() );
11699             SupportCount.count( t0_2, phylogenies_2, true, false );
11700             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
11701             while ( it.hasNext() ) {
11702                 final PhylogenyNode n = it.next();
11703                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
11704                     return false;
11705                 }
11706             }
11707             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
11708             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
11709                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
11710             SupportCount.count( t0_3, phylogenies_3, true, false );
11711             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
11712             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
11713                 return false;
11714             }
11715             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
11716                 return false;
11717             }
11718             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
11719                 return false;
11720             }
11721             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
11722                 return false;
11723             }
11724             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
11725                 return false;
11726             }
11727             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
11728                 return false;
11729             }
11730             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
11731                 return false;
11732             }
11733             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
11734                 return false;
11735             }
11736             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
11737                 return false;
11738             }
11739             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
11740                 return false;
11741             }
11742             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11743             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
11744                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
11745             SupportCount.count( t0_4, phylogenies_4, true, false );
11746             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
11747             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
11748                 return false;
11749             }
11750             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
11751                 return false;
11752             }
11753             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
11754                 return false;
11755             }
11756             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
11757                 return false;
11758             }
11759             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
11760                 return false;
11761             }
11762             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
11763                 return false;
11764             }
11765             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
11766                 return false;
11767             }
11768             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
11769                 return false;
11770             }
11771             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
11772                 return false;
11773             }
11774             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
11775                 return false;
11776             }
11777             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11778             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11779             double d = SupportCount.compare( b1, a, true, true, true );
11780             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
11781                 return false;
11782             }
11783             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11784             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11785             d = SupportCount.compare( b2, a, true, true, true );
11786             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
11787                 return false;
11788             }
11789             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11790             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
11791             d = SupportCount.compare( b3, a, true, true, true );
11792             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
11793                 return false;
11794             }
11795             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
11796             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
11797             d = SupportCount.compare( b4, a, true, true, false );
11798             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
11799                 return false;
11800             }
11801         }
11802         catch ( final Exception e ) {
11803             e.printStackTrace( System.out );
11804             return false;
11805         }
11806         return true;
11807     }
11808
11809     private static boolean testSupportTransfer() {
11810         try {
11811             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11812             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)",
11813                                                  new NHXParser() )[ 0 ];
11814             final Phylogeny p2 = factory
11815                     .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 ];
11816             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
11817                 return false;
11818             }
11819             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
11820                 return false;
11821             }
11822             support_transfer.moveBranchLengthsToBootstrap( p1 );
11823             support_transfer.transferSupportValues( p1, p2 );
11824             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
11825                 return false;
11826             }
11827             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
11828                 return false;
11829             }
11830             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
11831                 return false;
11832             }
11833             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
11834                 return false;
11835             }
11836             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
11837                 return false;
11838             }
11839             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
11840                 return false;
11841             }
11842             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
11843                 return false;
11844             }
11845             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
11846                 return false;
11847             }
11848         }
11849         catch ( final Exception e ) {
11850             e.printStackTrace( System.out );
11851             return false;
11852         }
11853         return true;
11854     }
11855
11856     private static boolean testTaxonomyExtraction() {
11857         try {
11858             final PhylogenyNode n0 = PhylogenyNode
11859                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11860             if ( n0.getNodeData().isHasTaxonomy() ) {
11861                 return false;
11862             }
11863             final PhylogenyNode n1 = PhylogenyNode
11864                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11865             if ( n1.getNodeData().isHasTaxonomy() ) {
11866                 System.out.println( n1.toString() );
11867                 return false;
11868             }
11869             final PhylogenyNode n2x = PhylogenyNode
11870                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11871             if ( n2x.getNodeData().isHasTaxonomy() ) {
11872                 return false;
11873             }
11874             final PhylogenyNode n3 = PhylogenyNode
11875                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11876             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11877                 System.out.println( n3.toString() );
11878                 return false;
11879             }
11880             final PhylogenyNode n4 = PhylogenyNode
11881                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11882             if ( n4.getNodeData().isHasTaxonomy() ) {
11883                 System.out.println( n4.toString() );
11884                 return false;
11885             }
11886             final PhylogenyNode n5 = PhylogenyNode
11887                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11888             if ( n5.getNodeData().isHasTaxonomy() ) {
11889                 System.out.println( n5.toString() );
11890                 return false;
11891             }
11892             final PhylogenyNode n6 = PhylogenyNode
11893                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11894             if ( n6.getNodeData().isHasTaxonomy() ) {
11895                 System.out.println( n6.toString() );
11896                 return false;
11897             }
11898             final PhylogenyNode n7 = PhylogenyNode
11899                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11900             if ( n7.getNodeData().isHasTaxonomy() ) {
11901                 System.out.println( n7.toString() );
11902                 return false;
11903             }
11904             final PhylogenyNode n8 = PhylogenyNode
11905                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11906             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11907                 System.out.println( n8.toString() );
11908                 return false;
11909             }
11910             final PhylogenyNode n9 = PhylogenyNode
11911                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11912             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11913                 System.out.println( n9.toString() );
11914                 return false;
11915             }
11916             final PhylogenyNode n10x = PhylogenyNode
11917                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11918             if ( n10x.getNodeData().isHasTaxonomy() ) {
11919                 System.out.println( n10x.toString() );
11920                 return false;
11921             }
11922             final PhylogenyNode n10xx = PhylogenyNode
11923                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11924             if ( n10xx.getNodeData().isHasTaxonomy() ) {
11925                 System.out.println( n10xx.toString() );
11926                 return false;
11927             }
11928             final PhylogenyNode n10 = PhylogenyNode
11929                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11930             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
11931                 System.out.println( n10.toString() );
11932                 return false;
11933             }
11934             final PhylogenyNode n11 = PhylogenyNode
11935                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11936             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
11937                 System.out.println( n11.toString() );
11938                 return false;
11939             }
11940             final PhylogenyNode n12 = PhylogenyNode
11941                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
11942                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11943             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
11944                 System.out.println( n12.toString() );
11945                 return false;
11946             }
11947             final PhylogenyNode n13 = PhylogenyNode
11948                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11949             if ( n13.getNodeData().isHasTaxonomy() ) {
11950                 System.out.println( n13.toString() );
11951                 return false;
11952             }
11953             final PhylogenyNode n14 = PhylogenyNode
11954                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11955             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
11956                 System.out.println( n14.toString() );
11957                 return false;
11958             }
11959             final PhylogenyNode n15 = PhylogenyNode
11960                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11961             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
11962                 System.out.println( n15.toString() );
11963                 return false;
11964             }
11965             final PhylogenyNode n16 = PhylogenyNode
11966                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11967             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
11968                 System.out.println( n16.toString() );
11969                 return false;
11970             }
11971             final PhylogenyNode n17 = PhylogenyNode
11972                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11973             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
11974                 System.out.println( n17.toString() );
11975                 return false;
11976             }
11977             //
11978             final PhylogenyNode n18 = PhylogenyNode
11979                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11980             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
11981                 System.out.println( n18.toString() );
11982                 return false;
11983             }
11984             final PhylogenyNode n19 = PhylogenyNode
11985                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
11986                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11987             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
11988                 System.out.println( n19.toString() );
11989                 return false;
11990             }
11991             final PhylogenyNode n20 = PhylogenyNode
11992                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11993             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
11994                 System.out.println( n20.toString() );
11995                 return false;
11996             }
11997             final PhylogenyNode n21 = PhylogenyNode
11998                     .createInstanceFromNhxString( "Mus musculus musculus K392",
11999                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12000             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12001                 System.out.println( n21.toString() );
12002                 return false;
12003             }
12004         }
12005         catch ( final Exception e ) {
12006             e.printStackTrace( System.out );
12007             return false;
12008         }
12009         return true;
12010     }
12011
12012     private static boolean testTreeCopy() {
12013         try {
12014             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12015             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12016             final Phylogeny t1 = t0.copy();
12017             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12018                 return false;
12019             }
12020             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12021                 return false;
12022             }
12023             t0.deleteSubtree( t0.getNode( "c" ), true );
12024             t0.deleteSubtree( t0.getNode( "a" ), true );
12025             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12026             t0.getNode( "b" ).setName( "Bee" );
12027             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12028                 return false;
12029             }
12030             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12031                 return false;
12032             }
12033             t0.deleteSubtree( t0.getNode( "e" ), true );
12034             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12035             t0.deleteSubtree( t0.getNode( "d" ), true );
12036             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12037                 return false;
12038             }
12039         }
12040         catch ( final Exception e ) {
12041             e.printStackTrace();
12042             return false;
12043         }
12044         return true;
12045     }
12046
12047     private static boolean testTreeMethods() {
12048         try {
12049             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12050             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12051             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12052             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12053                 System.out.println( t0.toNewHampshireX() );
12054                 return false;
12055             }
12056             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12057             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12058             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12059                 return false;
12060             }
12061             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12062                 return false;
12063             }
12064             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12065                 return false;
12066             }
12067         }
12068         catch ( final Exception e ) {
12069             e.printStackTrace( System.out );
12070             return false;
12071         }
12072         return true;
12073     }
12074
12075     private static boolean testUniprotEntryRetrieval() {
12076         try {
12077             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
12078             if ( !entry.getAccession().equals( "P12345" ) ) {
12079                 return false;
12080             }
12081             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12082                 return false;
12083             }
12084             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12085                 return false;
12086             }
12087             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12088                 return false;
12089             }
12090             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12091                 return false;
12092             }
12093             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12094                 return false;
12095             }
12096         }
12097         catch ( final IOException e ) {
12098             System.out.println();
12099             System.out.println( "the following might be due to absence internet connection:" );
12100             e.printStackTrace( System.out );
12101             return true;
12102         }
12103         catch ( final Exception e ) {
12104             return false;
12105         }
12106         return true;
12107     }
12108
12109     private static boolean testUniprotTaxonomySearch() {
12110         try {
12111             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12112                                                                                                  10 );
12113             if ( results.size() != 1 ) {
12114                 return false;
12115             }
12116             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12117                 return false;
12118             }
12119             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12120                 return false;
12121             }
12122             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12123                 return false;
12124             }
12125             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12126                 return false;
12127             }
12128             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12129                 return false;
12130             }
12131             results = null;
12132             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12133             if ( results.size() != 1 ) {
12134                 return false;
12135             }
12136             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12137                 return false;
12138             }
12139             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12140                 return false;
12141             }
12142             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12143                 return false;
12144             }
12145             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12146                 return false;
12147             }
12148             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12149                 return false;
12150             }
12151             results = null;
12152             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12153             if ( results.size() != 1 ) {
12154                 return false;
12155             }
12156             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12157                 return false;
12158             }
12159             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12160                 return false;
12161             }
12162             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12163                 return false;
12164             }
12165             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12166                 return false;
12167             }
12168             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12169                 return false;
12170             }
12171             results = null;
12172             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12173             if ( results.size() != 1 ) {
12174                 return false;
12175             }
12176             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12177                 return false;
12178             }
12179             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12180                 return false;
12181             }
12182             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12183                 return false;
12184             }
12185             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12186                 return false;
12187             }
12188             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12189                 return false;
12190             }
12191             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12192                 return false;
12193             }
12194             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12195                 return false;
12196             }
12197             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12198                     .equals( "Nematostella vectensis" ) ) {
12199                 System.out.println( results.get( 0 ).getLineage() );
12200                 return false;
12201             }
12202             //
12203             results = null;
12204             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12205             if ( results.size() != 1 ) {
12206                 return false;
12207             }
12208             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12209                 return false;
12210             }
12211             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12212                 return false;
12213             }
12214             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12215                 return false;
12216             }
12217             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12218                 return false;
12219             }
12220             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12221                 return false;
12222             }
12223             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12224                     .equals( "Xenopus tropicalis" ) ) {
12225                 System.out.println( results.get( 0 ).getLineage() );
12226                 return false;
12227             }
12228             //
12229             results = null;
12230             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12231             if ( results.size() != 1 ) {
12232                 return false;
12233             }
12234             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12235                 return false;
12236             }
12237             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12238                 return false;
12239             }
12240             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12241                 return false;
12242             }
12243             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12244                 return false;
12245             }
12246             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12247                 return false;
12248             }
12249             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12250                     .equals( "Xenopus tropicalis" ) ) {
12251                 System.out.println( results.get( 0 ).getLineage() );
12252                 return false;
12253             }
12254             //
12255             results = null;
12256             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12257             if ( results.size() != 1 ) {
12258                 return false;
12259             }
12260             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12261                 return false;
12262             }
12263             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12264                 return false;
12265             }
12266             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12267                 return false;
12268             }
12269             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12270                 return false;
12271             }
12272             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12273                 return false;
12274             }
12275             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12276                     .equals( "Xenopus tropicalis" ) ) {
12277                 System.out.println( results.get( 0 ).getLineage() );
12278                 return false;
12279             }
12280         }
12281         catch ( final IOException e ) {
12282             System.out.println();
12283             System.out.println( "the following might be due to absence internet connection:" );
12284             e.printStackTrace( System.out );
12285             return true;
12286         }
12287         catch ( final Exception e ) {
12288             return false;
12289         }
12290         return true;
12291     }
12292
12293     private static boolean testWabiTxSearch() {
12294         try {
12295             String result = "";
12296             result = TxSearch.searchSimple( "nematostella" );
12297             result = TxSearch.getTxId( "nematostella" );
12298             if ( !result.equals( "45350" ) ) {
12299                 return false;
12300             }
12301             result = TxSearch.getTxName( "45350" );
12302             if ( !result.equals( "Nematostella" ) ) {
12303                 return false;
12304             }
12305             result = TxSearch.getTxId( "nematostella vectensis" );
12306             if ( !result.equals( "45351" ) ) {
12307                 return false;
12308             }
12309             result = TxSearch.getTxName( "45351" );
12310             if ( !result.equals( "Nematostella vectensis" ) ) {
12311                 return false;
12312             }
12313             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
12314             if ( !result.equals( "536089" ) ) {
12315                 return false;
12316             }
12317             result = TxSearch.getTxName( "536089" );
12318             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
12319                 return false;
12320             }
12321             final List<String> queries = new ArrayList<String>();
12322             queries.add( "Campylobacter coli" );
12323             queries.add( "Escherichia coli" );
12324             queries.add( "Arabidopsis" );
12325             queries.add( "Trichoplax" );
12326             queries.add( "Samanea saman" );
12327             queries.add( "Kluyveromyces marxianus" );
12328             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
12329             queries.add( "Bornavirus parrot/PDD/2008" );
12330             final List<RANKS> ranks = new ArrayList<RANKS>();
12331             ranks.add( RANKS.SUPERKINGDOM );
12332             ranks.add( RANKS.KINGDOM );
12333             ranks.add( RANKS.FAMILY );
12334             ranks.add( RANKS.GENUS );
12335             ranks.add( RANKS.TRIBE );
12336             result = TxSearch.searchLineage( queries, ranks );
12337             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12338             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12339         }
12340         catch ( final Exception e ) {
12341             System.out.println();
12342             System.out.println( "the following might be due to absence internet connection:" );
12343             e.printStackTrace( System.out );
12344             return false;
12345         }
12346         return true;
12347     }
12348 }