4023539191e9fcc887943626d45ff469245db609
[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.development.DevelopmentTools;
45 import org.forester.evoinference.TestPhylogenyReconstruction;
46 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
47 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
48 import org.forester.go.TestGo;
49 import org.forester.io.parsers.FastaParser;
50 import org.forester.io.parsers.GeneralMsaParser;
51 import org.forester.io.parsers.HmmscanPerDomainTableParser;
52 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
53 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
54 import org.forester.io.parsers.nexus.NexusCharactersParser;
55 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
56 import org.forester.io.parsers.nhx.NHXParser;
57 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
58 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
59 import org.forester.io.parsers.tol.TolParser;
60 import org.forester.io.parsers.util.ParserUtils;
61 import org.forester.io.writers.PhylogenyWriter;
62 import org.forester.io.writers.SequenceWriter;
63 import org.forester.msa.BasicMsa;
64 import org.forester.msa.Mafft;
65 import org.forester.msa.Msa;
66 import org.forester.msa.MsaInferrer;
67 import org.forester.msa.MsaMethods;
68 import org.forester.pccx.TestPccx;
69 import org.forester.phylogeny.Phylogeny;
70 import org.forester.phylogeny.PhylogenyBranch;
71 import org.forester.phylogeny.PhylogenyMethods;
72 import org.forester.phylogeny.PhylogenyNode;
73 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
74 import org.forester.phylogeny.data.Accession;
75 import org.forester.phylogeny.data.Accession.Source;
76 import org.forester.phylogeny.data.BinaryCharacters;
77 import org.forester.phylogeny.data.BranchWidth;
78 import org.forester.phylogeny.data.Confidence;
79 import org.forester.phylogeny.data.Distribution;
80 import org.forester.phylogeny.data.DomainArchitecture;
81 import org.forester.phylogeny.data.Event;
82 import org.forester.phylogeny.data.Identifier;
83 import org.forester.phylogeny.data.PhylogenyData;
84 import org.forester.phylogeny.data.PhylogenyDataUtil;
85 import org.forester.phylogeny.data.Polygon;
86 import org.forester.phylogeny.data.PropertiesMap;
87 import org.forester.phylogeny.data.Property;
88 import org.forester.phylogeny.data.Property.AppliesTo;
89 import org.forester.phylogeny.data.ProteinDomain;
90 import org.forester.phylogeny.data.Taxonomy;
91 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
92 import org.forester.phylogeny.factories.PhylogenyFactory;
93 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
94 import org.forester.protein.BasicDomain;
95 import org.forester.protein.BasicProtein;
96 import org.forester.protein.Domain;
97 import org.forester.protein.Protein;
98 import org.forester.protein.ProteinId;
99 import org.forester.rio.TestRIO;
100 import org.forester.sdi.SDI;
101 import org.forester.sdi.SDIR;
102 import org.forester.sdi.TestGSDI;
103 import org.forester.sequence.BasicSequence;
104 import org.forester.sequence.Sequence;
105 import org.forester.species.BasicSpecies;
106 import org.forester.species.Species;
107 import org.forester.surfacing.TestSurfacing;
108 import org.forester.tools.ConfidenceAssessor;
109 import org.forester.tools.SupportCount;
110 import org.forester.tools.TreeSplitMatrix;
111 import org.forester.util.AsciiHistogram;
112 import org.forester.util.BasicDescriptiveStatistics;
113 import org.forester.util.BasicTable;
114 import org.forester.util.BasicTableParser;
115 import org.forester.util.DescriptiveStatistics;
116 import org.forester.util.ForesterConstants;
117 import org.forester.util.ForesterUtil;
118 import org.forester.util.GeneralTable;
119 import org.forester.util.SequenceAccessionTools;
120 import org.forester.ws.seqdb.SequenceDatabaseEntry;
121 import org.forester.ws.seqdb.SequenceDbWsTools;
122 import org.forester.ws.seqdb.UniProtTaxonomy;
123 import org.forester.ws.wabi.TxSearch;
124 import org.forester.ws.wabi.TxSearch.RANKS;
125 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
126 import org.forester.ws.wabi.TxSearch.TAX_RANK;
127
128 @SuppressWarnings( "unused")
129 public final class Test {
130
131     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
132                                                                    + ForesterUtil.getFileSeparator() + "resources"
133                                                                    + ForesterUtil.getFileSeparator();
134     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
135                                                                    + ForesterUtil.getFileSeparator() + "test_data"
136                                                                    + ForesterUtil.getFileSeparator();
137     private final static boolean PERFORM_DB_TESTS          = false;
138     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
139                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
140                                                                    + ForesterConstants.PHYLO_XML_XSD;
141     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
142                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
143                                                                    + ForesterConstants.PHYLO_XML_XSD;
144     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
145     private final static double  ZERO_DIFF                 = 1.0E-9;
146
147     public static boolean isEqual( final double a, final double b ) {
148         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
149     }
150
151     public static void main( final String[] args ) {
152         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
153         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
154                 + "]" );
155         Locale.setDefault( Locale.US );
156         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
157         int failed = 0;
158         int succeeded = 0;
159         System.out.print( "[Test if directory with files for testing exists/is readable: " );
160         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
161             System.out.println( "OK.]" );
162         }
163         else {
164             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
165             System.out.println( "Testing aborted." );
166             System.exit( -1 );
167         }
168         System.out.print( "[Test if resources directory exists/is readable: " );
169         if ( testDir( PATH_TO_RESOURCES ) ) {
170             System.out.println( "OK.]" );
171         }
172         else {
173             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
174             System.out.println( "Testing aborted." );
175             System.exit( -1 );
176         }
177         final long start_time = new Date().getTime();
178         System.out.print( "Basic node methods: " );
179         if ( Test.testBasicNodeMethods() ) {
180             System.out.println( "OK." );
181             succeeded++;
182         }
183         else {
184             System.out.println( "failed." );
185             failed++;
186         }
187         System.out.print( "Protein id: " );
188         if ( !testProteinId() ) {
189             System.out.println( "failed." );
190             failed++;
191         }
192         else {
193             succeeded++;
194         }
195         System.out.println( "OK." );
196         System.out.print( "Species: " );
197         if ( !testSpecies() ) {
198             System.out.println( "failed." );
199             failed++;
200         }
201         else {
202             succeeded++;
203         }
204         System.out.println( "OK." );
205         System.out.print( "Basic domain: " );
206         if ( !testBasicDomain() ) {
207             System.out.println( "failed." );
208             failed++;
209         }
210         else {
211             succeeded++;
212         }
213         System.out.println( "OK." );
214         System.out.print( "Basic protein: " );
215         if ( !testBasicProtein() ) {
216             System.out.println( "failed." );
217             failed++;
218         }
219         else {
220             succeeded++;
221         }
222         System.out.println( "OK." );
223         System.out.print( "Sequence writer: " );
224         if ( testSequenceWriter() ) {
225             System.out.println( "OK." );
226             succeeded++;
227         }
228         else {
229             System.out.println( "failed." );
230             failed++;
231         }
232         System.out.print( "Sequence id parsing: " );
233         if ( testSequenceIdParsing() ) {
234             System.out.println( "OK." );
235             succeeded++;
236         }
237         else {
238             System.out.println( "failed." );
239             failed++;
240         }
241         System.out.print( "UniProtKB id extraction: " );
242         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
243             System.out.println( "OK." );
244             succeeded++;
245         }
246         else {
247             System.out.println( "failed." );
248             failed++;
249         }
250         System.out.print( "Sequence DB tools 1: " );
251         if ( testSequenceDbWsTools1() ) {
252             System.out.println( "OK." );
253             succeeded++;
254         }
255         else {
256             System.out.println( "failed." );
257             failed++;
258         }
259         if ( PERFORM_DB_TESTS ) {
260             System.out.print( "Ebi Entry Retrieval: " );
261             if ( Test.testEbiEntryRetrieval() ) {
262                 System.out.println( "OK." );
263                 succeeded++;
264             }
265             else {
266                 System.out.println( "failed." );
267                 failed++;
268             }
269         }
270         // System.exit( 0 );
271         if ( PERFORM_DB_TESTS ) {
272             System.out.print( "Sequence DB tools 2: " );
273             if ( testSequenceDbWsTools2() ) {
274                 System.out.println( "OK." );
275                 succeeded++;
276             }
277             else {
278                 System.out.println( "failed." );
279                 failed++;
280                 System.exit( -1 );
281             }
282         }
283         // System.exit( 0 );
284         System.out.print( "Hmmscan output parser: " );
285         if ( testHmmscanOutputParser() ) {
286             System.out.println( "OK." );
287             succeeded++;
288         }
289         else {
290             System.out.println( "failed." );
291             failed++;
292         }
293         //
294         System.out.print( "Overlap removal: " );
295         if ( !org.forester.test.Test.testOverlapRemoval() ) {
296             System.out.println( "failed." );
297             failed++;
298         }
299         else {
300             succeeded++;
301         }
302         System.out.println( "OK." );
303         System.out.print( "Engulfing overlap removal: " );
304         if ( !Test.testEngulfingOverlapRemoval() ) {
305             System.out.println( "failed." );
306             failed++;
307         }
308         else {
309             succeeded++;
310         }
311         System.out.println( "OK." );
312         //
313         System.out.print( "Taxonomy code extraction: " );
314         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
315             System.out.println( "OK." );
316             succeeded++;
317         }
318         else {
319             System.out.println( "failed." );
320             failed++;
321         }
322         System.out.print( "SN extraction: " );
323         if ( Test.testExtractSNFromNodeName() ) {
324             System.out.println( "OK." );
325             succeeded++;
326         }
327         else {
328             System.out.println( "failed." );
329             failed++;
330         }
331         System.out.print( "Taxonomy extraction (general): " );
332         if ( Test.testTaxonomyExtraction() ) {
333             System.out.println( "OK." );
334             succeeded++;
335         }
336         else {
337             System.out.println( "failed." );
338             failed++;
339         }
340         System.out.print( "Uri for Aptx web sequence accession: " );
341         if ( Test.testCreateUriForSeqWeb() ) {
342             System.out.println( "OK." );
343             succeeded++;
344         }
345         else {
346             System.out.println( "failed." );
347             failed++;
348         }
349         System.out.print( "Basic node construction and parsing of NHX (node level): " );
350         if ( Test.testNHXNodeParsing() ) {
351             System.out.println( "OK." );
352             succeeded++;
353         }
354         else {
355             System.out.println( "failed." );
356             failed++;
357         }
358         System.out.print( "NHX parsing iterating: " );
359         if ( Test.testNHParsingIter() ) {
360             System.out.println( "OK." );
361             succeeded++;
362         }
363         else {
364             System.out.println( "failed." );
365             failed++;
366         }
367         System.out.print( "NH parsing: " );
368         if ( Test.testNHParsing() ) {
369             System.out.println( "OK." );
370             succeeded++;
371         }
372         else {
373             System.out.println( "failed." );
374             failed++;
375         }
376         System.out.print( "Conversion to NHX (node level): " );
377         if ( Test.testNHXconversion() ) {
378             System.out.println( "OK." );
379             succeeded++;
380         }
381         else {
382             System.out.println( "failed." );
383             failed++;
384         }
385         System.out.print( "NHX parsing: " );
386         if ( Test.testNHXParsing() ) {
387             System.out.println( "OK." );
388             succeeded++;
389         }
390         else {
391             System.out.println( "failed." );
392             failed++;
393         }
394         System.out.print( "NHX parsing with quotes: " );
395         if ( Test.testNHXParsingQuotes() ) {
396             System.out.println( "OK." );
397             succeeded++;
398         }
399         else {
400             System.out.println( "failed." );
401             failed++;
402         }
403         System.out.print( "NHX parsing (MrBayes): " );
404         if ( Test.testNHXParsingMB() ) {
405             System.out.println( "OK." );
406             succeeded++;
407         }
408         else {
409             System.out.println( "failed." );
410             failed++;
411         }
412         System.out.print( "Nexus characters parsing: " );
413         if ( Test.testNexusCharactersParsing() ) {
414             System.out.println( "OK." );
415             succeeded++;
416         }
417         else {
418             System.out.println( "failed." );
419             failed++;
420         }
421         System.out.print( "Nexus tree parsing iterating: " );
422         if ( Test.testNexusTreeParsingIterating() ) {
423             System.out.println( "OK." );
424             succeeded++;
425         }
426         else {
427             System.out.println( "failed." );
428             failed++;
429         }
430         System.out.print( "Nexus tree parsing: " );
431         if ( Test.testNexusTreeParsing() ) {
432             System.out.println( "OK." );
433             succeeded++;
434         }
435         else {
436             System.out.println( "failed." );
437             failed++;
438         }
439         System.out.print( "Nexus tree parsing (translating): " );
440         if ( Test.testNexusTreeParsingTranslating() ) {
441             System.out.println( "OK." );
442             succeeded++;
443         }
444         else {
445             System.out.println( "failed." );
446             failed++;
447         }
448         System.out.print( "Nexus matrix parsing: " );
449         if ( Test.testNexusMatrixParsing() ) {
450             System.out.println( "OK." );
451             succeeded++;
452         }
453         else {
454             System.out.println( "failed." );
455             failed++;
456         }
457         System.out.print( "Basic phyloXML parsing: " );
458         if ( Test.testBasicPhyloXMLparsing() ) {
459             System.out.println( "OK." );
460             succeeded++;
461         }
462         else {
463             System.out.println( "failed." );
464             failed++;
465         }
466         System.out.print( "Basic phyloXML parsing (validating against schema): " );
467         if ( testBasicPhyloXMLparsingValidating() ) {
468             System.out.println( "OK." );
469             succeeded++;
470         }
471         else {
472             System.out.println( "failed." );
473             failed++;
474         }
475         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
476         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
477             System.out.println( "OK." );
478             succeeded++;
479         }
480         else {
481             System.out.println( "failed." );
482             failed++;
483         }
484         System.out.print( "phyloXML Distribution Element: " );
485         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
486             System.out.println( "OK." );
487             succeeded++;
488         }
489         else {
490             System.out.println( "failed." );
491             failed++;
492         }
493         System.out.print( "Tol XML parsing: " );
494         if ( Test.testBasicTolXMLparsing() ) {
495             System.out.println( "OK." );
496             succeeded++;
497         }
498         else {
499             System.out.println( "failed." );
500             failed++;
501         }
502         System.out.print( "Copying of node data: " );
503         if ( Test.testCopyOfNodeData() ) {
504             System.out.println( "OK." );
505             succeeded++;
506         }
507         else {
508             System.out.println( "failed." );
509             failed++;
510         }
511         System.out.print( "Tree copy: " );
512         if ( Test.testTreeCopy() ) {
513             System.out.println( "OK." );
514             succeeded++;
515         }
516         else {
517             System.out.println( "failed." );
518             failed++;
519         }
520         System.out.print( "Basic tree methods: " );
521         if ( Test.testBasicTreeMethods() ) {
522             System.out.println( "OK." );
523             succeeded++;
524         }
525         else {
526             System.out.println( "failed." );
527             failed++;
528         }
529         System.out.print( "Tree methods: " );
530         if ( Test.testTreeMethods() ) {
531             System.out.println( "OK." );
532             succeeded++;
533         }
534         else {
535             System.out.println( "failed." );
536             failed++;
537         }
538         System.out.print( "Postorder Iterator: " );
539         if ( Test.testPostOrderIterator() ) {
540             System.out.println( "OK." );
541             succeeded++;
542         }
543         else {
544             System.out.println( "failed." );
545             failed++;
546         }
547         System.out.print( "Preorder Iterator: " );
548         if ( Test.testPreOrderIterator() ) {
549             System.out.println( "OK." );
550             succeeded++;
551         }
552         else {
553             System.out.println( "failed." );
554             failed++;
555         }
556         System.out.print( "Levelorder Iterator: " );
557         if ( Test.testLevelOrderIterator() ) {
558             System.out.println( "OK." );
559             succeeded++;
560         }
561         else {
562             System.out.println( "failed." );
563             failed++;
564         }
565         System.out.print( "Re-id methods: " );
566         if ( Test.testReIdMethods() ) {
567             System.out.println( "OK." );
568             succeeded++;
569         }
570         else {
571             System.out.println( "failed." );
572             failed++;
573         }
574         System.out.print( "Methods on last external nodes: " );
575         if ( Test.testLastExternalNodeMethods() ) {
576             System.out.println( "OK." );
577             succeeded++;
578         }
579         else {
580             System.out.println( "failed." );
581             failed++;
582         }
583         System.out.print( "Methods on external nodes: " );
584         if ( Test.testExternalNodeRelatedMethods() ) {
585             System.out.println( "OK." );
586             succeeded++;
587         }
588         else {
589             System.out.println( "failed." );
590             failed++;
591         }
592         System.out.print( "Deletion of external nodes: " );
593         if ( Test.testDeletionOfExternalNodes() ) {
594             System.out.println( "OK." );
595             succeeded++;
596         }
597         else {
598             System.out.println( "failed." );
599             failed++;
600         }
601         System.out.print( "Subtree deletion: " );
602         if ( Test.testSubtreeDeletion() ) {
603             System.out.println( "OK." );
604             succeeded++;
605         }
606         else {
607             System.out.println( "failed." );
608             failed++;
609         }
610         System.out.print( "Phylogeny branch: " );
611         if ( Test.testPhylogenyBranch() ) {
612             System.out.println( "OK." );
613             succeeded++;
614         }
615         else {
616             System.out.println( "failed." );
617             failed++;
618         }
619         System.out.print( "Rerooting: " );
620         if ( Test.testRerooting() ) {
621             System.out.println( "OK." );
622             succeeded++;
623         }
624         else {
625             System.out.println( "failed." );
626             failed++;
627         }
628         System.out.print( "Mipoint rooting: " );
629         if ( Test.testMidpointrooting() ) {
630             System.out.println( "OK." );
631             succeeded++;
632         }
633         else {
634             System.out.println( "failed." );
635             failed++;
636         }
637         System.out.print( "Node removal: " );
638         if ( Test.testNodeRemoval() ) {
639             System.out.println( "OK." );
640             succeeded++;
641         }
642         else {
643             System.out.println( "failed." );
644             failed++;
645         }
646         System.out.print( "Support count: " );
647         if ( Test.testSupportCount() ) {
648             System.out.println( "OK." );
649             succeeded++;
650         }
651         else {
652             System.out.println( "failed." );
653             failed++;
654         }
655         System.out.print( "Support transfer: " );
656         if ( Test.testSupportTransfer() ) {
657             System.out.println( "OK." );
658             succeeded++;
659         }
660         else {
661             System.out.println( "failed." );
662             failed++;
663         }
664         System.out.print( "Finding of LCA: " );
665         if ( Test.testGetLCA() ) {
666             System.out.println( "OK." );
667             succeeded++;
668         }
669         else {
670             System.out.println( "failed." );
671             failed++;
672         }
673         System.out.print( "Finding of LCA 2: " );
674         if ( Test.testGetLCA2() ) {
675             System.out.println( "OK." );
676             succeeded++;
677         }
678         else {
679             System.out.println( "failed." );
680             failed++;
681         }
682         System.out.print( "Calculation of distance between nodes: " );
683         if ( Test.testGetDistance() ) {
684             System.out.println( "OK." );
685             succeeded++;
686         }
687         else {
688             System.out.println( "failed." );
689             failed++;
690         }
691         System.out.print( "Descriptive statistics: " );
692         if ( Test.testDescriptiveStatistics() ) {
693             System.out.println( "OK." );
694             succeeded++;
695         }
696         else {
697             System.out.println( "failed." );
698             failed++;
699         }
700         System.out.print( "Data objects and methods: " );
701         if ( Test.testDataObjects() ) {
702             System.out.println( "OK." );
703             succeeded++;
704         }
705         else {
706             System.out.println( "failed." );
707             failed++;
708         }
709         System.out.print( "Properties map: " );
710         if ( Test.testPropertiesMap() ) {
711             System.out.println( "OK." );
712             succeeded++;
713         }
714         else {
715             System.out.println( "failed." );
716             failed++;
717         }
718         System.out.print( "SDIse: " );
719         if ( Test.testSDIse() ) {
720             System.out.println( "OK." );
721             succeeded++;
722         }
723         else {
724             System.out.println( "failed." );
725             failed++;
726         }
727         System.out.print( "SDIunrooted: " );
728         if ( Test.testSDIunrooted() ) {
729             System.out.println( "OK." );
730             succeeded++;
731         }
732         else {
733             System.out.println( "failed." );
734             failed++;
735         }
736         System.out.print( "GSDI: " );
737         if ( TestGSDI.test() ) {
738             System.out.println( "OK." );
739             succeeded++;
740         }
741         else {
742             System.out.println( "failed." );
743             failed++;
744         }
745         System.out.print( "RIO: " );
746         if ( TestRIO.test() ) {
747             System.out.println( "OK." );
748             succeeded++;
749         }
750         else {
751             System.out.println( "failed." );
752             failed++;
753         }
754         System.out.print( "Phylogeny reconstruction:" );
755         System.out.println();
756         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
757             System.out.println( "OK." );
758             succeeded++;
759         }
760         else {
761             System.out.println( "failed." );
762             failed++;
763         }
764         System.out.print( "Analysis of domain architectures: " );
765         System.out.println();
766         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
767             System.out.println( "OK." );
768             succeeded++;
769         }
770         else {
771             System.out.println( "failed." );
772             failed++;
773         }
774         System.out.print( "GO: " );
775         System.out.println();
776         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
777             System.out.println( "OK." );
778             succeeded++;
779         }
780         else {
781             System.out.println( "failed." );
782             failed++;
783         }
784         System.out.print( "Modeling tools: " );
785         if ( TestPccx.test() ) {
786             System.out.println( "OK." );
787             succeeded++;
788         }
789         else {
790             System.out.println( "failed." );
791             failed++;
792         }
793         System.out.print( "Split Matrix strict: " );
794         if ( Test.testSplitStrict() ) {
795             System.out.println( "OK." );
796             succeeded++;
797         }
798         else {
799             System.out.println( "failed." );
800             failed++;
801         }
802         System.out.print( "Split Matrix: " );
803         if ( Test.testSplit() ) {
804             System.out.println( "OK." );
805             succeeded++;
806         }
807         else {
808             System.out.println( "failed." );
809             failed++;
810         }
811         System.out.print( "Confidence Assessor: " );
812         if ( Test.testConfidenceAssessor() ) {
813             System.out.println( "OK." );
814             succeeded++;
815         }
816         else {
817             System.out.println( "failed." );
818             failed++;
819         }
820         System.out.print( "Basic table: " );
821         if ( Test.testBasicTable() ) {
822             System.out.println( "OK." );
823             succeeded++;
824         }
825         else {
826             System.out.println( "failed." );
827             failed++;
828         }
829         System.out.print( "General table: " );
830         if ( Test.testGeneralTable() ) {
831             System.out.println( "OK." );
832             succeeded++;
833         }
834         else {
835             System.out.println( "failed." );
836             failed++;
837         }
838         System.out.print( "Amino acid sequence: " );
839         if ( Test.testAminoAcidSequence() ) {
840             System.out.println( "OK." );
841             succeeded++;
842         }
843         else {
844             System.out.println( "failed." );
845             failed++;
846         }
847         System.out.print( "General MSA parser: " );
848         if ( Test.testGeneralMsaParser() ) {
849             System.out.println( "OK." );
850             succeeded++;
851         }
852         else {
853             System.out.println( "failed." );
854             failed++;
855         }
856         System.out.print( "Fasta parser for msa: " );
857         if ( Test.testFastaParser() ) {
858             System.out.println( "OK." );
859             succeeded++;
860         }
861         else {
862             System.out.println( "failed." );
863             failed++;
864         }
865         System.out.print( "Creation of balanced phylogeny: " );
866         if ( Test.testCreateBalancedPhylogeny() ) {
867             System.out.println( "OK." );
868             succeeded++;
869         }
870         else {
871             System.out.println( "failed." );
872             failed++;
873         }
874         System.out.print( "Genbank accessor parsing: " );
875         if ( Test.testGenbankAccessorParsing() ) {
876             System.out.println( "OK." );
877             succeeded++;
878         }
879         else {
880             System.out.println( "failed." );
881             failed++;
882         }
883         if ( PERFORM_DB_TESTS ) {
884             System.out.print( "Uniprot Entry Retrieval: " );
885             if ( Test.testUniprotEntryRetrieval() ) {
886                 System.out.println( "OK." );
887                 succeeded++;
888             }
889             else {
890                 System.out.println( "failed." );
891                 failed++;
892             }
893         }
894         if ( PERFORM_DB_TESTS ) {
895             System.out.print( "Uniprot Taxonomy Search: " );
896             if ( Test.testUniprotTaxonomySearch() ) {
897                 System.out.println( "OK." );
898                 succeeded++;
899             }
900             else {
901                 System.out.println( "failed." );
902                 failed++;
903             }
904         }
905         //----
906         String path = "";
907         final String os = ForesterUtil.OS_NAME.toLowerCase();
908         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
909             path = "/usr/local/bin/mafft";
910         }
911         else if ( os.indexOf( "win" ) >= 0 ) {
912             path = "C:\\Program Files\\mafft-win\\mafft.bat";
913         }
914         else {
915             path = "mafft";
916             if ( !MsaInferrer.isInstalled( path ) ) {
917                 path = "/usr/bin/mafft";
918             }
919             if ( !MsaInferrer.isInstalled( path ) ) {
920                 path = "/usr/local/bin/mafft";
921             }
922         }
923         if ( MsaInferrer.isInstalled( path ) ) {
924             System.out.print( "MAFFT (external program): " );
925             if ( Test.testMafft( path ) ) {
926                 System.out.println( "OK." );
927                 succeeded++;
928             }
929             else {
930                 System.out.println( "failed [will not count towards failed tests]" );
931             }
932         }
933         //----
934         System.out.print( "Next nodes with collapsed: " );
935         if ( Test.testNextNodeWithCollapsing() ) {
936             System.out.println( "OK." );
937             succeeded++;
938         }
939         else {
940             System.out.println( "failed." );
941             failed++;
942         }
943         System.out.print( "Simple MSA quality: " );
944         if ( Test.testMsaQualityMethod() ) {
945             System.out.println( "OK." );
946             succeeded++;
947         }
948         else {
949             System.out.println( "failed." );
950             failed++;
951         }
952         System.out.print( "NHX parsing from URL: " );
953         if ( Test.testNHXparsingFromURL() ) {
954             System.out.println( "OK." );
955             succeeded++;
956         }
957         else {
958             System.out.println( "failed." );
959             failed++;
960         }
961         System.out.print( "phyloXML parsing from URL: " );
962         if ( Test.testPhyloXMLparsingFromURL() ) {
963             System.out.println( "OK." );
964             succeeded++;
965         }
966         else {
967             System.out.println( "failed." );
968             failed++;
969         }
970         System.out.println();
971         final Runtime rt = java.lang.Runtime.getRuntime();
972         final long free_memory = rt.freeMemory() / 1000000;
973         final long total_memory = rt.totalMemory() / 1000000;
974         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
975                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
976         System.out.println();
977         System.out.println( "Successful tests: " + succeeded );
978         System.out.println( "Failed     tests: " + failed );
979         System.out.println();
980         if ( failed < 1 ) {
981             System.out.println( "OK." );
982         }
983         else {
984             System.out.println( "Not OK." );
985         }
986     }
987
988     public static boolean testEngulfingOverlapRemoval() {
989         try {
990             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
991             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
992             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
993             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
994             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
995             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
996             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
997             final List<Boolean> covered = new ArrayList<Boolean>();
998             covered.add( true ); // 0
999             covered.add( false ); // 1
1000             covered.add( true ); // 2
1001             covered.add( false ); // 3
1002             covered.add( true ); // 4
1003             covered.add( true ); // 5
1004             covered.add( false ); // 6
1005             covered.add( true ); // 7
1006             covered.add( true ); // 8
1007             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1008                 return false;
1009             }
1010             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1011                 return false;
1012             }
1013             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1014                 return false;
1015             }
1016             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1017                 return false;
1018             }
1019             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1020                 return false;
1021             }
1022             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1023                 return false;
1024             }
1025             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1026                 return false;
1027             }
1028             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1029             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1030             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1031             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1032             abc.addProteinDomain( a );
1033             abc.addProteinDomain( b );
1034             abc.addProteinDomain( c );
1035             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1036             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1037             if ( abc.getNumberOfProteinDomains() != 3 ) {
1038                 return false;
1039             }
1040             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1041                 return false;
1042             }
1043             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1044                 return false;
1045             }
1046             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1047                 return false;
1048             }
1049             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1050                 return false;
1051             }
1052             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1053             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1054             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1055             final Protein def = new BasicProtein( "def", "nemve", 0 );
1056             def.addProteinDomain( d );
1057             def.addProteinDomain( e );
1058             def.addProteinDomain( f );
1059             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1060             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1061             if ( def.getNumberOfProteinDomains() != 3 ) {
1062                 return false;
1063             }
1064             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1065                 return false;
1066             }
1067             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1068                 return false;
1069             }
1070             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1071                 return false;
1072             }
1073             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1074                 return false;
1075             }
1076             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1077                 return false;
1078             }
1079         }
1080         catch ( final Exception e ) {
1081             e.printStackTrace( System.out );
1082             return false;
1083         }
1084         return true;
1085     }
1086
1087     public static final boolean testPhyloXMLparsingFromURL() {
1088         try {
1089             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1090             final URL u = new URL( s );
1091             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1092             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1093             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1094                 return false;
1095             }
1096         }
1097         catch ( final Exception e ) {
1098             e.printStackTrace();
1099         }
1100         return true;
1101     }
1102
1103     public static final boolean testNHXparsingFromURL() {
1104         try {
1105             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1106             final URL u = new URL( s );
1107             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1108             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1109             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1110                 return false;
1111             }
1112             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1113                 System.out.println( phys[ 0 ].toNewHampshire() );
1114                 return false;
1115             }
1116             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1117                 System.out.println( phys[ 1 ].toNewHampshire() );
1118                 return false;
1119             }
1120             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1121             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1122                 return false;
1123             }
1124             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1125                 System.out.println( phys2[ 0 ].toNewHampshire() );
1126                 return false;
1127             }
1128             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1129             final NHXParser p = new NHXParser();
1130             final URL u2 = new URL( s );
1131             p.setSource( u2 );
1132             if ( !p.hasNext() ) {
1133                 return false;
1134             }
1135             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1136                 return false;
1137             }
1138             if ( !p.hasNext() ) {
1139                 return false;
1140             }
1141             p.reset();
1142             if ( !p.hasNext() ) {
1143                 return false;
1144             }
1145             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1146                 return false;
1147             }
1148             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1149                 return false;
1150             }
1151             p.reset();
1152             if ( !p.hasNext() ) {
1153                 return false;
1154             }
1155             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1156                 return false;
1157             }
1158             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1159                 return false;
1160             }
1161         }
1162         catch ( final Exception e ) {
1163             e.printStackTrace();
1164         }
1165         return true;
1166     }
1167
1168     public static boolean testOverlapRemoval() {
1169         try {
1170             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1171             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1172             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1173             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1174             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1175             final List<Boolean> covered = new ArrayList<Boolean>();
1176             covered.add( true ); // 0
1177             covered.add( false ); // 1
1178             covered.add( true ); // 2
1179             covered.add( false ); // 3
1180             covered.add( true ); // 4
1181             covered.add( true ); // 5
1182             covered.add( false ); // 6
1183             covered.add( true ); // 7
1184             covered.add( true ); // 8
1185             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1186                 return false;
1187             }
1188             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1189                 return false;
1190             }
1191             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1192                 return false;
1193             }
1194             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1195                 return false;
1196             }
1197             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1198                 return false;
1199             }
1200             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1201             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1202             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1203             ab.addProteinDomain( a );
1204             ab.addProteinDomain( b );
1205             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1206             if ( ab.getNumberOfProteinDomains() != 2 ) {
1207                 return false;
1208             }
1209             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1210                 return false;
1211             }
1212             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1213                 return false;
1214             }
1215             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1216             if ( ab.getNumberOfProteinDomains() != 2 ) {
1217                 return false;
1218             }
1219             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1220                 return false;
1221             }
1222             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1223             final Domain d = new BasicDomain( "d",
1224                                               ( short ) 10000,
1225                                               ( short ) 10500,
1226                                               ( short ) 1,
1227                                               ( short ) 1,
1228                                               0.0000001,
1229                                               1 );
1230             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1231             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1232             cde.addProteinDomain( c );
1233             cde.addProteinDomain( d );
1234             cde.addProteinDomain( e );
1235             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1236             if ( cde.getNumberOfProteinDomains() != 3 ) {
1237                 return false;
1238             }
1239             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1240                 return false;
1241             }
1242             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1243             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1244             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1245             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1246             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1247             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1248             fghi.addProteinDomain( f );
1249             fghi.addProteinDomain( g );
1250             fghi.addProteinDomain( h );
1251             fghi.addProteinDomain( i );
1252             fghi.addProteinDomain( i );
1253             fghi.addProteinDomain( i );
1254             fghi.addProteinDomain( i2 );
1255             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1256             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1257                 return false;
1258             }
1259             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1260                 return false;
1261             }
1262             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1263                 return false;
1264             }
1265             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1266             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1267                 return false;
1268             }
1269             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1270                 return false;
1271             }
1272             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1273             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1274             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1275             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1276             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1277             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1278             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1279             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1280             jklm.addProteinDomain( j );
1281             jklm.addProteinDomain( k );
1282             jklm.addProteinDomain( l );
1283             jklm.addProteinDomain( m );
1284             jklm.addProteinDomain( m0 );
1285             jklm.addProteinDomain( m1 );
1286             jklm.addProteinDomain( m2 );
1287             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1288             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1289                 return false;
1290             }
1291             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1292                 return false;
1293             }
1294             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1295                 return false;
1296             }
1297             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1298             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1299                 return false;
1300             }
1301             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1302                 return false;
1303             }
1304             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1305             final Protein od = new BasicProtein( "od", "varanus", 0 );
1306             od.addProteinDomain( only );
1307             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1308             if ( od.getNumberOfProteinDomains() != 1 ) {
1309                 return false;
1310             }
1311             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1312                 return false;
1313             }
1314         }
1315         catch ( final Exception e ) {
1316             e.printStackTrace( System.out );
1317             return false;
1318         }
1319         return true;
1320     }
1321
1322     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1323         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1324         return p;
1325     }
1326
1327     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1328         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1329     }
1330
1331     private static boolean testAminoAcidSequence() {
1332         try {
1333             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1334             if ( aa1.getLength() != 13 ) {
1335                 return false;
1336             }
1337             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1338                 return false;
1339             }
1340             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1341                 return false;
1342             }
1343             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1344                 return false;
1345             }
1346             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1347             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1348                 return false;
1349             }
1350             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1351             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1352                 return false;
1353             }
1354             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1355             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1356                 return false;
1357             }
1358         }
1359         catch ( final Exception e ) {
1360             e.printStackTrace();
1361             return false;
1362         }
1363         return true;
1364     }
1365
1366     private static boolean testBasicDomain() {
1367         try {
1368             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1369             if ( !pd.getDomainId().equals( "id" ) ) {
1370                 return false;
1371             }
1372             if ( pd.getNumber() != 1 ) {
1373                 return false;
1374             }
1375             if ( pd.getTotalCount() != 4 ) {
1376                 return false;
1377             }
1378             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1379                 return false;
1380             }
1381             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1382             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1383             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1384             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1385             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1386             if ( !a1.equals( a1 ) ) {
1387                 return false;
1388             }
1389             if ( !a1.equals( a1_copy ) ) {
1390                 return false;
1391             }
1392             if ( !a1.equals( a1_equal ) ) {
1393                 return false;
1394             }
1395             if ( !a1.equals( a2 ) ) {
1396                 return false;
1397             }
1398             if ( a1.equals( a3 ) ) {
1399                 return false;
1400             }
1401             if ( a1.compareTo( a1 ) != 0 ) {
1402                 return false;
1403             }
1404             if ( a1.compareTo( a1_copy ) != 0 ) {
1405                 return false;
1406             }
1407             if ( a1.compareTo( a1_equal ) != 0 ) {
1408                 return false;
1409             }
1410             if ( a1.compareTo( a2 ) != 0 ) {
1411                 return false;
1412             }
1413             if ( a1.compareTo( a3 ) == 0 ) {
1414                 return false;
1415             }
1416         }
1417         catch ( final Exception e ) {
1418             e.printStackTrace( System.out );
1419             return false;
1420         }
1421         return true;
1422     }
1423
1424     private static boolean testBasicNodeMethods() {
1425         try {
1426             if ( PhylogenyNode.getNodeCount() != 0 ) {
1427                 return false;
1428             }
1429             final PhylogenyNode n1 = new PhylogenyNode();
1430             final PhylogenyNode n2 = PhylogenyNode
1431                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1432             final PhylogenyNode n3 = PhylogenyNode
1433                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1434             final PhylogenyNode n4 = PhylogenyNode
1435                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1436             if ( n1.isHasAssignedEvent() ) {
1437                 return false;
1438             }
1439             if ( PhylogenyNode.getNodeCount() != 4 ) {
1440                 return false;
1441             }
1442             if ( n3.getIndicator() != 0 ) {
1443                 return false;
1444             }
1445             if ( n3.getNumberOfExternalNodes() != 1 ) {
1446                 return false;
1447             }
1448             if ( !n3.isExternal() ) {
1449                 return false;
1450             }
1451             if ( !n3.isRoot() ) {
1452                 return false;
1453             }
1454             if ( !n4.getName().equals( "n4" ) ) {
1455                 return false;
1456             }
1457         }
1458         catch ( final Exception e ) {
1459             e.printStackTrace( System.out );
1460             return false;
1461         }
1462         return true;
1463     }
1464
1465     private static boolean testBasicPhyloXMLparsing() {
1466         try {
1467             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1468             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1469             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1470                                                               xml_parser );
1471             if ( xml_parser.getErrorCount() > 0 ) {
1472                 System.out.println( xml_parser.getErrorMessages().toString() );
1473                 return false;
1474             }
1475             if ( phylogenies_0.length != 4 ) {
1476                 return false;
1477             }
1478             final Phylogeny t1 = phylogenies_0[ 0 ];
1479             final Phylogeny t2 = phylogenies_0[ 1 ];
1480             final Phylogeny t3 = phylogenies_0[ 2 ];
1481             final Phylogeny t4 = phylogenies_0[ 3 ];
1482             if ( t1.getNumberOfExternalNodes() != 1 ) {
1483                 return false;
1484             }
1485             if ( !t1.isRooted() ) {
1486                 return false;
1487             }
1488             if ( t1.isRerootable() ) {
1489                 return false;
1490             }
1491             if ( !t1.getType().equals( "gene_tree" ) ) {
1492                 return false;
1493             }
1494             if ( t2.getNumberOfExternalNodes() != 2 ) {
1495                 return false;
1496             }
1497             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1498                 return false;
1499             }
1500             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1501                 return false;
1502             }
1503             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1504                 return false;
1505             }
1506             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1507                 return false;
1508             }
1509             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1510                 return false;
1511             }
1512             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1513                 return false;
1514             }
1515             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1516                     .startsWith( "actgtgggggt" ) ) {
1517                 return false;
1518             }
1519             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1520                     .startsWith( "ctgtgatgcat" ) ) {
1521                 return false;
1522             }
1523             if ( t3.getNumberOfExternalNodes() != 4 ) {
1524                 return false;
1525             }
1526             if ( !t1.getName().equals( "t1" ) ) {
1527                 return false;
1528             }
1529             if ( !t2.getName().equals( "t2" ) ) {
1530                 return false;
1531             }
1532             if ( !t3.getName().equals( "t3" ) ) {
1533                 return false;
1534             }
1535             if ( !t4.getName().equals( "t4" ) ) {
1536                 return false;
1537             }
1538             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1539                 return false;
1540             }
1541             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1542                 return false;
1543             }
1544             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1545                 return false;
1546             }
1547             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1548                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1549                 return false;
1550             }
1551             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1552                 return false;
1553             }
1554             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1555                 return false;
1556             }
1557             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1558                 return false;
1559             }
1560             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1561                     .equals( "apoptosis" ) ) {
1562                 return false;
1563             }
1564             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1565                     .equals( "GO:0006915" ) ) {
1566                 return false;
1567             }
1568             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1569                     .equals( "UniProtKB" ) ) {
1570                 return false;
1571             }
1572             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1573                     .equals( "experimental" ) ) {
1574                 return false;
1575             }
1576             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1577                     .equals( "function" ) ) {
1578                 return false;
1579             }
1580             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1581                     .getValue() != 1 ) {
1582                 return false;
1583             }
1584             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1585                     .getType().equals( "ml" ) ) {
1586                 return false;
1587             }
1588             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1589                     .equals( "apoptosis" ) ) {
1590                 return false;
1591             }
1592             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1593                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1594                 return false;
1595             }
1596             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1597                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1598                 return false;
1599             }
1600             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1601                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1602                 return false;
1603             }
1604             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1605                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1606                 return false;
1607             }
1608             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1609                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1610                 return false;
1611             }
1612             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1613                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1614                 return false;
1615             }
1616             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1617                     .equals( "GO:0005829" ) ) {
1618                 return false;
1619             }
1620             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1621                     .equals( "intracellular organelle" ) ) {
1622                 return false;
1623             }
1624             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1625                 return false;
1626             }
1627             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1628                     .equals( "UniProt link" ) ) ) {
1629                 return false;
1630             }
1631             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1632                 return false;
1633             }
1634             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1635             if ( x.size() != 4 ) {
1636                 return false;
1637             }
1638             int c = 0;
1639             for( final Accession acc : x ) {
1640                 if ( c == 0 ) {
1641                     if ( !acc.getSource().equals( "KEGG" ) ) {
1642                         return false;
1643                     }
1644                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1645                         return false;
1646                     }
1647                 }
1648                 c++;
1649             }
1650         }
1651         catch ( final Exception e ) {
1652             e.printStackTrace( System.out );
1653             return false;
1654         }
1655         return true;
1656     }
1657
1658     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1659         try {
1660             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1661             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1662             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1663                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1664             }
1665             else {
1666                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1667             }
1668             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1669                                                               xml_parser );
1670             if ( xml_parser.getErrorCount() > 0 ) {
1671                 System.out.println( xml_parser.getErrorMessages().toString() );
1672                 return false;
1673             }
1674             if ( phylogenies_0.length != 4 ) {
1675                 return false;
1676             }
1677             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1678             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1679             if ( phylogenies_t1.length != 1 ) {
1680                 return false;
1681             }
1682             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1683             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1684                 return false;
1685             }
1686             if ( !t1_rt.isRooted() ) {
1687                 return false;
1688             }
1689             if ( t1_rt.isRerootable() ) {
1690                 return false;
1691             }
1692             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1693                 return false;
1694             }
1695             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1696             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1697             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1698             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1699                 return false;
1700             }
1701             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1702                 return false;
1703             }
1704             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1705                 return false;
1706             }
1707             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1708                 return false;
1709             }
1710             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1711                     .startsWith( "actgtgggggt" ) ) {
1712                 return false;
1713             }
1714             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1715                     .startsWith( "ctgtgatgcat" ) ) {
1716                 return false;
1717             }
1718             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1719             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1720             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1721             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1722             if ( phylogenies_1.length != 1 ) {
1723                 return false;
1724             }
1725             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1726             if ( !t3_rt.getName().equals( "t3" ) ) {
1727                 return false;
1728             }
1729             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1730                 return false;
1731             }
1732             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1733                 return false;
1734             }
1735             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1736                 return false;
1737             }
1738             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1739                 return false;
1740             }
1741             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1742                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1743                 return false;
1744             }
1745             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1746                 return false;
1747             }
1748             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1749                 return false;
1750             }
1751             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1752                     .equals( "UniProtKB" ) ) {
1753                 return false;
1754             }
1755             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1756                     .equals( "apoptosis" ) ) {
1757                 return false;
1758             }
1759             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1760                     .equals( "GO:0006915" ) ) {
1761                 return false;
1762             }
1763             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1764                     .equals( "UniProtKB" ) ) {
1765                 return false;
1766             }
1767             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1768                     .equals( "experimental" ) ) {
1769                 return false;
1770             }
1771             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1772                     .equals( "function" ) ) {
1773                 return false;
1774             }
1775             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1776                     .getValue() != 1 ) {
1777                 return false;
1778             }
1779             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1780                     .getType().equals( "ml" ) ) {
1781                 return false;
1782             }
1783             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1784                     .equals( "apoptosis" ) ) {
1785                 return false;
1786             }
1787             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1788                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1789                 return false;
1790             }
1791             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1792                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1793                 return false;
1794             }
1795             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1796                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1797                 return false;
1798             }
1799             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1800                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1801                 return false;
1802             }
1803             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1804                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1805                 return false;
1806             }
1807             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1808                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1809                 return false;
1810             }
1811             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1812                     .equals( "GO:0005829" ) ) {
1813                 return false;
1814             }
1815             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1816                     .equals( "intracellular organelle" ) ) {
1817                 return false;
1818             }
1819             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1820                 return false;
1821             }
1822             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1823                     .equals( "UniProt link" ) ) ) {
1824                 return false;
1825             }
1826             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1827                 return false;
1828             }
1829             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1830                 return false;
1831             }
1832             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1833                     .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." ) ) ) {
1834                 return false;
1835             }
1836             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1837                 return false;
1838             }
1839             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1840                 return false;
1841             }
1842             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1843                 return false;
1844             }
1845             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1846                 return false;
1847             }
1848             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1849                     .equals( "ncbi" ) ) {
1850                 return false;
1851             }
1852             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1853                 return false;
1854             }
1855             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1856                     .getName().equals( "B" ) ) {
1857                 return false;
1858             }
1859             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1860                     .getFrom() != 21 ) {
1861                 return false;
1862             }
1863             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1864                 return false;
1865             }
1866             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1867                     .getLength() != 24 ) {
1868                 return false;
1869             }
1870             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1871                     .getConfidence() != 2144 ) {
1872                 return false;
1873             }
1874             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1875                     .equals( "pfam" ) ) {
1876                 return false;
1877             }
1878             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1879                 return false;
1880             }
1881             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1882                 return false;
1883             }
1884             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1885                 return false;
1886             }
1887             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1888                 return false;
1889             }
1890             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1891             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1892                 return false;
1893             }
1894             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1895                 return false;
1896             }
1897             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1898                 return false;
1899             }
1900             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1901                 return false;
1902             }
1903             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1904                 return false;
1905             }
1906             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1907                 return false;
1908             }
1909             if ( taxbb.getSynonyms().size() != 2 ) {
1910                 return false;
1911             }
1912             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1913                 return false;
1914             }
1915             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1916                 return false;
1917             }
1918             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1919                 return false;
1920             }
1921             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1922                 return false;
1923             }
1924             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1925                 return false;
1926             }
1927             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1928                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1929                 return false;
1930             }
1931             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1932                 return false;
1933             }
1934             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1935                 return false;
1936             }
1937             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1938                 return false;
1939             }
1940             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1941                 return false;
1942             }
1943             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1944                 return false;
1945             }
1946             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1947                 return false;
1948             }
1949             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1950                 return false;
1951             }
1952             //
1953             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1954                 return false;
1955             }
1956             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1957                     .equalsIgnoreCase( "435" ) ) {
1958                 return false;
1959             }
1960             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1961                 return false;
1962             }
1963             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1964                     .equalsIgnoreCase( "443.7" ) ) {
1965                 return false;
1966             }
1967             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1968                 return false;
1969             }
1970             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1971                 return false;
1972             }
1973             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1974                     .equalsIgnoreCase( "433" ) ) {
1975                 return false;
1976             }
1977             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
1978                     .getCrossReferences();
1979             if ( x.size() != 4 ) {
1980                 return false;
1981             }
1982             int c = 0;
1983             for( final Accession acc : x ) {
1984                 if ( c == 0 ) {
1985                     if ( !acc.getSource().equals( "KEGG" ) ) {
1986                         return false;
1987                     }
1988                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1989                         return false;
1990                     }
1991                 }
1992                 c++;
1993             }
1994         }
1995         catch ( final Exception e ) {
1996             e.printStackTrace( System.out );
1997             return false;
1998         }
1999         return true;
2000     }
2001
2002     private static boolean testBasicPhyloXMLparsingValidating() {
2003         try {
2004             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2005             PhyloXmlParser xml_parser = null;
2006             try {
2007                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2008             }
2009             catch ( final Exception e ) {
2010                 // Do nothing -- means were not running from jar.
2011             }
2012             if ( xml_parser == null ) {
2013                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2014                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2015                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2016                 }
2017                 else {
2018                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2019                 }
2020             }
2021             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2022                                                               xml_parser );
2023             if ( xml_parser.getErrorCount() > 0 ) {
2024                 System.out.println( xml_parser.getErrorMessages().toString() );
2025                 return false;
2026             }
2027             if ( phylogenies_0.length != 4 ) {
2028                 return false;
2029             }
2030             final Phylogeny t1 = phylogenies_0[ 0 ];
2031             final Phylogeny t2 = phylogenies_0[ 1 ];
2032             final Phylogeny t3 = phylogenies_0[ 2 ];
2033             final Phylogeny t4 = phylogenies_0[ 3 ];
2034             if ( !t1.getName().equals( "t1" ) ) {
2035                 return false;
2036             }
2037             if ( !t2.getName().equals( "t2" ) ) {
2038                 return false;
2039             }
2040             if ( !t3.getName().equals( "t3" ) ) {
2041                 return false;
2042             }
2043             if ( !t4.getName().equals( "t4" ) ) {
2044                 return false;
2045             }
2046             if ( t1.getNumberOfExternalNodes() != 1 ) {
2047                 return false;
2048             }
2049             if ( t2.getNumberOfExternalNodes() != 2 ) {
2050                 return false;
2051             }
2052             if ( t3.getNumberOfExternalNodes() != 4 ) {
2053                 return false;
2054             }
2055             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2056             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2057             if ( xml_parser.getErrorCount() > 0 ) {
2058                 System.out.println( "errors:" );
2059                 System.out.println( xml_parser.getErrorMessages().toString() );
2060                 return false;
2061             }
2062             if ( phylogenies_1.length != 4 ) {
2063                 return false;
2064             }
2065             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2066                                                               xml_parser );
2067             if ( xml_parser.getErrorCount() > 0 ) {
2068                 System.out.println( "errors:" );
2069                 System.out.println( xml_parser.getErrorMessages().toString() );
2070                 return false;
2071             }
2072             if ( phylogenies_2.length != 1 ) {
2073                 return false;
2074             }
2075             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2076                 return false;
2077             }
2078             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2079                                                               xml_parser );
2080             if ( xml_parser.getErrorCount() > 0 ) {
2081                 System.out.println( xml_parser.getErrorMessages().toString() );
2082                 return false;
2083             }
2084             if ( phylogenies_3.length != 2 ) {
2085                 return false;
2086             }
2087             final Phylogeny a = phylogenies_3[ 0 ];
2088             if ( !a.getName().equals( "tree 4" ) ) {
2089                 return false;
2090             }
2091             if ( a.getNumberOfExternalNodes() != 3 ) {
2092                 return false;
2093             }
2094             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2095                 return false;
2096             }
2097             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2098                 return false;
2099             }
2100             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2101                                                               xml_parser );
2102             if ( xml_parser.getErrorCount() > 0 ) {
2103                 System.out.println( xml_parser.getErrorMessages().toString() );
2104                 return false;
2105             }
2106             if ( phylogenies_4.length != 1 ) {
2107                 return false;
2108             }
2109             final Phylogeny s = phylogenies_4[ 0 ];
2110             if ( s.getNumberOfExternalNodes() != 6 ) {
2111                 return false;
2112             }
2113             s.getNode( "first" );
2114             s.getNode( "<>" );
2115             s.getNode( "\"<a'b&c'd\">\"" );
2116             s.getNode( "'''\"" );
2117             s.getNode( "\"\"\"" );
2118             s.getNode( "dick & doof" );
2119         }
2120         catch ( final Exception e ) {
2121             e.printStackTrace( System.out );
2122             return false;
2123         }
2124         return true;
2125     }
2126
2127     private static boolean testBasicProtein() {
2128         try {
2129             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2130             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2131             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2132             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2133             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2134             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2135             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2136             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2137             p0.addProteinDomain( y );
2138             p0.addProteinDomain( e );
2139             p0.addProteinDomain( b );
2140             p0.addProteinDomain( c );
2141             p0.addProteinDomain( d );
2142             p0.addProteinDomain( a );
2143             p0.addProteinDomain( x );
2144             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2145                 return false;
2146             }
2147             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2148                 return false;
2149             }
2150             //
2151             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2152             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2153             aa0.addProteinDomain( a1 );
2154             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2155                 return false;
2156             }
2157             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2158                 return false;
2159             }
2160             //
2161             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2162             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2163             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2164             aa1.addProteinDomain( a11 );
2165             aa1.addProteinDomain( a12 );
2166             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2167                 return false;
2168             }
2169             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2170                 return false;
2171             }
2172             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2173             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2174                 return false;
2175             }
2176             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2177                 return false;
2178             }
2179             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2180                 return false;
2181             }
2182             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2183             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2184                 return false;
2185             }
2186             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2187                 return false;
2188             }
2189             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2190                 return false;
2191             }
2192             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2193                 return false;
2194             }
2195             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2196             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2197                 return false;
2198             }
2199             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2200                 return false;
2201             }
2202             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2203                 return false;
2204             }
2205             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2206                 return false;
2207             }
2208             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2209             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2210                 return false;
2211             }
2212             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2213                 return false;
2214             }
2215             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2216                 return false;
2217             }
2218             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2219                 return false;
2220             }
2221             //
2222             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2223             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2224             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2225             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2226             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2227             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2228             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2229             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2230             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2231             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2232             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2233             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2234             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2235             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2236             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2237             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2238             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2239             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2240             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2241             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2242             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2243             p00.addProteinDomain( y0 );
2244             p00.addProteinDomain( e0 );
2245             p00.addProteinDomain( b0 );
2246             p00.addProteinDomain( c0 );
2247             p00.addProteinDomain( d0 );
2248             p00.addProteinDomain( a0 );
2249             p00.addProteinDomain( x0 );
2250             p00.addProteinDomain( y1 );
2251             p00.addProteinDomain( y2 );
2252             p00.addProteinDomain( y3 );
2253             p00.addProteinDomain( e1 );
2254             p00.addProteinDomain( e2 );
2255             p00.addProteinDomain( e3 );
2256             p00.addProteinDomain( e4 );
2257             p00.addProteinDomain( e5 );
2258             p00.addProteinDomain( z0 );
2259             p00.addProteinDomain( z1 );
2260             p00.addProteinDomain( z2 );
2261             p00.addProteinDomain( zz0 );
2262             p00.addProteinDomain( zz1 );
2263             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2264                 return false;
2265             }
2266             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2267                 return false;
2268             }
2269             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2270                 return false;
2271             }
2272             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2273                 return false;
2274             }
2275             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" ) ) {
2276                 return false;
2277             }
2278             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2279             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2280             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2281             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2282             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2283             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2284             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2285             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2286             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2287             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2288             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2289             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2290             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2291             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2292             p.addProteinDomain( B15 );
2293             p.addProteinDomain( C50 );
2294             p.addProteinDomain( A60 );
2295             p.addProteinDomain( A30 );
2296             p.addProteinDomain( C70 );
2297             p.addProteinDomain( B35 );
2298             p.addProteinDomain( B40 );
2299             p.addProteinDomain( A0 );
2300             p.addProteinDomain( A10 );
2301             p.addProteinDomain( A20 );
2302             p.addProteinDomain( B25 );
2303             p.addProteinDomain( D80 );
2304             List<String> domains_ids = new ArrayList<String>();
2305             domains_ids.add( "A" );
2306             domains_ids.add( "B" );
2307             domains_ids.add( "C" );
2308             if ( !p.contains( domains_ids, false ) ) {
2309                 return false;
2310             }
2311             if ( !p.contains( domains_ids, true ) ) {
2312                 return false;
2313             }
2314             domains_ids.add( "X" );
2315             if ( p.contains( domains_ids, false ) ) {
2316                 return false;
2317             }
2318             if ( p.contains( domains_ids, true ) ) {
2319                 return false;
2320             }
2321             domains_ids = new ArrayList<String>();
2322             domains_ids.add( "A" );
2323             domains_ids.add( "C" );
2324             domains_ids.add( "D" );
2325             if ( !p.contains( domains_ids, false ) ) {
2326                 return false;
2327             }
2328             if ( !p.contains( domains_ids, true ) ) {
2329                 return false;
2330             }
2331             domains_ids = new ArrayList<String>();
2332             domains_ids.add( "A" );
2333             domains_ids.add( "D" );
2334             domains_ids.add( "C" );
2335             if ( !p.contains( domains_ids, false ) ) {
2336                 return false;
2337             }
2338             if ( p.contains( domains_ids, true ) ) {
2339                 return false;
2340             }
2341             domains_ids = new ArrayList<String>();
2342             domains_ids.add( "A" );
2343             domains_ids.add( "A" );
2344             domains_ids.add( "B" );
2345             if ( !p.contains( domains_ids, false ) ) {
2346                 return false;
2347             }
2348             if ( !p.contains( domains_ids, true ) ) {
2349                 return false;
2350             }
2351             domains_ids = new ArrayList<String>();
2352             domains_ids.add( "A" );
2353             domains_ids.add( "A" );
2354             domains_ids.add( "A" );
2355             domains_ids.add( "B" );
2356             domains_ids.add( "B" );
2357             if ( !p.contains( domains_ids, false ) ) {
2358                 return false;
2359             }
2360             if ( !p.contains( domains_ids, true ) ) {
2361                 return false;
2362             }
2363             domains_ids = new ArrayList<String>();
2364             domains_ids.add( "A" );
2365             domains_ids.add( "A" );
2366             domains_ids.add( "B" );
2367             domains_ids.add( "A" );
2368             domains_ids.add( "B" );
2369             domains_ids.add( "B" );
2370             domains_ids.add( "A" );
2371             domains_ids.add( "B" );
2372             domains_ids.add( "C" );
2373             domains_ids.add( "A" );
2374             domains_ids.add( "C" );
2375             domains_ids.add( "D" );
2376             if ( !p.contains( domains_ids, false ) ) {
2377                 return false;
2378             }
2379             if ( p.contains( domains_ids, true ) ) {
2380                 return false;
2381             }
2382         }
2383         catch ( final Exception e ) {
2384             e.printStackTrace( System.out );
2385             return false;
2386         }
2387         return true;
2388     }
2389
2390     private static boolean testBasicTable() {
2391         try {
2392             final BasicTable<String> t0 = new BasicTable<String>();
2393             if ( t0.getNumberOfColumns() != 0 ) {
2394                 return false;
2395             }
2396             if ( t0.getNumberOfRows() != 0 ) {
2397                 return false;
2398             }
2399             t0.setValue( 3, 2, "23" );
2400             t0.setValue( 10, 1, "error" );
2401             t0.setValue( 10, 1, "110" );
2402             t0.setValue( 9, 1, "19" );
2403             t0.setValue( 1, 10, "101" );
2404             t0.setValue( 10, 10, "1010" );
2405             t0.setValue( 100, 10, "10100" );
2406             t0.setValue( 0, 0, "00" );
2407             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2408                 return false;
2409             }
2410             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2411                 return false;
2412             }
2413             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2414                 return false;
2415             }
2416             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2417                 return false;
2418             }
2419             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2420                 return false;
2421             }
2422             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2423                 return false;
2424             }
2425             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2426                 return false;
2427             }
2428             if ( t0.getNumberOfColumns() != 101 ) {
2429                 return false;
2430             }
2431             if ( t0.getNumberOfRows() != 11 ) {
2432                 return false;
2433             }
2434             if ( t0.getValueAsString( 49, 4 ) != null ) {
2435                 return false;
2436             }
2437             final String l = ForesterUtil.getLineSeparator();
2438             final StringBuffer source = new StringBuffer();
2439             source.append( "" + l );
2440             source.append( "# 1 1 1 1 1 1 1 1" + l );
2441             source.append( " 00 01 02 03" + l );
2442             source.append( "   10 11 12 13  " + l );
2443             source.append( "20 21 22 23 " + l );
2444             source.append( "    30  31    32 33" + l );
2445             source.append( "40 41 42 43" + l );
2446             source.append( "  # 1 1 1 1 1 " + l );
2447             source.append( "50 51 52 53 54" + l );
2448             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2449             if ( t1.getNumberOfColumns() != 5 ) {
2450                 return false;
2451             }
2452             if ( t1.getNumberOfRows() != 6 ) {
2453                 return false;
2454             }
2455             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2456                 return false;
2457             }
2458             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2459                 return false;
2460             }
2461             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2462                 return false;
2463             }
2464             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2465                 return false;
2466             }
2467             final StringBuffer source1 = new StringBuffer();
2468             source1.append( "" + l );
2469             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2470             source1.append( " 00; 01 ;02;03" + l );
2471             source1.append( "   10; 11; 12; 13  " + l );
2472             source1.append( "20; 21; 22; 23 " + l );
2473             source1.append( "    30;  31;    32; 33" + l );
2474             source1.append( "40;41;42;43" + l );
2475             source1.append( "  # 1 1 1 1 1 " + l );
2476             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2477             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2478             if ( t2.getNumberOfColumns() != 5 ) {
2479                 return false;
2480             }
2481             if ( t2.getNumberOfRows() != 6 ) {
2482                 return false;
2483             }
2484             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2485                 return false;
2486             }
2487             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2488                 return false;
2489             }
2490             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2491                 return false;
2492             }
2493             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2494                 return false;
2495             }
2496             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2497                 return false;
2498             }
2499             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2500                 return false;
2501             }
2502             final StringBuffer source2 = new StringBuffer();
2503             source2.append( "" + l );
2504             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2505             source2.append( " 00; 01 ;02;03" + l );
2506             source2.append( "   10; 11; 12; 13  " + l );
2507             source2.append( "20; 21; 22; 23 " + l );
2508             source2.append( "                     " + l );
2509             source2.append( "    30;  31;    32; 33" + l );
2510             source2.append( "40;41;42;43" + l );
2511             source2.append( "  comment: 1 1 1 1 1 " + l );
2512             source2.append( ";;;50  ;   52; 53;;54   " + l );
2513             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2514                                                                         ';',
2515                                                                         false,
2516                                                                         false,
2517                                                                         "comment:",
2518                                                                         false );
2519             if ( tl.size() != 2 ) {
2520                 return false;
2521             }
2522             final BasicTable<String> t3 = tl.get( 0 );
2523             final BasicTable<String> t4 = tl.get( 1 );
2524             if ( t3.getNumberOfColumns() != 4 ) {
2525                 return false;
2526             }
2527             if ( t3.getNumberOfRows() != 3 ) {
2528                 return false;
2529             }
2530             if ( t4.getNumberOfColumns() != 4 ) {
2531                 return false;
2532             }
2533             if ( t4.getNumberOfRows() != 3 ) {
2534                 return false;
2535             }
2536             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2537                 return false;
2538             }
2539             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2540                 return false;
2541             }
2542         }
2543         catch ( final Exception e ) {
2544             e.printStackTrace( System.out );
2545             return false;
2546         }
2547         return true;
2548     }
2549
2550     private static boolean testBasicTolXMLparsing() {
2551         try {
2552             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2553             final TolParser parser = new TolParser();
2554             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2555             if ( parser.getErrorCount() > 0 ) {
2556                 System.out.println( parser.getErrorMessages().toString() );
2557                 return false;
2558             }
2559             if ( phylogenies_0.length != 1 ) {
2560                 return false;
2561             }
2562             final Phylogeny t1 = phylogenies_0[ 0 ];
2563             if ( t1.getNumberOfExternalNodes() != 5 ) {
2564                 return false;
2565             }
2566             if ( !t1.isRooted() ) {
2567                 return false;
2568             }
2569             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2570                 return false;
2571             }
2572             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2573                 return false;
2574             }
2575             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2576                 return false;
2577             }
2578             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2579                 return false;
2580             }
2581             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2582             if ( parser.getErrorCount() > 0 ) {
2583                 System.out.println( parser.getErrorMessages().toString() );
2584                 return false;
2585             }
2586             if ( phylogenies_1.length != 1 ) {
2587                 return false;
2588             }
2589             final Phylogeny t2 = phylogenies_1[ 0 ];
2590             if ( t2.getNumberOfExternalNodes() != 664 ) {
2591                 return false;
2592             }
2593             if ( !t2.isRooted() ) {
2594                 return false;
2595             }
2596             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2597                 return false;
2598             }
2599             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2600                 return false;
2601             }
2602             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2603                 return false;
2604             }
2605             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2606                 return false;
2607             }
2608             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2609                 return false;
2610             }
2611             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2612                     .equals( "Aquifex" ) ) {
2613                 return false;
2614             }
2615             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2616             if ( parser.getErrorCount() > 0 ) {
2617                 System.out.println( parser.getErrorMessages().toString() );
2618                 return false;
2619             }
2620             if ( phylogenies_2.length != 1 ) {
2621                 return false;
2622             }
2623             final Phylogeny t3 = phylogenies_2[ 0 ];
2624             if ( t3.getNumberOfExternalNodes() != 184 ) {
2625                 return false;
2626             }
2627             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2628                 return false;
2629             }
2630             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2631                 return false;
2632             }
2633             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2634                 return false;
2635             }
2636             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2637             if ( parser.getErrorCount() > 0 ) {
2638                 System.out.println( parser.getErrorMessages().toString() );
2639                 return false;
2640             }
2641             if ( phylogenies_3.length != 1 ) {
2642                 return false;
2643             }
2644             final Phylogeny t4 = phylogenies_3[ 0 ];
2645             if ( t4.getNumberOfExternalNodes() != 1 ) {
2646                 return false;
2647             }
2648             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2649                 return false;
2650             }
2651             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2652                 return false;
2653             }
2654             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2655                 return false;
2656             }
2657             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2658             if ( parser.getErrorCount() > 0 ) {
2659                 System.out.println( parser.getErrorMessages().toString() );
2660                 return false;
2661             }
2662             if ( phylogenies_4.length != 1 ) {
2663                 return false;
2664             }
2665             final Phylogeny t5 = phylogenies_4[ 0 ];
2666             if ( t5.getNumberOfExternalNodes() != 13 ) {
2667                 return false;
2668             }
2669             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2670                 return false;
2671             }
2672             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2673                 return false;
2674             }
2675             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2676                 return false;
2677             }
2678         }
2679         catch ( final Exception e ) {
2680             e.printStackTrace( System.out );
2681             return false;
2682         }
2683         return true;
2684     }
2685
2686     private static boolean testBasicTreeMethods() {
2687         try {
2688             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2689             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2690             if ( t2.getNumberOfExternalNodes() != 4 ) {
2691                 return false;
2692             }
2693             if ( t2.getHeight() != 8.5 ) {
2694                 return false;
2695             }
2696             if ( !t2.isCompletelyBinary() ) {
2697                 return false;
2698             }
2699             if ( t2.isEmpty() ) {
2700                 return false;
2701             }
2702             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2703             if ( t3.getNumberOfExternalNodes() != 5 ) {
2704                 return false;
2705             }
2706             if ( t3.getHeight() != 11 ) {
2707                 return false;
2708             }
2709             if ( t3.isCompletelyBinary() ) {
2710                 return false;
2711             }
2712             final PhylogenyNode n = t3.getNode( "ABC" );
2713             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 ];
2714             if ( t4.getNumberOfExternalNodes() != 9 ) {
2715                 return false;
2716             }
2717             if ( t4.getHeight() != 11 ) {
2718                 return false;
2719             }
2720             if ( t4.isCompletelyBinary() ) {
2721                 return false;
2722             }
2723             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)" );
2724             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2725             if ( t5.getNumberOfExternalNodes() != 8 ) {
2726                 return false;
2727             }
2728             if ( t5.getHeight() != 15 ) {
2729                 return false;
2730             }
2731             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)" );
2732             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2733             if ( t6.getHeight() != 15 ) {
2734                 return false;
2735             }
2736             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)" );
2737             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2738             if ( t7.getHeight() != 15 ) {
2739                 return false;
2740             }
2741             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)" );
2742             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2743             if ( t8.getNumberOfExternalNodes() != 10 ) {
2744                 return false;
2745             }
2746             if ( t8.getHeight() != 15 ) {
2747                 return false;
2748             }
2749             final char[] a9 = new char[] { 'a' };
2750             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2751             if ( t9.getHeight() != 0 ) {
2752                 return false;
2753             }
2754             final char[] a10 = new char[] { 'a', ':', '6' };
2755             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2756             if ( t10.getHeight() != 6 ) {
2757                 return false;
2758             }
2759         }
2760         catch ( final Exception e ) {
2761             e.printStackTrace( System.out );
2762             return false;
2763         }
2764         return true;
2765     }
2766
2767     private static boolean testConfidenceAssessor() {
2768         try {
2769             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2770             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2771             final Phylogeny[] ev0 = factory
2772                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2773                              new NHXParser() );
2774             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2775             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2776                 return false;
2777             }
2778             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2779                 return false;
2780             }
2781             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2782             final Phylogeny[] ev1 = factory
2783                     .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)));",
2784                              new NHXParser() );
2785             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2786             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2787                 return false;
2788             }
2789             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2790                 return false;
2791             }
2792             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2793             final Phylogeny[] ev_b = factory
2794                     .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",
2795                              new NHXParser() );
2796             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2797             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2798                 return false;
2799             }
2800             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2801                 return false;
2802             }
2803             //
2804             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2805             final Phylogeny[] ev1x = factory
2806                     .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)));",
2807                              new NHXParser() );
2808             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2809             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2810                 return false;
2811             }
2812             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2813                 return false;
2814             }
2815             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2816             final Phylogeny[] ev_bx = factory
2817                     .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",
2818                              new NHXParser() );
2819             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2820             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2821                 return false;
2822             }
2823             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2824                 return false;
2825             }
2826             //
2827             final Phylogeny[] t2 = factory
2828                     .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);",
2829                              new NHXParser() );
2830             final Phylogeny[] ev2 = factory
2831                     .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);",
2832                              new NHXParser() );
2833             for( final Phylogeny target : t2 ) {
2834                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2835             }
2836             //
2837             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2838                                                  new NHXParser() )[ 0 ];
2839             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2840             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2841             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2842                 return false;
2843             }
2844             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2845                 return false;
2846             }
2847             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2848                 return false;
2849             }
2850         }
2851         catch ( final Exception e ) {
2852             e.printStackTrace();
2853             return false;
2854         }
2855         return true;
2856     }
2857
2858     private static boolean testCopyOfNodeData() {
2859         try {
2860             final PhylogenyNode n1 = PhylogenyNode
2861                     .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]" );
2862             final PhylogenyNode n2 = n1.copyNodeData();
2863             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2864                 return false;
2865             }
2866         }
2867         catch ( final Exception e ) {
2868             e.printStackTrace();
2869             return false;
2870         }
2871         return true;
2872     }
2873
2874     private static boolean testCreateBalancedPhylogeny() {
2875         try {
2876             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
2877             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
2878                 return false;
2879             }
2880             if ( p0.getNumberOfExternalNodes() != 15625 ) {
2881                 return false;
2882             }
2883             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
2884             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
2885                 return false;
2886             }
2887             if ( p1.getNumberOfExternalNodes() != 100 ) {
2888                 return false;
2889             }
2890         }
2891         catch ( final Exception e ) {
2892             e.printStackTrace();
2893             return false;
2894         }
2895         return true;
2896     }
2897
2898     private static boolean testCreateUriForSeqWeb() {
2899         try {
2900             final PhylogenyNode n = new PhylogenyNode();
2901             n.setName( "tr|B3RJ64" );
2902             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
2903                 return false;
2904             }
2905             n.setName( "B0LM41_HUMAN" );
2906             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
2907                 return false;
2908             }
2909             n.setName( "NP_001025424" );
2910             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
2911                 return false;
2912             }
2913             n.setName( "_NM_001030253-" );
2914             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
2915                 return false;
2916             }
2917             n.setName( "XM_002122186" );
2918             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
2919                 return false;
2920             }
2921             n.setName( "dgh_AAA34956_gdg" );
2922             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2923                 return false;
2924             }
2925             n.setName( "AAA34956" );
2926             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2927                 return false;
2928             }
2929             n.setName( "GI:394892" );
2930             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2931                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2932                 return false;
2933             }
2934             n.setName( "gi_394892" );
2935             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2936                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2937                 return false;
2938             }
2939             n.setName( "gi6335_gi_394892_56635_Gi_43" );
2940             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2941                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2942                 return false;
2943             }
2944             n.setName( "P12345" );
2945             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2946                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2947                 return false;
2948             }
2949             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
2950             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2951                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2952                 return false;
2953             }
2954         }
2955         catch ( final Exception e ) {
2956             e.printStackTrace( System.out );
2957             return false;
2958         }
2959         return true;
2960     }
2961
2962     private static boolean testDataObjects() {
2963         try {
2964             final Confidence s0 = new Confidence();
2965             final Confidence s1 = new Confidence();
2966             if ( !s0.isEqual( s1 ) ) {
2967                 return false;
2968             }
2969             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2970             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2971             if ( s2.isEqual( s1 ) ) {
2972                 return false;
2973             }
2974             if ( !s2.isEqual( s3 ) ) {
2975                 return false;
2976             }
2977             final Confidence s4 = ( Confidence ) s3.copy();
2978             if ( !s4.isEqual( s3 ) ) {
2979                 return false;
2980             }
2981             s3.asSimpleText();
2982             s3.asText();
2983             // Taxonomy
2984             // ----------
2985             final Taxonomy t1 = new Taxonomy();
2986             final Taxonomy t2 = new Taxonomy();
2987             final Taxonomy t3 = new Taxonomy();
2988             final Taxonomy t4 = new Taxonomy();
2989             final Taxonomy t5 = new Taxonomy();
2990             t1.setIdentifier( new Identifier( "ecoli" ) );
2991             t1.setTaxonomyCode( "ECOLI" );
2992             t1.setScientificName( "E. coli" );
2993             t1.setCommonName( "coli" );
2994             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2995             if ( !t1.isEqual( t0 ) ) {
2996                 return false;
2997             }
2998             t2.setIdentifier( new Identifier( "ecoli" ) );
2999             t2.setTaxonomyCode( "OTHER" );
3000             t2.setScientificName( "what" );
3001             t2.setCommonName( "something" );
3002             if ( !t1.isEqual( t2 ) ) {
3003                 return false;
3004             }
3005             t2.setIdentifier( new Identifier( "nemve" ) );
3006             if ( t1.isEqual( t2 ) ) {
3007                 return false;
3008             }
3009             t1.setIdentifier( null );
3010             t3.setTaxonomyCode( "ECOLI" );
3011             t3.setScientificName( "what" );
3012             t3.setCommonName( "something" );
3013             if ( !t1.isEqual( t3 ) ) {
3014                 return false;
3015             }
3016             t1.setIdentifier( null );
3017             t1.setTaxonomyCode( "" );
3018             t4.setScientificName( "E. ColI" );
3019             t4.setCommonName( "something" );
3020             if ( !t1.isEqual( t4 ) ) {
3021                 return false;
3022             }
3023             t4.setScientificName( "B. subtilis" );
3024             t4.setCommonName( "something" );
3025             if ( t1.isEqual( t4 ) ) {
3026                 return false;
3027             }
3028             t1.setIdentifier( null );
3029             t1.setTaxonomyCode( "" );
3030             t1.setScientificName( "" );
3031             t5.setCommonName( "COLI" );
3032             if ( !t1.isEqual( t5 ) ) {
3033                 return false;
3034             }
3035             t5.setCommonName( "vibrio" );
3036             if ( t1.isEqual( t5 ) ) {
3037                 return false;
3038             }
3039             // Identifier
3040             // ----------
3041             final Identifier id0 = new Identifier( "123", "pfam" );
3042             final Identifier id1 = ( Identifier ) id0.copy();
3043             if ( !id1.isEqual( id1 ) ) {
3044                 return false;
3045             }
3046             if ( !id1.isEqual( id0 ) ) {
3047                 return false;
3048             }
3049             if ( !id0.isEqual( id1 ) ) {
3050                 return false;
3051             }
3052             id1.asSimpleText();
3053             id1.asText();
3054             // ProteinDomain
3055             // ---------------
3056             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3057             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3058             if ( !pd1.isEqual( pd1 ) ) {
3059                 return false;
3060             }
3061             if ( !pd1.isEqual( pd0 ) ) {
3062                 return false;
3063             }
3064             pd1.asSimpleText();
3065             pd1.asText();
3066             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3067             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3068             if ( !pd3.isEqual( pd3 ) ) {
3069                 return false;
3070             }
3071             if ( !pd2.isEqual( pd3 ) ) {
3072                 return false;
3073             }
3074             if ( !pd0.isEqual( pd3 ) ) {
3075                 return false;
3076             }
3077             pd3.asSimpleText();
3078             pd3.asText();
3079             // DomainArchitecture
3080             // ------------------
3081             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3082             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3083             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3084             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3085             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3086             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3087             domains0.add( d2 );
3088             domains0.add( d0 );
3089             domains0.add( d3 );
3090             domains0.add( d1 );
3091             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3092             if ( ds0.getNumberOfDomains() != 4 ) {
3093                 return false;
3094             }
3095             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3096             if ( !ds0.isEqual( ds0 ) ) {
3097                 return false;
3098             }
3099             if ( !ds0.isEqual( ds1 ) ) {
3100                 return false;
3101             }
3102             if ( ds1.getNumberOfDomains() != 4 ) {
3103                 return false;
3104             }
3105             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3106             domains1.add( d1 );
3107             domains1.add( d2 );
3108             domains1.add( d4 );
3109             domains1.add( d0 );
3110             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3111             if ( ds0.isEqual( ds2 ) ) {
3112                 return false;
3113             }
3114             ds1.asSimpleText();
3115             ds1.asText();
3116             ds1.toNHX();
3117             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3118             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3119                 System.out.println( ds3.toNHX() );
3120                 return false;
3121             }
3122             if ( ds3.getNumberOfDomains() != 3 ) {
3123                 return false;
3124             }
3125             // Event
3126             // -----
3127             final Event e1 = new Event( Event.EventType.fusion );
3128             if ( e1.isDuplication() ) {
3129                 return false;
3130             }
3131             if ( !e1.isFusion() ) {
3132                 return false;
3133             }
3134             if ( !e1.asText().toString().equals( "fusion" ) ) {
3135                 return false;
3136             }
3137             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3138                 return false;
3139             }
3140             final Event e11 = new Event( Event.EventType.fusion );
3141             if ( !e11.isEqual( e1 ) ) {
3142                 return false;
3143             }
3144             if ( !e11.toNHX().toString().equals( "" ) ) {
3145                 return false;
3146             }
3147             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3148             if ( e2.isDuplication() ) {
3149                 return false;
3150             }
3151             if ( !e2.isSpeciationOrDuplication() ) {
3152                 return false;
3153             }
3154             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3155                 return false;
3156             }
3157             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3158                 return false;
3159             }
3160             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3161                 return false;
3162             }
3163             if ( e11.isEqual( e2 ) ) {
3164                 return false;
3165             }
3166             final Event e2c = ( Event ) e2.copy();
3167             if ( !e2c.isEqual( e2 ) ) {
3168                 return false;
3169             }
3170             Event e3 = new Event( 1, 2, 3 );
3171             if ( e3.isDuplication() ) {
3172                 return false;
3173             }
3174             if ( e3.isSpeciation() ) {
3175                 return false;
3176             }
3177             if ( e3.isGeneLoss() ) {
3178                 return false;
3179             }
3180             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3181                 return false;
3182             }
3183             final Event e3c = ( Event ) e3.copy();
3184             final Event e3cc = ( Event ) e3c.copy();
3185             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3186                 return false;
3187             }
3188             e3 = null;
3189             if ( !e3c.isEqual( e3cc ) ) {
3190                 return false;
3191             }
3192             Event e4 = new Event( 1, 2, 3 );
3193             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3194                 return false;
3195             }
3196             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3197                 return false;
3198             }
3199             final Event e4c = ( Event ) e4.copy();
3200             e4 = null;
3201             final Event e4cc = ( Event ) e4c.copy();
3202             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3203                 return false;
3204             }
3205             if ( !e4c.isEqual( e4cc ) ) {
3206                 return false;
3207             }
3208             final Event e5 = new Event();
3209             if ( !e5.isUnassigned() ) {
3210                 return false;
3211             }
3212             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3213                 return false;
3214             }
3215             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3216                 return false;
3217             }
3218             final Event e6 = new Event( 1, 0, 0 );
3219             if ( !e6.asText().toString().equals( "duplication" ) ) {
3220                 return false;
3221             }
3222             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3223                 return false;
3224             }
3225             final Event e7 = new Event( 0, 1, 0 );
3226             if ( !e7.asText().toString().equals( "speciation" ) ) {
3227                 return false;
3228             }
3229             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3230                 return false;
3231             }
3232             final Event e8 = new Event( 0, 0, 1 );
3233             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3234                 return false;
3235             }
3236             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3237                 return false;
3238             }
3239         }
3240         catch ( final Exception e ) {
3241             e.printStackTrace( System.out );
3242             return false;
3243         }
3244         return true;
3245     }
3246
3247     private static boolean testDeletionOfExternalNodes() {
3248         try {
3249             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3250             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3251             final PhylogenyWriter w = new PhylogenyWriter();
3252             if ( t0.isEmpty() ) {
3253                 return false;
3254             }
3255             if ( t0.getNumberOfExternalNodes() != 1 ) {
3256                 return false;
3257             }
3258             t0.deleteSubtree( t0.getNode( "A" ), false );
3259             if ( t0.getNumberOfExternalNodes() != 0 ) {
3260                 return false;
3261             }
3262             if ( !t0.isEmpty() ) {
3263                 return false;
3264             }
3265             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3266             if ( t1.getNumberOfExternalNodes() != 2 ) {
3267                 return false;
3268             }
3269             t1.deleteSubtree( t1.getNode( "A" ), false );
3270             if ( t1.getNumberOfExternalNodes() != 1 ) {
3271                 return false;
3272             }
3273             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3274                 return false;
3275             }
3276             t1.deleteSubtree( t1.getNode( "B" ), false );
3277             if ( t1.getNumberOfExternalNodes() != 1 ) {
3278                 return false;
3279             }
3280             t1.deleteSubtree( t1.getNode( "r" ), false );
3281             if ( !t1.isEmpty() ) {
3282                 return false;
3283             }
3284             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3285             if ( t2.getNumberOfExternalNodes() != 3 ) {
3286                 return false;
3287             }
3288             t2.deleteSubtree( t2.getNode( "B" ), false );
3289             if ( t2.getNumberOfExternalNodes() != 2 ) {
3290                 return false;
3291             }
3292             t2.toNewHampshireX();
3293             PhylogenyNode n = t2.getNode( "A" );
3294             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3295                 return false;
3296             }
3297             t2.deleteSubtree( t2.getNode( "A" ), false );
3298             if ( t2.getNumberOfExternalNodes() != 2 ) {
3299                 return false;
3300             }
3301             t2.deleteSubtree( t2.getNode( "C" ), true );
3302             if ( t2.getNumberOfExternalNodes() != 1 ) {
3303                 return false;
3304             }
3305             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3306             if ( t3.getNumberOfExternalNodes() != 4 ) {
3307                 return false;
3308             }
3309             t3.deleteSubtree( t3.getNode( "B" ), true );
3310             if ( t3.getNumberOfExternalNodes() != 3 ) {
3311                 return false;
3312             }
3313             n = t3.getNode( "A" );
3314             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3315                 return false;
3316             }
3317             n = n.getNextExternalNode();
3318             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3319                 return false;
3320             }
3321             t3.deleteSubtree( t3.getNode( "A" ), true );
3322             if ( t3.getNumberOfExternalNodes() != 2 ) {
3323                 return false;
3324             }
3325             n = t3.getNode( "C" );
3326             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3327                 return false;
3328             }
3329             t3.deleteSubtree( t3.getNode( "C" ), true );
3330             if ( t3.getNumberOfExternalNodes() != 1 ) {
3331                 return false;
3332             }
3333             t3.deleteSubtree( t3.getNode( "D" ), true );
3334             if ( t3.getNumberOfExternalNodes() != 0 ) {
3335                 return false;
3336             }
3337             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3338             if ( t4.getNumberOfExternalNodes() != 6 ) {
3339                 return false;
3340             }
3341             t4.deleteSubtree( t4.getNode( "B2" ), true );
3342             if ( t4.getNumberOfExternalNodes() != 5 ) {
3343                 return false;
3344             }
3345             String s = w.toNewHampshire( t4, false, true ).toString();
3346             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3347                 return false;
3348             }
3349             t4.deleteSubtree( t4.getNode( "B11" ), true );
3350             if ( t4.getNumberOfExternalNodes() != 4 ) {
3351                 return false;
3352             }
3353             t4.deleteSubtree( t4.getNode( "C" ), true );
3354             if ( t4.getNumberOfExternalNodes() != 3 ) {
3355                 return false;
3356             }
3357             n = t4.getNode( "A" );
3358             n = n.getNextExternalNode();
3359             if ( !n.getName().equals( "B12" ) ) {
3360                 return false;
3361             }
3362             n = n.getNextExternalNode();
3363             if ( !n.getName().equals( "D" ) ) {
3364                 return false;
3365             }
3366             s = w.toNewHampshire( t4, false, true ).toString();
3367             if ( !s.equals( "((A,B12),D);" ) ) {
3368                 return false;
3369             }
3370             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3371             t5.deleteSubtree( t5.getNode( "A" ), true );
3372             if ( t5.getNumberOfExternalNodes() != 5 ) {
3373                 return false;
3374             }
3375             s = w.toNewHampshire( t5, false, true ).toString();
3376             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3377                 return false;
3378             }
3379             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3380             t6.deleteSubtree( t6.getNode( "B11" ), true );
3381             if ( t6.getNumberOfExternalNodes() != 5 ) {
3382                 return false;
3383             }
3384             s = w.toNewHampshire( t6, false, false ).toString();
3385             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3386                 return false;
3387             }
3388             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3389             t7.deleteSubtree( t7.getNode( "B12" ), true );
3390             if ( t7.getNumberOfExternalNodes() != 5 ) {
3391                 return false;
3392             }
3393             s = w.toNewHampshire( t7, false, true ).toString();
3394             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3395                 return false;
3396             }
3397             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3398             t8.deleteSubtree( t8.getNode( "B2" ), true );
3399             if ( t8.getNumberOfExternalNodes() != 5 ) {
3400                 return false;
3401             }
3402             s = w.toNewHampshire( t8, false, false ).toString();
3403             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3404                 return false;
3405             }
3406             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3407             t9.deleteSubtree( t9.getNode( "C" ), true );
3408             if ( t9.getNumberOfExternalNodes() != 5 ) {
3409                 return false;
3410             }
3411             s = w.toNewHampshire( t9, false, true ).toString();
3412             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3413                 return false;
3414             }
3415             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3416             t10.deleteSubtree( t10.getNode( "D" ), true );
3417             if ( t10.getNumberOfExternalNodes() != 5 ) {
3418                 return false;
3419             }
3420             s = w.toNewHampshire( t10, false, true ).toString();
3421             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3422                 return false;
3423             }
3424             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3425             t11.deleteSubtree( t11.getNode( "A" ), true );
3426             if ( t11.getNumberOfExternalNodes() != 2 ) {
3427                 return false;
3428             }
3429             s = w.toNewHampshire( t11, false, true ).toString();
3430             if ( !s.equals( "(B,C);" ) ) {
3431                 return false;
3432             }
3433             t11.deleteSubtree( t11.getNode( "C" ), true );
3434             if ( t11.getNumberOfExternalNodes() != 1 ) {
3435                 return false;
3436             }
3437             s = w.toNewHampshire( t11, false, false ).toString();
3438             if ( !s.equals( "B;" ) ) {
3439                 return false;
3440             }
3441             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3442             t12.deleteSubtree( t12.getNode( "B2" ), true );
3443             if ( t12.getNumberOfExternalNodes() != 8 ) {
3444                 return false;
3445             }
3446             s = w.toNewHampshire( t12, false, true ).toString();
3447             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3448                 return false;
3449             }
3450             t12.deleteSubtree( t12.getNode( "B3" ), true );
3451             if ( t12.getNumberOfExternalNodes() != 7 ) {
3452                 return false;
3453             }
3454             s = w.toNewHampshire( t12, false, true ).toString();
3455             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3456                 return false;
3457             }
3458             t12.deleteSubtree( t12.getNode( "C3" ), true );
3459             if ( t12.getNumberOfExternalNodes() != 6 ) {
3460                 return false;
3461             }
3462             s = w.toNewHampshire( t12, false, true ).toString();
3463             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3464                 return false;
3465             }
3466             t12.deleteSubtree( t12.getNode( "A1" ), true );
3467             if ( t12.getNumberOfExternalNodes() != 5 ) {
3468                 return false;
3469             }
3470             s = w.toNewHampshire( t12, false, true ).toString();
3471             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3472                 return false;
3473             }
3474             t12.deleteSubtree( t12.getNode( "B1" ), true );
3475             if ( t12.getNumberOfExternalNodes() != 4 ) {
3476                 return false;
3477             }
3478             s = w.toNewHampshire( t12, false, true ).toString();
3479             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3480                 return false;
3481             }
3482             t12.deleteSubtree( t12.getNode( "A3" ), true );
3483             if ( t12.getNumberOfExternalNodes() != 3 ) {
3484                 return false;
3485             }
3486             s = w.toNewHampshire( t12, false, true ).toString();
3487             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3488                 return false;
3489             }
3490             t12.deleteSubtree( t12.getNode( "A2" ), true );
3491             if ( t12.getNumberOfExternalNodes() != 2 ) {
3492                 return false;
3493             }
3494             s = w.toNewHampshire( t12, false, true ).toString();
3495             if ( !s.equals( "(C1,C2);" ) ) {
3496                 return false;
3497             }
3498             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3499             t13.deleteSubtree( t13.getNode( "D" ), true );
3500             if ( t13.getNumberOfExternalNodes() != 4 ) {
3501                 return false;
3502             }
3503             s = w.toNewHampshire( t13, false, true ).toString();
3504             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3505                 return false;
3506             }
3507             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3508             t14.deleteSubtree( t14.getNode( "E" ), true );
3509             if ( t14.getNumberOfExternalNodes() != 5 ) {
3510                 return false;
3511             }
3512             s = w.toNewHampshire( t14, false, true ).toString();
3513             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3514                 return false;
3515             }
3516             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3517             t15.deleteSubtree( t15.getNode( "B2" ), true );
3518             if ( t15.getNumberOfExternalNodes() != 11 ) {
3519                 return false;
3520             }
3521             t15.deleteSubtree( t15.getNode( "B1" ), true );
3522             if ( t15.getNumberOfExternalNodes() != 10 ) {
3523                 return false;
3524             }
3525             t15.deleteSubtree( t15.getNode( "B3" ), true );
3526             if ( t15.getNumberOfExternalNodes() != 9 ) {
3527                 return false;
3528             }
3529             t15.deleteSubtree( t15.getNode( "B4" ), true );
3530             if ( t15.getNumberOfExternalNodes() != 8 ) {
3531                 return false;
3532             }
3533             t15.deleteSubtree( t15.getNode( "A1" ), true );
3534             if ( t15.getNumberOfExternalNodes() != 7 ) {
3535                 return false;
3536             }
3537             t15.deleteSubtree( t15.getNode( "C4" ), true );
3538             if ( t15.getNumberOfExternalNodes() != 6 ) {
3539                 return false;
3540             }
3541         }
3542         catch ( final Exception e ) {
3543             e.printStackTrace( System.out );
3544             return false;
3545         }
3546         return true;
3547     }
3548
3549     private static boolean testDescriptiveStatistics() {
3550         try {
3551             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3552             dss1.addValue( 82 );
3553             dss1.addValue( 78 );
3554             dss1.addValue( 70 );
3555             dss1.addValue( 58 );
3556             dss1.addValue( 42 );
3557             if ( dss1.getN() != 5 ) {
3558                 return false;
3559             }
3560             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3561                 return false;
3562             }
3563             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3564                 return false;
3565             }
3566             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3567                 return false;
3568             }
3569             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3570                 return false;
3571             }
3572             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3573                 return false;
3574             }
3575             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3576                 return false;
3577             }
3578             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3579                 return false;
3580             }
3581             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3582                 return false;
3583             }
3584             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3585                 return false;
3586             }
3587             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3588                 return false;
3589             }
3590             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3591                 return false;
3592             }
3593             dss1.addValue( 123 );
3594             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3595                 return false;
3596             }
3597             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3598                 return false;
3599             }
3600             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3601                 return false;
3602             }
3603             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3604             dss2.addValue( -1.85 );
3605             dss2.addValue( 57.5 );
3606             dss2.addValue( 92.78 );
3607             dss2.addValue( 57.78 );
3608             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3609                 return false;
3610             }
3611             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3612                 return false;
3613             }
3614             final double[] a = dss2.getDataAsDoubleArray();
3615             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3616                 return false;
3617             }
3618             dss2.addValue( -100 );
3619             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3620                 return false;
3621             }
3622             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3623                 return false;
3624             }
3625             final double[] ds = new double[ 14 ];
3626             ds[ 0 ] = 34;
3627             ds[ 1 ] = 23;
3628             ds[ 2 ] = 1;
3629             ds[ 3 ] = 32;
3630             ds[ 4 ] = 11;
3631             ds[ 5 ] = 2;
3632             ds[ 6 ] = 12;
3633             ds[ 7 ] = 33;
3634             ds[ 8 ] = 13;
3635             ds[ 9 ] = 22;
3636             ds[ 10 ] = 21;
3637             ds[ 11 ] = 35;
3638             ds[ 12 ] = 24;
3639             ds[ 13 ] = 31;
3640             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3641             if ( bins.length != 4 ) {
3642                 return false;
3643             }
3644             if ( bins[ 0 ] != 2 ) {
3645                 return false;
3646             }
3647             if ( bins[ 1 ] != 3 ) {
3648                 return false;
3649             }
3650             if ( bins[ 2 ] != 4 ) {
3651                 return false;
3652             }
3653             if ( bins[ 3 ] != 5 ) {
3654                 return false;
3655             }
3656             final double[] ds1 = new double[ 9 ];
3657             ds1[ 0 ] = 10.0;
3658             ds1[ 1 ] = 19.0;
3659             ds1[ 2 ] = 9.999;
3660             ds1[ 3 ] = 0.0;
3661             ds1[ 4 ] = 39.9;
3662             ds1[ 5 ] = 39.999;
3663             ds1[ 6 ] = 30.0;
3664             ds1[ 7 ] = 19.999;
3665             ds1[ 8 ] = 30.1;
3666             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3667             if ( bins1.length != 4 ) {
3668                 return false;
3669             }
3670             if ( bins1[ 0 ] != 2 ) {
3671                 return false;
3672             }
3673             if ( bins1[ 1 ] != 3 ) {
3674                 return false;
3675             }
3676             if ( bins1[ 2 ] != 0 ) {
3677                 return false;
3678             }
3679             if ( bins1[ 3 ] != 4 ) {
3680                 return false;
3681             }
3682             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3683             if ( bins1_1.length != 3 ) {
3684                 return false;
3685             }
3686             if ( bins1_1[ 0 ] != 3 ) {
3687                 return false;
3688             }
3689             if ( bins1_1[ 1 ] != 2 ) {
3690                 return false;
3691             }
3692             if ( bins1_1[ 2 ] != 4 ) {
3693                 return false;
3694             }
3695             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3696             if ( bins1_2.length != 3 ) {
3697                 return false;
3698             }
3699             if ( bins1_2[ 0 ] != 2 ) {
3700                 return false;
3701             }
3702             if ( bins1_2[ 1 ] != 2 ) {
3703                 return false;
3704             }
3705             if ( bins1_2[ 2 ] != 2 ) {
3706                 return false;
3707             }
3708             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3709             dss3.addValue( 1 );
3710             dss3.addValue( 1 );
3711             dss3.addValue( 1 );
3712             dss3.addValue( 2 );
3713             dss3.addValue( 3 );
3714             dss3.addValue( 4 );
3715             dss3.addValue( 5 );
3716             dss3.addValue( 5 );
3717             dss3.addValue( 5 );
3718             dss3.addValue( 6 );
3719             dss3.addValue( 7 );
3720             dss3.addValue( 8 );
3721             dss3.addValue( 9 );
3722             dss3.addValue( 10 );
3723             dss3.addValue( 10 );
3724             dss3.addValue( 10 );
3725             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3726             histo.toStringBuffer( 10, '=', 40, 5 );
3727             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3728         }
3729         catch ( final Exception e ) {
3730             e.printStackTrace( System.out );
3731             return false;
3732         }
3733         return true;
3734     }
3735
3736     private static boolean testDir( final String file ) {
3737         try {
3738             final File f = new File( file );
3739             if ( !f.exists() ) {
3740                 return false;
3741             }
3742             if ( !f.isDirectory() ) {
3743                 return false;
3744             }
3745             if ( !f.canRead() ) {
3746                 return false;
3747             }
3748         }
3749         catch ( final Exception e ) {
3750             return false;
3751         }
3752         return true;
3753     }
3754
3755     private static boolean testEbiEntryRetrieval() {
3756         try {
3757             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3758             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3759                 System.out.println( entry.getAccession() );
3760                 return false;
3761             }
3762             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3763                 System.out.println( entry.getTaxonomyScientificName() );
3764                 return false;
3765             }
3766             if ( !entry.getSequenceName()
3767                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3768                 System.out.println( entry.getSequenceName() );
3769                 return false;
3770             }
3771             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
3772             //     System.out.println( entry.getSequenceSymbol() );
3773             //     return false;
3774             // }
3775             if ( !entry.getGeneName().equals( "treX-like" ) ) {
3776                 System.out.println( entry.getGeneName() );
3777                 return false;
3778             }
3779             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
3780                 System.out.println( entry.getTaxonomyIdentifier() );
3781                 return false;
3782             }
3783             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
3784                 System.out.println( entry.getAnnotations().first().getRefValue() );
3785                 return false;
3786             }
3787             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
3788                 System.out.println( entry.getAnnotations().first().getRefSource() );
3789                 return false;
3790             }
3791             if ( entry.getCrossReferences().size() != 5 ) {
3792                 return false;
3793             }
3794             //
3795             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
3796             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
3797                 return false;
3798             }
3799             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
3800                 System.out.println( entry1.getTaxonomyScientificName() );
3801                 return false;
3802             }
3803             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
3804                 System.out.println( entry1.getSequenceName() );
3805                 return false;
3806             }
3807             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
3808                 System.out.println( entry1.getTaxonomyIdentifier() );
3809                 return false;
3810             }
3811             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
3812                 System.out.println( entry1.getGeneName() );
3813                 return false;
3814             }
3815             if ( entry1.getCrossReferences().size() != 6 ) {
3816                 return false;
3817             }
3818             //
3819             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
3820             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
3821                 return false;
3822             }
3823             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3824                 System.out.println( entry2.getTaxonomyScientificName() );
3825                 return false;
3826             }
3827             if ( !entry2.getSequenceName()
3828                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
3829                 System.out.println( entry2.getSequenceName() );
3830                 return false;
3831             }
3832             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
3833                 System.out.println( entry2.getTaxonomyIdentifier() );
3834                 return false;
3835             }
3836             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
3837                 System.out.println( entry2.getGeneName() );
3838                 return false;
3839             }
3840             if ( entry2.getCrossReferences().size() != 3 ) {
3841                 return false;
3842             }
3843             //
3844             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
3845             if ( !entry3.getAccession().equals( "HM043801" ) ) {
3846                 return false;
3847             }
3848             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
3849                 System.out.println( entry3.getTaxonomyScientificName() );
3850                 return false;
3851             }
3852             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
3853                 System.out.println( entry3.getSequenceName() );
3854                 return false;
3855             }
3856             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
3857                 System.out.println( entry3.getTaxonomyIdentifier() );
3858                 return false;
3859             }
3860             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
3861                 System.out.println( entry3.getSequenceSymbol() );
3862                 return false;
3863             }
3864             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
3865                 return false;
3866             }
3867             if ( entry3.getCrossReferences().size() != 8 ) {
3868                 return false;
3869             }
3870             //
3871             //
3872             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
3873             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
3874                 return false;
3875             }
3876             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3877                 System.out.println( entry4.getTaxonomyScientificName() );
3878                 return false;
3879             }
3880             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
3881                 System.out.println( entry4.getSequenceName() );
3882                 return false;
3883             }
3884             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
3885                 System.out.println( entry4.getTaxonomyIdentifier() );
3886                 return false;
3887             }
3888             if ( !entry4.getGeneName().equals( "ras" ) ) {
3889                 System.out.println( entry4.getGeneName() );
3890                 return false;
3891             }
3892             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
3893             //     System.out.println( entry4.getChromosome() );
3894             //     return false;
3895             // }
3896             // if ( !entry4.getMap().equals( "ras" ) ) {
3897             //     System.out.println( entry4.getMap() );
3898             //     return false;
3899             // }
3900             //TODO FIXME gi...
3901             //
3902             //TODO fails:
3903             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
3904             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
3905             //                return false;
3906             //            }
3907             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
3908             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
3909                 return false;
3910             }
3911             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
3912                 System.out.println( entry5.getTaxonomyScientificName() );
3913                 return false;
3914             }
3915             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
3916                 System.out.println( entry5.getSequenceName() );
3917                 return false;
3918             }
3919             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
3920                 System.out.println( entry5.getTaxonomyIdentifier() );
3921                 return false;
3922             }
3923         }
3924         catch ( final IOException e ) {
3925             System.out.println();
3926             System.out.println( "the following might be due to absence internet connection:" );
3927             e.printStackTrace( System.out );
3928             return true;
3929         }
3930         catch ( final Exception e ) {
3931             e.printStackTrace();
3932             return false;
3933         }
3934         return true;
3935     }
3936
3937     private static boolean testExternalNodeRelatedMethods() {
3938         try {
3939             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3940             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3941             PhylogenyNode n = t1.getNode( "A" );
3942             n = n.getNextExternalNode();
3943             if ( !n.getName().equals( "B" ) ) {
3944                 return false;
3945             }
3946             n = n.getNextExternalNode();
3947             if ( !n.getName().equals( "C" ) ) {
3948                 return false;
3949             }
3950             n = n.getNextExternalNode();
3951             if ( !n.getName().equals( "D" ) ) {
3952                 return false;
3953             }
3954             n = t1.getNode( "B" );
3955             while ( !n.isLastExternalNode() ) {
3956                 n = n.getNextExternalNode();
3957             }
3958             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3959             n = t2.getNode( "A" );
3960             n = n.getNextExternalNode();
3961             if ( !n.getName().equals( "B" ) ) {
3962                 return false;
3963             }
3964             n = n.getNextExternalNode();
3965             if ( !n.getName().equals( "C" ) ) {
3966                 return false;
3967             }
3968             n = n.getNextExternalNode();
3969             if ( !n.getName().equals( "D" ) ) {
3970                 return false;
3971             }
3972             n = t2.getNode( "B" );
3973             while ( !n.isLastExternalNode() ) {
3974                 n = n.getNextExternalNode();
3975             }
3976             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3977             n = t3.getNode( "A" );
3978             n = n.getNextExternalNode();
3979             if ( !n.getName().equals( "B" ) ) {
3980                 return false;
3981             }
3982             n = n.getNextExternalNode();
3983             if ( !n.getName().equals( "C" ) ) {
3984                 return false;
3985             }
3986             n = n.getNextExternalNode();
3987             if ( !n.getName().equals( "D" ) ) {
3988                 return false;
3989             }
3990             n = n.getNextExternalNode();
3991             if ( !n.getName().equals( "E" ) ) {
3992                 return false;
3993             }
3994             n = n.getNextExternalNode();
3995             if ( !n.getName().equals( "F" ) ) {
3996                 return false;
3997             }
3998             n = n.getNextExternalNode();
3999             if ( !n.getName().equals( "G" ) ) {
4000                 return false;
4001             }
4002             n = n.getNextExternalNode();
4003             if ( !n.getName().equals( "H" ) ) {
4004                 return false;
4005             }
4006             n = t3.getNode( "B" );
4007             while ( !n.isLastExternalNode() ) {
4008                 n = n.getNextExternalNode();
4009             }
4010             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4011             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4012                 final PhylogenyNode node = iter.next();
4013             }
4014             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4015             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4016                 final PhylogenyNode node = iter.next();
4017             }
4018             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4019             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4020             if ( !iter.next().getName().equals( "A" ) ) {
4021                 return false;
4022             }
4023             if ( !iter.next().getName().equals( "B" ) ) {
4024                 return false;
4025             }
4026             if ( !iter.next().getName().equals( "C" ) ) {
4027                 return false;
4028             }
4029             if ( !iter.next().getName().equals( "D" ) ) {
4030                 return false;
4031             }
4032             if ( !iter.next().getName().equals( "E" ) ) {
4033                 return false;
4034             }
4035             if ( !iter.next().getName().equals( "F" ) ) {
4036                 return false;
4037             }
4038             if ( iter.hasNext() ) {
4039                 return false;
4040             }
4041         }
4042         catch ( final Exception e ) {
4043             e.printStackTrace( System.out );
4044             return false;
4045         }
4046         return true;
4047     }
4048
4049     private static boolean testExtractSNFromNodeName() {
4050         try {
4051             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4052                 return false;
4053             }
4054             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
4055                     .equals( "Mus musculus musculus" ) ) {
4056                 return false;
4057             }
4058             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
4059                     .equals( "Mus musculus musculus" ) ) {
4060                 return false;
4061             }
4062             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
4063                 return false;
4064             }
4065             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
4066                     .equals( "Mus musculus" ) ) {
4067                 return false;
4068             }
4069             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4070                 return false;
4071             }
4072             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus" )
4073                     .equals( "Mus musculus musculus" ) ) {
4074                 return false;
4075             }
4076             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4077                 return false;
4078             }
4079         }
4080         catch ( final Exception e ) {
4081             e.printStackTrace( System.out );
4082             return false;
4083         }
4084         return true;
4085     }
4086
4087     private static boolean testExtractTaxonomyCodeFromNodeName() {
4088         try {
4089             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4090                 return false;
4091             }
4092             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4093                     .equals( "SOYBN" ) ) {
4094                 return false;
4095             }
4096             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4097                     .equals( "ARATH" ) ) {
4098                 return false;
4099             }
4100             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4101                     .equals( "ARATH" ) ) {
4102                 return false;
4103             }
4104             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4105                 return false;
4106             }
4107             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4108                 return false;
4109             }
4110             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4111                 return false;
4112             }
4113             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4114                     .equals( "SOYBN" ) ) {
4115                 return false;
4116             }
4117             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4118                     .equals( "SOYBN" ) ) {
4119                 return false;
4120             }
4121             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4122                     .equals( "SOYBN" ) ) {
4123                 return false;
4124             }
4125             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4126                     .equals( "SOYBN" ) ) {
4127                 return false;
4128             }
4129             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4130                     .equals( "SOYBN" ) ) {
4131                 return false;
4132             }
4133             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4134                     .equals( "SOYBN" ) ) {
4135                 return false;
4136             }
4137             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4138                     .equals( "SOYBN" ) ) {
4139                 return false;
4140             }
4141             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4142                     .equals( "SOYBN" ) ) {
4143                 return false;
4144             }
4145             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4146                 return false;
4147             }
4148             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4149                     .equals( "SOYBN" ) ) {
4150                 return false;
4151             }
4152             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4153                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4154                 return false;
4155             }
4156             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4157                     .equals( "9YX45" ) ) {
4158                 return false;
4159             }
4160             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4161                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4162                     .equals( "MOUSE" ) ) {
4163                 return false;
4164             }
4165             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4166                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4167                     .equals( "MOUSE" ) ) {
4168                 return false;
4169             }
4170             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4171                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4172                     .equals( "MOUSE" ) ) {
4173                 return false;
4174             }
4175             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4176                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4177                 return false;
4178             }
4179             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4180                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4181                 return false;
4182             }
4183             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4184                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4185                 return false;
4186             }
4187             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4188                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4189                 return false;
4190             }
4191             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4192                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4193                 return false;
4194             }
4195             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4196                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4197                 return false;
4198             }
4199             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4200                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4201                 return false;
4202             }
4203             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4204                     .equals( "RAT" ) ) {
4205                 return false;
4206             }
4207             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4208                     .equals( "PIG" ) ) {
4209                 return false;
4210             }
4211             if ( !ParserUtils
4212                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4213                     .equals( "MOUSE" ) ) {
4214                 return false;
4215             }
4216             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4217                     .equals( "MOUSE" ) ) {
4218                 return false;
4219             }
4220             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4221                 return false;
4222             }
4223         }
4224         catch ( final Exception e ) {
4225             e.printStackTrace( System.out );
4226             return false;
4227         }
4228         return true;
4229     }
4230
4231     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4232         try {
4233             PhylogenyNode n = new PhylogenyNode();
4234             n.setName( "tr|B3RJ64" );
4235             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4236                 return false;
4237             }
4238             n.setName( "tr.B3RJ64" );
4239             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4240                 return false;
4241             }
4242             n.setName( "tr=B3RJ64" );
4243             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4244                 return false;
4245             }
4246             n.setName( "tr-B3RJ64" );
4247             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4248                 return false;
4249             }
4250             n.setName( "tr/B3RJ64" );
4251             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4252                 return false;
4253             }
4254             n.setName( "tr\\B3RJ64" );
4255             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4256                 return false;
4257             }
4258             n.setName( "tr_B3RJ64" );
4259             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4260                 return false;
4261             }
4262             n.setName( " tr|B3RJ64 " );
4263             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4264                 return false;
4265             }
4266             n.setName( "-tr|B3RJ64-" );
4267             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4268                 return false;
4269             }
4270             n.setName( "-tr=B3RJ64-" );
4271             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4272                 return false;
4273             }
4274             n.setName( "_tr=B3RJ64_" );
4275             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4276                 return false;
4277             }
4278             n.setName( " tr_tr|B3RJ64_sp|123 " );
4279             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4280                 return false;
4281             }
4282             n.setName( "B3RJ64" );
4283             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4284                 return false;
4285             }
4286             n.setName( "sp|B3RJ64" );
4287             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4288                 return false;
4289             }
4290             n.setName( "sp|B3RJ64C" );
4291             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4292                 return false;
4293             }
4294             n.setName( "sp B3RJ64" );
4295             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4296                 return false;
4297             }
4298             n.setName( "sp|B3RJ6X" );
4299             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4300                 return false;
4301             }
4302             n.setName( "sp|B3RJ6" );
4303             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4304                 return false;
4305             }
4306             n.setName( "K1PYK7_CRAGI" );
4307             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4308                 return false;
4309             }
4310             n.setName( "K1PYK7_PEA" );
4311             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4312                 return false;
4313             }
4314             n.setName( "K1PYK7_RAT" );
4315             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4316                 return false;
4317             }
4318             n.setName( "K1PYK7_PIG" );
4319             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4320                 return false;
4321             }
4322             n.setName( "~K1PYK7_PIG~" );
4323             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4324                 return false;
4325             }
4326             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4327             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4328                 return false;
4329             }
4330             n.setName( "K1PYKX_CRAGI" );
4331             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4332                 return false;
4333             }
4334             n.setName( "XXXXX_CRAGI" );
4335             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4336                 return false;
4337             }
4338             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4339             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4340                 return false;
4341             }
4342             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4343             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4344                 return false;
4345             }
4346             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4347             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4348                 return false;
4349             }
4350             n = new PhylogenyNode();
4351             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4352             seq.setSymbol( "K1PYK7_CRAGI" );
4353             n.getNodeData().addSequence( seq );
4354             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4355                 return false;
4356             }
4357             seq.setSymbol( "tr|B3RJ64" );
4358             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4359                 return false;
4360             }
4361             n = new PhylogenyNode();
4362             seq = new org.forester.phylogeny.data.Sequence();
4363             seq.setName( "K1PYK7_CRAGI" );
4364             n.getNodeData().addSequence( seq );
4365             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4366                 return false;
4367             }
4368             seq.setName( "tr|B3RJ64" );
4369             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4370                 return false;
4371             }
4372             n = new PhylogenyNode();
4373             seq = new org.forester.phylogeny.data.Sequence();
4374             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4375             n.getNodeData().addSequence( seq );
4376             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4377                 return false;
4378             }
4379             n = new PhylogenyNode();
4380             seq = new org.forester.phylogeny.data.Sequence();
4381             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4382             n.getNodeData().addSequence( seq );
4383             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4384                 return false;
4385             }
4386             //
4387             n = new PhylogenyNode();
4388             n.setName( "ACP19736" );
4389             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4390                 return false;
4391             }
4392             n = new PhylogenyNode();
4393             n.setName( "|ACP19736|" );
4394             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4395                 return false;
4396             }
4397         }
4398         catch ( final Exception e ) {
4399             e.printStackTrace( System.out );
4400             return false;
4401         }
4402         return true;
4403     }
4404
4405     private static boolean testFastaParser() {
4406         try {
4407             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4408                 return false;
4409             }
4410             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4411                 return false;
4412             }
4413             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4414             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4415                 return false;
4416             }
4417             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4418                 return false;
4419             }
4420             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4421                 return false;
4422             }
4423             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4424                 return false;
4425             }
4426             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4427                 return false;
4428             }
4429             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4430                 return false;
4431             }
4432         }
4433         catch ( final Exception e ) {
4434             e.printStackTrace();
4435             return false;
4436         }
4437         return true;
4438     }
4439
4440     private static boolean testGenbankAccessorParsing() {
4441         //The format for GenBank Accession numbers are:
4442         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4443         //Protein:    3 letters + 5 numerals
4444         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4445         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4446             return false;
4447         }
4448         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4449             return false;
4450         }
4451         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4452             return false;
4453         }
4454         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4455             return false;
4456         }
4457         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4458             return false;
4459         }
4460         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4461             return false;
4462         }
4463         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4464             return false;
4465         }
4466         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4467             return false;
4468         }
4469         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4470             return false;
4471         }
4472         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4473             return false;
4474         }
4475         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4476             return false;
4477         }
4478         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4479             return false;
4480         }
4481         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4482             return false;
4483         }
4484         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4485             return false;
4486         }
4487         return true;
4488     }
4489
4490     private static boolean testGeneralMsaParser() {
4491         try {
4492             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4493             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4494             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4495             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4496             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4497             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4498             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4499             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4500             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4501                 return false;
4502             }
4503             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4504                 return false;
4505             }
4506             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4507                 return false;
4508             }
4509             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4510                 return false;
4511             }
4512             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4513                 return false;
4514             }
4515             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4516                 return false;
4517             }
4518             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4519                 return false;
4520             }
4521             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4522                 return false;
4523             }
4524             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4525                 return false;
4526             }
4527             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4528                 return false;
4529             }
4530             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4531                 return false;
4532             }
4533             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4534                 return false;
4535             }
4536             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4537             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4538                 return false;
4539             }
4540             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4541                 return false;
4542             }
4543             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4544                 return false;
4545             }
4546             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4547             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4548                 return false;
4549             }
4550             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4551                 return false;
4552             }
4553             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4554                 return false;
4555             }
4556             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4557             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4558                 return false;
4559             }
4560             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4561                 return false;
4562             }
4563             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4564                 return false;
4565             }
4566         }
4567         catch ( final Exception e ) {
4568             e.printStackTrace();
4569             return false;
4570         }
4571         return true;
4572     }
4573
4574     private static boolean testGeneralTable() {
4575         try {
4576             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4577             t0.setValue( 3, 2, "23" );
4578             t0.setValue( 10, 1, "error" );
4579             t0.setValue( 10, 1, "110" );
4580             t0.setValue( 9, 1, "19" );
4581             t0.setValue( 1, 10, "101" );
4582             t0.setValue( 10, 10, "1010" );
4583             t0.setValue( 100, 10, "10100" );
4584             t0.setValue( 0, 0, "00" );
4585             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4586                 return false;
4587             }
4588             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4589                 return false;
4590             }
4591             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4592                 return false;
4593             }
4594             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4595                 return false;
4596             }
4597             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4598                 return false;
4599             }
4600             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4601                 return false;
4602             }
4603             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4604                 return false;
4605             }
4606             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4607                 return false;
4608             }
4609             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4610                 return false;
4611             }
4612             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4613             t1.setValue( "3", "2", "23" );
4614             t1.setValue( "10", "1", "error" );
4615             t1.setValue( "10", "1", "110" );
4616             t1.setValue( "9", "1", "19" );
4617             t1.setValue( "1", "10", "101" );
4618             t1.setValue( "10", "10", "1010" );
4619             t1.setValue( "100", "10", "10100" );
4620             t1.setValue( "0", "0", "00" );
4621             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4622             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4623                 return false;
4624             }
4625             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4626                 return false;
4627             }
4628             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4629                 return false;
4630             }
4631             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4632                 return false;
4633             }
4634             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4635                 return false;
4636             }
4637             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4638                 return false;
4639             }
4640             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4641                 return false;
4642             }
4643             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4644                 return false;
4645             }
4646             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4647                 return false;
4648             }
4649             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4650                 return false;
4651             }
4652         }
4653         catch ( final Exception e ) {
4654             e.printStackTrace( System.out );
4655             return false;
4656         }
4657         return true;
4658     }
4659
4660     private static boolean testGetDistance() {
4661         try {
4662             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4663             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",
4664                                                  new NHXParser() )[ 0 ];
4665             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4666                 return false;
4667             }
4668             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4669                 return false;
4670             }
4671             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
4672                 return false;
4673             }
4674             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
4675                 return false;
4676             }
4677             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
4678                 return false;
4679             }
4680             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
4681                 return false;
4682             }
4683             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
4684                 return false;
4685             }
4686             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
4687                 return false;
4688             }
4689             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
4690                 return false;
4691             }
4692             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
4693                 return false;
4694             }
4695             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
4696                 return false;
4697             }
4698             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
4699                 return false;
4700             }
4701             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
4702                 return false;
4703             }
4704             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
4705                 return false;
4706             }
4707             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
4708                 return false;
4709             }
4710             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
4711                 return false;
4712             }
4713             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
4714                 return false;
4715             }
4716             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
4717                 return false;
4718             }
4719             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
4720                 return false;
4721             }
4722             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
4723                 return false;
4724             }
4725             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
4726                 return false;
4727             }
4728             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
4729                 return false;
4730             }
4731             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
4732                 return false;
4733             }
4734             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
4735                 return false;
4736             }
4737             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
4738                 return false;
4739             }
4740             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
4741                 return false;
4742             }
4743             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
4744                 return false;
4745             }
4746             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
4747                 return false;
4748             }
4749             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
4750                 return false;
4751             }
4752             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
4753                 return false;
4754             }
4755             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
4756                 return false;
4757             }
4758             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",
4759                                                  new NHXParser() )[ 0 ];
4760             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
4761                 return false;
4762             }
4763             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
4764                 return false;
4765             }
4766             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
4767                 return false;
4768             }
4769             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
4770                 return false;
4771             }
4772             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
4773                 return false;
4774             }
4775             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
4776                 return false;
4777             }
4778             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
4779                 return false;
4780             }
4781             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
4782                 return false;
4783             }
4784             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
4785                 return false;
4786             }
4787             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
4788                 return false;
4789             }
4790             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
4791                 return false;
4792             }
4793         }
4794         catch ( final Exception e ) {
4795             e.printStackTrace( System.out );
4796             return false;
4797         }
4798         return true;
4799     }
4800
4801     private static boolean testGetLCA() {
4802         try {
4803             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4804             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4805                                                  new NHXParser() )[ 0 ];
4806             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
4807             if ( !A.getName().equals( "A" ) ) {
4808                 return false;
4809             }
4810             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
4811             if ( !gh.getName().equals( "gh" ) ) {
4812                 return false;
4813             }
4814             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
4815             if ( !ab.getName().equals( "ab" ) ) {
4816                 return false;
4817             }
4818             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
4819             if ( !ab2.getName().equals( "ab" ) ) {
4820                 return false;
4821             }
4822             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
4823             if ( !gh2.getName().equals( "gh" ) ) {
4824                 return false;
4825             }
4826             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
4827             if ( !gh3.getName().equals( "gh" ) ) {
4828                 return false;
4829             }
4830             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
4831             if ( !abc.getName().equals( "abc" ) ) {
4832                 return false;
4833             }
4834             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
4835             if ( !abc2.getName().equals( "abc" ) ) {
4836                 return false;
4837             }
4838             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
4839             if ( !abcd.getName().equals( "abcd" ) ) {
4840                 return false;
4841             }
4842             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
4843             if ( !abcd2.getName().equals( "abcd" ) ) {
4844                 return false;
4845             }
4846             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
4847             if ( !abcdef.getName().equals( "abcdef" ) ) {
4848                 return false;
4849             }
4850             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
4851             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4852                 return false;
4853             }
4854             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
4855             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4856                 return false;
4857             }
4858             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
4859             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4860                 return false;
4861             }
4862             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
4863             if ( !abcde.getName().equals( "abcde" ) ) {
4864                 return false;
4865             }
4866             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
4867             if ( !abcde2.getName().equals( "abcde" ) ) {
4868                 return false;
4869             }
4870             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
4871             if ( !r.getName().equals( "abcdefgh" ) ) {
4872                 return false;
4873             }
4874             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
4875             if ( !r2.getName().equals( "abcdefgh" ) ) {
4876                 return false;
4877             }
4878             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
4879             if ( !r3.getName().equals( "abcdefgh" ) ) {
4880                 return false;
4881             }
4882             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
4883             if ( !abcde3.getName().equals( "abcde" ) ) {
4884                 return false;
4885             }
4886             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
4887             if ( !abcde4.getName().equals( "abcde" ) ) {
4888                 return false;
4889             }
4890             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
4891             if ( !ab3.getName().equals( "ab" ) ) {
4892                 return false;
4893             }
4894             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
4895             if ( !ab4.getName().equals( "ab" ) ) {
4896                 return false;
4897             }
4898             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4899             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
4900             if ( !cd.getName().equals( "cd" ) ) {
4901                 return false;
4902             }
4903             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
4904             if ( !cd2.getName().equals( "cd" ) ) {
4905                 return false;
4906             }
4907             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
4908             if ( !cde.getName().equals( "cde" ) ) {
4909                 return false;
4910             }
4911             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
4912             if ( !cde2.getName().equals( "cde" ) ) {
4913                 return false;
4914             }
4915             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
4916             if ( !cdef.getName().equals( "cdef" ) ) {
4917                 return false;
4918             }
4919             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
4920             if ( !cdef2.getName().equals( "cdef" ) ) {
4921                 return false;
4922             }
4923             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
4924             if ( !cdef3.getName().equals( "cdef" ) ) {
4925                 return false;
4926             }
4927             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
4928             if ( !rt.getName().equals( "r" ) ) {
4929                 return false;
4930             }
4931             final Phylogeny p3 = factory
4932                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4933                              new NHXParser() )[ 0 ];
4934             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
4935             if ( !bc_3.getName().equals( "bc" ) ) {
4936                 return false;
4937             }
4938             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
4939             if ( !ac_3.getName().equals( "abc" ) ) {
4940                 return false;
4941             }
4942             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
4943             if ( !ad_3.getName().equals( "abcde" ) ) {
4944                 return false;
4945             }
4946             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
4947             if ( !af_3.getName().equals( "abcdef" ) ) {
4948                 return false;
4949             }
4950             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
4951             if ( !ag_3.getName().equals( "" ) ) {
4952                 return false;
4953             }
4954             if ( !ag_3.isRoot() ) {
4955                 return false;
4956             }
4957             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
4958             if ( !al_3.getName().equals( "" ) ) {
4959                 return false;
4960             }
4961             if ( !al_3.isRoot() ) {
4962                 return false;
4963             }
4964             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
4965             if ( !kl_3.getName().equals( "" ) ) {
4966                 return false;
4967             }
4968             if ( !kl_3.isRoot() ) {
4969                 return false;
4970             }
4971             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
4972             if ( !fl_3.getName().equals( "" ) ) {
4973                 return false;
4974             }
4975             if ( !fl_3.isRoot() ) {
4976                 return false;
4977             }
4978             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
4979             if ( !gk_3.getName().equals( "ghijk" ) ) {
4980                 return false;
4981             }
4982             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4983             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
4984             if ( !r_4.getName().equals( "r" ) ) {
4985                 return false;
4986             }
4987             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4988             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
4989             if ( !r_5.getName().equals( "root" ) ) {
4990                 return false;
4991             }
4992             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4993             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
4994             if ( !r_6.getName().equals( "rot" ) ) {
4995                 return false;
4996             }
4997             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4998             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
4999             if ( !r_7.getName().equals( "rott" ) ) {
5000                 return false;
5001             }
5002         }
5003         catch ( final Exception e ) {
5004             e.printStackTrace( System.out );
5005             return false;
5006         }
5007         return true;
5008     }
5009
5010     private static boolean testGetLCA2() {
5011         try {
5012             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5013             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5014             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5015             PhylogenyMethods.preOrderReId( p_a );
5016             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5017                                                                                               p_a.getNode( "a" ) );
5018             if ( !p_a_1.getName().equals( "a" ) ) {
5019                 return false;
5020             }
5021             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5022             PhylogenyMethods.preOrderReId( p_b );
5023             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5024                                                                                               p_b.getNode( "a" ) );
5025             if ( !p_b_1.getName().equals( "b" ) ) {
5026                 return false;
5027             }
5028             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5029                                                                                               p_b.getNode( "b" ) );
5030             if ( !p_b_2.getName().equals( "b" ) ) {
5031                 return false;
5032             }
5033             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5034             PhylogenyMethods.preOrderReId( p_c );
5035             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5036                                                                                               p_c.getNode( "a" ) );
5037             if ( !p_c_1.getName().equals( "b" ) ) {
5038                 return false;
5039             }
5040             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5041                                                                                               p_c.getNode( "c" ) );
5042             if ( !p_c_2.getName().equals( "c" ) ) {
5043                 System.out.println( p_c_2.getName() );
5044                 System.exit( -1 );
5045                 return false;
5046             }
5047             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5048                                                                                               p_c.getNode( "b" ) );
5049             if ( !p_c_3.getName().equals( "b" ) ) {
5050                 return false;
5051             }
5052             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5053                                                                                               p_c.getNode( "a" ) );
5054             if ( !p_c_4.getName().equals( "c" ) ) {
5055                 return false;
5056             }
5057             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5058                                                  new NHXParser() )[ 0 ];
5059             PhylogenyMethods.preOrderReId( p1 );
5060             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5061                                                                                           p1.getNode( "A" ) );
5062             if ( !A.getName().equals( "A" ) ) {
5063                 return false;
5064             }
5065             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5066                                                                                            p1.getNode( "gh" ) );
5067             if ( !gh.getName().equals( "gh" ) ) {
5068                 return false;
5069             }
5070             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5071                                                                                            p1.getNode( "B" ) );
5072             if ( !ab.getName().equals( "ab" ) ) {
5073                 return false;
5074             }
5075             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5076                                                                                             p1.getNode( "A" ) );
5077             if ( !ab2.getName().equals( "ab" ) ) {
5078                 return false;
5079             }
5080             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5081                                                                                             p1.getNode( "G" ) );
5082             if ( !gh2.getName().equals( "gh" ) ) {
5083                 return false;
5084             }
5085             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5086                                                                                             p1.getNode( "H" ) );
5087             if ( !gh3.getName().equals( "gh" ) ) {
5088                 return false;
5089             }
5090             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5091                                                                                             p1.getNode( "A" ) );
5092             if ( !abc.getName().equals( "abc" ) ) {
5093                 return false;
5094             }
5095             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5096                                                                                              p1.getNode( "C" ) );
5097             if ( !abc2.getName().equals( "abc" ) ) {
5098                 return false;
5099             }
5100             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5101                                                                                              p1.getNode( "D" ) );
5102             if ( !abcd.getName().equals( "abcd" ) ) {
5103                 return false;
5104             }
5105             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5106                                                                                               p1.getNode( "A" ) );
5107             if ( !abcd2.getName().equals( "abcd" ) ) {
5108                 return false;
5109             }
5110             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5111                                                                                                p1.getNode( "F" ) );
5112             if ( !abcdef.getName().equals( "abcdef" ) ) {
5113                 return false;
5114             }
5115             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5116                                                                                                 p1.getNode( "A" ) );
5117             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5118                 return false;
5119             }
5120             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5121                                                                                                 p1.getNode( "F" ) );
5122             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5123                 return false;
5124             }
5125             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5126                                                                                                 p1.getNode( "ab" ) );
5127             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5128                 return false;
5129             }
5130             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5131                                                                                               p1.getNode( "E" ) );
5132             if ( !abcde.getName().equals( "abcde" ) ) {
5133                 return false;
5134             }
5135             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5136                                                                                                p1.getNode( "A" ) );
5137             if ( !abcde2.getName().equals( "abcde" ) ) {
5138                 return false;
5139             }
5140             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5141                                                                                           p1.getNode( "abcdefgh" ) );
5142             if ( !r.getName().equals( "abcdefgh" ) ) {
5143                 return false;
5144             }
5145             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5146                                                                                            p1.getNode( "H" ) );
5147             if ( !r2.getName().equals( "abcdefgh" ) ) {
5148                 return false;
5149             }
5150             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5151                                                                                            p1.getNode( "A" ) );
5152             if ( !r3.getName().equals( "abcdefgh" ) ) {
5153                 return false;
5154             }
5155             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5156                                                                                                p1.getNode( "abcde" ) );
5157             if ( !abcde3.getName().equals( "abcde" ) ) {
5158                 return false;
5159             }
5160             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5161                                                                                                p1.getNode( "E" ) );
5162             if ( !abcde4.getName().equals( "abcde" ) ) {
5163                 return false;
5164             }
5165             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5166                                                                                             p1.getNode( "B" ) );
5167             if ( !ab3.getName().equals( "ab" ) ) {
5168                 return false;
5169             }
5170             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5171                                                                                             p1.getNode( "ab" ) );
5172             if ( !ab4.getName().equals( "ab" ) ) {
5173                 return false;
5174             }
5175             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5176             PhylogenyMethods.preOrderReId( p2 );
5177             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5178                                                                                            p2.getNode( "d" ) );
5179             if ( !cd.getName().equals( "cd" ) ) {
5180                 return false;
5181             }
5182             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5183                                                                                             p2.getNode( "c" ) );
5184             if ( !cd2.getName().equals( "cd" ) ) {
5185                 return false;
5186             }
5187             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5188                                                                                             p2.getNode( "e" ) );
5189             if ( !cde.getName().equals( "cde" ) ) {
5190                 return false;
5191             }
5192             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5193                                                                                              p2.getNode( "c" ) );
5194             if ( !cde2.getName().equals( "cde" ) ) {
5195                 return false;
5196             }
5197             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5198                                                                                              p2.getNode( "f" ) );
5199             if ( !cdef.getName().equals( "cdef" ) ) {
5200                 return false;
5201             }
5202             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5203                                                                                               p2.getNode( "f" ) );
5204             if ( !cdef2.getName().equals( "cdef" ) ) {
5205                 return false;
5206             }
5207             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5208                                                                                               p2.getNode( "d" ) );
5209             if ( !cdef3.getName().equals( "cdef" ) ) {
5210                 return false;
5211             }
5212             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5213                                                                                            p2.getNode( "a" ) );
5214             if ( !rt.getName().equals( "r" ) ) {
5215                 return false;
5216             }
5217             final Phylogeny p3 = factory
5218                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5219                              new NHXParser() )[ 0 ];
5220             PhylogenyMethods.preOrderReId( p3 );
5221             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5222                                                                                              p3.getNode( "c" ) );
5223             if ( !bc_3.getName().equals( "bc" ) ) {
5224                 return false;
5225             }
5226             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5227                                                                                              p3.getNode( "c" ) );
5228             if ( !ac_3.getName().equals( "abc" ) ) {
5229                 return false;
5230             }
5231             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5232                                                                                              p3.getNode( "d" ) );
5233             if ( !ad_3.getName().equals( "abcde" ) ) {
5234                 return false;
5235             }
5236             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5237                                                                                              p3.getNode( "f" ) );
5238             if ( !af_3.getName().equals( "abcdef" ) ) {
5239                 return false;
5240             }
5241             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5242                                                                                              p3.getNode( "g" ) );
5243             if ( !ag_3.getName().equals( "" ) ) {
5244                 return false;
5245             }
5246             if ( !ag_3.isRoot() ) {
5247                 return false;
5248             }
5249             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5250                                                                                              p3.getNode( "l" ) );
5251             if ( !al_3.getName().equals( "" ) ) {
5252                 return false;
5253             }
5254             if ( !al_3.isRoot() ) {
5255                 return false;
5256             }
5257             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5258                                                                                              p3.getNode( "l" ) );
5259             if ( !kl_3.getName().equals( "" ) ) {
5260                 return false;
5261             }
5262             if ( !kl_3.isRoot() ) {
5263                 return false;
5264             }
5265             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5266                                                                                              p3.getNode( "l" ) );
5267             if ( !fl_3.getName().equals( "" ) ) {
5268                 return false;
5269             }
5270             if ( !fl_3.isRoot() ) {
5271                 return false;
5272             }
5273             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5274                                                                                              p3.getNode( "k" ) );
5275             if ( !gk_3.getName().equals( "ghijk" ) ) {
5276                 return false;
5277             }
5278             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5279             PhylogenyMethods.preOrderReId( p4 );
5280             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5281                                                                                             p4.getNode( "c" ) );
5282             if ( !r_4.getName().equals( "r" ) ) {
5283                 return false;
5284             }
5285             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5286             PhylogenyMethods.preOrderReId( p5 );
5287             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5288                                                                                             p5.getNode( "c" ) );
5289             if ( !r_5.getName().equals( "root" ) ) {
5290                 return false;
5291             }
5292             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5293             PhylogenyMethods.preOrderReId( p6 );
5294             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5295                                                                                             p6.getNode( "a" ) );
5296             if ( !r_6.getName().equals( "rot" ) ) {
5297                 return false;
5298             }
5299             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5300             PhylogenyMethods.preOrderReId( p7 );
5301             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5302                                                                                             p7.getNode( "e" ) );
5303             if ( !r_7.getName().equals( "rott" ) ) {
5304                 return false;
5305             }
5306             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5307                                                                                              p7.getNode( "a" ) );
5308             if ( !r_71.getName().equals( "rott" ) ) {
5309                 return false;
5310             }
5311             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5312                                                                                              p7.getNode( "rott" ) );
5313             if ( !r_72.getName().equals( "rott" ) ) {
5314                 return false;
5315             }
5316             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5317                                                                                              p7.getNode( "a" ) );
5318             if ( !r_73.getName().equals( "rott" ) ) {
5319                 return false;
5320             }
5321             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5322                                                                                              p7.getNode( "rott" ) );
5323             if ( !r_74.getName().equals( "rott" ) ) {
5324                 return false;
5325             }
5326             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5327                                                                                              p7.getNode( "e" ) );
5328             if ( !r_75.getName().equals( "e" ) ) {
5329                 return false;
5330             }
5331         }
5332         catch ( final Exception e ) {
5333             e.printStackTrace( System.out );
5334             return false;
5335         }
5336         return true;
5337     }
5338
5339     private static boolean testHmmscanOutputParser() {
5340         final String test_dir = Test.PATH_TO_TEST_DATA;
5341         try {
5342             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5343                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5344             parser1.parse();
5345             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5346                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5347             final List<Protein> proteins = parser2.parse();
5348             if ( parser2.getProteinsEncountered() != 4 ) {
5349                 return false;
5350             }
5351             if ( proteins.size() != 4 ) {
5352                 return false;
5353             }
5354             if ( parser2.getDomainsEncountered() != 69 ) {
5355                 return false;
5356             }
5357             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5358                 return false;
5359             }
5360             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5361                 return false;
5362             }
5363             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5364                 return false;
5365             }
5366             final Protein p1 = proteins.get( 0 );
5367             if ( p1.getNumberOfProteinDomains() != 15 ) {
5368                 return false;
5369             }
5370             if ( p1.getLength() != 850 ) {
5371                 return false;
5372             }
5373             final Protein p2 = proteins.get( 1 );
5374             if ( p2.getNumberOfProteinDomains() != 51 ) {
5375                 return false;
5376             }
5377             if ( p2.getLength() != 1291 ) {
5378                 return false;
5379             }
5380             final Protein p3 = proteins.get( 2 );
5381             if ( p3.getNumberOfProteinDomains() != 2 ) {
5382                 return false;
5383             }
5384             final Protein p4 = proteins.get( 3 );
5385             if ( p4.getNumberOfProteinDomains() != 1 ) {
5386                 return false;
5387             }
5388             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5389                 return false;
5390             }
5391             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5392                 return false;
5393             }
5394             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5395                 return false;
5396             }
5397             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5398                 return false;
5399             }
5400             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5401                 return false;
5402             }
5403             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5404                 return false;
5405             }
5406             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5407                 return false;
5408             }
5409         }
5410         catch ( final Exception e ) {
5411             e.printStackTrace( System.out );
5412             return false;
5413         }
5414         return true;
5415     }
5416
5417     private static boolean testLastExternalNodeMethods() {
5418         try {
5419             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5420             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5421             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5422             final PhylogenyNode n1 = t0.getNode( "A" );
5423             if ( n1.isLastExternalNode() ) {
5424                 return false;
5425             }
5426             final PhylogenyNode n2 = t0.getNode( "B" );
5427             if ( n2.isLastExternalNode() ) {
5428                 return false;
5429             }
5430             final PhylogenyNode n3 = t0.getNode( "C" );
5431             if ( n3.isLastExternalNode() ) {
5432                 return false;
5433             }
5434             final PhylogenyNode n4 = t0.getNode( "D" );
5435             if ( !n4.isLastExternalNode() ) {
5436                 return false;
5437             }
5438         }
5439         catch ( final Exception e ) {
5440             e.printStackTrace( System.out );
5441             return false;
5442         }
5443         return true;
5444     }
5445
5446     private static boolean testLevelOrderIterator() {
5447         try {
5448             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5449             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5450             PhylogenyNodeIterator it0;
5451             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5452                 it0.next();
5453             }
5454             for( it0.reset(); it0.hasNext(); ) {
5455                 it0.next();
5456             }
5457             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5458             if ( !it.next().getName().equals( "r" ) ) {
5459                 return false;
5460             }
5461             if ( !it.next().getName().equals( "ab" ) ) {
5462                 return false;
5463             }
5464             if ( !it.next().getName().equals( "cd" ) ) {
5465                 return false;
5466             }
5467             if ( !it.next().getName().equals( "A" ) ) {
5468                 return false;
5469             }
5470             if ( !it.next().getName().equals( "B" ) ) {
5471                 return false;
5472             }
5473             if ( !it.next().getName().equals( "C" ) ) {
5474                 return false;
5475             }
5476             if ( !it.next().getName().equals( "D" ) ) {
5477                 return false;
5478             }
5479             if ( it.hasNext() ) {
5480                 return false;
5481             }
5482             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",
5483                                                  new NHXParser() )[ 0 ];
5484             PhylogenyNodeIterator it2;
5485             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5486                 it2.next();
5487             }
5488             for( it2.reset(); it2.hasNext(); ) {
5489                 it2.next();
5490             }
5491             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5492             if ( !it3.next().getName().equals( "r" ) ) {
5493                 return false;
5494             }
5495             if ( !it3.next().getName().equals( "abc" ) ) {
5496                 return false;
5497             }
5498             if ( !it3.next().getName().equals( "defg" ) ) {
5499                 return false;
5500             }
5501             if ( !it3.next().getName().equals( "A" ) ) {
5502                 return false;
5503             }
5504             if ( !it3.next().getName().equals( "B" ) ) {
5505                 return false;
5506             }
5507             if ( !it3.next().getName().equals( "C" ) ) {
5508                 return false;
5509             }
5510             if ( !it3.next().getName().equals( "D" ) ) {
5511                 return false;
5512             }
5513             if ( !it3.next().getName().equals( "E" ) ) {
5514                 return false;
5515             }
5516             if ( !it3.next().getName().equals( "F" ) ) {
5517                 return false;
5518             }
5519             if ( !it3.next().getName().equals( "G" ) ) {
5520                 return false;
5521             }
5522             if ( !it3.next().getName().equals( "1" ) ) {
5523                 return false;
5524             }
5525             if ( !it3.next().getName().equals( "2" ) ) {
5526                 return false;
5527             }
5528             if ( !it3.next().getName().equals( "3" ) ) {
5529                 return false;
5530             }
5531             if ( !it3.next().getName().equals( "4" ) ) {
5532                 return false;
5533             }
5534             if ( !it3.next().getName().equals( "5" ) ) {
5535                 return false;
5536             }
5537             if ( !it3.next().getName().equals( "6" ) ) {
5538                 return false;
5539             }
5540             if ( !it3.next().getName().equals( "f1" ) ) {
5541                 return false;
5542             }
5543             if ( !it3.next().getName().equals( "f2" ) ) {
5544                 return false;
5545             }
5546             if ( !it3.next().getName().equals( "f3" ) ) {
5547                 return false;
5548             }
5549             if ( !it3.next().getName().equals( "a" ) ) {
5550                 return false;
5551             }
5552             if ( !it3.next().getName().equals( "b" ) ) {
5553                 return false;
5554             }
5555             if ( !it3.next().getName().equals( "f21" ) ) {
5556                 return false;
5557             }
5558             if ( !it3.next().getName().equals( "X" ) ) {
5559                 return false;
5560             }
5561             if ( !it3.next().getName().equals( "Y" ) ) {
5562                 return false;
5563             }
5564             if ( !it3.next().getName().equals( "Z" ) ) {
5565                 return false;
5566             }
5567             if ( it3.hasNext() ) {
5568                 return false;
5569             }
5570             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5571             PhylogenyNodeIterator it4;
5572             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5573                 it4.next();
5574             }
5575             for( it4.reset(); it4.hasNext(); ) {
5576                 it4.next();
5577             }
5578             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5579             if ( !it5.next().getName().equals( "r" ) ) {
5580                 return false;
5581             }
5582             if ( !it5.next().getName().equals( "A" ) ) {
5583                 return false;
5584             }
5585             if ( !it5.next().getName().equals( "B" ) ) {
5586                 return false;
5587             }
5588             if ( !it5.next().getName().equals( "C" ) ) {
5589                 return false;
5590             }
5591             if ( !it5.next().getName().equals( "D" ) ) {
5592                 return false;
5593             }
5594             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5595             PhylogenyNodeIterator it6;
5596             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5597                 it6.next();
5598             }
5599             for( it6.reset(); it6.hasNext(); ) {
5600                 it6.next();
5601             }
5602             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5603             if ( !it7.next().getName().equals( "A" ) ) {
5604                 return false;
5605             }
5606             if ( it.hasNext() ) {
5607                 return false;
5608             }
5609         }
5610         catch ( final Exception e ) {
5611             e.printStackTrace( System.out );
5612             return false;
5613         }
5614         return true;
5615     }
5616
5617     private static boolean testMafft( final String path ) {
5618         try {
5619             final List<String> opts = new ArrayList<String>();
5620             opts.add( "--maxiterate" );
5621             opts.add( "1000" );
5622             opts.add( "--localpair" );
5623             opts.add( "--quiet" );
5624             Msa msa = null;
5625             final MsaInferrer mafft = Mafft.createInstance( path );
5626             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5627             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5628                 return false;
5629             }
5630             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5631                 return false;
5632             }
5633         }
5634         catch ( final Exception e ) {
5635             e.printStackTrace( System.out );
5636             return false;
5637         }
5638         return true;
5639     }
5640
5641     private static boolean testMidpointrooting() {
5642         try {
5643             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5644             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5645             PhylogenyMethods.midpointRoot( t0 );
5646             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5647                 return false;
5648             }
5649             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5650                 return false;
5651             }
5652             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5653                            1 ) ) {
5654                 return false;
5655             }
5656             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",
5657                                                  new NHXParser() )[ 0 ];
5658             if ( !t1.isRooted() ) {
5659                 return false;
5660             }
5661             PhylogenyMethods.midpointRoot( t1 );
5662             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5663                 return false;
5664             }
5665             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5666                 return false;
5667             }
5668             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5669                 return false;
5670             }
5671             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5672                 return false;
5673             }
5674             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5675                 return false;
5676             }
5677             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5678                 return false;
5679             }
5680             t1.reRoot( t1.getNode( "A" ) );
5681             PhylogenyMethods.midpointRoot( t1 );
5682             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5683                 return false;
5684             }
5685             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5686                 return false;
5687             }
5688             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5689                 return false;
5690             }
5691             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5692                 return false;
5693             }
5694             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5695                 System.exit( -1 );
5696                 return false;
5697             }
5698             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5699                 return false;
5700             }
5701         }
5702         catch ( final Exception e ) {
5703             e.printStackTrace( System.out );
5704             return false;
5705         }
5706         return true;
5707     }
5708
5709     private static boolean testMsaQualityMethod() {
5710         try {
5711             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
5712             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
5713             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
5714             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
5715             final List<Sequence> l = new ArrayList<Sequence>();
5716             l.add( s0 );
5717             l.add( s1 );
5718             l.add( s2 );
5719             l.add( s3 );
5720             final Msa msa = BasicMsa.createInstance( l );
5721             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
5722                 return false;
5723             }
5724             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
5725                 return false;
5726             }
5727             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
5728                 return false;
5729             }
5730             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
5731                 return false;
5732             }
5733             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
5734                 return false;
5735             }
5736             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
5737                 return false;
5738             }
5739             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
5740                 return false;
5741             }
5742         }
5743         catch ( final Exception e ) {
5744             e.printStackTrace( System.out );
5745             return false;
5746         }
5747         return true;
5748     }
5749
5750     private static boolean testNextNodeWithCollapsing() {
5751         try {
5752             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5753             PhylogenyNode n;
5754             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
5755             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5756             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
5757             t0.getNode( "cd" ).setCollapse( true );
5758             t0.getNode( "cde" ).setCollapse( true );
5759             n = t0.getFirstExternalNode();
5760             while ( n != null ) {
5761                 ext.add( n );
5762                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5763             }
5764             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5765                 return false;
5766             }
5767             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5768                 return false;
5769             }
5770             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
5771                 return false;
5772             }
5773             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
5774                 return false;
5775             }
5776             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
5777                 return false;
5778             }
5779             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
5780                 return false;
5781             }
5782             ext.clear();
5783             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5784             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
5785             t1.getNode( "ab" ).setCollapse( true );
5786             t1.getNode( "cd" ).setCollapse( true );
5787             t1.getNode( "cde" ).setCollapse( true );
5788             n = t1.getNode( "ab" );
5789             ext = new ArrayList<PhylogenyNode>();
5790             while ( n != null ) {
5791                 ext.add( n );
5792                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5793             }
5794             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5795                 return false;
5796             }
5797             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5798                 return false;
5799             }
5800             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5801                 return false;
5802             }
5803             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
5804                 return false;
5805             }
5806             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
5807                 return false;
5808             }
5809             //
5810             //
5811             ext.clear();
5812             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5813             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
5814             t2.getNode( "ab" ).setCollapse( true );
5815             t2.getNode( "cd" ).setCollapse( true );
5816             t2.getNode( "cde" ).setCollapse( true );
5817             t2.getNode( "c" ).setCollapse( true );
5818             t2.getNode( "d" ).setCollapse( true );
5819             t2.getNode( "e" ).setCollapse( true );
5820             t2.getNode( "gh" ).setCollapse( true );
5821             n = t2.getNode( "ab" );
5822             ext = new ArrayList<PhylogenyNode>();
5823             while ( n != null ) {
5824                 ext.add( n );
5825                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5826             }
5827             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5828                 return false;
5829             }
5830             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5831                 return false;
5832             }
5833             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5834                 return false;
5835             }
5836             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
5837                 return false;
5838             }
5839             //
5840             //
5841             ext.clear();
5842             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5843             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
5844             t3.getNode( "ab" ).setCollapse( true );
5845             t3.getNode( "cd" ).setCollapse( true );
5846             t3.getNode( "cde" ).setCollapse( true );
5847             t3.getNode( "c" ).setCollapse( true );
5848             t3.getNode( "d" ).setCollapse( true );
5849             t3.getNode( "e" ).setCollapse( true );
5850             t3.getNode( "gh" ).setCollapse( true );
5851             t3.getNode( "fgh" ).setCollapse( true );
5852             n = t3.getNode( "ab" );
5853             ext = new ArrayList<PhylogenyNode>();
5854             while ( n != null ) {
5855                 ext.add( n );
5856                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5857             }
5858             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5859                 return false;
5860             }
5861             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5862                 return false;
5863             }
5864             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
5865                 return false;
5866             }
5867             //
5868             //
5869             ext.clear();
5870             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5871             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
5872             t4.getNode( "ab" ).setCollapse( true );
5873             t4.getNode( "cd" ).setCollapse( true );
5874             t4.getNode( "cde" ).setCollapse( true );
5875             t4.getNode( "c" ).setCollapse( true );
5876             t4.getNode( "d" ).setCollapse( true );
5877             t4.getNode( "e" ).setCollapse( true );
5878             t4.getNode( "gh" ).setCollapse( true );
5879             t4.getNode( "fgh" ).setCollapse( true );
5880             t4.getNode( "abcdefgh" ).setCollapse( true );
5881             n = t4.getNode( "abcdefgh" );
5882             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
5883                 return false;
5884             }
5885             //
5886             //
5887             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5888             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
5889             ext.clear();
5890             n = t5.getFirstExternalNode();
5891             while ( n != null ) {
5892                 ext.add( n );
5893                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5894             }
5895             if ( ext.size() != 8 ) {
5896                 return false;
5897             }
5898             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5899                 return false;
5900             }
5901             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5902                 return false;
5903             }
5904             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5905                 return false;
5906             }
5907             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5908                 return false;
5909             }
5910             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5911                 return false;
5912             }
5913             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5914                 return false;
5915             }
5916             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
5917                 return false;
5918             }
5919             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
5920                 return false;
5921             }
5922             //
5923             //
5924             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5925             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
5926             ext.clear();
5927             t6.getNode( "ab" ).setCollapse( true );
5928             n = t6.getNode( "ab" );
5929             while ( n != null ) {
5930                 ext.add( n );
5931                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5932             }
5933             if ( ext.size() != 7 ) {
5934                 return false;
5935             }
5936             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5937                 return false;
5938             }
5939             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5940                 return false;
5941             }
5942             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5943                 return false;
5944             }
5945             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5946                 return false;
5947             }
5948             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5949                 return false;
5950             }
5951             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5952                 return false;
5953             }
5954             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5955                 return false;
5956             }
5957             //
5958             //
5959             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5960             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
5961             ext.clear();
5962             t7.getNode( "cd" ).setCollapse( true );
5963             n = t7.getNode( "a" );
5964             while ( n != null ) {
5965                 ext.add( n );
5966                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5967             }
5968             if ( ext.size() != 7 ) {
5969                 return false;
5970             }
5971             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5972                 return false;
5973             }
5974             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5975                 return false;
5976             }
5977             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5978                 return false;
5979             }
5980             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5981                 return false;
5982             }
5983             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5984                 return false;
5985             }
5986             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5987                 return false;
5988             }
5989             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5990                 return false;
5991             }
5992             //
5993             //
5994             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5995             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
5996             ext.clear();
5997             t8.getNode( "cd" ).setCollapse( true );
5998             t8.getNode( "c" ).setCollapse( true );
5999             t8.getNode( "d" ).setCollapse( true );
6000             n = t8.getNode( "a" );
6001             while ( n != null ) {
6002                 ext.add( n );
6003                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6004             }
6005             if ( ext.size() != 7 ) {
6006                 return false;
6007             }
6008             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6009                 return false;
6010             }
6011             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6012                 return false;
6013             }
6014             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6015                 System.out.println( "2 fail" );
6016                 return false;
6017             }
6018             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6019                 return false;
6020             }
6021             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6022                 return false;
6023             }
6024             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6025                 return false;
6026             }
6027             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6028                 return false;
6029             }
6030             //
6031             //
6032             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6033             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6034             ext.clear();
6035             t9.getNode( "gh" ).setCollapse( true );
6036             n = t9.getNode( "a" );
6037             while ( n != null ) {
6038                 ext.add( n );
6039                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6040             }
6041             if ( ext.size() != 7 ) {
6042                 return false;
6043             }
6044             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6045                 return false;
6046             }
6047             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6048                 return false;
6049             }
6050             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6051                 return false;
6052             }
6053             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6054                 return false;
6055             }
6056             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6057                 return false;
6058             }
6059             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6060                 return false;
6061             }
6062             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6063                 return false;
6064             }
6065             //
6066             //
6067             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6068             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6069             ext.clear();
6070             t10.getNode( "gh" ).setCollapse( true );
6071             t10.getNode( "g" ).setCollapse( true );
6072             t10.getNode( "h" ).setCollapse( true );
6073             n = t10.getNode( "a" );
6074             while ( n != null ) {
6075                 ext.add( n );
6076                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6077             }
6078             if ( ext.size() != 7 ) {
6079                 return false;
6080             }
6081             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6082                 return false;
6083             }
6084             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6085                 return false;
6086             }
6087             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6088                 return false;
6089             }
6090             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6091                 return false;
6092             }
6093             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6094                 return false;
6095             }
6096             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6097                 return false;
6098             }
6099             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6100                 return false;
6101             }
6102             //
6103             //
6104             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6105             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6106             ext.clear();
6107             t11.getNode( "gh" ).setCollapse( true );
6108             t11.getNode( "fgh" ).setCollapse( true );
6109             n = t11.getNode( "a" );
6110             while ( n != null ) {
6111                 ext.add( n );
6112                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6113             }
6114             if ( ext.size() != 6 ) {
6115                 return false;
6116             }
6117             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6118                 return false;
6119             }
6120             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6121                 return false;
6122             }
6123             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6124                 return false;
6125             }
6126             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6127                 return false;
6128             }
6129             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6130                 return false;
6131             }
6132             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6133                 return false;
6134             }
6135             //
6136             //
6137             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6138             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6139             ext.clear();
6140             t12.getNode( "gh" ).setCollapse( true );
6141             t12.getNode( "fgh" ).setCollapse( true );
6142             t12.getNode( "g" ).setCollapse( true );
6143             t12.getNode( "h" ).setCollapse( true );
6144             t12.getNode( "f" ).setCollapse( true );
6145             n = t12.getNode( "a" );
6146             while ( n != null ) {
6147                 ext.add( n );
6148                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6149             }
6150             if ( ext.size() != 6 ) {
6151                 return false;
6152             }
6153             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6154                 return false;
6155             }
6156             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6157                 return false;
6158             }
6159             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6160                 return false;
6161             }
6162             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6163                 return false;
6164             }
6165             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6166                 return false;
6167             }
6168             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6169                 return false;
6170             }
6171             //
6172             //
6173             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6174             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6175             ext.clear();
6176             t13.getNode( "ab" ).setCollapse( true );
6177             t13.getNode( "b" ).setCollapse( true );
6178             t13.getNode( "fgh" ).setCollapse( true );
6179             t13.getNode( "gh" ).setCollapse( true );
6180             n = t13.getNode( "ab" );
6181             while ( n != null ) {
6182                 ext.add( n );
6183                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6184             }
6185             if ( ext.size() != 5 ) {
6186                 return false;
6187             }
6188             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6189                 return false;
6190             }
6191             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6192                 return false;
6193             }
6194             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6195                 return false;
6196             }
6197             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6198                 return false;
6199             }
6200             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6201                 return false;
6202             }
6203             //
6204             //
6205             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6206             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6207             ext.clear();
6208             t14.getNode( "ab" ).setCollapse( true );
6209             t14.getNode( "a" ).setCollapse( true );
6210             t14.getNode( "fgh" ).setCollapse( true );
6211             t14.getNode( "gh" ).setCollapse( true );
6212             n = t14.getNode( "ab" );
6213             while ( n != null ) {
6214                 ext.add( n );
6215                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6216             }
6217             if ( ext.size() != 5 ) {
6218                 return false;
6219             }
6220             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6221                 return false;
6222             }
6223             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6224                 return false;
6225             }
6226             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6227                 return false;
6228             }
6229             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6230                 return false;
6231             }
6232             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6233                 return false;
6234             }
6235             //
6236             //
6237             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" );
6238             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6239             ext.clear();
6240             t15.getNode( "ab" ).setCollapse( true );
6241             t15.getNode( "a" ).setCollapse( true );
6242             t15.getNode( "fgh" ).setCollapse( true );
6243             t15.getNode( "gh" ).setCollapse( true );
6244             n = t15.getNode( "ab" );
6245             while ( n != null ) {
6246                 ext.add( n );
6247                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6248             }
6249             if ( ext.size() != 6 ) {
6250                 return false;
6251             }
6252             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6253                 return false;
6254             }
6255             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6256                 return false;
6257             }
6258             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6259                 return false;
6260             }
6261             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6262                 return false;
6263             }
6264             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6265                 return false;
6266             }
6267             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6268                 return false;
6269             }
6270             //
6271             //
6272             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" );
6273             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6274             ext.clear();
6275             t16.getNode( "ab" ).setCollapse( true );
6276             t16.getNode( "a" ).setCollapse( true );
6277             t16.getNode( "fgh" ).setCollapse( true );
6278             t16.getNode( "gh" ).setCollapse( true );
6279             t16.getNode( "cd" ).setCollapse( true );
6280             t16.getNode( "cde" ).setCollapse( true );
6281             t16.getNode( "d" ).setCollapse( true );
6282             t16.getNode( "x" ).setCollapse( true );
6283             n = t16.getNode( "ab" );
6284             while ( n != null ) {
6285                 ext.add( n );
6286                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6287             }
6288             if ( ext.size() != 4 ) {
6289                 return false;
6290             }
6291             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6292                 return false;
6293             }
6294             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6295                 return false;
6296             }
6297             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6298                 return false;
6299             }
6300             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6301                 return false;
6302             }
6303         }
6304         catch ( final Exception e ) {
6305             e.printStackTrace( System.out );
6306             return false;
6307         }
6308         return true;
6309     }
6310
6311     private static boolean testNexusCharactersParsing() {
6312         try {
6313             final NexusCharactersParser parser = new NexusCharactersParser();
6314             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6315             parser.parse();
6316             String[] labels = parser.getCharStateLabels();
6317             if ( labels.length != 7 ) {
6318                 return false;
6319             }
6320             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6321                 return false;
6322             }
6323             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6324                 return false;
6325             }
6326             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6327                 return false;
6328             }
6329             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6330                 return false;
6331             }
6332             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6333                 return false;
6334             }
6335             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6336                 return false;
6337             }
6338             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6339                 return false;
6340             }
6341             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6342             parser.parse();
6343             labels = parser.getCharStateLabels();
6344             if ( labels.length != 7 ) {
6345                 return false;
6346             }
6347             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6348                 return false;
6349             }
6350             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6351                 return false;
6352             }
6353             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6354                 return false;
6355             }
6356             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6357                 return false;
6358             }
6359             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6360                 return false;
6361             }
6362             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6363                 return false;
6364             }
6365             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6366                 return false;
6367             }
6368         }
6369         catch ( final Exception e ) {
6370             e.printStackTrace( System.out );
6371             return false;
6372         }
6373         return true;
6374     }
6375
6376     private static boolean testNexusMatrixParsing() {
6377         try {
6378             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
6379             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
6380             parser.parse();
6381             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
6382             if ( m.getNumberOfCharacters() != 9 ) {
6383                 return false;
6384             }
6385             if ( m.getNumberOfIdentifiers() != 5 ) {
6386                 return false;
6387             }
6388             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
6389                 return false;
6390             }
6391             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
6392                 return false;
6393             }
6394             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
6395                 return false;
6396             }
6397             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
6398                 return false;
6399             }
6400             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
6401                 return false;
6402             }
6403             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6404                 return false;
6405             }
6406             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
6407                 return false;
6408             }
6409             //            if ( labels.length != 7 ) {
6410             //                return false;
6411             //            }
6412             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6413             //                return false;
6414             //            }
6415             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6416             //                return false;
6417             //            }
6418             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6419             //                return false;
6420             //            }
6421             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6422             //                return false;
6423             //            }
6424             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6425             //                return false;
6426             //            }
6427             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6428             //                return false;
6429             //            }
6430             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6431             //                return false;
6432             //            }
6433             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6434             //            parser.parse();
6435             //            labels = parser.getCharStateLabels();
6436             //            if ( labels.length != 7 ) {
6437             //                return false;
6438             //            }
6439             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6440             //                return false;
6441             //            }
6442             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6443             //                return false;
6444             //            }
6445             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6446             //                return false;
6447             //            }
6448             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6449             //                return false;
6450             //            }
6451             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6452             //                return false;
6453             //            }
6454             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6455             //                return false;
6456             //            }
6457             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6458             //                return false;
6459             //            }
6460         }
6461         catch ( final Exception e ) {
6462             e.printStackTrace( System.out );
6463             return false;
6464         }
6465         return true;
6466     }
6467
6468     private static boolean testNexusTreeParsing() {
6469         try {
6470             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6471             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6472             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
6473             if ( phylogenies.length != 1 ) {
6474                 return false;
6475             }
6476             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
6477                 return false;
6478             }
6479             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6480                 return false;
6481             }
6482             phylogenies = null;
6483             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
6484             if ( phylogenies.length != 1 ) {
6485                 return false;
6486             }
6487             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6488                 return false;
6489             }
6490             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
6491                 return false;
6492             }
6493             phylogenies = null;
6494             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
6495             if ( phylogenies.length != 1 ) {
6496                 return false;
6497             }
6498             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6499                 return false;
6500             }
6501             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6502                 return false;
6503             }
6504             if ( phylogenies[ 0 ].isRooted() ) {
6505                 return false;
6506             }
6507             phylogenies = null;
6508             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
6509             if ( phylogenies.length != 18 ) {
6510                 return false;
6511             }
6512             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6513                 return false;
6514             }
6515             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
6516                 return false;
6517             }
6518             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
6519                 return false;
6520             }
6521             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
6522                 return false;
6523             }
6524             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6525                 return false;
6526             }
6527             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
6528                 return false;
6529             }
6530             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
6531                 return false;
6532             }
6533             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
6534                 return false;
6535             }
6536             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
6537                 return false;
6538             }
6539             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
6540                 return false;
6541             }
6542             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
6543                 return false;
6544             }
6545             if ( phylogenies[ 8 ].isRooted() ) {
6546                 return false;
6547             }
6548             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
6549                 return false;
6550             }
6551             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
6552                 return false;
6553             }
6554             if ( !phylogenies[ 9 ].isRooted() ) {
6555                 return false;
6556             }
6557             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
6558                 return false;
6559             }
6560             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
6561                 return false;
6562             }
6563             if ( !phylogenies[ 10 ].isRooted() ) {
6564                 return false;
6565             }
6566             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
6567                 return false;
6568             }
6569             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
6570                 return false;
6571             }
6572             if ( phylogenies[ 11 ].isRooted() ) {
6573                 return false;
6574             }
6575             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
6576                 return false;
6577             }
6578             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
6579                 return false;
6580             }
6581             if ( !phylogenies[ 12 ].isRooted() ) {
6582                 return false;
6583             }
6584             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
6585                 return false;
6586             }
6587             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
6588                 return false;
6589             }
6590             if ( !phylogenies[ 13 ].isRooted() ) {
6591                 return false;
6592             }
6593             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
6594                 return false;
6595             }
6596             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
6597                 return false;
6598             }
6599             if ( !phylogenies[ 14 ].isRooted() ) {
6600                 return false;
6601             }
6602             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
6603                 return false;
6604             }
6605             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
6606                 return false;
6607             }
6608             if ( phylogenies[ 15 ].isRooted() ) {
6609                 return false;
6610             }
6611             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
6612                 return false;
6613             }
6614             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
6615                 return false;
6616             }
6617             if ( !phylogenies[ 16 ].isRooted() ) {
6618                 return false;
6619             }
6620             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
6621                 return false;
6622             }
6623             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
6624                 return false;
6625             }
6626             if ( phylogenies[ 17 ].isRooted() ) {
6627                 return false;
6628             }
6629             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
6630                 return false;
6631             }
6632         }
6633         catch ( final Exception e ) {
6634             e.printStackTrace( System.out );
6635             return false;
6636         }
6637         return true;
6638     }
6639
6640     private static boolean testNexusTreeParsingIterating() {
6641         try {
6642             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
6643             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
6644             if ( !p.hasNext() ) {
6645                 return false;
6646             }
6647             Phylogeny phy = p.next();
6648             if ( phy == null ) {
6649                 return false;
6650             }
6651             if ( phy.getNumberOfExternalNodes() != 25 ) {
6652                 return false;
6653             }
6654             if ( !phy.getName().equals( "" ) ) {
6655                 return false;
6656             }
6657             if ( p.hasNext() ) {
6658                 return false;
6659             }
6660             phy = p.next();
6661             if ( phy != null ) {
6662                 return false;
6663             }
6664             //
6665             p.reset();
6666             if ( !p.hasNext() ) {
6667                 return false;
6668             }
6669             phy = p.next();
6670             if ( phy == null ) {
6671                 return false;
6672             }
6673             if ( phy.getNumberOfExternalNodes() != 25 ) {
6674                 return false;
6675             }
6676             if ( !phy.getName().equals( "" ) ) {
6677                 return false;
6678             }
6679             if ( p.hasNext() ) {
6680                 return false;
6681             }
6682             phy = p.next();
6683             if ( phy != null ) {
6684                 return false;
6685             }
6686             ////
6687             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
6688             if ( !p.hasNext() ) {
6689                 return false;
6690             }
6691             phy = p.next();
6692             if ( phy == null ) {
6693                 return false;
6694             }
6695             if ( phy.getNumberOfExternalNodes() != 10 ) {
6696                 return false;
6697             }
6698             if ( !phy.getName().equals( "name" ) ) {
6699                 return false;
6700             }
6701             if ( p.hasNext() ) {
6702                 return false;
6703             }
6704             phy = p.next();
6705             if ( phy != null ) {
6706                 return false;
6707             }
6708             //
6709             p.reset();
6710             if ( !p.hasNext() ) {
6711                 return false;
6712             }
6713             phy = p.next();
6714             if ( phy == null ) {
6715                 return false;
6716             }
6717             if ( phy.getNumberOfExternalNodes() != 10 ) {
6718                 return false;
6719             }
6720             if ( !phy.getName().equals( "name" ) ) {
6721                 return false;
6722             }
6723             if ( p.hasNext() ) {
6724                 return false;
6725             }
6726             phy = p.next();
6727             if ( phy != null ) {
6728                 return false;
6729             }
6730             ////
6731             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
6732             if ( !p.hasNext() ) {
6733                 return false;
6734             }
6735             phy = p.next();
6736             if ( phy == null ) {
6737                 return false;
6738             }
6739             if ( phy.getNumberOfExternalNodes() != 3 ) {
6740                 return false;
6741             }
6742             if ( !phy.getName().equals( "" ) ) {
6743                 return false;
6744             }
6745             if ( phy.isRooted() ) {
6746                 return false;
6747             }
6748             if ( p.hasNext() ) {
6749                 return false;
6750             }
6751             phy = p.next();
6752             if ( phy != null ) {
6753                 return false;
6754             }
6755             //
6756             p.reset();
6757             if ( !p.hasNext() ) {
6758                 return false;
6759             }
6760             phy = p.next();
6761             if ( phy == null ) {
6762                 return false;
6763             }
6764             if ( phy.getNumberOfExternalNodes() != 3 ) {
6765                 return false;
6766             }
6767             if ( !phy.getName().equals( "" ) ) {
6768                 return false;
6769             }
6770             if ( p.hasNext() ) {
6771                 return false;
6772             }
6773             phy = p.next();
6774             if ( phy != null ) {
6775                 return false;
6776             }
6777             ////
6778             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
6779             //            if ( phylogenies.length != 18 ) {
6780             //                return false;
6781             //            }
6782             //0
6783             if ( !p.hasNext() ) {
6784                 return false;
6785             }
6786             phy = p.next();
6787             if ( phy == null ) {
6788                 return false;
6789             }
6790             if ( phy.getNumberOfExternalNodes() != 10 ) {
6791                 return false;
6792             }
6793             if ( !phy.getName().equals( "tree 0" ) ) {
6794                 return false;
6795             }
6796             //1
6797             if ( !p.hasNext() ) {
6798                 return false;
6799             }
6800             phy = p.next();
6801             if ( phy == null ) {
6802                 return false;
6803             }
6804             if ( phy.getNumberOfExternalNodes() != 10 ) {
6805                 return false;
6806             }
6807             if ( !phy.getName().equals( "tree 1" ) ) {
6808                 return false;
6809             }
6810             //2
6811             if ( !p.hasNext() ) {
6812                 return false;
6813             }
6814             phy = p.next();
6815             if ( phy == null ) {
6816                 return false;
6817             }
6818             if ( phy.getNumberOfExternalNodes() != 3 ) {
6819                 return false;
6820             }
6821             if ( !phy.getName().equals( "" ) ) {
6822                 return false;
6823             }
6824             if ( phy.isRooted() ) {
6825                 return false;
6826             }
6827             //3
6828             if ( !p.hasNext() ) {
6829                 return false;
6830             }
6831             phy = p.next();
6832             if ( phy == null ) {
6833                 return false;
6834             }
6835             if ( phy.getNumberOfExternalNodes() != 4 ) {
6836                 return false;
6837             }
6838             if ( !phy.getName().equals( "" ) ) {
6839                 return false;
6840             }
6841             if ( !phy.isRooted() ) {
6842                 return false;
6843             }
6844             //4
6845             if ( !p.hasNext() ) {
6846                 return false;
6847             }
6848             phy = p.next();
6849             if ( phy == null ) {
6850                 return false;
6851             }
6852             if ( phy.getNumberOfExternalNodes() != 5 ) {
6853                 System.out.println( phy.getNumberOfExternalNodes() );
6854                 return false;
6855             }
6856             if ( !phy.getName().equals( "" ) ) {
6857                 return false;
6858             }
6859             if ( !phy.isRooted() ) {
6860                 return false;
6861             }
6862             //5
6863             if ( !p.hasNext() ) {
6864                 return false;
6865             }
6866             phy = p.next();
6867             if ( phy == null ) {
6868                 return false;
6869             }
6870             if ( phy.getNumberOfExternalNodes() != 3 ) {
6871                 return false;
6872             }
6873             if ( !phy.getName().equals( "" ) ) {
6874                 return false;
6875             }
6876             if ( phy.isRooted() ) {
6877                 return false;
6878             }
6879             //6
6880             if ( !p.hasNext() ) {
6881                 return false;
6882             }
6883             phy = p.next();
6884             if ( phy == null ) {
6885                 return false;
6886             }
6887             if ( phy.getNumberOfExternalNodes() != 2 ) {
6888                 return false;
6889             }
6890             if ( !phy.getName().equals( "" ) ) {
6891                 return false;
6892             }
6893             if ( !phy.isRooted() ) {
6894                 return false;
6895             }
6896             //7
6897             if ( !p.hasNext() ) {
6898                 return false;
6899             }
6900             phy = p.next();
6901             if ( phy.getNumberOfExternalNodes() != 3 ) {
6902                 return false;
6903             }
6904             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6905                 return false;
6906             }
6907             if ( !phy.isRooted() ) {
6908                 return false;
6909             }
6910             //8
6911             if ( !p.hasNext() ) {
6912                 return false;
6913             }
6914             phy = p.next();
6915             if ( phy.getNumberOfExternalNodes() != 3 ) {
6916                 return false;
6917             }
6918             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
6919                 return false;
6920             }
6921             if ( !phy.getName().equals( "tree 8" ) ) {
6922                 return false;
6923             }
6924             //9
6925             if ( !p.hasNext() ) {
6926                 return false;
6927             }
6928             phy = p.next();
6929             if ( phy.getNumberOfExternalNodes() != 3 ) {
6930                 return false;
6931             }
6932             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
6933                 return false;
6934             }
6935             if ( !phy.getName().equals( "tree 9" ) ) {
6936                 return false;
6937             }
6938             //10
6939             if ( !p.hasNext() ) {
6940                 return false;
6941             }
6942             phy = p.next();
6943             if ( phy.getNumberOfExternalNodes() != 3 ) {
6944                 return false;
6945             }
6946             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6947                 return false;
6948             }
6949             if ( !phy.getName().equals( "tree 10" ) ) {
6950                 return false;
6951             }
6952             if ( !phy.isRooted() ) {
6953                 return false;
6954             }
6955             //11
6956             if ( !p.hasNext() ) {
6957                 return false;
6958             }
6959             phy = p.next();
6960             if ( phy.getNumberOfExternalNodes() != 3 ) {
6961                 return false;
6962             }
6963             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
6964                 return false;
6965             }
6966             if ( !phy.getName().equals( "tree 11" ) ) {
6967                 return false;
6968             }
6969             if ( phy.isRooted() ) {
6970                 return false;
6971             }
6972             //12
6973             if ( !p.hasNext() ) {
6974                 return false;
6975             }
6976             phy = p.next();
6977             if ( phy.getNumberOfExternalNodes() != 3 ) {
6978                 return false;
6979             }
6980             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
6981                 return false;
6982             }
6983             if ( !phy.getName().equals( "tree 12" ) ) {
6984                 return false;
6985             }
6986             if ( !phy.isRooted() ) {
6987                 return false;
6988             }
6989             //13
6990             if ( !p.hasNext() ) {
6991                 return false;
6992             }
6993             phy = p.next();
6994             if ( phy.getNumberOfExternalNodes() != 3 ) {
6995                 return false;
6996             }
6997             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6998                 return false;
6999             }
7000             if ( !phy.getName().equals( "tree 13" ) ) {
7001                 return false;
7002             }
7003             if ( !phy.isRooted() ) {
7004                 return false;
7005             }
7006             //14
7007             if ( !p.hasNext() ) {
7008                 return false;
7009             }
7010             phy = p.next();
7011             if ( phy.getNumberOfExternalNodes() != 10 ) {
7012                 System.out.println( phy.getNumberOfExternalNodes() );
7013                 return false;
7014             }
7015             if ( !phy
7016                     .toNewHampshire()
7017                     .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;" ) ) {
7018                 System.out.println( phy.toNewHampshire() );
7019                 return false;
7020             }
7021             if ( !phy.getName().equals( "tree 14" ) ) {
7022                 return false;
7023             }
7024             if ( !phy.isRooted() ) {
7025                 return false;
7026             }
7027             //15
7028             if ( !p.hasNext() ) {
7029                 return false;
7030             }
7031             phy = p.next();
7032             if ( phy.getNumberOfExternalNodes() != 10 ) {
7033                 System.out.println( phy.getNumberOfExternalNodes() );
7034                 return false;
7035             }
7036             if ( !phy
7037                     .toNewHampshire()
7038                     .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;" ) ) {
7039                 System.out.println( phy.toNewHampshire() );
7040                 return false;
7041             }
7042             if ( !phy.getName().equals( "tree 15" ) ) {
7043                 return false;
7044             }
7045             if ( phy.isRooted() ) {
7046                 return false;
7047             }
7048             //16
7049             if ( !p.hasNext() ) {
7050                 return false;
7051             }
7052             phy = p.next();
7053             if ( phy.getNumberOfExternalNodes() != 10 ) {
7054                 System.out.println( phy.getNumberOfExternalNodes() );
7055                 return false;
7056             }
7057             if ( !phy
7058                     .toNewHampshire()
7059                     .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;" ) ) {
7060                 System.out.println( phy.toNewHampshire() );
7061                 return false;
7062             }
7063             if ( !phy.getName().equals( "tree 16" ) ) {
7064                 return false;
7065             }
7066             if ( !phy.isRooted() ) {
7067                 return false;
7068             }
7069             //17
7070             if ( !p.hasNext() ) {
7071                 return false;
7072             }
7073             phy = p.next();
7074             if ( phy.getNumberOfExternalNodes() != 10 ) {
7075                 System.out.println( phy.getNumberOfExternalNodes() );
7076                 return false;
7077             }
7078             if ( !phy
7079                     .toNewHampshire()
7080                     .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;" ) ) {
7081                 System.out.println( phy.toNewHampshire() );
7082                 return false;
7083             }
7084             if ( !phy.getName().equals( "tree 17" ) ) {
7085                 return false;
7086             }
7087             if ( phy.isRooted() ) {
7088                 return false;
7089             }
7090             //
7091             if ( p.hasNext() ) {
7092                 return false;
7093             }
7094             phy = p.next();
7095             if ( phy != null ) {
7096                 return false;
7097             }
7098             p.reset();
7099             //0
7100             if ( !p.hasNext() ) {
7101                 return false;
7102             }
7103             phy = p.next();
7104             if ( phy == null ) {
7105                 return false;
7106             }
7107             if ( phy.getNumberOfExternalNodes() != 10 ) {
7108                 return false;
7109             }
7110             if ( !phy.getName().equals( "tree 0" ) ) {
7111                 return false;
7112             }
7113             //1
7114             if ( !p.hasNext() ) {
7115                 return false;
7116             }
7117             phy = p.next();
7118             if ( phy == null ) {
7119                 return false;
7120             }
7121             if ( phy.getNumberOfExternalNodes() != 10 ) {
7122                 return false;
7123             }
7124             if ( !phy.getName().equals( "tree 1" ) ) {
7125                 return false;
7126             }
7127             //2
7128             if ( !p.hasNext() ) {
7129                 return false;
7130             }
7131             phy = p.next();
7132             if ( phy == null ) {
7133                 return false;
7134             }
7135             if ( phy.getNumberOfExternalNodes() != 3 ) {
7136                 return false;
7137             }
7138             if ( !phy.getName().equals( "" ) ) {
7139                 return false;
7140             }
7141             if ( phy.isRooted() ) {
7142                 return false;
7143             }
7144             //3
7145             if ( !p.hasNext() ) {
7146                 return false;
7147             }
7148             phy = p.next();
7149             if ( phy == null ) {
7150                 return false;
7151             }
7152             if ( phy.getNumberOfExternalNodes() != 4 ) {
7153                 return false;
7154             }
7155             if ( !phy.getName().equals( "" ) ) {
7156                 return false;
7157             }
7158             if ( !phy.isRooted() ) {
7159                 return false;
7160             }
7161             //4
7162             if ( !p.hasNext() ) {
7163                 return false;
7164             }
7165             phy = p.next();
7166             if ( phy == null ) {
7167                 return false;
7168             }
7169             if ( phy.getNumberOfExternalNodes() != 5 ) {
7170                 System.out.println( phy.getNumberOfExternalNodes() );
7171                 return false;
7172             }
7173             if ( !phy.getName().equals( "" ) ) {
7174                 return false;
7175             }
7176             if ( !phy.isRooted() ) {
7177                 return false;
7178             }
7179             //5
7180             if ( !p.hasNext() ) {
7181                 return false;
7182             }
7183             phy = p.next();
7184             if ( phy == null ) {
7185                 return false;
7186             }
7187             if ( phy.getNumberOfExternalNodes() != 3 ) {
7188                 return false;
7189             }
7190             if ( !phy.getName().equals( "" ) ) {
7191                 return false;
7192             }
7193             if ( phy.isRooted() ) {
7194                 return false;
7195             }
7196         }
7197         catch ( final Exception e ) {
7198             e.printStackTrace( System.out );
7199             return false;
7200         }
7201         return true;
7202     }
7203
7204     private static boolean testNexusTreeParsingTranslating() {
7205         try {
7206             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7207             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7208             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7209             if ( phylogenies.length != 1 ) {
7210                 return false;
7211             }
7212             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7213                 return false;
7214             }
7215             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7216                 return false;
7217             }
7218             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7219                 return false;
7220             }
7221             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7222                 return false;
7223             }
7224             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7225                     .equals( "Aranaeus" ) ) {
7226                 return false;
7227             }
7228             phylogenies = null;
7229             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7230             if ( phylogenies.length != 3 ) {
7231                 return false;
7232             }
7233             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7234                 return false;
7235             }
7236             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7237                 return false;
7238             }
7239             if ( phylogenies[ 0 ].isRooted() ) {
7240                 return false;
7241             }
7242             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7243                 return false;
7244             }
7245             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7246                 return false;
7247             }
7248             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7249                     .equals( "Aranaeus" ) ) {
7250                 return false;
7251             }
7252             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7253                 return false;
7254             }
7255             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7256                 return false;
7257             }
7258             if ( phylogenies[ 1 ].isRooted() ) {
7259                 return false;
7260             }
7261             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7262                 return false;
7263             }
7264             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7265                 return false;
7266             }
7267             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7268                     .equals( "Aranaeus" ) ) {
7269                 return false;
7270             }
7271             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7272                 return false;
7273             }
7274             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7275                 return false;
7276             }
7277             if ( !phylogenies[ 2 ].isRooted() ) {
7278                 return false;
7279             }
7280             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7281                 return false;
7282             }
7283             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7284                 return false;
7285             }
7286             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7287                     .equals( "Aranaeus" ) ) {
7288                 return false;
7289             }
7290             phylogenies = null;
7291             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
7292             if ( phylogenies.length != 3 ) {
7293                 return false;
7294             }
7295             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7296                 return false;
7297             }
7298             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7299                 return false;
7300             }
7301             if ( phylogenies[ 0 ].isRooted() ) {
7302                 return false;
7303             }
7304             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7305                 return false;
7306             }
7307             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7308                 return false;
7309             }
7310             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7311                     .equals( "Aranaeus" ) ) {
7312                 return false;
7313             }
7314             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7315                 return false;
7316             }
7317             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7318                 return false;
7319             }
7320             if ( phylogenies[ 1 ].isRooted() ) {
7321                 return false;
7322             }
7323             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7324                 return false;
7325             }
7326             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7327                 return false;
7328             }
7329             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7330                     .equals( "Aranaeus" ) ) {
7331                 return false;
7332             }
7333             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7334                 return false;
7335             }
7336             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7337                 return false;
7338             }
7339             if ( !phylogenies[ 2 ].isRooted() ) {
7340                 return false;
7341             }
7342             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7343                 return false;
7344             }
7345             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7346                 return false;
7347             }
7348             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7349                     .equals( "Aranaeus" ) ) {
7350                 return false;
7351             }
7352         }
7353         catch ( final Exception e ) {
7354             e.printStackTrace( System.out );
7355             return false;
7356         }
7357         return true;
7358     }
7359
7360     private static boolean testNHParsing() {
7361         try {
7362             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7363             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
7364             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
7365                 return false;
7366             }
7367             final NHXParser nhxp = new NHXParser();
7368             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
7369             nhxp.setReplaceUnderscores( true );
7370             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
7371             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
7372                 return false;
7373             }
7374             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
7375                 return false;
7376             }
7377             final Phylogeny p1b = factory
7378                     .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 ",
7379                              new NHXParser() )[ 0 ];
7380             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
7381                 return false;
7382             }
7383             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
7384                 return false;
7385             }
7386             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
7387             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
7388             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
7389             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
7390             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
7391             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
7392             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
7393             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
7394             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
7395             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
7396             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
7397                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
7398                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
7399                                                     new NHXParser() );
7400             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
7401                 return false;
7402             }
7403             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
7404                 return false;
7405             }
7406             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
7407                 return false;
7408             }
7409             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
7410                 return false;
7411             }
7412             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
7413             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
7414             final String p16_S = "((A,B),C)";
7415             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
7416             if ( p16.length != 1 ) {
7417                 return false;
7418             }
7419             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
7420                 return false;
7421             }
7422             final String p17_S = "(C,(A,B))";
7423             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
7424             if ( p17.length != 1 ) {
7425                 return false;
7426             }
7427             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
7428                 return false;
7429             }
7430             final String p18_S = "((A,B),(C,D))";
7431             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
7432             if ( p18.length != 1 ) {
7433                 return false;
7434             }
7435             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
7436                 return false;
7437             }
7438             final String p19_S = "(((A,B),C),D)";
7439             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
7440             if ( p19.length != 1 ) {
7441                 return false;
7442             }
7443             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
7444                 return false;
7445             }
7446             final String p20_S = "(A,(B,(C,D)))";
7447             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
7448             if ( p20.length != 1 ) {
7449                 return false;
7450             }
7451             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
7452                 return false;
7453             }
7454             final String p21_S = "(A,(B,(C,(D,E))))";
7455             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
7456             if ( p21.length != 1 ) {
7457                 return false;
7458             }
7459             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
7460                 return false;
7461             }
7462             final String p22_S = "((((A,B),C),D),E)";
7463             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
7464             if ( p22.length != 1 ) {
7465                 return false;
7466             }
7467             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
7468                 return false;
7469             }
7470             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7471             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
7472             if ( p23.length != 1 ) {
7473                 System.out.println( "xl=" + p23.length );
7474                 System.exit( -1 );
7475                 return false;
7476             }
7477             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
7478                 return false;
7479             }
7480             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7481             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
7482             if ( p24.length != 1 ) {
7483                 return false;
7484             }
7485             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
7486                 return false;
7487             }
7488             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7489             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7490             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
7491             if ( p241.length != 2 ) {
7492                 return false;
7493             }
7494             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
7495                 return false;
7496             }
7497             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
7498                 return false;
7499             }
7500             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
7501                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
7502                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
7503                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
7504                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
7505                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
7506                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
7507                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
7508             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
7509             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
7510                 return false;
7511             }
7512             final String p26_S = "(A,B)ab";
7513             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
7514             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
7515                 return false;
7516             }
7517             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7518             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
7519             if ( p27s.length != 1 ) {
7520                 System.out.println( "xxl=" + p27s.length );
7521                 System.exit( -1 );
7522                 return false;
7523             }
7524             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7525                 System.out.println( p27s[ 0 ].toNewHampshireX() );
7526                 System.exit( -1 );
7527                 return false;
7528             }
7529             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
7530                                                     new NHXParser() );
7531             if ( p27.length != 1 ) {
7532                 System.out.println( "yl=" + p27.length );
7533                 System.exit( -1 );
7534                 return false;
7535             }
7536             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7537                 System.out.println( p27[ 0 ].toNewHampshireX() );
7538                 System.exit( -1 );
7539                 return false;
7540             }
7541             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7542             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7543             final String p28_S3 = "(A,B)ab";
7544             final String p28_S4 = "((((A,B),C),D),;E;)";
7545             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
7546                                                     new NHXParser() );
7547             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
7548                 return false;
7549             }
7550             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
7551                 return false;
7552             }
7553             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
7554                 return false;
7555             }
7556             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
7557                 return false;
7558             }
7559             if ( p28.length != 4 ) {
7560                 return false;
7561             }
7562             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";
7563             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
7564             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
7565                 return false;
7566             }
7567             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";
7568             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
7569             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
7570                 return false;
7571             }
7572             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
7573             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
7574             if ( ( p32.length != 0 ) ) {
7575                 return false;
7576             }
7577             final String p33_S = "A";
7578             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
7579             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
7580                 return false;
7581             }
7582             final String p34_S = "B;";
7583             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
7584             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
7585                 return false;
7586             }
7587             final String p35_S = "B:0.2";
7588             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
7589             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
7590                 return false;
7591             }
7592             final String p36_S = "(A)";
7593             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
7594             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
7595                 return false;
7596             }
7597             final String p37_S = "((A))";
7598             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
7599             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
7600                 return false;
7601             }
7602             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7603             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
7604             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
7605                 return false;
7606             }
7607             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7608             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
7609             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
7610                 return false;
7611             }
7612             final String p40_S = "(A,B,C)";
7613             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
7614             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
7615                 return false;
7616             }
7617             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
7618             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
7619             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
7620                 return false;
7621             }
7622             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
7623             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
7624             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
7625                 return false;
7626             }
7627             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)";
7628             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
7629             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
7630                 return false;
7631             }
7632             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)))";
7633             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
7634             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
7635                 return false;
7636             }
7637             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
7638             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
7639             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
7640                 return false;
7641             }
7642             final String p46_S = "";
7643             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
7644             if ( p46.length != 0 ) {
7645                 return false;
7646             }
7647             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
7648             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7649                 return false;
7650             }
7651             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7652             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7653                 return false;
7654             }
7655             final Phylogeny p49 = factory
7656                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
7657                              new NHXParser() )[ 0 ];
7658             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7659                 return false;
7660             }
7661             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7662             if ( p50.getNode( "A" ) == null ) {
7663                 return false;
7664             }
7665             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7666                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
7667                 return false;
7668             }
7669             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
7670                 return false;
7671             }
7672             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
7673                     .equals( "((A,B)88:2.0,C);" ) ) {
7674                 return false;
7675             }
7676             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7677             if ( p51.getNode( "A(A" ) == null ) {
7678                 return false;
7679             }
7680             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7681             if ( p52.getNode( "A(A" ) == null ) {
7682                 return false;
7683             }
7684             final Phylogeny p53 = factory
7685                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
7686                              new NHXParser() )[ 0 ];
7687             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
7688                 return false;
7689             }
7690             // 
7691             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
7692             if ( p54.getNode( "A" ) == null ) {
7693                 return false;
7694             }
7695             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7696                     .equals( "((A,B)[88],C);" ) ) {
7697                 return false;
7698             }
7699         }
7700         catch ( final Exception e ) {
7701             e.printStackTrace( System.out );
7702             return false;
7703         }
7704         return true;
7705     }
7706
7707     private static boolean testNHParsingIter() {
7708         try {
7709             final String p0_str = "(A,B);";
7710             final NHXParser p = new NHXParser();
7711             p.setSource( p0_str );
7712             if ( !p.hasNext() ) {
7713                 return false;
7714             }
7715             final Phylogeny p0 = p.next();
7716             if ( !p0.toNewHampshire().equals( p0_str ) ) {
7717                 System.out.println( p0.toNewHampshire() );
7718                 return false;
7719             }
7720             if ( p.hasNext() ) {
7721                 return false;
7722             }
7723             if ( p.next() != null ) {
7724                 return false;
7725             }
7726             //
7727             final String p00_str = "(A,B)root;";
7728             p.setSource( p00_str );
7729             final Phylogeny p00 = p.next();
7730             if ( !p00.toNewHampshire().equals( p00_str ) ) {
7731                 System.out.println( p00.toNewHampshire() );
7732                 return false;
7733             }
7734             //
7735             final String p000_str = "A;";
7736             p.setSource( p000_str );
7737             final Phylogeny p000 = p.next();
7738             if ( !p000.toNewHampshire().equals( p000_str ) ) {
7739                 System.out.println( p000.toNewHampshire() );
7740                 return false;
7741             }
7742             //
7743             final String p0000_str = "A";
7744             p.setSource( p0000_str );
7745             final Phylogeny p0000 = p.next();
7746             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
7747                 System.out.println( p0000.toNewHampshire() );
7748                 return false;
7749             }
7750             //
7751             p.setSource( "(A)" );
7752             final Phylogeny p00000 = p.next();
7753             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
7754                 System.out.println( p00000.toNewHampshire() );
7755                 return false;
7756             }
7757             //
7758             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
7759             p.setSource( p1_str );
7760             if ( !p.hasNext() ) {
7761                 return false;
7762             }
7763             final Phylogeny p1_0 = p.next();
7764             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
7765                 System.out.println( p1_0.toNewHampshire() );
7766                 return false;
7767             }
7768             if ( !p.hasNext() ) {
7769                 return false;
7770             }
7771             final Phylogeny p1_1 = p.next();
7772             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
7773                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
7774                 return false;
7775             }
7776             if ( !p.hasNext() ) {
7777                 return false;
7778             }
7779             final Phylogeny p1_2 = p.next();
7780             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
7781                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
7782                 return false;
7783             }
7784             if ( !p.hasNext() ) {
7785                 return false;
7786             }
7787             final Phylogeny p1_3 = p.next();
7788             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
7789                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
7790                 return false;
7791             }
7792             if ( p.hasNext() ) {
7793                 return false;
7794             }
7795             if ( p.next() != null ) {
7796                 return false;
7797             }
7798             //
7799             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
7800             p.setSource( p2_str );
7801             if ( !p.hasNext() ) {
7802                 return false;
7803             }
7804             Phylogeny p2_0 = p.next();
7805             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7806                 System.out.println( p2_0.toNewHampshire() );
7807                 return false;
7808             }
7809             if ( !p.hasNext() ) {
7810                 return false;
7811             }
7812             Phylogeny p2_1 = p.next();
7813             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7814                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7815                 return false;
7816             }
7817             if ( !p.hasNext() ) {
7818                 return false;
7819             }
7820             Phylogeny p2_2 = p.next();
7821             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7822                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7823                 return false;
7824             }
7825             if ( !p.hasNext() ) {
7826                 return false;
7827             }
7828             Phylogeny p2_3 = p.next();
7829             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7830                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7831                 return false;
7832             }
7833             if ( !p.hasNext() ) {
7834                 return false;
7835             }
7836             Phylogeny p2_4 = p.next();
7837             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7838                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7839                 return false;
7840             }
7841             if ( p.hasNext() ) {
7842                 return false;
7843             }
7844             if ( p.next() != null ) {
7845                 return false;
7846             }
7847             ////
7848             p.reset();
7849             if ( !p.hasNext() ) {
7850                 return false;
7851             }
7852             p2_0 = p.next();
7853             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7854                 System.out.println( p2_0.toNewHampshire() );
7855                 return false;
7856             }
7857             if ( !p.hasNext() ) {
7858                 return false;
7859             }
7860             p2_1 = p.next();
7861             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7862                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7863                 return false;
7864             }
7865             if ( !p.hasNext() ) {
7866                 return false;
7867             }
7868             p2_2 = p.next();
7869             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7870                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7871                 return false;
7872             }
7873             if ( !p.hasNext() ) {
7874                 return false;
7875             }
7876             p2_3 = p.next();
7877             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7878                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7879                 return false;
7880             }
7881             if ( !p.hasNext() ) {
7882                 return false;
7883             }
7884             p2_4 = p.next();
7885             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7886                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7887                 return false;
7888             }
7889             if ( p.hasNext() ) {
7890                 return false;
7891             }
7892             if ( p.next() != null ) {
7893                 return false;
7894             }
7895             //
7896             final String p3_str = "((A,B),C)abc";
7897             p.setSource( p3_str );
7898             if ( !p.hasNext() ) {
7899                 return false;
7900             }
7901             final Phylogeny p3_0 = p.next();
7902             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
7903                 return false;
7904             }
7905             if ( p.hasNext() ) {
7906                 return false;
7907             }
7908             if ( p.next() != null ) {
7909                 return false;
7910             }
7911             //
7912             final String p4_str = "((A,B)ab,C)abc";
7913             p.setSource( p4_str );
7914             if ( !p.hasNext() ) {
7915                 return false;
7916             }
7917             final Phylogeny p4_0 = p.next();
7918             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
7919                 return false;
7920             }
7921             if ( p.hasNext() ) {
7922                 return false;
7923             }
7924             if ( p.next() != null ) {
7925                 return false;
7926             }
7927             //
7928             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
7929             p.setSource( p5_str );
7930             if ( !p.hasNext() ) {
7931                 return false;
7932             }
7933             final Phylogeny p5_0 = p.next();
7934             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
7935                 return false;
7936             }
7937             if ( p.hasNext() ) {
7938                 return false;
7939             }
7940             if ( p.next() != null ) {
7941                 return false;
7942             }
7943             //
7944             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7945             p.setSource( p6_str );
7946             if ( !p.hasNext() ) {
7947                 return false;
7948             }
7949             Phylogeny p6_0 = p.next();
7950             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7951                 return false;
7952             }
7953             if ( p.hasNext() ) {
7954                 return false;
7955             }
7956             if ( p.next() != null ) {
7957                 return false;
7958             }
7959             p.reset();
7960             if ( !p.hasNext() ) {
7961                 return false;
7962             }
7963             p6_0 = p.next();
7964             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7965                 return false;
7966             }
7967             if ( p.hasNext() ) {
7968                 return false;
7969             }
7970             if ( p.next() != null ) {
7971                 return false;
7972             }
7973             //
7974             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7975             p.setSource( p7_str );
7976             if ( !p.hasNext() ) {
7977                 return false;
7978             }
7979             Phylogeny p7_0 = p.next();
7980             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7981                 return false;
7982             }
7983             if ( p.hasNext() ) {
7984                 return false;
7985             }
7986             if ( p.next() != null ) {
7987                 return false;
7988             }
7989             p.reset();
7990             if ( !p.hasNext() ) {
7991                 return false;
7992             }
7993             p7_0 = p.next();
7994             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7995                 return false;
7996             }
7997             if ( p.hasNext() ) {
7998                 return false;
7999             }
8000             if ( p.next() != null ) {
8001                 return false;
8002             }
8003             //
8004             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8005             p.setSource( p8_str );
8006             if ( !p.hasNext() ) {
8007                 return false;
8008             }
8009             Phylogeny p8_0 = p.next();
8010             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8011                 return false;
8012             }
8013             if ( !p.hasNext() ) {
8014                 return false;
8015             }
8016             if ( !p.hasNext() ) {
8017                 return false;
8018             }
8019             Phylogeny p8_1 = p.next();
8020             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8021                 return false;
8022             }
8023             if ( p.hasNext() ) {
8024                 return false;
8025             }
8026             if ( p.next() != null ) {
8027                 return false;
8028             }
8029             p.reset();
8030             if ( !p.hasNext() ) {
8031                 return false;
8032             }
8033             p8_0 = p.next();
8034             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8035                 return false;
8036             }
8037             if ( !p.hasNext() ) {
8038                 return false;
8039             }
8040             p8_1 = p.next();
8041             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8042                 return false;
8043             }
8044             if ( p.hasNext() ) {
8045                 return false;
8046             }
8047             if ( p.next() != null ) {
8048                 return false;
8049             }
8050             p.reset();
8051             //
8052             p.setSource( "" );
8053             if ( p.hasNext() ) {
8054                 return false;
8055             }
8056             //
8057             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8058             if ( !p.hasNext() ) {
8059                 return false;
8060             }
8061             Phylogeny p_27 = p.next();
8062             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8063                 System.out.println( p_27.toNewHampshireX() );
8064                 System.exit( -1 );
8065                 return false;
8066             }
8067             if ( p.hasNext() ) {
8068                 return false;
8069             }
8070             if ( p.next() != null ) {
8071                 return false;
8072             }
8073             p.reset();
8074             if ( !p.hasNext() ) {
8075                 return false;
8076             }
8077             p_27 = p.next();
8078             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8079                 System.out.println( p_27.toNewHampshireX() );
8080                 System.exit( -1 );
8081                 return false;
8082             }
8083             if ( p.hasNext() ) {
8084                 return false;
8085             }
8086             if ( p.next() != null ) {
8087                 return false;
8088             }
8089             //
8090             final String p30_str = "(A,B);(C,D)";
8091             final NHXParser p30 = new NHXParser();
8092             p30.setSource( p30_str );
8093             if ( !p30.hasNext() ) {
8094                 return false;
8095             }
8096             Phylogeny phy30 = p30.next();
8097             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8098                 System.out.println( phy30.toNewHampshire() );
8099                 return false;
8100             }
8101             if ( !p30.hasNext() ) {
8102                 return false;
8103             }
8104             Phylogeny phy301 = p30.next();
8105             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8106                 System.out.println( phy301.toNewHampshire() );
8107                 return false;
8108             }
8109             if ( p30.hasNext() ) {
8110                 return false;
8111             }
8112             if ( p30.hasNext() ) {
8113                 return false;
8114             }
8115             if ( p30.next() != null ) {
8116                 return false;
8117             }
8118             if ( p30.next() != null ) {
8119                 return false;
8120             }
8121             p30.reset();
8122             if ( !p30.hasNext() ) {
8123                 return false;
8124             }
8125             phy30 = p30.next();
8126             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8127                 System.out.println( phy30.toNewHampshire() );
8128                 return false;
8129             }
8130             if ( !p30.hasNext() ) {
8131                 return false;
8132             }
8133             phy301 = p30.next();
8134             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8135                 System.out.println( phy301.toNewHampshire() );
8136                 return false;
8137             }
8138             if ( p30.hasNext() ) {
8139                 return false;
8140             }
8141             if ( p30.hasNext() ) {
8142                 return false;
8143             }
8144             if ( p30.next() != null ) {
8145                 return false;
8146             }
8147             if ( p30.next() != null ) {
8148                 return false;
8149             }
8150         }
8151         catch ( final Exception e ) {
8152             e.printStackTrace( System.out );
8153             return false;
8154         }
8155         return true;
8156     }
8157
8158     private static boolean testNHXconversion() {
8159         try {
8160             final PhylogenyNode n1 = new PhylogenyNode();
8161             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8162             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8163             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8164             final PhylogenyNode n5 = PhylogenyNode
8165                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8166             final PhylogenyNode n6 = PhylogenyNode
8167                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8168             if ( !n1.toNewHampshireX().equals( "" ) ) {
8169                 return false;
8170             }
8171             if ( !n2.toNewHampshireX().equals( "" ) ) {
8172                 return false;
8173             }
8174             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8175                 return false;
8176             }
8177             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8178                 return false;
8179             }
8180             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8181                 return false;
8182             }
8183             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8184                 System.out.println( n6.toNewHampshireX() );
8185                 return false;
8186             }
8187         }
8188         catch ( final Exception e ) {
8189             e.printStackTrace( System.out );
8190             return false;
8191         }
8192         return true;
8193     }
8194
8195     private static boolean testNHXNodeParsing() {
8196         try {
8197             final PhylogenyNode n1 = new PhylogenyNode();
8198             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8199             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8200             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8201             final PhylogenyNode n5 = PhylogenyNode
8202                     .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]" );
8203             if ( !n3.getName().equals( "n3" ) ) {
8204                 return false;
8205             }
8206             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8207                 return false;
8208             }
8209             if ( n3.isDuplication() ) {
8210                 return false;
8211             }
8212             if ( n3.isHasAssignedEvent() ) {
8213                 return false;
8214             }
8215             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
8216                 return false;
8217             }
8218             if ( !n4.getName().equals( "n4" ) ) {
8219                 return false;
8220             }
8221             if ( n4.getDistanceToParent() != 0.01 ) {
8222                 return false;
8223             }
8224             if ( !n5.getName().equals( "n5" ) ) {
8225                 return false;
8226             }
8227             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
8228                 return false;
8229             }
8230             if ( n5.getDistanceToParent() != 0.1 ) {
8231                 return false;
8232             }
8233             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
8234                 return false;
8235             }
8236             if ( !n5.isDuplication() ) {
8237                 return false;
8238             }
8239             if ( !n5.isHasAssignedEvent() ) {
8240                 return false;
8241             }
8242             final PhylogenyNode n8 = PhylogenyNode
8243                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
8244                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8245             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8246                 return false;
8247             }
8248             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
8249                 return false;
8250             }
8251             final PhylogenyNode n9 = PhylogenyNode
8252                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
8253                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8254             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
8255                 return false;
8256             }
8257             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
8258                 return false;
8259             }
8260             final PhylogenyNode n10 = PhylogenyNode
8261                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8262             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
8263                 return false;
8264             }
8265             final PhylogenyNode n20 = PhylogenyNode
8266                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8267             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8268                 return false;
8269             }
8270             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
8271                 return false;
8272             }
8273             final PhylogenyNode n20x = PhylogenyNode
8274                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8275             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
8276                 return false;
8277             }
8278             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
8279                 return false;
8280             }
8281             final PhylogenyNode n20xx = PhylogenyNode
8282                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8283             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
8284                 return false;
8285             }
8286             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
8287                 return false;
8288             }
8289             final PhylogenyNode n20xxx = PhylogenyNode
8290                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8291             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
8292                 return false;
8293             }
8294             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
8295                 return false;
8296             }
8297             final PhylogenyNode n20xxxx = PhylogenyNode
8298                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8299             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
8300                 return false;
8301             }
8302             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
8303                 return false;
8304             }
8305             final PhylogenyNode n21 = PhylogenyNode
8306                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8307             if ( !n21.getName().equals( "N21_PIG" ) ) {
8308                 return false;
8309             }
8310             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
8311                 return false;
8312             }
8313             final PhylogenyNode n21x = PhylogenyNode
8314                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8315             if ( !n21x.getName().equals( "n21_PIG" ) ) {
8316                 return false;
8317             }
8318             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
8319                 return false;
8320             }
8321             final PhylogenyNode n22 = PhylogenyNode
8322                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8323             if ( !n22.getName().equals( "n22/PIG" ) ) {
8324                 return false;
8325             }
8326             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
8327                 return false;
8328             }
8329             final PhylogenyNode n23 = PhylogenyNode
8330                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8331             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
8332                 return false;
8333             }
8334             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
8335                 return false;
8336             }
8337             final PhylogenyNode a = PhylogenyNode
8338                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8339             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8340                 return false;
8341             }
8342             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
8343                 return false;
8344             }
8345             final PhylogenyNode c1 = PhylogenyNode
8346                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
8347                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8348             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
8349                 return false;
8350             }
8351             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
8352                 return false;
8353             }
8354             final PhylogenyNode c2 = PhylogenyNode
8355                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
8356                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8357             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
8358                 return false;
8359             }
8360             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
8361                 return false;
8362             }
8363             final PhylogenyNode e3 = PhylogenyNode
8364                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8365             if ( !e3.getName().equals( "n10_RAT~" ) ) {
8366                 return false;
8367             }
8368             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
8369                 return false;
8370             }
8371             final PhylogenyNode n11 = PhylogenyNode
8372                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
8373                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8374             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
8375                 return false;
8376             }
8377             if ( n11.getDistanceToParent() != 0.4 ) {
8378                 return false;
8379             }
8380             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
8381                 return false;
8382             }
8383             final PhylogenyNode n12 = PhylogenyNode
8384                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
8385                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8386             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
8387                 return false;
8388             }
8389             if ( n12.getDistanceToParent() != 0.4 ) {
8390                 return false;
8391             }
8392             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
8393                 return false;
8394             }
8395             final PhylogenyNode o = PhylogenyNode
8396                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8397             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
8398                 return false;
8399             }
8400             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
8401                 return false;
8402             }
8403             if ( n1.getName().compareTo( "" ) != 0 ) {
8404                 return false;
8405             }
8406             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8407                 return false;
8408             }
8409             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8410                 return false;
8411             }
8412             if ( n2.getName().compareTo( "" ) != 0 ) {
8413                 return false;
8414             }
8415             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8416                 return false;
8417             }
8418             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8419                 return false;
8420             }
8421             final PhylogenyNode n00 = PhylogenyNode
8422                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
8423             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
8424                 return false;
8425             }
8426             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
8427                 return false;
8428             }
8429             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
8430             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
8431                 return false;
8432             }
8433             final PhylogenyNode n13 = PhylogenyNode
8434                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8435             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
8436                 return false;
8437             }
8438             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
8439                 return false;
8440             }
8441             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8442                 return false;
8443             }
8444             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8445                 return false;
8446             }
8447             final PhylogenyNode n14 = PhylogenyNode
8448                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8449             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
8450                 return false;
8451             }
8452             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
8453                 return false;
8454             }
8455             final PhylogenyNode n15 = PhylogenyNode
8456                     .createInstanceFromNhxString( "something_wicked[123]",
8457                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8458             if ( !n15.getName().equals( "something_wicked" ) ) {
8459                 return false;
8460             }
8461             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
8462                 return false;
8463             }
8464             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
8465                 return false;
8466             }
8467             final PhylogenyNode n16 = PhylogenyNode
8468                     .createInstanceFromNhxString( "something_wicked2[9]",
8469                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8470             if ( !n16.getName().equals( "something_wicked2" ) ) {
8471                 return false;
8472             }
8473             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
8474                 return false;
8475             }
8476             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
8477                 return false;
8478             }
8479             final PhylogenyNode n17 = PhylogenyNode
8480                     .createInstanceFromNhxString( "something_wicked3[a]",
8481                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8482             if ( !n17.getName().equals( "something_wicked3" ) ) {
8483                 return false;
8484             }
8485             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
8486                 return false;
8487             }
8488             final PhylogenyNode n18 = PhylogenyNode
8489                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8490             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
8491                 return false;
8492             }
8493             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
8494                 return false;
8495             }
8496             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
8497                 return false;
8498             }
8499             final PhylogenyNode n19 = PhylogenyNode
8500                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8501             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
8502                 return false;
8503             }
8504             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8505                 return false;
8506             }
8507             final PhylogenyNode n30 = PhylogenyNode
8508                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
8509                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8510             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
8511                 return false;
8512             }
8513             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8514                 return false;
8515             }
8516             final PhylogenyNode n31 = PhylogenyNode
8517                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
8518                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8519             if ( n31.getNodeData().isHasTaxonomy() ) {
8520                 return false;
8521             }
8522             final PhylogenyNode n32 = PhylogenyNode
8523                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8524             if ( n32.getNodeData().isHasTaxonomy() ) {
8525                 return false;
8526             }
8527             final PhylogenyNode n40 = PhylogenyNode
8528                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8529             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8530                 return false;
8531             }
8532             final PhylogenyNode n41 = PhylogenyNode
8533                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8534             if ( n41.getNodeData().isHasTaxonomy() ) {
8535                 return false;
8536             }
8537             final PhylogenyNode n42 = PhylogenyNode
8538                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8539             if ( n42.getNodeData().isHasTaxonomy() ) {
8540                 return false;
8541             }
8542             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
8543                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
8544             if ( n43.getNodeData().isHasTaxonomy() ) {
8545                 return false;
8546             }
8547             final PhylogenyNode n44 = PhylogenyNode
8548                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8549             if ( n44.getNodeData().isHasTaxonomy() ) {
8550                 return false;
8551             }
8552         }
8553         catch ( final Exception e ) {
8554             e.printStackTrace( System.out );
8555             return false;
8556         }
8557         return true;
8558     }
8559
8560     private static boolean testNHXParsing() {
8561         try {
8562             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8563             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
8564             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
8565                 return false;
8566             }
8567             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]";
8568             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
8569             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8570                 return false;
8571             }
8572             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]";
8573             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
8574             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
8575                 return false;
8576             }
8577             final Phylogeny[] p3 = factory
8578                     .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]",
8579                              new NHXParser() );
8580             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8581                 return false;
8582             }
8583             final Phylogeny[] p4 = factory
8584                     .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(]",
8585                              new NHXParser() );
8586             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8587                 return false;
8588             }
8589             final Phylogeny[] p5 = factory
8590                     .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(((]",
8591                              new NHXParser() );
8592             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8593                 return false;
8594             }
8595             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)";
8596             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)";
8597             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
8598             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
8599                 return false;
8600             }
8601             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)))";
8602             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)))";
8603             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
8604             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
8605                 return false;
8606             }
8607             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])   ))[,,, ])))))))";
8608             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
8609             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
8610             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
8611                 return false;
8612             }
8613             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
8614             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8615                 return false;
8616             }
8617             final Phylogeny p10 = factory
8618                     .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]",
8619                              new NHXParser() )[ 0 ];
8620             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8621                 return false;
8622             }
8623         }
8624         catch ( final Exception e ) {
8625             e.printStackTrace( System.out );
8626             return false;
8627         }
8628         return true;
8629     }
8630
8631     private static boolean testNHXParsingMB() {
8632         try {
8633             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8634             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
8635                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8636                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8637                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8638                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8639                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8640                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8641                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8642                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
8643             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
8644                 return false;
8645             }
8646             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
8647                 return false;
8648             }
8649             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
8650                            0.1100000000000000e+00 ) ) {
8651                 return false;
8652             }
8653             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
8654                 return false;
8655             }
8656             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
8657                 return false;
8658             }
8659             final Phylogeny p2 = factory
8660                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
8661                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8662                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8663                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8664                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8665                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8666                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8667                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8668                                      + "7.369400000000000e-02}])",
8669                              new NHXParser() )[ 0 ];
8670             if ( p2.getNode( "1" ) == null ) {
8671                 return false;
8672             }
8673             if ( p2.getNode( "2" ) == null ) {
8674                 return false;
8675             }
8676         }
8677         catch ( final Exception e ) {
8678             e.printStackTrace( System.out );
8679             System.exit( -1 );
8680             return false;
8681         }
8682         return true;
8683     }
8684
8685     private static boolean testNHXParsingQuotes() {
8686         try {
8687             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8688             final NHXParser p = new NHXParser();
8689             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
8690             if ( phylogenies_0.length != 5 ) {
8691                 return false;
8692             }
8693             final Phylogeny phy = phylogenies_0[ 4 ];
8694             if ( phy.getNumberOfExternalNodes() != 7 ) {
8695                 return false;
8696             }
8697             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
8698                 return false;
8699             }
8700             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
8701                 return false;
8702             }
8703             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
8704                     .getScientificName().equals( "hsapiens" ) ) {
8705                 return false;
8706             }
8707             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
8708                 return false;
8709             }
8710             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
8711                 return false;
8712             }
8713             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
8714                 return false;
8715             }
8716             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
8717                 return false;
8718             }
8719             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
8720                 return false;
8721             }
8722             final NHXParser p1p = new NHXParser();
8723             p1p.setIgnoreQuotes( true );
8724             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
8725             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
8726                 return false;
8727             }
8728             final NHXParser p2p = new NHXParser();
8729             p1p.setIgnoreQuotes( false );
8730             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
8731             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
8732                 return false;
8733             }
8734             final NHXParser p3p = new NHXParser();
8735             p3p.setIgnoreQuotes( false );
8736             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
8737             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
8738                 return false;
8739             }
8740             final NHXParser p4p = new NHXParser();
8741             p4p.setIgnoreQuotes( false );
8742             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
8743             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
8744                 return false;
8745             }
8746             final Phylogeny p10 = factory
8747                     .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]",
8748                              new NHXParser() )[ 0 ];
8749             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]";
8750             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
8751                 return false;
8752             }
8753             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
8754             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
8755                 return false;
8756             }
8757             //
8758             final Phylogeny p12 = factory
8759                     .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]",
8760                              new NHXParser() )[ 0 ];
8761             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]";
8762             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
8763                 return false;
8764             }
8765             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
8766             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
8767                 return false;
8768             }
8769             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;";
8770             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
8771                 return false;
8772             }
8773             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
8774             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
8775                 return false;
8776             }
8777         }
8778         catch ( final Exception e ) {
8779             e.printStackTrace( System.out );
8780             return false;
8781         }
8782         return true;
8783     }
8784
8785     private static boolean testNodeRemoval() {
8786         try {
8787             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8788             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
8789             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
8790             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
8791                 return false;
8792             }
8793             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
8794             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
8795             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
8796                 return false;
8797             }
8798             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
8799             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
8800             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
8801                 return false;
8802             }
8803         }
8804         catch ( final Exception e ) {
8805             e.printStackTrace( System.out );
8806             return false;
8807         }
8808         return true;
8809     }
8810
8811     private static boolean testPhylogenyBranch() {
8812         try {
8813             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
8814             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
8815             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
8816             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
8817             if ( !a1b1.equals( a1b1 ) ) {
8818                 return false;
8819             }
8820             if ( !a1b1.equals( b1a1 ) ) {
8821                 return false;
8822             }
8823             if ( !b1a1.equals( a1b1 ) ) {
8824                 return false;
8825             }
8826             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
8827             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
8828             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
8829             if ( a1_b1.equals( b1_a1 ) ) {
8830                 return false;
8831             }
8832             if ( a1_b1.equals( a1_b1_ ) ) {
8833                 return false;
8834             }
8835             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
8836             if ( !a1_b1.equals( b1_a1_ ) ) {
8837                 return false;
8838             }
8839             if ( a1_b1_.equals( b1_a1_ ) ) {
8840                 return false;
8841             }
8842             if ( !a1_b1_.equals( b1_a1 ) ) {
8843                 return false;
8844             }
8845         }
8846         catch ( final Exception e ) {
8847             e.printStackTrace( System.out );
8848             return false;
8849         }
8850         return true;
8851     }
8852
8853     private static boolean testPhyloXMLparsingOfDistributionElement() {
8854         try {
8855             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8856             PhyloXmlParser xml_parser = null;
8857             try {
8858                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
8859             }
8860             catch ( final Exception e ) {
8861                 // Do nothing -- means were not running from jar.
8862             }
8863             if ( xml_parser == null ) {
8864                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
8865                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
8866                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
8867                 }
8868                 else {
8869                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
8870                 }
8871             }
8872             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
8873                                                               xml_parser );
8874             if ( xml_parser.getErrorCount() > 0 ) {
8875                 System.out.println( xml_parser.getErrorMessages().toString() );
8876                 return false;
8877             }
8878             if ( phylogenies_0.length != 1 ) {
8879                 return false;
8880             }
8881             final Phylogeny t1 = phylogenies_0[ 0 ];
8882             PhylogenyNode n = null;
8883             Distribution d = null;
8884             n = t1.getNode( "root node" );
8885             if ( !n.getNodeData().isHasDistribution() ) {
8886                 return false;
8887             }
8888             if ( n.getNodeData().getDistributions().size() != 1 ) {
8889                 return false;
8890             }
8891             d = n.getNodeData().getDistribution();
8892             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8893                 return false;
8894             }
8895             if ( d.getPoints().size() != 1 ) {
8896                 return false;
8897             }
8898             if ( d.getPolygons() != null ) {
8899                 return false;
8900             }
8901             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8902                 return false;
8903             }
8904             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8905                 return false;
8906             }
8907             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8908                 return false;
8909             }
8910             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8911                 return false;
8912             }
8913             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8914                 return false;
8915             }
8916             n = t1.getNode( "node a" );
8917             if ( !n.getNodeData().isHasDistribution() ) {
8918                 return false;
8919             }
8920             if ( n.getNodeData().getDistributions().size() != 2 ) {
8921                 return false;
8922             }
8923             d = n.getNodeData().getDistribution( 1 );
8924             if ( !d.getDesc().equals( "San Diego" ) ) {
8925                 return false;
8926             }
8927             if ( d.getPoints().size() != 1 ) {
8928                 return false;
8929             }
8930             if ( d.getPolygons() != null ) {
8931                 return false;
8932             }
8933             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8934                 return false;
8935             }
8936             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8937                 return false;
8938             }
8939             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8940                 return false;
8941             }
8942             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8943                 return false;
8944             }
8945             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8946                 return false;
8947             }
8948             n = t1.getNode( "node bb" );
8949             if ( !n.getNodeData().isHasDistribution() ) {
8950                 return false;
8951             }
8952             if ( n.getNodeData().getDistributions().size() != 1 ) {
8953                 return false;
8954             }
8955             d = n.getNodeData().getDistribution( 0 );
8956             if ( d.getPoints().size() != 3 ) {
8957                 return false;
8958             }
8959             if ( d.getPolygons().size() != 2 ) {
8960                 return false;
8961             }
8962             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8963                 return false;
8964             }
8965             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8966                 return false;
8967             }
8968             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8969                 return false;
8970             }
8971             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8972                 return false;
8973             }
8974             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8975                 return false;
8976             }
8977             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8978                 return false;
8979             }
8980             Polygon p = d.getPolygons().get( 0 );
8981             if ( p.getPoints().size() != 3 ) {
8982                 return false;
8983             }
8984             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8985                 return false;
8986             }
8987             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8988                 return false;
8989             }
8990             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8991                 return false;
8992             }
8993             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8994                 return false;
8995             }
8996             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8997                 return false;
8998             }
8999             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9000                 return false;
9001             }
9002             p = d.getPolygons().get( 1 );
9003             if ( p.getPoints().size() != 3 ) {
9004                 return false;
9005             }
9006             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9007                 return false;
9008             }
9009             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9010                 return false;
9011             }
9012             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9013                 return false;
9014             }
9015             // Roundtrip:
9016             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9017             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9018             if ( rt.length != 1 ) {
9019                 return false;
9020             }
9021             final Phylogeny t1_rt = rt[ 0 ];
9022             n = t1_rt.getNode( "root node" );
9023             if ( !n.getNodeData().isHasDistribution() ) {
9024                 return false;
9025             }
9026             if ( n.getNodeData().getDistributions().size() != 1 ) {
9027                 return false;
9028             }
9029             d = n.getNodeData().getDistribution();
9030             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9031                 return false;
9032             }
9033             if ( d.getPoints().size() != 1 ) {
9034                 return false;
9035             }
9036             if ( d.getPolygons() != null ) {
9037                 return false;
9038             }
9039             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9040                 return false;
9041             }
9042             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9043                 return false;
9044             }
9045             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9046                 return false;
9047             }
9048             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9049                 return false;
9050             }
9051             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9052                 return false;
9053             }
9054             n = t1_rt.getNode( "node a" );
9055             if ( !n.getNodeData().isHasDistribution() ) {
9056                 return false;
9057             }
9058             if ( n.getNodeData().getDistributions().size() != 2 ) {
9059                 return false;
9060             }
9061             d = n.getNodeData().getDistribution( 1 );
9062             if ( !d.getDesc().equals( "San Diego" ) ) {
9063                 return false;
9064             }
9065             if ( d.getPoints().size() != 1 ) {
9066                 return false;
9067             }
9068             if ( d.getPolygons() != null ) {
9069                 return false;
9070             }
9071             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9072                 return false;
9073             }
9074             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9075                 return false;
9076             }
9077             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9078                 return false;
9079             }
9080             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9081                 return false;
9082             }
9083             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9084                 return false;
9085             }
9086             n = t1_rt.getNode( "node bb" );
9087             if ( !n.getNodeData().isHasDistribution() ) {
9088                 return false;
9089             }
9090             if ( n.getNodeData().getDistributions().size() != 1 ) {
9091                 return false;
9092             }
9093             d = n.getNodeData().getDistribution( 0 );
9094             if ( d.getPoints().size() != 3 ) {
9095                 return false;
9096             }
9097             if ( d.getPolygons().size() != 2 ) {
9098                 return false;
9099             }
9100             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9101                 return false;
9102             }
9103             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9104                 return false;
9105             }
9106             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9107                 return false;
9108             }
9109             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9110                 return false;
9111             }
9112             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9113                 return false;
9114             }
9115             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9116                 return false;
9117             }
9118             p = d.getPolygons().get( 0 );
9119             if ( p.getPoints().size() != 3 ) {
9120                 return false;
9121             }
9122             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9123                 return false;
9124             }
9125             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9126                 return false;
9127             }
9128             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9129                 return false;
9130             }
9131             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9132                 return false;
9133             }
9134             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9135                 return false;
9136             }
9137             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9138                 return false;
9139             }
9140             p = d.getPolygons().get( 1 );
9141             if ( p.getPoints().size() != 3 ) {
9142                 return false;
9143             }
9144             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9145                 return false;
9146             }
9147             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9148                 return false;
9149             }
9150             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9151                 return false;
9152             }
9153         }
9154         catch ( final Exception e ) {
9155             e.printStackTrace( System.out );
9156             return false;
9157         }
9158         return true;
9159     }
9160
9161     private static boolean testPostOrderIterator() {
9162         try {
9163             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9164             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9165             PhylogenyNodeIterator it0;
9166             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9167                 it0.next();
9168             }
9169             for( it0.reset(); it0.hasNext(); ) {
9170                 it0.next();
9171             }
9172             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9173             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9174             if ( !it.next().getName().equals( "A" ) ) {
9175                 return false;
9176             }
9177             if ( !it.next().getName().equals( "B" ) ) {
9178                 return false;
9179             }
9180             if ( !it.next().getName().equals( "ab" ) ) {
9181                 return false;
9182             }
9183             if ( !it.next().getName().equals( "C" ) ) {
9184                 return false;
9185             }
9186             if ( !it.next().getName().equals( "D" ) ) {
9187                 return false;
9188             }
9189             if ( !it.next().getName().equals( "cd" ) ) {
9190                 return false;
9191             }
9192             if ( !it.next().getName().equals( "abcd" ) ) {
9193                 return false;
9194             }
9195             if ( !it.next().getName().equals( "E" ) ) {
9196                 return false;
9197             }
9198             if ( !it.next().getName().equals( "F" ) ) {
9199                 return false;
9200             }
9201             if ( !it.next().getName().equals( "ef" ) ) {
9202                 return false;
9203             }
9204             if ( !it.next().getName().equals( "G" ) ) {
9205                 return false;
9206             }
9207             if ( !it.next().getName().equals( "H" ) ) {
9208                 return false;
9209             }
9210             if ( !it.next().getName().equals( "gh" ) ) {
9211                 return false;
9212             }
9213             if ( !it.next().getName().equals( "efgh" ) ) {
9214                 return false;
9215             }
9216             if ( !it.next().getName().equals( "r" ) ) {
9217                 return false;
9218             }
9219             if ( it.hasNext() ) {
9220                 return false;
9221             }
9222         }
9223         catch ( final Exception e ) {
9224             e.printStackTrace( System.out );
9225             return false;
9226         }
9227         return true;
9228     }
9229
9230     private static boolean testPreOrderIterator() {
9231         try {
9232             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9233             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9234             PhylogenyNodeIterator it0;
9235             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
9236                 it0.next();
9237             }
9238             for( it0.reset(); it0.hasNext(); ) {
9239                 it0.next();
9240             }
9241             PhylogenyNodeIterator it = t0.iteratorPreorder();
9242             if ( !it.next().getName().equals( "r" ) ) {
9243                 return false;
9244             }
9245             if ( !it.next().getName().equals( "ab" ) ) {
9246                 return false;
9247             }
9248             if ( !it.next().getName().equals( "A" ) ) {
9249                 return false;
9250             }
9251             if ( !it.next().getName().equals( "B" ) ) {
9252                 return false;
9253             }
9254             if ( !it.next().getName().equals( "cd" ) ) {
9255                 return false;
9256             }
9257             if ( !it.next().getName().equals( "C" ) ) {
9258                 return false;
9259             }
9260             if ( !it.next().getName().equals( "D" ) ) {
9261                 return false;
9262             }
9263             if ( it.hasNext() ) {
9264                 return false;
9265             }
9266             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9267             it = t1.iteratorPreorder();
9268             if ( !it.next().getName().equals( "r" ) ) {
9269                 return false;
9270             }
9271             if ( !it.next().getName().equals( "abcd" ) ) {
9272                 return false;
9273             }
9274             if ( !it.next().getName().equals( "ab" ) ) {
9275                 return false;
9276             }
9277             if ( !it.next().getName().equals( "A" ) ) {
9278                 return false;
9279             }
9280             if ( !it.next().getName().equals( "B" ) ) {
9281                 return false;
9282             }
9283             if ( !it.next().getName().equals( "cd" ) ) {
9284                 return false;
9285             }
9286             if ( !it.next().getName().equals( "C" ) ) {
9287                 return false;
9288             }
9289             if ( !it.next().getName().equals( "D" ) ) {
9290                 return false;
9291             }
9292             if ( !it.next().getName().equals( "efgh" ) ) {
9293                 return false;
9294             }
9295             if ( !it.next().getName().equals( "ef" ) ) {
9296                 return false;
9297             }
9298             if ( !it.next().getName().equals( "E" ) ) {
9299                 return false;
9300             }
9301             if ( !it.next().getName().equals( "F" ) ) {
9302                 return false;
9303             }
9304             if ( !it.next().getName().equals( "gh" ) ) {
9305                 return false;
9306             }
9307             if ( !it.next().getName().equals( "G" ) ) {
9308                 return false;
9309             }
9310             if ( !it.next().getName().equals( "H" ) ) {
9311                 return false;
9312             }
9313             if ( it.hasNext() ) {
9314                 return false;
9315             }
9316         }
9317         catch ( final Exception e ) {
9318             e.printStackTrace( System.out );
9319             return false;
9320         }
9321         return true;
9322     }
9323
9324     private static boolean testPropertiesMap() {
9325         try {
9326             final PropertiesMap pm = new PropertiesMap();
9327             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9328             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9329             final Property p2 = new Property( "something:else",
9330                                               "?",
9331                                               "improbable:research",
9332                                               "xsd:decimal",
9333                                               AppliesTo.NODE );
9334             pm.addProperty( p0 );
9335             pm.addProperty( p1 );
9336             pm.addProperty( p2 );
9337             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
9338                 return false;
9339             }
9340             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
9341                 return false;
9342             }
9343             if ( pm.getProperties().size() != 3 ) {
9344                 return false;
9345             }
9346             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
9347                 return false;
9348             }
9349             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9350                 return false;
9351             }
9352             if ( pm.getProperties().size() != 3 ) {
9353                 return false;
9354             }
9355             pm.removeProperty( "dimensions:diameter" );
9356             if ( pm.getProperties().size() != 2 ) {
9357                 return false;
9358             }
9359             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
9360                 return false;
9361             }
9362             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9363                 return false;
9364             }
9365         }
9366         catch ( final Exception e ) {
9367             e.printStackTrace( System.out );
9368             return false;
9369         }
9370         return true;
9371     }
9372
9373     private static boolean testProteinId() {
9374         try {
9375             final ProteinId id1 = new ProteinId( "a" );
9376             final ProteinId id2 = new ProteinId( "a" );
9377             final ProteinId id3 = new ProteinId( "A" );
9378             final ProteinId id4 = new ProteinId( "b" );
9379             if ( !id1.equals( id1 ) ) {
9380                 return false;
9381             }
9382             if ( id1.getId().equals( "x" ) ) {
9383                 return false;
9384             }
9385             if ( id1.getId().equals( null ) ) {
9386                 return false;
9387             }
9388             if ( !id1.equals( id2 ) ) {
9389                 return false;
9390             }
9391             if ( id1.equals( id3 ) ) {
9392                 return false;
9393             }
9394             if ( id1.hashCode() != id1.hashCode() ) {
9395                 return false;
9396             }
9397             if ( id1.hashCode() != id2.hashCode() ) {
9398                 return false;
9399             }
9400             if ( id1.hashCode() == id3.hashCode() ) {
9401                 return false;
9402             }
9403             if ( id1.compareTo( id1 ) != 0 ) {
9404                 return false;
9405             }
9406             if ( id1.compareTo( id2 ) != 0 ) {
9407                 return false;
9408             }
9409             if ( id1.compareTo( id3 ) != 0 ) {
9410                 return false;
9411             }
9412             if ( id1.compareTo( id4 ) >= 0 ) {
9413                 return false;
9414             }
9415             if ( id4.compareTo( id1 ) <= 0 ) {
9416                 return false;
9417             }
9418             if ( !id4.getId().equals( "b" ) ) {
9419                 return false;
9420             }
9421             final ProteinId id5 = new ProteinId( " C " );
9422             if ( !id5.getId().equals( "C" ) ) {
9423                 return false;
9424             }
9425             if ( id5.equals( id1 ) ) {
9426                 return false;
9427             }
9428         }
9429         catch ( final Exception e ) {
9430             e.printStackTrace( System.out );
9431             return false;
9432         }
9433         return true;
9434     }
9435
9436     private static boolean testReIdMethods() {
9437         try {
9438             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9439             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
9440             final long count = PhylogenyNode.getNodeCount();
9441             p.levelOrderReID();
9442             if ( p.getNode( "r" ).getId() != count ) {
9443                 return false;
9444             }
9445             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
9446                 return false;
9447             }
9448             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
9449                 return false;
9450             }
9451             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
9452                 return false;
9453             }
9454             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
9455                 return false;
9456             }
9457             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
9458                 return false;
9459             }
9460             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
9461                 return false;
9462             }
9463             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
9464                 return false;
9465             }
9466             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
9467                 return false;
9468             }
9469             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
9470                 return false;
9471             }
9472             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
9473                 return false;
9474             }
9475             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
9476                 return false;
9477             }
9478             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
9479                 return false;
9480             }
9481             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
9482                 return false;
9483             }
9484             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
9485                 return false;
9486             }
9487         }
9488         catch ( final Exception e ) {
9489             e.printStackTrace( System.out );
9490             return false;
9491         }
9492         return true;
9493     }
9494
9495     private static boolean testRerooting() {
9496         try {
9497             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9498             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",
9499                                                  new NHXParser() )[ 0 ];
9500             if ( !t1.isRooted() ) {
9501                 return false;
9502             }
9503             t1.reRoot( t1.getNode( "D" ) );
9504             t1.reRoot( t1.getNode( "CD" ) );
9505             t1.reRoot( t1.getNode( "A" ) );
9506             t1.reRoot( t1.getNode( "B" ) );
9507             t1.reRoot( t1.getNode( "AB" ) );
9508             t1.reRoot( t1.getNode( "D" ) );
9509             t1.reRoot( t1.getNode( "C" ) );
9510             t1.reRoot( t1.getNode( "CD" ) );
9511             t1.reRoot( t1.getNode( "A" ) );
9512             t1.reRoot( t1.getNode( "B" ) );
9513             t1.reRoot( t1.getNode( "AB" ) );
9514             t1.reRoot( t1.getNode( "D" ) );
9515             t1.reRoot( t1.getNode( "D" ) );
9516             t1.reRoot( t1.getNode( "C" ) );
9517             t1.reRoot( t1.getNode( "A" ) );
9518             t1.reRoot( t1.getNode( "B" ) );
9519             t1.reRoot( t1.getNode( "AB" ) );
9520             t1.reRoot( t1.getNode( "C" ) );
9521             t1.reRoot( t1.getNode( "D" ) );
9522             t1.reRoot( t1.getNode( "CD" ) );
9523             t1.reRoot( t1.getNode( "D" ) );
9524             t1.reRoot( t1.getNode( "A" ) );
9525             t1.reRoot( t1.getNode( "B" ) );
9526             t1.reRoot( t1.getNode( "AB" ) );
9527             t1.reRoot( t1.getNode( "C" ) );
9528             t1.reRoot( t1.getNode( "D" ) );
9529             t1.reRoot( t1.getNode( "CD" ) );
9530             t1.reRoot( t1.getNode( "D" ) );
9531             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
9532                 return false;
9533             }
9534             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
9535                 return false;
9536             }
9537             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
9538                 return false;
9539             }
9540             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
9541                 return false;
9542             }
9543             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
9544                 return false;
9545             }
9546             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
9547                 return false;
9548             }
9549             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",
9550                                                  new NHXParser() )[ 0 ];
9551             t2.reRoot( t2.getNode( "A" ) );
9552             t2.reRoot( t2.getNode( "D" ) );
9553             t2.reRoot( t2.getNode( "ABC" ) );
9554             t2.reRoot( t2.getNode( "A" ) );
9555             t2.reRoot( t2.getNode( "B" ) );
9556             t2.reRoot( t2.getNode( "D" ) );
9557             t2.reRoot( t2.getNode( "C" ) );
9558             t2.reRoot( t2.getNode( "ABC" ) );
9559             t2.reRoot( t2.getNode( "A" ) );
9560             t2.reRoot( t2.getNode( "B" ) );
9561             t2.reRoot( t2.getNode( "AB" ) );
9562             t2.reRoot( t2.getNode( "AB" ) );
9563             t2.reRoot( t2.getNode( "D" ) );
9564             t2.reRoot( t2.getNode( "C" ) );
9565             t2.reRoot( t2.getNode( "B" ) );
9566             t2.reRoot( t2.getNode( "AB" ) );
9567             t2.reRoot( t2.getNode( "D" ) );
9568             t2.reRoot( t2.getNode( "D" ) );
9569             t2.reRoot( t2.getNode( "ABC" ) );
9570             t2.reRoot( t2.getNode( "A" ) );
9571             t2.reRoot( t2.getNode( "B" ) );
9572             t2.reRoot( t2.getNode( "AB" ) );
9573             t2.reRoot( t2.getNode( "D" ) );
9574             t2.reRoot( t2.getNode( "C" ) );
9575             t2.reRoot( t2.getNode( "ABC" ) );
9576             t2.reRoot( t2.getNode( "A" ) );
9577             t2.reRoot( t2.getNode( "B" ) );
9578             t2.reRoot( t2.getNode( "AB" ) );
9579             t2.reRoot( t2.getNode( "D" ) );
9580             t2.reRoot( t2.getNode( "D" ) );
9581             t2.reRoot( t2.getNode( "C" ) );
9582             t2.reRoot( t2.getNode( "A" ) );
9583             t2.reRoot( t2.getNode( "B" ) );
9584             t2.reRoot( t2.getNode( "AB" ) );
9585             t2.reRoot( t2.getNode( "C" ) );
9586             t2.reRoot( t2.getNode( "D" ) );
9587             t2.reRoot( t2.getNode( "ABC" ) );
9588             t2.reRoot( t2.getNode( "D" ) );
9589             t2.reRoot( t2.getNode( "A" ) );
9590             t2.reRoot( t2.getNode( "B" ) );
9591             t2.reRoot( t2.getNode( "AB" ) );
9592             t2.reRoot( t2.getNode( "C" ) );
9593             t2.reRoot( t2.getNode( "D" ) );
9594             t2.reRoot( t2.getNode( "ABC" ) );
9595             t2.reRoot( t2.getNode( "D" ) );
9596             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9597                 return false;
9598             }
9599             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9600                 return false;
9601             }
9602             t2.reRoot( t2.getNode( "ABC" ) );
9603             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9604                 return false;
9605             }
9606             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9607                 return false;
9608             }
9609             t2.reRoot( t2.getNode( "AB" ) );
9610             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9611                 return false;
9612             }
9613             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9614                 return false;
9615             }
9616             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9617                 return false;
9618             }
9619             t2.reRoot( t2.getNode( "AB" ) );
9620             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9621                 return false;
9622             }
9623             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9624                 return false;
9625             }
9626             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9627                 return false;
9628             }
9629             t2.reRoot( t2.getNode( "D" ) );
9630             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9631                 return false;
9632             }
9633             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9634                 return false;
9635             }
9636             t2.reRoot( t2.getNode( "ABC" ) );
9637             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9638                 return false;
9639             }
9640             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9641                 return false;
9642             }
9643             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
9644                                                  new NHXParser() )[ 0 ];
9645             t3.reRoot( t3.getNode( "B" ) );
9646             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9647                 return false;
9648             }
9649             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9650                 return false;
9651             }
9652             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9653                 return false;
9654             }
9655             t3.reRoot( t3.getNode( "B" ) );
9656             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9657                 return false;
9658             }
9659             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9660                 return false;
9661             }
9662             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9663                 return false;
9664             }
9665             t3.reRoot( t3.getRoot() );
9666             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9667                 return false;
9668             }
9669             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9670                 return false;
9671             }
9672             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9673                 return false;
9674             }
9675         }
9676         catch ( final Exception e ) {
9677             e.printStackTrace( System.out );
9678             return false;
9679         }
9680         return true;
9681     }
9682
9683     private static boolean testSDIse() {
9684         try {
9685             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9686             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
9687             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
9688             gene1.setRooted( true );
9689             species1.setRooted( true );
9690             final SDI sdi = new SDI( gene1, species1 );
9691             if ( !gene1.getRoot().isDuplication() ) {
9692                 return false;
9693             }
9694             final Phylogeny species2 = factory
9695                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9696                              new NHXParser() )[ 0 ];
9697             final Phylogeny gene2 = factory
9698                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9699                              new NHXParser() )[ 0 ];
9700             species2.setRooted( true );
9701             gene2.setRooted( true );
9702             final SDI sdi2 = new SDI( gene2, species2 );
9703             if ( sdi2.getDuplicationsSum() != 0 ) {
9704                 return false;
9705             }
9706             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
9707                 return false;
9708             }
9709             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
9710                 return false;
9711             }
9712             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
9713                 return false;
9714             }
9715             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
9716                 return false;
9717             }
9718             if ( !gene2.getNode( "r" ).isSpeciation() ) {
9719                 return false;
9720             }
9721             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
9722                 return false;
9723             }
9724             final Phylogeny species3 = factory
9725                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9726                              new NHXParser() )[ 0 ];
9727             final Phylogeny gene3 = factory
9728                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9729                              new NHXParser() )[ 0 ];
9730             species3.setRooted( true );
9731             gene3.setRooted( true );
9732             final SDI sdi3 = new SDI( gene3, species3 );
9733             if ( sdi3.getDuplicationsSum() != 1 ) {
9734                 return false;
9735             }
9736             if ( !gene3.getNode( "aa" ).isDuplication() ) {
9737                 return false;
9738             }
9739             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
9740                 return false;
9741             }
9742             final Phylogeny species4 = factory
9743                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9744                              new NHXParser() )[ 0 ];
9745             final Phylogeny gene4 = factory
9746                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9747                              new NHXParser() )[ 0 ];
9748             species4.setRooted( true );
9749             gene4.setRooted( true );
9750             final SDI sdi4 = new SDI( gene4, species4 );
9751             if ( sdi4.getDuplicationsSum() != 1 ) {
9752                 return false;
9753             }
9754             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
9755                 return false;
9756             }
9757             if ( !gene4.getNode( "abc" ).isDuplication() ) {
9758                 return false;
9759             }
9760             if ( gene4.getNode( "abcd" ).isDuplication() ) {
9761                 return false;
9762             }
9763             if ( species4.getNumberOfExternalNodes() != 6 ) {
9764                 return false;
9765             }
9766             if ( gene4.getNumberOfExternalNodes() != 6 ) {
9767                 return false;
9768             }
9769             final Phylogeny species5 = factory
9770                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9771                              new NHXParser() )[ 0 ];
9772             final Phylogeny gene5 = factory
9773                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9774                              new NHXParser() )[ 0 ];
9775             species5.setRooted( true );
9776             gene5.setRooted( true );
9777             final SDI sdi5 = new SDI( gene5, species5 );
9778             if ( sdi5.getDuplicationsSum() != 2 ) {
9779                 return false;
9780             }
9781             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
9782                 return false;
9783             }
9784             if ( !gene5.getNode( "adc" ).isDuplication() ) {
9785                 return false;
9786             }
9787             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
9788                 return false;
9789             }
9790             if ( species5.getNumberOfExternalNodes() != 6 ) {
9791                 return false;
9792             }
9793             if ( gene5.getNumberOfExternalNodes() != 6 ) {
9794                 return false;
9795             }
9796             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
9797             // Conjecture for Comparing Molecular Phylogenies"
9798             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
9799             final Phylogeny species6 = factory
9800                     .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,"
9801                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9802                              new NHXParser() )[ 0 ];
9803             final Phylogeny gene6 = factory
9804                     .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,"
9805                                      + "((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,"
9806                                      + "(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;",
9807                              new NHXParser() )[ 0 ];
9808             species6.setRooted( true );
9809             gene6.setRooted( true );
9810             final SDI sdi6 = new SDI( gene6, species6 );
9811             if ( sdi6.getDuplicationsSum() != 3 ) {
9812                 return false;
9813             }
9814             if ( !gene6.getNode( "r" ).isDuplication() ) {
9815                 return false;
9816             }
9817             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
9818                 return false;
9819             }
9820             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
9821                 return false;
9822             }
9823             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
9824                 return false;
9825             }
9826             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
9827                 return false;
9828             }
9829             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
9830                 return false;
9831             }
9832             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
9833                 return false;
9834             }
9835             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
9836                 return false;
9837             }
9838             sdi6.computeMappingCostL();
9839             if ( sdi6.computeMappingCostL() != 17 ) {
9840                 return false;
9841             }
9842             if ( species6.getNumberOfExternalNodes() != 9 ) {
9843                 return false;
9844             }
9845             if ( gene6.getNumberOfExternalNodes() != 9 ) {
9846                 return false;
9847             }
9848             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
9849                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
9850                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
9851                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
9852                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
9853             species7.setRooted( true );
9854             final Phylogeny gene7_1 = Test
9855                     .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])" );
9856             gene7_1.setRooted( true );
9857             final SDI sdi7 = new SDI( gene7_1, species7 );
9858             if ( sdi7.getDuplicationsSum() != 0 ) {
9859                 return false;
9860             }
9861             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
9862                 return false;
9863             }
9864             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
9865                 return false;
9866             }
9867             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
9868                 return false;
9869             }
9870             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
9871                 return false;
9872             }
9873             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
9874                 return false;
9875             }
9876             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
9877                 return false;
9878             }
9879             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
9880                 return false;
9881             }
9882             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
9883                 return false;
9884             }
9885             final Phylogeny gene7_2 = Test
9886                     .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])" );
9887             gene7_2.setRooted( true );
9888             final SDI sdi7_2 = new SDI( gene7_2, species7 );
9889             if ( sdi7_2.getDuplicationsSum() != 1 ) {
9890                 return false;
9891             }
9892             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
9893                 return false;
9894             }
9895             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
9896                 return false;
9897             }
9898             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
9899                 return false;
9900             }
9901             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
9902                 return false;
9903             }
9904             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
9905                 return false;
9906             }
9907             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
9908                 return false;
9909             }
9910             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
9911                 return false;
9912             }
9913             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
9914                 return false;
9915             }
9916             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
9917                 return false;
9918             }
9919         }
9920         catch ( final Exception e ) {
9921             return false;
9922         }
9923         return true;
9924     }
9925
9926     private static boolean testSDIunrooted() {
9927         try {
9928             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9929             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
9930             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
9931             final Iterator<PhylogenyBranch> iter = l.iterator();
9932             PhylogenyBranch br = iter.next();
9933             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
9934                 return false;
9935             }
9936             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
9937                 return false;
9938             }
9939             br = iter.next();
9940             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9941                 return false;
9942             }
9943             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9944                 return false;
9945             }
9946             br = iter.next();
9947             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
9948                 return false;
9949             }
9950             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
9951                 return false;
9952             }
9953             br = iter.next();
9954             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9955                 return false;
9956             }
9957             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9958                 return false;
9959             }
9960             br = iter.next();
9961             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9962                 return false;
9963             }
9964             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9965                 return false;
9966             }
9967             br = iter.next();
9968             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9969                 return false;
9970             }
9971             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9972                 return false;
9973             }
9974             br = iter.next();
9975             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9976                 return false;
9977             }
9978             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9979                 return false;
9980             }
9981             br = iter.next();
9982             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9983                 return false;
9984             }
9985             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9986                 return false;
9987             }
9988             br = iter.next();
9989             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9990                 return false;
9991             }
9992             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9993                 return false;
9994             }
9995             br = iter.next();
9996             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9997                 return false;
9998             }
9999             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10000                 return false;
10001             }
10002             br = iter.next();
10003             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10004                 return false;
10005             }
10006             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10007                 return false;
10008             }
10009             br = iter.next();
10010             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10011                 return false;
10012             }
10013             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10014                 return false;
10015             }
10016             br = iter.next();
10017             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10018                 return false;
10019             }
10020             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10021                 return false;
10022             }
10023             br = iter.next();
10024             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10025                 return false;
10026             }
10027             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10028                 return false;
10029             }
10030             br = iter.next();
10031             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10032                 return false;
10033             }
10034             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10035                 return false;
10036             }
10037             if ( iter.hasNext() ) {
10038                 return false;
10039             }
10040             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10041             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10042             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10043             br = iter1.next();
10044             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10045                 return false;
10046             }
10047             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10048                 return false;
10049             }
10050             br = iter1.next();
10051             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10052                 return false;
10053             }
10054             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10055                 return false;
10056             }
10057             br = iter1.next();
10058             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10059                 return false;
10060             }
10061             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10062                 return false;
10063             }
10064             if ( iter1.hasNext() ) {
10065                 return false;
10066             }
10067             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10068             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10069             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10070             br = iter2.next();
10071             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10072                 return false;
10073             }
10074             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10075                 return false;
10076             }
10077             br = iter2.next();
10078             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10079                 return false;
10080             }
10081             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10082                 return false;
10083             }
10084             br = iter2.next();
10085             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10086                 return false;
10087             }
10088             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10089                 return false;
10090             }
10091             if ( iter2.hasNext() ) {
10092                 return false;
10093             }
10094             final Phylogeny species0 = factory
10095                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10096                              new NHXParser() )[ 0 ];
10097             final Phylogeny gene1 = factory
10098                     .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])",
10099                              new NHXParser() )[ 0 ];
10100             species0.setRooted( true );
10101             gene1.setRooted( true );
10102             final SDIR sdi_unrooted = new SDIR();
10103             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10104             if ( sdi_unrooted.getCount() != 1 ) {
10105                 return false;
10106             }
10107             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10108                 return false;
10109             }
10110             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10111                 return false;
10112             }
10113             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10114                 return false;
10115             }
10116             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10117                 return false;
10118             }
10119             final Phylogeny gene2 = factory
10120                     .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])",
10121                              new NHXParser() )[ 0 ];
10122             gene2.setRooted( true );
10123             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10124             if ( sdi_unrooted.getCount() != 1 ) {
10125                 return false;
10126             }
10127             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10128                 return false;
10129             }
10130             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10131                 return false;
10132             }
10133             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10134                 return false;
10135             }
10136             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10137                 return false;
10138             }
10139             final Phylogeny species6 = factory
10140                     .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,"
10141                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10142                              new NHXParser() )[ 0 ];
10143             final Phylogeny gene6 = factory
10144                     .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],"
10145                                      + "(((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],"
10146                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10147                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10148                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10149                              new NHXParser() )[ 0 ];
10150             species6.setRooted( true );
10151             gene6.setRooted( true );
10152             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10153             if ( sdi_unrooted.getCount() != 1 ) {
10154                 return false;
10155             }
10156             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10157                 return false;
10158             }
10159             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10160                 return false;
10161             }
10162             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10163                 return false;
10164             }
10165             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10166                 return false;
10167             }
10168             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10169                 return false;
10170             }
10171             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10172                 return false;
10173             }
10174             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10175                 return false;
10176             }
10177             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
10178                 return false;
10179             }
10180             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10181                 return false;
10182             }
10183             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
10184                 return false;
10185             }
10186             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
10187                 return false;
10188             }
10189             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10190                 return false;
10191             }
10192             p6 = null;
10193             final Phylogeny species7 = factory
10194                     .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,"
10195                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10196                              new NHXParser() )[ 0 ];
10197             final Phylogeny gene7 = factory
10198                     .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],"
10199                                      + "(((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],"
10200                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10201                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10202                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10203                              new NHXParser() )[ 0 ];
10204             species7.setRooted( true );
10205             gene7.setRooted( true );
10206             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
10207             if ( sdi_unrooted.getCount() != 1 ) {
10208                 return false;
10209             }
10210             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10211                 return false;
10212             }
10213             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10214                 return false;
10215             }
10216             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10217                 return false;
10218             }
10219             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
10220                 return false;
10221             }
10222             if ( !p7[ 0 ].getRoot().isDuplication() ) {
10223                 return false;
10224             }
10225             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10226                 return false;
10227             }
10228             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10229                 return false;
10230             }
10231             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
10232                 return false;
10233             }
10234             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10235                 return false;
10236             }
10237             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
10238                 return false;
10239             }
10240             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
10241                 return false;
10242             }
10243             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10244                 return false;
10245             }
10246             p7 = null;
10247             final Phylogeny species8 = factory
10248                     .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,"
10249                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10250                              new NHXParser() )[ 0 ];
10251             final Phylogeny gene8 = factory
10252                     .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],"
10253                                      + "(((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],"
10254                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10255                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10256                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10257                              new NHXParser() )[ 0 ];
10258             species8.setRooted( true );
10259             gene8.setRooted( true );
10260             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
10261             if ( sdi_unrooted.getCount() != 1 ) {
10262                 return false;
10263             }
10264             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10265                 return false;
10266             }
10267             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10268                 return false;
10269             }
10270             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10271                 return false;
10272             }
10273             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10274                 return false;
10275             }
10276             if ( !p8[ 0 ].getRoot().isDuplication() ) {
10277                 return false;
10278             }
10279             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10280                 return false;
10281             }
10282             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10283                 return false;
10284             }
10285             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
10286                 return false;
10287             }
10288             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10289                 return false;
10290             }
10291             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
10292                 return false;
10293             }
10294             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
10295                 return false;
10296             }
10297             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10298                 return false;
10299             }
10300             p8 = null;
10301         }
10302         catch ( final Exception e ) {
10303             e.printStackTrace( System.out );
10304             return false;
10305         }
10306         return true;
10307     }
10308
10309     private static boolean testSequenceDbWsTools1() {
10310         try {
10311             final PhylogenyNode n = new PhylogenyNode();
10312             n.setName( "NP_001025424" );
10313             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
10314             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10315                     || !acc.getValue().equals( "NP_001025424" ) ) {
10316                 return false;
10317             }
10318             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
10319             acc = SequenceDbWsTools.obtainSeqAccession( n );
10320             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10321                     || !acc.getValue().equals( "NP_001025424" ) ) {
10322                 return false;
10323             }
10324             n.setName( "NP_001025424.1" );
10325             acc = SequenceDbWsTools.obtainSeqAccession( n );
10326             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10327                     || !acc.getValue().equals( "NP_001025424" ) ) {
10328                 return false;
10329             }
10330             n.setName( "NM_001030253" );
10331             acc = SequenceDbWsTools.obtainSeqAccession( n );
10332             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10333                     || !acc.getValue().equals( "NM_001030253" ) ) {
10334                 return false;
10335             }
10336             n.setName( "BCL2_HUMAN" );
10337             acc = SequenceDbWsTools.obtainSeqAccession( n );
10338             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10339                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
10340                 System.out.println( acc.toString() );
10341                 return false;
10342             }
10343             n.setName( "P10415" );
10344             acc = SequenceDbWsTools.obtainSeqAccession( n );
10345             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10346                     || !acc.getValue().equals( "P10415" ) ) {
10347                 System.out.println( acc.toString() );
10348                 return false;
10349             }
10350             n.setName( " P10415 " );
10351             acc = SequenceDbWsTools.obtainSeqAccession( n );
10352             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10353                     || !acc.getValue().equals( "P10415" ) ) {
10354                 System.out.println( acc.toString() );
10355                 return false;
10356             }
10357             n.setName( "_P10415|" );
10358             acc = SequenceDbWsTools.obtainSeqAccession( n );
10359             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10360                     || !acc.getValue().equals( "P10415" ) ) {
10361                 System.out.println( acc.toString() );
10362                 return false;
10363             }
10364             n.setName( "AY695820" );
10365             acc = SequenceDbWsTools.obtainSeqAccession( n );
10366             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10367                     || !acc.getValue().equals( "AY695820" ) ) {
10368                 System.out.println( acc.toString() );
10369                 return false;
10370             }
10371             n.setName( "_AY695820_" );
10372             acc = SequenceDbWsTools.obtainSeqAccession( n );
10373             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10374                     || !acc.getValue().equals( "AY695820" ) ) {
10375                 System.out.println( acc.toString() );
10376                 return false;
10377             }
10378             n.setName( "AAA59452" );
10379             acc = SequenceDbWsTools.obtainSeqAccession( n );
10380             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10381                     || !acc.getValue().equals( "AAA59452" ) ) {
10382                 System.out.println( acc.toString() );
10383                 return false;
10384             }
10385             n.setName( "_AAA59452_" );
10386             acc = SequenceDbWsTools.obtainSeqAccession( n );
10387             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10388                     || !acc.getValue().equals( "AAA59452" ) ) {
10389                 System.out.println( acc.toString() );
10390                 return false;
10391             }
10392             n.setName( "AAA59452.1" );
10393             acc = SequenceDbWsTools.obtainSeqAccession( n );
10394             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10395                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10396                 System.out.println( acc.toString() );
10397                 return false;
10398             }
10399             n.setName( "_AAA59452.1_" );
10400             acc = SequenceDbWsTools.obtainSeqAccession( n );
10401             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10402                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10403                 System.out.println( acc.toString() );
10404                 return false;
10405             }
10406             n.setName( "GI:94894583" );
10407             acc = SequenceDbWsTools.obtainSeqAccession( n );
10408             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10409                     || !acc.getValue().equals( "94894583" ) ) {
10410                 System.out.println( acc.toString() );
10411                 return false;
10412             }
10413             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10414             acc = SequenceDbWsTools.obtainSeqAccession( n );
10415             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10416                     || !acc.getValue().equals( "71845847" ) ) {
10417                 System.out.println( acc.toString() );
10418                 return false;
10419             }
10420             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10421             acc = SequenceDbWsTools.obtainSeqAccession( n );
10422             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10423                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
10424                 System.out.println( acc.toString() );
10425                 return false;
10426             }
10427         }
10428         catch ( final Exception e ) {
10429             return false;
10430         }
10431         return true;
10432     }
10433
10434     private static boolean testSequenceDbWsTools2() {
10435         try {
10436             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
10437             SequenceDbWsTools.obtainSeqInformation( n1 );
10438             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
10439                 return false;
10440             }
10441             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10442                 return false;
10443             }
10444             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10445                 return false;
10446             }
10447             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
10448                 return false;
10449             }
10450             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
10451             SequenceDbWsTools.obtainSeqInformation( n2 );
10452             if ( !n2.getNodeData().getSequence().getName()
10453                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
10454                 return false;
10455             }
10456             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10457                 return false;
10458             }
10459             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10460                 return false;
10461             }
10462             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
10463                 return false;
10464             }
10465             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
10466             SequenceDbWsTools.obtainSeqInformation( n3 );
10467             if ( !n3.getNodeData().getSequence().getName()
10468                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
10469                 return false;
10470             }
10471             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
10472                 return false;
10473             }
10474             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10475                 return false;
10476             }
10477             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
10478                 return false;
10479             }
10480         }
10481         catch ( final IOException e ) {
10482             System.out.println();
10483             System.out.println( "the following might be due to absence internet connection:" );
10484             e.printStackTrace( System.out );
10485             return true;
10486         }
10487         catch ( final Exception e ) {
10488             e.printStackTrace();
10489             return false;
10490         }
10491         return true;
10492     }
10493
10494     private static boolean testSequenceIdParsing() {
10495         try {
10496             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
10497             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10498                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10499                 if ( id != null ) {
10500                     System.out.println( "value   =" + id.getValue() );
10501                     System.out.println( "provider=" + id.getSource() );
10502                 }
10503                 return false;
10504             }
10505             //
10506             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
10507             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10508                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10509                 if ( id != null ) {
10510                     System.out.println( "value   =" + id.getValue() );
10511                     System.out.println( "provider=" + id.getSource() );
10512                 }
10513                 return false;
10514             }
10515             //
10516             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
10517             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10518                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10519                 if ( id != null ) {
10520                     System.out.println( "value   =" + id.getValue() );
10521                     System.out.println( "provider=" + id.getSource() );
10522                 }
10523                 return false;
10524             }
10525             // 
10526             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
10527             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10528                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
10529                 if ( id != null ) {
10530                     System.out.println( "value   =" + id.getValue() );
10531                     System.out.println( "provider=" + id.getSource() );
10532                 }
10533                 return false;
10534             }
10535             // 
10536             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
10537             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10538                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
10539                 if ( id != null ) {
10540                     System.out.println( "value   =" + id.getValue() );
10541                     System.out.println( "provider=" + id.getSource() );
10542                 }
10543                 return false;
10544             }
10545             // 
10546             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
10547             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10548                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
10549                 if ( id != null ) {
10550                     System.out.println( "value   =" + id.getValue() );
10551                     System.out.println( "provider=" + id.getSource() );
10552                 }
10553                 return false;
10554             }
10555             // 
10556             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
10557             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10558                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
10559                 if ( id != null ) {
10560                     System.out.println( "value   =" + id.getValue() );
10561                     System.out.println( "provider=" + id.getSource() );
10562                 }
10563                 return false;
10564             }
10565             // 
10566             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
10567             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10568                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
10569                 if ( id != null ) {
10570                     System.out.println( "value   =" + id.getValue() );
10571                     System.out.println( "provider=" + id.getSource() );
10572                 }
10573                 return false;
10574             }
10575             // 
10576             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
10577             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10578                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
10579                 if ( id != null ) {
10580                     System.out.println( "value   =" + id.getValue() );
10581                     System.out.println( "provider=" + id.getSource() );
10582                 }
10583                 return false;
10584             }
10585             // 
10586             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
10587             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10588                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
10589                 if ( id != null ) {
10590                     System.out.println( "value   =" + id.getValue() );
10591                     System.out.println( "provider=" + id.getSource() );
10592                 }
10593                 return false;
10594             }
10595             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
10596             if ( id != null ) {
10597                 System.out.println( "value   =" + id.getValue() );
10598                 System.out.println( "provider=" + id.getSource() );
10599                 return false;
10600             }
10601         }
10602         catch ( final Exception e ) {
10603             e.printStackTrace( System.out );
10604             return false;
10605         }
10606         return true;
10607     }
10608
10609     private static boolean testSequenceWriter() {
10610         try {
10611             final String n = ForesterUtil.LINE_SEPARATOR;
10612             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
10613                 return false;
10614             }
10615             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
10616                 return false;
10617             }
10618             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
10619                 return false;
10620             }
10621             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
10622                 return false;
10623             }
10624             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
10625                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
10626                 return false;
10627             }
10628             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
10629                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
10630                 return false;
10631             }
10632         }
10633         catch ( final Exception e ) {
10634             e.printStackTrace();
10635             return false;
10636         }
10637         return true;
10638     }
10639
10640     private static boolean testSpecies() {
10641         try {
10642             final Species s1 = new BasicSpecies( "a" );
10643             final Species s2 = new BasicSpecies( "a" );
10644             final Species s3 = new BasicSpecies( "A" );
10645             final Species s4 = new BasicSpecies( "b" );
10646             if ( !s1.equals( s1 ) ) {
10647                 return false;
10648             }
10649             if ( s1.getSpeciesId().equals( "x" ) ) {
10650                 return false;
10651             }
10652             if ( s1.getSpeciesId().equals( null ) ) {
10653                 return false;
10654             }
10655             if ( !s1.equals( s2 ) ) {
10656                 return false;
10657             }
10658             if ( s1.equals( s3 ) ) {
10659                 return false;
10660             }
10661             if ( s1.hashCode() != s1.hashCode() ) {
10662                 return false;
10663             }
10664             if ( s1.hashCode() != s2.hashCode() ) {
10665                 return false;
10666             }
10667             if ( s1.hashCode() == s3.hashCode() ) {
10668                 return false;
10669             }
10670             if ( s1.compareTo( s1 ) != 0 ) {
10671                 return false;
10672             }
10673             if ( s1.compareTo( s2 ) != 0 ) {
10674                 return false;
10675             }
10676             if ( s1.compareTo( s3 ) != 0 ) {
10677                 return false;
10678             }
10679             if ( s1.compareTo( s4 ) >= 0 ) {
10680                 return false;
10681             }
10682             if ( s4.compareTo( s1 ) <= 0 ) {
10683                 return false;
10684             }
10685             if ( !s4.getSpeciesId().equals( "b" ) ) {
10686                 return false;
10687             }
10688             final Species s5 = new BasicSpecies( " C " );
10689             if ( !s5.getSpeciesId().equals( "C" ) ) {
10690                 return false;
10691             }
10692             if ( s5.equals( s1 ) ) {
10693                 return false;
10694             }
10695         }
10696         catch ( final Exception e ) {
10697             e.printStackTrace( System.out );
10698             return false;
10699         }
10700         return true;
10701     }
10702
10703     private static boolean testSplit() {
10704         try {
10705             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10706             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10707             //Archaeopteryx.createApplication( p0 );
10708             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10709             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10710             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10711             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10712             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10713             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10714             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10715             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10716             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10717             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10718             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
10719             // System.out.println( s0.toString() );
10720             //
10721             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10724             if ( s0.match( query_nodes ) ) {
10725                 return false;
10726             }
10727             query_nodes = new HashSet<PhylogenyNode>();
10728             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10729             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10730             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10731             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10732             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10733             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10734             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10735             if ( !s0.match( query_nodes ) ) {
10736                 return false;
10737             }
10738             //
10739             query_nodes = new HashSet<PhylogenyNode>();
10740             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10741             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10742             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10743             if ( !s0.match( query_nodes ) ) {
10744                 return false;
10745             }
10746             //
10747             query_nodes = new HashSet<PhylogenyNode>();
10748             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10749             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10750             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10751             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10752             if ( !s0.match( query_nodes ) ) {
10753                 return false;
10754             }
10755             //
10756             query_nodes = new HashSet<PhylogenyNode>();
10757             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10758             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10759             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10760             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10761             if ( !s0.match( query_nodes ) ) {
10762                 return false;
10763             }
10764             //
10765             query_nodes = new HashSet<PhylogenyNode>();
10766             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10767             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10768             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10769             if ( !s0.match( query_nodes ) ) {
10770                 return false;
10771             }
10772             //
10773             query_nodes = new HashSet<PhylogenyNode>();
10774             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10775             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10776             if ( !s0.match( query_nodes ) ) {
10777                 return false;
10778             }
10779             //
10780             query_nodes = new HashSet<PhylogenyNode>();
10781             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10782             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10783             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10784             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10785             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10786             if ( !s0.match( query_nodes ) ) {
10787                 return false;
10788             }
10789             //
10790             query_nodes = new HashSet<PhylogenyNode>();
10791             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10792             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10793             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10794             if ( !s0.match( query_nodes ) ) {
10795                 return false;
10796             }
10797             //
10798             query_nodes = new HashSet<PhylogenyNode>();
10799             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10800             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10801             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10802             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10803             if ( !s0.match( query_nodes ) ) {
10804                 return false;
10805             }
10806             //
10807             query_nodes = new HashSet<PhylogenyNode>();
10808             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10809             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10810             if ( s0.match( query_nodes ) ) {
10811                 return false;
10812             }
10813             //
10814             query_nodes = new HashSet<PhylogenyNode>();
10815             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10816             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10817             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10818             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10819             if ( s0.match( query_nodes ) ) {
10820                 return false;
10821             }
10822             //
10823             query_nodes = new HashSet<PhylogenyNode>();
10824             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10825             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10826             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10827             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10828             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10829             if ( s0.match( query_nodes ) ) {
10830                 return false;
10831             }
10832             //
10833             query_nodes = new HashSet<PhylogenyNode>();
10834             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10835             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10836             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10837             if ( s0.match( query_nodes ) ) {
10838                 return false;
10839             }
10840             //
10841             query_nodes = new HashSet<PhylogenyNode>();
10842             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10843             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10844             if ( s0.match( query_nodes ) ) {
10845                 return false;
10846             }
10847             //
10848             query_nodes = new HashSet<PhylogenyNode>();
10849             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10850             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10851             if ( s0.match( query_nodes ) ) {
10852                 return false;
10853             }
10854             //
10855             query_nodes = new HashSet<PhylogenyNode>();
10856             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10857             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10858             if ( s0.match( query_nodes ) ) {
10859                 return false;
10860             }
10861             //
10862             query_nodes = new HashSet<PhylogenyNode>();
10863             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10864             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10865             if ( s0.match( query_nodes ) ) {
10866                 return false;
10867             }
10868             //
10869             query_nodes = new HashSet<PhylogenyNode>();
10870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10872             if ( s0.match( query_nodes ) ) {
10873                 return false;
10874             }
10875             //
10876             query_nodes = new HashSet<PhylogenyNode>();
10877             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10878             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10879             if ( s0.match( query_nodes ) ) {
10880                 return false;
10881             }
10882             //
10883             query_nodes = new HashSet<PhylogenyNode>();
10884             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10885             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10886             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10887             if ( s0.match( query_nodes ) ) {
10888                 return false;
10889             }
10890             //
10891             query_nodes = new HashSet<PhylogenyNode>();
10892             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10893             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10894             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10895             if ( s0.match( query_nodes ) ) {
10896                 return false;
10897             }
10898             //
10899             query_nodes = new HashSet<PhylogenyNode>();
10900             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10901             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10902             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10903             if ( s0.match( query_nodes ) ) {
10904                 return false;
10905             }
10906             //
10907             query_nodes = new HashSet<PhylogenyNode>();
10908             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10909             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10910             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10911             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10912             if ( s0.match( query_nodes ) ) {
10913                 return false;
10914             }
10915             /////////
10916             //            query_nodes = new HashSet<PhylogenyNode>();
10917             //            query_nodes.add( new PhylogenyNode( "X" ) );
10918             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10919             //            query_nodes.add( new PhylogenyNode( "A" ) );
10920             //            query_nodes.add( new PhylogenyNode( "B" ) );
10921             //            query_nodes.add( new PhylogenyNode( "C" ) );
10922             //            query_nodes.add( new PhylogenyNode( "D" ) );
10923             //            query_nodes.add( new PhylogenyNode( "E" ) );
10924             //            query_nodes.add( new PhylogenyNode( "F" ) );
10925             //            query_nodes.add( new PhylogenyNode( "G" ) );
10926             //            if ( !s0.match( query_nodes ) ) {
10927             //                return false;
10928             //            }
10929             //            query_nodes = new HashSet<PhylogenyNode>();
10930             //            query_nodes.add( new PhylogenyNode( "X" ) );
10931             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10932             //            query_nodes.add( new PhylogenyNode( "A" ) );
10933             //            query_nodes.add( new PhylogenyNode( "B" ) );
10934             //            query_nodes.add( new PhylogenyNode( "C" ) );
10935             //            if ( !s0.match( query_nodes ) ) {
10936             //                return false;
10937             //            }
10938             //            //
10939             //            query_nodes = new HashSet<PhylogenyNode>();
10940             //            query_nodes.add( new PhylogenyNode( "X" ) );
10941             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10942             //            query_nodes.add( new PhylogenyNode( "D" ) );
10943             //            query_nodes.add( new PhylogenyNode( "E" ) );
10944             //            query_nodes.add( new PhylogenyNode( "F" ) );
10945             //            query_nodes.add( new PhylogenyNode( "G" ) );
10946             //            if ( !s0.match( query_nodes ) ) {
10947             //                return false;
10948             //            }
10949             //            //
10950             //            query_nodes = new HashSet<PhylogenyNode>();
10951             //            query_nodes.add( new PhylogenyNode( "X" ) );
10952             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10953             //            query_nodes.add( new PhylogenyNode( "A" ) );
10954             //            query_nodes.add( new PhylogenyNode( "B" ) );
10955             //            query_nodes.add( new PhylogenyNode( "C" ) );
10956             //            query_nodes.add( new PhylogenyNode( "D" ) );
10957             //            if ( !s0.match( query_nodes ) ) {
10958             //                return false;
10959             //            }
10960             //            //
10961             //            query_nodes = new HashSet<PhylogenyNode>();
10962             //            query_nodes.add( new PhylogenyNode( "X" ) );
10963             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10964             //            query_nodes.add( new PhylogenyNode( "E" ) );
10965             //            query_nodes.add( new PhylogenyNode( "F" ) );
10966             //            query_nodes.add( new PhylogenyNode( "G" ) );
10967             //            if ( !s0.match( query_nodes ) ) {
10968             //                return false;
10969             //            }
10970             //            //
10971             //            query_nodes = new HashSet<PhylogenyNode>();
10972             //            query_nodes.add( new PhylogenyNode( "X" ) );
10973             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10974             //            query_nodes.add( new PhylogenyNode( "F" ) );
10975             //            query_nodes.add( new PhylogenyNode( "G" ) );
10976             //            if ( !s0.match( query_nodes ) ) {
10977             //                return false;
10978             //            }
10979             //
10980             query_nodes = new HashSet<PhylogenyNode>();
10981             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10982             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10983             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10984             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10985             if ( s0.match( query_nodes ) ) {
10986                 return false;
10987             }
10988             //
10989             query_nodes = new HashSet<PhylogenyNode>();
10990             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10991             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10992             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10993             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10994             if ( s0.match( query_nodes ) ) {
10995                 return false;
10996             }
10997             ///////////////////////////
10998             //
10999             query_nodes = new HashSet<PhylogenyNode>();
11000             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11001             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11002             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11003             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11004             if ( s0.match( query_nodes ) ) {
11005                 return false;
11006             }
11007             //
11008             query_nodes = new HashSet<PhylogenyNode>();
11009             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11010             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11011             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11012             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11013             if ( s0.match( query_nodes ) ) {
11014                 return false;
11015             }
11016             //
11017             query_nodes = new HashSet<PhylogenyNode>();
11018             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11019             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11020             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11022             if ( s0.match( query_nodes ) ) {
11023                 return false;
11024             }
11025             //
11026             query_nodes = new HashSet<PhylogenyNode>();
11027             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11028             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11029             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11030             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11031             if ( s0.match( query_nodes ) ) {
11032                 return false;
11033             }
11034             //
11035             query_nodes = new HashSet<PhylogenyNode>();
11036             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11037             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11040             if ( s0.match( query_nodes ) ) {
11041                 return false;
11042             }
11043             //
11044             query_nodes = new HashSet<PhylogenyNode>();
11045             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11046             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11048             if ( s0.match( query_nodes ) ) {
11049                 return false;
11050             }
11051             //
11052             query_nodes = new HashSet<PhylogenyNode>();
11053             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11054             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11055             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11056             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11057             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11058             if ( s0.match( query_nodes ) ) {
11059                 return false;
11060             }
11061             //
11062             query_nodes = new HashSet<PhylogenyNode>();
11063             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11064             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11065             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11066             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11067             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11068             if ( s0.match( query_nodes ) ) {
11069                 return false;
11070             }
11071             //
11072             query_nodes = new HashSet<PhylogenyNode>();
11073             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11074             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11075             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11076             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11077             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11078             if ( s0.match( query_nodes ) ) {
11079                 return false;
11080             }
11081             //
11082             query_nodes = new HashSet<PhylogenyNode>();
11083             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11084             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11085             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11086             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11087             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11088             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11089             if ( s0.match( query_nodes ) ) {
11090                 return false;
11091             }
11092         }
11093         catch ( final Exception e ) {
11094             e.printStackTrace();
11095             return false;
11096         }
11097         return true;
11098     }
11099
11100     private static boolean testSplitStrict() {
11101         try {
11102             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11103             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11104             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11105             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11106             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11107             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11108             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11109             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11110             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11111             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11112             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11113             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11114             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11115             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11116             if ( s0.match( query_nodes ) ) {
11117                 return false;
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( "C" ) );
11123             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11124             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11125             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11126             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11127             if ( !s0.match( query_nodes ) ) {
11128                 return false;
11129             }
11130             //
11131             query_nodes = new HashSet<PhylogenyNode>();
11132             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11133             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11134             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11135             if ( !s0.match( query_nodes ) ) {
11136                 return false;
11137             }
11138             //
11139             query_nodes = new HashSet<PhylogenyNode>();
11140             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11141             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11142             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11143             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
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( "B" ) );
11151             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11152             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11153             if ( !s0.match( query_nodes ) ) {
11154                 return false;
11155             }
11156             //
11157             query_nodes = new HashSet<PhylogenyNode>();
11158             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11159             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11160             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11161             if ( !s0.match( query_nodes ) ) {
11162                 return false;
11163             }
11164             //
11165             query_nodes = new HashSet<PhylogenyNode>();
11166             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11167             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11168             if ( !s0.match( query_nodes ) ) {
11169                 return false;
11170             }
11171             //
11172             query_nodes = new HashSet<PhylogenyNode>();
11173             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11174             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11175             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11176             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11177             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11178             if ( !s0.match( query_nodes ) ) {
11179                 return false;
11180             }
11181             //
11182             query_nodes = new HashSet<PhylogenyNode>();
11183             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11184             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11185             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11186             if ( !s0.match( query_nodes ) ) {
11187                 return false;
11188             }
11189             //
11190             query_nodes = new HashSet<PhylogenyNode>();
11191             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11192             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11193             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11194             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11195             if ( !s0.match( query_nodes ) ) {
11196                 return false;
11197             }
11198             //
11199             query_nodes = new HashSet<PhylogenyNode>();
11200             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11201             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11202             if ( s0.match( query_nodes ) ) {
11203                 return false;
11204             }
11205             //
11206             query_nodes = new HashSet<PhylogenyNode>();
11207             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11208             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11209             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11210             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11211             if ( s0.match( query_nodes ) ) {
11212                 return false;
11213             }
11214             //
11215             query_nodes = new HashSet<PhylogenyNode>();
11216             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11217             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11218             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11219             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11220             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11221             if ( s0.match( query_nodes ) ) {
11222                 return false;
11223             }
11224             //
11225             query_nodes = new HashSet<PhylogenyNode>();
11226             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11227             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11228             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11229             if ( s0.match( query_nodes ) ) {
11230                 return false;
11231             }
11232             //
11233             query_nodes = new HashSet<PhylogenyNode>();
11234             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11235             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11236             if ( s0.match( query_nodes ) ) {
11237                 return false;
11238             }
11239             //
11240             query_nodes = new HashSet<PhylogenyNode>();
11241             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11242             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11243             if ( s0.match( query_nodes ) ) {
11244                 return false;
11245             }
11246             //
11247             query_nodes = new HashSet<PhylogenyNode>();
11248             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11249             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11250             if ( s0.match( query_nodes ) ) {
11251                 return false;
11252             }
11253             //
11254             query_nodes = new HashSet<PhylogenyNode>();
11255             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11256             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11257             if ( s0.match( query_nodes ) ) {
11258                 return false;
11259             }
11260             //
11261             query_nodes = new HashSet<PhylogenyNode>();
11262             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11263             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11264             if ( s0.match( query_nodes ) ) {
11265                 return false;
11266             }
11267             //
11268             query_nodes = new HashSet<PhylogenyNode>();
11269             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
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( "A" ) );
11277             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11278             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11279             if ( s0.match( query_nodes ) ) {
11280                 return false;
11281             }
11282             //
11283             query_nodes = new HashSet<PhylogenyNode>();
11284             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11285             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11286             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11287             if ( s0.match( query_nodes ) ) {
11288                 return false;
11289             }
11290             //
11291             query_nodes = new HashSet<PhylogenyNode>();
11292             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11293             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11294             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11295             if ( s0.match( query_nodes ) ) {
11296                 return false;
11297             }
11298             //
11299             query_nodes = new HashSet<PhylogenyNode>();
11300             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11301             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11302             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11303             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11304             if ( s0.match( query_nodes ) ) {
11305                 return false;
11306             }
11307         }
11308         catch ( final Exception e ) {
11309             e.printStackTrace();
11310             return false;
11311         }
11312         return true;
11313     }
11314
11315     private static boolean testSubtreeDeletion() {
11316         try {
11317             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11318             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11319             t1.deleteSubtree( t1.getNode( "A" ), false );
11320             if ( t1.getNumberOfExternalNodes() != 5 ) {
11321                 return false;
11322             }
11323             t1.toNewHampshireX();
11324             t1.deleteSubtree( t1.getNode( "E" ), false );
11325             if ( t1.getNumberOfExternalNodes() != 4 ) {
11326                 return false;
11327             }
11328             t1.toNewHampshireX();
11329             t1.deleteSubtree( t1.getNode( "F" ), false );
11330             if ( t1.getNumberOfExternalNodes() != 3 ) {
11331                 return false;
11332             }
11333             t1.toNewHampshireX();
11334             t1.deleteSubtree( t1.getNode( "D" ), false );
11335             t1.toNewHampshireX();
11336             if ( t1.getNumberOfExternalNodes() != 3 ) {
11337                 return false;
11338             }
11339             t1.deleteSubtree( t1.getNode( "def" ), false );
11340             t1.toNewHampshireX();
11341             if ( t1.getNumberOfExternalNodes() != 2 ) {
11342                 return false;
11343             }
11344             t1.deleteSubtree( t1.getNode( "B" ), false );
11345             t1.toNewHampshireX();
11346             if ( t1.getNumberOfExternalNodes() != 1 ) {
11347                 return false;
11348             }
11349             t1.deleteSubtree( t1.getNode( "C" ), false );
11350             t1.toNewHampshireX();
11351             if ( t1.getNumberOfExternalNodes() != 1 ) {
11352                 return false;
11353             }
11354             t1.deleteSubtree( t1.getNode( "abc" ), false );
11355             t1.toNewHampshireX();
11356             if ( t1.getNumberOfExternalNodes() != 1 ) {
11357                 return false;
11358             }
11359             t1.deleteSubtree( t1.getNode( "r" ), false );
11360             if ( t1.getNumberOfExternalNodes() != 0 ) {
11361                 return false;
11362             }
11363             if ( !t1.isEmpty() ) {
11364                 return false;
11365             }
11366             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11367             t2.deleteSubtree( t2.getNode( "A" ), false );
11368             t2.toNewHampshireX();
11369             if ( t2.getNumberOfExternalNodes() != 5 ) {
11370                 return false;
11371             }
11372             t2.deleteSubtree( t2.getNode( "abc" ), false );
11373             t2.toNewHampshireX();
11374             if ( t2.getNumberOfExternalNodes() != 3 ) {
11375                 return false;
11376             }
11377             t2.deleteSubtree( t2.getNode( "def" ), false );
11378             t2.toNewHampshireX();
11379             if ( t2.getNumberOfExternalNodes() != 1 ) {
11380                 return false;
11381             }
11382         }
11383         catch ( final Exception e ) {
11384             e.printStackTrace( System.out );
11385             return false;
11386         }
11387         return true;
11388     }
11389
11390     private static boolean testSupportCount() {
11391         try {
11392             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11393             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
11394             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
11395                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
11396                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
11397                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
11398                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
11399                                                               new NHXParser() );
11400             SupportCount.count( t0_1, phylogenies_1, true, false );
11401             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
11402             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
11403                                                                       + "(((((A,B),C),D),E),((F,G),X))"
11404                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
11405                                                                       + "(((((A,B),C),D),E),(F,G))"
11406                                                                       + "(((((A,B),C),D),E),(F,G))"
11407                                                                       + "(((((A,B),C),D),E),(F,G))"
11408                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
11409                                                                       + "(((((A,B),C),D),E),(F,G))"
11410                                                                       + "((((((A,B),C),D),E),F),G)"
11411                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
11412                                                               new NHXParser() );
11413             SupportCount.count( t0_2, phylogenies_2, true, false );
11414             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
11415             while ( it.hasNext() ) {
11416                 final PhylogenyNode n = it.next();
11417                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
11418                     return false;
11419                 }
11420             }
11421             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
11422             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
11423                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
11424             SupportCount.count( t0_3, phylogenies_3, true, false );
11425             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
11426             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
11427                 return false;
11428             }
11429             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
11430                 return false;
11431             }
11432             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
11433                 return false;
11434             }
11435             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
11436                 return false;
11437             }
11438             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
11439                 return false;
11440             }
11441             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
11442                 return false;
11443             }
11444             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
11445                 return false;
11446             }
11447             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
11448                 return false;
11449             }
11450             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
11451                 return false;
11452             }
11453             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
11454                 return false;
11455             }
11456             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11457             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
11458                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
11459             SupportCount.count( t0_4, phylogenies_4, true, false );
11460             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
11461             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
11462                 return false;
11463             }
11464             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
11465                 return false;
11466             }
11467             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
11468                 return false;
11469             }
11470             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
11471                 return false;
11472             }
11473             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
11474                 return false;
11475             }
11476             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
11477                 return false;
11478             }
11479             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
11480                 return false;
11481             }
11482             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
11483                 return false;
11484             }
11485             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
11486                 return false;
11487             }
11488             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
11489                 return false;
11490             }
11491             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11492             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11493             double d = SupportCount.compare( b1, a, true, true, true );
11494             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
11495                 return false;
11496             }
11497             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11498             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11499             d = SupportCount.compare( b2, a, true, true, true );
11500             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
11501                 return false;
11502             }
11503             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11504             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
11505             d = SupportCount.compare( b3, a, true, true, true );
11506             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
11507                 return false;
11508             }
11509             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
11510             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
11511             d = SupportCount.compare( b4, a, true, true, false );
11512             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
11513                 return false;
11514             }
11515         }
11516         catch ( final Exception e ) {
11517             e.printStackTrace( System.out );
11518             return false;
11519         }
11520         return true;
11521     }
11522
11523     private static boolean testSupportTransfer() {
11524         try {
11525             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11526             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)",
11527                                                  new NHXParser() )[ 0 ];
11528             final Phylogeny p2 = factory
11529                     .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 ];
11530             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
11531                 return false;
11532             }
11533             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
11534                 return false;
11535             }
11536             support_transfer.moveBranchLengthsToBootstrap( p1 );
11537             support_transfer.transferSupportValues( p1, p2 );
11538             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
11539                 return false;
11540             }
11541             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
11542                 return false;
11543             }
11544             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
11545                 return false;
11546             }
11547             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
11548                 return false;
11549             }
11550             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
11551                 return false;
11552             }
11553             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
11554                 return false;
11555             }
11556             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
11557                 return false;
11558             }
11559             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
11560                 return false;
11561             }
11562         }
11563         catch ( final Exception e ) {
11564             e.printStackTrace( System.out );
11565             return false;
11566         }
11567         return true;
11568     }
11569
11570     private static boolean testTaxonomyExtraction() {
11571         try {
11572             final PhylogenyNode n0 = PhylogenyNode
11573                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11574             if ( n0.getNodeData().isHasTaxonomy() ) {
11575                 return false;
11576             }
11577             final PhylogenyNode n1 = PhylogenyNode
11578                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11579             if ( n1.getNodeData().isHasTaxonomy() ) {
11580                 System.out.println( n1.toString() );
11581                 return false;
11582             }
11583             final PhylogenyNode n2x = PhylogenyNode
11584                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11585             if ( n2x.getNodeData().isHasTaxonomy() ) {
11586                 return false;
11587             }
11588             final PhylogenyNode n3 = PhylogenyNode
11589                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11590             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11591                 System.out.println( n3.toString() );
11592                 return false;
11593             }
11594             final PhylogenyNode n4 = PhylogenyNode
11595                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11596             if ( n4.getNodeData().isHasTaxonomy() ) {
11597                 System.out.println( n4.toString() );
11598                 return false;
11599             }
11600             final PhylogenyNode n5 = PhylogenyNode
11601                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11602             if ( n5.getNodeData().isHasTaxonomy() ) {
11603                 System.out.println( n5.toString() );
11604                 return false;
11605             }
11606             final PhylogenyNode n6 = PhylogenyNode
11607                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11608             if ( n6.getNodeData().isHasTaxonomy() ) {
11609                 System.out.println( n6.toString() );
11610                 return false;
11611             }
11612             final PhylogenyNode n7 = PhylogenyNode
11613                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11614             if ( n7.getNodeData().isHasTaxonomy() ) {
11615                 System.out.println( n7.toString() );
11616                 return false;
11617             }
11618             final PhylogenyNode n8 = PhylogenyNode
11619                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11620             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11621                 System.out.println( n8.toString() );
11622                 return false;
11623             }
11624             final PhylogenyNode n9 = PhylogenyNode
11625                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11626             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11627                 System.out.println( n9.toString() );
11628                 return false;
11629             }
11630             final PhylogenyNode n10x = PhylogenyNode
11631                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11632             if ( n10x.getNodeData().isHasTaxonomy() ) {
11633                 System.out.println( n10x.toString() );
11634                 return false;
11635             }
11636             final PhylogenyNode n10xx = PhylogenyNode
11637                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11638             if ( n10xx.getNodeData().isHasTaxonomy() ) {
11639                 System.out.println( n10xx.toString() );
11640                 return false;
11641             }
11642             final PhylogenyNode n10 = PhylogenyNode
11643                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11644             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
11645                 System.out.println( n10.toString() );
11646                 return false;
11647             }
11648             final PhylogenyNode n11 = PhylogenyNode
11649                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11650             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
11651                 System.out.println( n11.toString() );
11652                 return false;
11653             }
11654             final PhylogenyNode n12 = PhylogenyNode
11655                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
11656                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11657             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
11658                 System.out.println( n12.toString() );
11659                 return false;
11660             }
11661             final PhylogenyNode n13 = PhylogenyNode
11662                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11663             if ( n13.getNodeData().isHasTaxonomy() ) {
11664                 System.out.println( n13.toString() );
11665                 return false;
11666             }
11667         }
11668         catch ( final Exception e ) {
11669             e.printStackTrace( System.out );
11670             return false;
11671         }
11672         return true;
11673     }
11674
11675     private static boolean testTreeCopy() {
11676         try {
11677             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
11678             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
11679             final Phylogeny t1 = t0.copy();
11680             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
11681                 return false;
11682             }
11683             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
11684                 return false;
11685             }
11686             t0.deleteSubtree( t0.getNode( "c" ), true );
11687             t0.deleteSubtree( t0.getNode( "a" ), true );
11688             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
11689             t0.getNode( "b" ).setName( "Bee" );
11690             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
11691                 return false;
11692             }
11693             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
11694                 return false;
11695             }
11696             t0.deleteSubtree( t0.getNode( "e" ), true );
11697             t0.deleteSubtree( t0.getNode( "Bee" ), true );
11698             t0.deleteSubtree( t0.getNode( "d" ), true );
11699             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
11700                 return false;
11701             }
11702         }
11703         catch ( final Exception e ) {
11704             e.printStackTrace();
11705             return false;
11706         }
11707         return true;
11708     }
11709
11710     private static boolean testTreeMethods() {
11711         try {
11712             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11713             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
11714             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
11715             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
11716                 System.out.println( t0.toNewHampshireX() );
11717                 return false;
11718             }
11719             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
11720             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
11721             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
11722                 return false;
11723             }
11724             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
11725                 return false;
11726             }
11727             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
11728                 return false;
11729             }
11730         }
11731         catch ( final Exception e ) {
11732             e.printStackTrace( System.out );
11733             return false;
11734         }
11735         return true;
11736     }
11737
11738     private static boolean testUniprotEntryRetrieval() {
11739         try {
11740             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
11741             if ( !entry.getAccession().equals( "P12345" ) ) {
11742                 return false;
11743             }
11744             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
11745                 return false;
11746             }
11747             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
11748                 return false;
11749             }
11750             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
11751                 return false;
11752             }
11753             if ( !entry.getGeneName().equals( "GOT2" ) ) {
11754                 return false;
11755             }
11756             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
11757                 return false;
11758             }
11759         }
11760         catch ( final IOException e ) {
11761             System.out.println();
11762             System.out.println( "the following might be due to absence internet connection:" );
11763             e.printStackTrace( System.out );
11764             return true;
11765         }
11766         catch ( final Exception e ) {
11767             return false;
11768         }
11769         return true;
11770     }
11771
11772     private static boolean testUniprotTaxonomySearch() {
11773         try {
11774             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
11775                                                                                                  10 );
11776             if ( results.size() != 1 ) {
11777                 return false;
11778             }
11779             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11780                 return false;
11781             }
11782             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11783                 return false;
11784             }
11785             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11786                 return false;
11787             }
11788             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11789                 return false;
11790             }
11791             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11792                 return false;
11793             }
11794             results = null;
11795             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
11796             if ( results.size() != 1 ) {
11797                 return false;
11798             }
11799             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11800                 return false;
11801             }
11802             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11803                 return false;
11804             }
11805             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11806                 return false;
11807             }
11808             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11809                 return false;
11810             }
11811             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11812                 return false;
11813             }
11814             results = null;
11815             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
11816             if ( results.size() != 1 ) {
11817                 return false;
11818             }
11819             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11820                 return false;
11821             }
11822             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11823                 return false;
11824             }
11825             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11826                 return false;
11827             }
11828             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11829                 return false;
11830             }
11831             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11832                 return false;
11833             }
11834             results = null;
11835             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
11836             if ( results.size() != 1 ) {
11837                 return false;
11838             }
11839             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11840                 return false;
11841             }
11842             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11843                 return false;
11844             }
11845             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11846                 return false;
11847             }
11848             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11849                 return false;
11850             }
11851             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11852                 return false;
11853             }
11854             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
11855                 return false;
11856             }
11857             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
11858                 return false;
11859             }
11860             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11861                     .equals( "Nematostella vectensis" ) ) {
11862                 System.out.println( results.get( 0 ).getLineage() );
11863                 return false;
11864             }
11865             //
11866             results = null;
11867             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
11868             if ( results.size() != 1 ) {
11869                 return false;
11870             }
11871             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11872                 return false;
11873             }
11874             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11875                 return false;
11876             }
11877             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11878                 return false;
11879             }
11880             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11881                 return false;
11882             }
11883             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11884                 return false;
11885             }
11886             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11887                     .equals( "Xenopus tropicalis" ) ) {
11888                 System.out.println( results.get( 0 ).getLineage() );
11889                 return false;
11890             }
11891             //
11892             results = null;
11893             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
11894             if ( results.size() != 1 ) {
11895                 return false;
11896             }
11897             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11898                 return false;
11899             }
11900             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11901                 return false;
11902             }
11903             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11904                 return false;
11905             }
11906             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11907                 return false;
11908             }
11909             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11910                 return false;
11911             }
11912             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11913                     .equals( "Xenopus tropicalis" ) ) {
11914                 System.out.println( results.get( 0 ).getLineage() );
11915                 return false;
11916             }
11917             //
11918             results = null;
11919             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
11920             if ( results.size() != 1 ) {
11921                 return false;
11922             }
11923             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11924                 return false;
11925             }
11926             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11927                 return false;
11928             }
11929             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11930                 return false;
11931             }
11932             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11933                 return false;
11934             }
11935             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11936                 return false;
11937             }
11938             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11939                     .equals( "Xenopus tropicalis" ) ) {
11940                 System.out.println( results.get( 0 ).getLineage() );
11941                 return false;
11942             }
11943         }
11944         catch ( final IOException e ) {
11945             System.out.println();
11946             System.out.println( "the following might be due to absence internet connection:" );
11947             e.printStackTrace( System.out );
11948             return true;
11949         }
11950         catch ( final Exception e ) {
11951             return false;
11952         }
11953         return true;
11954     }
11955
11956     private static boolean testWabiTxSearch() {
11957         try {
11958             String result = "";
11959             result = TxSearch.searchSimple( "nematostella" );
11960             result = TxSearch.getTxId( "nematostella" );
11961             if ( !result.equals( "45350" ) ) {
11962                 return false;
11963             }
11964             result = TxSearch.getTxName( "45350" );
11965             if ( !result.equals( "Nematostella" ) ) {
11966                 return false;
11967             }
11968             result = TxSearch.getTxId( "nematostella vectensis" );
11969             if ( !result.equals( "45351" ) ) {
11970                 return false;
11971             }
11972             result = TxSearch.getTxName( "45351" );
11973             if ( !result.equals( "Nematostella vectensis" ) ) {
11974                 return false;
11975             }
11976             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
11977             if ( !result.equals( "536089" ) ) {
11978                 return false;
11979             }
11980             result = TxSearch.getTxName( "536089" );
11981             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
11982                 return false;
11983             }
11984             final List<String> queries = new ArrayList<String>();
11985             queries.add( "Campylobacter coli" );
11986             queries.add( "Escherichia coli" );
11987             queries.add( "Arabidopsis" );
11988             queries.add( "Trichoplax" );
11989             queries.add( "Samanea saman" );
11990             queries.add( "Kluyveromyces marxianus" );
11991             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
11992             queries.add( "Bornavirus parrot/PDD/2008" );
11993             final List<RANKS> ranks = new ArrayList<RANKS>();
11994             ranks.add( RANKS.SUPERKINGDOM );
11995             ranks.add( RANKS.KINGDOM );
11996             ranks.add( RANKS.FAMILY );
11997             ranks.add( RANKS.GENUS );
11998             ranks.add( RANKS.TRIBE );
11999             result = TxSearch.searchLineage( queries, ranks );
12000             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12001             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12002         }
12003         catch ( final Exception e ) {
12004             System.out.println();
12005             System.out.println( "the following might be due to absence internet connection:" );
12006             e.printStackTrace( System.out );
12007             return false;
12008         }
12009         return true;
12010     }
12011 }