inprogress
[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.util.ArrayList;
33 import java.util.Date;
34 import java.util.HashSet;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.Locale;
38 import java.util.Set;
39 import java.util.SortedSet;
40
41 import org.forester.application.support_transfer;
42 import org.forester.archaeopteryx.TreePanelUtil;
43 import org.forester.development.DevelopmentTools;
44 import org.forester.evoinference.TestPhylogenyReconstruction;
45 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
46 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
47 import org.forester.go.TestGo;
48 import org.forester.io.parsers.FastaParser;
49 import org.forester.io.parsers.GeneralMsaParser;
50 import org.forester.io.parsers.HmmscanPerDomainTableParser;
51 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
52 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
53 import org.forester.io.parsers.nexus.NexusCharactersParser;
54 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
55 import org.forester.io.parsers.nhx.NHXParser;
56 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
57 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
58 import org.forester.io.parsers.tol.TolParser;
59 import org.forester.io.parsers.util.ParserUtils;
60 import org.forester.io.writers.PhylogenyWriter;
61 import org.forester.io.writers.SequenceWriter;
62 import org.forester.msa.BasicMsa;
63 import org.forester.msa.Mafft;
64 import org.forester.msa.Msa;
65 import org.forester.msa.MsaInferrer;
66 import org.forester.msa.MsaMethods;
67 import org.forester.pccx.TestPccx;
68 import org.forester.phylogeny.Phylogeny;
69 import org.forester.phylogeny.PhylogenyBranch;
70 import org.forester.phylogeny.PhylogenyMethods;
71 import org.forester.phylogeny.PhylogenyNode;
72 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
73 import org.forester.phylogeny.data.Accession;
74 import org.forester.phylogeny.data.Accession.Source;
75 import org.forester.phylogeny.data.BinaryCharacters;
76 import org.forester.phylogeny.data.BranchWidth;
77 import org.forester.phylogeny.data.Confidence;
78 import org.forester.phylogeny.data.Distribution;
79 import org.forester.phylogeny.data.DomainArchitecture;
80 import org.forester.phylogeny.data.Event;
81 import org.forester.phylogeny.data.Identifier;
82 import org.forester.phylogeny.data.PhylogenyData;
83 import org.forester.phylogeny.data.PhylogenyDataUtil;
84 import org.forester.phylogeny.data.Polygon;
85 import org.forester.phylogeny.data.PropertiesMap;
86 import org.forester.phylogeny.data.Property;
87 import org.forester.phylogeny.data.Property.AppliesTo;
88 import org.forester.phylogeny.data.ProteinDomain;
89 import org.forester.phylogeny.data.Taxonomy;
90 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
91 import org.forester.phylogeny.factories.PhylogenyFactory;
92 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
93 import org.forester.protein.BasicDomain;
94 import org.forester.protein.BasicProtein;
95 import org.forester.protein.Domain;
96 import org.forester.protein.Protein;
97 import org.forester.protein.ProteinId;
98 import org.forester.rio.TestRIO;
99 import org.forester.sdi.SDI;
100 import org.forester.sdi.SDIR;
101 import org.forester.sdi.TestGSDI;
102 import org.forester.sequence.BasicSequence;
103 import org.forester.sequence.Sequence;
104 import org.forester.species.BasicSpecies;
105 import org.forester.species.Species;
106 import org.forester.surfacing.TestSurfacing;
107 import org.forester.tools.ConfidenceAssessor;
108 import org.forester.tools.SupportCount;
109 import org.forester.tools.TreeSplitMatrix;
110 import org.forester.util.AsciiHistogram;
111 import org.forester.util.BasicDescriptiveStatistics;
112 import org.forester.util.BasicTable;
113 import org.forester.util.BasicTableParser;
114 import org.forester.util.DescriptiveStatistics;
115 import org.forester.util.ForesterConstants;
116 import org.forester.util.ForesterUtil;
117 import org.forester.util.GeneralTable;
118 import org.forester.util.SequenceAccessionTools;
119 import org.forester.ws.seqdb.SequenceDatabaseEntry;
120 import org.forester.ws.seqdb.SequenceDbWsTools;
121 import org.forester.ws.seqdb.UniProtTaxonomy;
122 import org.forester.ws.wabi.TxSearch;
123 import org.forester.ws.wabi.TxSearch.RANKS;
124 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
125 import org.forester.ws.wabi.TxSearch.TAX_RANK;
126
127 @SuppressWarnings( "unused")
128 public final class Test {
129
130     private final static boolean PERFORM_DB_TESTS          = true;
131     private final static double  ZERO_DIFF                 = 1.0E-9;
132     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
133                                                                    + ForesterUtil.getFileSeparator() + "test_data"
134                                                                    + ForesterUtil.getFileSeparator();
135     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
136                                                                    + ForesterUtil.getFileSeparator() + "resources"
137                                                                    + ForesterUtil.getFileSeparator();
138     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
139     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
140                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
141                                                                    + ForesterConstants.PHYLO_XML_XSD;
142     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
143                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
144                                                                    + ForesterConstants.PHYLO_XML_XSD;
145
146     public static boolean isEqual( final double a, final double b ) {
147         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
148     }
149
150     public static void main( final String[] args ) {
151         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
152         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
153                 + "]" );
154         Locale.setDefault( Locale.US );
155         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
156         int failed = 0;
157         int succeeded = 0;
158         System.out.print( "[Test if directory with files for testing exists/is readable: " );
159         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
160             System.out.println( "OK.]" );
161         }
162         else {
163             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
164             System.out.println( "Testing aborted." );
165             System.exit( -1 );
166         }
167         System.out.print( "[Test if resources directory exists/is readable: " );
168         if ( testDir( PATH_TO_RESOURCES ) ) {
169             System.out.println( "OK.]" );
170         }
171         else {
172             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
173             System.out.println( "Testing aborted." );
174             System.exit( -1 );
175         }
176         final long start_time = new Date().getTime();
177         System.out.print( "Basic node methods: " );
178         if ( Test.testBasicNodeMethods() ) {
179             System.out.println( "OK." );
180             succeeded++;
181         }
182         else {
183             System.out.println( "failed." );
184             failed++;
185         }
186         System.out.print( "Protein id: " );
187         if ( !testProteinId() ) {
188             System.out.println( "failed." );
189             failed++;
190         }
191         else {
192             succeeded++;
193         }
194         System.out.println( "OK." );
195         System.out.print( "Species: " );
196         if ( !testSpecies() ) {
197             System.out.println( "failed." );
198             failed++;
199         }
200         else {
201             succeeded++;
202         }
203         System.out.println( "OK." );
204         System.out.print( "Basic domain: " );
205         if ( !testBasicDomain() ) {
206             System.out.println( "failed." );
207             failed++;
208         }
209         else {
210             succeeded++;
211         }
212         System.out.println( "OK." );
213         System.out.print( "Basic protein: " );
214         if ( !testBasicProtein() ) {
215             System.out.println( "failed." );
216             failed++;
217         }
218         else {
219             succeeded++;
220         }
221         System.out.println( "OK." );
222         System.out.print( "Sequence writer: " );
223         if ( testSequenceWriter() ) {
224             System.out.println( "OK." );
225             succeeded++;
226         }
227         else {
228             System.out.println( "failed." );
229             failed++;
230         }
231         System.out.print( "Sequence id parsing: " );
232         if ( testSequenceIdParsing() ) {
233             System.out.println( "OK." );
234             succeeded++;
235         }
236         else {
237             System.out.println( "failed." );
238             failed++;
239         }
240         if ( PERFORM_DB_TESTS ) {
241             System.out.print( "Ebi Entry Retrieval: " );
242             if ( Test.testEbiEntryRetrieval() ) {
243                 System.out.println( "OK." );
244                 succeeded++;
245             }
246             else {
247                 System.out.println( "failed." );
248                 failed++;
249             }
250         }
251         System.exit( 0 );
252         System.out.print( "UniProtKB id extraction: " );
253         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
254             System.out.println( "OK." );
255             succeeded++;
256         }
257         else {
258             System.out.println( "failed." );
259             failed++;
260         }
261         System.out.print( "Sequence DB tools 1: " );
262         if ( testSequenceDbWsTools1() ) {
263             System.out.println( "OK." );
264             succeeded++;
265         }
266         else {
267             System.out.println( "failed." );
268             failed++;
269         }
270         if ( PERFORM_DB_TESTS ) {
271             System.out.print( "Sequence DB tools 2: " );
272             if ( testSequenceDbWsTools2() ) {
273                 System.out.println( "OK." );
274                 succeeded++;
275             }
276             else {
277                 System.out.println( "failed." );
278                 failed++;
279                 System.exit( -1 );
280             }
281         }
282         System.out.print( "Hmmscan output parser: " );
283         if ( testHmmscanOutputParser() ) {
284             System.out.println( "OK." );
285             succeeded++;
286         }
287         else {
288             System.out.println( "failed." );
289             failed++;
290         }
291         System.out.print( "Taxonomy code extraction: " );
292         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
293             System.out.println( "OK." );
294             succeeded++;
295         }
296         else {
297             System.out.println( "failed." );
298             failed++;
299         }
300         System.out.print( "SN extraction: " );
301         if ( Test.testExtractSNFromNodeName() ) {
302             System.out.println( "OK." );
303             succeeded++;
304         }
305         else {
306             System.out.println( "failed." );
307             failed++;
308         }
309         System.out.print( "Taxonomy extraction (general): " );
310         if ( Test.testTaxonomyExtraction() ) {
311             System.out.println( "OK." );
312             succeeded++;
313         }
314         else {
315             System.out.println( "failed." );
316             failed++;
317         }
318         System.out.print( "Uri for Aptx web sequence accession: " );
319         if ( Test.testCreateUriForSeqWeb() ) {
320             System.out.println( "OK." );
321             succeeded++;
322         }
323         else {
324             System.out.println( "failed." );
325             failed++;
326         }
327         System.out.print( "Basic node construction and parsing of NHX (node level): " );
328         if ( Test.testNHXNodeParsing() ) {
329             System.out.println( "OK." );
330             succeeded++;
331         }
332         else {
333             System.out.println( "failed." );
334             failed++;
335         }
336         System.out.print( "NHX parsing iterating: " );
337         if ( Test.testNHParsingIter() ) {
338             System.out.println( "OK." );
339             succeeded++;
340         }
341         else {
342             System.out.println( "failed." );
343             failed++;
344         }
345         System.out.print( "NH parsing: " );
346         if ( Test.testNHParsing() ) {
347             System.out.println( "OK." );
348             succeeded++;
349         }
350         else {
351             System.out.println( "failed." );
352             failed++;
353         }
354         System.out.print( "Conversion to NHX (node level): " );
355         if ( Test.testNHXconversion() ) {
356             System.out.println( "OK." );
357             succeeded++;
358         }
359         else {
360             System.out.println( "failed." );
361             failed++;
362         }
363         System.out.print( "NHX parsing: " );
364         if ( Test.testNHXParsing() ) {
365             System.out.println( "OK." );
366             succeeded++;
367         }
368         else {
369             System.out.println( "failed." );
370             failed++;
371         }
372         System.out.print( "NHX parsing with quotes: " );
373         if ( Test.testNHXParsingQuotes() ) {
374             System.out.println( "OK." );
375             succeeded++;
376         }
377         else {
378             System.out.println( "failed." );
379             failed++;
380         }
381         System.out.print( "NHX parsing (MrBayes): " );
382         if ( Test.testNHXParsingMB() ) {
383             System.out.println( "OK." );
384             succeeded++;
385         }
386         else {
387             System.out.println( "failed." );
388             failed++;
389         }
390         System.out.print( "Nexus characters parsing: " );
391         if ( Test.testNexusCharactersParsing() ) {
392             System.out.println( "OK." );
393             succeeded++;
394         }
395         else {
396             System.out.println( "failed." );
397             failed++;
398         }
399         System.out.print( "Nexus tree parsing iterating: " );
400         if ( Test.testNexusTreeParsingIterating() ) {
401             System.out.println( "OK." );
402             succeeded++;
403         }
404         else {
405             System.out.println( "failed." );
406             failed++;
407         }
408         System.out.print( "Nexus tree parsing: " );
409         if ( Test.testNexusTreeParsing() ) {
410             System.out.println( "OK." );
411             succeeded++;
412         }
413         else {
414             System.out.println( "failed." );
415             failed++;
416         }
417         System.out.print( "Nexus tree parsing (translating): " );
418         if ( Test.testNexusTreeParsingTranslating() ) {
419             System.out.println( "OK." );
420             succeeded++;
421         }
422         else {
423             System.out.println( "failed." );
424             failed++;
425         }
426         System.out.print( "Nexus matrix parsing: " );
427         if ( Test.testNexusMatrixParsing() ) {
428             System.out.println( "OK." );
429             succeeded++;
430         }
431         else {
432             System.out.println( "failed." );
433             failed++;
434         }
435         System.out.print( "Basic phyloXML parsing: " );
436         if ( Test.testBasicPhyloXMLparsing() ) {
437             System.out.println( "OK." );
438             succeeded++;
439         }
440         else {
441             System.out.println( "failed." );
442             failed++;
443         }
444         System.out.print( "Basic phyloXML parsing (validating against schema): " );
445         if ( testBasicPhyloXMLparsingValidating() ) {
446             System.out.println( "OK." );
447             succeeded++;
448         }
449         else {
450             System.out.println( "failed." );
451             failed++;
452         }
453         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
454         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
455             System.out.println( "OK." );
456             succeeded++;
457         }
458         else {
459             System.out.println( "failed." );
460             failed++;
461         }
462         System.out.print( "phyloXML Distribution Element: " );
463         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
464             System.out.println( "OK." );
465             succeeded++;
466         }
467         else {
468             System.out.println( "failed." );
469             failed++;
470         }
471         System.out.print( "Tol XML parsing: " );
472         if ( Test.testBasicTolXMLparsing() ) {
473             System.out.println( "OK." );
474             succeeded++;
475         }
476         else {
477             System.out.println( "failed." );
478             failed++;
479         }
480         System.out.print( "Copying of node data: " );
481         if ( Test.testCopyOfNodeData() ) {
482             System.out.println( "OK." );
483             succeeded++;
484         }
485         else {
486             System.out.println( "failed." );
487             failed++;
488         }
489         System.out.print( "Basic tree methods: " );
490         if ( Test.testBasicTreeMethods() ) {
491             System.out.println( "OK." );
492             succeeded++;
493         }
494         else {
495             System.out.println( "failed." );
496             failed++;
497         }
498         System.out.print( "Tree methods: " );
499         if ( Test.testTreeMethods() ) {
500             System.out.println( "OK." );
501             succeeded++;
502         }
503         else {
504             System.out.println( "failed." );
505             failed++;
506         }
507         System.out.print( "Postorder Iterator: " );
508         if ( Test.testPostOrderIterator() ) {
509             System.out.println( "OK." );
510             succeeded++;
511         }
512         else {
513             System.out.println( "failed." );
514             failed++;
515         }
516         System.out.print( "Preorder Iterator: " );
517         if ( Test.testPreOrderIterator() ) {
518             System.out.println( "OK." );
519             succeeded++;
520         }
521         else {
522             System.out.println( "failed." );
523             failed++;
524         }
525         System.out.print( "Levelorder Iterator: " );
526         if ( Test.testLevelOrderIterator() ) {
527             System.out.println( "OK." );
528             succeeded++;
529         }
530         else {
531             System.out.println( "failed." );
532             failed++;
533         }
534         System.out.print( "Re-id methods: " );
535         if ( Test.testReIdMethods() ) {
536             System.out.println( "OK." );
537             succeeded++;
538         }
539         else {
540             System.out.println( "failed." );
541             failed++;
542         }
543         System.out.print( "Methods on last external nodes: " );
544         if ( Test.testLastExternalNodeMethods() ) {
545             System.out.println( "OK." );
546             succeeded++;
547         }
548         else {
549             System.out.println( "failed." );
550             failed++;
551         }
552         System.out.print( "Methods on external nodes: " );
553         if ( Test.testExternalNodeRelatedMethods() ) {
554             System.out.println( "OK." );
555             succeeded++;
556         }
557         else {
558             System.out.println( "failed." );
559             failed++;
560         }
561         System.out.print( "Deletion of external nodes: " );
562         if ( Test.testDeletionOfExternalNodes() ) {
563             System.out.println( "OK." );
564             succeeded++;
565         }
566         else {
567             System.out.println( "failed." );
568             failed++;
569         }
570         System.out.print( "Subtree deletion: " );
571         if ( Test.testSubtreeDeletion() ) {
572             System.out.println( "OK." );
573             succeeded++;
574         }
575         else {
576             System.out.println( "failed." );
577             failed++;
578         }
579         System.out.print( "Phylogeny branch: " );
580         if ( Test.testPhylogenyBranch() ) {
581             System.out.println( "OK." );
582             succeeded++;
583         }
584         else {
585             System.out.println( "failed." );
586             failed++;
587         }
588         System.out.print( "Rerooting: " );
589         if ( Test.testRerooting() ) {
590             System.out.println( "OK." );
591             succeeded++;
592         }
593         else {
594             System.out.println( "failed." );
595             failed++;
596         }
597         System.out.print( "Mipoint rooting: " );
598         if ( Test.testMidpointrooting() ) {
599             System.out.println( "OK." );
600             succeeded++;
601         }
602         else {
603             System.out.println( "failed." );
604             failed++;
605         }
606         System.out.print( "Node removal: " );
607         if ( Test.testNodeRemoval() ) {
608             System.out.println( "OK." );
609             succeeded++;
610         }
611         else {
612             System.out.println( "failed." );
613             failed++;
614         }
615         System.out.print( "Support count: " );
616         if ( Test.testSupportCount() ) {
617             System.out.println( "OK." );
618             succeeded++;
619         }
620         else {
621             System.out.println( "failed." );
622             failed++;
623         }
624         System.out.print( "Support transfer: " );
625         if ( Test.testSupportTransfer() ) {
626             System.out.println( "OK." );
627             succeeded++;
628         }
629         else {
630             System.out.println( "failed." );
631             failed++;
632         }
633         System.out.print( "Finding of LCA: " );
634         if ( Test.testGetLCA() ) {
635             System.out.println( "OK." );
636             succeeded++;
637         }
638         else {
639             System.out.println( "failed." );
640             failed++;
641         }
642         System.out.print( "Finding of LCA 2: " );
643         if ( Test.testGetLCA2() ) {
644             System.out.println( "OK." );
645             succeeded++;
646         }
647         else {
648             System.out.println( "failed." );
649             failed++;
650         }
651         System.out.print( "Calculation of distance between nodes: " );
652         if ( Test.testGetDistance() ) {
653             System.out.println( "OK." );
654             succeeded++;
655         }
656         else {
657             System.out.println( "failed." );
658             failed++;
659         }
660         System.out.print( "Descriptive statistics: " );
661         if ( Test.testDescriptiveStatistics() ) {
662             System.out.println( "OK." );
663             succeeded++;
664         }
665         else {
666             System.out.println( "failed." );
667             failed++;
668         }
669         System.out.print( "Data objects and methods: " );
670         if ( Test.testDataObjects() ) {
671             System.out.println( "OK." );
672             succeeded++;
673         }
674         else {
675             System.out.println( "failed." );
676             failed++;
677         }
678         System.out.print( "Properties map: " );
679         if ( Test.testPropertiesMap() ) {
680             System.out.println( "OK." );
681             succeeded++;
682         }
683         else {
684             System.out.println( "failed." );
685             failed++;
686         }
687         System.out.print( "SDIse: " );
688         if ( Test.testSDIse() ) {
689             System.out.println( "OK." );
690             succeeded++;
691         }
692         else {
693             System.out.println( "failed." );
694             failed++;
695         }
696         System.out.print( "SDIunrooted: " );
697         if ( Test.testSDIunrooted() ) {
698             System.out.println( "OK." );
699             succeeded++;
700         }
701         else {
702             System.out.println( "failed." );
703             failed++;
704         }
705         System.out.print( "GSDI: " );
706         if ( TestGSDI.test() ) {
707             System.out.println( "OK." );
708             succeeded++;
709         }
710         else {
711             System.out.println( "failed." );
712             failed++;
713         }
714         System.out.print( "RIO: " );
715         if ( TestRIO.test() ) {
716             System.out.println( "OK." );
717             succeeded++;
718         }
719         else {
720             System.out.println( "failed." );
721             failed++;
722         }
723         System.out.print( "Phylogeny reconstruction:" );
724         System.out.println();
725         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
726             System.out.println( "OK." );
727             succeeded++;
728         }
729         else {
730             System.out.println( "failed." );
731             failed++;
732         }
733         System.out.print( "Analysis of domain architectures: " );
734         System.out.println();
735         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
736             System.out.println( "OK." );
737             succeeded++;
738         }
739         else {
740             System.out.println( "failed." );
741             failed++;
742         }
743         System.out.print( "GO: " );
744         System.out.println();
745         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
746             System.out.println( "OK." );
747             succeeded++;
748         }
749         else {
750             System.out.println( "failed." );
751             failed++;
752         }
753         System.out.print( "Modeling tools: " );
754         if ( TestPccx.test() ) {
755             System.out.println( "OK." );
756             succeeded++;
757         }
758         else {
759             System.out.println( "failed." );
760             failed++;
761         }
762         System.out.print( "Split Matrix strict: " );
763         if ( Test.testSplitStrict() ) {
764             System.out.println( "OK." );
765             succeeded++;
766         }
767         else {
768             System.out.println( "failed." );
769             failed++;
770         }
771         System.out.print( "Split Matrix: " );
772         if ( Test.testSplit() ) {
773             System.out.println( "OK." );
774             succeeded++;
775         }
776         else {
777             System.out.println( "failed." );
778             failed++;
779         }
780         System.out.print( "Confidence Assessor: " );
781         if ( Test.testConfidenceAssessor() ) {
782             System.out.println( "OK." );
783             succeeded++;
784         }
785         else {
786             System.out.println( "failed." );
787             failed++;
788         }
789         System.out.print( "Basic table: " );
790         if ( Test.testBasicTable() ) {
791             System.out.println( "OK." );
792             succeeded++;
793         }
794         else {
795             System.out.println( "failed." );
796             failed++;
797         }
798         System.out.print( "General table: " );
799         if ( Test.testGeneralTable() ) {
800             System.out.println( "OK." );
801             succeeded++;
802         }
803         else {
804             System.out.println( "failed." );
805             failed++;
806         }
807         System.out.print( "Amino acid sequence: " );
808         if ( Test.testAminoAcidSequence() ) {
809             System.out.println( "OK." );
810             succeeded++;
811         }
812         else {
813             System.out.println( "failed." );
814             failed++;
815         }
816         System.out.print( "General MSA parser: " );
817         if ( Test.testGeneralMsaParser() ) {
818             System.out.println( "OK." );
819             succeeded++;
820         }
821         else {
822             System.out.println( "failed." );
823             failed++;
824         }
825         System.out.print( "Fasta parser for msa: " );
826         if ( Test.testFastaParser() ) {
827             System.out.println( "OK." );
828             succeeded++;
829         }
830         else {
831             System.out.println( "failed." );
832             failed++;
833         }
834         System.out.print( "Creation of balanced phylogeny: " );
835         if ( Test.testCreateBalancedPhylogeny() ) {
836             System.out.println( "OK." );
837             succeeded++;
838         }
839         else {
840             System.out.println( "failed." );
841             failed++;
842         }
843         System.out.print( "Genbank accessor parsing: " );
844         if ( Test.testGenbankAccessorParsing() ) {
845             System.out.println( "OK." );
846             succeeded++;
847         }
848         else {
849             System.out.println( "failed." );
850             failed++;
851         }
852         if ( PERFORM_DB_TESTS ) {
853             System.out.print( "Uniprot Entry Retrieval: " );
854             if ( Test.testUniprotEntryRetrieval() ) {
855                 System.out.println( "OK." );
856                 succeeded++;
857             }
858             else {
859                 System.out.println( "failed." );
860                 failed++;
861             }
862         }
863         if ( PERFORM_DB_TESTS ) {
864             System.out.print( "Uniprot Taxonomy Search: " );
865             if ( Test.testUniprotTaxonomySearch() ) {
866                 System.out.println( "OK." );
867                 succeeded++;
868             }
869             else {
870                 System.out.println( "failed." );
871                 failed++;
872             }
873         }
874         //----
875         String path = "";
876         final String os = ForesterUtil.OS_NAME.toLowerCase();
877         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
878             path = "/usr/local/bin/mafft";
879         }
880         else if ( os.indexOf( "win" ) >= 0 ) {
881             path = "C:\\Program Files\\mafft-win\\mafft.bat";
882         }
883         else {
884             path = "/home/czmasek/bin/mafft";
885         }
886         if ( !MsaInferrer.isInstalled( path ) ) {
887             path = "mafft";
888         }
889         if ( !MsaInferrer.isInstalled( path ) ) {
890             path = "/usr/local/bin/mafft";
891         }
892         if ( MsaInferrer.isInstalled( path ) ) {
893             System.out.print( "MAFFT (external program): " );
894             if ( Test.testMafft( path ) ) {
895                 System.out.println( "OK." );
896                 succeeded++;
897             }
898             else {
899                 System.out.println( "failed [will not count towards failed tests]" );
900             }
901         }
902         //----
903         System.out.print( "Next nodes with collapsed: " );
904         if ( Test.testNextNodeWithCollapsing() ) {
905             System.out.println( "OK." );
906             succeeded++;
907         }
908         else {
909             System.out.println( "failed." );
910             failed++;
911         }
912         System.out.print( "Simple MSA quality: " );
913         if ( Test.testMsaQualityMethod() ) {
914             System.out.println( "OK." );
915             succeeded++;
916         }
917         else {
918             System.out.println( "failed." );
919             failed++;
920         }
921         System.out.println();
922         final Runtime rt = java.lang.Runtime.getRuntime();
923         final long free_memory = rt.freeMemory() / 1000000;
924         final long total_memory = rt.totalMemory() / 1000000;
925         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
926                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
927         System.out.println();
928         System.out.println( "Successful tests: " + succeeded );
929         System.out.println( "Failed     tests: " + failed );
930         System.out.println();
931         if ( failed < 1 ) {
932             System.out.println( "OK." );
933         }
934         else {
935             System.out.println( "Not OK." );
936         }
937     }
938
939     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
940         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
941         return p;
942     }
943
944     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
945         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
946     }
947
948     private static boolean testAminoAcidSequence() {
949         try {
950             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
951             if ( aa1.getLength() != 13 ) {
952                 return false;
953             }
954             if ( aa1.getResidueAt( 0 ) != 'A' ) {
955                 return false;
956             }
957             if ( aa1.getResidueAt( 2 ) != 'K' ) {
958                 return false;
959             }
960             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
961                 return false;
962             }
963             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
964             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
965                 return false;
966             }
967             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
968             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
969                 return false;
970             }
971             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
972             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
973                 return false;
974             }
975         }
976         catch ( final Exception e ) {
977             e.printStackTrace();
978             return false;
979         }
980         return true;
981     }
982
983     private static boolean testBasicDomain() {
984         try {
985             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
986             if ( !pd.getDomainId().equals( "id" ) ) {
987                 return false;
988             }
989             if ( pd.getNumber() != 1 ) {
990                 return false;
991             }
992             if ( pd.getTotalCount() != 4 ) {
993                 return false;
994             }
995             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
996                 return false;
997             }
998             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
999             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1000             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1001             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1002             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1003             if ( !a1.equals( a1 ) ) {
1004                 return false;
1005             }
1006             if ( !a1.equals( a1_copy ) ) {
1007                 return false;
1008             }
1009             if ( !a1.equals( a1_equal ) ) {
1010                 return false;
1011             }
1012             if ( !a1.equals( a2 ) ) {
1013                 return false;
1014             }
1015             if ( a1.equals( a3 ) ) {
1016                 return false;
1017             }
1018             if ( a1.compareTo( a1 ) != 0 ) {
1019                 return false;
1020             }
1021             if ( a1.compareTo( a1_copy ) != 0 ) {
1022                 return false;
1023             }
1024             if ( a1.compareTo( a1_equal ) != 0 ) {
1025                 return false;
1026             }
1027             if ( a1.compareTo( a2 ) != 0 ) {
1028                 return false;
1029             }
1030             if ( a1.compareTo( a3 ) == 0 ) {
1031                 return false;
1032             }
1033         }
1034         catch ( final Exception e ) {
1035             e.printStackTrace( System.out );
1036             return false;
1037         }
1038         return true;
1039     }
1040
1041     private static boolean testBasicNodeMethods() {
1042         try {
1043             if ( PhylogenyNode.getNodeCount() != 0 ) {
1044                 return false;
1045             }
1046             final PhylogenyNode n1 = new PhylogenyNode();
1047             final PhylogenyNode n2 = PhylogenyNode
1048                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1049             final PhylogenyNode n3 = PhylogenyNode
1050                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1051             final PhylogenyNode n4 = PhylogenyNode
1052                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1053             if ( n1.isHasAssignedEvent() ) {
1054                 return false;
1055             }
1056             if ( PhylogenyNode.getNodeCount() != 4 ) {
1057                 return false;
1058             }
1059             if ( n3.getIndicator() != 0 ) {
1060                 return false;
1061             }
1062             if ( n3.getNumberOfExternalNodes() != 1 ) {
1063                 return false;
1064             }
1065             if ( !n3.isExternal() ) {
1066                 return false;
1067             }
1068             if ( !n3.isRoot() ) {
1069                 return false;
1070             }
1071             if ( !n4.getName().equals( "n4" ) ) {
1072                 return false;
1073             }
1074         }
1075         catch ( final Exception e ) {
1076             e.printStackTrace( System.out );
1077             return false;
1078         }
1079         return true;
1080     }
1081
1082     private static boolean testBasicPhyloXMLparsing() {
1083         try {
1084             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1085             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1086             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1087                                                               xml_parser );
1088             if ( xml_parser.getErrorCount() > 0 ) {
1089                 System.out.println( xml_parser.getErrorMessages().toString() );
1090                 return false;
1091             }
1092             if ( phylogenies_0.length != 4 ) {
1093                 return false;
1094             }
1095             final Phylogeny t1 = phylogenies_0[ 0 ];
1096             final Phylogeny t2 = phylogenies_0[ 1 ];
1097             final Phylogeny t3 = phylogenies_0[ 2 ];
1098             final Phylogeny t4 = phylogenies_0[ 3 ];
1099             if ( t1.getNumberOfExternalNodes() != 1 ) {
1100                 return false;
1101             }
1102             if ( !t1.isRooted() ) {
1103                 return false;
1104             }
1105             if ( t1.isRerootable() ) {
1106                 return false;
1107             }
1108             if ( !t1.getType().equals( "gene_tree" ) ) {
1109                 return false;
1110             }
1111             if ( t2.getNumberOfExternalNodes() != 2 ) {
1112                 return false;
1113             }
1114             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1115                 return false;
1116             }
1117             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1118                 return false;
1119             }
1120             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1121                 return false;
1122             }
1123             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1124                 return false;
1125             }
1126             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1127                 return false;
1128             }
1129             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1130                 return false;
1131             }
1132             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1133                     .startsWith( "actgtgggggt" ) ) {
1134                 return false;
1135             }
1136             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1137                     .startsWith( "ctgtgatgcat" ) ) {
1138                 return false;
1139             }
1140             if ( t3.getNumberOfExternalNodes() != 4 ) {
1141                 return false;
1142             }
1143             if ( !t1.getName().equals( "t1" ) ) {
1144                 return false;
1145             }
1146             if ( !t2.getName().equals( "t2" ) ) {
1147                 return false;
1148             }
1149             if ( !t3.getName().equals( "t3" ) ) {
1150                 return false;
1151             }
1152             if ( !t4.getName().equals( "t4" ) ) {
1153                 return false;
1154             }
1155             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1156                 return false;
1157             }
1158             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1159                 return false;
1160             }
1161             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1162                 return false;
1163             }
1164             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1165                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1166                 return false;
1167             }
1168             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1169                 return false;
1170             }
1171             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1172                 return false;
1173             }
1174             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1175                 return false;
1176             }
1177             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1178                     .equals( "apoptosis" ) ) {
1179                 return false;
1180             }
1181             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1182                     .equals( "GO:0006915" ) ) {
1183                 return false;
1184             }
1185             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1186                     .equals( "UniProtKB" ) ) {
1187                 return false;
1188             }
1189             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1190                     .equals( "experimental" ) ) {
1191                 return false;
1192             }
1193             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1194                     .equals( "function" ) ) {
1195                 return false;
1196             }
1197             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1198                     .getValue() != 1 ) {
1199                 return false;
1200             }
1201             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1202                     .getType().equals( "ml" ) ) {
1203                 return false;
1204             }
1205             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1206                     .equals( "apoptosis" ) ) {
1207                 return false;
1208             }
1209             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1210                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1211                 return false;
1212             }
1213             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1214                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1215                 return false;
1216             }
1217             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1218                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1219                 return false;
1220             }
1221             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1222                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1223                 return false;
1224             }
1225             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1226                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1227                 return false;
1228             }
1229             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1230                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1231                 return false;
1232             }
1233             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1234                     .equals( "GO:0005829" ) ) {
1235                 return false;
1236             }
1237             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1238                     .equals( "intracellular organelle" ) ) {
1239                 return false;
1240             }
1241             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1242                 return false;
1243             }
1244             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1245                     .equals( "UniProt link" ) ) ) {
1246                 return false;
1247             }
1248             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1249                 return false;
1250             }
1251             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1252             if ( x.size() != 4 ) {
1253                 return false;
1254             }
1255             int c = 0;
1256             for( final Accession acc : x ) {
1257                 if ( c == 0 ) {
1258                     if ( !acc.getSource().equals( "KEGG" ) ) {
1259                         return false;
1260                     }
1261                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1262                         return false;
1263                     }
1264                 }
1265                 c++;
1266             }
1267         }
1268         catch ( final Exception e ) {
1269             e.printStackTrace( System.out );
1270             return false;
1271         }
1272         return true;
1273     }
1274
1275     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1276         try {
1277             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1278             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1279             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1280                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1281             }
1282             else {
1283                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1284             }
1285             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1286                                                               xml_parser );
1287             if ( xml_parser.getErrorCount() > 0 ) {
1288                 System.out.println( xml_parser.getErrorMessages().toString() );
1289                 return false;
1290             }
1291             if ( phylogenies_0.length != 4 ) {
1292                 return false;
1293             }
1294             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1295             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1296             if ( phylogenies_t1.length != 1 ) {
1297                 return false;
1298             }
1299             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1300             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1301                 return false;
1302             }
1303             if ( !t1_rt.isRooted() ) {
1304                 return false;
1305             }
1306             if ( t1_rt.isRerootable() ) {
1307                 return false;
1308             }
1309             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1310                 return false;
1311             }
1312             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1313             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1314             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1315             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1316                 return false;
1317             }
1318             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1319                 return false;
1320             }
1321             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1322                 return false;
1323             }
1324             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1325                 return false;
1326             }
1327             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1328                     .startsWith( "actgtgggggt" ) ) {
1329                 return false;
1330             }
1331             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1332                     .startsWith( "ctgtgatgcat" ) ) {
1333                 return false;
1334             }
1335             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1336             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1337             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1338             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1339             if ( phylogenies_1.length != 1 ) {
1340                 return false;
1341             }
1342             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1343             if ( !t3_rt.getName().equals( "t3" ) ) {
1344                 return false;
1345             }
1346             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1347                 return false;
1348             }
1349             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1350                 return false;
1351             }
1352             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1353                 return false;
1354             }
1355             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1356                 return false;
1357             }
1358             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1359                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1360                 return false;
1361             }
1362             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1363                 return false;
1364             }
1365             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1366                 return false;
1367             }
1368             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1369                     .equals( "UniProtKB" ) ) {
1370                 return false;
1371             }
1372             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1373                     .equals( "apoptosis" ) ) {
1374                 return false;
1375             }
1376             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1377                     .equals( "GO:0006915" ) ) {
1378                 return false;
1379             }
1380             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1381                     .equals( "UniProtKB" ) ) {
1382                 return false;
1383             }
1384             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1385                     .equals( "experimental" ) ) {
1386                 return false;
1387             }
1388             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1389                     .equals( "function" ) ) {
1390                 return false;
1391             }
1392             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1393                     .getValue() != 1 ) {
1394                 return false;
1395             }
1396             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1397                     .getType().equals( "ml" ) ) {
1398                 return false;
1399             }
1400             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1401                     .equals( "apoptosis" ) ) {
1402                 return false;
1403             }
1404             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1405                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1406                 return false;
1407             }
1408             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1409                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1410                 return false;
1411             }
1412             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1413                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1414                 return false;
1415             }
1416             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1417                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1418                 return false;
1419             }
1420             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1421                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1422                 return false;
1423             }
1424             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1425                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1426                 return false;
1427             }
1428             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1429                     .equals( "GO:0005829" ) ) {
1430                 return false;
1431             }
1432             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1433                     .equals( "intracellular organelle" ) ) {
1434                 return false;
1435             }
1436             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1437                 return false;
1438             }
1439             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1440                     .equals( "UniProt link" ) ) ) {
1441                 return false;
1442             }
1443             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1444                 return false;
1445             }
1446             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1447                 return false;
1448             }
1449             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1450                     .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." ) ) ) {
1451                 return false;
1452             }
1453             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1454                 return false;
1455             }
1456             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1457                 return false;
1458             }
1459             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1460                 return false;
1461             }
1462             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1463                 return false;
1464             }
1465             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1466                     .equals( "ncbi" ) ) {
1467                 return false;
1468             }
1469             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1470                 return false;
1471             }
1472             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1473                     .getName().equals( "B" ) ) {
1474                 return false;
1475             }
1476             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1477                     .getFrom() != 21 ) {
1478                 return false;
1479             }
1480             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1481                 return false;
1482             }
1483             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1484                     .getLength() != 24 ) {
1485                 return false;
1486             }
1487             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1488                     .getConfidence() != 2144 ) {
1489                 return false;
1490             }
1491             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1492                     .equals( "pfam" ) ) {
1493                 return false;
1494             }
1495             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1496                 return false;
1497             }
1498             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1499                 return false;
1500             }
1501             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1502                 return false;
1503             }
1504             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1505                 return false;
1506             }
1507             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1508             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1509                 return false;
1510             }
1511             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1512                 return false;
1513             }
1514             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1515                 return false;
1516             }
1517             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1518                 return false;
1519             }
1520             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1521                 return false;
1522             }
1523             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1524                 return false;
1525             }
1526             if ( taxbb.getSynonyms().size() != 2 ) {
1527                 return false;
1528             }
1529             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1530                 return false;
1531             }
1532             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1533                 return false;
1534             }
1535             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1536                 return false;
1537             }
1538             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1539                 return false;
1540             }
1541             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1542                 return false;
1543             }
1544             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1545                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1546                 return false;
1547             }
1548             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1549                 return false;
1550             }
1551             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1552                 return false;
1553             }
1554             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1555                 return false;
1556             }
1557             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1558                 return false;
1559             }
1560             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1561                 return false;
1562             }
1563             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1564                 return false;
1565             }
1566             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1567                 return false;
1568             }
1569             //
1570             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1571                 return false;
1572             }
1573             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1574                     .equalsIgnoreCase( "435" ) ) {
1575                 return false;
1576             }
1577             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1578                 return false;
1579             }
1580             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1581                     .equalsIgnoreCase( "443.7" ) ) {
1582                 return false;
1583             }
1584             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1585                 return false;
1586             }
1587             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1588                 return false;
1589             }
1590             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1591                     .equalsIgnoreCase( "433" ) ) {
1592                 return false;
1593             }
1594             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
1595                     .getCrossReferences();
1596             if ( x.size() != 4 ) {
1597                 return false;
1598             }
1599             int c = 0;
1600             for( final Accession acc : x ) {
1601                 if ( c == 0 ) {
1602                     if ( !acc.getSource().equals( "KEGG" ) ) {
1603                         return false;
1604                     }
1605                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1606                         return false;
1607                     }
1608                 }
1609                 c++;
1610             }
1611         }
1612         catch ( final Exception e ) {
1613             e.printStackTrace( System.out );
1614             return false;
1615         }
1616         return true;
1617     }
1618
1619     private static boolean testBasicPhyloXMLparsingValidating() {
1620         try {
1621             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1622             PhyloXmlParser xml_parser = null;
1623             try {
1624                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1625             }
1626             catch ( final Exception e ) {
1627                 // Do nothing -- means were not running from jar.
1628             }
1629             if ( xml_parser == null ) {
1630                 xml_parser = new PhyloXmlParser();
1631                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1632                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1633                 }
1634                 else {
1635                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1636                 }
1637             }
1638             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1639                                                               xml_parser );
1640             if ( xml_parser.getErrorCount() > 0 ) {
1641                 System.out.println( xml_parser.getErrorMessages().toString() );
1642                 return false;
1643             }
1644             if ( phylogenies_0.length != 4 ) {
1645                 return false;
1646             }
1647             final Phylogeny t1 = phylogenies_0[ 0 ];
1648             final Phylogeny t2 = phylogenies_0[ 1 ];
1649             final Phylogeny t3 = phylogenies_0[ 2 ];
1650             final Phylogeny t4 = phylogenies_0[ 3 ];
1651             if ( !t1.getName().equals( "t1" ) ) {
1652                 return false;
1653             }
1654             if ( !t2.getName().equals( "t2" ) ) {
1655                 return false;
1656             }
1657             if ( !t3.getName().equals( "t3" ) ) {
1658                 return false;
1659             }
1660             if ( !t4.getName().equals( "t4" ) ) {
1661                 return false;
1662             }
1663             if ( t1.getNumberOfExternalNodes() != 1 ) {
1664                 return false;
1665             }
1666             if ( t2.getNumberOfExternalNodes() != 2 ) {
1667                 return false;
1668             }
1669             if ( t3.getNumberOfExternalNodes() != 4 ) {
1670                 return false;
1671             }
1672             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1673             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1674             if ( xml_parser.getErrorCount() > 0 ) {
1675                 System.out.println( "errors:" );
1676                 System.out.println( xml_parser.getErrorMessages().toString() );
1677                 return false;
1678             }
1679             if ( phylogenies_1.length != 4 ) {
1680                 return false;
1681             }
1682             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1683                                                               xml_parser );
1684             if ( xml_parser.getErrorCount() > 0 ) {
1685                 System.out.println( "errors:" );
1686                 System.out.println( xml_parser.getErrorMessages().toString() );
1687                 return false;
1688             }
1689             if ( phylogenies_2.length != 1 ) {
1690                 return false;
1691             }
1692             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1693                 return false;
1694             }
1695             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1696                                                               xml_parser );
1697             if ( xml_parser.getErrorCount() > 0 ) {
1698                 System.out.println( xml_parser.getErrorMessages().toString() );
1699                 return false;
1700             }
1701             if ( phylogenies_3.length != 2 ) {
1702                 return false;
1703             }
1704             final Phylogeny a = phylogenies_3[ 0 ];
1705             if ( !a.getName().equals( "tree 4" ) ) {
1706                 return false;
1707             }
1708             if ( a.getNumberOfExternalNodes() != 3 ) {
1709                 return false;
1710             }
1711             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1712                 return false;
1713             }
1714             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1715                 return false;
1716             }
1717             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1718                                                               xml_parser );
1719             if ( xml_parser.getErrorCount() > 0 ) {
1720                 System.out.println( xml_parser.getErrorMessages().toString() );
1721                 return false;
1722             }
1723             if ( phylogenies_4.length != 1 ) {
1724                 return false;
1725             }
1726             final Phylogeny s = phylogenies_4[ 0 ];
1727             if ( s.getNumberOfExternalNodes() != 6 ) {
1728                 return false;
1729             }
1730             s.getNode( "first" );
1731             s.getNode( "<>" );
1732             s.getNode( "\"<a'b&c'd\">\"" );
1733             s.getNode( "'''\"" );
1734             s.getNode( "\"\"\"" );
1735             s.getNode( "dick & doof" );
1736         }
1737         catch ( final Exception e ) {
1738             e.printStackTrace( System.out );
1739             return false;
1740         }
1741         return true;
1742     }
1743
1744     private static boolean testBasicProtein() {
1745         try {
1746             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
1747             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1748             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1749             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
1750             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
1751             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
1752             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1753             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1754             p0.addProteinDomain( y );
1755             p0.addProteinDomain( e );
1756             p0.addProteinDomain( b );
1757             p0.addProteinDomain( c );
1758             p0.addProteinDomain( d );
1759             p0.addProteinDomain( a );
1760             p0.addProteinDomain( x );
1761             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
1762                 return false;
1763             }
1764             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
1765                 return false;
1766             }
1767             //
1768             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
1769             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1770             aa0.addProteinDomain( a1 );
1771             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
1772                 return false;
1773             }
1774             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
1775                 return false;
1776             }
1777             //
1778             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
1779             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1780             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1781             aa1.addProteinDomain( a11 );
1782             aa1.addProteinDomain( a12 );
1783             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
1784                 return false;
1785             }
1786             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
1787                 return false;
1788             }
1789             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1790             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
1791                 return false;
1792             }
1793             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
1794                 return false;
1795             }
1796             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
1797                 return false;
1798             }
1799             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1800             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
1801                 return false;
1802             }
1803             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
1804                 return false;
1805             }
1806             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
1807                 return false;
1808             }
1809             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
1810                 return false;
1811             }
1812             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1813             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
1814                 return false;
1815             }
1816             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
1817                 return false;
1818             }
1819             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
1820                 return false;
1821             }
1822             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
1823                 return false;
1824             }
1825             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1826             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
1827                 return false;
1828             }
1829             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
1830                 return false;
1831             }
1832             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
1833                 return false;
1834             }
1835             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
1836                 return false;
1837             }
1838             //
1839             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
1840             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1841             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1842             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
1843             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
1844             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
1845             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
1846             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
1847             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
1848             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
1849             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
1850             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1851             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1852             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
1853             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
1854             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
1855             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
1856             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
1857             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
1858             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
1859             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
1860             p00.addProteinDomain( y0 );
1861             p00.addProteinDomain( e0 );
1862             p00.addProteinDomain( b0 );
1863             p00.addProteinDomain( c0 );
1864             p00.addProteinDomain( d0 );
1865             p00.addProteinDomain( a0 );
1866             p00.addProteinDomain( x0 );
1867             p00.addProteinDomain( y1 );
1868             p00.addProteinDomain( y2 );
1869             p00.addProteinDomain( y3 );
1870             p00.addProteinDomain( e1 );
1871             p00.addProteinDomain( e2 );
1872             p00.addProteinDomain( e3 );
1873             p00.addProteinDomain( e4 );
1874             p00.addProteinDomain( e5 );
1875             p00.addProteinDomain( z0 );
1876             p00.addProteinDomain( z1 );
1877             p00.addProteinDomain( z2 );
1878             p00.addProteinDomain( zz0 );
1879             p00.addProteinDomain( zz1 );
1880             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
1881                 return false;
1882             }
1883             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
1884                 return false;
1885             }
1886             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1887                 return false;
1888             }
1889             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1890                 return false;
1891             }
1892             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" ) ) {
1893                 return false;
1894             }
1895             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
1896             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1897             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
1898             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
1899             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
1900             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
1901             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
1902             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
1903             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
1904             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
1905             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
1906             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
1907             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
1908             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
1909             p.addProteinDomain( B15 );
1910             p.addProteinDomain( C50 );
1911             p.addProteinDomain( A60 );
1912             p.addProteinDomain( A30 );
1913             p.addProteinDomain( C70 );
1914             p.addProteinDomain( B35 );
1915             p.addProteinDomain( B40 );
1916             p.addProteinDomain( A0 );
1917             p.addProteinDomain( A10 );
1918             p.addProteinDomain( A20 );
1919             p.addProteinDomain( B25 );
1920             p.addProteinDomain( D80 );
1921             List<String> domains_ids = new ArrayList<String>();
1922             domains_ids.add( "A" );
1923             domains_ids.add( "B" );
1924             domains_ids.add( "C" );
1925             if ( !p.contains( domains_ids, false ) ) {
1926                 return false;
1927             }
1928             if ( !p.contains( domains_ids, true ) ) {
1929                 return false;
1930             }
1931             domains_ids.add( "X" );
1932             if ( p.contains( domains_ids, false ) ) {
1933                 return false;
1934             }
1935             if ( p.contains( domains_ids, true ) ) {
1936                 return false;
1937             }
1938             domains_ids = new ArrayList<String>();
1939             domains_ids.add( "A" );
1940             domains_ids.add( "C" );
1941             domains_ids.add( "D" );
1942             if ( !p.contains( domains_ids, false ) ) {
1943                 return false;
1944             }
1945             if ( !p.contains( domains_ids, true ) ) {
1946                 return false;
1947             }
1948             domains_ids = new ArrayList<String>();
1949             domains_ids.add( "A" );
1950             domains_ids.add( "D" );
1951             domains_ids.add( "C" );
1952             if ( !p.contains( domains_ids, false ) ) {
1953                 return false;
1954             }
1955             if ( p.contains( domains_ids, true ) ) {
1956                 return false;
1957             }
1958             domains_ids = new ArrayList<String>();
1959             domains_ids.add( "A" );
1960             domains_ids.add( "A" );
1961             domains_ids.add( "B" );
1962             if ( !p.contains( domains_ids, false ) ) {
1963                 return false;
1964             }
1965             if ( !p.contains( domains_ids, true ) ) {
1966                 return false;
1967             }
1968             domains_ids = new ArrayList<String>();
1969             domains_ids.add( "A" );
1970             domains_ids.add( "A" );
1971             domains_ids.add( "A" );
1972             domains_ids.add( "B" );
1973             domains_ids.add( "B" );
1974             if ( !p.contains( domains_ids, false ) ) {
1975                 return false;
1976             }
1977             if ( !p.contains( domains_ids, true ) ) {
1978                 return false;
1979             }
1980             domains_ids = new ArrayList<String>();
1981             domains_ids.add( "A" );
1982             domains_ids.add( "A" );
1983             domains_ids.add( "B" );
1984             domains_ids.add( "A" );
1985             domains_ids.add( "B" );
1986             domains_ids.add( "B" );
1987             domains_ids.add( "A" );
1988             domains_ids.add( "B" );
1989             domains_ids.add( "C" );
1990             domains_ids.add( "A" );
1991             domains_ids.add( "C" );
1992             domains_ids.add( "D" );
1993             if ( !p.contains( domains_ids, false ) ) {
1994                 return false;
1995             }
1996             if ( p.contains( domains_ids, true ) ) {
1997                 return false;
1998             }
1999         }
2000         catch ( final Exception e ) {
2001             e.printStackTrace( System.out );
2002             return false;
2003         }
2004         return true;
2005     }
2006
2007     private static boolean testBasicTable() {
2008         try {
2009             final BasicTable<String> t0 = new BasicTable<String>();
2010             if ( t0.getNumberOfColumns() != 0 ) {
2011                 return false;
2012             }
2013             if ( t0.getNumberOfRows() != 0 ) {
2014                 return false;
2015             }
2016             t0.setValue( 3, 2, "23" );
2017             t0.setValue( 10, 1, "error" );
2018             t0.setValue( 10, 1, "110" );
2019             t0.setValue( 9, 1, "19" );
2020             t0.setValue( 1, 10, "101" );
2021             t0.setValue( 10, 10, "1010" );
2022             t0.setValue( 100, 10, "10100" );
2023             t0.setValue( 0, 0, "00" );
2024             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2025                 return false;
2026             }
2027             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2028                 return false;
2029             }
2030             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2031                 return false;
2032             }
2033             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2034                 return false;
2035             }
2036             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2037                 return false;
2038             }
2039             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2040                 return false;
2041             }
2042             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2043                 return false;
2044             }
2045             if ( t0.getNumberOfColumns() != 101 ) {
2046                 return false;
2047             }
2048             if ( t0.getNumberOfRows() != 11 ) {
2049                 return false;
2050             }
2051             if ( t0.getValueAsString( 49, 4 ) != null ) {
2052                 return false;
2053             }
2054             final String l = ForesterUtil.getLineSeparator();
2055             final StringBuffer source = new StringBuffer();
2056             source.append( "" + l );
2057             source.append( "# 1 1 1 1 1 1 1 1" + l );
2058             source.append( " 00 01 02 03" + l );
2059             source.append( "   10 11 12 13  " + l );
2060             source.append( "20 21 22 23 " + l );
2061             source.append( "    30  31    32 33" + l );
2062             source.append( "40 41 42 43" + l );
2063             source.append( "  # 1 1 1 1 1 " + l );
2064             source.append( "50 51 52 53 54" + l );
2065             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2066             if ( t1.getNumberOfColumns() != 5 ) {
2067                 return false;
2068             }
2069             if ( t1.getNumberOfRows() != 6 ) {
2070                 return false;
2071             }
2072             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2073                 return false;
2074             }
2075             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2076                 return false;
2077             }
2078             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2079                 return false;
2080             }
2081             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2082                 return false;
2083             }
2084             final StringBuffer source1 = new StringBuffer();
2085             source1.append( "" + l );
2086             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2087             source1.append( " 00; 01 ;02;03" + l );
2088             source1.append( "   10; 11; 12; 13  " + l );
2089             source1.append( "20; 21; 22; 23 " + l );
2090             source1.append( "    30;  31;    32; 33" + l );
2091             source1.append( "40;41;42;43" + l );
2092             source1.append( "  # 1 1 1 1 1 " + l );
2093             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2094             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2095             if ( t2.getNumberOfColumns() != 5 ) {
2096                 return false;
2097             }
2098             if ( t2.getNumberOfRows() != 6 ) {
2099                 return false;
2100             }
2101             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2102                 return false;
2103             }
2104             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2105                 return false;
2106             }
2107             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2108                 return false;
2109             }
2110             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2111                 return false;
2112             }
2113             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2114                 return false;
2115             }
2116             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2117                 return false;
2118             }
2119             final StringBuffer source2 = new StringBuffer();
2120             source2.append( "" + l );
2121             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2122             source2.append( " 00; 01 ;02;03" + l );
2123             source2.append( "   10; 11; 12; 13  " + l );
2124             source2.append( "20; 21; 22; 23 " + l );
2125             source2.append( "                     " + l );
2126             source2.append( "    30;  31;    32; 33" + l );
2127             source2.append( "40;41;42;43" + l );
2128             source2.append( "  comment: 1 1 1 1 1 " + l );
2129             source2.append( ";;;50  ;   52; 53;;54   " + l );
2130             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2131                                                                         ';',
2132                                                                         false,
2133                                                                         false,
2134                                                                         "comment:",
2135                                                                         false );
2136             if ( tl.size() != 2 ) {
2137                 return false;
2138             }
2139             final BasicTable<String> t3 = tl.get( 0 );
2140             final BasicTable<String> t4 = tl.get( 1 );
2141             if ( t3.getNumberOfColumns() != 4 ) {
2142                 return false;
2143             }
2144             if ( t3.getNumberOfRows() != 3 ) {
2145                 return false;
2146             }
2147             if ( t4.getNumberOfColumns() != 4 ) {
2148                 return false;
2149             }
2150             if ( t4.getNumberOfRows() != 3 ) {
2151                 return false;
2152             }
2153             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2154                 return false;
2155             }
2156             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2157                 return false;
2158             }
2159         }
2160         catch ( final Exception e ) {
2161             e.printStackTrace( System.out );
2162             return false;
2163         }
2164         return true;
2165     }
2166
2167     private static boolean testBasicTolXMLparsing() {
2168         try {
2169             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2170             final TolParser parser = new TolParser();
2171             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2172             if ( parser.getErrorCount() > 0 ) {
2173                 System.out.println( parser.getErrorMessages().toString() );
2174                 return false;
2175             }
2176             if ( phylogenies_0.length != 1 ) {
2177                 return false;
2178             }
2179             final Phylogeny t1 = phylogenies_0[ 0 ];
2180             if ( t1.getNumberOfExternalNodes() != 5 ) {
2181                 return false;
2182             }
2183             if ( !t1.isRooted() ) {
2184                 return false;
2185             }
2186             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2187                 return false;
2188             }
2189             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2190                 return false;
2191             }
2192             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2193                 return false;
2194             }
2195             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2196                 return false;
2197             }
2198             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2199             if ( parser.getErrorCount() > 0 ) {
2200                 System.out.println( parser.getErrorMessages().toString() );
2201                 return false;
2202             }
2203             if ( phylogenies_1.length != 1 ) {
2204                 return false;
2205             }
2206             final Phylogeny t2 = phylogenies_1[ 0 ];
2207             if ( t2.getNumberOfExternalNodes() != 664 ) {
2208                 return false;
2209             }
2210             if ( !t2.isRooted() ) {
2211                 return false;
2212             }
2213             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2214                 return false;
2215             }
2216             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2217                 return false;
2218             }
2219             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2220                 return false;
2221             }
2222             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2223                 return false;
2224             }
2225             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2226                 return false;
2227             }
2228             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2229                     .equals( "Aquifex" ) ) {
2230                 return false;
2231             }
2232             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2233             if ( parser.getErrorCount() > 0 ) {
2234                 System.out.println( parser.getErrorMessages().toString() );
2235                 return false;
2236             }
2237             if ( phylogenies_2.length != 1 ) {
2238                 return false;
2239             }
2240             final Phylogeny t3 = phylogenies_2[ 0 ];
2241             if ( t3.getNumberOfExternalNodes() != 184 ) {
2242                 return false;
2243             }
2244             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2245                 return false;
2246             }
2247             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2248                 return false;
2249             }
2250             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2251                 return false;
2252             }
2253             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2254             if ( parser.getErrorCount() > 0 ) {
2255                 System.out.println( parser.getErrorMessages().toString() );
2256                 return false;
2257             }
2258             if ( phylogenies_3.length != 1 ) {
2259                 return false;
2260             }
2261             final Phylogeny t4 = phylogenies_3[ 0 ];
2262             if ( t4.getNumberOfExternalNodes() != 1 ) {
2263                 return false;
2264             }
2265             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2266                 return false;
2267             }
2268             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2269                 return false;
2270             }
2271             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2272                 return false;
2273             }
2274             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2275             if ( parser.getErrorCount() > 0 ) {
2276                 System.out.println( parser.getErrorMessages().toString() );
2277                 return false;
2278             }
2279             if ( phylogenies_4.length != 1 ) {
2280                 return false;
2281             }
2282             final Phylogeny t5 = phylogenies_4[ 0 ];
2283             if ( t5.getNumberOfExternalNodes() != 13 ) {
2284                 return false;
2285             }
2286             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2287                 return false;
2288             }
2289             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2290                 return false;
2291             }
2292             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2293                 return false;
2294             }
2295         }
2296         catch ( final Exception e ) {
2297             e.printStackTrace( System.out );
2298             return false;
2299         }
2300         return true;
2301     }
2302
2303     private static boolean testBasicTreeMethods() {
2304         try {
2305             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2306             final Phylogeny t1 = factory.create();
2307             if ( !t1.isEmpty() ) {
2308                 return false;
2309             }
2310             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2311             if ( t2.getNumberOfExternalNodes() != 4 ) {
2312                 return false;
2313             }
2314             if ( t2.getHeight() != 8.5 ) {
2315                 return false;
2316             }
2317             if ( !t2.isCompletelyBinary() ) {
2318                 return false;
2319             }
2320             if ( t2.isEmpty() ) {
2321                 return false;
2322             }
2323             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2324             if ( t3.getNumberOfExternalNodes() != 5 ) {
2325                 return false;
2326             }
2327             if ( t3.getHeight() != 11 ) {
2328                 return false;
2329             }
2330             if ( t3.isCompletelyBinary() ) {
2331                 return false;
2332             }
2333             final PhylogenyNode n = t3.getNode( "ABC" );
2334             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 ];
2335             if ( t4.getNumberOfExternalNodes() != 9 ) {
2336                 return false;
2337             }
2338             if ( t4.getHeight() != 11 ) {
2339                 return false;
2340             }
2341             if ( t4.isCompletelyBinary() ) {
2342                 return false;
2343             }
2344             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)" );
2345             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2346             if ( t5.getNumberOfExternalNodes() != 8 ) {
2347                 return false;
2348             }
2349             if ( t5.getHeight() != 15 ) {
2350                 return false;
2351             }
2352             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)" );
2353             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2354             if ( t6.getHeight() != 15 ) {
2355                 return false;
2356             }
2357             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)" );
2358             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2359             if ( t7.getHeight() != 15 ) {
2360                 return false;
2361             }
2362             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)" );
2363             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2364             if ( t8.getNumberOfExternalNodes() != 10 ) {
2365                 return false;
2366             }
2367             if ( t8.getHeight() != 15 ) {
2368                 return false;
2369             }
2370             final char[] a9 = new char[] { 'a' };
2371             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2372             if ( t9.getHeight() != 0 ) {
2373                 return false;
2374             }
2375             final char[] a10 = new char[] { 'a', ':', '6' };
2376             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2377             if ( t10.getHeight() != 6 ) {
2378                 return false;
2379             }
2380         }
2381         catch ( final Exception e ) {
2382             e.printStackTrace( System.out );
2383             return false;
2384         }
2385         return true;
2386     }
2387
2388     private static boolean testConfidenceAssessor() {
2389         try {
2390             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2391             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2392             final Phylogeny[] ev0 = factory
2393                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2394                              new NHXParser() );
2395             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2396             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2397                 return false;
2398             }
2399             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2400                 return false;
2401             }
2402             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2403             final Phylogeny[] ev1 = factory
2404                     .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)));",
2405                              new NHXParser() );
2406             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2407             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2408                 return false;
2409             }
2410             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2411                 return false;
2412             }
2413             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2414             final Phylogeny[] ev_b = factory
2415                     .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",
2416                              new NHXParser() );
2417             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2418             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2419                 return false;
2420             }
2421             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2422                 return false;
2423             }
2424             //
2425             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2426             final Phylogeny[] ev1x = factory
2427                     .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)));",
2428                              new NHXParser() );
2429             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2430             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2431                 return false;
2432             }
2433             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2434                 return false;
2435             }
2436             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2437             final Phylogeny[] ev_bx = factory
2438                     .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",
2439                              new NHXParser() );
2440             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2441             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2442                 return false;
2443             }
2444             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2445                 return false;
2446             }
2447             //
2448             final Phylogeny[] t2 = factory
2449                     .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);",
2450                              new NHXParser() );
2451             final Phylogeny[] ev2 = factory
2452                     .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);",
2453                              new NHXParser() );
2454             for( final Phylogeny target : t2 ) {
2455                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2456             }
2457             //
2458             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2459                                                  new NHXParser() )[ 0 ];
2460             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2461             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2462             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2463                 return false;
2464             }
2465             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2466                 return false;
2467             }
2468             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2469                 return false;
2470             }
2471         }
2472         catch ( final Exception e ) {
2473             e.printStackTrace();
2474             return false;
2475         }
2476         return true;
2477     }
2478
2479     private static boolean testCopyOfNodeData() {
2480         try {
2481             final PhylogenyNode n1 = PhylogenyNode
2482                     .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]" );
2483             final PhylogenyNode n2 = n1.copyNodeData();
2484             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2485                 return false;
2486             }
2487         }
2488         catch ( final Exception e ) {
2489             e.printStackTrace();
2490             return false;
2491         }
2492         return true;
2493     }
2494
2495     private static boolean testCreateBalancedPhylogeny() {
2496         try {
2497             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
2498             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
2499                 return false;
2500             }
2501             if ( p0.getNumberOfExternalNodes() != 15625 ) {
2502                 return false;
2503             }
2504             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
2505             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
2506                 return false;
2507             }
2508             if ( p1.getNumberOfExternalNodes() != 100 ) {
2509                 return false;
2510             }
2511         }
2512         catch ( final Exception e ) {
2513             e.printStackTrace();
2514             return false;
2515         }
2516         return true;
2517     }
2518
2519     private static boolean testCreateUriForSeqWeb() {
2520         try {
2521             final PhylogenyNode n = new PhylogenyNode();
2522             n.setName( "tr|B3RJ64" );
2523             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
2524                 return false;
2525             }
2526             n.setName( "B0LM41_HUMAN" );
2527             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
2528                 return false;
2529             }
2530             n.setName( "NP_001025424" );
2531             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
2532                 return false;
2533             }
2534             n.setName( "_NM_001030253-" );
2535             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
2536                 return false;
2537             }
2538             n.setName( "XM_002122186" );
2539             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
2540                 return false;
2541             }
2542             n.setName( "dgh_AAA34956_gdg" );
2543             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2544                 return false;
2545             }
2546             n.setName( "AAA34956" );
2547             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2548                 return false;
2549             }
2550             n.setName( "GI:394892" );
2551             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2552                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2553                 return false;
2554             }
2555             n.setName( "gi_394892" );
2556             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2557                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2558                 return false;
2559             }
2560             n.setName( "gi6335_gi_394892_56635_Gi_43" );
2561             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2562                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2563                 return false;
2564             }
2565             n.setName( "P12345" );
2566             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2567                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2568                 return false;
2569             }
2570             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
2571             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2572                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2573                 return false;
2574             }
2575         }
2576         catch ( final Exception e ) {
2577             e.printStackTrace( System.out );
2578             return false;
2579         }
2580         return true;
2581     }
2582
2583     private static boolean testDataObjects() {
2584         try {
2585             final Confidence s0 = new Confidence();
2586             final Confidence s1 = new Confidence();
2587             if ( !s0.isEqual( s1 ) ) {
2588                 return false;
2589             }
2590             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2591             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2592             if ( s2.isEqual( s1 ) ) {
2593                 return false;
2594             }
2595             if ( !s2.isEqual( s3 ) ) {
2596                 return false;
2597             }
2598             final Confidence s4 = ( Confidence ) s3.copy();
2599             if ( !s4.isEqual( s3 ) ) {
2600                 return false;
2601             }
2602             s3.asSimpleText();
2603             s3.asText();
2604             // Taxonomy
2605             // ----------
2606             final Taxonomy t1 = new Taxonomy();
2607             final Taxonomy t2 = new Taxonomy();
2608             final Taxonomy t3 = new Taxonomy();
2609             final Taxonomy t4 = new Taxonomy();
2610             final Taxonomy t5 = new Taxonomy();
2611             t1.setIdentifier( new Identifier( "ecoli" ) );
2612             t1.setTaxonomyCode( "ECOLI" );
2613             t1.setScientificName( "E. coli" );
2614             t1.setCommonName( "coli" );
2615             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2616             if ( !t1.isEqual( t0 ) ) {
2617                 return false;
2618             }
2619             t2.setIdentifier( new Identifier( "ecoli" ) );
2620             t2.setTaxonomyCode( "OTHER" );
2621             t2.setScientificName( "what" );
2622             t2.setCommonName( "something" );
2623             if ( !t1.isEqual( t2 ) ) {
2624                 return false;
2625             }
2626             t2.setIdentifier( new Identifier( "nemve" ) );
2627             if ( t1.isEqual( t2 ) ) {
2628                 return false;
2629             }
2630             t1.setIdentifier( null );
2631             t3.setTaxonomyCode( "ECOLI" );
2632             t3.setScientificName( "what" );
2633             t3.setCommonName( "something" );
2634             if ( !t1.isEqual( t3 ) ) {
2635                 return false;
2636             }
2637             t1.setIdentifier( null );
2638             t1.setTaxonomyCode( "" );
2639             t4.setScientificName( "E. ColI" );
2640             t4.setCommonName( "something" );
2641             if ( !t1.isEqual( t4 ) ) {
2642                 return false;
2643             }
2644             t4.setScientificName( "B. subtilis" );
2645             t4.setCommonName( "something" );
2646             if ( t1.isEqual( t4 ) ) {
2647                 return false;
2648             }
2649             t1.setIdentifier( null );
2650             t1.setTaxonomyCode( "" );
2651             t1.setScientificName( "" );
2652             t5.setCommonName( "COLI" );
2653             if ( !t1.isEqual( t5 ) ) {
2654                 return false;
2655             }
2656             t5.setCommonName( "vibrio" );
2657             if ( t1.isEqual( t5 ) ) {
2658                 return false;
2659             }
2660             // Identifier
2661             // ----------
2662             final Identifier id0 = new Identifier( "123", "pfam" );
2663             final Identifier id1 = ( Identifier ) id0.copy();
2664             if ( !id1.isEqual( id1 ) ) {
2665                 return false;
2666             }
2667             if ( !id1.isEqual( id0 ) ) {
2668                 return false;
2669             }
2670             if ( !id0.isEqual( id1 ) ) {
2671                 return false;
2672             }
2673             id1.asSimpleText();
2674             id1.asText();
2675             // ProteinDomain
2676             // ---------------
2677             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2678             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2679             if ( !pd1.isEqual( pd1 ) ) {
2680                 return false;
2681             }
2682             if ( !pd1.isEqual( pd0 ) ) {
2683                 return false;
2684             }
2685             pd1.asSimpleText();
2686             pd1.asText();
2687             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2688             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2689             if ( !pd3.isEqual( pd3 ) ) {
2690                 return false;
2691             }
2692             if ( !pd2.isEqual( pd3 ) ) {
2693                 return false;
2694             }
2695             if ( !pd0.isEqual( pd3 ) ) {
2696                 return false;
2697             }
2698             pd3.asSimpleText();
2699             pd3.asText();
2700             // DomainArchitecture
2701             // ------------------
2702             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2703             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2704             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2705             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2706             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2707             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2708             domains0.add( d2 );
2709             domains0.add( d0 );
2710             domains0.add( d3 );
2711             domains0.add( d1 );
2712             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2713             if ( ds0.getNumberOfDomains() != 4 ) {
2714                 return false;
2715             }
2716             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2717             if ( !ds0.isEqual( ds0 ) ) {
2718                 return false;
2719             }
2720             if ( !ds0.isEqual( ds1 ) ) {
2721                 return false;
2722             }
2723             if ( ds1.getNumberOfDomains() != 4 ) {
2724                 return false;
2725             }
2726             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2727             domains1.add( d1 );
2728             domains1.add( d2 );
2729             domains1.add( d4 );
2730             domains1.add( d0 );
2731             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2732             if ( ds0.isEqual( ds2 ) ) {
2733                 return false;
2734             }
2735             ds1.asSimpleText();
2736             ds1.asText();
2737             ds1.toNHX();
2738             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2739             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2740                 System.out.println( ds3.toNHX() );
2741                 return false;
2742             }
2743             if ( ds3.getNumberOfDomains() != 3 ) {
2744                 return false;
2745             }
2746             // Event
2747             // -----
2748             final Event e1 = new Event( Event.EventType.fusion );
2749             if ( e1.isDuplication() ) {
2750                 return false;
2751             }
2752             if ( !e1.isFusion() ) {
2753                 return false;
2754             }
2755             if ( !e1.asText().toString().equals( "fusion" ) ) {
2756                 return false;
2757             }
2758             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2759                 return false;
2760             }
2761             final Event e11 = new Event( Event.EventType.fusion );
2762             if ( !e11.isEqual( e1 ) ) {
2763                 return false;
2764             }
2765             if ( !e11.toNHX().toString().equals( "" ) ) {
2766                 return false;
2767             }
2768             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2769             if ( e2.isDuplication() ) {
2770                 return false;
2771             }
2772             if ( !e2.isSpeciationOrDuplication() ) {
2773                 return false;
2774             }
2775             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2776                 return false;
2777             }
2778             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2779                 return false;
2780             }
2781             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2782                 return false;
2783             }
2784             if ( e11.isEqual( e2 ) ) {
2785                 return false;
2786             }
2787             final Event e2c = ( Event ) e2.copy();
2788             if ( !e2c.isEqual( e2 ) ) {
2789                 return false;
2790             }
2791             Event e3 = new Event( 1, 2, 3 );
2792             if ( e3.isDuplication() ) {
2793                 return false;
2794             }
2795             if ( e3.isSpeciation() ) {
2796                 return false;
2797             }
2798             if ( e3.isGeneLoss() ) {
2799                 return false;
2800             }
2801             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2802                 return false;
2803             }
2804             final Event e3c = ( Event ) e3.copy();
2805             final Event e3cc = ( Event ) e3c.copy();
2806             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2807                 return false;
2808             }
2809             e3 = null;
2810             if ( !e3c.isEqual( e3cc ) ) {
2811                 return false;
2812             }
2813             Event e4 = new Event( 1, 2, 3 );
2814             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2815                 return false;
2816             }
2817             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2818                 return false;
2819             }
2820             final Event e4c = ( Event ) e4.copy();
2821             e4 = null;
2822             final Event e4cc = ( Event ) e4c.copy();
2823             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2824                 return false;
2825             }
2826             if ( !e4c.isEqual( e4cc ) ) {
2827                 return false;
2828             }
2829             final Event e5 = new Event();
2830             if ( !e5.isUnassigned() ) {
2831                 return false;
2832             }
2833             if ( !e5.asText().toString().equals( "unassigned" ) ) {
2834                 return false;
2835             }
2836             if ( !e5.asSimpleText().toString().equals( "" ) ) {
2837                 return false;
2838             }
2839             final Event e6 = new Event( 1, 0, 0 );
2840             if ( !e6.asText().toString().equals( "duplication" ) ) {
2841                 return false;
2842             }
2843             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2844                 return false;
2845             }
2846             final Event e7 = new Event( 0, 1, 0 );
2847             if ( !e7.asText().toString().equals( "speciation" ) ) {
2848                 return false;
2849             }
2850             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2851                 return false;
2852             }
2853             final Event e8 = new Event( 0, 0, 1 );
2854             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2855                 return false;
2856             }
2857             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2858                 return false;
2859             }
2860         }
2861         catch ( final Exception e ) {
2862             e.printStackTrace( System.out );
2863             return false;
2864         }
2865         return true;
2866     }
2867
2868     private static boolean testDeletionOfExternalNodes() {
2869         try {
2870             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2871             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2872             final PhylogenyWriter w = new PhylogenyWriter();
2873             if ( t0.isEmpty() ) {
2874                 return false;
2875             }
2876             if ( t0.getNumberOfExternalNodes() != 1 ) {
2877                 return false;
2878             }
2879             t0.deleteSubtree( t0.getNode( "A" ), false );
2880             if ( t0.getNumberOfExternalNodes() != 0 ) {
2881                 return false;
2882             }
2883             if ( !t0.isEmpty() ) {
2884                 return false;
2885             }
2886             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2887             if ( t1.getNumberOfExternalNodes() != 2 ) {
2888                 return false;
2889             }
2890             t1.deleteSubtree( t1.getNode( "A" ), false );
2891             if ( t1.getNumberOfExternalNodes() != 1 ) {
2892                 return false;
2893             }
2894             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2895                 return false;
2896             }
2897             t1.deleteSubtree( t1.getNode( "B" ), false );
2898             if ( t1.getNumberOfExternalNodes() != 1 ) {
2899                 return false;
2900             }
2901             t1.deleteSubtree( t1.getNode( "r" ), false );
2902             if ( !t1.isEmpty() ) {
2903                 return false;
2904             }
2905             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2906             if ( t2.getNumberOfExternalNodes() != 3 ) {
2907                 return false;
2908             }
2909             t2.deleteSubtree( t2.getNode( "B" ), false );
2910             if ( t2.getNumberOfExternalNodes() != 2 ) {
2911                 return false;
2912             }
2913             t2.toNewHampshireX();
2914             PhylogenyNode n = t2.getNode( "A" );
2915             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2916                 return false;
2917             }
2918             t2.deleteSubtree( t2.getNode( "A" ), false );
2919             if ( t2.getNumberOfExternalNodes() != 2 ) {
2920                 return false;
2921             }
2922             t2.deleteSubtree( t2.getNode( "C" ), true );
2923             if ( t2.getNumberOfExternalNodes() != 1 ) {
2924                 return false;
2925             }
2926             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2927             if ( t3.getNumberOfExternalNodes() != 4 ) {
2928                 return false;
2929             }
2930             t3.deleteSubtree( t3.getNode( "B" ), true );
2931             if ( t3.getNumberOfExternalNodes() != 3 ) {
2932                 return false;
2933             }
2934             n = t3.getNode( "A" );
2935             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2936                 return false;
2937             }
2938             n = n.getNextExternalNode();
2939             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2940                 return false;
2941             }
2942             t3.deleteSubtree( t3.getNode( "A" ), true );
2943             if ( t3.getNumberOfExternalNodes() != 2 ) {
2944                 return false;
2945             }
2946             n = t3.getNode( "C" );
2947             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2948                 return false;
2949             }
2950             t3.deleteSubtree( t3.getNode( "C" ), true );
2951             if ( t3.getNumberOfExternalNodes() != 1 ) {
2952                 return false;
2953             }
2954             t3.deleteSubtree( t3.getNode( "D" ), true );
2955             if ( t3.getNumberOfExternalNodes() != 0 ) {
2956                 return false;
2957             }
2958             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2959             if ( t4.getNumberOfExternalNodes() != 6 ) {
2960                 return false;
2961             }
2962             t4.deleteSubtree( t4.getNode( "B2" ), true );
2963             if ( t4.getNumberOfExternalNodes() != 5 ) {
2964                 return false;
2965             }
2966             String s = w.toNewHampshire( t4, false, true ).toString();
2967             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2968                 return false;
2969             }
2970             t4.deleteSubtree( t4.getNode( "B11" ), true );
2971             if ( t4.getNumberOfExternalNodes() != 4 ) {
2972                 return false;
2973             }
2974             t4.deleteSubtree( t4.getNode( "C" ), true );
2975             if ( t4.getNumberOfExternalNodes() != 3 ) {
2976                 return false;
2977             }
2978             n = t4.getNode( "A" );
2979             n = n.getNextExternalNode();
2980             if ( !n.getName().equals( "B12" ) ) {
2981                 return false;
2982             }
2983             n = n.getNextExternalNode();
2984             if ( !n.getName().equals( "D" ) ) {
2985                 return false;
2986             }
2987             s = w.toNewHampshire( t4, false, true ).toString();
2988             if ( !s.equals( "((A,B12),D);" ) ) {
2989                 return false;
2990             }
2991             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2992             t5.deleteSubtree( t5.getNode( "A" ), true );
2993             if ( t5.getNumberOfExternalNodes() != 5 ) {
2994                 return false;
2995             }
2996             s = w.toNewHampshire( t5, false, true ).toString();
2997             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2998                 return false;
2999             }
3000             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3001             t6.deleteSubtree( t6.getNode( "B11" ), true );
3002             if ( t6.getNumberOfExternalNodes() != 5 ) {
3003                 return false;
3004             }
3005             s = w.toNewHampshire( t6, false, false ).toString();
3006             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3007                 return false;
3008             }
3009             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3010             t7.deleteSubtree( t7.getNode( "B12" ), true );
3011             if ( t7.getNumberOfExternalNodes() != 5 ) {
3012                 return false;
3013             }
3014             s = w.toNewHampshire( t7, false, true ).toString();
3015             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3016                 return false;
3017             }
3018             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3019             t8.deleteSubtree( t8.getNode( "B2" ), true );
3020             if ( t8.getNumberOfExternalNodes() != 5 ) {
3021                 return false;
3022             }
3023             s = w.toNewHampshire( t8, false, false ).toString();
3024             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3025                 return false;
3026             }
3027             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3028             t9.deleteSubtree( t9.getNode( "C" ), true );
3029             if ( t9.getNumberOfExternalNodes() != 5 ) {
3030                 return false;
3031             }
3032             s = w.toNewHampshire( t9, false, true ).toString();
3033             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3034                 return false;
3035             }
3036             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3037             t10.deleteSubtree( t10.getNode( "D" ), true );
3038             if ( t10.getNumberOfExternalNodes() != 5 ) {
3039                 return false;
3040             }
3041             s = w.toNewHampshire( t10, false, true ).toString();
3042             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3043                 return false;
3044             }
3045             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3046             t11.deleteSubtree( t11.getNode( "A" ), true );
3047             if ( t11.getNumberOfExternalNodes() != 2 ) {
3048                 return false;
3049             }
3050             s = w.toNewHampshire( t11, false, true ).toString();
3051             if ( !s.equals( "(B,C);" ) ) {
3052                 return false;
3053             }
3054             t11.deleteSubtree( t11.getNode( "C" ), true );
3055             if ( t11.getNumberOfExternalNodes() != 1 ) {
3056                 return false;
3057             }
3058             s = w.toNewHampshire( t11, false, false ).toString();
3059             if ( !s.equals( "B;" ) ) {
3060                 return false;
3061             }
3062             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3063             t12.deleteSubtree( t12.getNode( "B2" ), true );
3064             if ( t12.getNumberOfExternalNodes() != 8 ) {
3065                 return false;
3066             }
3067             s = w.toNewHampshire( t12, false, true ).toString();
3068             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3069                 return false;
3070             }
3071             t12.deleteSubtree( t12.getNode( "B3" ), true );
3072             if ( t12.getNumberOfExternalNodes() != 7 ) {
3073                 return false;
3074             }
3075             s = w.toNewHampshire( t12, false, true ).toString();
3076             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3077                 return false;
3078             }
3079             t12.deleteSubtree( t12.getNode( "C3" ), true );
3080             if ( t12.getNumberOfExternalNodes() != 6 ) {
3081                 return false;
3082             }
3083             s = w.toNewHampshire( t12, false, true ).toString();
3084             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3085                 return false;
3086             }
3087             t12.deleteSubtree( t12.getNode( "A1" ), true );
3088             if ( t12.getNumberOfExternalNodes() != 5 ) {
3089                 return false;
3090             }
3091             s = w.toNewHampshire( t12, false, true ).toString();
3092             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3093                 return false;
3094             }
3095             t12.deleteSubtree( t12.getNode( "B1" ), true );
3096             if ( t12.getNumberOfExternalNodes() != 4 ) {
3097                 return false;
3098             }
3099             s = w.toNewHampshire( t12, false, true ).toString();
3100             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3101                 return false;
3102             }
3103             t12.deleteSubtree( t12.getNode( "A3" ), true );
3104             if ( t12.getNumberOfExternalNodes() != 3 ) {
3105                 return false;
3106             }
3107             s = w.toNewHampshire( t12, false, true ).toString();
3108             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3109                 return false;
3110             }
3111             t12.deleteSubtree( t12.getNode( "A2" ), true );
3112             if ( t12.getNumberOfExternalNodes() != 2 ) {
3113                 return false;
3114             }
3115             s = w.toNewHampshire( t12, false, true ).toString();
3116             if ( !s.equals( "(C1,C2);" ) ) {
3117                 return false;
3118             }
3119             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3120             t13.deleteSubtree( t13.getNode( "D" ), true );
3121             if ( t13.getNumberOfExternalNodes() != 4 ) {
3122                 return false;
3123             }
3124             s = w.toNewHampshire( t13, false, true ).toString();
3125             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3126                 return false;
3127             }
3128             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3129             t14.deleteSubtree( t14.getNode( "E" ), true );
3130             if ( t14.getNumberOfExternalNodes() != 5 ) {
3131                 return false;
3132             }
3133             s = w.toNewHampshire( t14, false, true ).toString();
3134             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3135                 return false;
3136             }
3137             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3138             t15.deleteSubtree( t15.getNode( "B2" ), true );
3139             if ( t15.getNumberOfExternalNodes() != 11 ) {
3140                 return false;
3141             }
3142             t15.deleteSubtree( t15.getNode( "B1" ), true );
3143             if ( t15.getNumberOfExternalNodes() != 10 ) {
3144                 return false;
3145             }
3146             t15.deleteSubtree( t15.getNode( "B3" ), true );
3147             if ( t15.getNumberOfExternalNodes() != 9 ) {
3148                 return false;
3149             }
3150             t15.deleteSubtree( t15.getNode( "B4" ), true );
3151             if ( t15.getNumberOfExternalNodes() != 8 ) {
3152                 return false;
3153             }
3154             t15.deleteSubtree( t15.getNode( "A1" ), true );
3155             if ( t15.getNumberOfExternalNodes() != 7 ) {
3156                 return false;
3157             }
3158             t15.deleteSubtree( t15.getNode( "C4" ), true );
3159             if ( t15.getNumberOfExternalNodes() != 6 ) {
3160                 return false;
3161             }
3162         }
3163         catch ( final Exception e ) {
3164             e.printStackTrace( System.out );
3165             return false;
3166         }
3167         return true;
3168     }
3169
3170     private static boolean testDescriptiveStatistics() {
3171         try {
3172             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3173             dss1.addValue( 82 );
3174             dss1.addValue( 78 );
3175             dss1.addValue( 70 );
3176             dss1.addValue( 58 );
3177             dss1.addValue( 42 );
3178             if ( dss1.getN() != 5 ) {
3179                 return false;
3180             }
3181             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3182                 return false;
3183             }
3184             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3185                 return false;
3186             }
3187             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3188                 return false;
3189             }
3190             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3191                 return false;
3192             }
3193             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3194                 return false;
3195             }
3196             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3197                 return false;
3198             }
3199             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3200                 return false;
3201             }
3202             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3203                 return false;
3204             }
3205             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3206                 return false;
3207             }
3208             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3209                 return false;
3210             }
3211             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3212                 return false;
3213             }
3214             dss1.addValue( 123 );
3215             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3216                 return false;
3217             }
3218             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3219                 return false;
3220             }
3221             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3222                 return false;
3223             }
3224             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3225             dss2.addValue( -1.85 );
3226             dss2.addValue( 57.5 );
3227             dss2.addValue( 92.78 );
3228             dss2.addValue( 57.78 );
3229             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3230                 return false;
3231             }
3232             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3233                 return false;
3234             }
3235             final double[] a = dss2.getDataAsDoubleArray();
3236             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3237                 return false;
3238             }
3239             dss2.addValue( -100 );
3240             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3241                 return false;
3242             }
3243             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3244                 return false;
3245             }
3246             final double[] ds = new double[ 14 ];
3247             ds[ 0 ] = 34;
3248             ds[ 1 ] = 23;
3249             ds[ 2 ] = 1;
3250             ds[ 3 ] = 32;
3251             ds[ 4 ] = 11;
3252             ds[ 5 ] = 2;
3253             ds[ 6 ] = 12;
3254             ds[ 7 ] = 33;
3255             ds[ 8 ] = 13;
3256             ds[ 9 ] = 22;
3257             ds[ 10 ] = 21;
3258             ds[ 11 ] = 35;
3259             ds[ 12 ] = 24;
3260             ds[ 13 ] = 31;
3261             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3262             if ( bins.length != 4 ) {
3263                 return false;
3264             }
3265             if ( bins[ 0 ] != 2 ) {
3266                 return false;
3267             }
3268             if ( bins[ 1 ] != 3 ) {
3269                 return false;
3270             }
3271             if ( bins[ 2 ] != 4 ) {
3272                 return false;
3273             }
3274             if ( bins[ 3 ] != 5 ) {
3275                 return false;
3276             }
3277             final double[] ds1 = new double[ 9 ];
3278             ds1[ 0 ] = 10.0;
3279             ds1[ 1 ] = 19.0;
3280             ds1[ 2 ] = 9.999;
3281             ds1[ 3 ] = 0.0;
3282             ds1[ 4 ] = 39.9;
3283             ds1[ 5 ] = 39.999;
3284             ds1[ 6 ] = 30.0;
3285             ds1[ 7 ] = 19.999;
3286             ds1[ 8 ] = 30.1;
3287             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3288             if ( bins1.length != 4 ) {
3289                 return false;
3290             }
3291             if ( bins1[ 0 ] != 2 ) {
3292                 return false;
3293             }
3294             if ( bins1[ 1 ] != 3 ) {
3295                 return false;
3296             }
3297             if ( bins1[ 2 ] != 0 ) {
3298                 return false;
3299             }
3300             if ( bins1[ 3 ] != 4 ) {
3301                 return false;
3302             }
3303             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3304             if ( bins1_1.length != 3 ) {
3305                 return false;
3306             }
3307             if ( bins1_1[ 0 ] != 3 ) {
3308                 return false;
3309             }
3310             if ( bins1_1[ 1 ] != 2 ) {
3311                 return false;
3312             }
3313             if ( bins1_1[ 2 ] != 4 ) {
3314                 return false;
3315             }
3316             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3317             if ( bins1_2.length != 3 ) {
3318                 return false;
3319             }
3320             if ( bins1_2[ 0 ] != 2 ) {
3321                 return false;
3322             }
3323             if ( bins1_2[ 1 ] != 2 ) {
3324                 return false;
3325             }
3326             if ( bins1_2[ 2 ] != 2 ) {
3327                 return false;
3328             }
3329             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3330             dss3.addValue( 1 );
3331             dss3.addValue( 1 );
3332             dss3.addValue( 1 );
3333             dss3.addValue( 2 );
3334             dss3.addValue( 3 );
3335             dss3.addValue( 4 );
3336             dss3.addValue( 5 );
3337             dss3.addValue( 5 );
3338             dss3.addValue( 5 );
3339             dss3.addValue( 6 );
3340             dss3.addValue( 7 );
3341             dss3.addValue( 8 );
3342             dss3.addValue( 9 );
3343             dss3.addValue( 10 );
3344             dss3.addValue( 10 );
3345             dss3.addValue( 10 );
3346             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3347             histo.toStringBuffer( 10, '=', 40, 5 );
3348             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3349         }
3350         catch ( final Exception e ) {
3351             e.printStackTrace( System.out );
3352             return false;
3353         }
3354         return true;
3355     }
3356
3357     private static boolean testDir( final String file ) {
3358         try {
3359             final File f = new File( file );
3360             if ( !f.exists() ) {
3361                 return false;
3362             }
3363             if ( !f.isDirectory() ) {
3364                 return false;
3365             }
3366             if ( !f.canRead() ) {
3367                 return false;
3368             }
3369         }
3370         catch ( final Exception e ) {
3371             return false;
3372         }
3373         return true;
3374     }
3375
3376     private static boolean testGenbankAccessorParsing() {
3377         //The format for GenBank Accession numbers are:
3378         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
3379         //Protein:    3 letters + 5 numerals
3380         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
3381         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
3382             return false;
3383         }
3384         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
3385             return false;
3386         }
3387         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
3388             return false;
3389         }
3390         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
3391             return false;
3392         }
3393         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
3394             return false;
3395         }
3396         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
3397             return false;
3398         }
3399         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
3400             return false;
3401         }
3402         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
3403             return false;
3404         }
3405         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
3406             return false;
3407         }
3408         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
3409             return false;
3410         }
3411         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
3412             return false;
3413         }
3414         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
3415             return false;
3416         }
3417         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
3418             return false;
3419         }
3420         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
3421             return false;
3422         }
3423         return true;
3424     }
3425
3426     private static boolean testExternalNodeRelatedMethods() {
3427         try {
3428             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3429             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3430             PhylogenyNode n = t1.getNode( "A" );
3431             n = n.getNextExternalNode();
3432             if ( !n.getName().equals( "B" ) ) {
3433                 return false;
3434             }
3435             n = n.getNextExternalNode();
3436             if ( !n.getName().equals( "C" ) ) {
3437                 return false;
3438             }
3439             n = n.getNextExternalNode();
3440             if ( !n.getName().equals( "D" ) ) {
3441                 return false;
3442             }
3443             n = t1.getNode( "B" );
3444             while ( !n.isLastExternalNode() ) {
3445                 n = n.getNextExternalNode();
3446             }
3447             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3448             n = t2.getNode( "A" );
3449             n = n.getNextExternalNode();
3450             if ( !n.getName().equals( "B" ) ) {
3451                 return false;
3452             }
3453             n = n.getNextExternalNode();
3454             if ( !n.getName().equals( "C" ) ) {
3455                 return false;
3456             }
3457             n = n.getNextExternalNode();
3458             if ( !n.getName().equals( "D" ) ) {
3459                 return false;
3460             }
3461             n = t2.getNode( "B" );
3462             while ( !n.isLastExternalNode() ) {
3463                 n = n.getNextExternalNode();
3464             }
3465             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3466             n = t3.getNode( "A" );
3467             n = n.getNextExternalNode();
3468             if ( !n.getName().equals( "B" ) ) {
3469                 return false;
3470             }
3471             n = n.getNextExternalNode();
3472             if ( !n.getName().equals( "C" ) ) {
3473                 return false;
3474             }
3475             n = n.getNextExternalNode();
3476             if ( !n.getName().equals( "D" ) ) {
3477                 return false;
3478             }
3479             n = n.getNextExternalNode();
3480             if ( !n.getName().equals( "E" ) ) {
3481                 return false;
3482             }
3483             n = n.getNextExternalNode();
3484             if ( !n.getName().equals( "F" ) ) {
3485                 return false;
3486             }
3487             n = n.getNextExternalNode();
3488             if ( !n.getName().equals( "G" ) ) {
3489                 return false;
3490             }
3491             n = n.getNextExternalNode();
3492             if ( !n.getName().equals( "H" ) ) {
3493                 return false;
3494             }
3495             n = t3.getNode( "B" );
3496             while ( !n.isLastExternalNode() ) {
3497                 n = n.getNextExternalNode();
3498             }
3499             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3500             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3501                 final PhylogenyNode node = iter.next();
3502             }
3503             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3504             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3505                 final PhylogenyNode node = iter.next();
3506             }
3507             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3508             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3509             if ( !iter.next().getName().equals( "A" ) ) {
3510                 return false;
3511             }
3512             if ( !iter.next().getName().equals( "B" ) ) {
3513                 return false;
3514             }
3515             if ( !iter.next().getName().equals( "C" ) ) {
3516                 return false;
3517             }
3518             if ( !iter.next().getName().equals( "D" ) ) {
3519                 return false;
3520             }
3521             if ( !iter.next().getName().equals( "E" ) ) {
3522                 return false;
3523             }
3524             if ( !iter.next().getName().equals( "F" ) ) {
3525                 return false;
3526             }
3527             if ( iter.hasNext() ) {
3528                 return false;
3529             }
3530         }
3531         catch ( final Exception e ) {
3532             e.printStackTrace( System.out );
3533             return false;
3534         }
3535         return true;
3536     }
3537
3538     private static boolean testExtractSNFromNodeName() {
3539         try {
3540             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
3541                 return false;
3542             }
3543             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
3544                     .equals( "Mus musculus musculus" ) ) {
3545                 return false;
3546             }
3547             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
3548                     .equals( "Mus musculus musculus" ) ) {
3549                 return false;
3550             }
3551             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
3552                 return false;
3553             }
3554             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
3555                     .equals( "Mus musculus" ) ) {
3556                 return false;
3557             }
3558         }
3559         catch ( final Exception e ) {
3560             e.printStackTrace( System.out );
3561             return false;
3562         }
3563         return true;
3564     }
3565
3566     private static boolean testExtractTaxonomyCodeFromNodeName() {
3567         try {
3568             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3569                 return false;
3570             }
3571             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3572                     .equals( "SOYBN" ) ) {
3573                 return false;
3574             }
3575             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3576                     .equals( "ARATH" ) ) {
3577                 return false;
3578             }
3579             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3580                     .equals( "ARATH" ) ) {
3581                 return false;
3582             }
3583             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3584                 return false;
3585             }
3586             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3587                 return false;
3588             }
3589             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3590                 return false;
3591             }
3592             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3593                     .equals( "SOYBN" ) ) {
3594                 return false;
3595             }
3596             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3597                     .equals( "SOYBN" ) ) {
3598                 return false;
3599             }
3600             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3601                     .equals( "SOYBN" ) ) {
3602                 return false;
3603             }
3604             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3605                     .equals( "SOYBN" ) ) {
3606                 return false;
3607             }
3608             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3609                     .equals( "SOYBN" ) ) {
3610                 return false;
3611             }
3612             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3613                     .equals( "SOYBN" ) ) {
3614                 return false;
3615             }
3616             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
3617                     .equals( "SOYBN" ) ) {
3618                 return false;
3619             }
3620             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
3621                     .equals( "SOYBN" ) ) {
3622                 return false;
3623             }
3624             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
3625                 return false;
3626             }
3627             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
3628                     .equals( "SOYBN" ) ) {
3629                 return false;
3630             }
3631             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
3632                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
3633                 return false;
3634             }
3635             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
3636                     .equals( "9YX45" ) ) {
3637                 return false;
3638             }
3639             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
3640                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3641                     .equals( "MOUSE" ) ) {
3642                 return false;
3643             }
3644             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
3645                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3646                     .equals( "MOUSE" ) ) {
3647                 return false;
3648             }
3649             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
3650                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3651                     .equals( "MOUSE" ) ) {
3652                 return false;
3653             }
3654             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
3655                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3656                 return false;
3657             }
3658             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
3659                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3660                 return false;
3661             }
3662             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
3663                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3664                 return false;
3665             }
3666             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
3667                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3668                 return false;
3669             }
3670             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
3671                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3672                 return false;
3673             }
3674             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
3675                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3676                 return false;
3677             }
3678             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
3679                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3680                 return false;
3681             }
3682             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3683                     .equals( "RAT" ) ) {
3684                 return false;
3685             }
3686             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
3687                     .equals( "PIG" ) ) {
3688                 return false;
3689             }
3690             if ( !ParserUtils
3691                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3692                     .equals( "MOUSE" ) ) {
3693                 return false;
3694             }
3695             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
3696                     .equals( "MOUSE" ) ) {
3697                 return false;
3698             }
3699             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3700                 return false;
3701             }
3702         }
3703         catch ( final Exception e ) {
3704             e.printStackTrace( System.out );
3705             return false;
3706         }
3707         return true;
3708     }
3709
3710     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
3711         try {
3712             PhylogenyNode n = new PhylogenyNode();
3713             n.setName( "tr|B3RJ64" );
3714             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3715                 return false;
3716             }
3717             n.setName( "tr.B3RJ64" );
3718             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3719                 return false;
3720             }
3721             n.setName( "tr=B3RJ64" );
3722             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3723                 return false;
3724             }
3725             n.setName( "tr-B3RJ64" );
3726             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3727                 return false;
3728             }
3729             n.setName( "tr/B3RJ64" );
3730             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3731                 return false;
3732             }
3733             n.setName( "tr\\B3RJ64" );
3734             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3735                 return false;
3736             }
3737             n.setName( "tr_B3RJ64" );
3738             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3739                 return false;
3740             }
3741             n.setName( " tr|B3RJ64 " );
3742             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3743                 return false;
3744             }
3745             n.setName( "-tr|B3RJ64-" );
3746             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3747                 return false;
3748             }
3749             n.setName( "-tr=B3RJ64-" );
3750             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3751                 return false;
3752             }
3753             n.setName( "_tr=B3RJ64_" );
3754             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3755                 return false;
3756             }
3757             n.setName( " tr_tr|B3RJ64_sp|123 " );
3758             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3759                 return false;
3760             }
3761             n.setName( "B3RJ64" );
3762             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3763                 return false;
3764             }
3765             n.setName( "sp|B3RJ64" );
3766             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3767                 return false;
3768             }
3769             n.setName( "sp|B3RJ64C" );
3770             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
3771                 return false;
3772             }
3773             n.setName( "sp B3RJ64" );
3774             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3775                 return false;
3776             }
3777             n.setName( "sp|B3RJ6X" );
3778             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
3779                 return false;
3780             }
3781             n.setName( "sp|B3RJ6" );
3782             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
3783                 return false;
3784             }
3785             n.setName( "K1PYK7_CRAGI" );
3786             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
3787                 return false;
3788             }
3789             n.setName( "K1PYK7_PEA" );
3790             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
3791                 return false;
3792             }
3793             n.setName( "K1PYK7_RAT" );
3794             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
3795                 return false;
3796             }
3797             n.setName( "K1PYK7_PIG" );
3798             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
3799                 return false;
3800             }
3801             n.setName( "~K1PYK7_PIG~" );
3802             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
3803                 return false;
3804             }
3805             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
3806             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
3807                 return false;
3808             }
3809             n.setName( "K1PYKX_CRAGI" );
3810             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
3811                 return false;
3812             }
3813             n.setName( "XXXXX_CRAGI" );
3814             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
3815                 return false;
3816             }
3817             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
3818             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
3819                 return false;
3820             }
3821             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
3822             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
3823                 return false;
3824             }
3825             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
3826             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
3827                 return false;
3828             }
3829             n = new PhylogenyNode();
3830             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
3831             seq.setSymbol( "K1PYK7_CRAGI" );
3832             n.getNodeData().addSequence( seq );
3833             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
3834                 return false;
3835             }
3836             seq.setSymbol( "tr|B3RJ64" );
3837             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3838                 return false;
3839             }
3840             n = new PhylogenyNode();
3841             seq = new org.forester.phylogeny.data.Sequence();
3842             seq.setName( "K1PYK7_CRAGI" );
3843             n.getNodeData().addSequence( seq );
3844             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
3845                 return false;
3846             }
3847             seq.setName( "tr|B3RJ64" );
3848             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3849                 return false;
3850             }
3851             n = new PhylogenyNode();
3852             seq = new org.forester.phylogeny.data.Sequence();
3853             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
3854             n.getNodeData().addSequence( seq );
3855             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
3856                 return false;
3857             }
3858             n = new PhylogenyNode();
3859             seq = new org.forester.phylogeny.data.Sequence();
3860             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
3861             n.getNodeData().addSequence( seq );
3862             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3863                 return false;
3864             }
3865             //
3866             n = new PhylogenyNode();
3867             n.setName( "ACP19736" );
3868             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
3869                 return false;
3870             }
3871             n = new PhylogenyNode();
3872             n.setName( "|ACP19736|" );
3873             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
3874                 return false;
3875             }
3876         }
3877         catch ( final Exception e ) {
3878             e.printStackTrace( System.out );
3879             return false;
3880         }
3881         return true;
3882     }
3883
3884     private static boolean testFastaParser() {
3885         try {
3886             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
3887                 return false;
3888             }
3889             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
3890                 return false;
3891             }
3892             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
3893             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
3894                 return false;
3895             }
3896             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
3897                 return false;
3898             }
3899             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
3900                 return false;
3901             }
3902             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
3903                 return false;
3904             }
3905             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
3906                 return false;
3907             }
3908             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
3909                 return false;
3910             }
3911         }
3912         catch ( final Exception e ) {
3913             e.printStackTrace();
3914             return false;
3915         }
3916         return true;
3917     }
3918
3919     private static boolean testGeneralMsaParser() {
3920         try {
3921             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
3922             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
3923             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
3924             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
3925             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
3926             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
3927             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
3928             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
3929             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
3930                 return false;
3931             }
3932             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
3933                 return false;
3934             }
3935             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
3936                 return false;
3937             }
3938             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
3939                 return false;
3940             }
3941             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
3942                 return false;
3943             }
3944             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
3945                 return false;
3946             }
3947             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
3948                 return false;
3949             }
3950             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
3951                 return false;
3952             }
3953             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
3954                 return false;
3955             }
3956             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
3957                 return false;
3958             }
3959             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
3960                 return false;
3961             }
3962             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
3963                 return false;
3964             }
3965             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
3966             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
3967                 return false;
3968             }
3969             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
3970                 return false;
3971             }
3972             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
3973                 return false;
3974             }
3975             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
3976             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
3977                 return false;
3978             }
3979             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
3980                 return false;
3981             }
3982             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
3983                 return false;
3984             }
3985             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
3986             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
3987                 return false;
3988             }
3989             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
3990                 return false;
3991             }
3992             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
3993                 return false;
3994             }
3995         }
3996         catch ( final Exception e ) {
3997             e.printStackTrace();
3998             return false;
3999         }
4000         return true;
4001     }
4002
4003     private static boolean testGeneralTable() {
4004         try {
4005             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4006             t0.setValue( 3, 2, "23" );
4007             t0.setValue( 10, 1, "error" );
4008             t0.setValue( 10, 1, "110" );
4009             t0.setValue( 9, 1, "19" );
4010             t0.setValue( 1, 10, "101" );
4011             t0.setValue( 10, 10, "1010" );
4012             t0.setValue( 100, 10, "10100" );
4013             t0.setValue( 0, 0, "00" );
4014             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4015                 return false;
4016             }
4017             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4018                 return false;
4019             }
4020             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4021                 return false;
4022             }
4023             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4024                 return false;
4025             }
4026             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4027                 return false;
4028             }
4029             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4030                 return false;
4031             }
4032             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4033                 return false;
4034             }
4035             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4036                 return false;
4037             }
4038             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4039                 return false;
4040             }
4041             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4042             t1.setValue( "3", "2", "23" );
4043             t1.setValue( "10", "1", "error" );
4044             t1.setValue( "10", "1", "110" );
4045             t1.setValue( "9", "1", "19" );
4046             t1.setValue( "1", "10", "101" );
4047             t1.setValue( "10", "10", "1010" );
4048             t1.setValue( "100", "10", "10100" );
4049             t1.setValue( "0", "0", "00" );
4050             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4051             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4052                 return false;
4053             }
4054             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4055                 return false;
4056             }
4057             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4058                 return false;
4059             }
4060             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4061                 return false;
4062             }
4063             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4064                 return false;
4065             }
4066             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4067                 return false;
4068             }
4069             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4070                 return false;
4071             }
4072             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4073                 return false;
4074             }
4075             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4076                 return false;
4077             }
4078             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4079                 return false;
4080             }
4081         }
4082         catch ( final Exception e ) {
4083             e.printStackTrace( System.out );
4084             return false;
4085         }
4086         return true;
4087     }
4088
4089     private static boolean testGetDistance() {
4090         try {
4091             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4092             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",
4093                                                  new NHXParser() )[ 0 ];
4094             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4095                 return false;
4096             }
4097             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4098                 return false;
4099             }
4100             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
4101                 return false;
4102             }
4103             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
4104                 return false;
4105             }
4106             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
4107                 return false;
4108             }
4109             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
4110                 return false;
4111             }
4112             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
4113                 return false;
4114             }
4115             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
4116                 return false;
4117             }
4118             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
4119                 return false;
4120             }
4121             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
4122                 return false;
4123             }
4124             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
4125                 return false;
4126             }
4127             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
4128                 return false;
4129             }
4130             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
4131                 return false;
4132             }
4133             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
4134                 return false;
4135             }
4136             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
4137                 return false;
4138             }
4139             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
4140                 return false;
4141             }
4142             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
4143                 return false;
4144             }
4145             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
4146                 return false;
4147             }
4148             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
4149                 return false;
4150             }
4151             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
4152                 return false;
4153             }
4154             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
4155                 return false;
4156             }
4157             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
4158                 return false;
4159             }
4160             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
4161                 return false;
4162             }
4163             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
4164                 return false;
4165             }
4166             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
4167                 return false;
4168             }
4169             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
4170                 return false;
4171             }
4172             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
4173                 return false;
4174             }
4175             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
4176                 return false;
4177             }
4178             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
4179                 return false;
4180             }
4181             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
4182                 return false;
4183             }
4184             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
4185                 return false;
4186             }
4187             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",
4188                                                  new NHXParser() )[ 0 ];
4189             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
4190                 return false;
4191             }
4192             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
4193                 return false;
4194             }
4195             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
4196                 return false;
4197             }
4198             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
4199                 return false;
4200             }
4201             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
4202                 return false;
4203             }
4204             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
4205                 return false;
4206             }
4207             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
4208                 return false;
4209             }
4210             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
4211                 return false;
4212             }
4213             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
4214                 return false;
4215             }
4216             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
4217                 return false;
4218             }
4219             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
4220                 return false;
4221             }
4222         }
4223         catch ( final Exception e ) {
4224             e.printStackTrace( System.out );
4225             return false;
4226         }
4227         return true;
4228     }
4229
4230     private static boolean testGetLCA() {
4231         try {
4232             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4233             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4234                                                  new NHXParser() )[ 0 ];
4235             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
4236             if ( !A.getName().equals( "A" ) ) {
4237                 return false;
4238             }
4239             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
4240             if ( !gh.getName().equals( "gh" ) ) {
4241                 return false;
4242             }
4243             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
4244             if ( !ab.getName().equals( "ab" ) ) {
4245                 return false;
4246             }
4247             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
4248             if ( !ab2.getName().equals( "ab" ) ) {
4249                 return false;
4250             }
4251             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
4252             if ( !gh2.getName().equals( "gh" ) ) {
4253                 return false;
4254             }
4255             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
4256             if ( !gh3.getName().equals( "gh" ) ) {
4257                 return false;
4258             }
4259             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
4260             if ( !abc.getName().equals( "abc" ) ) {
4261                 return false;
4262             }
4263             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
4264             if ( !abc2.getName().equals( "abc" ) ) {
4265                 return false;
4266             }
4267             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
4268             if ( !abcd.getName().equals( "abcd" ) ) {
4269                 return false;
4270             }
4271             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
4272             if ( !abcd2.getName().equals( "abcd" ) ) {
4273                 return false;
4274             }
4275             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
4276             if ( !abcdef.getName().equals( "abcdef" ) ) {
4277                 return false;
4278             }
4279             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
4280             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4281                 return false;
4282             }
4283             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
4284             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4285                 return false;
4286             }
4287             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
4288             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4289                 return false;
4290             }
4291             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
4292             if ( !abcde.getName().equals( "abcde" ) ) {
4293                 return false;
4294             }
4295             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
4296             if ( !abcde2.getName().equals( "abcde" ) ) {
4297                 return false;
4298             }
4299             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
4300             if ( !r.getName().equals( "abcdefgh" ) ) {
4301                 return false;
4302             }
4303             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
4304             if ( !r2.getName().equals( "abcdefgh" ) ) {
4305                 return false;
4306             }
4307             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
4308             if ( !r3.getName().equals( "abcdefgh" ) ) {
4309                 return false;
4310             }
4311             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
4312             if ( !abcde3.getName().equals( "abcde" ) ) {
4313                 return false;
4314             }
4315             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
4316             if ( !abcde4.getName().equals( "abcde" ) ) {
4317                 return false;
4318             }
4319             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
4320             if ( !ab3.getName().equals( "ab" ) ) {
4321                 return false;
4322             }
4323             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
4324             if ( !ab4.getName().equals( "ab" ) ) {
4325                 return false;
4326             }
4327             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4328             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
4329             if ( !cd.getName().equals( "cd" ) ) {
4330                 return false;
4331             }
4332             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
4333             if ( !cd2.getName().equals( "cd" ) ) {
4334                 return false;
4335             }
4336             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
4337             if ( !cde.getName().equals( "cde" ) ) {
4338                 return false;
4339             }
4340             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
4341             if ( !cde2.getName().equals( "cde" ) ) {
4342                 return false;
4343             }
4344             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
4345             if ( !cdef.getName().equals( "cdef" ) ) {
4346                 return false;
4347             }
4348             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
4349             if ( !cdef2.getName().equals( "cdef" ) ) {
4350                 return false;
4351             }
4352             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
4353             if ( !cdef3.getName().equals( "cdef" ) ) {
4354                 return false;
4355             }
4356             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
4357             if ( !rt.getName().equals( "r" ) ) {
4358                 return false;
4359             }
4360             final Phylogeny p3 = factory
4361                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4362                              new NHXParser() )[ 0 ];
4363             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
4364             if ( !bc_3.getName().equals( "bc" ) ) {
4365                 return false;
4366             }
4367             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
4368             if ( !ac_3.getName().equals( "abc" ) ) {
4369                 return false;
4370             }
4371             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
4372             if ( !ad_3.getName().equals( "abcde" ) ) {
4373                 return false;
4374             }
4375             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
4376             if ( !af_3.getName().equals( "abcdef" ) ) {
4377                 return false;
4378             }
4379             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
4380             if ( !ag_3.getName().equals( "" ) ) {
4381                 return false;
4382             }
4383             if ( !ag_3.isRoot() ) {
4384                 return false;
4385             }
4386             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
4387             if ( !al_3.getName().equals( "" ) ) {
4388                 return false;
4389             }
4390             if ( !al_3.isRoot() ) {
4391                 return false;
4392             }
4393             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
4394             if ( !kl_3.getName().equals( "" ) ) {
4395                 return false;
4396             }
4397             if ( !kl_3.isRoot() ) {
4398                 return false;
4399             }
4400             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
4401             if ( !fl_3.getName().equals( "" ) ) {
4402                 return false;
4403             }
4404             if ( !fl_3.isRoot() ) {
4405                 return false;
4406             }
4407             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
4408             if ( !gk_3.getName().equals( "ghijk" ) ) {
4409                 return false;
4410             }
4411             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4412             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
4413             if ( !r_4.getName().equals( "r" ) ) {
4414                 return false;
4415             }
4416             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4417             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
4418             if ( !r_5.getName().equals( "root" ) ) {
4419                 return false;
4420             }
4421             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4422             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
4423             if ( !r_6.getName().equals( "rot" ) ) {
4424                 return false;
4425             }
4426             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4427             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
4428             if ( !r_7.getName().equals( "rott" ) ) {
4429                 return false;
4430             }
4431         }
4432         catch ( final Exception e ) {
4433             e.printStackTrace( System.out );
4434             return false;
4435         }
4436         return true;
4437     }
4438
4439     private static boolean testGetLCA2() {
4440         try {
4441             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4442             final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
4443             PhylogenyMethods.preOrderReId( p_a );
4444             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
4445                                                                                               p_a.getNode( "a" ) );
4446             if ( !p_a_1.getName().equals( "a" ) ) {
4447                 return false;
4448             }
4449             final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4450             PhylogenyMethods.preOrderReId( p_b );
4451             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
4452                                                                                               p_b.getNode( "a" ) );
4453             if ( !p_b_1.getName().equals( "b" ) ) {
4454                 return false;
4455             }
4456             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
4457                                                                                               p_b.getNode( "b" ) );
4458             if ( !p_b_2.getName().equals( "b" ) ) {
4459                 return false;
4460             }
4461             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
4462             PhylogenyMethods.preOrderReId( p_c );
4463             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
4464                                                                                               p_c.getNode( "a" ) );
4465             if ( !p_c_1.getName().equals( "b" ) ) {
4466                 return false;
4467             }
4468             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4469                                                                                               p_c.getNode( "c" ) );
4470             if ( !p_c_2.getName().equals( "c" ) ) {
4471                 System.out.println( p_c_2.getName() );
4472                 System.exit( -1 );
4473                 return false;
4474             }
4475             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4476                                                                                               p_c.getNode( "b" ) );
4477             if ( !p_c_3.getName().equals( "b" ) ) {
4478                 return false;
4479             }
4480             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
4481                                                                                               p_c.getNode( "a" ) );
4482             if ( !p_c_4.getName().equals( "c" ) ) {
4483                 return false;
4484             }
4485             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4486                                                  new NHXParser() )[ 0 ];
4487             PhylogenyMethods.preOrderReId( p1 );
4488             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4489                                                                                           p1.getNode( "A" ) );
4490             if ( !A.getName().equals( "A" ) ) {
4491                 return false;
4492             }
4493             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
4494                                                                                            p1.getNode( "gh" ) );
4495             if ( !gh.getName().equals( "gh" ) ) {
4496                 return false;
4497             }
4498             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4499                                                                                            p1.getNode( "B" ) );
4500             if ( !ab.getName().equals( "ab" ) ) {
4501                 return false;
4502             }
4503             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4504                                                                                             p1.getNode( "A" ) );
4505             if ( !ab2.getName().equals( "ab" ) ) {
4506                 return false;
4507             }
4508             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4509                                                                                             p1.getNode( "G" ) );
4510             if ( !gh2.getName().equals( "gh" ) ) {
4511                 return false;
4512             }
4513             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
4514                                                                                             p1.getNode( "H" ) );
4515             if ( !gh3.getName().equals( "gh" ) ) {
4516                 return false;
4517             }
4518             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
4519                                                                                             p1.getNode( "A" ) );
4520             if ( !abc.getName().equals( "abc" ) ) {
4521                 return false;
4522             }
4523             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4524                                                                                              p1.getNode( "C" ) );
4525             if ( !abc2.getName().equals( "abc" ) ) {
4526                 return false;
4527             }
4528             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4529                                                                                              p1.getNode( "D" ) );
4530             if ( !abcd.getName().equals( "abcd" ) ) {
4531                 return false;
4532             }
4533             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
4534                                                                                               p1.getNode( "A" ) );
4535             if ( !abcd2.getName().equals( "abcd" ) ) {
4536                 return false;
4537             }
4538             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4539                                                                                                p1.getNode( "F" ) );
4540             if ( !abcdef.getName().equals( "abcdef" ) ) {
4541                 return false;
4542             }
4543             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4544                                                                                                 p1.getNode( "A" ) );
4545             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4546                 return false;
4547             }
4548             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4549                                                                                                 p1.getNode( "F" ) );
4550             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4551                 return false;
4552             }
4553             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4554                                                                                                 p1.getNode( "ab" ) );
4555             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4556                 return false;
4557             }
4558             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4559                                                                                               p1.getNode( "E" ) );
4560             if ( !abcde.getName().equals( "abcde" ) ) {
4561                 return false;
4562             }
4563             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4564                                                                                                p1.getNode( "A" ) );
4565             if ( !abcde2.getName().equals( "abcde" ) ) {
4566                 return false;
4567             }
4568             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
4569                                                                                           p1.getNode( "abcdefgh" ) );
4570             if ( !r.getName().equals( "abcdefgh" ) ) {
4571                 return false;
4572             }
4573             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4574                                                                                            p1.getNode( "H" ) );
4575             if ( !r2.getName().equals( "abcdefgh" ) ) {
4576                 return false;
4577             }
4578             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4579                                                                                            p1.getNode( "A" ) );
4580             if ( !r3.getName().equals( "abcdefgh" ) ) {
4581                 return false;
4582             }
4583             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4584                                                                                                p1.getNode( "abcde" ) );
4585             if ( !abcde3.getName().equals( "abcde" ) ) {
4586                 return false;
4587             }
4588             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
4589                                                                                                p1.getNode( "E" ) );
4590             if ( !abcde4.getName().equals( "abcde" ) ) {
4591                 return false;
4592             }
4593             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4594                                                                                             p1.getNode( "B" ) );
4595             if ( !ab3.getName().equals( "ab" ) ) {
4596                 return false;
4597             }
4598             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4599                                                                                             p1.getNode( "ab" ) );
4600             if ( !ab4.getName().equals( "ab" ) ) {
4601                 return false;
4602             }
4603             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4604             PhylogenyMethods.preOrderReId( p2 );
4605             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4606                                                                                            p2.getNode( "d" ) );
4607             if ( !cd.getName().equals( "cd" ) ) {
4608                 return false;
4609             }
4610             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4611                                                                                             p2.getNode( "c" ) );
4612             if ( !cd2.getName().equals( "cd" ) ) {
4613                 return false;
4614             }
4615             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4616                                                                                             p2.getNode( "e" ) );
4617             if ( !cde.getName().equals( "cde" ) ) {
4618                 return false;
4619             }
4620             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
4621                                                                                              p2.getNode( "c" ) );
4622             if ( !cde2.getName().equals( "cde" ) ) {
4623                 return false;
4624             }
4625             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4626                                                                                              p2.getNode( "f" ) );
4627             if ( !cdef.getName().equals( "cdef" ) ) {
4628                 return false;
4629             }
4630             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4631                                                                                               p2.getNode( "f" ) );
4632             if ( !cdef2.getName().equals( "cdef" ) ) {
4633                 return false;
4634             }
4635             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
4636                                                                                               p2.getNode( "d" ) );
4637             if ( !cdef3.getName().equals( "cdef" ) ) {
4638                 return false;
4639             }
4640             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4641                                                                                            p2.getNode( "a" ) );
4642             if ( !rt.getName().equals( "r" ) ) {
4643                 return false;
4644             }
4645             final Phylogeny p3 = factory
4646                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4647                              new NHXParser() )[ 0 ];
4648             PhylogenyMethods.preOrderReId( p3 );
4649             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
4650                                                                                              p3.getNode( "c" ) );
4651             if ( !bc_3.getName().equals( "bc" ) ) {
4652                 return false;
4653             }
4654             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4655                                                                                              p3.getNode( "c" ) );
4656             if ( !ac_3.getName().equals( "abc" ) ) {
4657                 return false;
4658             }
4659             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4660                                                                                              p3.getNode( "d" ) );
4661             if ( !ad_3.getName().equals( "abcde" ) ) {
4662                 return false;
4663             }
4664             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4665                                                                                              p3.getNode( "f" ) );
4666             if ( !af_3.getName().equals( "abcdef" ) ) {
4667                 return false;
4668             }
4669             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4670                                                                                              p3.getNode( "g" ) );
4671             if ( !ag_3.getName().equals( "" ) ) {
4672                 return false;
4673             }
4674             if ( !ag_3.isRoot() ) {
4675                 return false;
4676             }
4677             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4678                                                                                              p3.getNode( "l" ) );
4679             if ( !al_3.getName().equals( "" ) ) {
4680                 return false;
4681             }
4682             if ( !al_3.isRoot() ) {
4683                 return false;
4684             }
4685             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
4686                                                                                              p3.getNode( "l" ) );
4687             if ( !kl_3.getName().equals( "" ) ) {
4688                 return false;
4689             }
4690             if ( !kl_3.isRoot() ) {
4691                 return false;
4692             }
4693             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
4694                                                                                              p3.getNode( "l" ) );
4695             if ( !fl_3.getName().equals( "" ) ) {
4696                 return false;
4697             }
4698             if ( !fl_3.isRoot() ) {
4699                 return false;
4700             }
4701             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
4702                                                                                              p3.getNode( "k" ) );
4703             if ( !gk_3.getName().equals( "ghijk" ) ) {
4704                 return false;
4705             }
4706             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4707             PhylogenyMethods.preOrderReId( p4 );
4708             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
4709                                                                                             p4.getNode( "c" ) );
4710             if ( !r_4.getName().equals( "r" ) ) {
4711                 return false;
4712             }
4713             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4714             PhylogenyMethods.preOrderReId( p5 );
4715             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
4716                                                                                             p5.getNode( "c" ) );
4717             if ( !r_5.getName().equals( "root" ) ) {
4718                 return false;
4719             }
4720             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4721             PhylogenyMethods.preOrderReId( p6 );
4722             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
4723                                                                                             p6.getNode( "a" ) );
4724             if ( !r_6.getName().equals( "rot" ) ) {
4725                 return false;
4726             }
4727             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4728             PhylogenyMethods.preOrderReId( p7 );
4729             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
4730                                                                                             p7.getNode( "e" ) );
4731             if ( !r_7.getName().equals( "rott" ) ) {
4732                 return false;
4733             }
4734             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4735                                                                                              p7.getNode( "a" ) );
4736             if ( !r_71.getName().equals( "rott" ) ) {
4737                 return false;
4738             }
4739             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4740                                                                                              p7.getNode( "rott" ) );
4741             if ( !r_72.getName().equals( "rott" ) ) {
4742                 return false;
4743             }
4744             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4745                                                                                              p7.getNode( "a" ) );
4746             if ( !r_73.getName().equals( "rott" ) ) {
4747                 return false;
4748             }
4749             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4750                                                                                              p7.getNode( "rott" ) );
4751             if ( !r_74.getName().equals( "rott" ) ) {
4752                 return false;
4753             }
4754             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4755                                                                                              p7.getNode( "e" ) );
4756             if ( !r_75.getName().equals( "e" ) ) {
4757                 return false;
4758             }
4759         }
4760         catch ( final Exception e ) {
4761             e.printStackTrace( System.out );
4762             return false;
4763         }
4764         return true;
4765     }
4766
4767     private static boolean testHmmscanOutputParser() {
4768         final String test_dir = Test.PATH_TO_TEST_DATA;
4769         try {
4770             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4771                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4772             parser1.parse();
4773             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4774                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4775             final List<Protein> proteins = parser2.parse();
4776             if ( parser2.getProteinsEncountered() != 4 ) {
4777                 return false;
4778             }
4779             if ( proteins.size() != 4 ) {
4780                 return false;
4781             }
4782             if ( parser2.getDomainsEncountered() != 69 ) {
4783                 return false;
4784             }
4785             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4786                 return false;
4787             }
4788             if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4789                 return false;
4790             }
4791             final Protein p1 = proteins.get( 0 );
4792             if ( p1.getNumberOfProteinDomains() != 15 ) {
4793                 return false;
4794             }
4795             if ( p1.getLength() != 850 ) {
4796                 return false;
4797             }
4798             final Protein p2 = proteins.get( 1 );
4799             if ( p2.getNumberOfProteinDomains() != 51 ) {
4800                 return false;
4801             }
4802             if ( p2.getLength() != 1291 ) {
4803                 return false;
4804             }
4805             final Protein p3 = proteins.get( 2 );
4806             if ( p3.getNumberOfProteinDomains() != 2 ) {
4807                 return false;
4808             }
4809             final Protein p4 = proteins.get( 3 );
4810             if ( p4.getNumberOfProteinDomains() != 1 ) {
4811                 return false;
4812             }
4813             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4814                 return false;
4815             }
4816             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4817                 return false;
4818             }
4819             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4820                 return false;
4821             }
4822             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4823                 return false;
4824             }
4825             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4826                 return false;
4827             }
4828             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4829                 return false;
4830             }
4831             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4832                 return false;
4833             }
4834             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4835                 return false;
4836             }
4837             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4838                 return false;
4839             }
4840         }
4841         catch ( final Exception e ) {
4842             e.printStackTrace( System.out );
4843             return false;
4844         }
4845         return true;
4846     }
4847
4848     private static boolean testLastExternalNodeMethods() {
4849         try {
4850             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4851             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
4852             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
4853             final PhylogenyNode n1 = t0.getNode( "A" );
4854             if ( n1.isLastExternalNode() ) {
4855                 return false;
4856             }
4857             final PhylogenyNode n2 = t0.getNode( "B" );
4858             if ( n2.isLastExternalNode() ) {
4859                 return false;
4860             }
4861             final PhylogenyNode n3 = t0.getNode( "C" );
4862             if ( n3.isLastExternalNode() ) {
4863                 return false;
4864             }
4865             final PhylogenyNode n4 = t0.getNode( "D" );
4866             if ( !n4.isLastExternalNode() ) {
4867                 return false;
4868             }
4869         }
4870         catch ( final Exception e ) {
4871             e.printStackTrace( System.out );
4872             return false;
4873         }
4874         return true;
4875     }
4876
4877     private static boolean testLevelOrderIterator() {
4878         try {
4879             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4880             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
4881             PhylogenyNodeIterator it0;
4882             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
4883                 it0.next();
4884             }
4885             for( it0.reset(); it0.hasNext(); ) {
4886                 it0.next();
4887             }
4888             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
4889             if ( !it.next().getName().equals( "r" ) ) {
4890                 return false;
4891             }
4892             if ( !it.next().getName().equals( "ab" ) ) {
4893                 return false;
4894             }
4895             if ( !it.next().getName().equals( "cd" ) ) {
4896                 return false;
4897             }
4898             if ( !it.next().getName().equals( "A" ) ) {
4899                 return false;
4900             }
4901             if ( !it.next().getName().equals( "B" ) ) {
4902                 return false;
4903             }
4904             if ( !it.next().getName().equals( "C" ) ) {
4905                 return false;
4906             }
4907             if ( !it.next().getName().equals( "D" ) ) {
4908                 return false;
4909             }
4910             if ( it.hasNext() ) {
4911                 return false;
4912             }
4913             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",
4914                                                  new NHXParser() )[ 0 ];
4915             PhylogenyNodeIterator it2;
4916             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
4917                 it2.next();
4918             }
4919             for( it2.reset(); it2.hasNext(); ) {
4920                 it2.next();
4921             }
4922             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
4923             if ( !it3.next().getName().equals( "r" ) ) {
4924                 return false;
4925             }
4926             if ( !it3.next().getName().equals( "abc" ) ) {
4927                 return false;
4928             }
4929             if ( !it3.next().getName().equals( "defg" ) ) {
4930                 return false;
4931             }
4932             if ( !it3.next().getName().equals( "A" ) ) {
4933                 return false;
4934             }
4935             if ( !it3.next().getName().equals( "B" ) ) {
4936                 return false;
4937             }
4938             if ( !it3.next().getName().equals( "C" ) ) {
4939                 return false;
4940             }
4941             if ( !it3.next().getName().equals( "D" ) ) {
4942                 return false;
4943             }
4944             if ( !it3.next().getName().equals( "E" ) ) {
4945                 return false;
4946             }
4947             if ( !it3.next().getName().equals( "F" ) ) {
4948                 return false;
4949             }
4950             if ( !it3.next().getName().equals( "G" ) ) {
4951                 return false;
4952             }
4953             if ( !it3.next().getName().equals( "1" ) ) {
4954                 return false;
4955             }
4956             if ( !it3.next().getName().equals( "2" ) ) {
4957                 return false;
4958             }
4959             if ( !it3.next().getName().equals( "3" ) ) {
4960                 return false;
4961             }
4962             if ( !it3.next().getName().equals( "4" ) ) {
4963                 return false;
4964             }
4965             if ( !it3.next().getName().equals( "5" ) ) {
4966                 return false;
4967             }
4968             if ( !it3.next().getName().equals( "6" ) ) {
4969                 return false;
4970             }
4971             if ( !it3.next().getName().equals( "f1" ) ) {
4972                 return false;
4973             }
4974             if ( !it3.next().getName().equals( "f2" ) ) {
4975                 return false;
4976             }
4977             if ( !it3.next().getName().equals( "f3" ) ) {
4978                 return false;
4979             }
4980             if ( !it3.next().getName().equals( "a" ) ) {
4981                 return false;
4982             }
4983             if ( !it3.next().getName().equals( "b" ) ) {
4984                 return false;
4985             }
4986             if ( !it3.next().getName().equals( "f21" ) ) {
4987                 return false;
4988             }
4989             if ( !it3.next().getName().equals( "X" ) ) {
4990                 return false;
4991             }
4992             if ( !it3.next().getName().equals( "Y" ) ) {
4993                 return false;
4994             }
4995             if ( !it3.next().getName().equals( "Z" ) ) {
4996                 return false;
4997             }
4998             if ( it3.hasNext() ) {
4999                 return false;
5000             }
5001             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5002             PhylogenyNodeIterator it4;
5003             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5004                 it4.next();
5005             }
5006             for( it4.reset(); it4.hasNext(); ) {
5007                 it4.next();
5008             }
5009             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5010             if ( !it5.next().getName().equals( "r" ) ) {
5011                 return false;
5012             }
5013             if ( !it5.next().getName().equals( "A" ) ) {
5014                 return false;
5015             }
5016             if ( !it5.next().getName().equals( "B" ) ) {
5017                 return false;
5018             }
5019             if ( !it5.next().getName().equals( "C" ) ) {
5020                 return false;
5021             }
5022             if ( !it5.next().getName().equals( "D" ) ) {
5023                 return false;
5024             }
5025             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5026             PhylogenyNodeIterator it6;
5027             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5028                 it6.next();
5029             }
5030             for( it6.reset(); it6.hasNext(); ) {
5031                 it6.next();
5032             }
5033             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5034             if ( !it7.next().getName().equals( "A" ) ) {
5035                 return false;
5036             }
5037             if ( it.hasNext() ) {
5038                 return false;
5039             }
5040         }
5041         catch ( final Exception e ) {
5042             e.printStackTrace( System.out );
5043             return false;
5044         }
5045         return true;
5046     }
5047
5048     private static boolean testMafft( final String path ) {
5049         try {
5050             final List<String> opts = new ArrayList<String>();
5051             opts.add( "--maxiterate" );
5052             opts.add( "1000" );
5053             opts.add( "--localpair" );
5054             opts.add( "--quiet" );
5055             Msa msa = null;
5056             final MsaInferrer mafft = Mafft.createInstance( path );
5057             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5058             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5059                 return false;
5060             }
5061             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5062                 return false;
5063             }
5064         }
5065         catch ( final Exception e ) {
5066             e.printStackTrace( System.out );
5067             return false;
5068         }
5069         return true;
5070     }
5071
5072     private static boolean testMidpointrooting() {
5073         try {
5074             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5075             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5076             PhylogenyMethods.midpointRoot( t0 );
5077             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5078                 return false;
5079             }
5080             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5081                 return false;
5082             }
5083             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5084                            1 ) ) {
5085                 return false;
5086             }
5087             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",
5088                                                  new NHXParser() )[ 0 ];
5089             if ( !t1.isRooted() ) {
5090                 return false;
5091             }
5092             PhylogenyMethods.midpointRoot( t1 );
5093             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5094                 return false;
5095             }
5096             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5097                 return false;
5098             }
5099             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5100                 return false;
5101             }
5102             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5103                 return false;
5104             }
5105             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5106                 return false;
5107             }
5108             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5109                 return false;
5110             }
5111             t1.reRoot( t1.getNode( "A" ) );
5112             PhylogenyMethods.midpointRoot( t1 );
5113             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5114                 return false;
5115             }
5116             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5117                 return false;
5118             }
5119             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5120                 return false;
5121             }
5122             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5123                 return false;
5124             }
5125             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5126                 System.exit( -1 );
5127                 return false;
5128             }
5129             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5130                 return false;
5131             }
5132         }
5133         catch ( final Exception e ) {
5134             e.printStackTrace( System.out );
5135             return false;
5136         }
5137         return true;
5138     }
5139
5140     private static boolean testMsaQualityMethod() {
5141         try {
5142             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
5143             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
5144             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
5145             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
5146             final List<Sequence> l = new ArrayList<Sequence>();
5147             l.add( s0 );
5148             l.add( s1 );
5149             l.add( s2 );
5150             l.add( s3 );
5151             final Msa msa = BasicMsa.createInstance( l );
5152             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
5153                 return false;
5154             }
5155             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
5156                 return false;
5157             }
5158             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
5159                 return false;
5160             }
5161             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
5162                 return false;
5163             }
5164         }
5165         catch ( final Exception e ) {
5166             e.printStackTrace( System.out );
5167             return false;
5168         }
5169         return true;
5170     }
5171
5172     private static boolean testNextNodeWithCollapsing() {
5173         try {
5174             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5175             PhylogenyNode n;
5176             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
5177             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5178             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
5179             t0.getNode( "cd" ).setCollapse( true );
5180             t0.getNode( "cde" ).setCollapse( true );
5181             n = t0.getFirstExternalNode();
5182             while ( n != null ) {
5183                 ext.add( n );
5184                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5185             }
5186             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5187                 return false;
5188             }
5189             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5190                 return false;
5191             }
5192             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
5193                 return false;
5194             }
5195             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
5196                 return false;
5197             }
5198             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
5199                 return false;
5200             }
5201             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
5202                 return false;
5203             }
5204             ext.clear();
5205             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5206             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
5207             t1.getNode( "ab" ).setCollapse( true );
5208             t1.getNode( "cd" ).setCollapse( true );
5209             t1.getNode( "cde" ).setCollapse( true );
5210             n = t1.getNode( "ab" );
5211             ext = new ArrayList<PhylogenyNode>();
5212             while ( n != null ) {
5213                 ext.add( n );
5214                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5215             }
5216             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5217                 return false;
5218             }
5219             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5220                 return false;
5221             }
5222             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5223                 return false;
5224             }
5225             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
5226                 return false;
5227             }
5228             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
5229                 return false;
5230             }
5231             //
5232             //
5233             ext.clear();
5234             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5235             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
5236             t2.getNode( "ab" ).setCollapse( true );
5237             t2.getNode( "cd" ).setCollapse( true );
5238             t2.getNode( "cde" ).setCollapse( true );
5239             t2.getNode( "c" ).setCollapse( true );
5240             t2.getNode( "d" ).setCollapse( true );
5241             t2.getNode( "e" ).setCollapse( true );
5242             t2.getNode( "gh" ).setCollapse( true );
5243             n = t2.getNode( "ab" );
5244             ext = new ArrayList<PhylogenyNode>();
5245             while ( n != null ) {
5246                 ext.add( n );
5247                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5248             }
5249             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5250                 return false;
5251             }
5252             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5253                 return false;
5254             }
5255             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5256                 return false;
5257             }
5258             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
5259                 return false;
5260             }
5261             //
5262             //
5263             ext.clear();
5264             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5265             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
5266             t3.getNode( "ab" ).setCollapse( true );
5267             t3.getNode( "cd" ).setCollapse( true );
5268             t3.getNode( "cde" ).setCollapse( true );
5269             t3.getNode( "c" ).setCollapse( true );
5270             t3.getNode( "d" ).setCollapse( true );
5271             t3.getNode( "e" ).setCollapse( true );
5272             t3.getNode( "gh" ).setCollapse( true );
5273             t3.getNode( "fgh" ).setCollapse( true );
5274             n = t3.getNode( "ab" );
5275             ext = new ArrayList<PhylogenyNode>();
5276             while ( n != null ) {
5277                 ext.add( n );
5278                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5279             }
5280             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5281                 return false;
5282             }
5283             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5284                 return false;
5285             }
5286             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
5287                 return false;
5288             }
5289             //
5290             //
5291             ext.clear();
5292             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5293             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
5294             t4.getNode( "ab" ).setCollapse( true );
5295             t4.getNode( "cd" ).setCollapse( true );
5296             t4.getNode( "cde" ).setCollapse( true );
5297             t4.getNode( "c" ).setCollapse( true );
5298             t4.getNode( "d" ).setCollapse( true );
5299             t4.getNode( "e" ).setCollapse( true );
5300             t4.getNode( "gh" ).setCollapse( true );
5301             t4.getNode( "fgh" ).setCollapse( true );
5302             t4.getNode( "abcdefgh" ).setCollapse( true );
5303             n = t4.getNode( "abcdefgh" );
5304             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
5305                 return false;
5306             }
5307             //
5308             //
5309             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5310             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
5311             ext.clear();
5312             n = t5.getFirstExternalNode();
5313             while ( n != null ) {
5314                 ext.add( n );
5315                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5316             }
5317             if ( ext.size() != 8 ) {
5318                 return false;
5319             }
5320             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5321                 return false;
5322             }
5323             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5324                 return false;
5325             }
5326             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5327                 return false;
5328             }
5329             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5330                 return false;
5331             }
5332             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5333                 return false;
5334             }
5335             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5336                 return false;
5337             }
5338             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
5339                 return false;
5340             }
5341             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
5342                 return false;
5343             }
5344             //
5345             //
5346             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5347             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
5348             ext.clear();
5349             t6.getNode( "ab" ).setCollapse( true );
5350             n = t6.getNode( "ab" );
5351             while ( n != null ) {
5352                 ext.add( n );
5353                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5354             }
5355             if ( ext.size() != 7 ) {
5356                 return false;
5357             }
5358             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5359                 return false;
5360             }
5361             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5362                 return false;
5363             }
5364             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5365                 return false;
5366             }
5367             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5368                 return false;
5369             }
5370             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5371                 return false;
5372             }
5373             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5374                 return false;
5375             }
5376             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5377                 return false;
5378             }
5379             //
5380             //
5381             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5382             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
5383             ext.clear();
5384             t7.getNode( "cd" ).setCollapse( true );
5385             n = t7.getNode( "a" );
5386             while ( n != null ) {
5387                 ext.add( n );
5388                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5389             }
5390             if ( ext.size() != 7 ) {
5391                 return false;
5392             }
5393             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5394                 return false;
5395             }
5396             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5397                 return false;
5398             }
5399             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5400                 return false;
5401             }
5402             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5403                 return false;
5404             }
5405             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5406                 return false;
5407             }
5408             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5409                 return false;
5410             }
5411             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5412                 return false;
5413             }
5414             //
5415             //
5416             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5417             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
5418             ext.clear();
5419             t8.getNode( "cd" ).setCollapse( true );
5420             t8.getNode( "c" ).setCollapse( true );
5421             t8.getNode( "d" ).setCollapse( true );
5422             n = t8.getNode( "a" );
5423             while ( n != null ) {
5424                 ext.add( n );
5425                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5426             }
5427             if ( ext.size() != 7 ) {
5428                 return false;
5429             }
5430             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5431                 return false;
5432             }
5433             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5434                 return false;
5435             }
5436             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5437                 System.out.println( "2 fail" );
5438                 return false;
5439             }
5440             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5441                 return false;
5442             }
5443             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5444                 return false;
5445             }
5446             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5447                 return false;
5448             }
5449             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5450                 return false;
5451             }
5452             //
5453             //
5454             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5455             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
5456             ext.clear();
5457             t9.getNode( "gh" ).setCollapse( true );
5458             n = t9.getNode( "a" );
5459             while ( n != null ) {
5460                 ext.add( n );
5461                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5462             }
5463             if ( ext.size() != 7 ) {
5464                 return false;
5465             }
5466             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5467                 return false;
5468             }
5469             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5470                 return false;
5471             }
5472             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5473                 return false;
5474             }
5475             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5476                 return false;
5477             }
5478             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5479                 return false;
5480             }
5481             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5482                 return false;
5483             }
5484             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5485                 return false;
5486             }
5487             //
5488             //
5489             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5490             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
5491             ext.clear();
5492             t10.getNode( "gh" ).setCollapse( true );
5493             t10.getNode( "g" ).setCollapse( true );
5494             t10.getNode( "h" ).setCollapse( true );
5495             n = t10.getNode( "a" );
5496             while ( n != null ) {
5497                 ext.add( n );
5498                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5499             }
5500             if ( ext.size() != 7 ) {
5501                 return false;
5502             }
5503             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5504                 return false;
5505             }
5506             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5507                 return false;
5508             }
5509             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5510                 return false;
5511             }
5512             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5513                 return false;
5514             }
5515             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5516                 return false;
5517             }
5518             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5519                 return false;
5520             }
5521             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5522                 return false;
5523             }
5524             //
5525             //
5526             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5527             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
5528             ext.clear();
5529             t11.getNode( "gh" ).setCollapse( true );
5530             t11.getNode( "fgh" ).setCollapse( true );
5531             n = t11.getNode( "a" );
5532             while ( n != null ) {
5533                 ext.add( n );
5534                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5535             }
5536             if ( ext.size() != 6 ) {
5537                 return false;
5538             }
5539             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5540                 return false;
5541             }
5542             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5543                 return false;
5544             }
5545             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5546                 return false;
5547             }
5548             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5549                 return false;
5550             }
5551             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5552                 return false;
5553             }
5554             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5555                 return false;
5556             }
5557             //
5558             //
5559             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5560             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
5561             ext.clear();
5562             t12.getNode( "gh" ).setCollapse( true );
5563             t12.getNode( "fgh" ).setCollapse( true );
5564             t12.getNode( "g" ).setCollapse( true );
5565             t12.getNode( "h" ).setCollapse( true );
5566             t12.getNode( "f" ).setCollapse( true );
5567             n = t12.getNode( "a" );
5568             while ( n != null ) {
5569                 ext.add( n );
5570                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5571             }
5572             if ( ext.size() != 6 ) {
5573                 return false;
5574             }
5575             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5576                 return false;
5577             }
5578             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5579                 return false;
5580             }
5581             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5582                 return false;
5583             }
5584             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5585                 return false;
5586             }
5587             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5588                 return false;
5589             }
5590             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5591                 return false;
5592             }
5593             //
5594             //
5595             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5596             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
5597             ext.clear();
5598             t13.getNode( "ab" ).setCollapse( true );
5599             t13.getNode( "b" ).setCollapse( true );
5600             t13.getNode( "fgh" ).setCollapse( true );
5601             t13.getNode( "gh" ).setCollapse( true );
5602             n = t13.getNode( "ab" );
5603             while ( n != null ) {
5604                 ext.add( n );
5605                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5606             }
5607             if ( ext.size() != 5 ) {
5608                 return false;
5609             }
5610             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5611                 return false;
5612             }
5613             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5614                 return false;
5615             }
5616             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5617                 return false;
5618             }
5619             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5620                 return false;
5621             }
5622             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
5623                 return false;
5624             }
5625             //
5626             //
5627             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
5628             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
5629             ext.clear();
5630             t14.getNode( "ab" ).setCollapse( true );
5631             t14.getNode( "a" ).setCollapse( true );
5632             t14.getNode( "fgh" ).setCollapse( true );
5633             t14.getNode( "gh" ).setCollapse( true );
5634             n = t14.getNode( "ab" );
5635             while ( n != null ) {
5636                 ext.add( n );
5637                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5638             }
5639             if ( ext.size() != 5 ) {
5640                 return false;
5641             }
5642             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5643                 return false;
5644             }
5645             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5646                 return false;
5647             }
5648             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5649                 return false;
5650             }
5651             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5652                 return false;
5653             }
5654             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
5655                 return false;
5656             }
5657             //
5658             //
5659             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" );
5660             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
5661             ext.clear();
5662             t15.getNode( "ab" ).setCollapse( true );
5663             t15.getNode( "a" ).setCollapse( true );
5664             t15.getNode( "fgh" ).setCollapse( true );
5665             t15.getNode( "gh" ).setCollapse( true );
5666             n = t15.getNode( "ab" );
5667             while ( n != null ) {
5668                 ext.add( n );
5669                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5670             }
5671             if ( ext.size() != 6 ) {
5672                 return false;
5673             }
5674             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5675                 return false;
5676             }
5677             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5678                 return false;
5679             }
5680             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5681                 return false;
5682             }
5683             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5684                 return false;
5685             }
5686             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
5687                 return false;
5688             }
5689             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5690                 return false;
5691             }
5692             //
5693             //
5694             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" );
5695             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
5696             ext.clear();
5697             t16.getNode( "ab" ).setCollapse( true );
5698             t16.getNode( "a" ).setCollapse( true );
5699             t16.getNode( "fgh" ).setCollapse( true );
5700             t16.getNode( "gh" ).setCollapse( true );
5701             t16.getNode( "cd" ).setCollapse( true );
5702             t16.getNode( "cde" ).setCollapse( true );
5703             t16.getNode( "d" ).setCollapse( true );
5704             t16.getNode( "x" ).setCollapse( true );
5705             n = t16.getNode( "ab" );
5706             while ( n != null ) {
5707                 ext.add( n );
5708                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5709             }
5710             if ( ext.size() != 4 ) {
5711                 return false;
5712             }
5713             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5714                 return false;
5715             }
5716             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5717                 return false;
5718             }
5719             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
5720                 return false;
5721             }
5722             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
5723                 return false;
5724             }
5725         }
5726         catch ( final Exception e ) {
5727             e.printStackTrace( System.out );
5728             return false;
5729         }
5730         return true;
5731     }
5732
5733     private static boolean testNexusCharactersParsing() {
5734         try {
5735             final NexusCharactersParser parser = new NexusCharactersParser();
5736             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
5737             parser.parse();
5738             String[] labels = parser.getCharStateLabels();
5739             if ( labels.length != 7 ) {
5740                 return false;
5741             }
5742             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5743                 return false;
5744             }
5745             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5746                 return false;
5747             }
5748             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5749                 return false;
5750             }
5751             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5752                 return false;
5753             }
5754             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5755                 return false;
5756             }
5757             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5758                 return false;
5759             }
5760             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5761                 return false;
5762             }
5763             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
5764             parser.parse();
5765             labels = parser.getCharStateLabels();
5766             if ( labels.length != 7 ) {
5767                 return false;
5768             }
5769             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5770                 return false;
5771             }
5772             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5773                 return false;
5774             }
5775             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5776                 return false;
5777             }
5778             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5779                 return false;
5780             }
5781             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5782                 return false;
5783             }
5784             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5785                 return false;
5786             }
5787             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5788                 return false;
5789             }
5790         }
5791         catch ( final Exception e ) {
5792             e.printStackTrace( System.out );
5793             return false;
5794         }
5795         return true;
5796     }
5797
5798     private static boolean testNexusMatrixParsing() {
5799         try {
5800             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
5801             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
5802             parser.parse();
5803             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
5804             if ( m.getNumberOfCharacters() != 9 ) {
5805                 return false;
5806             }
5807             if ( m.getNumberOfIdentifiers() != 5 ) {
5808                 return false;
5809             }
5810             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
5811                 return false;
5812             }
5813             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
5814                 return false;
5815             }
5816             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
5817                 return false;
5818             }
5819             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
5820                 return false;
5821             }
5822             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
5823                 return false;
5824             }
5825             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
5826                 return false;
5827             }
5828             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
5829                 return false;
5830             }
5831             //            if ( labels.length != 7 ) {
5832             //                return false;
5833             //            }
5834             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5835             //                return false;
5836             //            }
5837             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5838             //                return false;
5839             //            }
5840             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5841             //                return false;
5842             //            }
5843             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5844             //                return false;
5845             //            }
5846             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5847             //                return false;
5848             //            }
5849             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5850             //                return false;
5851             //            }
5852             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5853             //                return false;
5854             //            }
5855             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
5856             //            parser.parse();
5857             //            labels = parser.getCharStateLabels();
5858             //            if ( labels.length != 7 ) {
5859             //                return false;
5860             //            }
5861             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5862             //                return false;
5863             //            }
5864             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5865             //                return false;
5866             //            }
5867             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5868             //                return false;
5869             //            }
5870             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5871             //                return false;
5872             //            }
5873             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5874             //                return false;
5875             //            }
5876             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5877             //                return false;
5878             //            }
5879             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5880             //                return false;
5881             //            }
5882         }
5883         catch ( final Exception e ) {
5884             e.printStackTrace( System.out );
5885             return false;
5886         }
5887         return true;
5888     }
5889
5890     private static boolean testNexusTreeParsing() {
5891         try {
5892             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5893             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
5894             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
5895             if ( phylogenies.length != 1 ) {
5896                 return false;
5897             }
5898             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
5899                 return false;
5900             }
5901             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
5902                 return false;
5903             }
5904             phylogenies = null;
5905             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
5906             if ( phylogenies.length != 1 ) {
5907                 return false;
5908             }
5909             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
5910                 return false;
5911             }
5912             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
5913                 return false;
5914             }
5915             phylogenies = null;
5916             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
5917             if ( phylogenies.length != 1 ) {
5918                 return false;
5919             }
5920             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5921                 return false;
5922             }
5923             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
5924                 return false;
5925             }
5926             if ( phylogenies[ 0 ].isRooted() ) {
5927                 return false;
5928             }
5929             phylogenies = null;
5930             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
5931             if ( phylogenies.length != 18 ) {
5932                 return false;
5933             }
5934             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
5935                 return false;
5936             }
5937             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
5938                 return false;
5939             }
5940             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
5941                 return false;
5942             }
5943             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
5944                 return false;
5945             }
5946             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5947                 return false;
5948             }
5949             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
5950                 return false;
5951             }
5952             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
5953                 return false;
5954             }
5955             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
5956                 return false;
5957             }
5958             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
5959                 return false;
5960             }
5961             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
5962                 return false;
5963             }
5964             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
5965                 return false;
5966             }
5967             if ( phylogenies[ 8 ].isRooted() ) {
5968                 return false;
5969             }
5970             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
5971                 return false;
5972             }
5973             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
5974                 return false;
5975             }
5976             if ( !phylogenies[ 9 ].isRooted() ) {
5977                 return false;
5978             }
5979             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
5980                 return false;
5981             }
5982             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
5983                 return false;
5984             }
5985             if ( !phylogenies[ 10 ].isRooted() ) {
5986                 return false;
5987             }
5988             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
5989                 return false;
5990             }
5991             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
5992                 return false;
5993             }
5994             if ( phylogenies[ 11 ].isRooted() ) {
5995                 return false;
5996             }
5997             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
5998                 return false;
5999             }
6000             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
6001                 return false;
6002             }
6003             if ( !phylogenies[ 12 ].isRooted() ) {
6004                 return false;
6005             }
6006             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
6007                 return false;
6008             }
6009             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
6010                 return false;
6011             }
6012             if ( !phylogenies[ 13 ].isRooted() ) {
6013                 return false;
6014             }
6015             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
6016                 return false;
6017             }
6018             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
6019                 return false;
6020             }
6021             if ( !phylogenies[ 14 ].isRooted() ) {
6022                 return false;
6023             }
6024             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
6025                 return false;
6026             }
6027             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
6028                 return false;
6029             }
6030             if ( phylogenies[ 15 ].isRooted() ) {
6031                 return false;
6032             }
6033             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
6034                 return false;
6035             }
6036             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
6037                 return false;
6038             }
6039             if ( !phylogenies[ 16 ].isRooted() ) {
6040                 return false;
6041             }
6042             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
6043                 return false;
6044             }
6045             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
6046                 return false;
6047             }
6048             if ( phylogenies[ 17 ].isRooted() ) {
6049                 return false;
6050             }
6051             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
6052                 return false;
6053             }
6054         }
6055         catch ( final Exception e ) {
6056             e.printStackTrace( System.out );
6057             return false;
6058         }
6059         return true;
6060     }
6061
6062     private static boolean testNexusTreeParsingIterating() {
6063         try {
6064             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
6065             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
6066             if ( !p.hasNext() ) {
6067                 return false;
6068             }
6069             Phylogeny phy = p.next();
6070             if ( phy == null ) {
6071                 return false;
6072             }
6073             if ( phy.getNumberOfExternalNodes() != 25 ) {
6074                 return false;
6075             }
6076             if ( !phy.getName().equals( "" ) ) {
6077                 return false;
6078             }
6079             if ( p.hasNext() ) {
6080                 return false;
6081             }
6082             phy = p.next();
6083             if ( phy != null ) {
6084                 return false;
6085             }
6086             //
6087             p.reset();
6088             if ( !p.hasNext() ) {
6089                 return false;
6090             }
6091             phy = p.next();
6092             if ( phy == null ) {
6093                 return false;
6094             }
6095             if ( phy.getNumberOfExternalNodes() != 25 ) {
6096                 return false;
6097             }
6098             if ( !phy.getName().equals( "" ) ) {
6099                 return false;
6100             }
6101             if ( p.hasNext() ) {
6102                 return false;
6103             }
6104             phy = p.next();
6105             if ( phy != null ) {
6106                 return false;
6107             }
6108             ////
6109             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
6110             if ( !p.hasNext() ) {
6111                 return false;
6112             }
6113             phy = p.next();
6114             if ( phy == null ) {
6115                 return false;
6116             }
6117             if ( phy.getNumberOfExternalNodes() != 10 ) {
6118                 return false;
6119             }
6120             if ( !phy.getName().equals( "name" ) ) {
6121                 return false;
6122             }
6123             if ( p.hasNext() ) {
6124                 return false;
6125             }
6126             phy = p.next();
6127             if ( phy != null ) {
6128                 return false;
6129             }
6130             //
6131             p.reset();
6132             if ( !p.hasNext() ) {
6133                 return false;
6134             }
6135             phy = p.next();
6136             if ( phy == null ) {
6137                 return false;
6138             }
6139             if ( phy.getNumberOfExternalNodes() != 10 ) {
6140                 return false;
6141             }
6142             if ( !phy.getName().equals( "name" ) ) {
6143                 return false;
6144             }
6145             if ( p.hasNext() ) {
6146                 return false;
6147             }
6148             phy = p.next();
6149             if ( phy != null ) {
6150                 return false;
6151             }
6152             ////
6153             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
6154             if ( !p.hasNext() ) {
6155                 return false;
6156             }
6157             phy = p.next();
6158             if ( phy == null ) {
6159                 return false;
6160             }
6161             if ( phy.getNumberOfExternalNodes() != 3 ) {
6162                 return false;
6163             }
6164             if ( !phy.getName().equals( "" ) ) {
6165                 return false;
6166             }
6167             if ( phy.isRooted() ) {
6168                 return false;
6169             }
6170             if ( p.hasNext() ) {
6171                 return false;
6172             }
6173             phy = p.next();
6174             if ( phy != null ) {
6175                 return false;
6176             }
6177             //
6178             p.reset();
6179             if ( !p.hasNext() ) {
6180                 return false;
6181             }
6182             phy = p.next();
6183             if ( phy == null ) {
6184                 return false;
6185             }
6186             if ( phy.getNumberOfExternalNodes() != 3 ) {
6187                 return false;
6188             }
6189             if ( !phy.getName().equals( "" ) ) {
6190                 return false;
6191             }
6192             if ( p.hasNext() ) {
6193                 return false;
6194             }
6195             phy = p.next();
6196             if ( phy != null ) {
6197                 return false;
6198             }
6199             ////
6200             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
6201             //            if ( phylogenies.length != 18 ) {
6202             //                return false;
6203             //            }
6204             //0
6205             if ( !p.hasNext() ) {
6206                 return false;
6207             }
6208             phy = p.next();
6209             if ( phy == null ) {
6210                 return false;
6211             }
6212             if ( phy.getNumberOfExternalNodes() != 10 ) {
6213                 return false;
6214             }
6215             if ( !phy.getName().equals( "tree 0" ) ) {
6216                 return false;
6217             }
6218             //1
6219             if ( !p.hasNext() ) {
6220                 return false;
6221             }
6222             phy = p.next();
6223             if ( phy == null ) {
6224                 return false;
6225             }
6226             if ( phy.getNumberOfExternalNodes() != 10 ) {
6227                 return false;
6228             }
6229             if ( !phy.getName().equals( "tree 1" ) ) {
6230                 return false;
6231             }
6232             //2
6233             if ( !p.hasNext() ) {
6234                 return false;
6235             }
6236             phy = p.next();
6237             if ( phy == null ) {
6238                 return false;
6239             }
6240             if ( phy.getNumberOfExternalNodes() != 3 ) {
6241                 return false;
6242             }
6243             if ( !phy.getName().equals( "" ) ) {
6244                 return false;
6245             }
6246             if ( phy.isRooted() ) {
6247                 return false;
6248             }
6249             //3
6250             if ( !p.hasNext() ) {
6251                 return false;
6252             }
6253             phy = p.next();
6254             if ( phy == null ) {
6255                 return false;
6256             }
6257             if ( phy.getNumberOfExternalNodes() != 4 ) {
6258                 return false;
6259             }
6260             if ( !phy.getName().equals( "" ) ) {
6261                 return false;
6262             }
6263             if ( !phy.isRooted() ) {
6264                 return false;
6265             }
6266             //4
6267             if ( !p.hasNext() ) {
6268                 return false;
6269             }
6270             phy = p.next();
6271             if ( phy == null ) {
6272                 return false;
6273             }
6274             if ( phy.getNumberOfExternalNodes() != 5 ) {
6275                 System.out.println( phy.getNumberOfExternalNodes() );
6276                 return false;
6277             }
6278             if ( !phy.getName().equals( "" ) ) {
6279                 return false;
6280             }
6281             if ( !phy.isRooted() ) {
6282                 return false;
6283             }
6284             //5
6285             if ( !p.hasNext() ) {
6286                 return false;
6287             }
6288             phy = p.next();
6289             if ( phy == null ) {
6290                 return false;
6291             }
6292             if ( phy.getNumberOfExternalNodes() != 3 ) {
6293                 return false;
6294             }
6295             if ( !phy.getName().equals( "" ) ) {
6296                 return false;
6297             }
6298             if ( phy.isRooted() ) {
6299                 return false;
6300             }
6301             //6
6302             if ( !p.hasNext() ) {
6303                 return false;
6304             }
6305             phy = p.next();
6306             if ( phy == null ) {
6307                 return false;
6308             }
6309             if ( phy.getNumberOfExternalNodes() != 2 ) {
6310                 return false;
6311             }
6312             if ( !phy.getName().equals( "" ) ) {
6313                 return false;
6314             }
6315             if ( !phy.isRooted() ) {
6316                 return false;
6317             }
6318             //7
6319             if ( !p.hasNext() ) {
6320                 return false;
6321             }
6322             phy = p.next();
6323             if ( phy.getNumberOfExternalNodes() != 3 ) {
6324                 return false;
6325             }
6326             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6327                 return false;
6328             }
6329             if ( !phy.isRooted() ) {
6330                 return false;
6331             }
6332             //8
6333             if ( !p.hasNext() ) {
6334                 return false;
6335             }
6336             phy = p.next();
6337             if ( phy.getNumberOfExternalNodes() != 3 ) {
6338                 return false;
6339             }
6340             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
6341                 return false;
6342             }
6343             if ( !phy.getName().equals( "tree 8" ) ) {
6344                 return false;
6345             }
6346             //9
6347             if ( !p.hasNext() ) {
6348                 return false;
6349             }
6350             phy = p.next();
6351             if ( phy.getNumberOfExternalNodes() != 3 ) {
6352                 return false;
6353             }
6354             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
6355                 return false;
6356             }
6357             if ( !phy.getName().equals( "tree 9" ) ) {
6358                 return false;
6359             }
6360             //10
6361             if ( !p.hasNext() ) {
6362                 return false;
6363             }
6364             phy = p.next();
6365             if ( phy.getNumberOfExternalNodes() != 3 ) {
6366                 return false;
6367             }
6368             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6369                 return false;
6370             }
6371             if ( !phy.getName().equals( "tree 10" ) ) {
6372                 return false;
6373             }
6374             if ( !phy.isRooted() ) {
6375                 return false;
6376             }
6377             //11
6378             if ( !p.hasNext() ) {
6379                 return false;
6380             }
6381             phy = p.next();
6382             if ( phy.getNumberOfExternalNodes() != 3 ) {
6383                 return false;
6384             }
6385             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
6386                 return false;
6387             }
6388             if ( !phy.getName().equals( "tree 11" ) ) {
6389                 return false;
6390             }
6391             if ( phy.isRooted() ) {
6392                 return false;
6393             }
6394             //12
6395             if ( !p.hasNext() ) {
6396                 return false;
6397             }
6398             phy = p.next();
6399             if ( phy.getNumberOfExternalNodes() != 3 ) {
6400                 return false;
6401             }
6402             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
6403                 return false;
6404             }
6405             if ( !phy.getName().equals( "tree 12" ) ) {
6406                 return false;
6407             }
6408             if ( !phy.isRooted() ) {
6409                 return false;
6410             }
6411             //13
6412             if ( !p.hasNext() ) {
6413                 return false;
6414             }
6415             phy = p.next();
6416             if ( phy.getNumberOfExternalNodes() != 3 ) {
6417                 return false;
6418             }
6419             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6420                 return false;
6421             }
6422             if ( !phy.getName().equals( "tree 13" ) ) {
6423                 return false;
6424             }
6425             if ( !phy.isRooted() ) {
6426                 return false;
6427             }
6428             //14
6429             if ( !p.hasNext() ) {
6430                 return false;
6431             }
6432             phy = p.next();
6433             if ( phy.getNumberOfExternalNodes() != 10 ) {
6434                 System.out.println( phy.getNumberOfExternalNodes() );
6435                 return false;
6436             }
6437             if ( !phy
6438                     .toNewHampshire()
6439                     .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;" ) ) {
6440                 System.out.println( phy.toNewHampshire() );
6441                 return false;
6442             }
6443             if ( !phy.getName().equals( "tree 14" ) ) {
6444                 return false;
6445             }
6446             if ( !phy.isRooted() ) {
6447                 return false;
6448             }
6449             //15
6450             if ( !p.hasNext() ) {
6451                 return false;
6452             }
6453             phy = p.next();
6454             if ( phy.getNumberOfExternalNodes() != 10 ) {
6455                 System.out.println( phy.getNumberOfExternalNodes() );
6456                 return false;
6457             }
6458             if ( !phy
6459                     .toNewHampshire()
6460                     .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;" ) ) {
6461                 System.out.println( phy.toNewHampshire() );
6462                 return false;
6463             }
6464             if ( !phy.getName().equals( "tree 15" ) ) {
6465                 return false;
6466             }
6467             if ( phy.isRooted() ) {
6468                 return false;
6469             }
6470             //16
6471             if ( !p.hasNext() ) {
6472                 return false;
6473             }
6474             phy = p.next();
6475             if ( phy.getNumberOfExternalNodes() != 10 ) {
6476                 System.out.println( phy.getNumberOfExternalNodes() );
6477                 return false;
6478             }
6479             if ( !phy
6480                     .toNewHampshire()
6481                     .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;" ) ) {
6482                 System.out.println( phy.toNewHampshire() );
6483                 return false;
6484             }
6485             if ( !phy.getName().equals( "tree 16" ) ) {
6486                 return false;
6487             }
6488             if ( !phy.isRooted() ) {
6489                 return false;
6490             }
6491             //17
6492             if ( !p.hasNext() ) {
6493                 return false;
6494             }
6495             phy = p.next();
6496             if ( phy.getNumberOfExternalNodes() != 10 ) {
6497                 System.out.println( phy.getNumberOfExternalNodes() );
6498                 return false;
6499             }
6500             if ( !phy
6501                     .toNewHampshire()
6502                     .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;" ) ) {
6503                 System.out.println( phy.toNewHampshire() );
6504                 return false;
6505             }
6506             if ( !phy.getName().equals( "tree 17" ) ) {
6507                 return false;
6508             }
6509             if ( phy.isRooted() ) {
6510                 return false;
6511             }
6512             //
6513             if ( p.hasNext() ) {
6514                 return false;
6515             }
6516             phy = p.next();
6517             if ( phy != null ) {
6518                 return false;
6519             }
6520             p.reset();
6521             //0
6522             if ( !p.hasNext() ) {
6523                 return false;
6524             }
6525             phy = p.next();
6526             if ( phy == null ) {
6527                 return false;
6528             }
6529             if ( phy.getNumberOfExternalNodes() != 10 ) {
6530                 return false;
6531             }
6532             if ( !phy.getName().equals( "tree 0" ) ) {
6533                 return false;
6534             }
6535             //1
6536             if ( !p.hasNext() ) {
6537                 return false;
6538             }
6539             phy = p.next();
6540             if ( phy == null ) {
6541                 return false;
6542             }
6543             if ( phy.getNumberOfExternalNodes() != 10 ) {
6544                 return false;
6545             }
6546             if ( !phy.getName().equals( "tree 1" ) ) {
6547                 return false;
6548             }
6549             //2
6550             if ( !p.hasNext() ) {
6551                 return false;
6552             }
6553             phy = p.next();
6554             if ( phy == null ) {
6555                 return false;
6556             }
6557             if ( phy.getNumberOfExternalNodes() != 3 ) {
6558                 return false;
6559             }
6560             if ( !phy.getName().equals( "" ) ) {
6561                 return false;
6562             }
6563             if ( phy.isRooted() ) {
6564                 return false;
6565             }
6566             //3
6567             if ( !p.hasNext() ) {
6568                 return false;
6569             }
6570             phy = p.next();
6571             if ( phy == null ) {
6572                 return false;
6573             }
6574             if ( phy.getNumberOfExternalNodes() != 4 ) {
6575                 return false;
6576             }
6577             if ( !phy.getName().equals( "" ) ) {
6578                 return false;
6579             }
6580             if ( !phy.isRooted() ) {
6581                 return false;
6582             }
6583             //4
6584             if ( !p.hasNext() ) {
6585                 return false;
6586             }
6587             phy = p.next();
6588             if ( phy == null ) {
6589                 return false;
6590             }
6591             if ( phy.getNumberOfExternalNodes() != 5 ) {
6592                 System.out.println( phy.getNumberOfExternalNodes() );
6593                 return false;
6594             }
6595             if ( !phy.getName().equals( "" ) ) {
6596                 return false;
6597             }
6598             if ( !phy.isRooted() ) {
6599                 return false;
6600             }
6601             //5
6602             if ( !p.hasNext() ) {
6603                 return false;
6604             }
6605             phy = p.next();
6606             if ( phy == null ) {
6607                 return false;
6608             }
6609             if ( phy.getNumberOfExternalNodes() != 3 ) {
6610                 return false;
6611             }
6612             if ( !phy.getName().equals( "" ) ) {
6613                 return false;
6614             }
6615             if ( phy.isRooted() ) {
6616                 return false;
6617             }
6618         }
6619         catch ( final Exception e ) {
6620             e.printStackTrace( System.out );
6621             return false;
6622         }
6623         return true;
6624     }
6625
6626     private static boolean testNexusTreeParsingTranslating() {
6627         try {
6628             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6629             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6630             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
6631             if ( phylogenies.length != 1 ) {
6632                 return false;
6633             }
6634             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6635                 return false;
6636             }
6637             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6638                 return false;
6639             }
6640             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6641                 return false;
6642             }
6643             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6644                 return false;
6645             }
6646             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6647                     .equals( "Aranaeus" ) ) {
6648                 return false;
6649             }
6650             phylogenies = null;
6651             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
6652             if ( phylogenies.length != 3 ) {
6653                 return false;
6654             }
6655             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6656                 return false;
6657             }
6658             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6659                 return false;
6660             }
6661             if ( phylogenies[ 0 ].isRooted() ) {
6662                 return false;
6663             }
6664             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6665                 return false;
6666             }
6667             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6668                 return false;
6669             }
6670             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6671                     .equals( "Aranaeus" ) ) {
6672                 return false;
6673             }
6674             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
6675                 return false;
6676             }
6677             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
6678                 return false;
6679             }
6680             if ( phylogenies[ 1 ].isRooted() ) {
6681                 return false;
6682             }
6683             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6684                 return false;
6685             }
6686             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6687                 return false;
6688             }
6689             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6690                     .equals( "Aranaeus" ) ) {
6691                 return false;
6692             }
6693             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6694                 return false;
6695             }
6696             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
6697                 return false;
6698             }
6699             if ( !phylogenies[ 2 ].isRooted() ) {
6700                 return false;
6701             }
6702             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6703                 return false;
6704             }
6705             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6706                 return false;
6707             }
6708             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6709                     .equals( "Aranaeus" ) ) {
6710                 return false;
6711             }
6712             phylogenies = null;
6713             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
6714             if ( phylogenies.length != 3 ) {
6715                 return false;
6716             }
6717             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6718                 return false;
6719             }
6720             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6721                 return false;
6722             }
6723             if ( phylogenies[ 0 ].isRooted() ) {
6724                 return false;
6725             }
6726             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6727                 return false;
6728             }
6729             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6730                 return false;
6731             }
6732             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6733                     .equals( "Aranaeus" ) ) {
6734                 return false;
6735             }
6736             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
6737                 return false;
6738             }
6739             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
6740                 return false;
6741             }
6742             if ( phylogenies[ 1 ].isRooted() ) {
6743                 return false;
6744             }
6745             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6746                 return false;
6747             }
6748             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6749                 return false;
6750             }
6751             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6752                     .equals( "Aranaeus" ) ) {
6753                 return false;
6754             }
6755             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6756                 return false;
6757             }
6758             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
6759                 return false;
6760             }
6761             if ( !phylogenies[ 2 ].isRooted() ) {
6762                 return false;
6763             }
6764             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6765                 return false;
6766             }
6767             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6768                 return false;
6769             }
6770             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6771                     .equals( "Aranaeus" ) ) {
6772                 return false;
6773             }
6774         }
6775         catch ( final Exception e ) {
6776             e.printStackTrace( System.out );
6777             return false;
6778         }
6779         return true;
6780     }
6781
6782     private static boolean testNHParsing() {
6783         try {
6784             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6785             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
6786             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
6787                 return false;
6788             }
6789             final NHXParser nhxp = new NHXParser();
6790             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
6791             nhxp.setReplaceUnderscores( true );
6792             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
6793             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
6794                 return false;
6795             }
6796             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
6797                 return false;
6798             }
6799             final Phylogeny p1b = factory
6800                     .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 ",
6801                              new NHXParser() )[ 0 ];
6802             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
6803                 return false;
6804             }
6805             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
6806                 return false;
6807             }
6808             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
6809             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
6810             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
6811             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
6812             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
6813             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
6814             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
6815             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
6816             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
6817             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
6818             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
6819                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
6820                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
6821                                                     new NHXParser() );
6822             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
6823                 return false;
6824             }
6825             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
6826                 return false;
6827             }
6828             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
6829                 return false;
6830             }
6831             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
6832                 return false;
6833             }
6834             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
6835             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
6836             final String p16_S = "((A,B),C)";
6837             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
6838             if ( p16.length != 1 ) {
6839                 return false;
6840             }
6841             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
6842                 return false;
6843             }
6844             final String p17_S = "(C,(A,B))";
6845             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
6846             if ( p17.length != 1 ) {
6847                 return false;
6848             }
6849             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
6850                 return false;
6851             }
6852             final String p18_S = "((A,B),(C,D))";
6853             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
6854             if ( p18.length != 1 ) {
6855                 return false;
6856             }
6857             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
6858                 return false;
6859             }
6860             final String p19_S = "(((A,B),C),D)";
6861             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
6862             if ( p19.length != 1 ) {
6863                 return false;
6864             }
6865             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
6866                 return false;
6867             }
6868             final String p20_S = "(A,(B,(C,D)))";
6869             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
6870             if ( p20.length != 1 ) {
6871                 return false;
6872             }
6873             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
6874                 return false;
6875             }
6876             final String p21_S = "(A,(B,(C,(D,E))))";
6877             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
6878             if ( p21.length != 1 ) {
6879                 return false;
6880             }
6881             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
6882                 return false;
6883             }
6884             final String p22_S = "((((A,B),C),D),E)";
6885             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
6886             if ( p22.length != 1 ) {
6887                 return false;
6888             }
6889             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
6890                 return false;
6891             }
6892             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6893             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
6894             if ( p23.length != 1 ) {
6895                 System.out.println( "xl=" + p23.length );
6896                 System.exit( -1 );
6897                 return false;
6898             }
6899             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
6900                 return false;
6901             }
6902             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6903             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
6904             if ( p24.length != 1 ) {
6905                 return false;
6906             }
6907             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
6908                 return false;
6909             }
6910             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6911             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6912             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
6913             if ( p241.length != 2 ) {
6914                 return false;
6915             }
6916             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
6917                 return false;
6918             }
6919             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
6920                 return false;
6921             }
6922             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
6923                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
6924                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
6925                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
6926                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
6927                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
6928                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
6929                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
6930             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
6931             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
6932                 return false;
6933             }
6934             final String p26_S = "(A,B)ab";
6935             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
6936             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
6937                 return false;
6938             }
6939             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6940             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
6941             if ( p27s.length != 1 ) {
6942                 System.out.println( "xxl=" + p27s.length );
6943                 System.exit( -1 );
6944                 return false;
6945             }
6946             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
6947                 System.out.println( p27s[ 0 ].toNewHampshireX() );
6948                 System.exit( -1 );
6949                 return false;
6950             }
6951             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
6952                                                     new NHXParser() );
6953             if ( p27.length != 1 ) {
6954                 System.out.println( "yl=" + p27.length );
6955                 System.exit( -1 );
6956                 return false;
6957             }
6958             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
6959                 System.out.println( p27[ 0 ].toNewHampshireX() );
6960                 System.exit( -1 );
6961                 return false;
6962             }
6963             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6964             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6965             final String p28_S3 = "(A,B)ab";
6966             final String p28_S4 = "((((A,B),C),D),;E;)";
6967             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
6968                                                     new NHXParser() );
6969             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
6970                 return false;
6971             }
6972             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
6973                 return false;
6974             }
6975             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
6976                 return false;
6977             }
6978             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
6979                 return false;
6980             }
6981             if ( p28.length != 4 ) {
6982                 return false;
6983             }
6984             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";
6985             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
6986             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
6987                 return false;
6988             }
6989             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";
6990             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
6991             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
6992                 return false;
6993             }
6994             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
6995             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
6996             if ( ( p32.length != 0 ) ) {
6997                 return false;
6998             }
6999             final String p33_S = "A";
7000             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
7001             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
7002                 return false;
7003             }
7004             final String p34_S = "B;";
7005             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
7006             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
7007                 return false;
7008             }
7009             final String p35_S = "B:0.2";
7010             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
7011             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
7012                 return false;
7013             }
7014             final String p36_S = "(A)";
7015             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
7016             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
7017                 return false;
7018             }
7019             final String p37_S = "((A))";
7020             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
7021             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
7022                 return false;
7023             }
7024             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7025             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
7026             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
7027                 return false;
7028             }
7029             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7030             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
7031             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
7032                 return false;
7033             }
7034             final String p40_S = "(A,B,C)";
7035             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
7036             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
7037                 return false;
7038             }
7039             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
7040             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
7041             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
7042                 return false;
7043             }
7044             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
7045             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
7046             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
7047                 return false;
7048             }
7049             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)";
7050             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
7051             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
7052                 return false;
7053             }
7054             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)))";
7055             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
7056             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
7057                 return false;
7058             }
7059             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
7060             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
7061             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
7062                 return false;
7063             }
7064             final String p46_S = "";
7065             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
7066             if ( p46.length != 0 ) {
7067                 return false;
7068             }
7069             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
7070             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7071                 return false;
7072             }
7073             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7074             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7075                 return false;
7076             }
7077             final Phylogeny p49 = factory
7078                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
7079                              new NHXParser() )[ 0 ];
7080             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7081                 return false;
7082             }
7083             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7084             if ( p50.getNode( "A" ) == null ) {
7085                 return false;
7086             }
7087             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7088                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
7089                 return false;
7090             }
7091             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
7092                 return false;
7093             }
7094             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
7095                     .equals( "((A,B)88:2.0,C);" ) ) {
7096                 return false;
7097             }
7098             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7099             if ( p51.getNode( "A(A" ) == null ) {
7100                 return false;
7101             }
7102             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7103             if ( p52.getNode( "A(A" ) == null ) {
7104                 return false;
7105             }
7106             final Phylogeny p53 = factory
7107                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
7108                              new NHXParser() )[ 0 ];
7109             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
7110                 return false;
7111             }
7112             // 
7113             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
7114             if ( p54.getNode( "A" ) == null ) {
7115                 return false;
7116             }
7117             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7118                     .equals( "((A,B)[88],C);" ) ) {
7119                 return false;
7120             }
7121         }
7122         catch ( final Exception e ) {
7123             e.printStackTrace( System.out );
7124             return false;
7125         }
7126         return true;
7127     }
7128
7129     private static boolean testNHParsingIter() {
7130         try {
7131             final String p0_str = "(A,B);";
7132             final NHXParser p = new NHXParser();
7133             p.setSource( p0_str );
7134             if ( !p.hasNext() ) {
7135                 return false;
7136             }
7137             final Phylogeny p0 = p.next();
7138             if ( !p0.toNewHampshire().equals( p0_str ) ) {
7139                 System.out.println( p0.toNewHampshire() );
7140                 return false;
7141             }
7142             if ( p.hasNext() ) {
7143                 return false;
7144             }
7145             if ( p.next() != null ) {
7146                 return false;
7147             }
7148             //
7149             final String p00_str = "(A,B)root;";
7150             p.setSource( p00_str );
7151             final Phylogeny p00 = p.next();
7152             if ( !p00.toNewHampshire().equals( p00_str ) ) {
7153                 System.out.println( p00.toNewHampshire() );
7154                 return false;
7155             }
7156             //
7157             final String p000_str = "A;";
7158             p.setSource( p000_str );
7159             final Phylogeny p000 = p.next();
7160             if ( !p000.toNewHampshire().equals( p000_str ) ) {
7161                 System.out.println( p000.toNewHampshire() );
7162                 return false;
7163             }
7164             //
7165             final String p0000_str = "A";
7166             p.setSource( p0000_str );
7167             final Phylogeny p0000 = p.next();
7168             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
7169                 System.out.println( p0000.toNewHampshire() );
7170                 return false;
7171             }
7172             //
7173             p.setSource( "(A)" );
7174             final Phylogeny p00000 = p.next();
7175             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
7176                 System.out.println( p00000.toNewHampshire() );
7177                 return false;
7178             }
7179             //
7180             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
7181             p.setSource( p1_str );
7182             if ( !p.hasNext() ) {
7183                 return false;
7184             }
7185             final Phylogeny p1_0 = p.next();
7186             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
7187                 System.out.println( p1_0.toNewHampshire() );
7188                 return false;
7189             }
7190             if ( !p.hasNext() ) {
7191                 return false;
7192             }
7193             final Phylogeny p1_1 = p.next();
7194             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
7195                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
7196                 return false;
7197             }
7198             if ( !p.hasNext() ) {
7199                 return false;
7200             }
7201             final Phylogeny p1_2 = p.next();
7202             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
7203                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
7204                 return false;
7205             }
7206             if ( !p.hasNext() ) {
7207                 return false;
7208             }
7209             final Phylogeny p1_3 = p.next();
7210             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
7211                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
7212                 return false;
7213             }
7214             if ( p.hasNext() ) {
7215                 return false;
7216             }
7217             if ( p.next() != null ) {
7218                 return false;
7219             }
7220             //
7221             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
7222             p.setSource( p2_str );
7223             if ( !p.hasNext() ) {
7224                 return false;
7225             }
7226             Phylogeny p2_0 = p.next();
7227             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7228                 System.out.println( p2_0.toNewHampshire() );
7229                 return false;
7230             }
7231             if ( !p.hasNext() ) {
7232                 return false;
7233             }
7234             Phylogeny p2_1 = p.next();
7235             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7236                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7237                 return false;
7238             }
7239             if ( !p.hasNext() ) {
7240                 return false;
7241             }
7242             Phylogeny p2_2 = p.next();
7243             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7244                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7245                 return false;
7246             }
7247             if ( !p.hasNext() ) {
7248                 return false;
7249             }
7250             Phylogeny p2_3 = p.next();
7251             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7252                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7253                 return false;
7254             }
7255             if ( !p.hasNext() ) {
7256                 return false;
7257             }
7258             Phylogeny p2_4 = p.next();
7259             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7260                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7261                 return false;
7262             }
7263             if ( p.hasNext() ) {
7264                 return false;
7265             }
7266             if ( p.next() != null ) {
7267                 return false;
7268             }
7269             ////
7270             p.reset();
7271             if ( !p.hasNext() ) {
7272                 return false;
7273             }
7274             p2_0 = p.next();
7275             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7276                 System.out.println( p2_0.toNewHampshire() );
7277                 return false;
7278             }
7279             if ( !p.hasNext() ) {
7280                 return false;
7281             }
7282             p2_1 = p.next();
7283             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7284                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7285                 return false;
7286             }
7287             if ( !p.hasNext() ) {
7288                 return false;
7289             }
7290             p2_2 = p.next();
7291             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7292                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7293                 return false;
7294             }
7295             if ( !p.hasNext() ) {
7296                 return false;
7297             }
7298             p2_3 = p.next();
7299             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7300                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7301                 return false;
7302             }
7303             if ( !p.hasNext() ) {
7304                 return false;
7305             }
7306             p2_4 = p.next();
7307             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7308                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7309                 return false;
7310             }
7311             if ( p.hasNext() ) {
7312                 return false;
7313             }
7314             if ( p.next() != null ) {
7315                 return false;
7316             }
7317             //
7318             final String p3_str = "((A,B),C)abc";
7319             p.setSource( p3_str );
7320             if ( !p.hasNext() ) {
7321                 return false;
7322             }
7323             final Phylogeny p3_0 = p.next();
7324             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
7325                 return false;
7326             }
7327             if ( p.hasNext() ) {
7328                 return false;
7329             }
7330             if ( p.next() != null ) {
7331                 return false;
7332             }
7333             //
7334             final String p4_str = "((A,B)ab,C)abc";
7335             p.setSource( p4_str );
7336             if ( !p.hasNext() ) {
7337                 return false;
7338             }
7339             final Phylogeny p4_0 = p.next();
7340             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
7341                 return false;
7342             }
7343             if ( p.hasNext() ) {
7344                 return false;
7345             }
7346             if ( p.next() != null ) {
7347                 return false;
7348             }
7349             //
7350             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
7351             p.setSource( p5_str );
7352             if ( !p.hasNext() ) {
7353                 return false;
7354             }
7355             final Phylogeny p5_0 = p.next();
7356             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
7357                 return false;
7358             }
7359             if ( p.hasNext() ) {
7360                 return false;
7361             }
7362             if ( p.next() != null ) {
7363                 return false;
7364             }
7365             //
7366             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7367             p.setSource( p6_str );
7368             if ( !p.hasNext() ) {
7369                 return false;
7370             }
7371             Phylogeny p6_0 = p.next();
7372             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7373                 return false;
7374             }
7375             if ( p.hasNext() ) {
7376                 return false;
7377             }
7378             if ( p.next() != null ) {
7379                 return false;
7380             }
7381             p.reset();
7382             if ( !p.hasNext() ) {
7383                 return false;
7384             }
7385             p6_0 = p.next();
7386             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7387                 return false;
7388             }
7389             if ( p.hasNext() ) {
7390                 return false;
7391             }
7392             if ( p.next() != null ) {
7393                 return false;
7394             }
7395             //
7396             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7397             p.setSource( p7_str );
7398             if ( !p.hasNext() ) {
7399                 return false;
7400             }
7401             Phylogeny p7_0 = p.next();
7402             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7403                 return false;
7404             }
7405             if ( p.hasNext() ) {
7406                 return false;
7407             }
7408             if ( p.next() != null ) {
7409                 return false;
7410             }
7411             p.reset();
7412             if ( !p.hasNext() ) {
7413                 return false;
7414             }
7415             p7_0 = p.next();
7416             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7417                 return false;
7418             }
7419             if ( p.hasNext() ) {
7420                 return false;
7421             }
7422             if ( p.next() != null ) {
7423                 return false;
7424             }
7425             //
7426             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
7427             p.setSource( p8_str );
7428             if ( !p.hasNext() ) {
7429                 return false;
7430             }
7431             Phylogeny p8_0 = p.next();
7432             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7433                 return false;
7434             }
7435             if ( !p.hasNext() ) {
7436                 return false;
7437             }
7438             if ( !p.hasNext() ) {
7439                 return false;
7440             }
7441             Phylogeny p8_1 = p.next();
7442             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7443                 return false;
7444             }
7445             if ( p.hasNext() ) {
7446                 return false;
7447             }
7448             if ( p.next() != null ) {
7449                 return false;
7450             }
7451             p.reset();
7452             if ( !p.hasNext() ) {
7453                 return false;
7454             }
7455             p8_0 = p.next();
7456             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7457                 return false;
7458             }
7459             if ( !p.hasNext() ) {
7460                 return false;
7461             }
7462             p8_1 = p.next();
7463             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7464                 return false;
7465             }
7466             if ( p.hasNext() ) {
7467                 return false;
7468             }
7469             if ( p.next() != null ) {
7470                 return false;
7471             }
7472             p.reset();
7473             //
7474             p.setSource( "" );
7475             if ( p.hasNext() ) {
7476                 return false;
7477             }
7478             //
7479             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
7480             if ( !p.hasNext() ) {
7481                 return false;
7482             }
7483             Phylogeny p_27 = p.next();
7484             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7485                 System.out.println( p_27.toNewHampshireX() );
7486                 System.exit( -1 );
7487                 return false;
7488             }
7489             if ( p.hasNext() ) {
7490                 return false;
7491             }
7492             if ( p.next() != null ) {
7493                 return false;
7494             }
7495             p.reset();
7496             if ( !p.hasNext() ) {
7497                 return false;
7498             }
7499             p_27 = p.next();
7500             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7501                 System.out.println( p_27.toNewHampshireX() );
7502                 System.exit( -1 );
7503                 return false;
7504             }
7505             if ( p.hasNext() ) {
7506                 return false;
7507             }
7508             if ( p.next() != null ) {
7509                 return false;
7510             }
7511         }
7512         catch ( final Exception e ) {
7513             e.printStackTrace( System.out );
7514             return false;
7515         }
7516         return true;
7517     }
7518
7519     private static boolean testNHXconversion() {
7520         try {
7521             final PhylogenyNode n1 = new PhylogenyNode();
7522             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7523             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7524             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7525             final PhylogenyNode n5 = PhylogenyNode
7526                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
7527             final PhylogenyNode n6 = PhylogenyNode
7528                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
7529             if ( !n1.toNewHampshireX().equals( "" ) ) {
7530                 return false;
7531             }
7532             if ( !n2.toNewHampshireX().equals( "" ) ) {
7533                 return false;
7534             }
7535             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
7536                 return false;
7537             }
7538             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
7539                 return false;
7540             }
7541             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
7542                 return false;
7543             }
7544             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
7545                 System.out.println( n6.toNewHampshireX() );
7546                 return false;
7547             }
7548         }
7549         catch ( final Exception e ) {
7550             e.printStackTrace( System.out );
7551             return false;
7552         }
7553         return true;
7554     }
7555
7556     private static boolean testNHXNodeParsing() {
7557         try {
7558             final PhylogenyNode n1 = new PhylogenyNode();
7559             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7560             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7561             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7562             final PhylogenyNode n5 = PhylogenyNode
7563                     .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]" );
7564             if ( !n3.getName().equals( "n3" ) ) {
7565                 return false;
7566             }
7567             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7568                 return false;
7569             }
7570             if ( n3.isDuplication() ) {
7571                 return false;
7572             }
7573             if ( n3.isHasAssignedEvent() ) {
7574                 return false;
7575             }
7576             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
7577                 return false;
7578             }
7579             if ( !n4.getName().equals( "n4" ) ) {
7580                 return false;
7581             }
7582             if ( n4.getDistanceToParent() != 0.01 ) {
7583                 return false;
7584             }
7585             if ( !n5.getName().equals( "n5" ) ) {
7586                 return false;
7587             }
7588             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
7589                 return false;
7590             }
7591             if ( n5.getDistanceToParent() != 0.1 ) {
7592                 return false;
7593             }
7594             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
7595                 return false;
7596             }
7597             if ( !n5.isDuplication() ) {
7598                 return false;
7599             }
7600             if ( !n5.isHasAssignedEvent() ) {
7601                 return false;
7602             }
7603             final PhylogenyNode n8 = PhylogenyNode
7604                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
7605                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7606             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7607                 return false;
7608             }
7609             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
7610                 return false;
7611             }
7612             final PhylogenyNode n9 = PhylogenyNode
7613                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
7614                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7615             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
7616                 return false;
7617             }
7618             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
7619                 return false;
7620             }
7621             final PhylogenyNode n10 = PhylogenyNode
7622                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7623             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
7624                 return false;
7625             }
7626             final PhylogenyNode n20 = PhylogenyNode
7627                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7628             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7629                 return false;
7630             }
7631             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
7632                 return false;
7633             }
7634             final PhylogenyNode n20x = PhylogenyNode
7635                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7636             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
7637                 return false;
7638             }
7639             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
7640                 return false;
7641             }
7642             final PhylogenyNode n20xx = PhylogenyNode
7643                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7644             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
7645                 return false;
7646             }
7647             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
7648                 return false;
7649             }
7650             final PhylogenyNode n20xxx = PhylogenyNode
7651                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7652             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
7653                 return false;
7654             }
7655             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
7656                 return false;
7657             }
7658             final PhylogenyNode n20xxxx = PhylogenyNode
7659                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7660             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
7661                 return false;
7662             }
7663             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
7664                 return false;
7665             }
7666             final PhylogenyNode n21 = PhylogenyNode
7667                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7668             if ( !n21.getName().equals( "N21_PIG" ) ) {
7669                 return false;
7670             }
7671             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
7672                 return false;
7673             }
7674             final PhylogenyNode n21x = PhylogenyNode
7675                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7676             if ( !n21x.getName().equals( "n21_PIG" ) ) {
7677                 return false;
7678             }
7679             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
7680                 return false;
7681             }
7682             final PhylogenyNode n22 = PhylogenyNode
7683                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7684             if ( !n22.getName().equals( "n22/PIG" ) ) {
7685                 return false;
7686             }
7687             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
7688                 return false;
7689             }
7690             final PhylogenyNode n23 = PhylogenyNode
7691                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7692             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
7693                 return false;
7694             }
7695             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
7696                 return false;
7697             }
7698             final PhylogenyNode a = PhylogenyNode
7699                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7700             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7701                 return false;
7702             }
7703             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
7704                 return false;
7705             }
7706             final PhylogenyNode c1 = PhylogenyNode
7707                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
7708                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7709             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
7710                 return false;
7711             }
7712             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
7713                 return false;
7714             }
7715             final PhylogenyNode c2 = PhylogenyNode
7716                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
7717                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7718             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
7719                 return false;
7720             }
7721             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
7722                 return false;
7723             }
7724             final PhylogenyNode e3 = PhylogenyNode
7725                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7726             if ( !e3.getName().equals( "n10_RAT~" ) ) {
7727                 return false;
7728             }
7729             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
7730                 return false;
7731             }
7732             final PhylogenyNode n11 = PhylogenyNode
7733                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
7734                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7735             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
7736                 return false;
7737             }
7738             if ( n11.getDistanceToParent() != 0.4 ) {
7739                 return false;
7740             }
7741             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
7742                 return false;
7743             }
7744             final PhylogenyNode n12 = PhylogenyNode
7745                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
7746                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7747             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
7748                 return false;
7749             }
7750             if ( n12.getDistanceToParent() != 0.4 ) {
7751                 return false;
7752             }
7753             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
7754                 return false;
7755             }
7756             final PhylogenyNode o = PhylogenyNode
7757                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7758             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
7759                 return false;
7760             }
7761             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
7762                 return false;
7763             }
7764             if ( n1.getName().compareTo( "" ) != 0 ) {
7765                 return false;
7766             }
7767             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
7768                 return false;
7769             }
7770             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7771                 return false;
7772             }
7773             if ( n2.getName().compareTo( "" ) != 0 ) {
7774                 return false;
7775             }
7776             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
7777                 return false;
7778             }
7779             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7780                 return false;
7781             }
7782             final PhylogenyNode n00 = PhylogenyNode
7783                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
7784             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
7785                 return false;
7786             }
7787             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
7788                 return false;
7789             }
7790             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
7791             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
7792                 return false;
7793             }
7794             final PhylogenyNode n13 = PhylogenyNode
7795                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7796             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
7797                 return false;
7798             }
7799             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
7800                 return false;
7801             }
7802             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
7803                 return false;
7804             }
7805             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7806                 return false;
7807             }
7808             final PhylogenyNode n14 = PhylogenyNode
7809                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7810             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
7811                 return false;
7812             }
7813             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
7814                 return false;
7815             }
7816             final PhylogenyNode n15 = PhylogenyNode
7817                     .createInstanceFromNhxString( "something_wicked[123]",
7818                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7819             if ( !n15.getName().equals( "something_wicked" ) ) {
7820                 return false;
7821             }
7822             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
7823                 return false;
7824             }
7825             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
7826                 return false;
7827             }
7828             final PhylogenyNode n16 = PhylogenyNode
7829                     .createInstanceFromNhxString( "something_wicked2[9]",
7830                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7831             if ( !n16.getName().equals( "something_wicked2" ) ) {
7832                 return false;
7833             }
7834             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
7835                 return false;
7836             }
7837             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
7838                 return false;
7839             }
7840             final PhylogenyNode n17 = PhylogenyNode
7841                     .createInstanceFromNhxString( "something_wicked3[a]",
7842                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7843             if ( !n17.getName().equals( "something_wicked3" ) ) {
7844                 return false;
7845             }
7846             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
7847                 return false;
7848             }
7849             final PhylogenyNode n18 = PhylogenyNode
7850                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7851             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
7852                 return false;
7853             }
7854             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
7855                 return false;
7856             }
7857             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
7858                 return false;
7859             }
7860             final PhylogenyNode n19 = PhylogenyNode
7861                     .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7862             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
7863                 return false;
7864             }
7865             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7866                 return false;
7867             }
7868             final PhylogenyNode n30 = PhylogenyNode
7869                     .createInstanceFromNhxString( "blah_1234567-roejojoej",
7870                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7871             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
7872                 return false;
7873             }
7874             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7875                 return false;
7876             }
7877             final PhylogenyNode n31 = PhylogenyNode
7878                     .createInstanceFromNhxString( "blah_12345678-roejojoej",
7879                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7880             if ( n31.getNodeData().isHasTaxonomy() ) {
7881                 return false;
7882             }
7883             final PhylogenyNode n32 = PhylogenyNode
7884                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7885             if ( n32.getNodeData().isHasTaxonomy() ) {
7886                 return false;
7887             }
7888             final PhylogenyNode n40 = PhylogenyNode
7889                     .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7890             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
7891                 return false;
7892             }
7893             final PhylogenyNode n41 = PhylogenyNode
7894                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7895             if ( n41.getNodeData().isHasTaxonomy() ) {
7896                 return false;
7897             }
7898             final PhylogenyNode n42 = PhylogenyNode
7899                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7900             if ( n42.getNodeData().isHasTaxonomy() ) {
7901                 return false;
7902             }
7903             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
7904                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
7905             if ( n43.getNodeData().isHasTaxonomy() ) {
7906                 return false;
7907             }
7908             final PhylogenyNode n44 = PhylogenyNode
7909                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7910             if ( n44.getNodeData().isHasTaxonomy() ) {
7911                 return false;
7912             }
7913         }
7914         catch ( final Exception e ) {
7915             e.printStackTrace( System.out );
7916             return false;
7917         }
7918         return true;
7919     }
7920
7921     private static boolean testNHXParsing() {
7922         try {
7923             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7924             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
7925             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
7926                 return false;
7927             }
7928             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]";
7929             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
7930             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7931                 return false;
7932             }
7933             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]";
7934             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
7935             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
7936                 return false;
7937             }
7938             final Phylogeny[] p3 = factory
7939                     .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]",
7940                              new NHXParser() );
7941             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7942                 return false;
7943             }
7944             final Phylogeny[] p4 = factory
7945                     .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(]",
7946                              new NHXParser() );
7947             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7948                 return false;
7949             }
7950             final Phylogeny[] p5 = factory
7951                     .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(((]",
7952                              new NHXParser() );
7953             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7954                 return false;
7955             }
7956             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)";
7957             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)";
7958             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
7959             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
7960                 return false;
7961             }
7962             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)))";
7963             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)))";
7964             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
7965             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
7966                 return false;
7967             }
7968             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])   ))[,,, ])))))))";
7969             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
7970             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
7971             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
7972                 return false;
7973             }
7974             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
7975             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
7976                 return false;
7977             }
7978             final Phylogeny p10 = factory
7979                     .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]",
7980                              new NHXParser() )[ 0 ];
7981             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
7982                 return false;
7983             }
7984         }
7985         catch ( final Exception e ) {
7986             e.printStackTrace( System.out );
7987             return false;
7988         }
7989         return true;
7990     }
7991
7992     private static boolean testNHXParsingMB() {
7993         try {
7994             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7995             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
7996                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7997                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
7998                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
7999                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8000                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8001                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8002                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8003                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
8004             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
8005                 return false;
8006             }
8007             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
8008                 return false;
8009             }
8010             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
8011                            0.1100000000000000e+00 ) ) {
8012                 return false;
8013             }
8014             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
8015                 return false;
8016             }
8017             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
8018                 return false;
8019             }
8020             final Phylogeny p2 = factory
8021                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
8022                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8023                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8024                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8025                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8026                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8027                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8028                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8029                                      + "7.369400000000000e-02}])",
8030                              new NHXParser() )[ 0 ];
8031             if ( p2.getNode( "1" ) == null ) {
8032                 return false;
8033             }
8034             if ( p2.getNode( "2" ) == null ) {
8035                 return false;
8036             }
8037         }
8038         catch ( final Exception e ) {
8039             e.printStackTrace( System.out );
8040             System.exit( -1 );
8041             return false;
8042         }
8043         return true;
8044     }
8045
8046     private static boolean testNHXParsingQuotes() {
8047         try {
8048             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8049             final NHXParser p = new NHXParser();
8050             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
8051             if ( phylogenies_0.length != 5 ) {
8052                 return false;
8053             }
8054             final Phylogeny phy = phylogenies_0[ 4 ];
8055             if ( phy.getNumberOfExternalNodes() != 7 ) {
8056                 return false;
8057             }
8058             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
8059                 return false;
8060             }
8061             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
8062                 return false;
8063             }
8064             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
8065                     .getScientificName().equals( "hsapiens" ) ) {
8066                 return false;
8067             }
8068             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
8069                 return false;
8070             }
8071             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
8072                 return false;
8073             }
8074             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
8075                 return false;
8076             }
8077             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
8078                 return false;
8079             }
8080             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
8081                 return false;
8082             }
8083             final NHXParser p1p = new NHXParser();
8084             p1p.setIgnoreQuotes( true );
8085             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
8086             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
8087                 return false;
8088             }
8089             final NHXParser p2p = new NHXParser();
8090             p1p.setIgnoreQuotes( false );
8091             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
8092             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
8093                 return false;
8094             }
8095             final NHXParser p3p = new NHXParser();
8096             p3p.setIgnoreQuotes( false );
8097             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
8098             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
8099                 return false;
8100             }
8101             final NHXParser p4p = new NHXParser();
8102             p4p.setIgnoreQuotes( false );
8103             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
8104             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
8105                 return false;
8106             }
8107             final Phylogeny p10 = factory
8108                     .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]",
8109                              new NHXParser() )[ 0 ];
8110             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]";
8111             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
8112                 return false;
8113             }
8114             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
8115             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
8116                 return false;
8117             }
8118             //
8119             final Phylogeny p12 = factory
8120                     .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]",
8121                              new NHXParser() )[ 0 ];
8122             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]";
8123             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
8124                 return false;
8125             }
8126             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
8127             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
8128                 return false;
8129             }
8130             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;";
8131             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
8132                 return false;
8133             }
8134             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
8135             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
8136                 return false;
8137             }
8138         }
8139         catch ( final Exception e ) {
8140             e.printStackTrace( System.out );
8141             return false;
8142         }
8143         return true;
8144     }
8145
8146     private static boolean testNodeRemoval() {
8147         try {
8148             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8149             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
8150             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
8151             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
8152                 return false;
8153             }
8154             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
8155             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
8156             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
8157                 return false;
8158             }
8159             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
8160             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
8161             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
8162                 return false;
8163             }
8164         }
8165         catch ( final Exception e ) {
8166             e.printStackTrace( System.out );
8167             return false;
8168         }
8169         return true;
8170     }
8171
8172     private static boolean testPhylogenyBranch() {
8173         try {
8174             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
8175             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
8176             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
8177             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
8178             if ( !a1b1.equals( a1b1 ) ) {
8179                 return false;
8180             }
8181             if ( !a1b1.equals( b1a1 ) ) {
8182                 return false;
8183             }
8184             if ( !b1a1.equals( a1b1 ) ) {
8185                 return false;
8186             }
8187             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
8188             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
8189             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
8190             if ( a1_b1.equals( b1_a1 ) ) {
8191                 return false;
8192             }
8193             if ( a1_b1.equals( a1_b1_ ) ) {
8194                 return false;
8195             }
8196             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
8197             if ( !a1_b1.equals( b1_a1_ ) ) {
8198                 return false;
8199             }
8200             if ( a1_b1_.equals( b1_a1_ ) ) {
8201                 return false;
8202             }
8203             if ( !a1_b1_.equals( b1_a1 ) ) {
8204                 return false;
8205             }
8206         }
8207         catch ( final Exception e ) {
8208             e.printStackTrace( System.out );
8209             return false;
8210         }
8211         return true;
8212     }
8213
8214     private static boolean testPhyloXMLparsingOfDistributionElement() {
8215         try {
8216             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8217             PhyloXmlParser xml_parser = null;
8218             try {
8219                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
8220             }
8221             catch ( final Exception e ) {
8222                 // Do nothing -- means were not running from jar.
8223             }
8224             if ( xml_parser == null ) {
8225                 xml_parser = new PhyloXmlParser();
8226                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
8227                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
8228                 }
8229                 else {
8230                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
8231                 }
8232             }
8233             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
8234                                                               xml_parser );
8235             if ( xml_parser.getErrorCount() > 0 ) {
8236                 System.out.println( xml_parser.getErrorMessages().toString() );
8237                 return false;
8238             }
8239             if ( phylogenies_0.length != 1 ) {
8240                 return false;
8241             }
8242             final Phylogeny t1 = phylogenies_0[ 0 ];
8243             PhylogenyNode n = null;
8244             Distribution d = null;
8245             n = t1.getNode( "root node" );
8246             if ( !n.getNodeData().isHasDistribution() ) {
8247                 return false;
8248             }
8249             if ( n.getNodeData().getDistributions().size() != 1 ) {
8250                 return false;
8251             }
8252             d = n.getNodeData().getDistribution();
8253             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8254                 return false;
8255             }
8256             if ( d.getPoints().size() != 1 ) {
8257                 return false;
8258             }
8259             if ( d.getPolygons() != null ) {
8260                 return false;
8261             }
8262             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8263                 return false;
8264             }
8265             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8266                 return false;
8267             }
8268             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8269                 return false;
8270             }
8271             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8272                 return false;
8273             }
8274             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8275                 return false;
8276             }
8277             n = t1.getNode( "node a" );
8278             if ( !n.getNodeData().isHasDistribution() ) {
8279                 return false;
8280             }
8281             if ( n.getNodeData().getDistributions().size() != 2 ) {
8282                 return false;
8283             }
8284             d = n.getNodeData().getDistribution( 1 );
8285             if ( !d.getDesc().equals( "San Diego" ) ) {
8286                 return false;
8287             }
8288             if ( d.getPoints().size() != 1 ) {
8289                 return false;
8290             }
8291             if ( d.getPolygons() != null ) {
8292                 return false;
8293             }
8294             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8295                 return false;
8296             }
8297             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8298                 return false;
8299             }
8300             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8301                 return false;
8302             }
8303             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8304                 return false;
8305             }
8306             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8307                 return false;
8308             }
8309             n = t1.getNode( "node bb" );
8310             if ( !n.getNodeData().isHasDistribution() ) {
8311                 return false;
8312             }
8313             if ( n.getNodeData().getDistributions().size() != 1 ) {
8314                 return false;
8315             }
8316             d = n.getNodeData().getDistribution( 0 );
8317             if ( d.getPoints().size() != 3 ) {
8318                 return false;
8319             }
8320             if ( d.getPolygons().size() != 2 ) {
8321                 return false;
8322             }
8323             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8324                 return false;
8325             }
8326             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8327                 return false;
8328             }
8329             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8330                 return false;
8331             }
8332             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8333                 return false;
8334             }
8335             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8336                 return false;
8337             }
8338             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8339                 return false;
8340             }
8341             Polygon p = d.getPolygons().get( 0 );
8342             if ( p.getPoints().size() != 3 ) {
8343                 return false;
8344             }
8345             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8346                 return false;
8347             }
8348             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8349                 return false;
8350             }
8351             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8352                 return false;
8353             }
8354             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8355                 return false;
8356             }
8357             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8358                 return false;
8359             }
8360             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8361                 return false;
8362             }
8363             p = d.getPolygons().get( 1 );
8364             if ( p.getPoints().size() != 3 ) {
8365                 return false;
8366             }
8367             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8368                 return false;
8369             }
8370             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8371                 return false;
8372             }
8373             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8374                 return false;
8375             }
8376             // Roundtrip:
8377             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
8378             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
8379             if ( rt.length != 1 ) {
8380                 return false;
8381             }
8382             final Phylogeny t1_rt = rt[ 0 ];
8383             n = t1_rt.getNode( "root node" );
8384             if ( !n.getNodeData().isHasDistribution() ) {
8385                 return false;
8386             }
8387             if ( n.getNodeData().getDistributions().size() != 1 ) {
8388                 return false;
8389             }
8390             d = n.getNodeData().getDistribution();
8391             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8392                 return false;
8393             }
8394             if ( d.getPoints().size() != 1 ) {
8395                 return false;
8396             }
8397             if ( d.getPolygons() != null ) {
8398                 return false;
8399             }
8400             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8401                 return false;
8402             }
8403             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8404                 return false;
8405             }
8406             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8407                 return false;
8408             }
8409             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8410                 return false;
8411             }
8412             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8413                 return false;
8414             }
8415             n = t1_rt.getNode( "node a" );
8416             if ( !n.getNodeData().isHasDistribution() ) {
8417                 return false;
8418             }
8419             if ( n.getNodeData().getDistributions().size() != 2 ) {
8420                 return false;
8421             }
8422             d = n.getNodeData().getDistribution( 1 );
8423             if ( !d.getDesc().equals( "San Diego" ) ) {
8424                 return false;
8425             }
8426             if ( d.getPoints().size() != 1 ) {
8427                 return false;
8428             }
8429             if ( d.getPolygons() != null ) {
8430                 return false;
8431             }
8432             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8433                 return false;
8434             }
8435             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8436                 return false;
8437             }
8438             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8439                 return false;
8440             }
8441             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8442                 return false;
8443             }
8444             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8445                 return false;
8446             }
8447             n = t1_rt.getNode( "node bb" );
8448             if ( !n.getNodeData().isHasDistribution() ) {
8449                 return false;
8450             }
8451             if ( n.getNodeData().getDistributions().size() != 1 ) {
8452                 return false;
8453             }
8454             d = n.getNodeData().getDistribution( 0 );
8455             if ( d.getPoints().size() != 3 ) {
8456                 return false;
8457             }
8458             if ( d.getPolygons().size() != 2 ) {
8459                 return false;
8460             }
8461             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8462                 return false;
8463             }
8464             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8465                 return false;
8466             }
8467             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8468                 return false;
8469             }
8470             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8471                 return false;
8472             }
8473             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8474                 return false;
8475             }
8476             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8477                 return false;
8478             }
8479             p = d.getPolygons().get( 0 );
8480             if ( p.getPoints().size() != 3 ) {
8481                 return false;
8482             }
8483             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8484                 return false;
8485             }
8486             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8487                 return false;
8488             }
8489             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8490                 return false;
8491             }
8492             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8493                 return false;
8494             }
8495             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8496                 return false;
8497             }
8498             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8499                 return false;
8500             }
8501             p = d.getPolygons().get( 1 );
8502             if ( p.getPoints().size() != 3 ) {
8503                 return false;
8504             }
8505             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8506                 return false;
8507             }
8508             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8509                 return false;
8510             }
8511             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8512                 return false;
8513             }
8514         }
8515         catch ( final Exception e ) {
8516             e.printStackTrace( System.out );
8517             return false;
8518         }
8519         return true;
8520     }
8521
8522     private static boolean testPostOrderIterator() {
8523         try {
8524             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8525             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
8526             PhylogenyNodeIterator it0;
8527             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
8528                 it0.next();
8529             }
8530             for( it0.reset(); it0.hasNext(); ) {
8531                 it0.next();
8532             }
8533             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
8534             final PhylogenyNodeIterator it = t1.iteratorPostorder();
8535             if ( !it.next().getName().equals( "A" ) ) {
8536                 return false;
8537             }
8538             if ( !it.next().getName().equals( "B" ) ) {
8539                 return false;
8540             }
8541             if ( !it.next().getName().equals( "ab" ) ) {
8542                 return false;
8543             }
8544             if ( !it.next().getName().equals( "C" ) ) {
8545                 return false;
8546             }
8547             if ( !it.next().getName().equals( "D" ) ) {
8548                 return false;
8549             }
8550             if ( !it.next().getName().equals( "cd" ) ) {
8551                 return false;
8552             }
8553             if ( !it.next().getName().equals( "abcd" ) ) {
8554                 return false;
8555             }
8556             if ( !it.next().getName().equals( "E" ) ) {
8557                 return false;
8558             }
8559             if ( !it.next().getName().equals( "F" ) ) {
8560                 return false;
8561             }
8562             if ( !it.next().getName().equals( "ef" ) ) {
8563                 return false;
8564             }
8565             if ( !it.next().getName().equals( "G" ) ) {
8566                 return false;
8567             }
8568             if ( !it.next().getName().equals( "H" ) ) {
8569                 return false;
8570             }
8571             if ( !it.next().getName().equals( "gh" ) ) {
8572                 return false;
8573             }
8574             if ( !it.next().getName().equals( "efgh" ) ) {
8575                 return false;
8576             }
8577             if ( !it.next().getName().equals( "r" ) ) {
8578                 return false;
8579             }
8580             if ( it.hasNext() ) {
8581                 return false;
8582             }
8583         }
8584         catch ( final Exception e ) {
8585             e.printStackTrace( System.out );
8586             return false;
8587         }
8588         return true;
8589     }
8590
8591     private static boolean testPreOrderIterator() {
8592         try {
8593             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8594             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
8595             PhylogenyNodeIterator it0;
8596             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
8597                 it0.next();
8598             }
8599             for( it0.reset(); it0.hasNext(); ) {
8600                 it0.next();
8601             }
8602             PhylogenyNodeIterator it = t0.iteratorPreorder();
8603             if ( !it.next().getName().equals( "r" ) ) {
8604                 return false;
8605             }
8606             if ( !it.next().getName().equals( "ab" ) ) {
8607                 return false;
8608             }
8609             if ( !it.next().getName().equals( "A" ) ) {
8610                 return false;
8611             }
8612             if ( !it.next().getName().equals( "B" ) ) {
8613                 return false;
8614             }
8615             if ( !it.next().getName().equals( "cd" ) ) {
8616                 return false;
8617             }
8618             if ( !it.next().getName().equals( "C" ) ) {
8619                 return false;
8620             }
8621             if ( !it.next().getName().equals( "D" ) ) {
8622                 return false;
8623             }
8624             if ( it.hasNext() ) {
8625                 return false;
8626             }
8627             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
8628             it = t1.iteratorPreorder();
8629             if ( !it.next().getName().equals( "r" ) ) {
8630                 return false;
8631             }
8632             if ( !it.next().getName().equals( "abcd" ) ) {
8633                 return false;
8634             }
8635             if ( !it.next().getName().equals( "ab" ) ) {
8636                 return false;
8637             }
8638             if ( !it.next().getName().equals( "A" ) ) {
8639                 return false;
8640             }
8641             if ( !it.next().getName().equals( "B" ) ) {
8642                 return false;
8643             }
8644             if ( !it.next().getName().equals( "cd" ) ) {
8645                 return false;
8646             }
8647             if ( !it.next().getName().equals( "C" ) ) {
8648                 return false;
8649             }
8650             if ( !it.next().getName().equals( "D" ) ) {
8651                 return false;
8652             }
8653             if ( !it.next().getName().equals( "efgh" ) ) {
8654                 return false;
8655             }
8656             if ( !it.next().getName().equals( "ef" ) ) {
8657                 return false;
8658             }
8659             if ( !it.next().getName().equals( "E" ) ) {
8660                 return false;
8661             }
8662             if ( !it.next().getName().equals( "F" ) ) {
8663                 return false;
8664             }
8665             if ( !it.next().getName().equals( "gh" ) ) {
8666                 return false;
8667             }
8668             if ( !it.next().getName().equals( "G" ) ) {
8669                 return false;
8670             }
8671             if ( !it.next().getName().equals( "H" ) ) {
8672                 return false;
8673             }
8674             if ( it.hasNext() ) {
8675                 return false;
8676             }
8677         }
8678         catch ( final Exception e ) {
8679             e.printStackTrace( System.out );
8680             return false;
8681         }
8682         return true;
8683     }
8684
8685     private static boolean testPropertiesMap() {
8686         try {
8687             final PropertiesMap pm = new PropertiesMap();
8688             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
8689             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
8690             final Property p2 = new Property( "something:else",
8691                                               "?",
8692                                               "improbable:research",
8693                                               "xsd:decimal",
8694                                               AppliesTo.NODE );
8695             pm.addProperty( p0 );
8696             pm.addProperty( p1 );
8697             pm.addProperty( p2 );
8698             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
8699                 return false;
8700             }
8701             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
8702                 return false;
8703             }
8704             if ( pm.getProperties().size() != 3 ) {
8705                 return false;
8706             }
8707             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
8708                 return false;
8709             }
8710             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
8711                 return false;
8712             }
8713             if ( pm.getProperties().size() != 3 ) {
8714                 return false;
8715             }
8716             pm.removeProperty( "dimensions:diameter" );
8717             if ( pm.getProperties().size() != 2 ) {
8718                 return false;
8719             }
8720             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
8721                 return false;
8722             }
8723             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
8724                 return false;
8725             }
8726         }
8727         catch ( final Exception e ) {
8728             e.printStackTrace( System.out );
8729             return false;
8730         }
8731         return true;
8732     }
8733
8734     private static boolean testProteinId() {
8735         try {
8736             final ProteinId id1 = new ProteinId( "a" );
8737             final ProteinId id2 = new ProteinId( "a" );
8738             final ProteinId id3 = new ProteinId( "A" );
8739             final ProteinId id4 = new ProteinId( "b" );
8740             if ( !id1.equals( id1 ) ) {
8741                 return false;
8742             }
8743             if ( id1.getId().equals( "x" ) ) {
8744                 return false;
8745             }
8746             if ( id1.getId().equals( null ) ) {
8747                 return false;
8748             }
8749             if ( !id1.equals( id2 ) ) {
8750                 return false;
8751             }
8752             if ( id1.equals( id3 ) ) {
8753                 return false;
8754             }
8755             if ( id1.hashCode() != id1.hashCode() ) {
8756                 return false;
8757             }
8758             if ( id1.hashCode() != id2.hashCode() ) {
8759                 return false;
8760             }
8761             if ( id1.hashCode() == id3.hashCode() ) {
8762                 return false;
8763             }
8764             if ( id1.compareTo( id1 ) != 0 ) {
8765                 return false;
8766             }
8767             if ( id1.compareTo( id2 ) != 0 ) {
8768                 return false;
8769             }
8770             if ( id1.compareTo( id3 ) != 0 ) {
8771                 return false;
8772             }
8773             if ( id1.compareTo( id4 ) >= 0 ) {
8774                 return false;
8775             }
8776             if ( id4.compareTo( id1 ) <= 0 ) {
8777                 return false;
8778             }
8779             if ( !id4.getId().equals( "b" ) ) {
8780                 return false;
8781             }
8782             final ProteinId id5 = new ProteinId( " C " );
8783             if ( !id5.getId().equals( "C" ) ) {
8784                 return false;
8785             }
8786             if ( id5.equals( id1 ) ) {
8787                 return false;
8788             }
8789         }
8790         catch ( final Exception e ) {
8791             e.printStackTrace( System.out );
8792             return false;
8793         }
8794         return true;
8795     }
8796
8797     private static boolean testReIdMethods() {
8798         try {
8799             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8800             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
8801             final long count = PhylogenyNode.getNodeCount();
8802             p.levelOrderReID();
8803             if ( p.getNode( "r" ).getId() != count ) {
8804                 return false;
8805             }
8806             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
8807                 return false;
8808             }
8809             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
8810                 return false;
8811             }
8812             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
8813                 return false;
8814             }
8815             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
8816                 return false;
8817             }
8818             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
8819                 return false;
8820             }
8821             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
8822                 return false;
8823             }
8824             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
8825                 return false;
8826             }
8827             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
8828                 return false;
8829             }
8830             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
8831                 return false;
8832             }
8833             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
8834                 return false;
8835             }
8836             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
8837                 return false;
8838             }
8839             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
8840                 return false;
8841             }
8842             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
8843                 return false;
8844             }
8845             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
8846                 return false;
8847             }
8848         }
8849         catch ( final Exception e ) {
8850             e.printStackTrace( System.out );
8851             return false;
8852         }
8853         return true;
8854     }
8855
8856     private static boolean testRerooting() {
8857         try {
8858             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8859             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",
8860                                                  new NHXParser() )[ 0 ];
8861             if ( !t1.isRooted() ) {
8862                 return false;
8863             }
8864             t1.reRoot( t1.getNode( "D" ) );
8865             t1.reRoot( t1.getNode( "CD" ) );
8866             t1.reRoot( t1.getNode( "A" ) );
8867             t1.reRoot( t1.getNode( "B" ) );
8868             t1.reRoot( t1.getNode( "AB" ) );
8869             t1.reRoot( t1.getNode( "D" ) );
8870             t1.reRoot( t1.getNode( "C" ) );
8871             t1.reRoot( t1.getNode( "CD" ) );
8872             t1.reRoot( t1.getNode( "A" ) );
8873             t1.reRoot( t1.getNode( "B" ) );
8874             t1.reRoot( t1.getNode( "AB" ) );
8875             t1.reRoot( t1.getNode( "D" ) );
8876             t1.reRoot( t1.getNode( "D" ) );
8877             t1.reRoot( t1.getNode( "C" ) );
8878             t1.reRoot( t1.getNode( "A" ) );
8879             t1.reRoot( t1.getNode( "B" ) );
8880             t1.reRoot( t1.getNode( "AB" ) );
8881             t1.reRoot( t1.getNode( "C" ) );
8882             t1.reRoot( t1.getNode( "D" ) );
8883             t1.reRoot( t1.getNode( "CD" ) );
8884             t1.reRoot( t1.getNode( "D" ) );
8885             t1.reRoot( t1.getNode( "A" ) );
8886             t1.reRoot( t1.getNode( "B" ) );
8887             t1.reRoot( t1.getNode( "AB" ) );
8888             t1.reRoot( t1.getNode( "C" ) );
8889             t1.reRoot( t1.getNode( "D" ) );
8890             t1.reRoot( t1.getNode( "CD" ) );
8891             t1.reRoot( t1.getNode( "D" ) );
8892             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
8893                 return false;
8894             }
8895             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
8896                 return false;
8897             }
8898             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
8899                 return false;
8900             }
8901             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
8902                 return false;
8903             }
8904             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
8905                 return false;
8906             }
8907             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
8908                 return false;
8909             }
8910             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",
8911                                                  new NHXParser() )[ 0 ];
8912             t2.reRoot( t2.getNode( "A" ) );
8913             t2.reRoot( t2.getNode( "D" ) );
8914             t2.reRoot( t2.getNode( "ABC" ) );
8915             t2.reRoot( t2.getNode( "A" ) );
8916             t2.reRoot( t2.getNode( "B" ) );
8917             t2.reRoot( t2.getNode( "D" ) );
8918             t2.reRoot( t2.getNode( "C" ) );
8919             t2.reRoot( t2.getNode( "ABC" ) );
8920             t2.reRoot( t2.getNode( "A" ) );
8921             t2.reRoot( t2.getNode( "B" ) );
8922             t2.reRoot( t2.getNode( "AB" ) );
8923             t2.reRoot( t2.getNode( "AB" ) );
8924             t2.reRoot( t2.getNode( "D" ) );
8925             t2.reRoot( t2.getNode( "C" ) );
8926             t2.reRoot( t2.getNode( "B" ) );
8927             t2.reRoot( t2.getNode( "AB" ) );
8928             t2.reRoot( t2.getNode( "D" ) );
8929             t2.reRoot( t2.getNode( "D" ) );
8930             t2.reRoot( t2.getNode( "ABC" ) );
8931             t2.reRoot( t2.getNode( "A" ) );
8932             t2.reRoot( t2.getNode( "B" ) );
8933             t2.reRoot( t2.getNode( "AB" ) );
8934             t2.reRoot( t2.getNode( "D" ) );
8935             t2.reRoot( t2.getNode( "C" ) );
8936             t2.reRoot( t2.getNode( "ABC" ) );
8937             t2.reRoot( t2.getNode( "A" ) );
8938             t2.reRoot( t2.getNode( "B" ) );
8939             t2.reRoot( t2.getNode( "AB" ) );
8940             t2.reRoot( t2.getNode( "D" ) );
8941             t2.reRoot( t2.getNode( "D" ) );
8942             t2.reRoot( t2.getNode( "C" ) );
8943             t2.reRoot( t2.getNode( "A" ) );
8944             t2.reRoot( t2.getNode( "B" ) );
8945             t2.reRoot( t2.getNode( "AB" ) );
8946             t2.reRoot( t2.getNode( "C" ) );
8947             t2.reRoot( t2.getNode( "D" ) );
8948             t2.reRoot( t2.getNode( "ABC" ) );
8949             t2.reRoot( t2.getNode( "D" ) );
8950             t2.reRoot( t2.getNode( "A" ) );
8951             t2.reRoot( t2.getNode( "B" ) );
8952             t2.reRoot( t2.getNode( "AB" ) );
8953             t2.reRoot( t2.getNode( "C" ) );
8954             t2.reRoot( t2.getNode( "D" ) );
8955             t2.reRoot( t2.getNode( "ABC" ) );
8956             t2.reRoot( t2.getNode( "D" ) );
8957             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8958                 return false;
8959             }
8960             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8961                 return false;
8962             }
8963             t2.reRoot( t2.getNode( "ABC" ) );
8964             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8965                 return false;
8966             }
8967             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8968                 return false;
8969             }
8970             t2.reRoot( t2.getNode( "AB" ) );
8971             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8972                 return false;
8973             }
8974             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8975                 return false;
8976             }
8977             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8978                 return false;
8979             }
8980             t2.reRoot( t2.getNode( "AB" ) );
8981             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8982                 return false;
8983             }
8984             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8985                 return false;
8986             }
8987             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8988                 return false;
8989             }
8990             t2.reRoot( t2.getNode( "D" ) );
8991             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8992                 return false;
8993             }
8994             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8995                 return false;
8996             }
8997             t2.reRoot( t2.getNode( "ABC" ) );
8998             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8999                 return false;
9000             }
9001             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9002                 return false;
9003             }
9004             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
9005                                                  new NHXParser() )[ 0 ];
9006             t3.reRoot( t3.getNode( "B" ) );
9007             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9008                 return false;
9009             }
9010             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9011                 return false;
9012             }
9013             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9014                 return false;
9015             }
9016             t3.reRoot( t3.getNode( "B" ) );
9017             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9018                 return false;
9019             }
9020             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9021                 return false;
9022             }
9023             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9024                 return false;
9025             }
9026             t3.reRoot( t3.getRoot() );
9027             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9028                 return false;
9029             }
9030             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9031                 return false;
9032             }
9033             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9034                 return false;
9035             }
9036         }
9037         catch ( final Exception e ) {
9038             e.printStackTrace( System.out );
9039             return false;
9040         }
9041         return true;
9042     }
9043
9044     private static boolean testSDIse() {
9045         try {
9046             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9047             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
9048             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
9049             gene1.setRooted( true );
9050             species1.setRooted( true );
9051             final SDI sdi = new SDI( gene1, species1 );
9052             if ( !gene1.getRoot().isDuplication() ) {
9053                 return false;
9054             }
9055             final Phylogeny species2 = factory
9056                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9057                              new NHXParser() )[ 0 ];
9058             final Phylogeny gene2 = factory
9059                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9060                              new NHXParser() )[ 0 ];
9061             species2.setRooted( true );
9062             gene2.setRooted( true );
9063             final SDI sdi2 = new SDI( gene2, species2 );
9064             if ( sdi2.getDuplicationsSum() != 0 ) {
9065                 return false;
9066             }
9067             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
9068                 return false;
9069             }
9070             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
9071                 return false;
9072             }
9073             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
9074                 return false;
9075             }
9076             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
9077                 return false;
9078             }
9079             if ( !gene2.getNode( "r" ).isSpeciation() ) {
9080                 return false;
9081             }
9082             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
9083                 return false;
9084             }
9085             final Phylogeny species3 = factory
9086                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9087                              new NHXParser() )[ 0 ];
9088             final Phylogeny gene3 = factory
9089                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9090                              new NHXParser() )[ 0 ];
9091             species3.setRooted( true );
9092             gene3.setRooted( true );
9093             final SDI sdi3 = new SDI( gene3, species3 );
9094             if ( sdi3.getDuplicationsSum() != 1 ) {
9095                 return false;
9096             }
9097             if ( !gene3.getNode( "aa" ).isDuplication() ) {
9098                 return false;
9099             }
9100             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
9101                 return false;
9102             }
9103             final Phylogeny species4 = factory
9104                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9105                              new NHXParser() )[ 0 ];
9106             final Phylogeny gene4 = factory
9107                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9108                              new NHXParser() )[ 0 ];
9109             species4.setRooted( true );
9110             gene4.setRooted( true );
9111             final SDI sdi4 = new SDI( gene4, species4 );
9112             if ( sdi4.getDuplicationsSum() != 1 ) {
9113                 return false;
9114             }
9115             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
9116                 return false;
9117             }
9118             if ( !gene4.getNode( "abc" ).isDuplication() ) {
9119                 return false;
9120             }
9121             if ( gene4.getNode( "abcd" ).isDuplication() ) {
9122                 return false;
9123             }
9124             if ( species4.getNumberOfExternalNodes() != 6 ) {
9125                 return false;
9126             }
9127             if ( gene4.getNumberOfExternalNodes() != 6 ) {
9128                 return false;
9129             }
9130             final Phylogeny species5 = factory
9131                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9132                              new NHXParser() )[ 0 ];
9133             final Phylogeny gene5 = factory
9134                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9135                              new NHXParser() )[ 0 ];
9136             species5.setRooted( true );
9137             gene5.setRooted( true );
9138             final SDI sdi5 = new SDI( gene5, species5 );
9139             if ( sdi5.getDuplicationsSum() != 2 ) {
9140                 return false;
9141             }
9142             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
9143                 return false;
9144             }
9145             if ( !gene5.getNode( "adc" ).isDuplication() ) {
9146                 return false;
9147             }
9148             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
9149                 return false;
9150             }
9151             if ( species5.getNumberOfExternalNodes() != 6 ) {
9152                 return false;
9153             }
9154             if ( gene5.getNumberOfExternalNodes() != 6 ) {
9155                 return false;
9156             }
9157             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
9158             // Conjecture for Comparing Molecular Phylogenies"
9159             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
9160             final Phylogeny species6 = factory
9161                     .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,"
9162                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9163                              new NHXParser() )[ 0 ];
9164             final Phylogeny gene6 = factory
9165                     .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,"
9166                                      + "((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,"
9167                                      + "(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;",
9168                              new NHXParser() )[ 0 ];
9169             species6.setRooted( true );
9170             gene6.setRooted( true );
9171             final SDI sdi6 = new SDI( gene6, species6 );
9172             if ( sdi6.getDuplicationsSum() != 3 ) {
9173                 return false;
9174             }
9175             if ( !gene6.getNode( "r" ).isDuplication() ) {
9176                 return false;
9177             }
9178             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
9179                 return false;
9180             }
9181             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
9182                 return false;
9183             }
9184             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
9185                 return false;
9186             }
9187             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
9188                 return false;
9189             }
9190             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
9191                 return false;
9192             }
9193             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
9194                 return false;
9195             }
9196             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
9197                 return false;
9198             }
9199             sdi6.computeMappingCostL();
9200             if ( sdi6.computeMappingCostL() != 17 ) {
9201                 return false;
9202             }
9203             if ( species6.getNumberOfExternalNodes() != 9 ) {
9204                 return false;
9205             }
9206             if ( gene6.getNumberOfExternalNodes() != 9 ) {
9207                 return false;
9208             }
9209             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
9210                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
9211                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
9212                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
9213                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
9214             species7.setRooted( true );
9215             final Phylogeny gene7_1 = Test
9216                     .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])" );
9217             gene7_1.setRooted( true );
9218             final SDI sdi7 = new SDI( gene7_1, species7 );
9219             if ( sdi7.getDuplicationsSum() != 0 ) {
9220                 return false;
9221             }
9222             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
9223                 return false;
9224             }
9225             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
9226                 return false;
9227             }
9228             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
9229                 return false;
9230             }
9231             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
9232                 return false;
9233             }
9234             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
9235                 return false;
9236             }
9237             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
9238                 return false;
9239             }
9240             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
9241                 return false;
9242             }
9243             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
9244                 return false;
9245             }
9246             final Phylogeny gene7_2 = Test
9247                     .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])" );
9248             gene7_2.setRooted( true );
9249             final SDI sdi7_2 = new SDI( gene7_2, species7 );
9250             if ( sdi7_2.getDuplicationsSum() != 1 ) {
9251                 return false;
9252             }
9253             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
9254                 return false;
9255             }
9256             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
9257                 return false;
9258             }
9259             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
9260                 return false;
9261             }
9262             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
9263                 return false;
9264             }
9265             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
9266                 return false;
9267             }
9268             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
9269                 return false;
9270             }
9271             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
9272                 return false;
9273             }
9274             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
9275                 return false;
9276             }
9277             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
9278                 return false;
9279             }
9280         }
9281         catch ( final Exception e ) {
9282             return false;
9283         }
9284         return true;
9285     }
9286
9287     private static boolean testSDIunrooted() {
9288         try {
9289             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9290             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
9291             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
9292             final Iterator<PhylogenyBranch> iter = l.iterator();
9293             PhylogenyBranch br = iter.next();
9294             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
9295                 return false;
9296             }
9297             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
9298                 return false;
9299             }
9300             br = iter.next();
9301             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9302                 return false;
9303             }
9304             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9305                 return false;
9306             }
9307             br = iter.next();
9308             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
9309                 return false;
9310             }
9311             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
9312                 return false;
9313             }
9314             br = iter.next();
9315             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9316                 return false;
9317             }
9318             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9319                 return false;
9320             }
9321             br = iter.next();
9322             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9323                 return false;
9324             }
9325             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9326                 return false;
9327             }
9328             br = iter.next();
9329             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9330                 return false;
9331             }
9332             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9333                 return false;
9334             }
9335             br = iter.next();
9336             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9337                 return false;
9338             }
9339             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9340                 return false;
9341             }
9342             br = iter.next();
9343             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9344                 return false;
9345             }
9346             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9347                 return false;
9348             }
9349             br = iter.next();
9350             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9351                 return false;
9352             }
9353             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9354                 return false;
9355             }
9356             br = iter.next();
9357             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9358                 return false;
9359             }
9360             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9361                 return false;
9362             }
9363             br = iter.next();
9364             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9365                 return false;
9366             }
9367             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9368                 return false;
9369             }
9370             br = iter.next();
9371             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
9372                 return false;
9373             }
9374             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
9375                 return false;
9376             }
9377             br = iter.next();
9378             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9379                 return false;
9380             }
9381             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9382                 return false;
9383             }
9384             br = iter.next();
9385             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
9386                 return false;
9387             }
9388             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
9389                 return false;
9390             }
9391             br = iter.next();
9392             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
9393                 return false;
9394             }
9395             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
9396                 return false;
9397             }
9398             if ( iter.hasNext() ) {
9399                 return false;
9400             }
9401             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
9402             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
9403             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
9404             br = iter1.next();
9405             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9406                 return false;
9407             }
9408             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9409                 return false;
9410             }
9411             br = iter1.next();
9412             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9413                 return false;
9414             }
9415             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9416                 return false;
9417             }
9418             br = iter1.next();
9419             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9420                 return false;
9421             }
9422             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9423                 return false;
9424             }
9425             if ( iter1.hasNext() ) {
9426                 return false;
9427             }
9428             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
9429             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
9430             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
9431             br = iter2.next();
9432             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9433                 return false;
9434             }
9435             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9436                 return false;
9437             }
9438             br = iter2.next();
9439             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9440                 return false;
9441             }
9442             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9443                 return false;
9444             }
9445             br = iter2.next();
9446             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9447                 return false;
9448             }
9449             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9450                 return false;
9451             }
9452             if ( iter2.hasNext() ) {
9453                 return false;
9454             }
9455             final Phylogeny species0 = factory
9456                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9457                              new NHXParser() )[ 0 ];
9458             final Phylogeny gene1 = factory
9459                     .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])",
9460                              new NHXParser() )[ 0 ];
9461             species0.setRooted( true );
9462             gene1.setRooted( true );
9463             final SDIR sdi_unrooted = new SDIR();
9464             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
9465             if ( sdi_unrooted.getCount() != 1 ) {
9466                 return false;
9467             }
9468             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
9469                 return false;
9470             }
9471             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
9472                 return false;
9473             }
9474             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
9475                 return false;
9476             }
9477             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9478                 return false;
9479             }
9480             final Phylogeny gene2 = factory
9481                     .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])",
9482                              new NHXParser() )[ 0 ];
9483             gene2.setRooted( true );
9484             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
9485             if ( sdi_unrooted.getCount() != 1 ) {
9486                 return false;
9487             }
9488             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9489                 return false;
9490             }
9491             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9492                 return false;
9493             }
9494             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
9495                 return false;
9496             }
9497             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9498                 return false;
9499             }
9500             final Phylogeny species6 = factory
9501                     .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,"
9502                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9503                              new NHXParser() )[ 0 ];
9504             final Phylogeny gene6 = factory
9505                     .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],"
9506                                      + "(((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],"
9507                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9508                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9509                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9510                              new NHXParser() )[ 0 ];
9511             species6.setRooted( true );
9512             gene6.setRooted( true );
9513             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
9514             if ( sdi_unrooted.getCount() != 1 ) {
9515                 return false;
9516             }
9517             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9518                 return false;
9519             }
9520             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9521                 return false;
9522             }
9523             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9524                 return false;
9525             }
9526             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9527                 return false;
9528             }
9529             if ( !p6[ 0 ].getRoot().isDuplication() ) {
9530                 return false;
9531             }
9532             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9533                 return false;
9534             }
9535             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9536                 return false;
9537             }
9538             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
9539                 return false;
9540             }
9541             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9542                 return false;
9543             }
9544             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
9545                 return false;
9546             }
9547             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
9548                 return false;
9549             }
9550             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9551                 return false;
9552             }
9553             p6 = null;
9554             final Phylogeny species7 = factory
9555                     .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,"
9556                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9557                              new NHXParser() )[ 0 ];
9558             final Phylogeny gene7 = factory
9559                     .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],"
9560                                      + "(((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],"
9561                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9562                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9563                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9564                              new NHXParser() )[ 0 ];
9565             species7.setRooted( true );
9566             gene7.setRooted( true );
9567             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
9568             if ( sdi_unrooted.getCount() != 1 ) {
9569                 return false;
9570             }
9571             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9572                 return false;
9573             }
9574             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9575                 return false;
9576             }
9577             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9578                 return false;
9579             }
9580             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
9581                 return false;
9582             }
9583             if ( !p7[ 0 ].getRoot().isDuplication() ) {
9584                 return false;
9585             }
9586             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9587                 return false;
9588             }
9589             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9590                 return false;
9591             }
9592             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
9593                 return false;
9594             }
9595             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9596                 return false;
9597             }
9598             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
9599                 return false;
9600             }
9601             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
9602                 return false;
9603             }
9604             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9605                 return false;
9606             }
9607             p7 = null;
9608             final Phylogeny species8 = factory
9609                     .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,"
9610                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9611                              new NHXParser() )[ 0 ];
9612             final Phylogeny gene8 = factory
9613                     .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],"
9614                                      + "(((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],"
9615                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9616                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9617                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9618                              new NHXParser() )[ 0 ];
9619             species8.setRooted( true );
9620             gene8.setRooted( true );
9621             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
9622             if ( sdi_unrooted.getCount() != 1 ) {
9623                 return false;
9624             }
9625             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9626                 return false;
9627             }
9628             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9629                 return false;
9630             }
9631             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9632                 return false;
9633             }
9634             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9635                 return false;
9636             }
9637             if ( !p8[ 0 ].getRoot().isDuplication() ) {
9638                 return false;
9639             }
9640             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9641                 return false;
9642             }
9643             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9644                 return false;
9645             }
9646             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
9647                 return false;
9648             }
9649             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9650                 return false;
9651             }
9652             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
9653                 return false;
9654             }
9655             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
9656                 return false;
9657             }
9658             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9659                 return false;
9660             }
9661             p8 = null;
9662         }
9663         catch ( final Exception e ) {
9664             e.printStackTrace( System.out );
9665             return false;
9666         }
9667         return true;
9668     }
9669
9670     private static boolean testSequenceIdParsing() {
9671         try {
9672             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
9673             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9674                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
9675                 if ( id != null ) {
9676                     System.out.println( "value   =" + id.getValue() );
9677                     System.out.println( "provider=" + id.getSource() );
9678                 }
9679                 return false;
9680             }
9681             //
9682             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
9683             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9684                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
9685                 if ( id != null ) {
9686                     System.out.println( "value   =" + id.getValue() );
9687                     System.out.println( "provider=" + id.getSource() );
9688                 }
9689                 return false;
9690             }
9691             //
9692             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
9693             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9694                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
9695                 if ( id != null ) {
9696                     System.out.println( "value   =" + id.getValue() );
9697                     System.out.println( "provider=" + id.getSource() );
9698                 }
9699                 return false;
9700             }
9701             // 
9702             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
9703             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9704                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
9705                 if ( id != null ) {
9706                     System.out.println( "value   =" + id.getValue() );
9707                     System.out.println( "provider=" + id.getSource() );
9708                 }
9709                 return false;
9710             }
9711             // 
9712             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
9713             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9714                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
9715                 if ( id != null ) {
9716                     System.out.println( "value   =" + id.getValue() );
9717                     System.out.println( "provider=" + id.getSource() );
9718                 }
9719                 return false;
9720             }
9721             // 
9722             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
9723             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9724                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
9725                 if ( id != null ) {
9726                     System.out.println( "value   =" + id.getValue() );
9727                     System.out.println( "provider=" + id.getSource() );
9728                 }
9729                 return false;
9730             }
9731             // 
9732             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
9733             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9734                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
9735                 if ( id != null ) {
9736                     System.out.println( "value   =" + id.getValue() );
9737                     System.out.println( "provider=" + id.getSource() );
9738                 }
9739                 return false;
9740             }
9741             // 
9742             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
9743             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9744                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
9745                 if ( id != null ) {
9746                     System.out.println( "value   =" + id.getValue() );
9747                     System.out.println( "provider=" + id.getSource() );
9748                 }
9749                 return false;
9750             }
9751             // 
9752             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
9753             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9754                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
9755                 if ( id != null ) {
9756                     System.out.println( "value   =" + id.getValue() );
9757                     System.out.println( "provider=" + id.getSource() );
9758                 }
9759                 return false;
9760             }
9761             // 
9762             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
9763             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9764                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
9765                 if ( id != null ) {
9766                     System.out.println( "value   =" + id.getValue() );
9767                     System.out.println( "provider=" + id.getSource() );
9768                 }
9769                 return false;
9770             }
9771             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
9772             if ( id != null ) {
9773                 System.out.println( "value   =" + id.getValue() );
9774                 System.out.println( "provider=" + id.getSource() );
9775                 return false;
9776             }
9777         }
9778         catch ( final Exception e ) {
9779             e.printStackTrace( System.out );
9780             return false;
9781         }
9782         return true;
9783     }
9784
9785     private static boolean testSequenceWriter() {
9786         try {
9787             final String n = ForesterUtil.LINE_SEPARATOR;
9788             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
9789                 return false;
9790             }
9791             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
9792                 return false;
9793             }
9794             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
9795                 return false;
9796             }
9797             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
9798                 return false;
9799             }
9800             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
9801                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
9802                 return false;
9803             }
9804             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
9805                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
9806                 return false;
9807             }
9808         }
9809         catch ( final Exception e ) {
9810             e.printStackTrace();
9811             return false;
9812         }
9813         return true;
9814     }
9815
9816     private static boolean testSpecies() {
9817         try {
9818             final Species s1 = new BasicSpecies( "a" );
9819             final Species s2 = new BasicSpecies( "a" );
9820             final Species s3 = new BasicSpecies( "A" );
9821             final Species s4 = new BasicSpecies( "b" );
9822             if ( !s1.equals( s1 ) ) {
9823                 return false;
9824             }
9825             if ( s1.getSpeciesId().equals( "x" ) ) {
9826                 return false;
9827             }
9828             if ( s1.getSpeciesId().equals( null ) ) {
9829                 return false;
9830             }
9831             if ( !s1.equals( s2 ) ) {
9832                 return false;
9833             }
9834             if ( s1.equals( s3 ) ) {
9835                 return false;
9836             }
9837             if ( s1.hashCode() != s1.hashCode() ) {
9838                 return false;
9839             }
9840             if ( s1.hashCode() != s2.hashCode() ) {
9841                 return false;
9842             }
9843             if ( s1.hashCode() == s3.hashCode() ) {
9844                 return false;
9845             }
9846             if ( s1.compareTo( s1 ) != 0 ) {
9847                 return false;
9848             }
9849             if ( s1.compareTo( s2 ) != 0 ) {
9850                 return false;
9851             }
9852             if ( s1.compareTo( s3 ) != 0 ) {
9853                 return false;
9854             }
9855             if ( s1.compareTo( s4 ) >= 0 ) {
9856                 return false;
9857             }
9858             if ( s4.compareTo( s1 ) <= 0 ) {
9859                 return false;
9860             }
9861             if ( !s4.getSpeciesId().equals( "b" ) ) {
9862                 return false;
9863             }
9864             final Species s5 = new BasicSpecies( " C " );
9865             if ( !s5.getSpeciesId().equals( "C" ) ) {
9866                 return false;
9867             }
9868             if ( s5.equals( s1 ) ) {
9869                 return false;
9870             }
9871         }
9872         catch ( final Exception e ) {
9873             e.printStackTrace( System.out );
9874             return false;
9875         }
9876         return true;
9877     }
9878
9879     private static boolean testSplit() {
9880         try {
9881             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9882             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
9883             //Archaeopteryx.createApplication( p0 );
9884             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
9885             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9886             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9887             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9888             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9889             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9890             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9891             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9892             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
9893             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
9894             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
9895             // System.out.println( s0.toString() );
9896             //
9897             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
9898             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9899             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9900             if ( s0.match( query_nodes ) ) {
9901                 return false;
9902             }
9903             query_nodes = new HashSet<PhylogenyNode>();
9904             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9905             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9908             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9909             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9910             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9911             if ( !s0.match( query_nodes ) ) {
9912                 return false;
9913             }
9914             //
9915             query_nodes = new HashSet<PhylogenyNode>();
9916             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9917             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9918             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9919             if ( !s0.match( query_nodes ) ) {
9920                 return false;
9921             }
9922             //
9923             query_nodes = new HashSet<PhylogenyNode>();
9924             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9925             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9926             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9927             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9928             if ( !s0.match( query_nodes ) ) {
9929                 return false;
9930             }
9931             //
9932             query_nodes = new HashSet<PhylogenyNode>();
9933             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9934             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9935             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9936             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9937             if ( !s0.match( query_nodes ) ) {
9938                 return false;
9939             }
9940             //
9941             query_nodes = new HashSet<PhylogenyNode>();
9942             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9943             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9944             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9945             if ( !s0.match( query_nodes ) ) {
9946                 return false;
9947             }
9948             //
9949             query_nodes = new HashSet<PhylogenyNode>();
9950             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9951             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9952             if ( !s0.match( query_nodes ) ) {
9953                 return false;
9954             }
9955             //
9956             query_nodes = new HashSet<PhylogenyNode>();
9957             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9958             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9959             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9960             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9961             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9962             if ( !s0.match( query_nodes ) ) {
9963                 return false;
9964             }
9965             //
9966             query_nodes = new HashSet<PhylogenyNode>();
9967             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9968             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9969             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9970             if ( !s0.match( query_nodes ) ) {
9971                 return false;
9972             }
9973             //
9974             query_nodes = new HashSet<PhylogenyNode>();
9975             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9976             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9977             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9978             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9979             if ( !s0.match( query_nodes ) ) {
9980                 return false;
9981             }
9982             //
9983             query_nodes = new HashSet<PhylogenyNode>();
9984             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9985             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9986             if ( s0.match( query_nodes ) ) {
9987                 return false;
9988             }
9989             //
9990             query_nodes = new HashSet<PhylogenyNode>();
9991             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9992             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9993             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9994             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9995             if ( s0.match( query_nodes ) ) {
9996                 return false;
9997             }
9998             //
9999             query_nodes = new HashSet<PhylogenyNode>();
10000             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10001             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10002             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10003             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10004             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10005             if ( s0.match( query_nodes ) ) {
10006                 return false;
10007             }
10008             //
10009             query_nodes = new HashSet<PhylogenyNode>();
10010             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10011             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10012             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10013             if ( s0.match( query_nodes ) ) {
10014                 return false;
10015             }
10016             //
10017             query_nodes = new HashSet<PhylogenyNode>();
10018             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10019             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10020             if ( s0.match( query_nodes ) ) {
10021                 return false;
10022             }
10023             //
10024             query_nodes = new HashSet<PhylogenyNode>();
10025             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10026             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10027             if ( s0.match( query_nodes ) ) {
10028                 return false;
10029             }
10030             //
10031             query_nodes = new HashSet<PhylogenyNode>();
10032             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10033             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10034             if ( s0.match( query_nodes ) ) {
10035                 return false;
10036             }
10037             //
10038             query_nodes = new HashSet<PhylogenyNode>();
10039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10040             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10041             if ( s0.match( query_nodes ) ) {
10042                 return false;
10043             }
10044             //
10045             query_nodes = new HashSet<PhylogenyNode>();
10046             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10048             if ( s0.match( query_nodes ) ) {
10049                 return false;
10050             }
10051             //
10052             query_nodes = new HashSet<PhylogenyNode>();
10053             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10054             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10055             if ( s0.match( query_nodes ) ) {
10056                 return false;
10057             }
10058             //
10059             query_nodes = new HashSet<PhylogenyNode>();
10060             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10061             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10062             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10063             if ( s0.match( query_nodes ) ) {
10064                 return false;
10065             }
10066             //
10067             query_nodes = new HashSet<PhylogenyNode>();
10068             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10069             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10070             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10071             if ( s0.match( query_nodes ) ) {
10072                 return false;
10073             }
10074             //
10075             query_nodes = new HashSet<PhylogenyNode>();
10076             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10077             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10078             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10079             if ( s0.match( query_nodes ) ) {
10080                 return false;
10081             }
10082             //
10083             query_nodes = new HashSet<PhylogenyNode>();
10084             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10085             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10086             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10087             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10088             if ( s0.match( query_nodes ) ) {
10089                 return false;
10090             }
10091             /////////
10092             //            query_nodes = new HashSet<PhylogenyNode>();
10093             //            query_nodes.add( new PhylogenyNode( "X" ) );
10094             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10095             //            query_nodes.add( new PhylogenyNode( "A" ) );
10096             //            query_nodes.add( new PhylogenyNode( "B" ) );
10097             //            query_nodes.add( new PhylogenyNode( "C" ) );
10098             //            query_nodes.add( new PhylogenyNode( "D" ) );
10099             //            query_nodes.add( new PhylogenyNode( "E" ) );
10100             //            query_nodes.add( new PhylogenyNode( "F" ) );
10101             //            query_nodes.add( new PhylogenyNode( "G" ) );
10102             //            if ( !s0.match( query_nodes ) ) {
10103             //                return false;
10104             //            }
10105             //            query_nodes = new HashSet<PhylogenyNode>();
10106             //            query_nodes.add( new PhylogenyNode( "X" ) );
10107             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10108             //            query_nodes.add( new PhylogenyNode( "A" ) );
10109             //            query_nodes.add( new PhylogenyNode( "B" ) );
10110             //            query_nodes.add( new PhylogenyNode( "C" ) );
10111             //            if ( !s0.match( query_nodes ) ) {
10112             //                return false;
10113             //            }
10114             //            //
10115             //            query_nodes = new HashSet<PhylogenyNode>();
10116             //            query_nodes.add( new PhylogenyNode( "X" ) );
10117             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10118             //            query_nodes.add( new PhylogenyNode( "D" ) );
10119             //            query_nodes.add( new PhylogenyNode( "E" ) );
10120             //            query_nodes.add( new PhylogenyNode( "F" ) );
10121             //            query_nodes.add( new PhylogenyNode( "G" ) );
10122             //            if ( !s0.match( query_nodes ) ) {
10123             //                return false;
10124             //            }
10125             //            //
10126             //            query_nodes = new HashSet<PhylogenyNode>();
10127             //            query_nodes.add( new PhylogenyNode( "X" ) );
10128             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10129             //            query_nodes.add( new PhylogenyNode( "A" ) );
10130             //            query_nodes.add( new PhylogenyNode( "B" ) );
10131             //            query_nodes.add( new PhylogenyNode( "C" ) );
10132             //            query_nodes.add( new PhylogenyNode( "D" ) );
10133             //            if ( !s0.match( query_nodes ) ) {
10134             //                return false;
10135             //            }
10136             //            //
10137             //            query_nodes = new HashSet<PhylogenyNode>();
10138             //            query_nodes.add( new PhylogenyNode( "X" ) );
10139             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10140             //            query_nodes.add( new PhylogenyNode( "E" ) );
10141             //            query_nodes.add( new PhylogenyNode( "F" ) );
10142             //            query_nodes.add( new PhylogenyNode( "G" ) );
10143             //            if ( !s0.match( query_nodes ) ) {
10144             //                return false;
10145             //            }
10146             //            //
10147             //            query_nodes = new HashSet<PhylogenyNode>();
10148             //            query_nodes.add( new PhylogenyNode( "X" ) );
10149             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10150             //            query_nodes.add( new PhylogenyNode( "F" ) );
10151             //            query_nodes.add( new PhylogenyNode( "G" ) );
10152             //            if ( !s0.match( query_nodes ) ) {
10153             //                return false;
10154             //            }
10155             //
10156             query_nodes = new HashSet<PhylogenyNode>();
10157             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10158             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10159             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10160             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10161             if ( s0.match( query_nodes ) ) {
10162                 return false;
10163             }
10164             //
10165             query_nodes = new HashSet<PhylogenyNode>();
10166             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10167             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10168             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10169             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10170             if ( s0.match( query_nodes ) ) {
10171                 return false;
10172             }
10173             ///////////////////////////
10174             //
10175             query_nodes = new HashSet<PhylogenyNode>();
10176             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10177             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10178             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10179             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10180             if ( s0.match( query_nodes ) ) {
10181                 return false;
10182             }
10183             //
10184             query_nodes = new HashSet<PhylogenyNode>();
10185             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10186             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10187             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10188             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10189             if ( s0.match( query_nodes ) ) {
10190                 return false;
10191             }
10192             //
10193             query_nodes = new HashSet<PhylogenyNode>();
10194             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10195             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10196             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10197             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10198             if ( s0.match( query_nodes ) ) {
10199                 return false;
10200             }
10201             //
10202             query_nodes = new HashSet<PhylogenyNode>();
10203             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10204             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10205             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10206             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10207             if ( s0.match( query_nodes ) ) {
10208                 return false;
10209             }
10210             //
10211             query_nodes = new HashSet<PhylogenyNode>();
10212             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10213             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10214             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10215             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10216             if ( s0.match( query_nodes ) ) {
10217                 return false;
10218             }
10219             //
10220             query_nodes = new HashSet<PhylogenyNode>();
10221             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10222             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10223             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10224             if ( s0.match( query_nodes ) ) {
10225                 return false;
10226             }
10227             //
10228             query_nodes = new HashSet<PhylogenyNode>();
10229             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10230             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10231             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10232             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10233             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10234             if ( s0.match( query_nodes ) ) {
10235                 return false;
10236             }
10237             //
10238             query_nodes = new HashSet<PhylogenyNode>();
10239             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10240             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10241             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10242             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10243             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10244             if ( s0.match( query_nodes ) ) {
10245                 return false;
10246             }
10247             //
10248             query_nodes = new HashSet<PhylogenyNode>();
10249             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10250             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10251             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10252             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10253             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10254             if ( s0.match( query_nodes ) ) {
10255                 return false;
10256             }
10257             //
10258             query_nodes = new HashSet<PhylogenyNode>();
10259             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10260             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10261             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10262             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10263             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10264             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10265             if ( s0.match( query_nodes ) ) {
10266                 return false;
10267             }
10268         }
10269         catch ( final Exception e ) {
10270             e.printStackTrace();
10271             return false;
10272         }
10273         return true;
10274     }
10275
10276     private static boolean testSplitStrict() {
10277         try {
10278             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10279             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10280             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10281             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10282             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10283             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10284             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10285             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10286             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10287             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10288             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
10289             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10290             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10291             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10292             if ( s0.match( query_nodes ) ) {
10293                 return false;
10294             }
10295             query_nodes = new HashSet<PhylogenyNode>();
10296             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10297             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10298             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10299             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10300             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10301             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10302             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10303             if ( !s0.match( query_nodes ) ) {
10304                 return false;
10305             }
10306             //
10307             query_nodes = new HashSet<PhylogenyNode>();
10308             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10309             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10310             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10311             if ( !s0.match( query_nodes ) ) {
10312                 return false;
10313             }
10314             //
10315             query_nodes = new HashSet<PhylogenyNode>();
10316             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10317             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10318             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10319             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10320             if ( !s0.match( query_nodes ) ) {
10321                 return false;
10322             }
10323             //
10324             query_nodes = new HashSet<PhylogenyNode>();
10325             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10326             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10327             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10328             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10329             if ( !s0.match( query_nodes ) ) {
10330                 return false;
10331             }
10332             //
10333             query_nodes = new HashSet<PhylogenyNode>();
10334             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10335             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10336             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10337             if ( !s0.match( query_nodes ) ) {
10338                 return false;
10339             }
10340             //
10341             query_nodes = new HashSet<PhylogenyNode>();
10342             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10343             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10344             if ( !s0.match( query_nodes ) ) {
10345                 return false;
10346             }
10347             //
10348             query_nodes = new HashSet<PhylogenyNode>();
10349             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10350             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10351             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10352             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10353             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10354             if ( !s0.match( query_nodes ) ) {
10355                 return false;
10356             }
10357             //
10358             query_nodes = new HashSet<PhylogenyNode>();
10359             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10360             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10361             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10362             if ( !s0.match( query_nodes ) ) {
10363                 return false;
10364             }
10365             //
10366             query_nodes = new HashSet<PhylogenyNode>();
10367             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10368             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10369             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10370             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10371             if ( !s0.match( query_nodes ) ) {
10372                 return false;
10373             }
10374             //
10375             query_nodes = new HashSet<PhylogenyNode>();
10376             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10377             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10378             if ( s0.match( query_nodes ) ) {
10379                 return false;
10380             }
10381             //
10382             query_nodes = new HashSet<PhylogenyNode>();
10383             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10384             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10385             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10386             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10387             if ( s0.match( query_nodes ) ) {
10388                 return false;
10389             }
10390             //
10391             query_nodes = new HashSet<PhylogenyNode>();
10392             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10393             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10394             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10395             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10396             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10397             if ( s0.match( query_nodes ) ) {
10398                 return false;
10399             }
10400             //
10401             query_nodes = new HashSet<PhylogenyNode>();
10402             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10403             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10404             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10405             if ( s0.match( query_nodes ) ) {
10406                 return false;
10407             }
10408             //
10409             query_nodes = new HashSet<PhylogenyNode>();
10410             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10411             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10412             if ( s0.match( query_nodes ) ) {
10413                 return false;
10414             }
10415             //
10416             query_nodes = new HashSet<PhylogenyNode>();
10417             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10418             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10419             if ( s0.match( query_nodes ) ) {
10420                 return false;
10421             }
10422             //
10423             query_nodes = new HashSet<PhylogenyNode>();
10424             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10425             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10426             if ( s0.match( query_nodes ) ) {
10427                 return false;
10428             }
10429             //
10430             query_nodes = new HashSet<PhylogenyNode>();
10431             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10432             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10433             if ( s0.match( query_nodes ) ) {
10434                 return false;
10435             }
10436             //
10437             query_nodes = new HashSet<PhylogenyNode>();
10438             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10439             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10440             if ( s0.match( query_nodes ) ) {
10441                 return false;
10442             }
10443             //
10444             query_nodes = new HashSet<PhylogenyNode>();
10445             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10446             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10447             if ( s0.match( query_nodes ) ) {
10448                 return false;
10449             }
10450             //
10451             query_nodes = new HashSet<PhylogenyNode>();
10452             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10453             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10454             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10455             if ( s0.match( query_nodes ) ) {
10456                 return false;
10457             }
10458             //
10459             query_nodes = new HashSet<PhylogenyNode>();
10460             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10461             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10462             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10463             if ( s0.match( query_nodes ) ) {
10464                 return false;
10465             }
10466             //
10467             query_nodes = new HashSet<PhylogenyNode>();
10468             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10469             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10470             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10471             if ( s0.match( query_nodes ) ) {
10472                 return false;
10473             }
10474             //
10475             query_nodes = new HashSet<PhylogenyNode>();
10476             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10477             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10478             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10479             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10480             if ( s0.match( query_nodes ) ) {
10481                 return false;
10482             }
10483         }
10484         catch ( final Exception e ) {
10485             e.printStackTrace();
10486             return false;
10487         }
10488         return true;
10489     }
10490
10491     private static boolean testSubtreeDeletion() {
10492         try {
10493             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10494             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10495             t1.deleteSubtree( t1.getNode( "A" ), false );
10496             if ( t1.getNumberOfExternalNodes() != 5 ) {
10497                 return false;
10498             }
10499             t1.toNewHampshireX();
10500             t1.deleteSubtree( t1.getNode( "E" ), false );
10501             if ( t1.getNumberOfExternalNodes() != 4 ) {
10502                 return false;
10503             }
10504             t1.toNewHampshireX();
10505             t1.deleteSubtree( t1.getNode( "F" ), false );
10506             if ( t1.getNumberOfExternalNodes() != 3 ) {
10507                 return false;
10508             }
10509             t1.toNewHampshireX();
10510             t1.deleteSubtree( t1.getNode( "D" ), false );
10511             t1.toNewHampshireX();
10512             if ( t1.getNumberOfExternalNodes() != 3 ) {
10513                 return false;
10514             }
10515             t1.deleteSubtree( t1.getNode( "def" ), false );
10516             t1.toNewHampshireX();
10517             if ( t1.getNumberOfExternalNodes() != 2 ) {
10518                 return false;
10519             }
10520             t1.deleteSubtree( t1.getNode( "B" ), false );
10521             t1.toNewHampshireX();
10522             if ( t1.getNumberOfExternalNodes() != 1 ) {
10523                 return false;
10524             }
10525             t1.deleteSubtree( t1.getNode( "C" ), false );
10526             t1.toNewHampshireX();
10527             if ( t1.getNumberOfExternalNodes() != 1 ) {
10528                 return false;
10529             }
10530             t1.deleteSubtree( t1.getNode( "abc" ), false );
10531             t1.toNewHampshireX();
10532             if ( t1.getNumberOfExternalNodes() != 1 ) {
10533                 return false;
10534             }
10535             t1.deleteSubtree( t1.getNode( "r" ), false );
10536             if ( t1.getNumberOfExternalNodes() != 0 ) {
10537                 return false;
10538             }
10539             if ( !t1.isEmpty() ) {
10540                 return false;
10541             }
10542             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10543             t2.deleteSubtree( t2.getNode( "A" ), false );
10544             t2.toNewHampshireX();
10545             if ( t2.getNumberOfExternalNodes() != 5 ) {
10546                 return false;
10547             }
10548             t2.deleteSubtree( t2.getNode( "abc" ), false );
10549             t2.toNewHampshireX();
10550             if ( t2.getNumberOfExternalNodes() != 3 ) {
10551                 return false;
10552             }
10553             t2.deleteSubtree( t2.getNode( "def" ), false );
10554             t2.toNewHampshireX();
10555             if ( t2.getNumberOfExternalNodes() != 1 ) {
10556                 return false;
10557             }
10558         }
10559         catch ( final Exception e ) {
10560             e.printStackTrace( System.out );
10561             return false;
10562         }
10563         return true;
10564     }
10565
10566     private static boolean testSupportCount() {
10567         try {
10568             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10569             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
10570             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
10571                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
10572                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
10573                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
10574                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
10575                                                               new NHXParser() );
10576             SupportCount.count( t0_1, phylogenies_1, true, false );
10577             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
10578             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
10579                                                                       + "(((((A,B),C),D),E),((F,G),X))"
10580                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
10581                                                                       + "(((((A,B),C),D),E),(F,G))"
10582                                                                       + "(((((A,B),C),D),E),(F,G))"
10583                                                                       + "(((((A,B),C),D),E),(F,G))"
10584                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
10585                                                                       + "(((((A,B),C),D),E),(F,G))"
10586                                                                       + "((((((A,B),C),D),E),F),G)"
10587                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
10588                                                               new NHXParser() );
10589             SupportCount.count( t0_2, phylogenies_2, true, false );
10590             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
10591             while ( it.hasNext() ) {
10592                 final PhylogenyNode n = it.next();
10593                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
10594                     return false;
10595                 }
10596             }
10597             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
10598             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
10599                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
10600             SupportCount.count( t0_3, phylogenies_3, true, false );
10601             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
10602             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
10603                 return false;
10604             }
10605             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
10606                 return false;
10607             }
10608             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
10609                 return false;
10610             }
10611             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
10612                 return false;
10613             }
10614             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
10615                 return false;
10616             }
10617             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
10618                 return false;
10619             }
10620             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
10621                 return false;
10622             }
10623             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
10624                 return false;
10625             }
10626             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
10627                 return false;
10628             }
10629             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
10630                 return false;
10631             }
10632             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10633             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
10634                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
10635             SupportCount.count( t0_4, phylogenies_4, true, false );
10636             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
10637             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
10638                 return false;
10639             }
10640             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
10641                 return false;
10642             }
10643             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
10644                 return false;
10645             }
10646             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
10647                 return false;
10648             }
10649             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
10650                 return false;
10651             }
10652             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
10653                 return false;
10654             }
10655             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
10656                 return false;
10657             }
10658             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
10659                 return false;
10660             }
10661             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
10662                 return false;
10663             }
10664             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
10665                 return false;
10666             }
10667             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10668             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10669             double d = SupportCount.compare( b1, a, true, true, true );
10670             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
10671                 return false;
10672             }
10673             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10674             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10675             d = SupportCount.compare( b2, a, true, true, true );
10676             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
10677                 return false;
10678             }
10679             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10680             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
10681             d = SupportCount.compare( b3, a, true, true, true );
10682             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
10683                 return false;
10684             }
10685             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
10686             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
10687             d = SupportCount.compare( b4, a, true, true, false );
10688             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
10689                 return false;
10690             }
10691         }
10692         catch ( final Exception e ) {
10693             e.printStackTrace( System.out );
10694             return false;
10695         }
10696         return true;
10697     }
10698
10699     private static boolean testSupportTransfer() {
10700         try {
10701             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10702             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)",
10703                                                  new NHXParser() )[ 0 ];
10704             final Phylogeny p2 = factory
10705                     .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 ];
10706             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
10707                 return false;
10708             }
10709             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
10710                 return false;
10711             }
10712             support_transfer.moveBranchLengthsToBootstrap( p1 );
10713             support_transfer.transferSupportValues( p1, p2 );
10714             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
10715                 return false;
10716             }
10717             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
10718                 return false;
10719             }
10720             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
10721                 return false;
10722             }
10723             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
10724                 return false;
10725             }
10726             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
10727                 return false;
10728             }
10729             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
10730                 return false;
10731             }
10732             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
10733                 return false;
10734             }
10735             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
10736                 return false;
10737             }
10738         }
10739         catch ( final Exception e ) {
10740             e.printStackTrace( System.out );
10741             return false;
10742         }
10743         return true;
10744     }
10745
10746     private static boolean testTaxonomyExtraction() {
10747         try {
10748             final PhylogenyNode n0 = PhylogenyNode
10749                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10750             if ( n0.getNodeData().isHasTaxonomy() ) {
10751                 return false;
10752             }
10753             final PhylogenyNode n1 = PhylogenyNode
10754                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10755             if ( n1.getNodeData().isHasTaxonomy() ) {
10756                 System.out.println( n1.toString() );
10757                 return false;
10758             }
10759             final PhylogenyNode n2x = PhylogenyNode
10760                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10761             if ( n2x.getNodeData().isHasTaxonomy() ) {
10762                 return false;
10763             }
10764             final PhylogenyNode n3 = PhylogenyNode
10765                     .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10766             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10767                 System.out.println( n3.toString() );
10768                 return false;
10769             }
10770             final PhylogenyNode n4 = PhylogenyNode
10771                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10772             if ( n4.getNodeData().isHasTaxonomy() ) {
10773                 System.out.println( n4.toString() );
10774                 return false;
10775             }
10776             final PhylogenyNode n5 = PhylogenyNode
10777                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10778             if ( n5.getNodeData().isHasTaxonomy() ) {
10779                 System.out.println( n5.toString() );
10780                 return false;
10781             }
10782             final PhylogenyNode n6 = PhylogenyNode
10783                     .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10784             if ( n6.getNodeData().isHasTaxonomy() ) {
10785                 System.out.println( n6.toString() );
10786                 return false;
10787             }
10788             final PhylogenyNode n7 = PhylogenyNode
10789                     .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10790             if ( n7.getNodeData().isHasTaxonomy() ) {
10791                 System.out.println( n7.toString() );
10792                 return false;
10793             }
10794             final PhylogenyNode n8 = PhylogenyNode
10795                     .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10796             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10797                 System.out.println( n8.toString() );
10798                 return false;
10799             }
10800             final PhylogenyNode n9 = PhylogenyNode
10801                     .createInstanceFromNhxString( "blag_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10802             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10803                 System.out.println( n9.toString() );
10804                 return false;
10805             }
10806             final PhylogenyNode n10x = PhylogenyNode
10807                     .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10808             if ( n10x.getNodeData().isHasTaxonomy() ) {
10809                 System.out.println( n10x.toString() );
10810                 return false;
10811             }
10812             final PhylogenyNode n10xx = PhylogenyNode
10813                     .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10814             if ( n10xx.getNodeData().isHasTaxonomy() ) {
10815                 System.out.println( n10xx.toString() );
10816                 return false;
10817             }
10818             final PhylogenyNode n10 = PhylogenyNode
10819                     .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10820             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
10821                 System.out.println( n10.toString() );
10822                 return false;
10823             }
10824             final PhylogenyNode n11 = PhylogenyNode
10825                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10826             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
10827                 System.out.println( n11.toString() );
10828                 return false;
10829             }
10830             final PhylogenyNode n12 = PhylogenyNode
10831                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
10832                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10833             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
10834                 System.out.println( n12.toString() );
10835                 return false;
10836             }
10837             final PhylogenyNode n13 = PhylogenyNode
10838                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10839             if ( n13.getNodeData().isHasTaxonomy() ) {
10840                 System.out.println( n13.toString() );
10841                 return false;
10842             }
10843         }
10844         catch ( final Exception e ) {
10845             e.printStackTrace( System.out );
10846             return false;
10847         }
10848         return true;
10849     }
10850
10851     private static boolean testTreeMethods() {
10852         try {
10853             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10854             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
10855             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
10856             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
10857                 System.out.println( t0.toNewHampshireX() );
10858                 return false;
10859             }
10860             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
10861             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
10862             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
10863                 return false;
10864             }
10865             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
10866                 return false;
10867             }
10868             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
10869                 return false;
10870             }
10871         }
10872         catch ( final Exception e ) {
10873             e.printStackTrace( System.out );
10874             return false;
10875         }
10876         return true;
10877     }
10878
10879     private static boolean testSequenceDbWsTools1() {
10880         try {
10881             final PhylogenyNode n = new PhylogenyNode();
10882             n.setName( "NP_001025424" );
10883             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
10884             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10885                     || !acc.getValue().equals( "NP_001025424" ) ) {
10886                 return false;
10887             }
10888             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
10889             acc = SequenceDbWsTools.obtainSeqAccession( n );
10890             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10891                     || !acc.getValue().equals( "NP_001025424" ) ) {
10892                 return false;
10893             }
10894             n.setName( "NP_001025424.1" );
10895             acc = SequenceDbWsTools.obtainSeqAccession( n );
10896             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10897                     || !acc.getValue().equals( "NP_001025424" ) ) {
10898                 return false;
10899             }
10900             n.setName( "NM_001030253" );
10901             acc = SequenceDbWsTools.obtainSeqAccession( n );
10902             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10903                     || !acc.getValue().equals( "NM_001030253" ) ) {
10904                 return false;
10905             }
10906             n.setName( "BCL2_HUMAN" );
10907             acc = SequenceDbWsTools.obtainSeqAccession( n );
10908             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10909                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
10910                 System.out.println( acc.toString() );
10911                 return false;
10912             }
10913             n.setName( "P10415" );
10914             acc = SequenceDbWsTools.obtainSeqAccession( n );
10915             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10916                     || !acc.getValue().equals( "P10415" ) ) {
10917                 System.out.println( acc.toString() );
10918                 return false;
10919             }
10920             n.setName( " P10415 " );
10921             acc = SequenceDbWsTools.obtainSeqAccession( n );
10922             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10923                     || !acc.getValue().equals( "P10415" ) ) {
10924                 System.out.println( acc.toString() );
10925                 return false;
10926             }
10927             n.setName( "_P10415|" );
10928             acc = SequenceDbWsTools.obtainSeqAccession( n );
10929             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10930                     || !acc.getValue().equals( "P10415" ) ) {
10931                 System.out.println( acc.toString() );
10932                 return false;
10933             }
10934             n.setName( "AY695820" );
10935             acc = SequenceDbWsTools.obtainSeqAccession( n );
10936             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10937                     || !acc.getValue().equals( "AY695820" ) ) {
10938                 System.out.println( acc.toString() );
10939                 return false;
10940             }
10941             n.setName( "_AY695820_" );
10942             acc = SequenceDbWsTools.obtainSeqAccession( n );
10943             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10944                     || !acc.getValue().equals( "AY695820" ) ) {
10945                 System.out.println( acc.toString() );
10946                 return false;
10947             }
10948             n.setName( "AAA59452" );
10949             acc = SequenceDbWsTools.obtainSeqAccession( n );
10950             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10951                     || !acc.getValue().equals( "AAA59452" ) ) {
10952                 System.out.println( acc.toString() );
10953                 return false;
10954             }
10955             n.setName( "_AAA59452_" );
10956             acc = SequenceDbWsTools.obtainSeqAccession( n );
10957             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10958                     || !acc.getValue().equals( "AAA59452" ) ) {
10959                 System.out.println( acc.toString() );
10960                 return false;
10961             }
10962             n.setName( "AAA59452.1" );
10963             acc = SequenceDbWsTools.obtainSeqAccession( n );
10964             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10965                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10966                 System.out.println( acc.toString() );
10967                 return false;
10968             }
10969             n.setName( "_AAA59452.1_" );
10970             acc = SequenceDbWsTools.obtainSeqAccession( n );
10971             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10972                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10973                 System.out.println( acc.toString() );
10974                 return false;
10975             }
10976             n.setName( "GI:94894583" );
10977             acc = SequenceDbWsTools.obtainSeqAccession( n );
10978             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10979                     || !acc.getValue().equals( "94894583" ) ) {
10980                 System.out.println( acc.toString() );
10981                 return false;
10982             }
10983         }
10984         catch ( final Exception e ) {
10985             return false;
10986         }
10987         return true;
10988     }
10989
10990     private static boolean testSequenceDbWsTools2() {
10991         try {
10992             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
10993             SequenceDbWsTools.obtainSeqInformation( n1 );
10994             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
10995                 return false;
10996             }
10997             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10998                 return false;
10999             }
11000             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11001                 return false;
11002             }
11003             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11004                 return false;
11005             }
11006             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11007             SequenceDbWsTools.obtainSeqInformation( n2 );
11008             System.out.println( n2.toString() );
11009             if ( !n2.getNodeData().getSequence().getName()
11010                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
11011                 return false;
11012             }
11013             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11014                 return false;
11015             }
11016             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11017                 return false;
11018             }
11019             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11020                 return false;
11021             }
11022             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11023             SequenceDbWsTools.obtainSeqInformation( n3 );
11024             System.out.println( "n=" + n3.toString() );
11025             if ( !n3.getNodeData().getSequence().getName()
11026                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11027                 return false;
11028             }
11029             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11030                 return false;
11031             }
11032             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11033                 return false;
11034             }
11035             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11036                 return false;
11037             }
11038         }
11039         catch ( final IOException e ) {
11040             System.out.println();
11041             System.out.println( "the following might be due to absence internet connection:" );
11042             e.printStackTrace( System.out );
11043             return true;
11044         }
11045         catch ( final Exception e ) {
11046             e.printStackTrace();
11047             return false;
11048         }
11049         return true;
11050     }
11051
11052     private static boolean testEbiEntryRetrieval() {
11053         try {
11054             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
11055             if ( !entry.getAccession().equals( "AAK41263" ) ) {
11056                 System.out.println( entry.getAccession() );
11057                 return false;
11058             }
11059             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
11060                 System.out.println( entry.getTaxonomyScientificName() );
11061                 return false;
11062             }
11063             if ( !entry.getSequenceName()
11064                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
11065                 System.out.println( entry.getSequenceName() );
11066                 return false;
11067             }
11068             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
11069             //     System.out.println( entry.getSequenceSymbol() );
11070             //     return false;
11071             // }
11072             if ( !entry.getGeneName().equals( "treX-like" ) ) {
11073                 System.out.println( entry.getGeneName() );
11074                 return false;
11075             }
11076             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
11077                 System.out.println( entry.getTaxonomyIdentifier() );
11078                 return false;
11079             }
11080             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
11081                 System.out.println( entry.getAnnotations().first().getRefValue() );
11082                 return false;
11083             }
11084             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
11085                 System.out.println( entry.getAnnotations().first().getRefSource() );
11086                 return false;
11087             }
11088             if ( entry.getCrossReferences().size() != 5 ) {
11089                 return false;
11090             }
11091             //
11092             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
11093             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
11094                 return false;
11095             }
11096             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
11097                 System.out.println( entry1.getTaxonomyScientificName() );
11098                 return false;
11099             }
11100             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
11101                 System.out.println( entry1.getSequenceName() );
11102                 return false;
11103             }
11104             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
11105                 System.out.println( entry1.getTaxonomyIdentifier() );
11106                 return false;
11107             }
11108             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
11109                 System.out.println( entry1.getGeneName() );
11110                 return false;
11111             }
11112             if ( entry1.getCrossReferences().size() != 6 ) {
11113                 return false;
11114             }
11115             //
11116             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
11117             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
11118                 return false;
11119             }
11120             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
11121                 System.out.println( entry2.getTaxonomyScientificName() );
11122                 return false;
11123             }
11124             if ( !entry2.getSequenceName()
11125                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11126                 System.out.println( entry2.getSequenceName() );
11127                 return false;
11128             }
11129             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
11130                 System.out.println( entry2.getTaxonomyIdentifier() );
11131                 return false;
11132             }
11133             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
11134                 System.out.println( entry2.getGeneName() );
11135                 return false;
11136             }
11137             if ( entry2.getCrossReferences().size() != 3 ) {
11138                 return false;
11139             }
11140             //
11141             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
11142             if ( !entry3.getAccession().equals( "HM043801" ) ) {
11143                 return false;
11144             }
11145             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
11146                 System.out.println( entry3.getTaxonomyScientificName() );
11147                 return false;
11148             }
11149             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
11150                 System.out.println( entry3.getSequenceName() );
11151                 return false;
11152             }
11153             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
11154                 System.out.println( entry3.getTaxonomyIdentifier() );
11155                 return false;
11156             }
11157             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
11158                 System.out.println( entry3.getSequenceSymbol() );
11159                 return false;
11160             }
11161             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
11162                 return false;
11163             }
11164             if ( entry3.getCrossReferences().size() != 8 ) {
11165                 return false;
11166             }
11167             //
11168             //
11169             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
11170             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
11171                 return false;
11172             }
11173             //
11174             //TODO fails:
11175             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
11176             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
11177             //                return false;
11178             //            }
11179         }
11180         catch ( final IOException e ) {
11181             System.out.println();
11182             System.out.println( "the following might be due to absence internet connection:" );
11183             e.printStackTrace( System.out );
11184             return true;
11185         }
11186         catch ( final Exception e ) {
11187             e.printStackTrace();
11188             return false;
11189         }
11190         return true;
11191     }
11192
11193     private static boolean testUniprotEntryRetrieval() {
11194         try {
11195             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
11196             if ( !entry.getAccession().equals( "P12345" ) ) {
11197                 return false;
11198             }
11199             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
11200                 return false;
11201             }
11202             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
11203                 return false;
11204             }
11205             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
11206                 return false;
11207             }
11208             if ( !entry.getGeneName().equals( "GOT2" ) ) {
11209                 return false;
11210             }
11211             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
11212                 return false;
11213             }
11214         }
11215         catch ( final IOException e ) {
11216             System.out.println();
11217             System.out.println( "the following might be due to absence internet connection:" );
11218             e.printStackTrace( System.out );
11219             return true;
11220         }
11221         catch ( final Exception e ) {
11222             return false;
11223         }
11224         return true;
11225     }
11226
11227     private static boolean testUniprotTaxonomySearch() {
11228         try {
11229             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
11230                                                                                                  10 );
11231             if ( results.size() != 1 ) {
11232                 return false;
11233             }
11234             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11235                 return false;
11236             }
11237             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11238                 return false;
11239             }
11240             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11241                 return false;
11242             }
11243             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11244                 return false;
11245             }
11246             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11247                 return false;
11248             }
11249             results = null;
11250             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
11251             if ( results.size() != 1 ) {
11252                 return false;
11253             }
11254             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11255                 return false;
11256             }
11257             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11258                 return false;
11259             }
11260             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11261                 return false;
11262             }
11263             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11264                 return false;
11265             }
11266             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11267                 return false;
11268             }
11269             results = null;
11270             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
11271             if ( results.size() != 1 ) {
11272                 return false;
11273             }
11274             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11275                 return false;
11276             }
11277             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11278                 return false;
11279             }
11280             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11281                 return false;
11282             }
11283             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11284                 return false;
11285             }
11286             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11287                 return false;
11288             }
11289             results = null;
11290             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
11291             if ( results.size() != 1 ) {
11292                 return false;
11293             }
11294             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11295                 return false;
11296             }
11297             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11298                 return false;
11299             }
11300             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11301                 return false;
11302             }
11303             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11304                 return false;
11305             }
11306             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11307                 return false;
11308             }
11309             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
11310                 return false;
11311             }
11312             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
11313                 return false;
11314             }
11315             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11316                     .equals( "Nematostella vectensis" ) ) {
11317                 System.out.println( results.get( 0 ).getLineage() );
11318                 return false;
11319             }
11320             //
11321             results = null;
11322             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
11323             if ( results.size() != 1 ) {
11324                 return false;
11325             }
11326             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11327                 return false;
11328             }
11329             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11330                 return false;
11331             }
11332             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11333                 return false;
11334             }
11335             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11336                 return false;
11337             }
11338             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11339                 return false;
11340             }
11341             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11342                     .equals( "Xenopus tropicalis" ) ) {
11343                 System.out.println( results.get( 0 ).getLineage() );
11344                 return false;
11345             }
11346             //
11347             results = null;
11348             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
11349             if ( results.size() != 1 ) {
11350                 return false;
11351             }
11352             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11353                 return false;
11354             }
11355             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11356                 return false;
11357             }
11358             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11359                 return false;
11360             }
11361             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11362                 return false;
11363             }
11364             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11365                 return false;
11366             }
11367             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11368                     .equals( "Xenopus tropicalis" ) ) {
11369                 System.out.println( results.get( 0 ).getLineage() );
11370                 return false;
11371             }
11372             //
11373             results = null;
11374             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
11375             if ( results.size() != 1 ) {
11376                 return false;
11377             }
11378             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11379                 return false;
11380             }
11381             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11382                 return false;
11383             }
11384             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11385                 return false;
11386             }
11387             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11388                 return false;
11389             }
11390             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11391                 return false;
11392             }
11393             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11394                     .equals( "Xenopus tropicalis" ) ) {
11395                 System.out.println( results.get( 0 ).getLineage() );
11396                 return false;
11397             }
11398         }
11399         catch ( final IOException e ) {
11400             System.out.println();
11401             System.out.println( "the following might be due to absence internet connection:" );
11402             e.printStackTrace( System.out );
11403             return true;
11404         }
11405         catch ( final Exception e ) {
11406             return false;
11407         }
11408         return true;
11409     }
11410
11411     private static boolean testWabiTxSearch() {
11412         try {
11413             String result = "";
11414             result = TxSearch.searchSimple( "nematostella" );
11415             result = TxSearch.getTxId( "nematostella" );
11416             if ( !result.equals( "45350" ) ) {
11417                 return false;
11418             }
11419             result = TxSearch.getTxName( "45350" );
11420             if ( !result.equals( "Nematostella" ) ) {
11421                 return false;
11422             }
11423             result = TxSearch.getTxId( "nematostella vectensis" );
11424             if ( !result.equals( "45351" ) ) {
11425                 return false;
11426             }
11427             result = TxSearch.getTxName( "45351" );
11428             if ( !result.equals( "Nematostella vectensis" ) ) {
11429                 return false;
11430             }
11431             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
11432             if ( !result.equals( "536089" ) ) {
11433                 return false;
11434             }
11435             result = TxSearch.getTxName( "536089" );
11436             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
11437                 return false;
11438             }
11439             final List<String> queries = new ArrayList<String>();
11440             queries.add( "Campylobacter coli" );
11441             queries.add( "Escherichia coli" );
11442             queries.add( "Arabidopsis" );
11443             queries.add( "Trichoplax" );
11444             queries.add( "Samanea saman" );
11445             queries.add( "Kluyveromyces marxianus" );
11446             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
11447             queries.add( "Bornavirus parrot/PDD/2008" );
11448             final List<RANKS> ranks = new ArrayList<RANKS>();
11449             ranks.add( RANKS.SUPERKINGDOM );
11450             ranks.add( RANKS.KINGDOM );
11451             ranks.add( RANKS.FAMILY );
11452             ranks.add( RANKS.GENUS );
11453             ranks.add( RANKS.TRIBE );
11454             result = TxSearch.searchLineage( queries, ranks );
11455             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
11456             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
11457         }
11458         catch ( final Exception e ) {
11459             System.out.println();
11460             System.out.println( "the following might be due to absence internet connection:" );
11461             e.printStackTrace( System.out );
11462             return false;
11463         }
11464         return true;
11465     }
11466 }